[libc-commits] [libc] 70b95ca - [libc][math] Fix sqrtf128 implicit conversions. (#127154)

via libc-commits libc-commits at lists.llvm.org
Sat Feb 15 02:11:57 PST 2025


Author: lntue
Date: 2025-02-15T05:11:54-05:00
New Revision: 70b95ca6dbee7036dcfa5995ff804471fd7e8c2a

URL: https://github.com/llvm/llvm-project/commit/70b95ca6dbee7036dcfa5995ff804471fd7e8c2a
DIFF: https://github.com/llvm/llvm-project/commit/70b95ca6dbee7036dcfa5995ff804471fd7e8c2a.diff

LOG: [libc][math] Fix sqrtf128 implicit conversions. (#127154)

This fixes rv32 buildbot failure from
https://github.com/llvm/llvm-project/pull/122578

Added: 
    

Modified: 
    libc/src/math/generic/sqrtf128.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/math/generic/sqrtf128.cpp b/libc/src/math/generic/sqrtf128.cpp
index c844d3afa11c8..3aa7db8362734 100644
--- a/libc/src/math/generic/sqrtf128.cpp
+++ b/libc/src/math/generic/sqrtf128.cpp
@@ -383,25 +383,26 @@ LLVM_LIBC_FUNCTION(float128, sqrtf128, (float128 x)) {
       // 1 so just need to add shifted m and 1.
       Int128 t1 = t0;
       Int128 sgn = t0 >> 127; // sign of the 
diff erence
-      t1 -= (m << 1) ^ sgn;
-      t1 += 1 + sgn;
+      Int128 m_xor_sgn = static_cast<Int128>(m << 1) ^ sgn;
+      t1 -= m_xor_sgn;
+      t1 += Int128(1) + sgn;
 
       Int128 sgn1 = t1 >> 127;
       if (LIBC_UNLIKELY(sgn == sgn1)) {
         t0 = t1;
         v -= sgn << 15;
-        t1 -= (m << 1) ^ sgn;
-        t1 += 1 + sgn;
+        t1 -= m_xor_sgn;
+        t1 += Int128(1) + sgn;
       }
 
       if (t1 == 0) {
         // 1 ulp offset brings again an exact root
-        v = (m - (2 * sgn + 1)) << 15;
+        v = (m - static_cast<UInt128>((sgn << 1) + 1)) << 15;
       } else {
         t1 += t0;
         Int128 side = t1 >> 127; // select what is closer m or m+-1
         v &= ~UInt128(0) << 15;  // wipe the fractional bits
-        v -= ((sgn & side) | (~sgn & 1)) << (15 + side);
+        v -= ((sgn & side) | (~sgn & 1)) << (15 + static_cast<int>(side));
         v |= 1; // add sticky bit since we cannot have an exact mid-point
                 // situation
       }


        


More information about the libc-commits mailing list