Add static_assert_imm{1,5,6} macros
This commit is contained in:
committed by
Amanieu d'Antras
parent
da451f7195
commit
33937e8ef7
@@ -1,46 +1,60 @@
|
|||||||
//! Utility macros.
|
//! Utility macros.
|
||||||
|
|
||||||
// Helper struct used to trigger const eval errors when the const generic immediate value `imm` is
|
// Helper struct used to trigger const eval errors when the const generic immediate value `IMM` is
|
||||||
// out of `bits`-bit range.
|
// out of `[MIN-MAX]` range.
|
||||||
pub(crate) struct ValidateConstImm<const IMM: i32, const BITS: i32>;
|
pub(crate) struct ValidateConstImm<const IMM: i32, const MIN: i32, const MAX: i32>;
|
||||||
impl<const IMM: i32, const BITS: i32> ValidateConstImm<IMM, BITS> {
|
impl<const IMM: i32, const MIN: i32, const MAX: i32> ValidateConstImm<IMM, MIN, MAX> {
|
||||||
pub(crate) const VALID: () = {
|
pub(crate) const VALID: () = {
|
||||||
let _ = 1 / ((IMM >= 0 && IMM < (1 << BITS)) as usize);
|
let _ = 1 / ((IMM >= MIN && IMM <= MAX) as usize);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! static_assert_imm1 {
|
macro_rules! static_assert_imm1 {
|
||||||
($imm:ident) => {
|
($imm:ident) => {
|
||||||
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 1>::VALID;
|
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 0, { (1 << 1) - 1 }>::VALID;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! static_assert_imm2 {
|
macro_rules! static_assert_imm2 {
|
||||||
($imm:ident) => {
|
($imm:ident) => {
|
||||||
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 2>::VALID;
|
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 0, { (1 << 2) - 1 }>::VALID;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! static_assert_imm3 {
|
macro_rules! static_assert_imm3 {
|
||||||
($imm:ident) => {
|
($imm:ident) => {
|
||||||
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 3>::VALID;
|
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 0, { (1 << 3) - 1 }>::VALID;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! static_assert_imm4 {
|
macro_rules! static_assert_imm4 {
|
||||||
($imm:ident) => {
|
($imm:ident) => {
|
||||||
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 4>::VALID;
|
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 0, { (1 << 4) - 1 }>::VALID;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused_macros)]
|
||||||
|
macro_rules! static_assert_imm5 {
|
||||||
|
($imm:ident) => {
|
||||||
|
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 0, { (1 << 5) - 1 }>::VALID;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
macro_rules! static_assert_imm6 {
|
||||||
|
($imm:ident) => {
|
||||||
|
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 0, { (1 << 6) - 1 }>::VALID;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_macros)]
|
||||||
macro_rules! static_assert_imm8 {
|
macro_rules! static_assert_imm8 {
|
||||||
($imm:ident) => {
|
($imm:ident) => {
|
||||||
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 8>::VALID;
|
let _ = $crate::core_arch::macros::ValidateConstImm::<$imm, 0, { (1 << 8) - 1 }>::VALID;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user