fixunssfti.c revision 276789
1218885Sdim/* ===-- fixunssfti.c - Implement __fixunssfti -----------------------------=== 2218885Sdim * 3218885Sdim * The LLVM Compiler Infrastructure 4218885Sdim * 5218885Sdim * This file is dual licensed under the MIT and the University of Illinois Open 6218885Sdim * Source Licenses. See LICENSE.TXT for details. 7218885Sdim * 8218885Sdim * ===----------------------------------------------------------------------=== 9218885Sdim * 10218885Sdim * This file implements __fixunssfti for the compiler_rt library. 11218885Sdim * 12218885Sdim * ===----------------------------------------------------------------------=== 13218885Sdim */ 14218885Sdim 15218885Sdim#include "int_lib.h" 16218885Sdim 17224145Sdim#ifdef CRT_HAS_128BIT 18218885Sdim 19218885Sdim/* Returns: convert a to a unsigned long long, rounding toward zero. 20224145Sdim * Negative values all become zero. 21224145Sdim */ 22218885Sdim 23234353Sdim/* Assumption: float is a IEEE 32 bit floating point type 24218885Sdim * tu_int is a 64 bit integral type 25218885Sdim * value in float is representable in tu_int or is negative 26218885Sdim * (no range checking performed) 27218885Sdim */ 28218885Sdim 29218885Sdim/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */ 30218885Sdim 31218885SdimCOMPILER_RT_ABI tu_int 32226633Sdim__fixunssfti(float a) 33226633Sdim{ 34226633Sdim float_bits fb; 35226633Sdim fb.f = a; 36226633Sdim int e = ((fb.u & 0x7F800000) >> 23) - 127; 37226633Sdim if (e < 0 || (fb.u & 0x80000000)) 38218885Sdim return 0; 39218885Sdim tu_int r = (fb.u & 0x007FFFFF) | 0x00800000; 40224145Sdim if (e > 23) 41234353Sdim r <<= (e - 23); 42234353Sdim else 43234353Sdim r >>= (23 - e); 44218885Sdim return r; 45218885Sdim} 46226633Sdim 47226633Sdim#endif /* CRT_HAS_128BIT */ 48226633Sdim