1/* 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * %sccs.include.redist.c% 10 * 11 * from: $Header: fixunsdfsi.s,v 1.3 91/10/08 00:03:15 torek Exp $ 12 */ 13 14#if defined(LIBC_SCCS) && !defined(lint) 15 .asciz "@(#)fixunsdfsi.s 8.1 (Berkeley) 06/04/93" 16#endif /* LIBC_SCCS and not lint */ 17 18/* 19 * Convert double to unsigned integer (for gcc). 20 * 21 * I have made the output for NaN agree with the Sun compiler, not 22 * that it really matters, by using `fbul,a'. 23 */ 24 25#include "DEFS.h" 26 27 .align 8 28Lbig: 29 .word 0x41e00000 ! .double 0r2147483648.0e+00 30 .word 0 ! (who me, not trust the assembler?) 31 32ENTRY(__fixunsdfsi) 33 sub %sp, 8, %sp 34 std %o0, [%sp + 64] ! get argument into fpu reg 35 ldd [%sp + 64], %f0 36 sethi %hi(Lbig), %g1 37 ldd [%g1 + %lo(Lbig)], %f2 38 fcmped %f0, %f2 ! d < 2^31, or NaN, or -Inf? 39 nop ! (fpop2 delay) 40 fbul,a 1f ! if so, use fdtoi to convert to int 41 fdtoi %f0, %f0 ! (this includes negatives!) 42 43 ! d does not fit in an int, so subtract 2^31, convert, 44 ! and add 2^31 again (sigh). Just hope the intermediate 45 ! fits (if not, the result is undefined anyway). 46 47 fsubd %f0, %f2, %f0 ! d -= 2^31 48 fdtoi %f0, %f0 ! convert to int 49 st %f0, [%sp + 64] ! move into return reg 50 ld [%sp + 64], %o0 51 sethi %hi(0x80000000), %o1 52 add %o0, %o1, %o0 ! add 2^31 53 retl 54 add %sp, 8, %sp 55 561: 57 st %f0, [%sp + 64] ! return result 58 ld [%sp + 64], %o0 59 retl 60 add %sp, 8, %sp 61