1 |
|
|
/* ===-- fixunsxfsi.c - Implement __fixunsxfsi -----------------------------=== |
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 __fixunsxfsi for the compiler_rt library. |
11 |
|
|
* |
12 |
|
|
* ===----------------------------------------------------------------------=== |
13 |
|
|
*/ |
14 |
|
|
|
15 |
|
|
#if !_ARCH_PPC |
16 |
|
|
|
17 |
|
|
#include "int_lib.h" |
18 |
|
|
|
19 |
|
|
/* Returns: convert a to a unsigned int, 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 |
|
|
* su_int is a 32 bit integral type |
25 |
|
|
* value in long double is representable in su_int or is negative |
26 |
|
|
*/ |
27 |
|
|
|
28 |
|
|
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | |
29 |
|
|
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm |
30 |
|
|
*/ |
31 |
|
|
|
32 |
|
|
COMPILER_RT_ABI su_int |
33 |
|
|
__fixunsxfsi(long double a) |
34 |
|
|
{ |
35 |
|
|
long_double_bits fb; |
36 |
|
|
fb.f = a; |
37 |
|
|
int e = (fb.u.high.s.low & 0x00007FFF) - 16383; |
38 |
|
|
if (e < 0 || (fb.u.high.s.low & 0x00008000)) |
39 |
|
|
return 0; |
40 |
|
|
if ((unsigned)e > sizeof(su_int) * CHAR_BIT) |
41 |
|
|
return ~(su_int)0; |
42 |
|
|
return fb.u.low.s.high >> (31 - e); |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
#endif /* !_ARCH_PPC */ |