Skip to content

Use PCMPISTRM for the intersection and difference comparison on SSE4.2+ in Stable Simd - #380

Merged
Kerollmops merged 1 commit into
stable_simdfrom
stable_simd_pcmpistrm
Oct 26, 2026
Merged

Kerollmops merged 1 commit into
stable_simdfrom
stable_simd_pcmpistrm

Conversation

@Dr-Emann

@Dr-Emann Dr-Emann commented Oct 9, 2026

Copy link
Copy Markdown
Member

Look ma, no unsafe!

Following CRoaring, compare a vector of lhs against a vector of rhs with the SSE4.2 PCMPISTRM instruction via a fearless_simd::kernel!. PCMPISTRM treats a zero lane as the end of the string, so the slower PCMPESTRM is used while either current vector may start with a zero (only possible at the start of the sorted arrays). Other SIMD levels keep the portable all-pairs comparison.

Compared with the portable comparison, and, and_len and sub are 4-13% faster with default flags and 3-21% faster with -C target-cpu=native. Using PCMPESTRM throughout was 0-12% slower.

@Dr-Emann
Dr-Emann added this pull request to stack #381 October 9, 2026 17:16
@Dr-Emann
Dr-Emann force-pushed the stable_simd_pcmpistrm branch from ea864db to 3efbae2 Compare October 9, 2026 17:22
@Dr-Emann
Dr-Emann force-pushed the stable_simd_pcmpistrm branch from 3efbae2 to b21d9fd Compare October 9, 2026 19:05
@Dr-Emann
Dr-Emann force-pushed the stable_simd_pcmpistrm branch 2 times, most recently from 9c10d41 to 51fde93 Compare October 9, 2026 19:56
@emschwartz emschwartz mentioned this pull request Oct 10, 2026

@Kerollmops Kerollmops left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive changes thank you! And all that without unsafe, great 👍

I was wondering if it would be hard to do the same for ARMv8 architecture or if this function is not necessarily impacted by the PCMPESTRM instruction equivalent? I suppose it's not.

@Dr-Emann
Dr-Emann force-pushed the stable_simd_pcmpistrm branch from 51fde93 to a7f51ff Compare October 22, 2026 03:23
@Dr-Emann

Copy link
Copy Markdown
Member Author

I don't believe there's any equivalent operation on ARM/aarch64.

Following CRoaring, compare a vector of `lhs` against a vector of `rhs`
with the SSE4.2 PCMPISTRM instruction via a `fearless_simd::kernel!`.
PCMPISTRM treats a zero lane as the end of the string, so the slower
PCMPESTRM is used while either current vector may start with a zero (only
possible at the start of the sorted arrays). Other SIMD levels keep the
portable all-pairs comparison.

Compared with the portable comparison, `and`, `and_len` and `sub` are
4-13% faster with default flags and 3-21% faster with
`-C target-cpu=native`. Using PCMPESTRM throughout was 0-12% slower.
@Dr-Emann
Dr-Emann force-pushed the stable_simd_pcmpistrm branch from a7f51ff to 1edc9af Compare October 23, 2026 00:14
@Kerollmops
Kerollmops added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit d364c83 Oct 26, 2026
28 checks passed
@Kerollmops
Kerollmops deleted the stable_simd_pcmpistrm branch October 26, 2026 15:51
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.

2 participants