xref: /original-bsd/lib/libc/tahoe/gen/urem.s (revision f1656be1)
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Computer Consoles Inc.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that this notice is preserved and that due credit is given
10 * to the University of California at Berkeley. The name of the University
11 * may not be used to endorse or promote products derived from this
12 * software without specific prior written permission. This software
13 * is provided ``as is'' without express or implied warranty.
14 */
15
16#if defined(LIBC_SCCS) && !defined(lint)
17_sccsid:.asciz	"@(#)urem.s	1.2 (Berkeley) 05/23/88"
18#endif /* LIBC_SCCS and not lint */
19
20/*
21 * Unsigned remainder.
22 *
23 * urem(dividend, divisor)
24 */
25#include "DEFS.h"
26
27ASENTRY(urem, 0)
28	bitl	$0x80000000,8(fp)	#  if (divisor & 0x80000000){
29	jeql	1f
30	movl	4(fp),r0
31	cmpl	8(fp),r0		#  if (divisor <= dividend )
32	jgtru	2f
33	subl2	8(fp),r0		#       return(dividend-divisor);
342:					#  else return(dividend);}
35	ret
361:
37	clrl	r2			#  return(dividend%divisor);
38	movl	4(fp),r3
39	ediv	8(fp),r2,r1,r0
40	ret
41
42/*
43 * aurem(dividendp, divisor) -- like urem but uses address of dividend.
44 *	Implements %= avoiding side effects in the dividend expression.
45 */
46ASENTRY(aurem, 0)
47	bitl	$0x80000000,8(fp)	#  if (divisor & 0x80000000){
48	jeql	1f
49	movl	*4(fp),r0
50	cmpl	8(fp),r0		#  if (divisor <= dividend )
51	jgtru	2f
52	subl2	8(fp),r0		#       return(dividend-divisor);
53					#  else return(dividend);}
54	jbr	2f
551:
56	clrl	r2			#  return(dividend%divisor);
57	movl	*4(fp),r3
58	ediv	8(fp),r2,r1,r0
592:
60	movl	r0,*4(fp)
61	ret
62