Skip to content

Fix undefined behavior in movemask_epi8 #1354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/core_arch/src/x86/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,9 @@ pub unsafe fn _mm256_min_epu8(a: __m256i, b: __m256i) -> __m256i {
#[cfg_attr(test, assert_instr(vpmovmskb))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm256_movemask_epi8(a: __m256i) -> i32 {
simd_bitmask::<_, u32>(a.as_i8x32()) as i32
let z = i8x32::splat(0);
let m: i8x32 = simd_lt(a.as_i8x32(), z);
simd_bitmask::<_, u32>(m) as i32
}

/// Computes the sum of absolute differences (SADs) of quadruplets of unsigned
Expand Down
4 changes: 3 additions & 1 deletion crates/core_arch/src/x86/sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,9 @@ pub unsafe fn _mm_insert_epi16<const IMM8: i32>(a: __m128i, i: i32) -> __m128i {
#[cfg_attr(test, assert_instr(pmovmskb))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_movemask_epi8(a: __m128i) -> i32 {
simd_bitmask::<_, u16>(a.as_i8x16()) as u32 as i32
let z = i8x16::splat(0);
let m: i8x16 = simd_lt(a.as_i8x16(), z);
simd_bitmask::<_, u16>(m) as u32 as i32
}

/// Shuffles 32-bit integers in `a` using the control in `IMM8`.
Expand Down