Skip to content

Conversation

@tarcieri
Copy link
Member

Generically implements selecting between two values based upon a provided mask value, rather than duplicating this logic

@tarcieri tarcieri force-pushed the cmov/generic-mask-selection branch from 86caefd to 78ebe66 Compare January 15, 2026 15:01
Generically implements selecting between two values based upon a
provided mask value, rather than duplicating this logic
@tarcieri tarcieri force-pushed the cmov/generic-mask-selection branch from 78ebe66 to 2f2eb8d Compare January 15, 2026 15:05
@tarcieri tarcieri merged commit b53e6bf into master Jan 15, 2026
22 checks passed
@tarcieri tarcieri deleted the cmov/generic-mask-selection branch January 15, 2026 15:20
tarcieri added a commit that referenced this pull request Jan 15, 2026
Uses the `masksel` function added in #1342 to impl `CmovEq`. This should
be less circuitious than the previous implementation.

Mask generation still goes through `masknz32`/`masknz64` which either
use `testnz32`/`testnz64` and `black_box` or use an optimized assembly
implementation of `masknz32` (vicariously for `masknz64`), which means
these functions still have a strategy to prevent branch insertion.
tarcieri added a commit that referenced this pull request Jan 15, 2026
Uses the `masksel` function added in #1342 to impl `CmovEq`. This should
be less circuitious than the previous implementation.

This approach means we can get rid of all of the `test*` functions like
`testeq*`, `testne*`, and `testnz*` and implement everything in terms of
mask generation.

The pure Rust versions of `masknz32` and `masknz64` still internally use
`black_box` to prevent optimizations around the non-zero bit extracted
before computing the mask.
tarcieri added a commit that referenced this pull request Jan 15, 2026
Uses the `masksel` function added in #1342 to impl `CmovEq`. This should
be less circuitious than the previous implementation.

This approach means we can get rid of all of the `test*` functions like
`testeq*`, `testne*`, and `testnz*` and implement everything in terms of
mask generation.

The pure Rust versions of `masknz32` and `masknz64` still internally use
`black_box` to prevent optimizations around the non-zero bit extracted
before computing the mask.
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