Weiming Zhao | 9b7bbec | 2017-03-21 05:32:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 2 | // XFAIL: aarch64 |
| 3 | // test fails for aarch64 (see pr32260) |
| 4 | |
Simon Dardis | 19a4d97 | 2017-05-04 13:34:17 +0000 | [diff] [blame^] | 5 | // UNSUPPORTED: mips |
| 6 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 7 | //===-- fixunsxfti_test.c - Test __fixunsxfti -----------------------------===// |
| 8 | // |
| 9 | // The LLVM Compiler Infrastructure |
| 10 | // |
Howard Hinnant | 5b791f6 | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 11 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 12 | // Source Licenses. See LICENSE.TXT for details. |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | // |
| 16 | // This file tests __fixunsxfti for the compiler_rt library. |
| 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 20 | #include "int_lib.h" |
| 21 | #include <stdio.h> |
| 22 | |
Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 23 | #ifdef CRT_HAS_128BIT |
| 24 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 25 | // Returns: convert a to a unsigned long long, rounding toward zero. |
| 26 | // Negative values all become zero. |
| 27 | |
| 28 | // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes |
| 29 | // tu_int is a 64 bit integral type |
| 30 | // value in long double is representable in tu_int or is negative |
| 31 | // (no range checking performed) |
| 32 | |
| 33 | // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | |
| 34 | // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm |
| 35 | |
Derek Schuff | eb0ebc3 | 2015-04-24 15:45:57 +0000 | [diff] [blame] | 36 | COMPILER_RT_ABI tu_int __fixunsxfti(long double a); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 37 | |
| 38 | int test__fixunsxfti(long double a, tu_int expected) |
| 39 | { |
| 40 | tu_int x = __fixunsxfti(a); |
| 41 | if (x != expected) |
| 42 | { |
| 43 | utwords xt; |
| 44 | xt.all = x; |
| 45 | utwords expectedt; |
| 46 | expectedt.all = expected; |
| 47 | printf("error in __fixunsxfti(%LA) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n", |
Daniel Dunbar | 6485720 | 2009-10-27 17:49:07 +0000 | [diff] [blame] | 48 | a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 49 | } |
| 50 | return x != expected; |
| 51 | } |
| 52 | |
| 53 | char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0}; |
| 54 | char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0}; |
| 55 | char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; |
| 56 | |
| 57 | #endif |
| 58 | |
| 59 | int main() |
| 60 | { |
Joerg Sonnenberger | 1474312 | 2014-03-18 21:35:30 +0000 | [diff] [blame] | 61 | #ifdef CRT_HAS_128BIT |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 62 | if (test__fixunsxfti(0.0, 0)) |
| 63 | return 1; |
| 64 | |
| 65 | if (test__fixunsxfti(0.5, 0)) |
| 66 | return 1; |
| 67 | if (test__fixunsxfti(0.99, 0)) |
| 68 | return 1; |
| 69 | if (test__fixunsxfti(1.0, 1)) |
| 70 | return 1; |
| 71 | if (test__fixunsxfti(1.5, 1)) |
| 72 | return 1; |
| 73 | if (test__fixunsxfti(1.99, 1)) |
| 74 | return 1; |
| 75 | if (test__fixunsxfti(2.0, 2)) |
| 76 | return 1; |
| 77 | if (test__fixunsxfti(2.01, 2)) |
| 78 | return 1; |
| 79 | if (test__fixunsxfti(-0.5, 0)) |
| 80 | return 1; |
| 81 | if (test__fixunsxfti(-0.99, 0)) |
| 82 | return 1; |
| 83 | if (test__fixunsxfti(-1.0, 0)) |
| 84 | return 1; |
| 85 | if (test__fixunsxfti(-1.5, 0)) |
| 86 | return 1; |
| 87 | if (test__fixunsxfti(-1.99, 0)) |
| 88 | return 1; |
| 89 | if (test__fixunsxfti(-2.0, 0)) |
| 90 | return 1; |
| 91 | if (test__fixunsxfti(-2.01, 0)) |
| 92 | return 1; |
| 93 | |
| 94 | if (test__fixunsxfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL)) |
| 95 | return 1; |
| 96 | if (test__fixunsxfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL)) |
| 97 | return 1; |
| 98 | |
| 99 | if (test__fixunsxfti(-0x1.FFFFFEp+62, 0)) |
| 100 | return 1; |
| 101 | if (test__fixunsxfti(-0x1.FFFFFCp+62, 0)) |
| 102 | return 1; |
| 103 | |
| 104 | if (test__fixunsxfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL)) |
| 105 | return 1; |
| 106 | if (test__fixunsxfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL)) |
| 107 | return 1; |
| 108 | |
| 109 | if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFp+62, 0)) |
| 110 | return 1; |
| 111 | if (test__fixunsxfti(-0x1.FFFFFFFFFFFFEp+62, 0)) |
| 112 | return 1; |
| 113 | |
| 114 | if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL)) |
| 115 | return 1; |
| 116 | if (test__fixunsxfti(0x1.0000000000000002p+63L, 0x8000000000000001LL)) |
| 117 | return 1; |
| 118 | if (test__fixunsxfti(0x1.0000000000000000p+63L, 0x8000000000000000LL)) |
| 119 | return 1; |
| 120 | if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL)) |
| 121 | return 1; |
| 122 | if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL)) |
| 123 | return 1; |
| 124 | |
| 125 | if (test__fixunsxfti(-0x1.0000000000000000p+63L, 0)) |
| 126 | return 1; |
| 127 | if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFFFCp+62L, 0)) |
| 128 | return 1; |
| 129 | if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFFF8p+62L, 0)) |
| 130 | return 1; |
| 131 | |
| 132 | if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFEp+127L, make_ti(0xFFFFFFFFFFFFFFFFLL, 0))) |
| 133 | return 1; |
| 134 | if (test__fixunsxfti(0x1.0000000000000002p+127L, make_ti(0x8000000000000001LL, 0))) |
| 135 | return 1; |
| 136 | if (test__fixunsxfti(0x1.0000000000000000p+127L, make_ti(0x8000000000000000LL, 0))) |
| 137 | return 1; |
| 138 | if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL, 0))) |
| 139 | return 1; |
| 140 | if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFF8p+126L, make_ti(0x7FFFFFFFFFFFFFFELL, 0))) |
| 141 | return 1; |
| 142 | |
Joerg Sonnenberger | d9bcddd | 2011-05-29 21:43:29 +0000 | [diff] [blame] | 143 | #else |
| 144 | printf("skipped\n"); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 145 | #endif |
| 146 | return 0; |
| 147 | } |