Files
mruby-mruby/mrbgems/mruby-bigint/core
Yukihiro "Matz" Matsumoto a39aabe2ac mruby-bigint: optimize modular arithmetic with single-limb fast path
Implement specialized modular reduction algorithm for single-limb modulus
to avoid expensive division operations. The optimization uses repeated
division with double-precision arithmetic for multi-limb dividends and
direct modulo operation for single-limb dividends.

Algorithm:
- Single-limb dividend: direct modulo operation (x % m)
- Multi-limb dividend: iterative reduction using double-precision arithmetic
  processing limbs from most significant to least significant

Purpose:
- Accelerate common modular arithmetic operations with small moduli
- Reduce computational overhead for cryptographic and mathematical operations
- Improve performance of rational number arithmetic that relies on modular ops

Performance impact:
- Single-limb modulus: ~1.04M ops/sec (6x improvement over general case)
- Maintains correctness for all existing modular arithmetic operations
- Zero impact on large modulus operations (fallback to existing algorithm)

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:45 +09:00
..
2025-05-14 02:01:02 +10:00