Skip to content

Various improvements on integer multiplication (including NTT) - #74

Merged
cmpute merged 19 commits into
masterfrom
ssa
Jun 14, 2026
Merged

Various improvements on integer multiplication (including NTT)#74
cmpute merged 19 commits into
masterfrom
ssa

Conversation

@cmpute

@cmpute cmpute commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Criterion comparison: master run against ssa baseline. Negative = master faster; positive = ssa faster.

  ┌──────────────┬─────────┬─────────┬────────────────┐
  │ bits (words) │ master  │   ssa   │ ssa vs master  │
  ├──────────────┼─────────┼─────────┼────────────────┤
  │ 1e1 (~1)     │ 5.6 ns  │ 25.7 ns │ 4.6x slower    │
  ├──────────────┼─────────┼─────────┼────────────────┤
  │ 1e2 (~2)     │ 126 ns  │ 195 ns  │ 1.6x slower    │
  ├──────────────┼─────────┼─────────┼────────────────┤
  │ 1e3 (~16)    │ 738 ns  │ 1.33 µs │ 1.8x slower    │
  ├──────────────┼─────────┼─────────┼────────────────┤
  │ 1e4 (~156)   │ 48.8 µs │ 31.1 µs │ ~tied (p=0.65) │
  ├──────────────┼─────────┼─────────┼────────────────┤
  │ 1e5 (~1.5k)  │ 2.40 ms │ 0.76 ms │ 3.2x faster    │
  ├──────────────┼─────────┼─────────┼────────────────┤
  │ 1e6 (~15k)   │ 45.2 ms │ 18.5 ms │ 2.4x faster    │
  ├──────────────┼─────────┼─────────┼────────────────┤
  │ 1e7 (~150k)  │ 626 ms  │ 463 ms  │ 1.35x faster   │
  └──────────────┴─────────┴─────────┴────────────────┘

The master branch has merged improvements for small integer multiplications.

ubig_mul_asymmetric — b fixed at 500k bits (~8k words), a varies

(ssa-only; this benchmark was added in the branch)

  ┌─────────────────┬─────────┐
  │ a size / b size │  time   │
  ├─────────────────┼─────────┤
  │ 1k / 500k       │ 164 µs  │
  ├─────────────────┼─────────┤
  │ 10k / 500k      │ 917 µs  │
  ├─────────────────┼─────────┤
  │ 100k / 500k     │ 3.6 ms  │
  ├─────────────────┼─────────┤
  │ 500k / 500k     │ 5.7 ms  │
  ├─────────────────┼─────────┤
  │ 1M / 500k       │ 15.5 ms │
  ├─────────────────┼─────────┤
  │ 2M / 500k       │ 26.1 ms │
  ├─────────────────┼─────────┤
  │ 5M / 500k       │ 60.0 ms │
  └─────────────────┴─────────┘

Jacob Zhong and others added 10 commits June 14, 2026 01:03
Use native Word/Lane types throughout pack.rs (instead of u64/u32) so the
same source compiles cleanly on both 32-bit and 64-bit targets. Resolve
the remaining clippy warnings (unnecessary_cast, let_and_return,
too_many_arguments, needless_range_loop, type_complexity) that were
failing the -D warnings CI run.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds a second clippy step to the existing Clippy job that runs with
--cfg force_bits="32", catching Word-width-dependent lints like the
unnecessary_cast warnings recently fixed in the NTT module.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Extract radix once in from_str_native to avoid repeated B as u32 casts,
and silence the identity try_into() in num_traits::Num::from_str_radix
on 32-bit Word targets.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Tests removed are fully subsumed by the schoolbook-comparison and
roundtrip tests added later in development.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@cmpute
cmpute merged commit 70cb8dd into master Jun 14, 2026
13 checks passed
@cmpute
cmpute deleted the ssa branch June 14, 2026 14:51
CokieMiner pushed a commit to CokieMiner/dashu that referenced this pull request Jun 25, 2026
…e#74)

* Add plan for NTT implementation

* WIP: implemented ntt mul

* WIP: tidy up

* WIP: some param tuning

* WIP: further tune b_pack

* WIP: minor test improvements

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* Some minor improvements

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* Fix CI

* Fix CI again

* Change solinas to proth for NTT

* Tidy up num-modular usage

* Tune the NTT threshold

* Tidy up

* Remove todos

* Fix 32-bit and clippy CI failures in NTT module

Use native Word/Lane types throughout pack.rs (instead of u64/u32) so the
same source compiles cleanly on both 32-bit and 64-bit targets. Resolve
the remaining clippy warnings (unnecessary_cast, let_and_return,
too_many_arguments, needless_range_loop, type_complexity) that were
failing the -D warnings CI run.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* CI: run clippy on 32-bit Word target

Adds a second clippy step to the existing Clippy job that runs with
--cfg force_bits="32", catching Word-width-dependent lints like the
unnecessary_cast warnings recently fixed in the NTT module.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* Fix clippy warnings on 32-bit Word in dashu-float

Extract radix once in from_str_native to avoid repeated B as u32 casts,
and silence the identity try_into() in num_traits::Num::from_str_radix
on 32-bit Word targets.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* Remove development-only NTT tests

Tests removed are fully subsumed by the schoolbook-comparison and
roundtrip tests added later in development.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* Fix fmt

---------

Co-authored-by: Jacob Zhong <jacob@rimbot.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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