xref: /csrg-svn/lib/libc/vax/gen/udiv.s (revision 61225)
147836Sbostic/*-
2*61225Sbostic * Copyright (c) 1991, 1993
3*61225Sbostic *	The Regents of the University of California.  All rights reserved.
447836Sbostic *
547993Sdonn * This code is derived from software contributed to Berkeley by
647993Sdonn * Donn Seeley at UUNET Technologies, Inc.
747993Sdonn *
847836Sbostic * %sccs.include.redist.c%
947836Sbostic */
1013420Sroot
1147836Sbostic#if defined(LIBC_SCCS) && !defined(lint)
12*61225Sbostic	.asciz "@(#)udiv.s	8.1 (Berkeley) 06/04/93"
1347836Sbostic#endif /* LIBC_SCCS and not lint */
1447836Sbostic
1513420Sroot/*
1647836Sbostic * Unsigned division, PCC flavor.
1747836Sbostic * udiv() takes an ordinary dividend/divisor pair;
1847836Sbostic * audiv() takes a pointer to a dividend and an ordinary divisor.
1913420Sroot */
2013420Sroot
2113420Sroot#include "DEFS.h"
2213420Sroot
2347836Sbostic#define	DIVIDEND	4(ap)
2447836Sbostic#define	DIVISOR		8(ap)
2547836Sbostic
2647836SbosticASENTRY(udiv,0)
2747836Sbostic	movl	DIVISOR,r2
2847836Sbostic	jlss	Leasy		# big divisor: settle by comparison
2947836Sbostic	movl	DIVIDEND,r0
3047836Sbostic	jlss	Lhard		# big dividend: extended division
3147836Sbostic	divl2	r2,r0		# small divisor and dividend: signed division
3213420Sroot	ret
3347836SbosticLhard:
3447836Sbostic	clrl	r1
3547836Sbostic	ediv	r2,r0,r0,r1
3613420Sroot	ret
3747836SbosticLeasy:
3847836Sbostic	cmpl	DIVIDEND,r2
3947836Sbostic	jgequ	Lone		# if dividend is as big or bigger, return 1
4047836Sbostic	clrl	r0		# else return 0
4113420Sroot	ret
4247836SbosticLone:
4347836Sbostic	movl	$1,r0
4447836Sbostic	ret
4517718Sralph
4647836SbosticASENTRY(audiv,0)
4747864Sbostic	movl	DIVIDEND,r3
4847836Sbostic	movl	DIVISOR,r2
4947838Sbostic	jlss	La_easy		# big divisor: settle by comparison
5047836Sbostic	movl	(r3),r0
5147838Sbostic	jlss	La_hard		# big dividend: extended division
5247838Sbostic	divl2	r2,r0		# small divisor and dividend: signed division
5347838Sbostic	movl	r0,(r3)		# leave the value of the assignment in r0
5417718Sralph	ret
5547838SbosticLa_hard:
5647836Sbostic	clrl	r1
5747838Sbostic	ediv	r2,r0,r0,r1
5847838Sbostic	movl	r0,(r3)
5917718Sralph	ret
6047838SbosticLa_easy:
6147836Sbostic	cmpl	(r3),r2
6247838Sbostic	jgequ	La_one		# if dividend is as big or bigger, return 1
6347838Sbostic	clrl	r0		# else return 0
6447838Sbostic	clrl	(r3)
6517718Sralph	ret
6647838SbosticLa_one:
6747838Sbostic	movl	$1,r0
6847838Sbostic	movl	r0,(r3)
6947836Sbostic	ret
70