xref: /original-bsd/sys/tahoe/math/Kcvtld.s (revision f3c03cba)
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 *	@(#)Kcvtld.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	.text
18ENTRY(Kcvtld, R5|R4|R3|R2)
19	clrl	r4		# r4 - negative flag.
20	clrl	r2		# r2 - exponent.
21	movl	12(fp),r0	# fetch operand.
22	movl	r0,r5		# need another copy.
23	jeql	retzero		# return zero.
24	jgtr	positive
25	mnegl	r0,r0
26	jvs	retmin		# return minimum integer.
27	incl	r4		# remember it was negative.
28	movl	r0,r5		# remember the negated value.
29 #
30 #Compute exponent:
31 #
32positive:
33	ffs	r0,r1
34	incl 	r1
35	addl2	r1,r2
36	shrl	r1,r0,r0
37	jneq	positive	# look for more set bits.
38 #
39 #we have the exponent in r2.
40 #
41	movl	r5,r0		# r0,r1 will hold the resulting f.p. number.
42	clrl 	r1
43 #
44 #Shift the fraction part to its proper place:
45 #
46	subl3	r2,$HID_POS,r3
47	jlss	shiftr		# if less then zero we have to shift right.
48	shll	r3,r0,r0	# else we shift left.
49	jmp	shifted
50shiftr:
51	mnegl	r3,r3
52	shrq	r3,r0,r0
53shifted:
54	andl2	$CLEARHID,r0	# clear the hidden bit.
55	shal	$EXPSHIFT,r2,r2	# shift the exponent to its proper place.
56	orl2	$EXPSIGN,r2	# set the exponent sign bit(to bias it).
57	orl2	r2,r0		# combine exponent & fraction.
58	bbc	$0,r4,sign_ok	# do we  have to set the sign bit?
59	orl2	$SIGNBIT,r0	# yes...
60sign_ok:
61	ret
62
63retzero:
64	clrl 	r0
65	clrl	r1
66	ret
67
68retmin:
69 	movl	$0xd0000000,r0
70	clrl	r1
71	ret
72
73
74
75