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