fixunsdfdi.c revision 222656
1214152Sed/* ===-- fixunsdfdi.c - Implement __fixunsdfdi -----------------------------=== 2214152Sed * 3214152Sed * The LLVM Compiler Infrastructure 4214152Sed * 5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open 6222656Sed * Source Licenses. See LICENSE.TXT for details. 7214152Sed * 8214152Sed * ===----------------------------------------------------------------------=== 9214152Sed * 10214152Sed * This file implements __fixunsdfdi for the compiler_rt library. 11214152Sed * 12214152Sed * ===----------------------------------------------------------------------=== 13214152Sed */ 14222656Sed#include "abi.h" 15214152Sed 16214152Sed#include "int_lib.h" 17214152Sed 18214152Sed/* Returns: convert a to a unsigned long long, rounding toward zero. 19214152Sed * Negative values all become zero. 20214152Sed */ 21214152Sed 22214152Sed/* Assumption: double is a IEEE 64 bit floating point type 23214152Sed * du_int is a 64 bit integral type 24214152Sed * value in double is representable in du_int or is negative 25214152Sed * (no range checking performed) 26214152Sed */ 27214152Sed 28214152Sed/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */ 29214152Sed 30222656SedARM_EABI_FNALIAS(d2ulz, fixunsdfdi); 31222656Sed 32222656SedCOMPILER_RT_ABI du_int 33214152Sed__fixunsdfdi(double a) 34214152Sed{ 35214152Sed double_bits fb; 36214152Sed fb.f = a; 37214152Sed int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023; 38214152Sed if (e < 0 || (fb.u.s.high & 0x80000000)) 39214152Sed return 0; 40214152Sed udwords r; 41214152Sed r.s.high = (fb.u.s.high & 0x000FFFFF) | 0x00100000; 42214152Sed r.s.low = fb.u.s.low; 43214152Sed if (e > 52) 44214152Sed r.all <<= (e - 52); 45214152Sed else 46214152Sed r.all >>= (52 - e); 47214152Sed return r.all; 48214152Sed} 49