Repository navigation
float32 Log: correctly rounded (CORE-MATH logf) with an AVX2 kernel at NumPy parity - #91
Merged
Merged
Conversation
logCR transcribes CORE-MATH's binary32 logf (Sibidanov and Zimmermann, MIT): a 64-entry table and a degree-3 polynomial in float64 bound the result; a degree-8 polynomial decides the 762 750 positive inputs whose bounds round apart. Products are converted to float64 explicitly so no architecture fuses them. TestLogCRMatchesLog32 finds it equal to log32, already proven correctly rounded, on all 2^32 inputs. log32CRAVX2 runs the fast path on 8 floats at a time (VGATHERDPD for the tables, unfused VMULPD/VADDPD in logCR's order) and hands back each block it cannot finish to logCR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Log32 and Log32P now run log32Fast: log32CRAVX2 on amd64 with AVX2, logCR in Go elsewhere. TestLog32CorrectlyRounded, run on all 2^32 inputs against the 300-bit reference, finds 0 incorrectly rounded on darwin/arm64 (Go) and Zen 3 (AVX2). The via64 log32 and its 24-entry exception table move to a test file as the independent oracle. perf.md, README and SECURITY.md describe the new path; float32 Log goes from 3x NumPy to parity on one Zen 3 core. 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
Logis now correctly rounded and at NumPy's speed on amd64 with AVX2. Before this PR it was 3× slower than NumPy, whose own source puts its float32 log at 3.83 ULP.The algorithm: CORE-MATH's correctly rounded binary32 logf (
src/binary32/log/logf.c, Sibidanov and Zimmermann, MIT). Arm's optimized-routines has no correctly rounded logf.logCRtranscribes it one C operation per Go operation. Every product is converted to float64 explicitly, so arm64, ppc64le and s390x cannot fuse it.Proof over all 2³² float32 inputs (
NDARRAY_EXHAUSTIVE=1):TestLogCRMatchesLog32:logCRequals v0.33.0'slog32on every input, with 0 differences on darwin/arm64, Zen 3 and POWER9. Thatlog32widens to float64Logand uses an exception table; it shares no code withlogCR.TestLog32CorrectlyRounded:Log32against the 300-bit reference gives 0 incorrectly rounded on darwin/arm64 and linux/ppc64le (POWER9), both the Go path, and on Zen 3 (the AVX2 kernel).The kernel:
log32CRAVX2(go-asmgen, AVX2) runs the fast path on 8 floats at a time.VGATHERDPDand usesVMULPD/VADDPDinlogCR's order, never fused.logCR: an input that is not a positive normal float32, or bounds that round apart.logCRon 300 000 inputs and at every length 0–70, in place too. It is fenced, and its constant-block offsets are tested.Log, 16 Ki, one Zen 3 core (load 0.35)Through the API against v0.33.0 (
abbench, 8 interleaved rounds, load ≤ 8): −65% at 16 Ki and −68% at 1 Mi, p = 0.000.The old via64
log32and its exception table move tovia64_oracle_test.goas the oracle. The audit entry is in SECURITY.md. Still open: the s390x exhaustive run (LinuxONE unreachable today; CI's s390x lane runs the sample), and the SIMD kernels for the other architectures.🤖 Generated with Claude Code