Skip to content

Commit 764ae1d

Browse files
committed
Fix implementation of _mm256_alignr_epi8<16>
The function is supposed to return first argument for IMM8 == 8.
1 parent f3f4e1e commit 764ae1d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

crates/core_arch/src/x86/avx2.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
//! [wiki_avx]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions
1919
//! [wiki_fma]: https://en.wikipedia.org/wiki/Fused_multiply-accumulate
2020
21+
use core::hint::unreachable_unchecked;
22+
2123
use crate::core_arch::{simd::*, x86::*};
2224
use crate::intrinsics::simd::*;
2325

@@ -181,6 +183,10 @@ pub unsafe fn _mm256_alignr_epi8<const IMM8: i32>(a: __m256i, b: __m256i) -> __m
181183
let a = a.as_i8x32();
182184
let b = b.as_i8x32();
183185

186+
if IMM8 == 16 {
187+
return transmute(a);
188+
}
189+
184190
let r: i8x32 = match IMM8 % 16 {
185191
0 => simd_shuffle!(
186192
b,
@@ -310,7 +316,7 @@ pub unsafe fn _mm256_alignr_epi8<const IMM8: i32>(a: __m256i, b: __m256i) -> __m
310316
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
311317
],
312318
),
313-
_ => b,
319+
_ => unreachable_unchecked(),
314320
};
315321
transmute(r)
316322
}
@@ -5317,16 +5323,6 @@ mod tests {
53175323
);
53185324
assert_eq_m256i(r, expected);
53195325

5320-
#[rustfmt::skip]
5321-
let expected = _mm256_setr_epi8(
5322-
-1, -2, -3, -4, -5, -6, -7, -8,
5323-
-9, -10, -11, -12, -13, -14, -15, -16, -17,
5324-
-18, -19, -20, -21, -22, -23, -24, -25,
5325-
-26, -27, -28, -29, -30, -31, -32,
5326-
);
5327-
let r = _mm256_alignr_epi8::<16>(a, b);
5328-
assert_eq_m256i(r, expected);
5329-
53305326
let r = _mm256_alignr_epi8::<15>(a, b);
53315327
#[rustfmt::skip]
53325328
let expected = _mm256_setr_epi8(
@@ -5339,6 +5335,9 @@ mod tests {
53395335

53405336
let r = _mm256_alignr_epi8::<0>(a, b);
53415337
assert_eq_m256i(r, b);
5338+
5339+
let r = _mm256_alignr_epi8::<16>(a, b);
5340+
assert_eq_m256i(r, a);
53425341
}
53435342

53445343
#[simd_test(enable = "avx2")]

0 commit comments

Comments
 (0)