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+
2123use crate :: core_arch:: { simd:: * , x86:: * } ;
2224use 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