| 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 2 | // REQUIRES: librt_has_fixtfti |
| 3 | |
| 4 | #include "int_lib.h" |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | #if __LDBL_MANT_DIG__ == 113 |
| 8 | |
| 9 | #include "fp_test.h" |
| 10 | |
| 11 | ti_int __fixtfti(long double a); |
| 12 | |
| 13 | int test__fixtfti(long double a, ti_int expected) |
| 14 | { |
| 15 | ti_int x = __fixtfti(a); |
| 16 | int ret = (x != expected); |
| 17 | |
| 18 | if (ret) |
| 19 | { |
| 20 | twords xt; |
| 21 | xt.all = x; |
| 22 | |
| 23 | twords expectedt; |
| 24 | expectedt.all = expected; |
| 25 | |
| 26 | printf("error in test__fixtfti(%.20Lf) = 0x%.16llX%.16llX, " |
| 27 | "expected 0x%.16llX%.16llX\n" , |
| 28 | a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); |
| 29 | } |
| 30 | return ret; |
| 31 | } |
| 32 | |
| 33 | char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; |
| 34 | |
| 35 | #endif |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | #if __LDBL_MANT_DIG__ == 113 |
| 40 | if (test__fixtfti(makeInf128(), make_ti(0x7fffffffffffffffLL, |
| 41 | 0xffffffffffffffffLL))) |
| 42 | return 1; |
| 43 | if (test__fixtfti(0, make_ti(0x0LL, 0x0LL))) |
| 44 | return 1; |
| 45 | if (test__fixtfti(0x1.23456789abcdefp+5L, make_ti(0x0LL, 0x24LL))) |
| 46 | return 1; |
| 47 | if (test__fixtfti(0x1.23456789abcdefp-3L, make_ti(0x0LL, 0x0LL))) |
| 48 | return 1; |
| 49 | if (test__fixtfti(0x1.23456789abcdef12345678p+20L, |
| 50 | make_ti(0x0LL, 0x123456LL))) |
| 51 | return 1; |
| 52 | if (test__fixtfti(0x1.23456789abcdef123456789abcdep+112L, |
| 53 | make_ti(0x123456789abcdLL, 0xef123456789abcdeLL))) |
| 54 | return 1; |
| 55 | if (test__fixtfti(-0x1.23456789abcdef123456789abcdep+112L, |
| 56 | make_ti(0xFFFEDCBA98765432LL, 0x10EDCBA987654322LL))) |
| 57 | return 1; |
| 58 | if (test__fixtfti(0x1.23456789abcdefp+256L, make_ti(0x7fffffffffffffffLL, |
| 59 | 0xffffffffffffffffLL))) |
| 60 | return 1; |
| 61 | if (test__fixtfti(-0x1.23456789abcdefp+20L, make_ti(0xffffffffffffffffLL, |
| 62 | 0xffffffffffedcbaaLL))) |
| 63 | return 1; |
| 64 | if (test__fixtfti(-0x1.23456789abcdefp+256L, make_ti(0x8000000000000000LL, |
| 65 | 0x0))) |
| 66 | return 1; |
| 67 | |
| 68 | #else |
| 69 | printf(format: "skipped\n" ); |
| 70 | |
| 71 | #endif |
| 72 | return 0; |
| 73 | } |
| 74 | |