xref: /csrg-svn/lib/libc/tahoe/gen/modf.s (revision 30512)
129696Ssam#ifdef LIBC_SCCS
2*30512Ssam	.asciz	"@(#)modf.s	1.2 (Berkeley) 02/16/87"
329696Ssam#endif LIBC_SCCS
429696Ssam
529696Ssam/*
629696Ssam * double modf (value, iptr)
729696Ssam * double value, *iptr;
829696Ssam *
929696Ssam * Modf returns the fractional part of "value",
1029696Ssam * and stores the integer part indirectly through "iptr".
1129696Ssam *
1229696Ssam * This version uses floating point (look in ../fpe for
1329696Ssam * a much slower integer version).
1429696Ssam */
1529696Ssam
1629696Ssam#include "DEFS.h"
1729696Ssam
1829696SsamENTRY(modf, 0)
19*30512Ssam	ldd	4(fp)		# value
20*30512Ssam	cvdl	r2		# integerize
21*30512Ssam	bvs	1f		# did integer part overflow?
22*30512Ssam	cvld	r2		# integer part
23*30512Ssam	std	r0
24*30512Ssam	std	*12(fp)		# *iptr = r2
2529696Ssam	ldd	4(fp)
26*30512Ssam	subd	r0		# value-(int)value
27*30512Ssam	std	r0		# return fraction
2829696Ssam	ret
2929696Ssam1:
30*30512Ssam	/*
31*30512Ssam	 * If the integer portion overflowed, mask out the fractional
32*30512Ssam	 * bits in the double word instead of cvdl-ing.
33*30512Ssam	 */
3429696Ssam	ldd	4(fp)
35*30512Ssam	std	r0		# (r0,r1) = value
36*30512Ssam	shrl	$23,r0,r2	# extract sign,exponent of value
37*30512Ssam	andl2	$255,r2		# exponent
38*30512Ssam	subl2	$152,r2		# e-152
39*30512Ssam	/*
40*30512Ssam	 * If it overflowed then value>=2^31 and e>=160
41*30512Ssam	 * so we mask only r1 (low bits of fraction), not r0
42*30512Ssam	 */
43*30512Ssam	mnegl	$1,r3
44*30512Ssam	shrl	r2,r3,r3	# -1>>(e-152) is neg mask to clear fraction
45*30512Ssam	mcoml	r3,r3		# complement mask
46*30512Ssam	andl2	r3,r1		# mask off truly fractional bits from fraction
47*30512Ssam	ldd	r0		# now (r0,r1) = integerized value
48*30512Ssam	std	*12(fp)		# *iptr = integerized
49*30512Ssam	ldd	4(fp)
5029696Ssam	subd	r0
51*30512Ssam	std	r0		# return fraction
5229696Ssam	ret
53