Repository navigation
perf: Log is a port of Arm's optimized-routines log; fixes subnormals on amd64 - #17
Merged
Merged
Conversation
… on amd64
Log went through Map(math.Log): 11.6 ns per element on a Zen 3 core
against NumPy's 4.2. It now runs a port of the double-precision log of
Arm's optimized-routines (the companion of the Exp port, glibc's since
2.28; MIT licence, attributed): a 128-entry {1/c, log(c)} table and a
degree-6 polynomial, a degree-12 one within 2^-4 of 1, and z/c - 1 as one
math.FMA, exact on every target. Log10 is log(x)*(1/ln10), math.Log10's
own formula, on this log.
Accuracy: worst 0.508 ULP against a 300-bit reference over 10 000 inputs
(math.Log: 0.727 on arm64). TestLogTable checks all 128 entries against
the properties log_data.c documents. Speed at 16 Ki on one core: M4
37 us (math.Log 72), Zen 3 73 us (math.Log 175, NumPy 69).
It also removes a Go bug go-ndarray inherited: Go 1.26's amd64 math.Log
is wrong for subnormal inputs (log(5e-324) = -709.09 instead of -744.44,
log(1e-310) = -709.09 instead of -713.80), confirmed on a real Zen 3.
TestLogSubnormal fails with the old Map(math.Log) under amd64.
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.
Log went through Map(math.Log): 11.6 ns per element on a Zen 3 core
against NumPy's 4.2. It now runs a port of the double-precision log of
Arm's optimized-routines (the companion of the Exp port, glibc's since
2.28; MIT licence, attributed): a 128-entry {1/c, log(c)} table and a
degree-6 polynomial, a degree-12 one within 2^-4 of 1, and z/c - 1 as one
math.FMA, exact on every target. Log10 is log(x)*(1/ln10), math.Log10's
own formula, on this log.
Accuracy: worst 0.508 ULP against a 300-bit reference over 10 000 inputs
(math.Log: 0.727 on arm64). TestLogTable checks all 128 entries against
the properties log_data.c documents. Speed at 16 Ki on one core: M4
37 us (math.Log 72), Zen 3 73 us (math.Log 175, NumPy 69).
It also removes a Go bug go-ndarray inherited: Go 1.26's amd64 math.Log
is wrong for subnormal inputs (log(5e-324) = -709.09 instead of -744.44,
log(1e-310) = -709.09 instead of -713.80), confirmed on a real Zen 3.
TestLogSubnormal fails with the old Map(math.Log) under amd64.
🤖 Generated with Claude Code