Repository navigation
perf: ppc64le Max/Min (float64, float32) with an integer NaN mask - #70
Merged
Merged
Conversation
xvmaxdp/xvmindp (and sp) do not propagate NaN as Go/NumPy do, and Go's assembler has no VSX float compare. The kernel builds the NaN mask in integer arithmetic: a lane is NaN iff (x AND abs) >u +Inf's bits (vcmpgtud/vcmpgtuw against DATA constants), OR-accumulated. It reduces whole blocks into four accumulators folded into one stored vector, plus the NaN flag; Go folds the lanes and the tail with its max/min and sends a zero result to the scalar oracle for its sign. POWER9 (abbench): Max float64 -86% / -86%, float32 -91% / -91% (2^14 / 2^20), now faster than NumPy 2.5.3 on one core (7.28 vs 11.8 us and 0.472 vs 0.615 ms float64; 4.58 vs 7.13 us and 0.289 vs 0.324 ms float32). Sum controls flat. A sabotaged kernel (one NaN-mask OR removed) fails the float32 and float64 oracle tests on the POWER9. 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.
ppc64le
Max/Minfor float64 and float32. They were 4.4–5.4× (float64) and about 7× (float32) slower than NumPy on a POWER9. Both are now faster than NumPy there.Why it took a detour.
xvmaxdp/xvmindp(and thespforms) do not propagate NaN as Go and NumPy do, so the float64 path used a scalar reducer. A NaN mask needs a float compare, and Go's assembler has no VSX float compare. Adding one would have meant a go-asmgen registry entry plus a cmd/asm patch.How. The mask is built in integer arithmetic instead:
x AND 0x7FF…F) exceed +Inf's bits as an unsigned integer.vcmpgtud/vcmpgtuwtest that on the VMX registers, against two read-only DATA constants, and the results are OR-accumulated.xvmax/xvmininto four accumulators and folds them vertically into one vector stored toout. It returns the NaN flag.max/min. A zero result goes to the scalar oracle for its sign, as on amd64. So neither the instruction's NaN rule nor its zero-tie rule can show.Measured on a POWER9 (cfarm29,
abbench, 6 rounds, alternated, pinned core):MaxThe
Sumcontrols are flat.Tests on the POWER9.
The local coverage gate (
covblocks) reports 0 uncovered blocks.Max/Minnow has vector kernels on every 64-bit target but loong64, which needs go-asmgen registry entries since Go's assembler has no vector float max, min or compare there.A minor release, v0.24.0.
🤖 Generated with Claude Code