Edward O'Callaghan | 2bf6272 | 2009-08-05 04:02:56 +0000 | [diff] [blame] | 1 | /* ===-- fixunsxfdi.c - Implement __fixunsxfdi -----------------------------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Edward O'Callaghan | 2bf6272 | 2009-08-05 04:02:56 +0000 | [diff] [blame] | 7 | * |
| 8 | * ===----------------------------------------------------------------------=== |
| 9 | * |
| 10 | * This file implements __fixunsxfdi for the compiler_rt library. |
| 11 | * |
| 12 | * ===----------------------------------------------------------------------=== |
| 13 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 14 | |
| 15 | #if !_ARCH_PPC |
| 16 | |
| 17 | #include "int_lib.h" |
| 18 | |
Edward O'Callaghan | 2bf6272 | 2009-08-05 04:02:56 +0000 | [diff] [blame] | 19 | /* Returns: convert a to a unsigned long long, rounding toward zero. |
| 20 | * Negative values all become zero. |
| 21 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 22 | |
Edward O'Callaghan | 2bf6272 | 2009-08-05 04:02:56 +0000 | [diff] [blame] | 23 | /* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes |
| 24 | * du_int is a 64 bit integral type |
| 25 | * value in long double is representable in du_int or is negative |
| 26 | * (no range checking performed) |
| 27 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 28 | |
Edward O'Callaghan | 2bf6272 | 2009-08-05 04:02:56 +0000 | [diff] [blame] | 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 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 32 | |
| 33 | du_int |
| 34 | __fixunsxfdi(long double a) |
| 35 | { |
| 36 | long_double_bits fb; |
| 37 | fb.f = a; |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 38 | int e = (fb.u.high.s.low & 0x00007FFF) - 16383; |
| 39 | if (e < 0 || (fb.u.high.s.low & 0x00008000)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 40 | return 0; |
| 41 | return fb.u.low.all >> (63 - e); |
| 42 | } |
| 43 | |
| 44 | #endif |