rust-lang / rust-lang/stdarch

`_mm_adds_epu8` doesn't generate the right instruction.

Open
#2,154 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
694
Forks
336
Avg merge
5d 14h
Merged PRs (30d)
9

Description

https://godbolt.org/z/KTTPcKP58

#[target_feature(enable = "sse2")]
pub fn simd_gte2(x: __m128i) -> i32 {
  let bc = _mm_set1_epi8(0x7e);
  let y = _mm_adds_epu8(x, bc);
  
   _mm_movemask_epi8(y)
}
.LCPI0_0:
        .zero   16,2
example::simd_gte2:
        movdqa  xmm0, xmmword ptr [rdi]
        movdqa  xmm1, xmmword ptr [rip + .LCPI0_0]
        pmaxub  xmm1, xmm0 ; 1
        pcmpeqb xmm1, xmm0 ; 2: these two instructions can be simplified to paddusb
        pmovmskb        eax, xmm1
        ret

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 _mm_adds_epu8 implementation and its existing tests in stdarch, then reproduce the Godbolt example to inspect the generated assembly. Trace the intrinsic's lowering and add a regression test that verifies the expected saturating-add instruction is emitted instead of the pmaxub/pcmpeqb sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.