1/* $OpenBSD: fixunsdfsi.S,v 1.3 2003/07/21 18:43:55 jason Exp $ */ 2/* $NetBSD: fixunsdfsi.S,v 1.3 2000/07/25 04:26:12 mycroft Exp $ */ 3/* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This software was developed by the Computer Systems Engineering group 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9 * contributed to Berkeley. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36#include <machine/asm.h> 37#define _LOCORE 38#include <machine/frame.h> 39 40/* 41 * Convert double to unsigned integer (for gcc). 42 * 43 * I have made the output for NaN agree with the Sun compiler, not 44 * that it really matters, by using `fbul,a'. 45 */ 46 47 .align 8 48Lbigd: 49 .word 0x43e00000 ! .double 2^63 50 .word 0 ! (who me, not trust the assembler?) 51Lbigf: 52 .word 0x5f000000 ! .float 2^63 53 54/* 55 *unsigned long __dtoul(double): 56 * double -> unsigned long 57 */ 58ENTRY(__dtoul) 59 sub %sp, 16, %sp 60 std %f2, [%sp + 64 + BIAS + 8] 61#ifdef PIC 62 PICCY_SET(Lbigd, %g1, %o0) 63 ldd [%g1], %f2 64#else 65 sethi %hi(Lbigd), %g1 66 ldd [%g1 + %lo(Lbigd)], %f2 67#endif 68 fcmped %f0, %f2 ! d < 2^63, or NaN, or -Inf? 69 nop ! (fpop2 delay) 70 fbul,a 1f ! if so, use fdtoi to convert to int 71 fdtox %f0, %f0 ! (this includes negatives!) 72 73 ! d does not fit in an int, so subtract 2^63, convert, 74 ! and add 2^63 again (sigh). Just hope the intermediate 75 ! fits (if not, the result is undefined anyway). 76 77 fsubd %f0, %f2, %f0 ! d -= 2^63 78 fdtox %f0, %f0 ! convert to int 79 std %f0, [%sp + 64 + BIAS] ! move into return reg 80 ldx [%sp + 64 + BIAS], %o0 81 sethi %hi(0x80000000), %o1 82 sllx %o1, 32, %o1 83 add %o0, %o1, %o0 ! add 2^63 84 ldd [%sp + 64 + BIAS + 8], %f2 85 retl 86 add %sp, 16, %sp 87 881: 89 std %f0, [%sp + 64 + BIAS] ! return result 90 ldx [%sp + 64 + BIAS], %o0 91 ldd [%sp + 64 + BIAS + 8], %f2 92 retl 93 add %sp, 16, %sp 94 95/* 96 *unsigned long __ftoul(float): 97 * float -> unsigned long 98 */ 99ENTRY(__ftoul) 100 sub %sp, 16, %sp 101 st %f1, [%sp + 64 + BIAS + 8] 102 st %f2, [%sp + 64 + BIAS + 12] 103#ifdef PIC 104 PICCY_SET(Lbigf, %g1, %o0) 105 ld [%g1], %f2 106#else 107 sethi %hi(Lbigf), %g1 108 ld [%g1 + %lo(Lbigf)], %f2 109#endif 110 fcmpes %f0, %f2 ! d < 2^63, or NaN, or -Inf? 111 nop ! (fpop2 delay) 112 fbul,a 1f ! if so, use fdtoi to convert to int 113 fstox %f0, %f0 ! (this includes negatives!) 114 115 ! d does not fit in an int, so subtract 2^63, convert, 116 ! and add 2^63 again (sigh). Just hope the intermediate 117 ! fits (if not, the result is undefined anyway). 118 119 fsubs %f0, %f2, %f0 ! d -= 2^63 120 fstox %f0, %f0 ! convert to int 121 std %f0, [%sp + 64 + BIAS] ! move into return reg 122 ldx [%sp + 64 + BIAS], %o0 123 sethi %hi(0x80000000), %o1 124 sllx %o1, 32, %o1 125 add %o0, %o1, %o0 ! add 2^63 126 ld [%sp + 64 + BIAS + 8], %f1 127 ld [%sp + 64 + BIAS + 12], %f2 128 retl 129 add %sp, 16, %sp 130 1311: 132 std %f0, [%sp + 64 + BIAS] ! return result 133 ldx [%sp + 64 + BIAS], %o0 134 ld [%sp + 64 + BIAS + 8], %f1 135 ld [%sp + 64 + BIAS + 12], %f2 136 retl 137 add %sp, 16, %sp 138