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