fixunsdfsi.S revision 86535
186535Sjake/*
286535Sjake * Copyright (c) 1992, 1993
386535Sjake *	The Regents of the University of California.  All rights reserved.
486535Sjake *
586535Sjake * This software was developed by the Computer Systems Engineering group
686535Sjake * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
786535Sjake * contributed to Berkeley.
886535Sjake *
986535Sjake * Redistribution and use in source and binary forms, with or without
1086535Sjake * modification, are permitted provided that the following conditions
1186535Sjake * are met:
1286535Sjake * 1. Redistributions of source code must retain the above copyright
1386535Sjake *    notice, this list of conditions and the following disclaimer.
1486535Sjake * 2. Redistributions in binary form must reproduce the above copyright
1586535Sjake *    notice, this list of conditions and the following disclaimer in the
1686535Sjake *    documentation and/or other materials provided with the distribution.
1786535Sjake * 3. All advertising materials mentioning features or use of this software
1886535Sjake *    must display the following acknowledgement:
1986535Sjake *	This product includes software developed by the University of
2086535Sjake *	California, Berkeley and its contributors.
2186535Sjake * 4. Neither the name of the University nor the names of its contributors
2286535Sjake *    may be used to endorse or promote products derived from this software
2386535Sjake *    without specific prior written permission.
2486535Sjake *
2586535Sjake * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2686535Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2786535Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2886535Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2986535Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3086535Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3186535Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3286535Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3386535Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3486535Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3586535Sjake * SUCH DAMAGE.
3686535Sjake *
3786535Sjake * from: Header: fixunsdfsi.s,v 1.3 91/10/08 00:03:15 torek Exp
3886535Sjake */
3986535Sjake
4086535Sjake#include <machine/asm.h>
4186535Sjake
4286535Sjake#if defined(LIBC_SCCS) && !defined(lint)
4386535Sjake#if 0
4486535Sjake	.asciz "@(#)fixunsdfsi.s	8.1 (Berkeley) 6/4/93"
4586535Sjake#else
4686535Sjake	RCSID("$NetBSD: fixunsdfsi.S,v 1.3 2000/07/25 04:26:12 mycroft Exp $")
4786535Sjake#endif
4886535Sjake#endif /* LIBC_SCCS and not lint */
4986535Sjake
5086535Sjake#if defined(SYSLIBC_RCS) && !defined(lint)
5186535Sjake	.text
5286535Sjake	.asciz "$FreeBSD: head/lib/libc/sparc64/gen/fixunsdfsi.S 86535 2001-11-18 04:40:30Z jake $"
5386535Sjake#endif /* SYSLIBC_RCS and not lint */
5486535Sjake
5586535Sjake/*
5686535Sjake * Convert double to unsigned integer (for gcc).
5786535Sjake *
5886535Sjake * I have made the output for NaN agree with the Sun compiler, not
5986535Sjake * that it really matters, by using `fbul,a'.
6086535Sjake */
6186535Sjake
6286535Sjake
6386535Sjake	.align	8
6486535Sjake.Lbig:
6586535Sjake	.word	0x43e00000		! .double 2^63
6686535Sjake	.word	0			! (who me, not trust the assembler?)
6786535Sjake
6886535Sjake/*
6986535Sjake * Same as above but to unsigned long
7086535Sjake */
7186535SjakeENTRY(__dtoul)
7286535Sjake	sub	%sp, 16, %sp
7386535Sjake	std	%f2, [%sp + 64 + SPOFF + 8]
7486535Sjake	sethi	%hi(.Lbig), %g1
7586535Sjake	ldd	[%g1 + %lo(.Lbig)], %f2
7686535Sjake	fcmped	%f0, %f2		! d < 2^63, or NaN, or -Inf?
7786535Sjake	nop				! (fpop2 delay)
7886535Sjake	fbul,a	1f			! if so, use fdtoi to convert to int
7986535Sjake	 fdtox	%f0, %f0		!        (this includes negatives!)
8086535Sjake
8186535Sjake	! d does not fit in an int, so subtract 2^63, convert,
8286535Sjake	! and add 2^63 again (sigh).  Just hope the intermediate
8386535Sjake	! fits (if not, the result is undefined anyway).
8486535Sjake
8586535Sjake	fsubd	%f0, %f2, %f0		! d -= 2^63
8686535Sjake	fdtox	%f0, %f0		! convert to int
8786535Sjake	std	%f0, [%sp + 64 + SPOFF]	! move into return reg
8886535Sjake	ldx	[%sp + 64 + SPOFF], %o0
8986535Sjake	sethi	%hi(0x80000000), %o1
9086535Sjake	sllx	%o1, 32, %o1
9186535Sjake	add	%o0, %o1, %o0		! add 2^63
9286535Sjake	ldd	[%sp + 64 + SPOFF + 8], %f2
9386535Sjake	retl
9486535Sjake	 add	%sp, 16, %sp
9586535Sjake
9686535Sjake1:
9786535Sjake	std	%f0, [%sp + 64 + SPOFF]	! return result
9886535Sjake	ldx	[%sp + 64 + SPOFF], %o0
9986535Sjake	ldd	[%sp + 64 + SPOFF + 8], %f2
10086535Sjake	retl
10186535Sjake	 add	%sp, 16, %sp
10286535SjakeEND(__dtoul)
103