rust-lang / rust-lang/portable-simd
Mask operations are not optimized well
Open
Nobody has claimed this yet.
C-bug
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 108
- Avg merge
- 22h 53m
- Merged PRs (30d)
- 3
Description
I tried this code (godbolt):
#![feature(portable_simd)]
use std::simd::prelude::*;
type Simd = u8x16;
#[no_mangle]
pub fn check_hex(chunk: Simd) -> bool {
let valid_digit = chunk.simd_ge(Simd::splat(b'0')) & chunk.simd_le(Simd::splat(b'9'));
let valid_upper = chunk.simd_ge(Simd::splat(b'A')) & chunk.simd_le(Simd::splat(b'F'));
let valid_lower = chunk.simd_ge(Simd::splat(b'a')) & chunk.simd_le(Simd::splat(b'f'));
let valid = valid_digit | valid_upper | valid_lower;
valid.all()
}
I expected to see this happen: optimizes as well as the hand-rolled x86 version
Instead, this happened: doesn't, see godbolt
Meta
rustc --version --verbose:
rustc 1.91.0-nightly (1ebbd87a6 2025-08-11)
binary: rustc
commit-hash: 1ebbd87a62ce96a72b22da61b7c2c43893534842
commit-date: 2025-08-11
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0
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 with the Rust reproducer and its Godbolt link, then compare the generated code for the portable-SIMD mask operations with the hand-rolled x86 version. Identify why the mask expression is not optimized equivalently; done means the reproducer generates comparably efficient code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100