xref: /csrg-svn/lib/libc/tahoe/fpe/cvtud.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 */
1029512Ssam
1136829Sbostic#if defined(SYSLIBC_SCCS) && !defined(lint)
12*61181Sbostic	.asciz "@(#)cvtud.s	8.1 (Berkeley) 06/04/93"
1336829Sbostic#endif /* SYSLIBC_SCCS and not lint */
1436829Sbostic
1529512Ssam#include <tahoemath/fp.h>
1629512Ssam#include "DEFS.h"
1729512Ssam
1829512SsamXENTRY(cvtud, R2|R3|R4|R5)
1929512Ssam #
2029512Ssam #	Some initializations:
2129512Ssam #
2229512Ssam	clrl	r2		# r2 - exponent.
2329512Ssam	movl	4(fp),r0	# fetch operand.
2429512Ssam	jeql	retzero		# return zero.
2529512Ssam #
2629512Ssam #	Compute exponent:
2729512Ssam #
2829512Ssampositive:
2929512Ssam	ffs	r0,r1
3029512Ssam	incl 	r1
3129512Ssam	addl2	r1,r2
3229512Ssam	shrl	r1,r0,r0
3329512Ssam	jneq	positive	# look for more set bits.
3429512Ssam #
3529512Ssam # we have the exponent in r2.
3629512Ssam #
3729512Ssam	movl	4(fp),r0	# r0,r1 will hold the resulting f.p. number.
3829512Ssam	clrl 	r1
3929512Ssam #
4029512Ssam #	Shift the fraction part to its proper place:
4129512Ssam #
4229512Ssam	subl3	r2,$HID_POS,r3
4329512Ssam	jlss	shiftr		# if less then zero we have to shift right.
4429512Ssam	shll	r3,r0,r0	# else we shift left.
4529512Ssam	jmp	shifted
4629512Ssamshiftr:
4729512Ssam	mnegl	r3,r3
4829512Ssam	shrq	r3,r0,r0
4929512Ssamshifted:
5029512Ssam	andl2	$CLEARHID,r0	# clear the hidden bit.
5129512Ssam	shal	$EXPSHIFT,r2,r2	# shift the exponent to its proper place.
5229512Ssam	orl2	$EXPSIGN,r2	# set the exponent sign bit(to bias it).
5329512Ssam	orl2	r2,r0		# combine exponent & fraction.
5429512Ssamsign_ok:
5529512Ssam	ret
5629512Ssam
5729512Ssamretzero:
5829512Ssam	clrl 	r0
5929512Ssam	clrl	r1
6029512Ssam	ret
6129512Ssam
6229512Ssam
63