xref: /csrg-svn/lib/libc/tahoe/fpe/fnorm.s (revision 61181)
136829Sbostic/*
2*61181Sbostic * Copyright (c) 1986, 1993
3*61181Sbostic *	The Regents of the University of California.  All rights reserved.
436829Sbostic *
536829Sbostic * This code is derived from software contributed to Berkeley by
636829Sbostic * Computer Consoles Inc.
736829Sbostic *
842637Sbostic * %sccs.include.redist.c%
936829Sbostic */
1029514Ssam
1136829Sbostic#if defined(SYSLIBC_SCCS) && !defined(lint)
12*61181Sbostic	.asciz "@(#)fnorm.s	8.1 (Berkeley) 06/04/93"
1336829Sbostic#endif /* SYSLIBC_SCCS and not lint */
1436829Sbostic
1529514Ssam#include <tahoemath/fp.h>
1629514Ssam#include "DEFS.h"
1729514Ssam
1829514SsamENTRY(fnorm, R2|R3|R4|R5|R6)
1929514Ssam	movl	r0,r4		# copy to temporary.
2029514Ssam	jneq	inr0
2129514Ssam	movl	r1,r5
2229514Ssam	clrl	r3		# r3 - pos of m.s.b
2329514Ssaminr1:	ffs	r5,r6
2429514Ssam	incl	r6
2529514Ssam	addl2	r6,r3
2629514Ssam	shrl	r6,r5,r5
2729514Ssam	jneq	inr1
2829514Ssam	cmpl	$0,r3
2929514Ssam	jeql	retzero
3029514Ssam	jmp	cmpshift
3129514Ssaminr0:	movl	$32,r3
3229514Ssaminr00:	ffs	r4,r6
3329514Ssam	incl	r6
3429514Ssam	addl2	r6,r3
3529514Ssam	shrl	r6,r4,r4
3629514Ssam	jneq	inr00
3729514Ssam
3829514Ssamcmpshift:
3929514Ssam				# compute the shift (r4).
4029514Ssam	subl3	r3,$HID_R0R1,r4
4129514Ssam	jlss	shiftr		# if less then zero we shift right.
4229514Ssam	shlq	r4,r0,r0	# else we shift left.
4329514Ssam	subl2	r4,r2		# uodate exponent.
4429514Ssam	jleq	underflow	# if less then 0 (biased) it is underflow.
4529514Ssam	jmp	combine		# go to combine exponent and fraction.
4629514Ssamshiftr:
4729514Ssam	mnegl	r4,r4
4829514Ssam	shrq	r4,r0,r0	# shift right.
4929514Ssam	addl2	r4,r2		# update exponent
5029514Ssam	cmpl	r2,$256
5129514Ssam	jgeq	overflow	# check for overflow.
5229514Ssamcombine:
5329514Ssam	andl2	$CLEARHID,r0	# clear the hidden bit.
5429514Ssam	shal	$EXPSHIFT,r2,r2	# shift the exponent to its proper place.
5529514Ssam	orl2	r2,r0
5629514Ssam	ret
5729514Ssam
5829514Ssamunderflow:
5929514Ssam	callf	$4,fpunder
6029514Ssam	ret
6129514Ssam
6229514Ssamoverflow:
6329514Ssam	callf 	$4,fpover
6429514Ssam	ret
6529514Ssamretzero:
6629514Ssam	clrl	r0
6729514Ssam	clrl	r1
6829514Ssam	ret
69