Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert x86/sse41.rs intrinsics to const generics #1026

Merged
merged 2 commits into from
Mar 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions crates/core_arch/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
//! Utility macros.

// Helper struct used to trigger const eval errors when a const generic immediate value is
// out of range.
pub(crate) struct ValidateConstImm8<const imm8: i32>();
impl<const imm8: i32> ValidateConstImm8<imm8> {
// Helper struct used to trigger const eval errors when the const generic immediate value `imm` is
// out of `bits`-bit range.
pub(crate) struct ValidateConstImm<const imm: i32, const bits: i32>;
impl<const imm: i32, const bits: i32> ValidateConstImm<imm, bits> {
pub(crate) const VALID: () = {
let _ = 1 / ((imm8 >= 0 && imm8 <= 255) as usize);
let _ = 1 / ((imm >= 0 && imm < (1 << bits)) as usize);
};
}

#[allow(unused)]
macro_rules! static_assert_imm2 {
($imm:ident) => {
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 2>::VALID;
};
}

#[allow(unused)]
macro_rules! static_assert_imm3 {
($imm:ident) => {
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 3>::VALID;
};
}

#[allow(unused)]
macro_rules! static_assert_imm4 {
($imm:ident) => {
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 4>::VALID;
};
}

#[allow(unused)]
macro_rules! static_assert_imm8 {
($imm:ident) => {
let _ = $crate::core_arch::macros::ValidateConstImm8::<$imm>::VALID;
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 8>::VALID;
};
}

10 changes: 5 additions & 5 deletions crates/core_arch/src/x86/avx2.rs
Original file line number Diff line number Diff line change
@@ -4415,14 +4415,14 @@ mod tests {

#[simd_test(enable = "avx2")]
unsafe fn test_mm_broadcastb_epi8() {
let a = _mm_insert_epi8(_mm_set1_epi8(0x00), 0x2a, 0);
let a = _mm_insert_epi8::<0>(_mm_set1_epi8(0x00), 0x2a);
let res = _mm_broadcastb_epi8(a);
assert_eq_m128i(res, _mm_set1_epi8(0x2a));
}

#[simd_test(enable = "avx2")]
unsafe fn test_mm256_broadcastb_epi8() {
let a = _mm_insert_epi8(_mm_set1_epi8(0x00), 0x2a, 0);
let a = _mm_insert_epi8::<0>(_mm_set1_epi8(0x00), 0x2a);
let res = _mm256_broadcastb_epi8(a);
assert_eq_m256i(res, _mm256_set1_epi8(0x2a));
}
@@ -5204,7 +5204,7 @@ mod tests {
#[simd_test(enable = "avx2")]
unsafe fn test_mm256_sll_epi32() {
let a = _mm256_set1_epi32(0xFFFF);
let b = _mm_insert_epi32(_mm_set1_epi32(0), 4, 0);
let b = _mm_insert_epi32::<0>(_mm_set1_epi32(0), 4);
let r = _mm256_sll_epi32(a, b);
assert_eq_m256i(r, _mm256_set1_epi32(0xFFFF0));
}
@@ -5295,7 +5295,7 @@ mod tests {
#[simd_test(enable = "avx2")]
unsafe fn test_mm256_sra_epi32() {
let a = _mm256_set1_epi32(-1);
let b = _mm_insert_epi32(_mm_set1_epi32(0), 1, 0);
let b = _mm_insert_epi32::<0>(_mm_set1_epi32(0), 1);
let r = _mm256_sra_epi32(a, b);
assert_eq_m256i(r, _mm256_set1_epi32(-1));
}
@@ -5365,7 +5365,7 @@ mod tests {
#[simd_test(enable = "avx2")]
unsafe fn test_mm256_srl_epi32() {
let a = _mm256_set1_epi32(0xFFFF);
let b = _mm_insert_epi32(_mm_set1_epi32(0), 4, 0);
let b = _mm_insert_epi32::<0>(_mm_set1_epi32(0), 4);
let r = _mm256_srl_epi32(a, b);
assert_eq_m256i(r, _mm256_set1_epi32(0xFFF));
}
Loading