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