xref: /original-bsd/lib/libc/vax/gen/urem.s (revision 6219b5e8)
1/*	urem.s	4.4	85/01/16	*/
2
3/*
4 * urem - unsigned remainder for vax-11
5 *
6 * arguments: dividend, divisor
7 * result: remainder
8 * uses r0-r2
9 *
10 * if 1 < divisor <= 2147483647, zero-extend the dividend
11 * to 64 bits and let ediv do the work.  If the divisor is 1,
12 * ediv will overflow if bit 31 of the dividend is on, so
13 * just return 0.  If the divisor is 0, do the ediv also,
14 * so it will generate the proper exception.  All other values
15 * of the divisor have bit 31 on: in this case the remainder
16 * must be the dividend if divisor > dividend, and the dividend
17 * minus the divisor otherwise.  The comparison must be unsigned.
18 */
19#include "DEFS.h"
20
21ASENTRY(urem, 0)
22	movl	4(ap),r0	/* dividend */
23	movl	8(ap),r2	/* divisor */
24	jeql	1f		/* if divisor=0, force exception */
25	cmpl	r2,$1		/* if divisor <= 1 (signed), */
26	jleq	2f		/*  no division is necessary */
271:
28	clrl	r1		/* zero-extend the dividend */
29	ediv	r2,r0,r2,r0	/* divide.  q->r2 (discarded), r->r0 */
30	ret
312:
32	jneq	1f		/* if divisor=1, return 0 */
33	clrl	r0		/*  (because doing the divide will overflow */
34	ret			/*  if the dividend has its high bit on) */
351:
36	cmpl	r0,r2		/* if dividend < divisor (unsigned) */
37	jlssu	1f		/*  remainder is dividend */
38	subl2	r2,r0		/*  else remainder is dividend - divisor */
391:
40	ret
41
42/*
43 * aurem - unsigned remainder for vax-11
44 *
45 * arguments: *dividend, divisor
46 * result: remainder in r0 and *dividend
47 * uses r0-r2
48 */
49#include "DEFS.h"
50
51ASENTRY(aurem, 0)
52	movl	*4(ap),r0	/* dividend */
53	movl	8(ap),r2	/* divisor */
54	jeql	1f		/* if divisor=0, force exception */
55	cmpl	r2,$1		/* if divisor <= 1 (signed), */
56	jleq	2f		/*  no division is necessary */
571:
58	clrl	r1		/* zero-extend the dividend */
59	ediv	r2,r0,r2,r0	/* divide.  q->r2 (discarded), r->r0 */
60	movl	r0,*4(ap)	/* save result */
61	ret
622:
63	jneq	1f		/* if divisor=1, return 0 */
64	clrl	r0		/*  (because doing the divide will overflow */
65	clrl	*4(ap)		/*  if the dividend has its high bit on) */
66	ret
671:
68	cmpl	r0,r2		/* if dividend < divisor (unsigned) */
69	jlssu	1f		/*  remainder is dividend */
70	subl2	r2,r0		/*  else remainder is dividend - divisor */
711:
72	movl	r0,*4(ap)	/* save result */
73	ret
74