xref: /original-bsd/lib/libc/vax/gen/urem.s (revision f8e19ae4)
1b580cc63Sbostic/*-
2*f8e19ae4Sbostic * Copyright (c) 1991, 1993
3*f8e19ae4Sbostic *	The Regents of the University of California.  All rights reserved.
4b580cc63Sbostic *
59fbb7d9bSdonn * This code is derived from software contributed to Berkeley by
69fbb7d9bSdonn * Donn Seeley at UUNET Technologies, Inc.
79fbb7d9bSdonn *
8b580cc63Sbostic * %sccs.include.redist.c%
9b580cc63Sbostic */
10b580cc63Sbostic
11b580cc63Sbostic#if defined(LIBC_SCCS) && !defined(lint)
12*f8e19ae4Sbostic	.asciz "@(#)urem.s	8.1 (Berkeley) 06/04/93"
13b580cc63Sbostic#endif /* LIBC_SCCS and not lint */
14b580cc63Sbostic
15b580cc63Sbostic#include "DEFS.h"
16165e9bdaSroot
17165e9bdaSroot/*
18b580cc63Sbostic * Unsigned modulus, PCC flavor.
19b580cc63Sbostic * urem() takes an ordinary dividend/divisor pair;
20b580cc63Sbostic * aurem() takes a pointer to a dividend and an ordinary divisor.
21165e9bdaSroot */
22b580cc63Sbostic
23b580cc63Sbostic#define	DIVIDEND	4(ap)
24b580cc63Sbostic#define	DIVISOR		8(ap)
25165e9bdaSroot
26909d29b8SsamASENTRY(urem,0)
27b580cc63Sbostic	movl	DIVISOR,r2
28b580cc63Sbostic	jlss	Leasy		# big divisor: settle by comparison
29b580cc63Sbostic	movl	DIVIDEND,r0
30b580cc63Sbostic	jlss	Lhard		# big dividend: need extended division
31b580cc63Sbostic	divl3	r2,r0,r1	# small divisor and dividend: signed modulus
32b580cc63Sbostic	mull2	r2,r1
33b580cc63Sbostic	subl2	r1,r0
34165e9bdaSroot	ret
35b580cc63SbosticLhard:
36b580cc63Sbostic	clrl	r1
37b580cc63Sbostic	ediv	r2,r0,r1,r0
38165e9bdaSroot	ret
39b580cc63SbosticLeasy:
40b580cc63Sbostic	subl3	r2,DIVIDEND,r0
41b580cc63Sbostic	jcc	Ldifference	# if divisor goes in once, return difference
42b580cc63Sbostic	movl	DIVIDEND,r0	# if divisor is bigger, return dividend
43b580cc63SbosticLdifference:
44b580cc63Sbostic	ret
459e3ea573Sralph
469e3ea573SralphASENTRY(aurem,0)
4712a601b9Sdonn	movl	DIVIDEND,r3
48b580cc63Sbostic	movl	DIVISOR,r2
49e47887b9Sbostic	jlss	La_easy		# big divisor: settle by comparison
50b580cc63Sbostic	movl	(r3),r0
51e47887b9Sbostic	jlss	La_hard		# big dividend: need extended division
52b580cc63Sbostic	divl3	r2,r0,r1	# small divisor and dividend: signed modulus
53b580cc63Sbostic	mull2	r2,r1
54e47887b9Sbostic	subl2	r1,r0
55e47887b9Sbostic	movl	r0,(r3)		# leave the value of the assignment in r0
569e3ea573Sralph	ret
57e47887b9SbosticLa_hard:
58b580cc63Sbostic	clrl	r1
59e47887b9Sbostic	ediv	r2,r0,r1,r0
60e47887b9Sbostic	movl	r0,(r3)
619e3ea573Sralph	ret
62e47887b9SbosticLa_easy:
63b580cc63Sbostic	subl3	r2,(r3),r0
64e47887b9Sbostic	jcs	La_dividend	# if divisor is bigger, leave dividend alone
65b580cc63Sbostic	movl	r0,(r3)		# if divisor goes in once, store difference
66e47887b9Sbostic	ret
67e47887b9SbosticLa_dividend:
68e47887b9Sbostic	movl	(r3),r0
699e3ea573Sralph	ret
70