Fix undefined behavior in movemask_epi8 (#1354)

Fixes https://github.com/rust-lang/stdarch/issues/1347
This commit is contained in:
Nugine 2022-11-17 02:15:48 +08:00 committed by GitHub
parent 75127705cc
commit 83cd38d056
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -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

View file

@ -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`.