Skip to content

[libc] Fix compilation when long double is used as float128 #97747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

mikhailramalho
Copy link
Member

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

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
@llvmbot
Copy link
Member

llvmbot commented Jul 4, 2024

@llvm/pr-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

Changes

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 --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);

@mikhailramalho mikhailramalho merged commit 0ccec54 into llvm:main Jul 4, 2024
6 of 7 checks passed
@mikhailramalho mikhailramalho deleted the fix-float-rv32 branch July 4, 2024 16:34
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants