Skip to content

Commit be08cd6

Browse files
lqdAmanieu
authored andcommitted
convert _mm256_inserti128_si256 to const generics
1 parent edf90ff commit be08cd6

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

crates/core_arch/src/x86/avx2.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,24 +1813,22 @@ pub unsafe fn _mm256_mask_i64gather_pd<const SCALE: i32>(
18131813
}
18141814

18151815
/// Copies `a` to `dst`, then insert 128 bits (of integer data) from `b` at the
1816-
/// location specified by `imm8`.
1816+
/// location specified by `IMM1`.
18171817
///
18181818
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm256_inserti128_si256)
18191819
#[inline]
18201820
#[target_feature(enable = "avx2")]
18211821
#[cfg_attr(
18221822
all(test, not(target_os = "windows")),
1823-
assert_instr(vinsertf128, imm8 = 1)
1823+
assert_instr(vinsertf128, IMM1 = 1)
18241824
)]
1825-
#[rustc_args_required_const(2)]
1825+
#[rustc_legacy_const_generics(2)]
18261826
#[stable(feature = "simd_x86", since = "1.27.0")]
1827-
pub unsafe fn _mm256_inserti128_si256(a: __m256i, b: __m128i, imm8: i32) -> __m256i {
1827+
pub unsafe fn _mm256_inserti128_si256<const IMM1: i32>(a: __m256i, b: __m128i) -> __m256i {
1828+
static_assert_imm1!(IMM1);
18281829
let a = a.as_i64x4();
18291830
let b = _mm256_castsi128_si256(b).as_i64x4();
1830-
let dst: i64x4 = match imm8 & 0b01 {
1831-
0 => simd_shuffle4(a, b, [4, 5, 2, 3]),
1832-
_ => simd_shuffle4(a, b, [0, 1, 4, 5]),
1833-
};
1831+
let dst: i64x4 = simd_shuffle4(a, b, [[4, 5, 2, 3], [0, 1, 4, 5]][IMM1 as usize]);
18341832
transmute(dst)
18351833
}
18361834

@@ -4494,7 +4492,7 @@ mod tests {
44944492
unsafe fn test_mm256_inserti128_si256() {
44954493
let a = _mm256_setr_epi64x(1, 2, 3, 4);
44964494
let b = _mm_setr_epi64x(7, 8);
4497-
let r = _mm256_inserti128_si256(a, b, 0b01);
4495+
let r = _mm256_inserti128_si256::<1>(a, b);
44984496
let e = _mm256_setr_epi64x(1, 2, 7, 8);
44994497
assert_eq_m256i(r, e);
45004498
}

0 commit comments

Comments
 (0)