fixunsxfti.c revision b3a6901e66f55b35aa9e01bcb24134e6a65ea004
1//===-- fixunsxfti.c - Implement __fixunsxfti -----------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements __fixunsxfti for the compiler_rt library. 11// 12//===----------------------------------------------------------------------===// 13 14#if __x86_64 15 16#include "int_lib.h" 17 18// Returns: convert a to a unsigned long long, rounding toward zero. 19// Negative values all become zero. 20 21// Assumption: long double is an intel 80 bit floating point type padded with 6 bytes 22// tu_int is a 64 bit integral type 23// value in long double is representable in tu_int or is negative 24// (no range checking performed) 25 26// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | 27// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm 28 29tu_int 30__fixunsxfti(long double a) 31{ 32 long_double_bits fb; 33 fb.f = a; 34 int e = (fb.u.high.low & 0x00007FFF) - 16383; 35 if (e < 0 || (fb.u.high.low & 0x00008000)) 36 return 0; 37 tu_int r = fb.u.low.all; 38 if (e > 63) 39 r <<= (e - 63); 40 else 41 r >>= (63 - e); 42 return r; 43} 44 45#endif 46