Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / fixunstfti_test.c
blob2812b282667f51de10d17269389fd1ac2cc00063
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunstfti
3 // UNSUPPORTED: target=mips{{.*}}
5 #include <stdio.h>
8 #if __LDBL_MANT_DIG__ == 113
10 #include "fp_test.h"
11 #include "int_lib.h"
13 // Returns: convert a to a unsigned long long, rounding toward zero.
14 // Negative values all become zero.
16 // Assumption: long double is a 128 bit floating point type
17 // tu_int is a 128 bit integral type
18 // value in long double is representable in tu_int or is negative
19 // (no range checking performed)
21 COMPILER_RT_ABI tu_int __fixunstfti(long double a);
23 int test__fixunstfti(long double a, tu_int expected)
25 tu_int x = __fixunstfti(a);
26 if (x != expected)
28 twords xt;
29 xt.all = x;
31 twords expectedt;
32 expectedt.all = expected;
34 printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, "
35 "expected 0x%.16llX%.16llX\n",
36 a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
38 return x != expected;
41 char assumption_1[sizeof(tu_int) == 4*sizeof(su_int)] = {0};
42 char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
43 char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
45 #endif
47 int main()
49 #if __LDBL_MANT_DIG__ == 113
50 if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL,
51 0xffffffffffffffffLL)))
52 return 1;
54 if (test__fixunstfti(0.0, 0))
55 return 1;
57 if (test__fixunstfti(0.5, 0))
58 return 1;
59 if (test__fixunstfti(0.99, 0))
60 return 1;
61 if (test__fixunstfti(1.0, 1))
62 return 1;
63 if (test__fixunstfti(1.5, 1))
64 return 1;
65 if (test__fixunstfti(1.99, 1))
66 return 1;
67 if (test__fixunstfti(2.0, 2))
68 return 1;
69 if (test__fixunstfti(2.01, 2))
70 return 1;
71 if (test__fixunstfti(-0.01, 0))
72 return 1;
73 if (test__fixunstfti(-0.99, 0))
74 return 1;
76 if (test__fixunstfti(0x1.p+128, make_ti(0xffffffffffffffffLL,
77 0xffffffffffffffffLL)))
78 return 1;
80 if (test__fixunstfti(0x1.FFFFFEp+126, make_ti(0x7fffff8000000000LL, 0x0)))
81 return 1;
82 if (test__fixunstfti(0x1.FFFFFEp+127, make_ti(0xffffff0000000000LL, 0x0)))
83 return 1;
84 if (test__fixunstfti(0x1.FFFFFEp+128, make_ti(0xffffffffffffffffLL,
85 0xffffffffffffffffLL)))
86 return 1;
87 if (test__fixunstfti(0x1.FFFFFEp+129, make_ti(0xffffffffffffffffLL,
88 0xffffffffffffffffLL)))
89 return 1;
91 #else
92 printf("skipped\n");
93 #endif
94 return 0;