xref: /csrg-svn/lib/libc/tahoe/fpe/cvtld.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 */
1029511Ssam
1136829Sbostic#if defined(SYSLIBC_SCCS) && !defined(lint)
12*61181Sbostic	.asciz "@(#)cvtld.s	8.1 (Berkeley) 06/04/93"
1336829Sbostic#endif /* SYSLIBC_SCCS and not lint */
1436829Sbostic
1529511Ssam#include <tahoemath/fp.h>
1629511Ssam#include "DEFS.h"
1729511Ssam
1829511SsamXENTRY(cvtld, R2|R3|R4|R5)
1929511Ssam #
2029511Ssam #Some initializations:
2129511Ssam #
2229511Ssam	clrl	r4		# r4 - negative flag.
2329511Ssam	clrl	r2		# r2 - exponent.
2429511Ssam	movl	4(fp),r0	# fetch operand.
2529511Ssam	movl	r0,r5		# need another copy.
2629511Ssam	jeql	retzero		# return zero.
2729511Ssam	jgtr	positive
2829511Ssam	mnegl	r0,r0
2929511Ssam	jvs	retmin		# return minimum integer.
3029511Ssam	incl	r4		# remember it was negative.
3129511Ssam	movl	r0,r5		# remember the negated value.
3229511Ssam #
3329511Ssam #Compute exponent:
3429511Ssam #
3529511Ssampositive:
3629511Ssam	ffs	r0,r1
3729511Ssam	incl 	r1
3829511Ssam	addl2	r1,r2
3929511Ssam	shrl	r1,r0,r0
4029511Ssam	jneq	positive	# look for more set bits.
4129511Ssam #
4229511Ssam #we have the exponent in r2.
4329511Ssam #
4429511Ssam	movl	r5,r0		# r0,r1 will hold the resulting f.p. number.
4529511Ssam	clrl 	r1
4629511Ssam #
4729511Ssam #Shift the fraction part to its proper place:
4829511Ssam #
4929511Ssam	subl3	r2,$HID_POS,r3
5029511Ssam	jlss	shiftr		# if less then zero we have to shift right.
5129511Ssam	shll	r3,r0,r0	# else we shift left.
5229511Ssam	jmp	shifted
5329511Ssamshiftr:
5429511Ssam	mnegl	r3,r3
5529511Ssam	shrq	r3,r0,r0
5629511Ssamshifted:
5729511Ssam	andl2	$CLEARHID,r0	# clear the hidden bit.
5829511Ssam	shal	$EXPSHIFT,r2,r2	# shift the exponent to its proper place.
5929511Ssam	orl2	$EXPSIGN,r2	# set the exponent sign bit(to bias it).
6029511Ssam	orl2	r2,r0		# combine exponent & fraction.
6129511Ssam	bbc	$0,r4,sign_ok	# do we  have to set the sign bit?
6229511Ssam	orl2	$SIGNBIT,r0	# yes...
6329511Ssamsign_ok:
6429511Ssam	ret
6529511Ssam
6629511Ssamretzero:
6729511Ssam	clrl 	r0
6829511Ssam	clrl	r1
6929511Ssam	ret
7029511Ssam
7129511Ssamretmin:
7229511Ssam 	movl	$0xd0000000,r0
7329511Ssam	clrl	r1
7429511Ssam	ret
7529511Ssam
7629511Ssam
7729511Ssam
78