Skip to content

Commit 8196129

Browse files
committed
fixup! [libc][math][c23] Add {f,d}mul{l,f128} and f16mul{,f,l,f128} C23 math functions
Switch to fputil::quick_mul.
1 parent 780bc8e commit 8196129

File tree

1 file changed

+4
-19
lines changed
  • libc/src/__support/FPUtil/generic

1 file changed

+4
-19
lines changed

libc/src/__support/FPUtil/generic/mul.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Division of IEEE 754 floating-point numbers -------------*- C++ -*-===//
1+
//===-- Multiplication of IEEE 754 floating-point numbers -------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -35,9 +35,8 @@ mul(InType x, InType y) {
3535
using InFPBits = FPBits<InType>;
3636
using InStorageType = typename InFPBits::StorageType;
3737
// The product of two p-digit numbers is a 2p-digit number.
38-
using DyadicFloat = DyadicFloat<cpp::bit_ceil(
39-
2 * static_cast<size_t>(InFPBits::FRACTION_LEN))>;
40-
using DyadicMantissaType = typename DyadicFloat::MantissaType;
38+
using DyadicFloat =
39+
DyadicFloat<cpp::bit_ceil(2 * static_cast<size_t>(InFPBits::SIG_LEN))>;
4140

4241
InFPBits x_bits(x);
4342
InFPBits y_bits(y);
@@ -96,21 +95,7 @@ mul(InType x, InType y) {
9695
DyadicFloat xd(x);
9796
DyadicFloat yd(y);
9897

99-
// The product is either in the [2, 4) range or the [1, 2) range. We initially
100-
// set the exponent as if the product were in the [2, 4) range. If the product
101-
// is in the [1, 2) range, then it has 1 leading zero bit and the DyadicFloat
102-
// constructor will normalize it and adjust the exponent.
103-
int result_exp = xd.get_unbiased_exponent() + yd.get_unbiased_exponent() + 1 -
104-
DyadicMantissaType::BITS + 1;
105-
106-
// We use a single DyadicFloat type, which can fit the 2p-digit product, for
107-
// both the normalized inputs and the product. So we need to right-shift the
108-
// normalized input mantissas before multiplying them.
109-
xd.shift_right(DyadicMantissaType::BITS / 2);
110-
yd.shift_right(DyadicMantissaType::BITS / 2);
111-
DyadicMantissaType product = xd.mantissa * yd.mantissa;
112-
113-
DyadicFloat result(result_sign, result_exp, product);
98+
DyadicFloat result = quick_mul(xd, yd);
11499
return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
115100
}
116101

0 commit comments

Comments
 (0)