[libc-commits] [libc] [libc] Fix compilation when long double is used as float128 (PR #97747)
via libc-commits
libc-commits at lists.llvm.org
Thu Jul 4 08:39:03 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Mikhail R. Gadelha (mikhailramalho)
<details>
<summary>Changes</summary>
Small patch that fixes the compilation when float128 is a long double, e.g., rv32. It fixes a static_cast, adds a missing %= operator and changes a cast to use get_val() in a test case instead
---
Full diff: https://github.com/llvm/llvm-project/pull/97747.diff
3 Files Affected:
- (modified) libc/src/__support/FPUtil/generic/FMod.h (+2-1)
- (modified) libc/src/__support/big_int.h (+4)
- (modified) libc/test/src/math/smoke/CopySignTest.h (+1-1)
``````````diff
diff --git a/libc/src/__support/FPUtil/generic/FMod.h b/libc/src/__support/FPUtil/generic/FMod.h
index f840a92b1a5a2..0b9244ebdc8a8 100644
--- a/libc/src/__support/FPUtil/generic/FMod.h
+++ b/libc/src/__support/FPUtil/generic/FMod.h
@@ -160,7 +160,8 @@ template <typename T> struct FModDivisionInvMultHelper {
template <typename T, typename U = typename FPBits<T>::StorageType,
typename DivisionHelper = FModDivisionSimpleHelper<U>>
class FMod {
- static_assert(cpp::is_floating_point_v<T> && cpp::is_unsigned_v<U> &&
+ static_assert(cpp::is_floating_point_v<T> &&
+ is_unsigned_integral_or_big_int_v<U> &&
(sizeof(U) * CHAR_BIT > FPBits<T>::FRACTION_LEN),
"FMod instantiated with invalid type.");
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 59a3912ef0f09..82a5251418854 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -731,6 +731,10 @@ struct BigInt {
return *result.div(other);
}
+ LIBC_INLINE constexpr BigInt operator%=(const BigInt &other) {
+ return *this->div(other);
+ }
+
LIBC_INLINE constexpr BigInt &operator*=(const BigInt &other) {
*this = *this * other;
return *this;
diff --git a/libc/test/src/math/smoke/CopySignTest.h b/libc/test/src/math/smoke/CopySignTest.h
index 1eb323a3aa41f..7dc6f5abe6389 100644
--- a/libc/test/src/math/smoke/CopySignTest.h
+++ b/libc/test/src/math/smoke/CopySignTest.h
@@ -42,9 +42,9 @@ class CopySignTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
StorageType v = 0;
for (int i = 0; i <= COUNT; ++i, v += STEP) {
FPBits x_bits = FPBits(v);
- T x = T(v);
if (x_bits.is_nan() || x_bits.is_inf())
continue;
+ T x = x_bits.get_val();
T res1 = func(x, -x);
ASSERT_FP_EQ(res1, -x);
``````````
</details>
https://github.com/llvm/llvm-project/pull/97747
More information about the libc-commits
mailing list