Skip to content

Commit 70b95ca

Browse files
authored
[libc][math] Fix sqrtf128 implicit conversions. (#127154)
This fixes rv32 buildbot failure from #122578
1 parent 8f3a070 commit 70b95ca

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

libc/src/math/generic/sqrtf128.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -383,25 +383,26 @@ LLVM_LIBC_FUNCTION(float128, sqrtf128, (float128 x)) {
383383
// 1 so just need to add shifted m and 1.
384384
Int128 t1 = t0;
385385
Int128 sgn = t0 >> 127; // sign of the difference
386-
t1 -= (m << 1) ^ sgn;
387-
t1 += 1 + sgn;
386+
Int128 m_xor_sgn = static_cast<Int128>(m << 1) ^ sgn;
387+
t1 -= m_xor_sgn;
388+
t1 += Int128(1) + sgn;
388389

389390
Int128 sgn1 = t1 >> 127;
390391
if (LIBC_UNLIKELY(sgn == sgn1)) {
391392
t0 = t1;
392393
v -= sgn << 15;
393-
t1 -= (m << 1) ^ sgn;
394-
t1 += 1 + sgn;
394+
t1 -= m_xor_sgn;
395+
t1 += Int128(1) + sgn;
395396
}
396397

397398
if (t1 == 0) {
398399
// 1 ulp offset brings again an exact root
399-
v = (m - (2 * sgn + 1)) << 15;
400+
v = (m - static_cast<UInt128>((sgn << 1) + 1)) << 15;
400401
} else {
401402
t1 += t0;
402403
Int128 side = t1 >> 127; // select what is closer m or m+-1
403404
v &= ~UInt128(0) << 15; // wipe the fractional bits
404-
v -= ((sgn & side) | (~sgn & 1)) << (15 + side);
405+
v -= ((sgn & side) | (~sgn & 1)) << (15 + static_cast<int>(side));
405406
v |= 1; // add sticky bit since we cannot have an exact mid-point
406407
// situation
407408
}

0 commit comments

Comments
 (0)