rust-lang / rust-lang/portable-simd

`Simd::gather_unchecked()`

Open
#475 3 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

I've been tinkering with Simd::gather_or_default() and noticed that it optimizes far worse than I'd like and it turned out to be caused by bounds checks.

Example

I just happen to know that due to the logic of the code, it can never ever go out of bounds, but compiler can't reason that far. As you can see, assembly is quite compact and does use vpgatherdd as I expected. Now change if true to if false to make it use Simd::gather_or_default(). There is much more code now and it performs measurably worse too.

So I'd like to request something like Simd::gather_unchecked().

I see there are a bunch of gather variants, but they all support a lot of features and generate worse code as the result. For example, Simd::gather_select_unchecked() is unable to optimize-out Mask::splat(true). If it did, I think it would be pretty much what I need, but I don't know how realistic it is to expect such an optimization.

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 the issue's Godbolt example and compare Simd::gather_or_default() with Simd::gather_select_unchecked(), especially the Mask::splat(true) case. Determine whether an unchecked gather API or an equivalent optimization best addresses the bounds-check overhead, then verify that the resulting assembly uses the intended compact gather instruction without changing safety requirements.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.