xref: /original-bsd/lib/libc/tahoe/gen/udiv.s (revision ad93c43e)
1#ifdef LIBC_SCCS
2	.asciz	"@(#)udiv.s	1.2 (Berkeley/CCI) 12/11/87"
3#endif LIBC_SCCS
4
5/*
6 * Unsigned divide.
7 *
8 * udiv(dividend, divisor)
9 */
10#include "DEFS.h"
11
12ASENTRY(udiv, 0)
13	bitl	$0x80000000,8(fp)	#  if (divisor & 0x80000000){
14	jeql	1f
15	cmpl	8(fp),4(fp)		#  if (divisor > dividend )
16	jlequ	2f
17	clrl	r0			#      return(0);
18	ret
192:					#  else
20	movl	$1,r0			#      return(1);}
21	ret
221:
23	clrl	r2			#  return(dividend/divisor);
24	movl	4(fp),r3
25	ediv	8(fp),r2,r0,r1
26	ret
27
28/*
29 * audiv(dividendp, divisor) -- like udiv but uses address of dividend.
30 *	Implements /= avoiding side effects in the dividend expression.
31 */
32ASENTRY(audiv, 0)
33	bitl	$0x80000000,8(fp)	#  if (divisor & 0x80000000){
34	jeql	1f
35	cmpl	8(fp),*4(fp)		#  if (divisor > dividend )
36	jlequ	2f
37	clrl	r0			#      return(0);
38	jbr	3f
392:					#  else
40	movl	$1,r0			#      return(1);}
41	jbr	3f
421:
43	clrl	r2			#  return(dividend/divisor);
44	movl	*4(fp),r3
45	ediv	8(fp),r2,r0,r1
463:
47	movl	r0,*4(fp)
48	ret
49