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