xref: /llvm-project/compiler-rt/test/builtins/Unit/extendxftf2_test.c (revision d2ce3e9621411f3391def327f89e3a650918989f)
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_extendxftf2
3 
4 #include "int_lib.h"
5 #include <stdio.h>
6 
7 #if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) &&                          \
8     (defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
9 
10 #include "fp_test.h"
11 
12 COMPILER_RT_ABI tf_float __extendxftf2(long double a);
13 
test__extendxftf2(long double a,uint64_t expectedHi,uint64_t expectedLo)14 int test__extendxftf2(long double a, uint64_t expectedHi, uint64_t expectedLo) {
15   tf_float x = __extendxftf2(a);
16   int ret = compareResultF128(x, expectedHi, expectedLo);
17 
18   if (ret) {
19     printf("error in __extendxftf2(%.20Lf) = %.20Lf, "
20            "expected %.20Lf\n",
21            a, x, fromRep128(expectedHi, expectedLo));
22   }
23   return ret;
24 }
25 
26 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
27 
28 #endif
29 
main()30 int main() {
31 #if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) &&                          \
32     (defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
33   // qNaN
34   if (test__extendxftf2(makeQNaN80(), UINT64_C(0x7fff800000000000),
35                         UINT64_C(0x0)))
36     return 1;
37   // NaN
38   if (test__extendxftf2(makeNaN80(UINT64_C(0x3fffffffffffffff)),
39                         UINT64_C(0x7fff7fffffffffff),
40                         UINT64_C(0xfffe000000000000)))
41     return 1;
42   // inf
43   if (test__extendxftf2(makeInf80(), UINT64_C(0x7fff000000000000),
44                         UINT64_C(0x0)))
45     return 1;
46   // zero
47   if (test__extendxftf2(0.0, UINT64_C(0x0), UINT64_C(0x0)))
48     return 1;
49   if (test__extendxftf2(0x1.23456789abcdefp+5, UINT64_C(0x400423456789abcd),
50                         UINT64_C(0xf000000000000000)))
51     return 1;
52   if (test__extendxftf2(0x1.edcba987654321fp-9, UINT64_C(0x3ff6edcba9876543),
53                         UINT64_C(0x2000000000000000)))
54     return 1;
55   if (test__extendxftf2(0x1.23456789abcdefp+45, UINT64_C(0x402c23456789abcd),
56                         UINT64_C(0xf000000000000000)))
57     return 1;
58   if (test__extendxftf2(0x1.edcba987654321fp-45, UINT64_C(0x3fd2edcba9876543),
59                         UINT64_C(0x2000000000000000)))
60     return 1;
61   // denormal number
62   if (test__extendxftf2(1e-4932L, UINT64_C(0x00004c248f91e526),
63                         UINT64_C(0xafe0000000000000)))
64     return 1;
65   // denormal number
66   if (test__extendxftf2(2e-4932L, UINT64_C(0x000098491f23ca4d),
67                         UINT64_C(0x5fc0000000000000)))
68     return 1;
69 #else
70   printf("skipped\n");
71 
72 #endif
73   return 0;
74 }
75