Skip to content

Commit 7ef7a4a

Browse files
marxinAmanieu
authored andcommitted
Fix implementation of _mm256_alignr_epi8<16>
The function is supposed to return first argument for IMM8 == 8.
1 parent 13a58f8 commit 7ef7a4a

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

@@ -178,6 +180,10 @@ pub unsafe fn _mm256_alignr_epi8<const IMM8: i32>(a: __m256i, b: __m256i) -> __m
178180
let a = a.as_i8x32();
179181
let b = b.as_i8x32();
180182

183+
if IMM8 == 16 {
184+
return transmute(a);
185+
}
186+
181187
let r: i8x32 = match IMM8 % 16 {
182188
0 => simd_shuffle!(
183189
b,
@@ -307,7 +313,7 @@ pub unsafe fn _mm256_alignr_epi8<const IMM8: i32>(a: __m256i, b: __m256i) -> __m
307313
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
308314
],
309315
),
310-
_ => b,
316+
_ => unreachable_unchecked(),
311317
};
312318
transmute(r)
313319
}
@@ -5305,16 +5311,6 @@ mod tests {
53055311
);
53065312
assert_eq_m256i(r, expected);
53075313

5308-
#[rustfmt::skip]
5309-
let expected = _mm256_setr_epi8(
5310-
-1, -2, -3, -4, -5, -6, -7, -8,
5311-
-9, -10, -11, -12, -13, -14, -15, -16, -17,
5312-
-18, -19, -20, -21, -22, -23, -24, -25,
5313-
-26, -27, -28, -29, -30, -31, -32,
5314-
);
5315-
let r = _mm256_alignr_epi8::<16>(a, b);
5316-
assert_eq_m256i(r, expected);
5317-
53185314
let r = _mm256_alignr_epi8::<15>(a, b);
53195315
#[rustfmt::skip]
53205316
let expected = _mm256_setr_epi8(
@@ -5327,6 +5323,9 @@ mod tests {
53275323

53285324
let r = _mm256_alignr_epi8::<0>(a, b);
53295325
assert_eq_m256i(r, b);
5326+
5327+
let r = _mm256_alignr_epi8::<16>(a, b);
5328+
assert_eq_m256i(r, a);
53305329
}
53315330

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

0 commit comments

Comments
 (0)