[compiler-rt] Fix extendhfxf2 test (PR #117665)
B I Mohammed Abbas via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 25 21:08:06 PST 2024
https://github.com/biabbas updated https://github.com/llvm/llvm-project/pull/117665
>From fdad6bc8330ecf3d2661cb96fca504c8a6c0796e Mon Sep 17 00:00:00 2001
From: B I Mohammed Abbas <bimohammadabbas at gmail.com>
Date: Tue, 26 Nov 2024 10:05:18 +0530
Subject: [PATCH 1/2] Fix extendhfxf2 test
---
.../test/builtins/Unit/extendhfxf2_test.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/compiler-rt/test/builtins/Unit/extendhfxf2_test.c b/compiler-rt/test/builtins/Unit/extendhfxf2_test.c
index 80e6f78cdd9c4f..bbcfb520d3bf18 100644
--- a/compiler-rt/test/builtins/Unit/extendhfxf2_test.c
+++ b/compiler-rt/test/builtins/Unit/extendhfxf2_test.c
@@ -5,15 +5,15 @@
#include <math.h> // for isnan, isinf
#include <stdio.h>
-#include "int_lib.h"
+#include "fp_test.h"
#if HAS_80_BIT_LONG_DOUBLE && defined(COMPILER_RT_HAS_FLOAT16)
-long double __extendhfxf2(_Float16 f);
+long double __extendhfxf2(TYPE_FP16 f);
-int test_extendhfxf2(_Float16 a, long double expected) {
+int test_extendhfxf2(TYPE_FP16 a, long double expected) {
long double x = __extendhfxf2(a);
- __uint16_t *b = (void *)&a;
+ unsigned short *b = (void *)&a;
int ret = !((isnan(x) && isnan(expected)) || x == expected);
if (ret) {
printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
@@ -23,8 +23,6 @@ int test_extendhfxf2(_Float16 a, long double expected) {
return ret;
}
-char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0};
-
int main() {
// Small positive value
if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000L))
@@ -46,6 +44,7 @@ int main() {
if (test_extendhfxf2(-0x1p-16f, -0x1p-16L))
return 1;
+# ifdef __builtin_huge_valf64x
// Positive infinity
if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x()))
return 1;
@@ -55,11 +54,16 @@ int main() {
(long double)-__builtin_huge_valf64x()))
return 1;
+# endif
+
+# ifdef __builtin_nanf64x
// NaN
if (test_extendhfxf2(__builtin_nanf16(""),
(long double)__builtin_nanf64x("")))
return 1;
+# endif
+
return 0;
}
>From 89c09d976d3a78264100ec09bf494453731d126d Mon Sep 17 00:00:00 2001
From: B I Mohammed Abbas <bimohammadabbas at gmail.com>
Date: Tue, 26 Nov 2024 10:37:53 +0530
Subject: [PATCH 2/2] Changes from review
---
.../test/builtins/Unit/extendhfxf2_test.c | 25 +++++++------------
compiler-rt/test/builtins/Unit/fp_test.h | 9 +++++++
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/compiler-rt/test/builtins/Unit/extendhfxf2_test.c b/compiler-rt/test/builtins/Unit/extendhfxf2_test.c
index bbcfb520d3bf18..474c733f6ddaea 100644
--- a/compiler-rt/test/builtins/Unit/extendhfxf2_test.c
+++ b/compiler-rt/test/builtins/Unit/extendhfxf2_test.c
@@ -11,14 +11,14 @@
long double __extendhfxf2(TYPE_FP16 f);
-int test_extendhfxf2(TYPE_FP16 a, long double expected) {
- long double x = __extendhfxf2(a);
- unsigned short *b = (void *)&a;
- int ret = !((isnan(x) && isnan(expected)) || x == expected);
+int test_extendhfxf2(TYPE_FP16 a, xf_float expected) {
+ xf_float x = __extendhfxf2(a);
+ uint16_t a_rep = toRep16(a);
+ int ret = compareResultF80(x, expected);
if (ret) {
printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
"expected %.20Lf\n",
- *b, x, expected);
+ a_rep, x, expected);
}
return ret;
}
@@ -44,26 +44,19 @@ int main() {
if (test_extendhfxf2(-0x1p-16f, -0x1p-16L))
return 1;
-# ifdef __builtin_huge_valf64x
// Positive infinity
- if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x()))
+ if (test_extendhfxf2(makeInf16(), makeInf80()))
return 1;
// Negative infinity
- if (test_extendhfxf2(-__builtin_huge_valf16(),
- (long double)-__builtin_huge_valf64x()))
+ if (test_extendhfxf2(makeNegativeInf16(),
+ makeNegativeInf80()))
return 1;
-# endif
-
-# ifdef __builtin_nanf64x
// NaN
- if (test_extendhfxf2(__builtin_nanf16(""),
- (long double)__builtin_nanf64x("")))
+ if (test_extendhfxf2(makeQNaN16(), makeQNaN80()))
return 1;
-# endif
-
return 0;
}
diff --git a/compiler-rt/test/builtins/Unit/fp_test.h b/compiler-rt/test/builtins/Unit/fp_test.h
index 4eb54b7425c107..56bae062075c0e 100644
--- a/compiler-rt/test/builtins/Unit/fp_test.h
+++ b/compiler-rt/test/builtins/Unit/fp_test.h
@@ -265,6 +265,10 @@ static inline long double makeNaN80(uint64_t rand) {
static inline long double makeInf80(void) {
return F80FromRep128(0x7fffUL, 0x8000000000000000UL);
}
+
+static inline long double makeNegativeInf80(void) {
+ return F80FromRep128(0xffffUL, 0x8000000000000000UL);
+}
#endif
#if defined(CRT_HAS_TF_MODE)
@@ -299,6 +303,11 @@ static inline TYPE_FP16 makeInf16(void)
return fromRep16(0x7c00U);
}
+static inline TYPE_FP16 makeNegativeInf16(void)
+{
+ return fromRep16(0xfc00U);
+}
+
static inline float makeInf32(void)
{
return fromRep32(0x7f800000U);
More information about the llvm-commits
mailing list