xref: /original-bsd/sys/tahoe/math/Kdivf.s (revision c8089215)
1/*-
2 * Copyright (c) 1985 The 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 * %sccs.include.redist.c%
9 *
10 *	@(#)Kdivf.s	7.1 (Berkeley) 12/06/90
11 */
12
13#include "../math/fp.h"
14#include "../math/Kfp.h"
15#include "../tahoe/SYS.h"
16
17#define	HIDDEN	23	 	# here we count from 0 not from 1 as in fp.h
18
19	.text
20ENTRY(Kdivf, R9|R8|R7|R6|R5|R4|R3|R2)
21	clrl	r1
22	clrl	r3		# r3 - sign: 0 for positive,1 for negative.
23	movl	4(fp),r0
24	jgeq	1f
25	movl	$1,r3
261:	movl	12(fp),r2
27	jgeq	2f
28	bbc	$0,r3,1f	# seconed operand is negative.
29	clrl	r3		# if first was negative, make result positive.
30	jmp	2f
311:	movl	$1,r3		# if first was positive, make result negative.
322:	andl2	$EXPMASK,r0	# compute first 'pure'exponent.
33	jeql	retz
34	shrl	$EXPSHIFT,r0,r0
35	subl2	$BIAS,r0
36	andl2	$EXPMASK,r2	# compute seconed 'pure'exponent.
37	jeql	retz2
38	shrl	$EXPSHIFT,r2,r2
39	subl2	$BIAS,r2
40	subl3	r2,r0,r2	# subtruct the exponents.
41	addl2	$BIAS,r2
42	jleq	underf
43				# normalization can make the exp. smaller.
44 #
45 #	We have the sign in r3,the exponent in r2,now is the time to
46 # 	perform the division...
47 #
48	# fetch dividend. (r0)
49	andl3	$(0!(EXPMASK | SIGNBIT)),4(fp),r0
50	orl2	$(0!CLEARHID),r0
51	clrl	r1
52
53	# fetch divisor : (r6)
54	andl3	$(0!(EXPMASK | SIGNBIT)),12(fp),r6
55	orl2	$(0!CLEARHID),r6
56
57	shll	$2,r6,r6	# make the divisor bigger so we will not
58				# get overflow at the divission.
59	ediv	r6,r0,r0,r7	# quo to r0, rem to r7
60	subl2	$6,r2		# to compensate for: normalization (-24),
61				# ediv (+32), shifting r6 (-2).
62
63over:
64	pushl	20(fp)
65	callf	$8,_Kfnorm	# we can use fnorm because we have data
66				# at r1 as well.(sfnorm takes care only
67				# of r0).
68sign:
691:	bbc	$0,r3,done
70	orl2	$SIGNBIT,r0
71done:	ret
72
73retz:
74	clrl	r0
75	ret
76
77retz2:	bbc	$31,12(fp),z_div
78	clrl	r0
79	ret
80
81underf:
82	orl2	$HFS_UNDF,*20(fp)
83	ret
84z_div:
85	orl2	$HFS_DIVZ,*20(fp)
86	ret
87