Skip to content

Commit 5d117e6

Browse files
committed
Refactor decimal128 fma
1 parent 9b78f40 commit 5d117e6

File tree

3 files changed

+5
-136
lines changed

3 files changed

+5
-136
lines changed

include/boost/decimal/decimal128.hpp

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,75 +2419,6 @@ constexpr auto scalbnd128(decimal128 num, int expval) noexcept -> decimal128
24192419
return scalblnd128(num, static_cast<long>(expval));
24202420
}
24212421

2422-
constexpr auto fmad128(decimal128 x, decimal128 y, decimal128 z) noexcept -> decimal128
2423-
{
2424-
// First calculate x * y without rounding
2425-
constexpr decimal128 zero {0, 0};
2426-
2427-
const auto res {detail::check_non_finite(x, y)};
2428-
if (res != zero)
2429-
{
2430-
return res;
2431-
}
2432-
2433-
auto sig_lhs {x.full_significand()};
2434-
auto exp_lhs {x.biased_exponent()};
2435-
detail::normalize<decimal128>(sig_lhs, exp_lhs);
2436-
2437-
auto sig_rhs {y.full_significand()};
2438-
auto exp_rhs {y.biased_exponent()};
2439-
detail::normalize<decimal128>(sig_rhs, exp_rhs);
2440-
2441-
auto mul_result {d128_mul_impl(sig_lhs, exp_lhs, x.isneg(), sig_rhs, exp_rhs, y.isneg())};
2442-
const decimal128 dec_result {mul_result.sig, mul_result.exp, mul_result.sign};
2443-
2444-
return dec_result + z;
2445-
2446-
/*
2447-
const auto res_add {detail::check_non_finite(dec_result, z)};
2448-
if (res_add != zero)
2449-
{
2450-
return res_add;
2451-
}
2452-
2453-
bool lhs_bigger {dec_result > z};
2454-
if (dec_result.isneg() && z.isneg())
2455-
{
2456-
lhs_bigger = !lhs_bigger;
2457-
}
2458-
bool abs_lhs_bigger {abs(dec_result) > abs(z)};
2459-
2460-
detail::normalize<decimal128>(mul_result.sig, mul_result.exp);
2461-
2462-
auto sig_z {z.full_significand()};
2463-
auto exp_z {z.biased_exponent()};
2464-
detail::normalize<decimal128>(sig_z, exp_z);
2465-
detail::decimal128_components z_components {sig_z, exp_z, z.isneg()};
2466-
2467-
if (!lhs_bigger)
2468-
{
2469-
detail::swap(mul_result, z_components);
2470-
abs_lhs_bigger = !abs_lhs_bigger;
2471-
}
2472-
2473-
detail::decimal128_components result {};
2474-
2475-
if (!mul_result.sign && z_components.sign)
2476-
{
2477-
result = d128_sub_impl(mul_result.sig, mul_result.exp, mul_result.sign,
2478-
z_components.sig, z_components.exp, z_components.sign,
2479-
abs_lhs_bigger);
2480-
}
2481-
else
2482-
{
2483-
result = d128_add_impl(mul_result.sig, mul_result.exp, mul_result.sign,
2484-
z_components.sig, z_components.exp, z_components.sign);
2485-
}
2486-
2487-
return {result.sig, result.exp, result.sign};
2488-
*/
2489-
}
2490-
24912422
} //namespace decimal
24922423
} //namespace boost
24932424

include/boost/decimal/decimal64.hpp

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,73 +2353,6 @@ constexpr auto copysignd64(decimal64 mag, decimal64 sgn) noexcept -> decimal64
23532353
return mag;
23542354
}
23552355

2356-
/*
2357-
constexpr auto fmad64(decimal64 x, decimal64 y, decimal64 z) noexcept -> decimal64
2358-
{
2359-
// First calculate x * y without rounding
2360-
constexpr decimal64 zero {0, 0};
2361-
2362-
const auto res {detail::check_non_finite(x, y)};
2363-
if (res != zero)
2364-
{
2365-
return res;
2366-
}
2367-
2368-
auto sig_lhs {x.full_significand()};
2369-
auto exp_lhs {x.biased_exponent()};
2370-
detail::normalize<decimal64>(sig_lhs, exp_lhs);
2371-
2372-
auto sig_rhs {y.full_significand()};
2373-
auto exp_rhs {y.biased_exponent()};
2374-
detail::normalize<decimal64>(sig_rhs, exp_rhs);
2375-
2376-
auto mul_result {d64_mul_impl(sig_lhs, exp_lhs, x.isneg(), sig_rhs, exp_rhs, y.isneg())};
2377-
const decimal64 dec_result {mul_result.sig, mul_result.exp, mul_result.sign};
2378-
2379-
const auto res_add {detail::check_non_finite(dec_result, z)};
2380-
if (res_add != zero)
2381-
{
2382-
return res_add;
2383-
}
2384-
2385-
bool lhs_bigger {dec_result > z};
2386-
if (dec_result.isneg() && z.isneg())
2387-
{
2388-
lhs_bigger = !lhs_bigger;
2389-
}
2390-
bool abs_lhs_bigger {abs(dec_result) > abs(z)};
2391-
2392-
detail::normalize<decimal64>(mul_result.sig, mul_result.exp);
2393-
2394-
auto sig_z {z.full_significand()};
2395-
auto exp_z {z.biased_exponent()};
2396-
detail::normalize<decimal64>(sig_z, exp_z);
2397-
detail::decimal64_components z_components {sig_z, exp_z, z.isneg()};
2398-
2399-
if (!lhs_bigger)
2400-
{
2401-
detail::swap(mul_result, z_components);
2402-
abs_lhs_bigger = !abs_lhs_bigger;
2403-
}
2404-
2405-
detail::decimal64_components result {};
2406-
2407-
if (!mul_result.sign && z_components.sign)
2408-
{
2409-
result = d64_sub_impl(mul_result.sig, mul_result.exp, mul_result.sign,
2410-
z_components.sig, z_components.exp, z_components.sign,
2411-
abs_lhs_bigger);
2412-
}
2413-
else
2414-
{
2415-
result = d64_add_impl(mul_result.sig, mul_result.exp, mul_result.sign,
2416-
z_components.sig, z_components.exp, z_components.sign);
2417-
}
2418-
2419-
return {result.sig, result.exp, result.sign};
2420-
}
2421-
*/
2422-
24232356
} //namespace decimal
24242357
} //namespace boost
24252358

include/boost/decimal/detail/cmath/fma.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ constexpr auto fmad64(decimal64 x, decimal64 y, decimal64 z) noexcept -> decimal
152152
return {result.sig, result.exp, result.sign};
153153
}
154154

155+
constexpr auto fmad128(decimal128 x, decimal128 y, decimal128 z) noexcept -> decimal128
156+
{
157+
return x * y + z;
158+
}
159+
155160
BOOST_DECIMAL_EXPORT constexpr auto fma(decimal32 x, decimal32 y, decimal32 z) noexcept -> decimal32
156161
{
157162
return fmad32(x, y, z);

0 commit comments

Comments
 (0)