1156cd587Sjoerg /* ===-- fixunsxfti.c - Implement __fixunsxfti -----------------------------=== 2156cd587Sjoerg * 3156cd587Sjoerg * The LLVM Compiler Infrastructure 4156cd587Sjoerg * 5156cd587Sjoerg * This file is dual licensed under the MIT and the University of Illinois Open 6156cd587Sjoerg * Source Licenses. See LICENSE.TXT for details. 7156cd587Sjoerg * 8156cd587Sjoerg * ===----------------------------------------------------------------------=== 9156cd587Sjoerg * 10156cd587Sjoerg * This file implements __fixunsxfti for the compiler_rt library. 11156cd587Sjoerg * 12156cd587Sjoerg * ===----------------------------------------------------------------------=== 13156cd587Sjoerg */ 14156cd587Sjoerg 15156cd587Sjoerg #include "int_lib.h" 16156cd587Sjoerg 17156cd587Sjoerg #ifdef CRT_HAS_128BIT 18156cd587Sjoerg 19156cd587Sjoerg /* Returns: convert a to a unsigned long long, rounding toward zero. 20156cd587Sjoerg * Negative values all become zero. 21156cd587Sjoerg */ 22156cd587Sjoerg 23156cd587Sjoerg /* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes 24*ef84fd3bSjoerg * tu_int is a 128 bit integral type 25156cd587Sjoerg * value in long double is representable in tu_int or is negative 26156cd587Sjoerg */ 27156cd587Sjoerg 28156cd587Sjoerg /* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | 29156cd587Sjoerg * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm 30156cd587Sjoerg */ 31156cd587Sjoerg 32f7f78b33Sjoerg COMPILER_RT_ABI tu_int __fixunsxfti(long double a)33156cd587Sjoerg__fixunsxfti(long double a) 34156cd587Sjoerg { 35156cd587Sjoerg long_double_bits fb; 36156cd587Sjoerg fb.f = a; 37156cd587Sjoerg int e = (fb.u.high.s.low & 0x00007FFF) - 16383; 38156cd587Sjoerg if (e < 0 || (fb.u.high.s.low & 0x00008000)) 39156cd587Sjoerg return 0; 40*ef84fd3bSjoerg if ((unsigned)e > sizeof(tu_int) * CHAR_BIT) 41*ef84fd3bSjoerg return ~(tu_int)0; 42156cd587Sjoerg tu_int r = fb.u.low.all; 43156cd587Sjoerg if (e > 63) 44156cd587Sjoerg r <<= (e - 63); 45156cd587Sjoerg else 46156cd587Sjoerg r >>= (63 - e); 47156cd587Sjoerg return r; 48156cd587Sjoerg } 49156cd587Sjoerg 50156cd587Sjoerg #endif /* CRT_HAS_128BIT */ 51