mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
LibJS+LibCrypto: Use a bitwise approach for BigInt's as*IntN methods
This speeds up expressions such as `BigInt.asIntN(0x4000000000000, 1n)` (#3615). And those involving very large bigints.
This commit is contained in:
Notes:
github-actions[bot]
2025-03-20 08:45:14 +00:00
Author: https://github.com/ttrssreal Commit: https://github.com/LadybirdBrowser/ladybird/commit/12cbefbee7b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3994 Reviewed-by: https://github.com/gmta ✅
@@ -291,6 +291,17 @@ FLATTEN SignedBigInteger SignedBigInteger::shift_right(size_t num_bits) const
|
||||
return SignedBigInteger { m_unsigned_data.shift_right(num_bits), m_sign };
|
||||
}
|
||||
|
||||
FLATTEN ErrorOr<SignedBigInteger> SignedBigInteger::mod_power_of_two(size_t power_of_two) const
|
||||
{
|
||||
auto const lower_bits = m_unsigned_data.as_n_bits(power_of_two);
|
||||
|
||||
if (is_positive())
|
||||
return SignedBigInteger(lower_bits);
|
||||
|
||||
// twos encode lower bits
|
||||
return SignedBigInteger(TRY(lower_bits.try_bitwise_not_fill_to_one_based_index(power_of_two)).plus(1).as_n_bits(power_of_two));
|
||||
}
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::multiplied_by(SignedBigInteger const& other) const
|
||||
{
|
||||
bool result_sign = m_sign ^ other.m_sign;
|
||||
|
||||
Reference in New Issue
Block a user