[libc-commits] [libc] [libc][math][c23] Fix setpayloadsig smoke test on RV32 (PR #102538)
Job Henandez Lara via libc-commits
libc-commits at lists.llvm.org
Thu Aug 8 17:17:47 PDT 2024
https://github.com/Jobhdez updated https://github.com/llvm/llvm-project/pull/102538
>From 76d04246ab751b647f7b15b85feec0a3147aa595 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Thu, 8 Aug 2024 14:03:00 -0700
Subject: [PATCH 1/5] fix bug
---
libc/test/src/math/smoke/SetPayloadSigTest.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/libc/test/src/math/smoke/SetPayloadSigTest.h b/libc/test/src/math/smoke/SetPayloadSigTest.h
index 7ec3ac08a180a..023a04554d0db 100644
--- a/libc/test/src/math/smoke/SetPayloadSigTest.h
+++ b/libc/test/src/math/smoke/SetPayloadSigTest.h
@@ -35,7 +35,13 @@ class SetPayloadSigTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_EQ(1, func(&res, T(-1.0)));
EXPECT_EQ(1, func(&res, T(0x42.1p+0)));
EXPECT_EQ(1, func(&res, T(-0x42.1p+0)));
- EXPECT_EQ(1, func(&res, T(StorageType(1) << (FPBits::FRACTION_LEN - 1))));
+
+ FPBits default_snan_payload_bits = FPBits::one();
+ default_snan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 1 +
+ FPBits::EXP_BIAS);
+ T default_snan_payload = default_snan_payload_bits.get_val();
+
+ EXPECT_EQ(1, func(&res, default_snan_payload));
}
void testValidPayloads(SetPayloadSigFunc func) {
>From 6c89a05ebfa7e0616c7d13b793e259078fa0e9f4 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Thu, 8 Aug 2024 14:03:25 -0700
Subject: [PATCH 2/5] format code
---
libc/test/src/math/smoke/SetPayloadSigTest.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/math/smoke/SetPayloadSigTest.h b/libc/test/src/math/smoke/SetPayloadSigTest.h
index 023a04554d0db..67eb0d0a0bfaf 100644
--- a/libc/test/src/math/smoke/SetPayloadSigTest.h
+++ b/libc/test/src/math/smoke/SetPayloadSigTest.h
@@ -40,7 +40,7 @@ class SetPayloadSigTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
default_snan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 1 +
FPBits::EXP_BIAS);
T default_snan_payload = default_snan_payload_bits.get_val();
-
+
EXPECT_EQ(1, func(&res, default_snan_payload));
}
>From 924c032fae9b18314e52ea38aa72f0453de9fe9f Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Thu, 8 Aug 2024 15:06:03 -0700
Subject: [PATCH 3/5] address review
---
libc/test/src/math/smoke/SetPayloadSigTest.h | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/libc/test/src/math/smoke/SetPayloadSigTest.h b/libc/test/src/math/smoke/SetPayloadSigTest.h
index 67eb0d0a0bfaf..b3a31d30c2bf2 100644
--- a/libc/test/src/math/smoke/SetPayloadSigTest.h
+++ b/libc/test/src/math/smoke/SetPayloadSigTest.h
@@ -40,7 +40,7 @@ class SetPayloadSigTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
default_snan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 1 +
FPBits::EXP_BIAS);
T default_snan_payload = default_snan_payload_bits.get_val();
-
+
EXPECT_EQ(1, func(&res, default_snan_payload));
}
@@ -61,11 +61,15 @@ class SetPayloadSigTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_TRUE(FPBits(res).is_signaling_nan());
EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x123).uintval(),
FPBits(res).uintval());
-
- EXPECT_EQ(0, func(&res, T(FPBits::FRACTION_MASK >> 1)));
+
+ FPBits nan_payload_bits = FPBits::one();
+ nan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 2 +
+ FPBits::EXP_BIAS);
+ T nan_payload = nan_payload_bits.get_val();
+ EXPECT_EQ(0, func(&res, nan_payload));
EXPECT_TRUE(FPBits(res).is_signaling_nan());
EXPECT_EQ(
- FPBits::signaling_nan(Sign::POS, FPBits::FRACTION_MASK >> 1).uintval(),
+ FPBits::signaling_nan(Sign::POS, nan_payload).uintval(),
FPBits(res).uintval());
}
};
>From 98d2080a6d538aef957e0d2cae347301e43f6db7 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Thu, 8 Aug 2024 15:06:23 -0700
Subject: [PATCH 4/5] format code
---
libc/test/src/math/smoke/SetPayloadSigTest.h | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/libc/test/src/math/smoke/SetPayloadSigTest.h b/libc/test/src/math/smoke/SetPayloadSigTest.h
index b3a31d30c2bf2..34fe7d351bc7f 100644
--- a/libc/test/src/math/smoke/SetPayloadSigTest.h
+++ b/libc/test/src/math/smoke/SetPayloadSigTest.h
@@ -40,7 +40,7 @@ class SetPayloadSigTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
default_snan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 1 +
FPBits::EXP_BIAS);
T default_snan_payload = default_snan_payload_bits.get_val();
-
+
EXPECT_EQ(1, func(&res, default_snan_payload));
}
@@ -61,16 +61,15 @@ class SetPayloadSigTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_TRUE(FPBits(res).is_signaling_nan());
EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x123).uintval(),
FPBits(res).uintval());
-
+
FPBits nan_payload_bits = FPBits::one();
nan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 2 +
FPBits::EXP_BIAS);
T nan_payload = nan_payload_bits.get_val();
EXPECT_EQ(0, func(&res, nan_payload));
EXPECT_TRUE(FPBits(res).is_signaling_nan());
- EXPECT_EQ(
- FPBits::signaling_nan(Sign::POS, nan_payload).uintval(),
- FPBits(res).uintval());
+ EXPECT_EQ(FPBits::signaling_nan(Sign::POS, nan_payload).uintval(),
+ FPBits(res).uintval());
}
};
>From 791859458cfbe40cc90e58893011cb827932fa8e Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Thu, 8 Aug 2024 17:17:28 -0700
Subject: [PATCH 5/5] address review
---
libc/test/src/math/smoke/SetPayloadSigTest.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libc/test/src/math/smoke/SetPayloadSigTest.h b/libc/test/src/math/smoke/SetPayloadSigTest.h
index 34fe7d351bc7f..65eb653cb9e33 100644
--- a/libc/test/src/math/smoke/SetPayloadSigTest.h
+++ b/libc/test/src/math/smoke/SetPayloadSigTest.h
@@ -40,7 +40,7 @@ class SetPayloadSigTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
default_snan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 1 +
FPBits::EXP_BIAS);
T default_snan_payload = default_snan_payload_bits.get_val();
-
+
EXPECT_EQ(1, func(&res, default_snan_payload));
}
@@ -61,15 +61,17 @@ class SetPayloadSigTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_TRUE(FPBits(res).is_signaling_nan());
EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x123).uintval(),
FPBits(res).uintval());
-
+
FPBits nan_payload_bits = FPBits::one();
nan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 2 +
FPBits::EXP_BIAS);
+ nan_payload_bits.set_mantissa(FPBits::SIG_MASK - 3);
T nan_payload = nan_payload_bits.get_val();
EXPECT_EQ(0, func(&res, nan_payload));
EXPECT_TRUE(FPBits(res).is_signaling_nan());
- EXPECT_EQ(FPBits::signaling_nan(Sign::POS, nan_payload).uintval(),
- FPBits(res).uintval());
+ EXPECT_EQ(
+ FPBits::signaling_nan(Sign::POS, FPBits::FRACTION_MASK >> 1).uintval(),
+ FPBits(res).uintval());
}
};
More information about the libc-commits
mailing list