Skip to content

Comments

x86: use simd::intrinsics for bitshifts #2034

Open
okaneco wants to merge 6 commits intorust-lang:mainfrom
okaneco:shifts
Open

x86: use simd::intrinsics for bitshifts #2034
okaneco wants to merge 6 commits intorust-lang:mainfrom
okaneco:shifts

Conversation

@okaneco
Copy link
Contributor

@okaneco okaneco commented Feb 19, 2026

  • Use intrinsics in sse2, avx2, avx512f, and avx512bw
  • Mark intrinsics and tests that call these functions as const

Nothing notable about the implementation.

Intrinsics take count as the shift argument with the shift being a u64 in the low 64-bits of an __m128i. The shift amount must be less than the bit width of the type being shifted.

@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2026

r? @Amanieu

rustbot has assigned @Amanieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Amanieu, @folkertdev, @sayantn
  • @Amanieu, @folkertdev, @sayantn expanded to Amanieu, folkertdev, sayantn
  • Random selection from Amanieu, folkertdev, sayantn

pub const fn _mm_sll_epi16(a: __m128i, count: __m128i) -> __m128i {
let shift = count.as_u64x2().as_array()[0];
unsafe {
if shift >= 16 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check that LLVM is actually able to eliminate this check and fold it into the psllw instruction? It might still be keeping the check and only doing a psllw on the else branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants