Skip to content

Check grid narrow phase distances 8 pairs at a time - #20

Merged
nhz2 merged 1 commit into
mainfrom
grid-simd-distance
Oct 25, 2026
Merged

nhz2 merged 1 commit into
mainfrom
grid-simd-distance

Conversation

@nhz2

@nhz2 nhz2 commented Oct 25, 2026

Copy link
Copy Markdown
Member

The narrow phase distance pass now transposes 8 candidate pairs into one simplex with SIMD.Vec lanes and runs the generic dist_sqr on it, for every pair type. The kernels do the same operations on every lane, so the result is bit identical to the scalar check.

The candidate buffer has GRID_SIMD_WIDTH - 1 slots of padding, and the last group is padded with copies of the last pair, so there is no scalar tail loop. The distances go to a d2 scratch buffer in their own loop, followed by a scalar cutoff check and compaction. Doing the cutoff check in the distance loop made LLVM load each group's indexes as a vector and extract them with vpextrq before the position loads, about twice as slow.

Add a test that dist_sqr on SIMD lanes is bit identical to the scalar version for the kernels the grid uses.

Ring benchmark, single thread: 0.95 ms -> 0.79 ms.

The narrow phase distance pass now transposes 8 candidate pairs into one
simplex with `SIMD.Vec` lanes and runs the generic `dist_sqr` on it, for
every pair type. The kernels do the same operations on every lane, so the
result is bit identical to the scalar check.

The candidate buffer has `GRID_SIMD_WIDTH - 1` slots of padding, and the
last group is padded with copies of the last pair, so there is no scalar
tail loop. The distances go to a `d2` scratch buffer in their own loop,
followed by a scalar cutoff check and compaction. Doing the cutoff check
in the distance loop made LLVM load each group's indexes as a vector and
extract them with `vpextrq` before the position loads, about twice as
slow.

Add a test that `dist_sqr` on SIMD lanes is bit identical to the scalar
version for the kernels the grid uses.

Ring benchmark, single thread: 0.95 ms -> 0.79 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nhz2
nhz2 merged commit 9753de3 into main Oct 25, 2026
2 checks passed
@nhz2
nhz2 deleted the grid-simd-distance branch October 25, 2026 16:32
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