rust-lang / rust-lang/portable-simd

swizzle_dyn: variant where out-of-bounds indices return implementation-defined result

Open
#486 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request
Dominant language
Rust
Stars
1.1k
Forks
108
Avg merge
22h 53m
Merged PRs (30d)
3

Description

One of the swizzle variants is defined like this:

https://github.com/rust-lang/portable-simd/blob/d7a525f66ace336c4b67bf1576c4ce341ac110c9/crates/core_simd/src/swizzle_dyn.rs#L40-L41

With zeroing_idxs being a function that sets the most significant bit to 1 (so that the result is 0) without touching the relevant least significant bits.

The problem is: there are situations where the user can guarantee that out-of-bounds indices always have the most significant bits set to 1, but there is no way to communicate it to swizzle_dyn, which will always waste performance with zeroing_idxs.

The only way to prevent the inefficiency is with a new function that doesn't call zeroing_idxs in the first place.

Similar situation with avx2_pshufb, which does pretty much the same thing.

Relevant: https://github.com/linebender/fearless_simd/pull/304.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with crates/core_simd/src/swizzle_dyn.rs at the linked definition, then inspect avx2_pshufb and the linked fearless_simd pull request for the related use case. Define the requested variant that avoids zeroing_idxs when callers guarantee the high bits of out-of-bounds indices, covering both relevant swizzle paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.