Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | //===-- fixxfti_test.c - Test __fixxfti -----------------------------------===// |
| 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 __fixxfti for the compiler_rt library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #if __x86_64 |
| 15 | |
| 16 | #include "int_lib.h" |
| 17 | #include <stdio.h> |
| 18 | |
| 19 | // Returns: convert a to a signed long long, rounding toward zero. |
| 20 | |
| 21 | // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes |
| 22 | // su_int is a 32 bit integral type |
| 23 | // value in long double is representable in ti_int (no range checking performed) |
| 24 | |
| 25 | // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | |
| 26 | // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm |
| 27 | |
| 28 | ti_int __fixxfti(long double a); |
| 29 | |
| 30 | int test__fixxfti(long double a, ti_int expected) |
| 31 | { |
| 32 | ti_int x = __fixxfti(a); |
| 33 | if (x != expected) |
| 34 | { |
| 35 | utwords xt; |
| 36 | xt.all = x; |
| 37 | utwords expectedt; |
| 38 | expectedt.all = expected; |
| 39 | printf("error in __fixxfti(%LA) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n", |
Daniel Dunbar | cff5248 | 2009-10-27 17:49:07 +0000 | [diff] [blame] | 40 | a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 41 | } |
| 42 | return x != expected; |
| 43 | } |
| 44 | |
| 45 | char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; |
| 46 | char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0}; |
| 47 | char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; |
| 48 | |
| 49 | #endif |
| 50 | |
| 51 | int main() |
| 52 | { |
| 53 | #if __x86_64 |
| 54 | if (test__fixxfti(0.0, 0)) |
| 55 | return 1; |
| 56 | |
| 57 | if (test__fixxfti(0.5, 0)) |
| 58 | return 1; |
| 59 | if (test__fixxfti(0.99, 0)) |
| 60 | return 1; |
| 61 | if (test__fixxfti(1.0, 1)) |
| 62 | return 1; |
| 63 | if (test__fixxfti(1.5, 1)) |
| 64 | return 1; |
| 65 | if (test__fixxfti(1.99, 1)) |
| 66 | return 1; |
| 67 | if (test__fixxfti(2.0, 2)) |
| 68 | return 1; |
| 69 | if (test__fixxfti(2.01, 2)) |
| 70 | return 1; |
| 71 | if (test__fixxfti(-0.5, 0)) |
| 72 | return 1; |
| 73 | if (test__fixxfti(-0.99, 0)) |
| 74 | return 1; |
| 75 | if (test__fixxfti(-1.0, -1)) |
| 76 | return 1; |
| 77 | if (test__fixxfti(-1.5, -1)) |
| 78 | return 1; |
| 79 | if (test__fixxfti(-1.99, -1)) |
| 80 | return 1; |
| 81 | if (test__fixxfti(-2.0, -2)) |
| 82 | return 1; |
| 83 | if (test__fixxfti(-2.01, -2)) |
| 84 | return 1; |
| 85 | |
| 86 | if (test__fixxfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL)) |
| 87 | return 1; |
| 88 | if (test__fixxfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL)) |
| 89 | return 1; |
| 90 | |
| 91 | if (test__fixxfti(-0x1.FFFFFEp+62, make_ti(0xFFFFFFFFFFFFFFFFLL, |
| 92 | 0x8000008000000000LL))) |
| 93 | return 1; |
| 94 | if (test__fixxfti(-0x1.FFFFFCp+62, make_ti(0xFFFFFFFFFFFFFFFFLL, |
| 95 | 0x8000010000000000LL))) |
| 96 | return 1; |
| 97 | |
| 98 | if (test__fixxfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL)) |
| 99 | return 1; |
| 100 | if (test__fixxfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL)) |
| 101 | return 1; |
| 102 | |
| 103 | if (test__fixxfti(-0x1.FFFFFFFFFFFFFp+62, make_ti(0xFFFFFFFFFFFFFFFFLL, |
| 104 | 0x8000000000000400LL))) |
| 105 | return 1; |
| 106 | if (test__fixxfti(-0x1.FFFFFFFFFFFFEp+62, make_ti(0xFFFFFFFFFFFFFFFFLL, |
| 107 | 0x8000000000000800LL))) |
| 108 | return 1; |
| 109 | |
| 110 | if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL)) |
| 111 | return 1; |
| 112 | if (test__fixxfti(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL)) |
| 113 | return 1; |
| 114 | |
| 115 | if (test__fixxfti(-0x1.0000000000000000p+63L, make_ti(0xFFFFFFFFFFFFFFFFLL, |
| 116 | 0x8000000000000000LL))) |
| 117 | return 1; |
| 118 | if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp+62L, make_ti(0xFFFFFFFFFFFFFFFFLL, |
| 119 | 0x8000000000000001LL))) |
| 120 | return 1; |
| 121 | if (test__fixxfti(-0x1.FFFFFFFFFFFFFFF8p+62L, make_ti(0xFFFFFFFFFFFFFFFFLL, |
| 122 | 0x8000000000000002LL))) |
| 123 | return 1; |
| 124 | |
| 125 | if (test__fixxfti(0x1.FFFFFFFFFFFFFFFEp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL, |
| 126 | 0x8000000000000000LL))) |
| 127 | return 1; |
| 128 | if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL, |
| 129 | 0x0000000000000000LL))) |
| 130 | |
| 131 | return 1; |
| 132 | |
| 133 | if (test__fixxfti(-0x1.0000000000000000p+127L, make_ti(0x8000000000000000LL, |
| 134 | 0x0000000000000000LL))) |
| 135 | return 1; |
| 136 | if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFEp+126L, make_ti(0x8000000000000000LL, |
| 137 | 0x8000000000000000LL))) |
| 138 | return 1; |
| 139 | if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x8000000000000001LL, |
| 140 | 0x0000000000000000LL))) |
| 141 | return 1; |
Joerg Sonnenberger | 7482815 | 2011-05-29 21:43:29 +0000 | [diff] [blame^] | 142 | #else |
| 143 | printf("skipped\n"); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 144 | #endif |
| 145 | return 0; |
| 146 | } |