xref: /original-bsd/lib/libc/tahoe/fpe/cvtud.s (revision 540a81df)
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 * %sccs.include.redist.c%
9 */
10
11#if defined(SYSLIBC_SCCS) && !defined(lint)
12	.asciz "@(#)cvtud.s	1.3 (Berkeley) 06/01/90"
13#endif /* SYSLIBC_SCCS and not lint */
14
15#include <tahoemath/fp.h>
16#include "DEFS.h"
17
18XENTRY(cvtud, R2|R3|R4|R5)
19 #
20 #	Some initializations:
21 #
22	clrl	r2		# r2 - exponent.
23	movl	4(fp),r0	# fetch operand.
24	jeql	retzero		# return zero.
25 #
26 #	Compute exponent:
27 #
28positive:
29	ffs	r0,r1
30	incl 	r1
31	addl2	r1,r2
32	shrl	r1,r0,r0
33	jneq	positive	# look for more set bits.
34 #
35 # we have the exponent in r2.
36 #
37	movl	4(fp),r0	# r0,r1 will hold the resulting f.p. number.
38	clrl 	r1
39 #
40 #	Shift the fraction part to its proper place:
41 #
42	subl3	r2,$HID_POS,r3
43	jlss	shiftr		# if less then zero we have to shift right.
44	shll	r3,r0,r0	# else we shift left.
45	jmp	shifted
46shiftr:
47	mnegl	r3,r3
48	shrq	r3,r0,r0
49shifted:
50	andl2	$CLEARHID,r0	# clear the hidden bit.
51	shal	$EXPSHIFT,r2,r2	# shift the exponent to its proper place.
52	orl2	$EXPSIGN,r2	# set the exponent sign bit(to bias it).
53	orl2	r2,r0		# combine exponent & fraction.
54sign_ok:
55	ret
56
57retzero:
58	clrl 	r0
59	clrl	r1
60	ret
61
62
63