fixunsdfsi.S revision 99018
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) 4399018Sobrien .asciz "@(#)fixunsdfsi.s 8.1 (Berkeley) 6/4/93" 4486535Sjake#if 0 4586535Sjake RCSID("$NetBSD: fixunsdfsi.S,v 1.3 2000/07/25 04:26:12 mycroft Exp $") 4686535Sjake#endif 4786535Sjake#endif /* LIBC_SCCS and not lint */ 4899018Sobrien__FBSDID("$FreeBSD: head/lib/libc/sparc64/gen/fixunsdfsi.S 99018 2002-06-29 03:23:51Z obrien $"); 4986535Sjake 5086535Sjake/* 5186535Sjake * Convert double to unsigned integer (for gcc). 5286535Sjake * 5386535Sjake * I have made the output for NaN agree with the Sun compiler, not 5486535Sjake * that it really matters, by using `fbul,a'. 5586535Sjake */ 5686535Sjake 5786535Sjake 5886535Sjake .align 8 5986535Sjake.Lbig: 6086535Sjake .word 0x43e00000 ! .double 2^63 6186535Sjake .word 0 ! (who me, not trust the assembler?) 6286535Sjake 6386535Sjake/* 6486535Sjake * Same as above but to unsigned long 6586535Sjake */ 6686535SjakeENTRY(__dtoul) 6792053Stmm PIC_PROLOGUE(%o4, %o5) 6886535Sjake sub %sp, 16, %sp 6992053Stmm std %f2, [%sp + CCFSZ + SPOFF + 8] 7092053Stmm SET(.Lbig, %o5, %o3) 7192053Stmm ldd [%o3], %f2 7286535Sjake fcmped %f0, %f2 ! d < 2^63, or NaN, or -Inf? 7392053Stmm fbul,a 1f ! if so, use fdtox to convert to long 7486535Sjake fdtox %f0, %f0 ! (this includes negatives!) 7586535Sjake 7692053Stmm ! d does not fit in a long, so subtract 2^63, convert, 7786535Sjake ! and add 2^63 again (sigh). Just hope the intermediate 7886535Sjake ! fits (if not, the result is undefined anyway). 7986535Sjake 8086535Sjake fsubd %f0, %f2, %f0 ! d -= 2^63 8192053Stmm fdtox %f0, %f0 ! convert to long 8292053Stmm std %f0, [%sp + CCFSZ + SPOFF] ! move into return reg 8392053Stmm ldx [%sp + CCFSZ + SPOFF], %o0 8486535Sjake sethi %hi(0x80000000), %o1 8586535Sjake sllx %o1, 32, %o1 8686535Sjake add %o0, %o1, %o0 ! add 2^63 8792053Stmm ldd [%sp + CCFSZ + SPOFF + 8], %f2 8886535Sjake retl 8986535Sjake add %sp, 16, %sp 9086535Sjake 9186535Sjake1: 9292053Stmm std %f0, [%sp + CCFSZ + SPOFF] ! return result 9392053Stmm ldx [%sp + CCFSZ + SPOFF], %o0 9492053Stmm ldd [%sp + CCFSZ + SPOFF + 8], %f2 9586535Sjake retl 9686535Sjake add %sp, 16, %sp 9786535SjakeEND(__dtoul) 98