xref: /csrg-svn/lib/libc/tahoe/fpe/divd.s (revision 36829)
1/*
2 * Copyright (c) 1986 Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Computer Consoles Inc.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the University of California, Berkeley.  The name of the
14 * University may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 */
20
21#if defined(SYSLIBC_SCCS) && !defined(lint)
22	.asciz "@(#)divd.s	1.2 (Berkeley) 02/17/89"
23#endif /* SYSLIBC_SCCS and not lint */
24
25#include <tahoemath/fp.h>
26#include "DEFS.h"
27
28#define	HIDDEN	23	/* here we count from 0 not from 1 as in fp.h */
29
30XENTRY(divd, R2|R3|R4|R5|R6|R7|R8|R9)
31	clrl	r3		# r3 - sign: 0 for positive,1 for negative.
32	movl	4(fp),r0
33	jgeq	1f
34	movl	$1,r3
351:	movl	12(fp),r2
36	jgeq	2f
37	bbc	$0,r3,1f	# seconed operand is negative.
38	clrl	r3		# if first was negative, make result positive.
39	jmp	2f
401:	movl	$1,r3		# if first was positive, make result negative.
412:	andl2	$EXPMASK,r0	# compute first 'pure'exponent.
42	jeql	is_res1
43	shrl	$EXPSHIFT,r0,r0
44	subl2	$BIAS,r0
45	andl2	$EXPMASK,r2	# compute seconed 'pure'exponent.
46	jeql	is_res2
47	shrl	$EXPSHIFT,r2,r2
48	subl2	$BIAS,r2
49	subl3	r2,r0,r2	# subtruct the exponents.
50	addl2	$BIAS,r2
51	jleq	underf
52				# normalization can make the exp. smaller.
53 #
54 #	We have the sign in r3,the exponent in r2,now is the time to
55 # 	perform the division...
56 #
57	# fetch dividend. (r4,r5)
58	andl3	$(0!(EXPMASK | SIGNBIT)),4(fp),r4
59	orl2	$(0!CLEARHID),r4
60	movl	8(fp),r5
61
62	# fetch divisor : (r6,r7)
63	andl3	$(0!(EXPMASK | SIGNBIT)),12(fp),r6
64	orl2	$(0!CLEARHID),r6
65	movl	16(fp),r7
66
67	movl	$0,r0		# init r0,r1 to be zeros
68	movl	$0,r1
69	movl	$(0!CLEARHID),r8# r8 first bit to set (if).
70	shll	$1,r8,r8	# to have one more bit,because we might
71				# have to shift left to normelize.
72	movl	$0,r9
73
742:
75	subl2	r7,r5
76	sbwc	r6,r4
77	jgeq	1f
78	addl2	r7,r5
79	adwc	r6,r4
80	shlq	$1,r4,r4
81	shrq	$1,r8,r8
82	jeql	over
83	jmp	2b
841:
85	orl2	r8,r0
86	orl2	r9,r1
87	shlq	$1,r4,r4
88	shrq	$1,r8,r8
89	jneq	2b
90
91over:
92	callf	$4,fnorm
93sign:
941:	bbc	$0,r3,done
95	orl2	$SIGNBIT,r0
96done:	ret
97
98is_res1:
99	bbc 	$31,4(fp),retz
100	callf	$4,fpresop
101	ret
102is_res2:
103	bbc 	$31,12(fp),z_div
104	callf	$4,fpresop
105	ret
106retz:
107	  clrl	r0
108	  clrl	r1
109	  ret
110underf:
111	callf	$4,fpunder
112	ret
113z_div:
114	callf	$4,fpzdiv
115	ret
116