mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-07 17:41:54 +00:00
LibCrypto: Improve efficiency of UnsignedBigInteger::shift_left
Before: - a separate Word element allocation of the underlying Vector<Word> was necessary for every new word in a multi-word shift - two additional temporary UnsignedBigInteger buffers were allocated and passed through, including in downstream calls (e.g. Multiplication) - an additional allocation and word shift for the carry - FIXME note seems to point to some of these issues After: - main change is in LibCrypto/BigInt/Algorithms/BitwiseOperations.cpp - one single allocation per call, using shift_left_by_n_words - only the input "number" and "output" need to be allocated by the caller - downstream calls are adapted not to allocate or pass temporary buffers - noticeable performance improvement when running TestBigInteger: 0.41-0.42s (before) to 0.28-0.29s (after) Intel Core i9 laptop Bonus: remove unused variables from UnsignedBigInteger::divided_by - These were likely cut-and-paste artifacts from UnsignedBigInteger::multiplied_by; not caught by "unused-varible". NOTE: making this change in a separate commit than shift_right, even if it touches the same file BitwiseOperations.cpp since: - it is a "bonus" addition: not necessary for fixing the shift_right bug, but logically unrelated to the shift_right code - it brings a chain of downstream interface modifications (7 files), unrelated to shift_right
This commit is contained in:
parent
05cfbdd6fb
commit
d2ea77c099
Notes:
github-actions[bot]
2025-03-23 18:34:27 +00:00
Author: https://github.com/manuel-za
Commit: d2ea77c099
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3174
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/trflynn89
9 changed files with 60 additions and 74 deletions
|
@ -14,8 +14,6 @@ void UnsignedBigIntegerAlgorithms::destructive_modular_power_without_allocation(
|
|||
UnsignedBigInteger& base,
|
||||
UnsignedBigInteger const& m,
|
||||
UnsignedBigInteger& temp_1,
|
||||
UnsignedBigInteger& temp_2,
|
||||
UnsignedBigInteger& temp_3,
|
||||
UnsignedBigInteger& temp_multiply,
|
||||
UnsignedBigInteger& temp_quotient,
|
||||
UnsignedBigInteger& temp_remainder,
|
||||
|
@ -25,7 +23,7 @@ void UnsignedBigIntegerAlgorithms::destructive_modular_power_without_allocation(
|
|||
while (!(ep < 1)) {
|
||||
if (ep.words()[0] % 2 == 1) {
|
||||
// exp = (exp * base) % m;
|
||||
multiply_without_allocation(exp, base, temp_1, temp_2, temp_3, temp_multiply);
|
||||
multiply_without_allocation(exp, base, temp_1, temp_multiply);
|
||||
divide_without_allocation(temp_multiply, m, temp_quotient, temp_remainder);
|
||||
exp.set_to(temp_remainder);
|
||||
}
|
||||
|
@ -34,7 +32,7 @@ void UnsignedBigIntegerAlgorithms::destructive_modular_power_without_allocation(
|
|||
ep.set_to(ep.shift_right(1));
|
||||
|
||||
// base = (base * base) % m;
|
||||
multiply_without_allocation(base, base, temp_1, temp_2, temp_3, temp_multiply);
|
||||
multiply_without_allocation(base, base, temp_1, temp_multiply);
|
||||
divide_without_allocation(temp_multiply, m, temp_quotient, temp_remainder);
|
||||
base.set_to(temp_remainder);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue