1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:47:34 +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:
Dan Klishch 2023-02-04 19:03:52 +03:00 committed by Andrew Kaster
parent 67ec347bfa
commit 8f8e31e780
3 changed files with 4 additions and 26 deletions

View file

@ -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;