1156cd587Sjoerg /* ===-- fixunsxfdi.c - Implement __fixunsxfdi -----------------------------=== 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 __fixunsxfdi for the compiler_rt library. 11156cd587Sjoerg * 12156cd587Sjoerg * ===----------------------------------------------------------------------=== 13156cd587Sjoerg */ 14156cd587Sjoerg 15156cd587Sjoerg #if !_ARCH_PPC 16156cd587Sjoerg 17156cd587Sjoerg #include "int_lib.h" 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 24156cd587Sjoerg * du_int is a 64 bit integral type 25156cd587Sjoerg * value in long double is representable in du_int or is negative 26156cd587Sjoerg * (no range checking performed) 27156cd587Sjoerg */ 28156cd587Sjoerg 29156cd587Sjoerg /* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | 30156cd587Sjoerg * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm 31156cd587Sjoerg */ 32156cd587Sjoerg 33f7f78b33Sjoerg COMPILER_RT_ABI du_int __fixunsxfdi(long double a)34156cd587Sjoerg__fixunsxfdi(long double a) 35156cd587Sjoerg { 36156cd587Sjoerg long_double_bits fb; 37156cd587Sjoerg fb.f = a; 38156cd587Sjoerg int e = (fb.u.high.s.low & 0x00007FFF) - 16383; 39156cd587Sjoerg if (e < 0 || (fb.u.high.s.low & 0x00008000)) 40156cd587Sjoerg return 0; 41*ef84fd3bSjoerg if ((unsigned)e > sizeof(du_int) * CHAR_BIT) 42*ef84fd3bSjoerg return ~(du_int)0; 43156cd587Sjoerg return fb.u.low.all >> (63 - e); 44156cd587Sjoerg } 45156cd587Sjoerg 46156cd587Sjoerg #endif 47