xref: /original-bsd/lib/libc/tahoe/fpe/sfnorm.s (revision 5e36add1)
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 "@(#)sfnorm.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(sfnorm, R2|R3|R4|R5|R6)
19	clrl	r1
20	movl	r0,r4		/* copy to temporary. */
21	jeql	retzero
22	clrl	r3		/* r3 - pos of m.s.b */
23inr00:	ffs	r4,r6
24	incl	r6
25	addl2	r6,r3
26	shrl	r6,r4,r4
27	jneq	inr00
28
29cmpshift:
30				/* compute the shift (r4). */
31	subl3	r3,$HID_POS,r4
32	jlss	shiftr		/* if less then zero we shift right. */
33	shll	r4,r0,r0	/* else we shift left. */
34	subl2	r4,r2		/* uodate exponent. */
35	jleq	underflow	/* if less then 0 (biased) it is underflow. */
36	jmp	combine		/* go to combine exponent and fraction. */
37shiftr:
38	mnegl	r4,r4
39	shrl	r4,r0,r0	/* shift right. */
40	addl2	r4,r2		/* update exponent */
41	cmpl	r2,$256
42	jgeq	overflow	/* check for overflow. */
43combine:
44	andl2	$CLEARHID,r0	/* clear the hidden bit. */
45	shal	$EXPSHIFT,r2,r2	/* shift the exponent to its proper place. */
46	orl2	r2,r0
47	ret
48
49underflow:
50	callf	$4,sfpunder
51	ret
52
53overflow:
54	callf 	$4,sfpover
55	ret
56retzero:
57	clrl	r0
58	ret
59