xref: /csrg-svn/lib/libc/vax/gen/udiv.s (revision 47836)
1*47836Sbostic/*-
2*47836Sbostic * Copyright (c) 1991 The Regents of the University of California.
3*47836Sbostic * All rights reserved.
4*47836Sbostic *
5*47836Sbostic * %sccs.include.redist.c%
6*47836Sbostic */
713420Sroot
8*47836Sbostic#if defined(LIBC_SCCS) && !defined(lint)
9*47836Sbostic	.asciz "@(#)udiv.s	5.3 (Berkeley) 04/08/91"
10*47836Sbostic#endif /* LIBC_SCCS and not lint */
11*47836Sbostic
1213420Sroot/*
13*47836Sbostic * Unsigned division, PCC flavor.
14*47836Sbostic * udiv() takes an ordinary dividend/divisor pair;
15*47836Sbostic * audiv() takes a pointer to a dividend and an ordinary divisor.
1613420Sroot */
1713420Sroot
1813420Sroot#include "DEFS.h"
1913420Sroot
20*47836Sbostic#define	DIVIDEND	4(ap)
21*47836Sbostic#define	DIVISOR		8(ap)
22*47836Sbostic
23*47836SbosticASENTRY(udiv,0)
24*47836Sbostic	movl	DIVISOR,r2
25*47836Sbostic	jlss	Leasy		# big divisor: settle by comparison
26*47836Sbostic	movl	DIVIDEND,r0
27*47836Sbostic	jlss	Lhard		# big dividend: extended division
28*47836Sbostic	divl2	r2,r0		# small divisor and dividend: signed division
2913420Sroot	ret
30*47836SbosticLhard:
31*47836Sbostic	clrl	r1
32*47836Sbostic	ediv	r2,r0,r0,r1
3313420Sroot	ret
34*47836SbosticLeasy:
35*47836Sbostic	cmpl	DIVIDEND,r2
36*47836Sbostic	jgequ	Lone		# if dividend is as big or bigger, return 1
37*47836Sbostic	clrl	r0		# else return 0
3813420Sroot	ret
39*47836SbosticLone:
40*47836Sbostic	movl	$1,r0
41*47836Sbostic	ret
4217718Sralph
43*47836SbosticASENTRY(audiv,0)
44*47836Sbostic	movl	DIVISOR,r2
45*47836Sbostic	jlss	Laeasy		# big divisor: settle by comparison
46*47836Sbostic	movl	DIVIDEND,r3
47*47836Sbostic	movl	(r3),r0
48*47836Sbostic	jlss	Lahard		# big dividend: extended division
49*47836Sbostic	divl3	r2,r0,(r3)	# small divisor and dividend: signed division
5017718Sralph	ret
51*47836SbosticLahard:
52*47836Sbostic	clrl	r1
53*47836Sbostic	ediv	r2,r0,(r3),r1
5417718Sralph	ret
55*47836SbosticLaeasy:
56*47836Sbostic	cmpl	(r3),r2
57*47836Sbostic	jgequ	Laone		# if dividend is as big or bigger, store 1
58*47836Sbostic	clrl	(r3)		# else store 0
5917718Sralph	ret
60*47836SbosticLaone:
61*47836Sbostic	movl	$1,(r3)
62*47836Sbostic	ret
63