Skip to content

Commit

Permalink
Fix undefined behavior in movemask_epi8 (#1354)
Browse files Browse the repository at this point in the history
Fixes #1347
  • Loading branch information
Nugine authored Nov 16, 2022
1 parent 88bef95 commit 547e3b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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

0 comments on commit 547e3b0

Please sign in to comment.