[libc-commits] [libc] 0ccec54 - [libc] Fix compilation when long double is used as float128 (#97747)
via libc-commits
libc-commits at lists.llvm.org
Thu Jul 4 09:34:42 PDT 2024
Author: Mikhail R. Gadelha
Date: 2024-07-04T13:34:39-03:00
New Revision: 0ccec541d526a1be84fdfcf8f42553965dadff78
URL: https://github.com/llvm/llvm-project/commit/0ccec541d526a1be84fdfcf8f42553965dadff78
DIFF: https://github.com/llvm/llvm-project/commit/0ccec541d526a1be84fdfcf8f42553965dadff78.diff
LOG: [libc] Fix compilation when long double is used as float128 (#97747)
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
Added:
Modified:
libc/src/__support/FPUtil/generic/FMod.h
libc/src/__support/big_int.h
libc/test/src/math/smoke/CopySignTest.h
Removed:
################################################################################
diff --git a/libc/src/__support/FPUtil/generic/FMod.h b/libc/src/__support/FPUtil/generic/FMod.h
index f840a92b1a5a2c..0b9244ebdc8a87 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 59a3912ef0f098..82a5251418854a 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 1eb323a3aa41fb..7dc6f5abe63891 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);
More information about the libc-commits
mailing list