Home | History | Annotate | Line # | Download | only in gen
urem.S revision 1.2.48.1
      1       1.1  christos /*-
      2       1.1  christos  * Copyright (c) 1991, 1993
      3       1.1  christos  *	The Regents of the University of California.  All rights reserved.
      4       1.1  christos  *
      5       1.1  christos  * This code is derived from software contributed to Berkeley by
      6       1.1  christos  * Donn Seeley at UUNET Technologies, Inc.
      7       1.1  christos  *
      8       1.1  christos  * Redistribution and use in source and binary forms, with or without
      9       1.1  christos  * modification, are permitted provided that the following conditions
     10       1.1  christos  * are met:
     11       1.1  christos  * 1. Redistributions of source code must retain the above copyright
     12       1.1  christos  *    notice, this list of conditions and the following disclaimer.
     13       1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     15       1.1  christos  *    documentation and/or other materials provided with the distribution.
     16       1.1  christos  * 3. Neither the name of the University nor the names of its contributors
     17       1.1  christos  *    may be used to endorse or promote products derived from this software
     18       1.1  christos  *    without specific prior written permission.
     19       1.1  christos  *
     20       1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     21       1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22       1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23       1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     24       1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25       1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26       1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27       1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28       1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29       1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30       1.1  christos  * SUCH DAMAGE.
     31       1.1  christos  */
     32       1.1  christos 
     33       1.2      matt #include <machine/asm.h>
     34       1.1  christos 
     35  1.2.48.1    bouyer 	/* .asciz "@(#)urem.s	8.1 (Berkeley) 6/4/93" */
     36  1.2.48.1    bouyer RCSID("$NetBSD: urem.S,v 1.2.48.1 2011/02/08 16:18:28 bouyer Exp $")
     37  1.2.48.1    bouyer 
     38       1.1  christos /*
     39       1.1  christos  * Unsigned modulus, PCC flavor.
     40       1.1  christos  * urem() takes an ordinary dividend/divisor pair;
     41       1.1  christos  * aurem() takes a pointer to a dividend and an ordinary divisor.
     42       1.1  christos  */
     43       1.1  christos 
     44       1.1  christos #define	DIVIDEND	4(%ap)
     45       1.1  christos #define	DIVISOR		8(%ap)
     46       1.1  christos 
     47       1.1  christos ASENTRY(__urem,0)
     48       1.1  christos 	movl	DIVISOR,%r2
     49       1.1  christos 	jlss	Leasy		# big divisor: settle by comparison
     50       1.1  christos 	movl	DIVIDEND,%r0
     51       1.1  christos 	jlss	Lhard		# big dividend: need extended division
     52       1.1  christos 	divl3	%r2,%r0,%r1	# small divisor and dividend: signed modulus
     53       1.1  christos 	mull2	%r2,%r1
     54       1.1  christos 	subl2	%r1,%r0
     55       1.1  christos 	ret
     56       1.1  christos Lhard:
     57       1.1  christos 	clrl	%r1
     58       1.1  christos 	ediv	%r2,%r0,%r1,%r0
     59       1.1  christos 	ret
     60       1.1  christos Leasy:
     61       1.1  christos 	subl3	%r2,DIVIDEND,%r0
     62       1.1  christos 	jcc	Ldifference	# if divisor goes in once, return difference
     63       1.1  christos 	movl	DIVIDEND,%r0	# if divisor is bigger, return dividend
     64       1.1  christos Ldifference:
     65       1.1  christos 	ret
     66  1.2.48.1    bouyer END(__urem)
     67       1.1  christos 
     68       1.1  christos ASENTRY(__aurem,0)
     69       1.1  christos 	movl	DIVIDEND,%r3
     70       1.1  christos 	movl	DIVISOR,%r2
     71       1.1  christos 	jlss	La_easy		# big divisor: settle by comparison
     72       1.1  christos 	movl	(%r3),%r0
     73       1.1  christos 	jlss	La_hard		# big dividend: need extended division
     74       1.1  christos 	divl3	%r2,%r0,%r1	# small divisor and dividend: signed modulus
     75       1.1  christos 	mull2	%r2,%r1
     76       1.1  christos 	subl2	%r1,%r0
     77       1.1  christos 	movl	%r0,(%r3)		# leave the value of the assignment in %r0
     78       1.1  christos 	ret
     79       1.1  christos La_hard:
     80       1.1  christos 	clrl	%r1
     81       1.1  christos 	ediv	%r2,%r0,%r1,%r0
     82       1.1  christos 	movl	%r0,(%r3)
     83       1.1  christos 	ret
     84       1.1  christos La_easy:
     85       1.1  christos 	subl3	%r2,(%r3),%r0
     86       1.1  christos 	jcs	La_dividend	# if divisor is bigger, leave dividend alone
     87       1.1  christos 	movl	%r0,(%r3)		# if divisor goes in once, store difference
     88       1.1  christos 	ret
     89       1.1  christos La_dividend:
     90       1.1  christos 	movl	(%r3),%r0
     91       1.1  christos 	ret
     92  1.2.48.1    bouyer END(__aurem)
     93