convert _mm512_slli_epi16 to const generics

This commit is contained in:
Rémy Rakic 2021-03-04 23:23:51 +01:00 committed by Amanieu d'Antras
parent 70f22e3f5a
commit 9901c39e08
2 changed files with 23 additions and 10 deletions

View file

@ -5008,16 +5008,12 @@ pub unsafe fn _mm_maskz_sll_epi16(k: __mmask8, a: __m128i, count: __m128i) -> __
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_slli_epi16&expand=5301)
#[inline]
#[target_feature(enable = "avx512bw")]
#[cfg_attr(test, assert_instr(vpsllw, imm8 = 5))]
#[rustc_args_required_const(1)]
pub unsafe fn _mm512_slli_epi16(a: __m512i, imm8: u32) -> __m512i {
#[cfg_attr(test, assert_instr(vpsllw, IMM8 = 5))]
#[rustc_legacy_const_generics(1)]
pub unsafe fn _mm512_slli_epi16<const IMM8: u32>(a: __m512i) -> __m512i {
static_assert_imm_u8!(IMM8);
let a = a.as_i16x32();
macro_rules! call {
($imm8:expr) => {
vpslliw(a, $imm8)
};
}
let r = constify_imm8_sae!(imm8, call);
let r = vpslliw(a, IMM8);
transmute(r)
}
@ -14476,7 +14472,7 @@ mod tests {
#[simd_test(enable = "avx512bw")]
unsafe fn test_mm512_slli_epi16() {
let a = _mm512_set1_epi16(1 << 15);
let r = _mm512_slli_epi16(a, 1);
let r = _mm512_slli_epi16::<1>(a);
let e = _mm512_set1_epi16(0);
assert_eq_m512i(r, e);
}

View file

@ -32,6 +32,23 @@ macro_rules! static_assert_sae {
};
}
// Helper struct used to trigger const eval errors when the unsigned const generic immediate value
// `IMM` is out of `[MIN-MAX]` range.
pub(crate) struct ValidateConstImmU32<const IMM: u32, const MIN: u32, const MAX: u32>;
impl<const IMM: u32, const MIN: u32, const MAX: u32> ValidateConstImmU32<IMM, MIN, MAX> {
pub(crate) const VALID: () = {
let _ = 1 / ((IMM >= MIN && IMM <= MAX) as usize);
};
}
#[allow(unused_macros)]
macro_rules! static_assert_imm_u8 {
($imm:ident) => {
let _ =
$crate::core_arch::x86::macros::ValidateConstImmU32::<$imm, 0, { (1 << 8) - 1 }>::VALID;
};
}
macro_rules! constify_imm3 {
($imm8:expr, $expand:ident) => {
#[allow(overflowing_literals)]