Skip to content

Multiplication with 8-decdig batch#501

Merged
tompng merged 1 commit intoruby:masterfrom
tompng:batch_mult
Mar 30, 2026
Merged

Multiplication with 8-decdig batch#501
tompng merged 1 commit intoruby:masterfrom
tompng:batch_mult

Conversation

@tompng
Copy link
Copy Markdown
Member

@tompng tompng commented Mar 20, 2026

Perform multiplication with 8-decdigs * 8-decdigs batch. This will reduce carry operation by 1/4, and may enable vectorization.

Benchmark

irb(main):001> measure
TIME is added.
irb(main):002> x = BigDecimal('111111111'*num_decdig); t = 100000.times{x*x};

Smaller is better

num_decdig time(master) time(this branch) memo
99 4.388227s 0.971541s 4.5 time faster
50 1.133961s 0.276888s 4.1 times faster
20 0.216531s 0.076732s 2.8 times faster
10 0.080238s 0.041933s 1.9 times faster
4 0.018200s 0.017952s same
1 0.0147669s 0.016004s slower

Optimal threshold of using NTT multiplication and Newton-Raphson division has changed because multiplication gets about 4 times faster (when num_decdig is near threshold).

@tompng tompng force-pushed the batch_mult branch 5 times, most recently from c4aab0b to 91e1b4f Compare March 30, 2026 18:23
Perform multiplication with 8-decdigs * 8-decdigs batch.
This will reduce carry operation by 1/4, and may enable vectorization.
@tompng tompng merged commit 32fb1de into ruby:master Mar 30, 2026
84 checks passed
@tompng tompng deleted the batch_mult branch March 30, 2026 18:38
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