Skip to content

perf: float32 Exp and Log on the float64 kernels (2-3.5x faster) - #86

Merged
tannevaled merged 2 commits into
mainfrom
perf/float32-transcendental
Nov 1, 2026
Merged

tannevaled merged 2 commits into
mainfrom
perf/float32-transcendental

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

float32 Exp and Log called math.Exp/math.Log per element: 6–14× slower than NumPy on one Zen 3 core. They now run this package's float64 kernels (the Arm optimized-routines ports, 0.504 ULP in float64), 256 elements at a time through a stack buffer, with no allocation. Each result is rounded once, so it is within 0.5 + 2⁻²⁹ float32 ULP.

float32, one Zen 3 core, abbench 8 rounds before after NumPy 2.5.4
Exp, 16 Ki 297 µs 84 µs 26 µs
Log, 16 Ki 198 µs 99 µs 32 µs
Exp, 1 Mi 18.8 ms 5.2 ms 1.73 ms
Log, 1 Mi 12.4 ms 6.1 ms 2.02 ms

These are +255% / +102% / +265% / +109% in throughput, all at p = 0.000.

Still 3× slower than NumPy, whose float32 kernels are SIMD (simd_exp_f32, simd_log_f32). docs/perf.md records this as an open defect, and porting those kernels is the next step.

Tests (via64_test.go):

  • agreement with float32(math.Exp/Log(x)) within 1 ULP, and equal on at least 99.9% of 100 000 inputs;
  • the special values: ±0, ±Inf, NaN, overflow (exp(89) gives +Inf), the subnormals, and log of a negative number;
  • every length from 0 to 600, so the chunk boundaries are crossed;
  • in-place use and the parallel split.

The new BenchmarkDTypeExpLog uses the same operand as the NumPy reference script. SECURITY.md has the audit entry.

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 1, 2026 11:02
float32 Exp and Log called math.Exp/math.Log per element, 6-14x slower
than NumPy on one Zen 3 core. They now run this package's float64
kernels (the Arm optimized-routines ports) 256 elements at a time
through a stack buffer, rounding each result once: within 0.5 + 2^-29
float32 ULP, no allocation.

abbench, 8 rounds, one Zen 3 core: Exp 297 -> 84 us and Log 198 ->
99 us at 16 Ki; Exp 18.8 -> 5.2 ms and Log 12.4 -> 6.1 ms at 1 Mi.
Still about 3x slower than NumPy's float32 SIMD, recorded as an open
defect in docs/perf.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 8ec101b into main Nov 1, 2026
12 checks passed
@tannevaled
tannevaled deleted the perf/float32-transcendental branch November 1, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant