From cde0f324000c1eb04832c1b63ae48074d6dc3da8 Mon Sep 17 00:00:00 2001 From: Derek Miller <1340081+derek-miller@users.noreply.github.com> Date: Sat, 17 Oct 2026 22:18:46 -0500 Subject: [PATCH 1/2] Raise mul's OpenSSL routing threshold to match a Control4 controller Measured on the dev controller inside a jit="1" driver (every finitelabs driver sets it), mul through lua-openssl only beats pure Lua from about 12 limb products per converted limb, not the 4 that divmod, mod and mod_mul win at. mul now routes at MUL_ROUTE_MIN_RATIO (12); the others keep 4. The same measurement replaces the pure-Lua mod_exp costs recorded in 2026-08: the current code takes 21 ms + 1.34 ms per exponent bit with the JIT and 65 ms + 15.5 ms without, so a Pair-Setup exchange is ~2.5 s or ~28 s in pure Lua, against ~0.04 s through bn.powmod, not minutes. --- CLAUDE.md | 40 ++++++++--------- README.md | 6 +-- src/crypto/bignum.lua | 100 +++++++++++++++++++++++------------------- src/crypto/srp.lua | 14 +++--- 4 files changed, 83 insertions(+), 77 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 6aada88..40c1aa3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -166,11 +166,12 @@ Routing is deliberate and hardwired, not runtime-probed: in `hkdf.lua`. - **bignum** → per operation, behind `Feature.BN` and that operation's own multi-limb known-answer check; `bignum.is_accelerated(op)` reports each. - `mod_exp` routes at every size; `mul`, `divmod`, `mod` and `mod_mul` once - estimated pure-Lua work reaches `ROUTE_MIN_RATIO` limb products per limb - converted, so linear-cost calls stay pure Lua. The measurements and the one - known loss (narrow `mul` under LuaJIT's JIT) are in `bignum.lua`'s OpenSSL - section; measure whether Control4's LuaJIT runs its JIT before changing it. + `mod_exp` routes at every size; `divmod`, `mod` and `mod_mul` once estimated + pure-Lua work reaches `ROUTE_MIN_RATIO` (4) limb products per limb converted, + `mul` at `MUL_ROUTE_MIN_RATIO` (12), so linear-cost calls stay pure Lua. Both + ratios come from controller measurements with the driver's JIT on, which every + finitelabs driver enables with `jit="1"` on its `