xref: /csrg-svn/lib/libc/sparc/gen/fixunsdfsi.s (revision 61168)
154386Storek/*
2*61168Sbostic * Copyright (c) 1992, 1993
3*61168Sbostic *	The Regents of the University of California.  All rights reserved.
454386Storek *
554386Storek * This software was developed by the Computer Systems Engineering group
654386Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
754386Storek * contributed to Berkeley.
854386Storek *
954386Storek * %sccs.include.redist.c%
1054386Storek *
1154386Storek * from: $Header: fixunsdfsi.s,v 1.3 91/10/08 00:03:15 torek Exp $
1254386Storek */
1354386Storek
1454386Storek#if defined(LIBC_SCCS) && !defined(lint)
15*61168Sbostic	.asciz "@(#)fixunsdfsi.s	8.1 (Berkeley) 06/04/93"
1654386Storek#endif /* LIBC_SCCS and not lint */
1754386Storek
1854386Storek/*
1954386Storek * Convert double to unsigned integer (for gcc).
2054386Storek *
2154386Storek * I have made the output for NaN agree with the Sun compiler, not
2254386Storek * that it really matters, by using `fbul,a'.
2354386Storek */
2454386Storek
2554386Storek#include "DEFS.h"
2654386Storek
2754386Storek	.align	8
2854386StorekLbig:
2954386Storek	.word	0x41e00000		! .double 0r2147483648.0e+00
3054386Storek	.word	0			! (who me, not trust the assembler?)
3154386Storek
3254386StorekENTRY(__fixunsdfsi)
3354386Storek	sub	%sp, 8, %sp
3454386Storek	std	%o0, [%sp + 64]		! get argument into fpu reg
3554386Storek	ldd	[%sp + 64], %f0
3654386Storek	sethi	%hi(Lbig), %g1
3754386Storek	ldd	[%g1 + %lo(Lbig)], %f2
3854386Storek	fcmped	%f0, %f2		! d < 2^31, or NaN, or -Inf?
3954386Storek	nop				! (fpop2 delay)
4054386Storek	fbul,a	1f			! if so, use fdtoi to convert to int
4154386Storek	fdtoi	%f0, %f0		!        (this includes negatives!)
4254386Storek
4354386Storek	! d does not fit in an int, so subtract 2^31, convert,
4454386Storek	! and add 2^31 again (sigh).  Just hope the intermediate
4554386Storek	! fits (if not, the result is undefined anyway).
4654386Storek
4754386Storek	fsubd	%f0, %f2, %f0		! d -= 2^31
4854386Storek	fdtoi	%f0, %f0		! convert to int
4954386Storek	st	%f0, [%sp + 64]		! move into return reg
5054386Storek	ld	[%sp + 64], %o0
5154386Storek	sethi	%hi(0x80000000), %o1
5254386Storek	add	%o0, %o1, %o0		! add 2^31
5354386Storek	retl
5454386Storek	add	%sp, 8, %sp
5554386Storek
5654386Storek1:
5754386Storek	st	%f0, [%sp + 64]		! return result
5854386Storek	ld	[%sp + 64], %o0
5954386Storek	retl
6054386Storek	add	%sp, 8, %sp
61