Skip to content

Conversation

andrewwhitehead
Copy link
Contributor

This implements basic wrapping multiplication for Uint and BoxedUint, deferring to Karatsuba multiplication when it would be faster (estimated by benchmarks). The number of limbs needs to get fairly high before it needs to switch over though, and Uint currently only implements Karatsuba for a few limb counts that are powers of two (I also have a const implementation that might help with that).

A few relevant benchmarks:

wrapping ops/wrapping_mul, U256xU256
                        time:   [4.3439 ns 4.4469 ns 4.5640 ns]
                        change: [−52.321% −49.534% −46.632%] (p = 0.00 < 0.05)
                        Performance has improved.
wrapping ops/wrapping_mul, U4096xU4096
                        time:   [1.9225 µs 1.9347 µs 1.9493 µs]
                        change: [−14.332% −13.199% −11.674%] (p = 0.00 < 0.05)
                        Performance has improved.
wrapping ops/wrapping_mul, U8192xU4096
                        time:   [5.7493 µs 5.7893 µs 5.8438 µs]
                        change: [−31.980% −29.997% −28.668%] (p = 0.00 < 0.05)
                        Performance has improved.
wrapping ops/boxed_wrapping_mul
                        time:   [2.2299 µs 2.2406 µs 2.2524 µs]
                        change: [−27.376% −27.000% −26.631%] (p = 0.00 < 0.05)
                        Performance has improved.

…thods into a separate module

Signed-off-by: Andrew Whitehead <[email protected]>
Signed-off-by: Andrew Whitehead <[email protected]>
Signed-off-by: Andrew Whitehead <[email protected]>
Signed-off-by: Andrew Whitehead <[email protected]>
@tarcieri tarcieri requested review from tarcieri and fjarri August 27, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant