xref: /original-bsd/lib/libc/tahoe/fpe/cvtuf.s (revision 549425d7)
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 "@(#)cvtuf.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
28XENTRY(cvtuf, R2|R3|R4|R5)
29 #
30 #	Some initializations:
31 #
32	clrl	r1
33	clrl	r2		# r2 - exponent.
34	movl	4(fp),r0	# fetch operand.
35	jeql	retzero		# return zero.
36 #
37 #	Compute exponent:
38 #
39positive:
40	ffs	r0,r1
41	incl 	r1
42	addl2	r1,r2
43	shrl	r1,r0,r0
44	jneq	positive	# look for more set bits.
45 #
46 # we have the exponent in r2.
47 #
48	movl	4(fp),r0	# r0 will hold the resulting f.p. number.
49 #
50 #	Shift the fraction part to its proper place:
51 #
52	subl3	r2,$HID_POS,r3
53	jlss	shiftr		# if less then zero we have to shift right.
54	shll	r3,r0,r0	# else we shift left.
55	jmp	shifted
56shiftr:
57	mnegl	r3,r3
58	shrl	r3,r0,r0
59shifted:
60	andl2	$CLEARHID,r0	# clear the hidden bit.
61	shal	$EXPSHIFT,r2,r2	# shift the exponent to its proper place.
62	orl2	$EXPSIGN,r2	# set the exponent sign bit(to bias it).
63	orl2	r2,r0		# combine exponent & fraction.
64sign_ok:
65	ret
66
67retzero:
68	clrl 	r0
69	ret
70
71
72