| 1 | // XFAIL: target=aarch64-{{.*}}-windows-{{.*}} |
| 2 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 3 | // REQUIRES: librt_has_fixunstfdi |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | #if _ARCH_PPC || __aarch64__ || __arm64ec__ |
| 8 | |
| 9 | #include "int_lib.h" |
| 10 | |
| 11 | // Returns: convert a to a unsigned long long, rounding toward zero. |
| 12 | // Negative values all become zero. |
| 13 | |
| 14 | // Assumption: long double is a 128 bit floating point type |
| 15 | // du_int is a 64 bit integral type |
| 16 | // value in long double is representable in du_int or is negative |
| 17 | // (no range checking performed) |
| 18 | |
| 19 | COMPILER_RT_ABI du_int __fixunstfdi(long double a); |
| 20 | |
| 21 | int test__fixunstfdi(long double a, du_int expected) |
| 22 | { |
| 23 | du_int x = __fixunstfdi(a); |
| 24 | if (x != expected) |
| 25 | printf("error in __fixunstfdi(%LA) = %llX, expected %llX\n" , |
| 26 | a, x, expected); |
| 27 | return x != expected; |
| 28 | } |
| 29 | |
| 30 | char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0}; |
| 31 | char assumption_2[sizeof(du_int)*CHAR_BIT == 64] = {0}; |
| 32 | char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; |
| 33 | |
| 34 | #endif |
| 35 | |
| 36 | int main() |
| 37 | { |
| 38 | #if _ARCH_PPC || __aarch64__ || __arm64ec__ |
| 39 | if (test__fixunstfdi(0.0, 0)) |
| 40 | return 1; |
| 41 | |
| 42 | if (test__fixunstfdi(0.5, 0)) |
| 43 | return 1; |
| 44 | if (test__fixunstfdi(0.99, 0)) |
| 45 | return 1; |
| 46 | if (test__fixunstfdi(1.0, 1)) |
| 47 | return 1; |
| 48 | if (test__fixunstfdi(1.5, 1)) |
| 49 | return 1; |
| 50 | if (test__fixunstfdi(1.99, 1)) |
| 51 | return 1; |
| 52 | if (test__fixunstfdi(2.0, 2)) |
| 53 | return 1; |
| 54 | if (test__fixunstfdi(2.01, 2)) |
| 55 | return 1; |
| 56 | if (test__fixunstfdi(-0.5, 0)) |
| 57 | return 1; |
| 58 | if (test__fixunstfdi(-0.99, 0)) |
| 59 | return 1; |
| 60 | if (test__fixunstfdi(-1.0, 0)) |
| 61 | return 1; |
| 62 | if (test__fixunstfdi(-1.5, 0)) |
| 63 | return 1; |
| 64 | if (test__fixunstfdi(-1.99, 0)) |
| 65 | return 1; |
| 66 | if (test__fixunstfdi(-2.0, 0)) |
| 67 | return 1; |
| 68 | if (test__fixunstfdi(-2.01, 0)) |
| 69 | return 1; |
| 70 | |
| 71 | if (test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL)) |
| 72 | return 1; |
| 73 | if (test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL)) |
| 74 | return 1; |
| 75 | |
| 76 | if (test__fixunstfdi(-0x1.FFFFFEp+62, 0)) |
| 77 | return 1; |
| 78 | if (test__fixunstfdi(-0x1.FFFFFCp+62, 0)) |
| 79 | return 1; |
| 80 | |
| 81 | if (test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL)) |
| 82 | return 1; |
| 83 | if (test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL)) |
| 84 | return 1; |
| 85 | |
| 86 | if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0)) |
| 87 | return 1; |
| 88 | if (test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0)) |
| 89 | return 1; |
| 90 | |
| 91 | if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL)) |
| 92 | return 1; |
| 93 | if (test__fixunstfdi(0x1.0000000000000002p+63L, 0x8000000000000001LL)) |
| 94 | return 1; |
| 95 | if (test__fixunstfdi(0x1.0000000000000000p+63L, 0x8000000000000000LL)) |
| 96 | return 1; |
| 97 | if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL)) |
| 98 | return 1; |
| 99 | if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL)) |
| 100 | return 1; |
| 101 | if (test__fixunstfdi(0x1.p+64L, 0xFFFFFFFFFFFFFFFFLL)) |
| 102 | return 1; |
| 103 | |
| 104 | if (test__fixunstfdi(-0x1.0000000000000000p+63L, 0)) |
| 105 | return 1; |
| 106 | if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0)) |
| 107 | return 1; |
| 108 | if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0)) |
| 109 | return 1; |
| 110 | |
| 111 | #else |
| 112 | printf(format: "skipped\n" ); |
| 113 | #endif |
| 114 | return 0; |
| 115 | } |
| 116 | |