Skip to content

perf: ppc64le Max/Min (float64, float32) with an integer NaN mask - #70

Merged
tannevaled merged 1 commit into
mainfrom
ppc64le-extrema
Oct 26, 2026
Merged

tannevaled merged 1 commit into
mainfrom
ppc64le-extrema

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

ppc64le Max/Min for 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 the sp forms) 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:

  • NaN test: a lane is NaN iff its magnitude bits (x AND 0x7FF…F) exceed +Inf's bits as an unsigned integer. vcmpgtud/vcmpgtuw test that on the VMX registers, against two read-only DATA constants, and the results are OR-accumulated.
  • Kernel: it reduces whole blocks with xvmax/xvmin into four accumulators and folds them vertically into one vector stored to out. It returns the NaN flag.
  • Go: it folds the lanes and the tail with its 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):

Max 2¹⁴ 2²⁰ NumPy 2.5.3 (one core)
float64 53.5 → 7.28 µs (−86.4%) 3.48 → 0.472 ms (−86.5%) 11.8 µs / 0.615 ms
float32 49.9 → 4.58 µs (−90.8%) 3.13 → 0.289 ms (−90.8%) 7.13 µs / 0.324 ms

The Sum controls are flat.

Tests on the POWER9.

  • The sequential-oracle tests (NaN, real signed zeros and infinities at every position), the PROT_NONE fence and the root suite all pass.
  • A sabotaged kernel (one of the four NaN-mask ORs replaced by a NOP) fails both the float32 and the float64 oracle test.

The local coverage gate (covblocks) reports 0 uncovered blocks. Max/Min now 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

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>
@tannevaled
tannevaled merged commit 46b2688 into main Oct 26, 2026
12 checks passed
@tannevaled
tannevaled deleted the ppc64le-extrema branch October 26, 2026 13:20
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