Uh oh!
There was an error while loading. Please reload this page.
Optimized implementation for uN::{gather,scatter}_bits - #149663
Conversation
This comment has been minimized.
This comment has been minimized.
9549004 to
2c752afCompare
This comment has been minimized.
This comment has been minimized.
2c752af to
ac7e6c6CompareDo take this with a grain of salt, since I authored the benchmarks with this in mind. In particular, since the new implementation doesn't have any input-dependent control-flow, it is easily vectorized which all of these benchmarks allow for. Benchmarked locally on an
|
rustbot
commented
Dec 5, 2025
rustbot has assigned @Mark-Simulacrum. Use |
There was a problem hiding this comment.
Nice work.
I noticed spot-checking some random constant masks that this implementation and the HD implementation flip-flop on which has more instructions, but it's only a small difference count. On simpler masks, they seem to optimize similarly.
The dynamic mask output is a drastic improvement with this by a quarter/third reduction of instructions for gather and scatter.
alive2 showing that this implementation and the current implementation appear to be equivalent functions
gather - https://alive2.llvm.org/ce/z/wKxY2Z
scatter - https://alive2.llvm.org/ce/z/_98DbY
scratchpad for the LLVM IR output - https://rust.godbolt.org/z/brbePx44T
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Mark-Simulacrum
commented
Dec 28, 2025
@bors r+ rollup |
bors
commented
Dec 28, 2025
… r=Mark-Simulacrum
Optimized implementation for uN::{gather,scatter}_bits
Feature gate: #![feature(uint_gather_scatter_bits)]
Tracking issue: rust-lang#149069
Accepted ACP: rust-lang/libs-team#695
Implements the methods using the parallel suffix strategy mentioned in the ACP discussion. The referenced source material provides C implementations, though this PR makes improvements over those, cutting the instruction count by a third:
https://rust.godbolt.org/z/rn5naYnK4 (this PR)
https://c.godbolt.org/z/WzYd5WbsY (Hacker's delight)
This was initially based on the code for `gather_bits` that `@okaneco` provided in rust-lang/libs-team#695 (comment) . I wanted to understand how it worked, and later on noticed some opportunities for improvement, which eventually led to this PR.…uwer Rollup of 8 pull requests Successful merges: - #148321 (parser/lexer: bump to Unicode 17, use faster unicode-ident) - #149540 (std: sys: fs: uefi: Implement readdir) - #149582 (Implement `Duration::div_duration_{floor,ceil}`) - #149663 (Optimized implementation for uN::{gather,scatter}_bits) - #149667 (Fix ICE by rejecting const blocks in patterns during AST lowering (closes#148138)) - #149947 (add several older crashtests) - #150011 (Add more `unbounded_sh[lr]` examples) - #150411 (refactor `destructure_const`) r? `@ghost` `@rustbot` modify labels: rollup
Uh oh!
There was an error while loading. Please reload this page.
Rollup merge of #149663 - quaternic:gather-scatter-bits-opt, r=Mark-Simulacrum Optimized implementation for uN::{gather,scatter}_bits Feature gate: #![feature(uint_gather_scatter_bits)] Tracking issue: #149069 Accepted ACP: rust-lang/libs-team#695 Implements the methods using the parallel suffix strategy mentioned in the ACP discussion. The referenced source material provides C implementations, though this PR makes improvements over those, cutting the instruction count by a third: https://rust.godbolt.org/z/rn5naYnK4 (this PR) https://c.godbolt.org/z/WzYd5WbsY (Hacker's delight) This was initially based on the code for `gather_bits` that ``@okaneco`` provided in rust-lang/libs-team#695 (comment) . I wanted to understand how it worked, and later on noticed some opportunities for improvement, which eventually led to this PR.
…uwer Rollup of 8 pull requests Successful merges: - rust-lang/rust#148321 (parser/lexer: bump to Unicode 17, use faster unicode-ident) - rust-lang/rust#149540 (std: sys: fs: uefi: Implement readdir) - rust-lang/rust#149582 (Implement `Duration::div_duration_{floor,ceil}`) - rust-lang/rust#149663 (Optimized implementation for uN::{gather,scatter}_bits) - rust-lang/rust#149667 (Fix ICE by rejecting const blocks in patterns during AST lowering (closesrust-lang/rust#148138)) - rust-lang/rust#149947 (add several older crashtests) - rust-lang/rust#150011 (Add more `unbounded_sh[lr]` examples) - rust-lang/rust#150411 (refactor `destructure_const`) r? `@ghost` `@rustbot` modify labels: rollup
Feature gate: #![feature(uint_gather_scatter_bits)]
Tracking issue: #149069
Accepted ACP: rust-lang/libs-team#695
Implements the methods using the parallel suffix strategy mentioned in the ACP discussion. The referenced source material provides C implementations, though this PR makes improvements over those, cutting the instruction count by a third:
https://rust.godbolt.org/z/rn5naYnK4 (this PR)
https://c.godbolt.org/z/WzYd5WbsY (Hacker's delight)
This was initially based on the code for
gather_bitsthat @okaneco provided in rust-lang/libs-team#695 (comment) . I wanted to understand how it worked, and later on noticed some opportunities for improvement, which eventually led to this PR.