Skip to content

Commit e63acd3

Browse files
committed
Fix extendhfxf2_test and update fp_extend.h
1 parent ae719f0 commit e63acd3

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

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

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

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

1010
#if HAS_80_BIT_LONG_DOUBLE && defined(COMPILER_RT_HAS_FLOAT16)
1111

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

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);
14+
int test_extendhfxf2(TYPE_FP16 a, uint64_t expectedHi, uint64_t expectedLo) {
15+
xf_float x = __extendhfxf2(a);
16+
int ret = compareResultF80(x, expectedHi, expectedLo);
1817
if (ret) {
1918
printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
2019
"expected %.20Lf\n",
21-
*b, x, expected);
20+
toRep16(a), x, F80FromRep128(expectedHi, expectedLo));
2221
}
2322
return ret;
2423
}
2524

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

3331
// Small negative value
34-
if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000L))
32+
if (test_extendhfxf2(fromRep16(0xae66), UINT64_C(0xbffb),
33+
UINT64_C(0xccc0000000000000)))
3534
return 1;
3635

3736
// Zero
38-
if (test_extendhfxf2(0.0f, 0.0L))
37+
if (test_extendhfxf2(fromRep16(0), UINT64_C(0x0), UINT64_C(0x0)))
3938
return 1;
4039

4140
// Smallest positive non-zero value
42-
if (test_extendhfxf2(0x1p-16f, 0x1p-16L))
41+
if (test_extendhfxf2(fromRep16(0x0100), UINT64_C(0x3fef),
42+
UINT64_C(0x8000000000000000)))
4343
return 1;
4444

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

4950
// Positive infinity
50-
if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x()))
51+
if (test_extendhfxf2(makeInf16(), UINT64_C(0x7fff),
52+
UINT64_C(0x8000000000000000)))
5153
return 1;
5254

5355
// Negative infinity
54-
if (test_extendhfxf2(-__builtin_huge_valf16(),
55-
(long double)-__builtin_huge_valf64x()))
56+
if (test_extendhfxf2(makeNegativeInf16(), UINT64_C(0xffff),
57+
UINT64_C(0x8000000000000000)))
5658
return 1;
5759

5860
// NaN
59-
if (test_extendhfxf2(__builtin_nanf16(""),
60-
(long double)__builtin_nanf64x("")))
61+
if (test_extendhfxf2(makeQNaN16(), UINT64_C(0x7fff),
62+
UINT64_C(0xc000000000000000)))
6163
return 1;
6264

6365
return 0;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static inline double makeQNaN64(void)
230230
return fromRep64(0x7ff8000000000000UL);
231231
}
232232

233-
#if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__)
233+
#if HAS_80_BIT_LONG_DOUBLE
234234
static inline long double F80FromRep128(uint64_t hi, uint64_t lo) {
235235
__uint128_t x = ((__uint128_t)hi << 64) + lo;
236236
long double ret;
@@ -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)