|
1 |
| -//===-- Division of IEEE 754 floating-point numbers -------------*- C++ -*-===// |
| 1 | +//===-- Multiplication of IEEE 754 floating-point numbers -------*- C++ -*-===// |
2 | 2 | //
|
3 | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
4 | 4 | // See https://llvm.org/LICENSE.txt for license information.
|
@@ -35,9 +35,8 @@ mul(InType x, InType y) {
|
35 | 35 | using InFPBits = FPBits<InType>;
|
36 | 36 | using InStorageType = typename InFPBits::StorageType;
|
37 | 37 | // 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))>; |
41 | 40 |
|
42 | 41 | InFPBits x_bits(x);
|
43 | 42 | InFPBits y_bits(y);
|
@@ -96,21 +95,7 @@ mul(InType x, InType y) {
|
96 | 95 | DyadicFloat xd(x);
|
97 | 96 | DyadicFloat yd(y);
|
98 | 97 |
|
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); |
114 | 99 | return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
|
115 | 100 | }
|
116 | 101 |
|
|
0 commit comments