xref: /original-bsd/lib/libc/tahoe/fpe/divd.s (revision c3e32dec)
1/*
2 * Copyright (c) 1986, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Computer Consoles Inc.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#if defined(SYSLIBC_SCCS) && !defined(lint)
12	.asciz "@(#)divd.s	8.1 (Berkeley) 06/04/93"
13#endif /* SYSLIBC_SCCS and not lint */
14
15#include <tahoemath/fp.h>
16#include "DEFS.h"
17
18#define	HIDDEN	23	/* here we count from 0 not from 1 as in fp.h */
19
20XENTRY(divd, R2|R3|R4|R5|R6|R7|R8|R9)
21	clrl	r3		# r3 - sign: 0 for positive,1 for negative.
22	movl	4(fp),r0
23	jgeq	1f
24	movl	$1,r3
251:	movl	12(fp),r2
26	jgeq	2f
27	bbc	$0,r3,1f	# seconed operand is negative.
28	clrl	r3		# if first was negative, make result positive.
29	jmp	2f
301:	movl	$1,r3		# if first was positive, make result negative.
312:	andl2	$EXPMASK,r0	# compute first 'pure'exponent.
32	jeql	is_res1
33	shrl	$EXPSHIFT,r0,r0
34	subl2	$BIAS,r0
35	andl2	$EXPMASK,r2	# compute seconed 'pure'exponent.
36	jeql	is_res2
37	shrl	$EXPSHIFT,r2,r2
38	subl2	$BIAS,r2
39	subl3	r2,r0,r2	# subtruct the exponents.
40	addl2	$BIAS,r2
41	jleq	underf
42				# normalization can make the exp. smaller.
43 #
44 #	We have the sign in r3,the exponent in r2,now is the time to
45 # 	perform the division...
46 #
47	# fetch dividend. (r4,r5)
48	andl3	$(0!(EXPMASK | SIGNBIT)),4(fp),r4
49	orl2	$(0!CLEARHID),r4
50	movl	8(fp),r5
51
52	# fetch divisor : (r6,r7)
53	andl3	$(0!(EXPMASK | SIGNBIT)),12(fp),r6
54	orl2	$(0!CLEARHID),r6
55	movl	16(fp),r7
56
57	movl	$0,r0		# init r0,r1 to be zeros
58	movl	$0,r1
59	movl	$(0!CLEARHID),r8# r8 first bit to set (if).
60	shll	$1,r8,r8	# to have one more bit,because we might
61				# have to shift left to normelize.
62	movl	$0,r9
63
642:
65	subl2	r7,r5
66	sbwc	r6,r4
67	jgeq	1f
68	addl2	r7,r5
69	adwc	r6,r4
70	shlq	$1,r4,r4
71	shrq	$1,r8,r8
72	jeql	over
73	jmp	2b
741:
75	orl2	r8,r0
76	orl2	r9,r1
77	shlq	$1,r4,r4
78	shrq	$1,r8,r8
79	jneq	2b
80
81over:
82	callf	$4,fnorm
83sign:
841:	bbc	$0,r3,done
85	orl2	$SIGNBIT,r0
86done:	ret
87
88is_res1:
89	bbc 	$31,4(fp),retz
90	callf	$4,fpresop
91	ret
92is_res2:
93	bbc 	$31,12(fp),z_div
94	callf	$4,fpresop
95	ret
96retz:
97	  clrl	r0
98	  clrl	r1
99	  ret
100underf:
101	callf	$4,fpunder
102	ret
103z_div:
104	callf	$4,fpzdiv
105	ret
106