xref: /csrg-svn/lib/libc/tahoe/gen/udiv.s (revision 61183)
134438Sbostic/*
2*61183Sbostic * Copyright (c) 1988, 1993
3*61183Sbostic *	The Regents of the University of California.  All rights reserved.
434438Sbostic *
534438Sbostic * This code is derived from software contributed to Berkeley by
634438Sbostic * Computer Consoles Inc.
746166Sbostic *
846166Sbostic * %sccs.include.redist.c%
934438Sbostic */
1029702Ssam
1134438Sbostic#if defined(LIBC_SCCS) && !defined(lint)
12*61183Sbostic	.asciz "@(#)udiv.s	8.1 (Berkeley) 06/04/93"
1334438Sbostic#endif /* LIBC_SCCS and not lint */
1434438Sbostic
1529702Ssam/*
1629702Ssam * Unsigned divide.
1729702Ssam *
1829702Ssam * udiv(dividend, divisor)
1929702Ssam */
2029702Ssam#include "DEFS.h"
2129702Ssam
2229702SsamASENTRY(udiv, 0)
2329702Ssam	bitl	$0x80000000,8(fp)	#  if (divisor & 0x80000000){
2429702Ssam	jeql	1f
2529702Ssam	cmpl	8(fp),4(fp)		#  if (divisor > dividend )
2629702Ssam	jlequ	2f
2729702Ssam	clrl	r0			#      return(0);
2829702Ssam	ret
2929702Ssam2:					#  else
3029702Ssam	movl	$1,r0			#      return(1);}
3129702Ssam	ret
3229702Ssam1:
3332977Sdonn	clrl	r2			#  return(dividend/divisor);
3432977Sdonn	movl	4(fp),r3
3532977Sdonn	ediv	8(fp),r2,r0,r1
3629702Ssam	ret
3732977Sdonn
3832977Sdonn/*
3932977Sdonn * audiv(dividendp, divisor) -- like udiv but uses address of dividend.
4032977Sdonn *	Implements /= avoiding side effects in the dividend expression.
4132977Sdonn */
4232977SdonnASENTRY(audiv, 0)
4332977Sdonn	bitl	$0x80000000,8(fp)	#  if (divisor & 0x80000000){
4432977Sdonn	jeql	1f
4532977Sdonn	cmpl	8(fp),*4(fp)		#  if (divisor > dividend )
4632977Sdonn	jlequ	2f
4732977Sdonn	clrl	r0			#      return(0);
4832977Sdonn	jbr	3f
4932977Sdonn2:					#  else
5032977Sdonn	movl	$1,r0			#      return(1);}
5132977Sdonn	jbr	3f
5232977Sdonn1:
5332977Sdonn	clrl	r2			#  return(dividend/divisor);
5432977Sdonn	movl	*4(fp),r3
5532977Sdonn	ediv	8(fp),r2,r0,r1
5632977Sdonn3:
5732977Sdonn	movl	r0,*4(fp)
5832977Sdonn	ret
59