Skip to content

Commit 06d24da

Browse files
biabbasarichardson
andauthored
Fix extendhfxf2 test (#117665)
Fix changes in #113897 Co-authored-by: Alex Richardson <[email protected]>
1 parent e846148 commit 06d24da

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,62 @@
55
#include <math.h> // for isnan, isinf
66
#include <stdio.h>
77

8-
#include "int_lib.h"
8+
#include "fp_test.h"
99

10-
#if HAS_80_BIT_LONG_DOUBLE && defined(COMPILER_RT_HAS_FLOAT16)
10+
#if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) && \
11+
defined(COMPILER_RT_HAS_FLOAT16)
1112

12-
long double __extendhfxf2(_Float16 f);
13+
xf_float __extendhfxf2(TYPE_FP16 f);
1314

14-
int test_extendhfxf2(_Float16 a, long double expected) {
15-
long double x = __extendhfxf2(a);
16-
__uint16_t *b = (void *)&a;
17-
int ret = !((isnan(x) && isnan(expected)) || x == expected);
15+
int test_extendhfxf2(TYPE_FP16 a, uint64_t expectedHi, uint64_t expectedLo) {
16+
xf_float x = __extendhfxf2(a);
17+
int ret = compareResultF80(x, expectedHi, expectedLo);
1818
if (ret) {
1919
printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
2020
"expected %.20Lf\n",
21-
*b, x, expected);
21+
toRep16(a), x, F80FromRep128(expectedHi, expectedLo));
2222
}
2323
return ret;
2424
}
2525

26-
char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0};
27-
2826
int main() {
2927
// Small positive value
30-
if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000L))
28+
if (test_extendhfxf2(fromRep16(0x2e66), UINT64_C(0x3ffb),
29+
UINT64_C(0xccc0000000000000)))
3130
return 1;
3231

3332
// Small negative value
34-
if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000L))
33+
if (test_extendhfxf2(fromRep16(0xae66), UINT64_C(0xbffb),
34+
UINT64_C(0xccc0000000000000)))
3535
return 1;
3636

3737
// Zero
38-
if (test_extendhfxf2(0.0f, 0.0L))
38+
if (test_extendhfxf2(fromRep16(0), UINT64_C(0x0), UINT64_C(0x0)))
3939
return 1;
4040

4141
// Smallest positive non-zero value
42-
if (test_extendhfxf2(0x1p-16f, 0x1p-16L))
42+
if (test_extendhfxf2(fromRep16(0x0100), UINT64_C(0x3fef),
43+
UINT64_C(0x8000000000000000)))
4344
return 1;
4445

4546
// Smallest negative non-zero value
46-
if (test_extendhfxf2(-0x1p-16f, -0x1p-16L))
47+
if (test_extendhfxf2(fromRep16(0x8100), UINT64_C(0xbfef),
48+
UINT64_C(0x8000000000000000)))
4749
return 1;
4850

4951
// Positive infinity
50-
if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x()))
52+
if (test_extendhfxf2(makeInf16(), UINT64_C(0x7fff),
53+
UINT64_C(0x8000000000000000)))
5154
return 1;
5255

5356
// Negative infinity
54-
if (test_extendhfxf2(-__builtin_huge_valf16(),
55-
(long double)-__builtin_huge_valf64x()))
57+
if (test_extendhfxf2(makeNegativeInf16(), UINT64_C(0xffff),
58+
UINT64_C(0x8000000000000000)))
5659
return 1;
5760

5861
// NaN
59-
if (test_extendhfxf2(__builtin_nanf16(""),
60-
(long double)__builtin_nanf64x("")))
62+
if (test_extendhfxf2(makeQNaN16(), UINT64_C(0x7fff),
63+
UINT64_C(0xc000000000000000)))
6164
return 1;
6265

6366
return 0;

compiler-rt/test/builtins/Unit/fp_test.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ static inline long double makeNaN80(uint64_t rand) {
265265
static inline long double makeInf80(void) {
266266
return F80FromRep128(0x7fffUL, 0x8000000000000000UL);
267267
}
268+
269+
static inline long double makeNegativeInf80(void) {
270+
return F80FromRep128(0xffffUL, 0x8000000000000000UL);
271+
}
268272
#endif
269273

270274
#if defined(CRT_HAS_TF_MODE)
@@ -299,6 +303,8 @@ static inline TYPE_FP16 makeInf16(void)
299303
return fromRep16(0x7c00U);
300304
}
301305

306+
static inline TYPE_FP16 makeNegativeInf16(void) { return fromRep16(0xfc00U); }
307+
302308
static inline float makeInf32(void)
303309
{
304310
return fromRep32(0x7f800000U);

0 commit comments

Comments
 (0)