From d4558e1b307e594f29602fd45752d278b4eb47b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sat, 6 Mar 2021 00:34:58 +0100 Subject: [PATCH] add helper macro for const generics gather instructions' scales --- .../stdarch/crates/core_arch/src/x86/macros.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/stdarch/crates/core_arch/src/x86/macros.rs b/library/stdarch/crates/core_arch/src/x86/macros.rs index 8a6f025d534b..73c6ab0ecdce 100644 --- a/library/stdarch/crates/core_arch/src/x86/macros.rs +++ b/library/stdarch/crates/core_arch/src/x86/macros.rs @@ -49,6 +49,22 @@ macro_rules! static_assert_imm_u8 { }; } +// Helper struct used to trigger const eval errors when the const generic immediate value `SCALE` is +// not valid for gather instructions: the only valid scale values are 1, 2, 4 and 8. +pub(crate) struct ValidateConstGatherScale; +impl ValidateConstGatherScale { + pub(crate) const VALID: () = { + let _ = 1 / ((SCALE == 1 || SCALE == 2 || SCALE == 4 || SCALE == 8) as usize); + }; +} + +#[allow(unused)] +macro_rules! static_assert_imm8_scale { + ($imm:ident) => { + let _ = $crate::core_arch::x86::macros::ValidateConstGatherScale::<$imm>::VALID; + }; +} + macro_rules! constify_imm3 { ($imm8:expr, $expand:ident) => { #[allow(overflowing_literals)]