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 * 4. Neither the name of the University nor the names of its contributors 1886535Sjake * may be used to endorse or promote products derived from this software 1986535Sjake * without specific prior written permission. 2086535Sjake * 2186535Sjake * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2286535Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2386535Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2486535Sjake * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2586535Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2686535Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2786535Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2886535Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2986535Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3086535Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3186535Sjake * SUCH DAMAGE. 3286535Sjake * 3386535Sjake * from: Header: fixunsdfsi.s,v 1.3 91/10/08 00:03:15 torek Exp 3486535Sjake */ 3586535Sjake 3686535Sjake#include <machine/asm.h> 3786535Sjake 3886535Sjake#if defined(LIBC_SCCS) && !defined(lint) 3999018Sobrien .asciz "@(#)fixunsdfsi.s 8.1 (Berkeley) 6/4/93" 4086535Sjake#if 0 4186535Sjake RCSID("$NetBSD: fixunsdfsi.S,v 1.3 2000/07/25 04:26:12 mycroft Exp $") 4286535Sjake#endif 4386535Sjake#endif /* LIBC_SCCS and not lint */ 4499018Sobrien__FBSDID("$FreeBSD: releng/10.2/lib/libc/sparc64/gen/fixunsdfsi.S 165903 2007-01-09 00:28:16Z imp $"); 4586535Sjake 4686535Sjake/* 4786535Sjake * Convert double to unsigned integer (for gcc). 4886535Sjake * 4986535Sjake * I have made the output for NaN agree with the Sun compiler, not 5086535Sjake * that it really matters, by using `fbul,a'. 5186535Sjake */ 5286535Sjake 5386535Sjake 5486535Sjake .align 8 5586535Sjake.Lbig: 5686535Sjake .word 0x43e00000 ! .double 2^63 5786535Sjake .word 0 ! (who me, not trust the assembler?) 5886535Sjake 5986535Sjake/* 6086535Sjake * Same as above but to unsigned long 6186535Sjake */ 6286535SjakeENTRY(__dtoul) 6392053Stmm PIC_PROLOGUE(%o4, %o5) 6486535Sjake sub %sp, 16, %sp 6592053Stmm std %f2, [%sp + CCFSZ + SPOFF + 8] 6692053Stmm SET(.Lbig, %o5, %o3) 6792053Stmm ldd [%o3], %f2 6886535Sjake fcmped %f0, %f2 ! d < 2^63, or NaN, or -Inf? 6992053Stmm fbul,a 1f ! if so, use fdtox to convert to long 7086535Sjake fdtox %f0, %f0 ! (this includes negatives!) 7186535Sjake 7292053Stmm ! d does not fit in a long, so subtract 2^63, convert, 7386535Sjake ! and add 2^63 again (sigh). Just hope the intermediate 7486535Sjake ! fits (if not, the result is undefined anyway). 7586535Sjake 7686535Sjake fsubd %f0, %f2, %f0 ! d -= 2^63 7792053Stmm fdtox %f0, %f0 ! convert to long 7892053Stmm std %f0, [%sp + CCFSZ + SPOFF] ! move into return reg 7992053Stmm ldx [%sp + CCFSZ + SPOFF], %o0 8086535Sjake sethi %hi(0x80000000), %o1 8186535Sjake sllx %o1, 32, %o1 8286535Sjake add %o0, %o1, %o0 ! add 2^63 8392053Stmm ldd [%sp + CCFSZ + SPOFF + 8], %f2 8486535Sjake retl 8586535Sjake add %sp, 16, %sp 8686535Sjake 8786535Sjake1: 8892053Stmm std %f0, [%sp + CCFSZ + SPOFF] ! return result 8992053Stmm ldx [%sp + CCFSZ + SPOFF], %o0 9092053Stmm ldd [%sp + CCFSZ + SPOFF + 8], %f2 9186535Sjake retl 9286535Sjake add %sp, 16, %sp 9386535SjakeEND(__dtoul) 94