Skip to content

perf: loong64 Max/Min (float64, float32) in LSX integer arithmetic - #71

Merged
tannevaled merged 4 commits into
mainfrom
loong64-extrema
Oct 26, 2026
Merged

tannevaled merged 4 commits into
mainfrom
loong64-extrema

Conversation

@tannevaled

@tannevaled tannevaled commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

loong64 Max/Min for float64 and float32, the last 64-bit target without vector extrema. It also closes a test gap that the sabotage run found.

Kernels in LSX integer arithmetic. Go's loong64 assembler has no vector float max, min or compare:

  • Order: t = x XOR ((x >>a N−1) >>l 1) flips the magnitude bits of the negatives. The signed order of t is the float order, with −0 below +0 (Go's rule), and the map is its own inverse.
  • Extremum: max(acc, t) = acc XOR ((acc XOR t) AND (acc < t)) (vslt.d/vslt.w); min swaps the compare.
  • NaN: a lane is NaN iff (x AND abs) >u +Inf's bits (vsltu). The masks are OR-accumulated and returned as a flag.

The four accumulators fold the same way into one vector, stored in t order. Go maps it back and folds the lanes and the tail with its max/min.

The test gap.

  • The pass that shouldn't have happened: a deliberately sabotaged kernel, with the NaN mask of max32LSX's first lane dropped, passed CI.
  • Why: in this integer order a positive NaN sorts above +Inf, so a max finds it without any NaN test. Every test NaN was math.NaN(), which is positive. A negative NaN sorts below everything, and only the NaN test catches it. x86's default NaN (0×∞, ∞−∞) is negative.
  • Fix: the extremum tests now use both signs, for float32 and float64 on every architecture.
  • Result: the sabotage then failed exactly where it should (TestExtrema32MatchSequential: special Max32 n=16: -0, sequential NaN, loong64 lane), while every other architecture's kernels passed the negative-NaN cases.
  • The sabotage commits are not in the squashed result.

Validated under emulation only. CI's loong64 lane runs qemu la464 with LASX required (#67). The Loongson these would be timed on (cfarm401) accepted TCP but never sent its SSH banner today, so their speed is not measured yet. docs/perf.md says so.

The local coverage gate (covblocks) reports 0 uncovered blocks. SECURITY.md records the test gap.

A minor release, v0.25.0.

🤖 Generated with Claude Code

tannevaled and others added 4 commits October 26, 2026 14:25
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Proves CI's loong64 lane (qemu la464, LASX required) fails on a broken
kernel. The next push removes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…now fail)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled marked this pull request as ready for review October 26, 2026 13:58
@tannevaled
tannevaled merged commit 53f2cd8 into main Oct 26, 2026
12 checks passed
@tannevaled
tannevaled deleted the loong64-extrema branch October 26, 2026 14:09
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