Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | //===-- fixunsdfsi_test.c - Test __fixunsdfsi -----------------------------===// |
| 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. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file tests __fixunsdfsi for the compiler_rt library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "int_lib.h" |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | // Returns: convert a to a unsigned int, rounding toward zero. |
| 18 | // Negative values all become zero. |
| 19 | |
| 20 | // Assumption: double is a IEEE 64 bit floating point type |
| 21 | // su_int is a 32 bit integral type |
| 22 | // value in double is representable in su_int or is negative |
| 23 | // (no range checking performed) |
| 24 | |
| 25 | // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm |
| 26 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 27 | COMPILER_RT_ABI su_int __fixunsdfsi(double a); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 28 | |
| 29 | int test__fixunsdfsi(double a, su_int expected) |
| 30 | { |
| 31 | su_int x = __fixunsdfsi(a); |
| 32 | if (x != expected) |
| 33 | printf("error in __fixunsdfsi(%A) = %X, expected %X\n", a, x, expected); |
| 34 | return x != expected; |
| 35 | } |
| 36 | |
| 37 | char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0}; |
| 38 | char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0}; |
| 39 | |
| 40 | int main() |
| 41 | { |
| 42 | if (test__fixunsdfsi(0.0, 0)) |
| 43 | return 1; |
| 44 | |
| 45 | if (test__fixunsdfsi(0.5, 0)) |
| 46 | return 1; |
| 47 | if (test__fixunsdfsi(0.99, 0)) |
| 48 | return 1; |
| 49 | if (test__fixunsdfsi(1.0, 1)) |
| 50 | return 1; |
| 51 | if (test__fixunsdfsi(1.5, 1)) |
| 52 | return 1; |
| 53 | if (test__fixunsdfsi(1.99, 1)) |
| 54 | return 1; |
| 55 | if (test__fixunsdfsi(2.0, 2)) |
| 56 | return 1; |
| 57 | if (test__fixunsdfsi(2.01, 2)) |
| 58 | return 1; |
| 59 | if (test__fixunsdfsi(-0.5, 0)) |
| 60 | return 1; |
| 61 | if (test__fixunsdfsi(-0.99, 0)) |
| 62 | return 1; |
| 63 | #if !TARGET_LIBGCC |
| 64 | if (test__fixunsdfsi(-1.0, 0)) // libgcc ignores "returns 0 for negative input" spec |
| 65 | return 1; |
| 66 | if (test__fixunsdfsi(-1.5, 0)) |
| 67 | return 1; |
| 68 | if (test__fixunsdfsi(-1.99, 0)) |
| 69 | return 1; |
| 70 | if (test__fixunsdfsi(-2.0, 0)) |
| 71 | return 1; |
| 72 | if (test__fixunsdfsi(-2.01, 0)) |
| 73 | return 1; |
| 74 | #endif |
| 75 | |
| 76 | if (test__fixunsdfsi(0x1.000000p+31, 0x80000000)) |
| 77 | return 1; |
| 78 | if (test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00)) |
| 79 | return 1; |
| 80 | if (test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80)) |
| 81 | return 1; |
| 82 | if (test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00)) |
| 83 | return 1; |
| 84 | |
| 85 | #if !TARGET_LIBGCC |
| 86 | if (test__fixunsdfsi(-0x1.FFFFFEp+30, 0)) |
| 87 | return 1; |
| 88 | if (test__fixunsdfsi(-0x1.FFFFFCp+30, 0)) |
| 89 | return 1; |
| 90 | #endif |
| 91 | |
| 92 | if (test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF)) |
| 93 | return 1; |
| 94 | if (test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF)) |
| 95 | return 1; |
| 96 | if (test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE)) |
| 97 | return 1; |
| 98 | |
| 99 | return 0; |
| 100 | } |