xref: /csrg-svn/lib/libc/vax/gen/urem.s (revision 61225)
147837Sbostic/*-
2*61225Sbostic * Copyright (c) 1991, 1993
3*61225Sbostic *	The Regents of the University of California.  All rights reserved.
413421Sroot *
547993Sdonn * This code is derived from software contributed to Berkeley by
647993Sdonn * Donn Seeley at UUNET Technologies, Inc.
747993Sdonn *
847837Sbostic * %sccs.include.redist.c%
913421Sroot */
1047837Sbostic
1147837Sbostic#if defined(LIBC_SCCS) && !defined(lint)
12*61225Sbostic	.asciz "@(#)urem.s	8.1 (Berkeley) 06/04/93"
1347837Sbostic#endif /* LIBC_SCCS and not lint */
1447837Sbostic
1513421Sroot#include "DEFS.h"
1613421Sroot
1717717Sralph/*
1847837Sbostic * Unsigned modulus, PCC flavor.
1947837Sbostic * urem() takes an ordinary dividend/divisor pair;
2047837Sbostic * aurem() takes a pointer to a dividend and an ordinary divisor.
2117717Sralph */
2217717Sralph
2347837Sbostic#define	DIVIDEND	4(ap)
2447837Sbostic#define	DIVISOR		8(ap)
2547837Sbostic
2647837SbosticASENTRY(urem,0)
2747837Sbostic	movl	DIVISOR,r2
2847837Sbostic	jlss	Leasy		# big divisor: settle by comparison
2947837Sbostic	movl	DIVIDEND,r0
3047837Sbostic	jlss	Lhard		# big dividend: need extended division
3147837Sbostic	divl3	r2,r0,r1	# small divisor and dividend: signed modulus
3247837Sbostic	mull2	r2,r1
3347837Sbostic	subl2	r1,r0
3417717Sralph	ret
3547837SbosticLhard:
3647837Sbostic	clrl	r1
3747837Sbostic	ediv	r2,r0,r1,r0
3817717Sralph	ret
3947837SbosticLeasy:
4047837Sbostic	subl3	r2,DIVIDEND,r0
4147837Sbostic	jcc	Ldifference	# if divisor goes in once, return difference
4247837Sbostic	movl	DIVIDEND,r0	# if divisor is bigger, return dividend
4347837SbosticLdifference:
4447837Sbostic	ret
4547837Sbostic
4647837SbosticASENTRY(aurem,0)
4747866Sdonn	movl	DIVIDEND,r3
4847837Sbostic	movl	DIVISOR,r2
4947838Sbostic	jlss	La_easy		# big divisor: settle by comparison
5047837Sbostic	movl	(r3),r0
5147838Sbostic	jlss	La_hard		# big dividend: need extended division
5247837Sbostic	divl3	r2,r0,r1	# small divisor and dividend: signed modulus
5347837Sbostic	mull2	r2,r1
5447838Sbostic	subl2	r1,r0
5547838Sbostic	movl	r0,(r3)		# leave the value of the assignment in r0
5647837Sbostic	ret
5747838SbosticLa_hard:
5847837Sbostic	clrl	r1
5947838Sbostic	ediv	r2,r0,r1,r0
6047838Sbostic	movl	r0,(r3)
6147837Sbostic	ret
6247838SbosticLa_easy:
6347837Sbostic	subl3	r2,(r3),r0
6447838Sbostic	jcs	La_dividend	# if divisor is bigger, leave dividend alone
6547837Sbostic	movl	r0,(r3)		# if divisor goes in once, store difference
6647837Sbostic	ret
6747838SbosticLa_dividend:
6847838Sbostic	movl	(r3),r0
6947838Sbostic	ret
70