rust-lang / rust-lang/rustc_codegen_gcc
simd_gather/scatter implementations seem fundamentally wrong
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.2k
- Forks
- 105
- Avg merge
- 8h 20m
- Merged PRs (30d)
- 14
Description
The point of simd_gather/scatter is that I have a vector of pointers and a mask, and only the pointers that are "enabled" will actually be used. The others may point to garbage memory or memory that is being concurrently read/written by other threads or whatever, they must not be touched.
If I understand the implementations for these intrinsics in compiler/rustc_codegen_gcc/src/intrinsic/simd.rs correctly, then they currently always read and write all the pointers, and uses shuffle to decide which values to keep. Apart from the fact that this does a bunch of sequential loads and stores (completely losing the SIMD effect, making me wonder why a shuffle is used when some basic if-then-else would be a lot simpler), this will make programs that use simd_gather/scatter produce the wrong behavior in quite subtle ways.
As a comparatively minor issue that is not worth tracking separately, the implementation also seems to assume that the length of the vector is a power of 2.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in compiler/rustc_codegen_gcc/src/intrinsic/simd.rs and inspect the simd_gather and simd_scatter implementations, comparing their pointer and mask handling with the issue's required behavior. Verify that disabled pointers are not accessed and consider the stated non-power-of-two vector-length assumption; done means both concerns are addressed and covered by relevant regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100