Skip to content

Commit 0fe9703

Browse files
committed
Extendhfxf2 test updated
1 parent 6345941 commit 0fe9703

File tree

1 file changed

+35
-49
lines changed

1 file changed

+35
-49
lines changed

compiler-rt/test/builtins/Unit/extendhfxf2_test.c

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,64 @@
11
// RUN: %clang_builtins %s %librt -o %t && %run %t
22
// REQUIRES: librt_has_extendhfxf2
33

4-
#include "int_lib.h"
4+
#include <limits.h>
5+
#include <math.h> // for isnan, isinf
56
#include <stdio.h>
67

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);
810

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) {
1412
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));
1716
if (ret) {
18-
printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
17+
printf("error in test__extendhfsf2(%#.4x) = %.20Lf, "
1918
"expected %.20Lf\n",
20-
toRep16(a), x, fromRep128(expectedHi, expectedLo));
19+
*b, x, expected);
2120
}
2221
return ret;
2322
}
2423

25-
char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0};
24+
char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0};
2625

2726
#endif
2827

2928
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))
4832
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))
5536
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))
5840
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))
6144
return 1;
6245

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))
6648
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()))
6952
return 1;
7053

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()))
7357
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("")))
7662
return 1;
7763
#else
7864
printf("skipped\n");

0 commit comments

Comments
 (0)