| Crates.io | mod2k |
| lib.rs | mod2k |
| version | 0.1.1 |
| created_at | 2025-12-22 06:00:07.268173+00 |
| updated_at | 2025-12-22 20:31:51.519238+00 |
| description | Fast arithmetic modulo `2^k`, `2^k - 1`, and `2^k - d`. |
| homepage | |
| repository | https://github.com/purplesyringa/mod2k |
| max_upload_size | |
| id | 1999142 |
| size | 106,319 |
mod2kA #![no_std] Rust crate for fast arithmetic modulo 2^k, 2^k - 1, and 2^k - d.
Modular arithmetic is useful for fast hashing, verification of polynomial operations, and as a ring balancing the cost of division with the cost of other operations. Different moduli make different quality vs performance tradeoffs. This crate provides a uniform interface for fast implementations of multiple moduli, allowing you to tune the balance without rewriting your code to adopt faster algorithms:
2^8 - 5, 2^16 - 15, 2^32 - 5, 2^64 - 59. Slowest (~12 insn per multiplication, ~7 insn per addition, slow shifts and inversions), excellent quality.2^7 - 1, 2^13 - 1, 2^31 - 1, 2^61 - 1. Medium performance (~10 insn per multiplication, ~5 insn per addition), excellent quality (but slightly fewer bits of precision compared to "big" primes).2^8 - 1, 2^16 - 1, 2^32 - 1, 2^64 - 1. Great performance (~4 insn per multiplication, ~2 insn per addition), medium quality (the moduli have relatively big prime factors).2^8, 2^16, 2^32, 2^64. Fastest (1 insn per multiplication and addition), but have seed-independent collisions and do not support division by 2.mod2k is estimated to be ~2x faster than general-purpose modular arithmetic libraries on average, and more specific performance information is available.
Check the docs for more information.