Home | History | Annotate | Line # | Download | only in gen
urem.S revision 1.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.1  christos #if defined(LIBC_SCCS) && !defined(lint)
     34  1.1  christos 	/* .asciz "@(#)urem.s	8.1 (Berkeley) 6/4/93" */
     35  1.1  christos 	.asciz "$NetBSD: urem.S,v 1.1 2005/12/20 19:28:50 christos Exp $"
     36  1.1  christos #endif /* LIBC_SCCS and not lint */
     37  1.1  christos 
     38  1.1  christos #include "DEFS.h"
     39  1.1  christos 
     40  1.1  christos /*
     41  1.1  christos  * Unsigned modulus, PCC flavor.
     42  1.1  christos  * urem() takes an ordinary dividend/divisor pair;
     43  1.1  christos  * aurem() takes a pointer to a dividend and an ordinary divisor.
     44  1.1  christos  */
     45  1.1  christos 
     46  1.1  christos #define	DIVIDEND	4(%ap)
     47  1.1  christos #define	DIVISOR		8(%ap)
     48  1.1  christos 
     49  1.1  christos #ifdef __ELF__
     50  1.1  christos ASENTRY(__urem,0)
     51  1.1  christos #else
     52  1.1  christos ASENTRY(urem,0)
     53  1.1  christos #endif
     54  1.1  christos 	movl	DIVISOR,%r2
     55  1.1  christos 	jlss	Leasy		# big divisor: settle by comparison
     56  1.1  christos 	movl	DIVIDEND,%r0
     57  1.1  christos 	jlss	Lhard		# big dividend: need extended division
     58  1.1  christos 	divl3	%r2,%r0,%r1	# small divisor and dividend: signed modulus
     59  1.1  christos 	mull2	%r2,%r1
     60  1.1  christos 	subl2	%r1,%r0
     61  1.1  christos 	ret
     62  1.1  christos Lhard:
     63  1.1  christos 	clrl	%r1
     64  1.1  christos 	ediv	%r2,%r0,%r1,%r0
     65  1.1  christos 	ret
     66  1.1  christos Leasy:
     67  1.1  christos 	subl3	%r2,DIVIDEND,%r0
     68  1.1  christos 	jcc	Ldifference	# if divisor goes in once, return difference
     69  1.1  christos 	movl	DIVIDEND,%r0	# if divisor is bigger, return dividend
     70  1.1  christos Ldifference:
     71  1.1  christos 	ret
     72  1.1  christos 
     73  1.1  christos #ifdef __ELF__
     74  1.1  christos ASENTRY(__aurem,0)
     75  1.1  christos #else
     76  1.1  christos ASENTRY(aurem,0)
     77  1.1  christos #endif
     78  1.1  christos 	movl	DIVIDEND,%r3
     79  1.1  christos 	movl	DIVISOR,%r2
     80  1.1  christos 	jlss	La_easy		# big divisor: settle by comparison
     81  1.1  christos 	movl	(%r3),%r0
     82  1.1  christos 	jlss	La_hard		# big dividend: need extended division
     83  1.1  christos 	divl3	%r2,%r0,%r1	# small divisor and dividend: signed modulus
     84  1.1  christos 	mull2	%r2,%r1
     85  1.1  christos 	subl2	%r1,%r0
     86  1.1  christos 	movl	%r0,(%r3)		# leave the value of the assignment in %r0
     87  1.1  christos 	ret
     88  1.1  christos La_hard:
     89  1.1  christos 	clrl	%r1
     90  1.1  christos 	ediv	%r2,%r0,%r1,%r0
     91  1.1  christos 	movl	%r0,(%r3)
     92  1.1  christos 	ret
     93  1.1  christos La_easy:
     94  1.1  christos 	subl3	%r2,(%r3),%r0
     95  1.1  christos 	jcs	La_dividend	# if divisor is bigger, leave dividend alone
     96  1.1  christos 	movl	%r0,(%r3)		# if divisor goes in once, store difference
     97  1.1  christos 	ret
     98  1.1  christos La_dividend:
     99  1.1  christos 	movl	(%r3),%r0
    100  1.1  christos 	ret
    101