1214152Sed/* ===-- fixunsdfti.c - Implement __fixunsdfti -----------------------------=== 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 __fixunsdfti for the compiler_rt library. 11214152Sed * 12214152Sed * ===----------------------------------------------------------------------=== 13214152Sed */ 14214152Sed 15239138Sandrew#include "int_lib.h" 16239138Sandrew 17263763Sdim#ifdef CRT_HAS_128BIT 18214152Sed 19214152Sed/* Returns: convert a to a unsigned long long, rounding toward zero. 20214152Sed * Negative values all become zero. 21214152Sed */ 22214152Sed 23214152Sed/* Assumption: double is a IEEE 64 bit floating point type 24214152Sed * tu_int is a 64 bit integral type 25214152Sed * value in double is representable in tu_int or is negative 26214152Sed * (no range checking performed) 27214152Sed */ 28214152Sed 29214152Sed/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */ 30214152Sed 31214152Sedtu_int 32214152Sed__fixunsdfti(double a) 33214152Sed{ 34214152Sed double_bits fb; 35214152Sed fb.f = a; 36214152Sed int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023; 37214152Sed if (e < 0 || (fb.u.s.high & 0x80000000)) 38214152Sed return 0; 39214152Sed tu_int r = 0x0010000000000000uLL | (fb.u.all & 0x000FFFFFFFFFFFFFuLL); 40214152Sed if (e > 52) 41214152Sed r <<= (e - 52); 42214152Sed else 43214152Sed r >>= (52 - e); 44214152Sed return r; 45214152Sed} 46214152Sed 47263763Sdim#endif /* CRT_HAS_128BIT */ 48