rust-lang / rust-lang/portable-simd

Support `MaybeUninit` vectors

Open
#286 9 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

Vectors of MaybeUninit values and operations over them (eg. Simd<MaybeUninit<T>, N> + Simd<MaybeUninit<T>, N>) would be incredibly useful for more advanced struct of array operations.
This is mostly inspired by how Futhark handles sum types and is something that I actually have a use case for.
The basic premise is that we hold and perform operations over potentially uninit values but only keep the values that are defined. A more concrete case of this would be in a struct of array Option type

struct SoaOption<T> {
    discriminants: Vec<bool>,
    values: Vec<MaybeUninit<T>>,
}

// The general operation we're performing is `Option::map(|x| x * 2)`, but over the entire array of options
let mut options: SoaOption<u32> = ...;
options.values.as_simd_mut().for_each(|x: MaybeUninit<u32>| x * Simd::splat(2));

// Then later when we're unpacking our struct of array form, we use our `discriminants` vector to tell us whether it's a `Some` or `None`
let mut unpacked: Vec<Option<u32>> = options
    .discriminants
    .into_iter()
    .zip(options.values)
    .map(|(discrim, x)| discrim.then(|| x.assume_init()))
    .collect();

This allows efficiently operating over SoA formed enums, which would be amazing

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 by reviewing the existing Simd vector-operation APIs and how MaybeUninit values are represented. The issue provides no files or tests to run; done would require agreeing on an API and ensuring operations preserve defined values while safely handling uninitialized lanes.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.