mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-24 08:30:21 +00:00
AK+LibCrypto: Delete 64x64 wide multiplication workarounds
Now UFixedBigInt exposes API to do wide multiplications of this kind efficiently.
This commit is contained in:
parent
67ec347bfa
commit
8f8e31e780
Notes:
sideshowbarker
2024-07-17 05:02:42 +09:00
Author: https://github.com/DanShaders Commit: https://github.com/SerenityOS/serenity/commit/8f8e31e780 Pull-request: https://github.com/SerenityOS/serenity/pull/17330 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/Hendiadyoin1
3 changed files with 4 additions and 26 deletions
|
@ -1227,14 +1227,7 @@ static i32 decimal_exponent_to_binary_exponent(i32 exponent)
|
|||
|
||||
static u128 multiply(u64 a, u64 b)
|
||||
{
|
||||
#ifdef __SIZEOF_INT128__
|
||||
unsigned __int128 result = (unsigned __int128)a * b;
|
||||
u64 low = result;
|
||||
u64 high = result >> 64;
|
||||
return u128 { low, high };
|
||||
#else
|
||||
return u128 { a }.wide_multiply(u128 { b }).low;
|
||||
#endif
|
||||
return UFixedBigInt<64>(a).wide_multiply(b);
|
||||
}
|
||||
|
||||
template<unsigned Precision>
|
||||
|
@ -1249,10 +1242,7 @@ u128 multiplication_approximation(u64 value, i32 exponent)
|
|||
|
||||
if ((lower_result.high() & mask) == mask) {
|
||||
auto upper_result = multiply(z.low(), value);
|
||||
lower_result.low() += upper_result.high();
|
||||
if (upper_result.high() > lower_result.low()) {
|
||||
++lower_result.high();
|
||||
}
|
||||
lower_result += upper_result.high();
|
||||
}
|
||||
|
||||
return lower_result;
|
||||
|
|
|
@ -171,25 +171,14 @@ FloatingPointExponentialForm inner_convert_floating_point_to_decimal_exponential
|
|||
|
||||
static u128 multiply(u64 a, u64 b)
|
||||
{
|
||||
#ifdef __SIZEOF_INT128__
|
||||
unsigned __int128 result = (unsigned __int128)a * b;
|
||||
u64 low = result;
|
||||
u64 high = result >> 64;
|
||||
return u128 { low, high };
|
||||
#else
|
||||
return u128 { a }.wide_multiply(u128 { b }).low;
|
||||
#endif
|
||||
return UFixedBigInt<64>(a).wide_multiply(b);
|
||||
}
|
||||
|
||||
template<>
|
||||
FloatingPointExponentialForm convert_floating_point_to_decimal_exponential_form<float>(float value)
|
||||
{
|
||||
auto multiply_and_shift = [](u64 operand, u64 multiplier, i32 shift) {
|
||||
#ifdef __SIZEOF_INT128__
|
||||
auto result = (unsigned __int128)operand * multiplier;
|
||||
#else
|
||||
auto result = multiply(operand, multiplier);
|
||||
#endif
|
||||
if (shift < 0)
|
||||
return static_cast<u64>(result << static_cast<u32>(-shift));
|
||||
else
|
||||
|
|
|
@ -57,8 +57,7 @@ static u256 select(u256 const& left, u256 const& right, bool condition)
|
|||
|
||||
static u512 multiply(u256 const& left, u256 const& right)
|
||||
{
|
||||
auto result = left.wide_multiply(right);
|
||||
return { result.low, result.high };
|
||||
return left.wide_multiply(right);
|
||||
}
|
||||
|
||||
static u256 modular_reduce(u256 const& value)
|
||||
|
|
Loading…
Reference in a new issue