mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
a39aabe2ac
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>