Repository navigation
perf: float32 Exp in AVX2, correctly rounded and as fast as NumPy - #90
Merged
Merged
Conversation
…very float32 expCR transcribes the double-precision exp of Arm optimized-routines' cr_expf (math/aarch64/advsimd/cr_expf.c, MIT) one operation per line, every vfmaq as math.FMA, so a SIMD kernel can repeat it bit for bit: x/ln2 rounded to 1/64 by a shift, a 64-entry table of 2^(i/64) (re-derived at 300 bits by TestExpCRTable), and a degree-5 polynomial. Its float64 error is up to 1.006 ULP, so the exhaustive certifier takes a per-function margin (4 ULP here; 2 for the 0.504-ULP kernels). Over all 2^32 float32 inputs: 7 decided by the 300-bit reference, 0 incorrectly rounded. No exception table needed. This is the target for the SIMD float32 exp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every architecture's float32 Exp now runs expCR, the transcription of Arm's correctly rounded expf (proven over all 2^32 inputs in the previous commit). On amd64 with AVX2+FMA, exp32CRAVX2 (go-asmgen) repeats its operations eight floats at a time: VCVTPS2PD, the FMA sequence, VPGATHERQQ for the 2^(i/64) table, the exponent from z<<46, then one VCVTPD2PS. Inputs are clamped to +-512 (same float32 result) and NaN lanes restored. The kernel is bit-identical to expCR (100 000 inputs, specials, lengths 0-70) and fenced. On Zen 3 the exhaustive test, which runs it, finds 0 incorrectly rounded of 2^32. Zen 3, one core, abbench 8 rounds: 16 Ki 90 -> 26.9 us (NumPy 27.1), 1 Mi 5.8 -> 1.48 ms (NumPy 1.66). Parity, then 11% faster than NumPy, which is at 2.52 ULP; we are correctly rounded. Log moves to its own log32 (unchanged behaviour); the old via64 exp path is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_test.go Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
float32
Expis now correctly rounded and at NumPy's speed or better on amd64. NumPy's own source puts its float32 exp at 2.52 ULP.The algorithm: Arm optimized-routines' correctly rounded vector expf (
math/aarch64/advsimd/cr_expf.c+cr_expf_utils.h, MIT).expCRtranscribes it one operation per line, every vfmaq asmath.FMA.TestExpCRTable).Proof (all 2³² float32 inputs): 7 decided by the 300-bit reference, 0 incorrectly rounded, with no exception table needed.
The kernel:
exp32CRAVX2(go-asmgen, AVX2+FMA) does the same operations on 8 floats at a time.expCRon 100 000 inputs, every special value, and every length 0–70, and it is fenced.Every architecture now runs
expCR(in Go where there is no kernel yet), so the bits are the same everywhere.Exp, one Zen 3 core, abbench 8 roundsThroughput is +235% and +289% (p = 0.000). The host was at load 59 on 128 cores; NumPy ran in the same session on the same pinned core.
float32
Logbehaves exactly as before, moved to its ownlog32; the old via64 exp path is gone. Still open: float32Logat 3× NumPy, and Exp kernels for the other architectures. The audit entry is in SECURITY.md.🤖 Generated with Claude Code