|
1 | 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t
|
2 | 2 | // REQUIRES: librt_has_extendhfxf2
|
3 | 3 |
|
4 |
| -#include "int_lib.h" |
| 4 | +#include <limits.h> |
| 5 | +#include <math.h> // for isnan, isinf |
5 | 6 | #include <stdio.h>
|
6 | 7 |
|
7 |
| -#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16) |
| 8 | +#if __LDBL_MANT_DIG__ >= 64 && defined(COMPILER_RT_HAS_FLOAT16) |
| 9 | +long double __extendhfxf2(_Float16 f); |
8 | 10 |
|
9 |
| -# include "fp_test.h" |
10 |
| - |
11 |
| -COMPILER_RT_ABI long double __extendhfxf2(TYPE_FP16 a); |
12 |
| - |
13 |
| -int test__extendhfxf2(TYPE_FP16 a, uint64_t expectedHi, uint64_t expectedLo) { |
| 11 | +int test_extendhfxf2(_Float16 a, long double expected) { |
14 | 12 | long double x = __extendhfxf2(a);
|
15 |
| - int ret = compareResultF128(x, expectedHi, expectedLo); |
16 |
| - |
| 13 | + __uint16_t *b = (void *)&a; |
| 14 | + int ret = !(x == expected || (isnan(x) && isnan(expected)) || |
| 15 | + (isinf(x) && isinf(expected) && x == expected)); |
17 | 16 | if (ret) {
|
18 |
| - printf("error in test__extendhfxf2(%#.4x) = %.20Lf, " |
| 17 | + printf("error in test__extendhfsf2(%#.4x) = %.20Lf, " |
19 | 18 | "expected %.20Lf\n",
|
20 |
| - toRep16(a), x, fromRep128(expectedHi, expectedLo)); |
| 19 | + *b, x, expected); |
21 | 20 | }
|
22 | 21 | return ret;
|
23 | 22 | }
|
24 | 23 |
|
25 |
| -char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0}; |
| 24 | +char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0}; |
26 | 25 |
|
27 | 26 | #endif
|
28 | 27 |
|
29 | 28 | int main() {
|
30 |
| -#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16) |
31 |
| - // qNaN |
32 |
| - if (test__extendhfxf2(makeQNaN16(), UINT64_C(0x7fff800000000000), |
33 |
| - UINT64_C(0x0))) |
34 |
| - return 1; |
35 |
| - // NaN |
36 |
| - if (test__extendhfxf2(makeNaN16(UINT16_C(0x0100)), |
37 |
| - UINT64_C(0x7fff400000000000), UINT64_C(0x0))) |
38 |
| - return 1; |
39 |
| - // inf |
40 |
| - if (test__extendhfxf2(makeInf16(), UINT64_C(0x7fff000000000000), |
41 |
| - UINT64_C(0x0))) |
42 |
| - return 1; |
43 |
| - if (test__extendhfxf2(-makeInf16(), UINT64_C(0xffff000000000000), |
44 |
| - UINT64_C(0x0))) |
45 |
| - return 1; |
46 |
| - // zero |
47 |
| - if (test__extendhfxf2(fromRep16(0x0U), UINT64_C(0x0), UINT64_C(0x0))) |
| 29 | +#if __LDBL_MANT_DIG__ >= 64 && defined(COMPILER_RT_HAS_FLOAT16) |
| 30 | + // Small positive value |
| 31 | + if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000L)) |
48 | 32 | return 1;
|
49 |
| - if (test__extendhfxf2(fromRep16(0x8000U), UINT64_C(0x8000000000000000), |
50 |
| - UINT64_C(0x0))) |
51 |
| - return 1; |
52 |
| - // denormal |
53 |
| - if (test__extendhfxf2(fromRep16(0x0010U), UINT64_C(0x3feb000000000000), |
54 |
| - UINT64_C(0x0000000000000000))) |
| 33 | + |
| 34 | + // Small negative value |
| 35 | + if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000L)) |
55 | 36 | return 1;
|
56 |
| - if (test__extendhfxf2(fromRep16(0x0001U), UINT64_C(0x3fe7000000000000), |
57 |
| - UINT64_C(0x0000000000000000))) |
| 37 | + |
| 38 | + // Zero |
| 39 | + if (test_extendhfxf2(0.0f, 0.0L)) |
58 | 40 | return 1;
|
59 |
| - if (test__extendhfxf2(fromRep16(0x8001U), UINT64_C(0xbfe7000000000000), |
60 |
| - UINT64_C(0x0000000000000000))) |
| 41 | + |
| 42 | + // Smallest positive non-zero value |
| 43 | + if (test_extendhfxf2(0x1p-16f, 0x1p-16L)) |
61 | 44 | return 1;
|
62 | 45 |
|
63 |
| - // pi |
64 |
| - if (test__extendhfxf2(fromRep16(0x4248U), UINT64_C(0x4000920000000000), |
65 |
| - UINT64_C(0x0000000000000000))) |
| 46 | + // Smallest negative non-zero value |
| 47 | + if (test_extendhfxf2(-0x1p-16f, -0x1p-16L)) |
66 | 48 | return 1;
|
67 |
| - if (test__extendhfxf2(fromRep16(0xc248U), UINT64_C(0xc000920000000000), |
68 |
| - UINT64_C(0x0000000000000000))) |
| 49 | + |
| 50 | + // Positive infinity |
| 51 | + if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x())) |
69 | 52 | return 1;
|
70 | 53 |
|
71 |
| - if (test__extendhfxf2(fromRep16(0x508cU), UINT64_C(0x4004230000000000), |
72 |
| - UINT64_C(0x0))) |
| 54 | + // Negative infinity |
| 55 | + if (test_extendhfxf2(-__builtin_huge_valf16(), |
| 56 | + (long double)-__builtin_huge_valf64x())) |
73 | 57 | return 1;
|
74 |
| - if (test__extendhfxf2(fromRep16(0x1bb7U), UINT64_C(0x3ff6edc000000000), |
75 |
| - UINT64_C(0x0))) |
| 58 | + |
| 59 | + // NaN |
| 60 | + if (test_extendhfxf2(__builtin_nanf16(""), |
| 61 | + (long double)__builtin_nanf64x(""))) |
76 | 62 | return 1;
|
77 | 63 | #else
|
78 | 64 | printf("skipped\n");
|
|
0 commit comments