| 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 2 | // REQUIRES: librt_has_floattisf |
| 3 | // REQUIRES: int128 |
| 4 | |
| 5 | #include "int_lib.h" |
| 6 | #include <float.h> |
| 7 | #include <stdio.h> |
| 8 | |
| 9 | #ifdef CRT_HAS_128BIT |
| 10 | |
| 11 | // Returns: convert a to a float, rounding toward even. |
| 12 | |
| 13 | // Assumption: float is a IEEE 32 bit floating point type |
| 14 | // ti_int is a 64 bit integral type |
| 15 | |
| 16 | // seee eeee emmm mmmm mmmm mmmm mmmm mmmm |
| 17 | |
| 18 | COMPILER_RT_ABI float __floattisf(ti_int a); |
| 19 | |
| 20 | int test__floattisf(ti_int a, float expected) |
| 21 | { |
| 22 | float x = __floattisf(a); |
| 23 | if (x != expected) |
| 24 | { |
| 25 | twords at; |
| 26 | at.all = a; |
| 27 | printf(format: "error in __floattisf(0x%.16llX%.16llX) = %a, expected %a\n" , |
| 28 | at.s.high, at.s.low, x, expected); |
| 29 | } |
| 30 | return x != expected; |
| 31 | } |
| 32 | |
| 33 | char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; |
| 34 | char assumption_2[sizeof(ti_int)*CHAR_BIT == 128] = {0}; |
| 35 | char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0}; |
| 36 | |
| 37 | #endif |
| 38 | |
| 39 | int main() |
| 40 | { |
| 41 | #ifdef CRT_HAS_128BIT |
| 42 | if (test__floattisf(a: 0, expected: 0.0F)) |
| 43 | return 1; |
| 44 | |
| 45 | if (test__floattisf(a: 1, expected: 1.0F)) |
| 46 | return 1; |
| 47 | if (test__floattisf(a: 2, expected: 2.0F)) |
| 48 | return 1; |
| 49 | if (test__floattisf(a: -1, expected: -1.0F)) |
| 50 | return 1; |
| 51 | if (test__floattisf(a: -2, expected: -2.0F)) |
| 52 | return 1; |
| 53 | |
| 54 | if (test__floattisf(a: 0x7FFFFF8000000000LL, expected: 0x1.FFFFFEp+62F)) |
| 55 | return 1; |
| 56 | if (test__floattisf(a: 0x7FFFFF0000000000LL, expected: 0x1.FFFFFCp+62F)) |
| 57 | return 1; |
| 58 | |
| 59 | if (test__floattisf(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0x8000008000000000LL), |
| 60 | expected: -0x1.FFFFFEp+62F)) |
| 61 | return 1; |
| 62 | if (test__floattisf(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0x8000010000000000LL), |
| 63 | expected: -0x1.FFFFFCp+62F)) |
| 64 | return 1; |
| 65 | |
| 66 | if (test__floattisf(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0x8000000000000000LL), |
| 67 | expected: -0x1.000000p+63F)) |
| 68 | return 1; |
| 69 | if (test__floattisf(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0x8000000000000001LL), |
| 70 | expected: -0x1.000000p+63F)) |
| 71 | return 1; |
| 72 | |
| 73 | if (test__floattisf(a: 0x0007FB72E8000000LL, expected: 0x1.FEDCBAp+50F)) |
| 74 | return 1; |
| 75 | |
| 76 | if (test__floattisf(a: 0x0007FB72EA000000LL, expected: 0x1.FEDCBAp+50F)) |
| 77 | return 1; |
| 78 | if (test__floattisf(a: 0x0007FB72EB000000LL, expected: 0x1.FEDCBAp+50F)) |
| 79 | return 1; |
| 80 | if (test__floattisf(a: 0x0007FB72EBFFFFFFLL, expected: 0x1.FEDCBAp+50F)) |
| 81 | return 1; |
| 82 | if (test__floattisf(a: 0x0007FB72EC000000LL, expected: 0x1.FEDCBCp+50F)) |
| 83 | return 1; |
| 84 | if (test__floattisf(a: 0x0007FB72E8000001LL, expected: 0x1.FEDCBAp+50F)) |
| 85 | return 1; |
| 86 | |
| 87 | if (test__floattisf(a: 0x0007FB72E6000000LL, expected: 0x1.FEDCBAp+50F)) |
| 88 | return 1; |
| 89 | if (test__floattisf(a: 0x0007FB72E7000000LL, expected: 0x1.FEDCBAp+50F)) |
| 90 | return 1; |
| 91 | if (test__floattisf(a: 0x0007FB72E7FFFFFFLL, expected: 0x1.FEDCBAp+50F)) |
| 92 | return 1; |
| 93 | if (test__floattisf(a: 0x0007FB72E4000001LL, expected: 0x1.FEDCBAp+50F)) |
| 94 | return 1; |
| 95 | if (test__floattisf(a: 0x0007FB72E4000000LL, expected: 0x1.FEDCB8p+50F)) |
| 96 | return 1; |
| 97 | |
| 98 | if (test__floattisf(a: make_ti(h: 0x0007FB72E8000000LL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 99 | return 1; |
| 100 | |
| 101 | if (test__floattisf(a: make_ti(h: 0x0007FB72EA000000LL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 102 | return 1; |
| 103 | if (test__floattisf(a: make_ti(h: 0x0007FB72EB000000LL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 104 | return 1; |
| 105 | if (test__floattisf(a: make_ti(h: 0x0007FB72EBFFFFFFLL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 106 | return 1; |
| 107 | if (test__floattisf(a: make_ti(h: 0x0007FB72EC000000LL, l: 0), expected: 0x1.FEDCBCp+114F)) |
| 108 | return 1; |
| 109 | if (test__floattisf(a: make_ti(h: 0x0007FB72E8000001LL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 110 | return 1; |
| 111 | |
| 112 | if (test__floattisf(a: make_ti(h: 0x0007FB72E6000000LL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 113 | return 1; |
| 114 | if (test__floattisf(a: make_ti(h: 0x0007FB72E7000000LL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 115 | return 1; |
| 116 | if (test__floattisf(a: make_ti(h: 0x0007FB72E7FFFFFFLL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 117 | return 1; |
| 118 | if (test__floattisf(a: make_ti(h: 0x0007FB72E4000001LL, l: 0), expected: 0x1.FEDCBAp+114F)) |
| 119 | return 1; |
| 120 | if (test__floattisf(a: make_ti(h: 0x0007FB72E4000000LL, l: 0), expected: 0x1.FEDCB8p+114F)) |
| 121 | return 1; |
| 122 | |
| 123 | #else |
| 124 | printf("skipped\n" ); |
| 125 | #endif |
| 126 | return 0; |
| 127 | } |
| 128 | |