[libc-commits] [libc] [libc][math][c23] Add f16fmaf C23 math function (PR #95483)
via libc-commits
libc-commits at lists.llvm.org
Thu Jun 13 16:09:03 PDT 2024
================
@@ -198,46 +230,40 @@ template <> LIBC_INLINE double fma<double>(double x, double y, double z) {
}
}
- uint64_t result = 0;
+ OutStorageType result = 0;
int r_exp = 0; // Unbiased exponent of the result
// Normalize the result.
if (prod_mant != 0) {
- uint64_t prod_hi = static_cast<uint64_t>(prod_mant >> 64);
- int lead_zeros =
- prod_hi ? cpp::countl_zero(prod_hi)
- : 64 + cpp::countl_zero(static_cast<uint64_t>(prod_mant));
+ int lead_zeros = cpp::countl_zero(prod_mant);
// Move the leading 1 to the most significant bit.
prod_mant <<= lead_zeros;
- // The lower 64 bits are always sticky bits after moving the leading 1 to
- // the most significant bit.
- sticky_bits |= (static_cast<uint64_t>(prod_mant) != 0);
- result = static_cast<uint64_t>(prod_mant >> 64);
- // Change prod_lsb_exp the be the exponent of the least significant bit of
- // the result.
- prod_lsb_exp += 64 - lead_zeros;
- r_exp = prod_lsb_exp + 63;
+ prod_lsb_exp -= lead_zeros;
+ r_exp = prod_lsb_exp + (cpp::numeric_limits<TmpResultType>::digits - 1) -
+ InFPBits::EXP_BIAS + OutFPBits::EXP_BIAS;
if (r_exp > 0) {
// The result is normal. We will shift the mantissa to the right by
// 63 - 52 = 11 bits (from the locations of the most significant bit).
// Then the rounding bit will correspond the 11th bit, and the lowest
// 10 bits are merged into sticky bits.
----------------
overmighty wrote:
I need to update these comments.
https://github.com/llvm/llvm-project/pull/95483
More information about the libc-commits
mailing list