fixxfti.c revision 222656
192108Sphk/* ===-- fixxfti.c - Implement __fixxfti -----------------------------------=== 292108Sphk * 392108Sphk * The LLVM Compiler Infrastructure 492108Sphk * 592108Sphk * This file is dual licensed under the MIT and the University of Illinois Open 692108Sphk * Source Licenses. See LICENSE.TXT for details. 792108Sphk * 892108Sphk * ===----------------------------------------------------------------------=== 992108Sphk * 1092108Sphk * This file implements __fixxfti for the compiler_rt library. 1192108Sphk * 1292108Sphk * ===----------------------------------------------------------------------=== 1392108Sphk */ 1492108Sphk 1592108Sphk#if __x86_64 1692108Sphk 1792108Sphk#include "int_lib.h" 1892108Sphk 1992108Sphk/* Returns: convert a to a signed long long, rounding toward zero. */ 2092108Sphk 2192108Sphk/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes 2292108Sphk * su_int is a 32 bit integral type 2392108Sphk * value in long double is representable in ti_int (no range checking performed) 2492108Sphk */ 2592108Sphk 2692108Sphk/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | 2792108Sphk * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm 2892108Sphk */ 2992108Sphk 3092108Sphkti_int 3192108Sphk__fixxfti(long double a) 3292108Sphk{ 3392108Sphk long_double_bits fb; 3492108Sphk fb.f = a; 3592108Sphk int e = (fb.u.high.s.low & 0x00007FFF) - 16383; 3692108Sphk if (e < 0) 3792108Sphk return 0; 3892108Sphk ti_int s = -(si_int)((fb.u.high.s.low & 0x00008000) >> 15); 3992108Sphk ti_int r = fb.u.low.all; 4092108Sphk if (e > 63) 41116196Sobrien r <<= (e - 63); 42116196Sobrien else 43116196Sobrien r >>= (63 - e); 4492108Sphk return (r ^ s) - s; 4592108Sphk} 4692108Sphk 4792108Sphk#endif /* __x86_64 */ 4892108Sphk