fixunsdfsi.S revision 92053
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 92053 2002-03-11 03:10:55Z tmm $" 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) 7292053Stmm PIC_PROLOGUE(%o4, %o5) 7386535Sjake sub %sp, 16, %sp 7492053Stmm std %f2, [%sp + CCFSZ + SPOFF + 8] 7592053Stmm SET(.Lbig, %o5, %o3) 7692053Stmm ldd [%o3], %f2 7786535Sjake fcmped %f0, %f2 ! d < 2^63, or NaN, or -Inf? 7892053Stmm fbul,a 1f ! if so, use fdtox to convert to long 7986535Sjake fdtox %f0, %f0 ! (this includes negatives!) 8086535Sjake 8192053Stmm ! d does not fit in a long, 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 8692053Stmm fdtox %f0, %f0 ! convert to long 8792053Stmm std %f0, [%sp + CCFSZ + SPOFF] ! move into return reg 8892053Stmm ldx [%sp + CCFSZ + SPOFF], %o0 8986535Sjake sethi %hi(0x80000000), %o1 9086535Sjake sllx %o1, 32, %o1 9186535Sjake add %o0, %o1, %o0 ! add 2^63 9292053Stmm ldd [%sp + CCFSZ + SPOFF + 8], %f2 9386535Sjake retl 9486535Sjake add %sp, 16, %sp 9586535Sjake 9686535Sjake1: 9792053Stmm std %f0, [%sp + CCFSZ + SPOFF] ! return result 9892053Stmm ldx [%sp + CCFSZ + SPOFF], %o0 9992053Stmm ldd [%sp + CCFSZ + SPOFF + 8], %f2 10086535Sjake retl 10186535Sjake add %sp, 16, %sp 10286535SjakeEND(__dtoul) 103