Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / floatditf_test.c
blob29761d7c8eabc151a60288763092fae9927ec4ba
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_floatditf
4 #include "int_lib.h"
5 #include <complex.h>
6 #include <math.h>
7 #include <stdio.h>
9 // The testcase currently assumes IEEE TF format, once that has been
10 // fixed the defined(CRT_HAS_IEEE_TF) guard can be removed to enable it for
11 // IBM 128 floats as well.
12 #if defined(CRT_HAS_IEEE_TF)
14 # include "fp_test.h"
16 // Returns: long integer converted to tf_float
18 COMPILER_RT_ABI tf_float __floatditf(di_int a);
20 int test__floatditf(di_int a, uint64_t expectedHi, uint64_t expectedLo) {
21 tf_float x = __floatditf(a);
22 int ret = compareResultF128(x, expectedHi, expectedLo);
24 if (ret)
25 printf("error in __floatditf(%Ld) = %.20Lf, "
26 "expected %.20Lf\n",
27 a, x, fromRep128(expectedHi, expectedLo));
28 return ret;
31 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
33 #endif
35 int main() {
36 #if defined(CRT_HAS_IEEE_TF)
37 if (test__floatditf(0x7fffffffffffffff, UINT64_C(0x403dffffffffffff),
38 UINT64_C(0xfffc000000000000)))
39 return 1;
40 if (test__floatditf(0x123456789abcdef1, UINT64_C(0x403b23456789abcd),
41 UINT64_C(0xef10000000000000)))
42 return 1;
43 if (test__floatditf(0x2, UINT64_C(0x4000000000000000), UINT64_C(0x0)))
44 return 1;
45 if (test__floatditf(0x1, UINT64_C(0x3fff000000000000), UINT64_C(0x0)))
46 return 1;
47 if (test__floatditf(0x0, UINT64_C(0x0), UINT64_C(0x0)))
48 return 1;
49 if (test__floatditf(0xffffffffffffffff, UINT64_C(0xbfff000000000000),
50 UINT64_C(0x0)))
51 return 1;
52 if (test__floatditf(0xfffffffffffffffe, UINT64_C(0xc000000000000000),
53 UINT64_C(0x0)))
54 return 1;
55 if (test__floatditf(-0x123456789abcdef1, UINT64_C(0xc03b23456789abcd),
56 UINT64_C(0xef10000000000000)))
57 return 1;
58 if (test__floatditf(0x8000000000000000, UINT64_C(0xc03e000000000000),
59 UINT64_C(0x0)))
60 return 1;
62 #else
63 printf("skipped\n");
65 #endif
66 return 0;