Skip to content

perf: float32 Max/Min read float32 directly; SSE2 and NEON kernels - #64

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

tannevaled merged 1 commit into
mainfrom
float32-extrema

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

float32 Max/Min converted the whole array to a new float64 array and reduced that. On a POWER9 they were 11.9–15× slower than NumPy.

Changes

  • Every architecture. kernels.Max32/Min32 read the float32 elements directly, with four independent chains of Go's max/min. The value is the same as before, since float32 → float64 is exact.
  • amd64: MAXPS/MINPS, 16 floats per iteration, with a CMPPS-unordered NaN mask. MAXPS/MINPS return their source operand on a zero tie, so a zero result goes back to the scalar loop for its sign. That is the rule v0.19.1 introduced for float64.
  • arm64: NEON VFMAX/VFMIN on .S4, which propagate NaN and order −0 below +0 themselves.

Measured with abbench: alternated, 6 rounds, pinned core.

float32 Max 2¹⁴ 2²⁰ float64 control
Zen 3 (SSE2) −91.6% −88.4% ~
Neoverse N1 (NEON) −94.6% −93.2% ~
POWER9 (Go loop) −41.9% −34.3% ~

float32 Max is now faster than float64 on both kernel architectures, since it reads half the bytes.

Tests

  • Bit for bit against one sequential pass of Go's max/min, with NaN, real signed zeros (math.Copysign(0, -1)) and infinities at every position, for every length up to 70.
  • A sabotaged kernel (one VFMIN in max32NEON, one MINPS in max32SSE2) fails it, on Apple M and on Zen 3.
  • The PROT_NONE fence covers both kernels.
  • A root test checks that the result equals the old float64 path, strided views included.
  • Kernel tests pass on Zen 3, Neoverse N1 and Apple M. The local coverage gate (covblocks) reports 0 uncovered blocks.

Not in this PR (recorded in docs/perf.md):

  • ppc64le and loong64: they need go-asmgen registry entries first. Go's assemblers have no VSX float compare, and loong64 has no vector float max, min or compare at all.
  • s390x (VFMAXSB mode 1): waiting for a z machine to test on.
  • riscv64: next.

A minor release, v0.20.0.

🤖 Generated with Claude Code

float32 Max/Min converted the whole array to float64 and reduced that:
on a POWER9 they were 11.9-15x slower than NumPy. kernels.Max32/Min32
now read the float32 elements, with four chains of Go's max/min
(the value is the same: the conversion is exact), and run vector
kernels on amd64 (MAXPS/MINPS + CMPPS-unordered NaN mask; a zero
result goes to the scalar loop for its sign, the v0.19.1 rule) and
arm64 (NEON VFMAX/VFMIN .S4, NaN-propagating, -0 below +0).

abbench, alternated, pinned core, float32 Max 2^14 / 2^20:
Zen 3 -92% / -88%, Neoverse N1 -95% / -93%, POWER9 (Go loop)
-42% / -34%; float64 controls flat.

Tested bit for bit against one sequential pass of Go's max/min, with
NaN, real signed zeros and infinities at every position to length 70;
a sabotaged kernel fails it on both architectures; fenced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit f4ab9ab into main Oct 26, 2026
12 checks passed
@tannevaled
tannevaled deleted the float32-extrema branch October 26, 2026 10:29
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