NEON-vectorized union2by2 - #567
Open
gitRasheed wants to merge 2 commits into
Open
Conversation
This was referenced Sep 11, 2026
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.
NEON kernel for
union2by2, the array-container union, on arm64. Fixes #288. Both arrays need at least 32 elements and 128 between them. Smaller inputs keep the scalar assembly from #287.This replaces #538, which carried a partial block between steps and only paid off from 384 elements per side. This one carries nothing. Each step takes a 16-element window from both sides, lets x be the smaller of the two window maxima, sorts all 32 through a bitonic merge network, drops repeats and lanes above x, stores the rest, and advances each cursor by its count of values at or below x. Every step retires a closed value interval, so there is no seam state and the unread tails are strictly above the last stored value. Windows entirely below the other side are copied straight through. An 8-lane stage handles the last blocks and inputs under 64, then the scalar merge takes the tails.
Array unions had a hand-written scalar path on arm64 and nothing wider.
I made a page that steps through this kernel on worked examples and annotates the assembly line by line, to make the design choices easier to follow: https://claude.ai/code/artifact/5f77af0d-89c2-4965-9d15-95fde361c47f#union (the other tabs cover the other three kernels).
Changes
setutil_arm64.go: the lane-compaction table (its own commit, shared with NEON-vectorized intersection2by2 #543, NEON-vectorized difference #568 and NEON-vectorized exclusiveUnion2by2 #569 so the four merge in any order) and the dispatch: thresholds, the zero-length bufferlazyorArraypasses with capacity, and the in-place self-union geometry (set2 at the output base with set1 an identical copy), which goes to the scalar routine because its reads stay ahead of its writes.setutil_neon_part_arm64.s: the kernel.setutil_arm64.s: Union2by2 arm64 assembly #287's routine renamedunion2by2scalar, unchanged.iorArrayandlazyorArray, the partition prefixes the kernel returns at several sizes and shapes, window ties, mixed window ownership, and copy-on-write bitmaps.BenchmarkUnion2By2rotating fixed-seed datasets, andBenchmarkUnionRealDataover the real-roaring-datasets corpus behindBENCH_REAL_DATA=1.Testing
go testpasses for all packages on Graviton 4, for this branch alone and with the other three kernel branches merged in.go fmtclean. Smat fuzzer (through the wrapper noted in #538,-tags gofuzz), 300 seconds on Graviton 4: 286,276 executions, no failures.Performance
Graviton 4 (c8g.xlarge), Go 1.26.2, medians of five runs.
BenchmarkUnion2By2from this PR, dispatch against the #287 scalar routine, ns/op:Real-roaring-datasets, master against this branch,
BenchmarkUnionRealDataover all twelve datasets, raw and optimized, pairwise, accumulated and FastOr: geomean 7 percent less time over 72 cells, with census-income raw accumulated 663 to 428 µs, census1881 raw FastOr 3.18 to 2.13 ms, wikileaks-noquotes raw accumulated 2.11 to 1.63 ms. No allocation changes.