1//! Utility macros.
2
3#[allow(unused)]
4macro_rules! static_assert {
5 ($e:expr) => {
6 const {
7 assert!($e);
8 }
9 };
10 ($e:expr, $msg:expr) => {
11 const {
12 assert!($e, $msg);
13 }
14 };
15}
16
17#[allow(unused_macros)]
18macro_rules! static_assert_uimm_bits {
19 ($imm:ident, $bits:expr) => {
20 // `0 <= $imm` produces a warning if the immediate has an unsigned type
21 #[allow(unused_comparisons)]
22 {
23 static_assert!(
24 0 <= $imm && $imm < (1 << $bits),
25 concat!(
26 stringify!($imm),
27 " doesn't fit in ",
28 stringify!($bits),
29 " bits",
30 )
31 )
32 }
33 };
34}
35
36#[allow(unused_macros)]
37macro_rules! static_assert_simm_bits {
38 ($imm:ident, $bits:expr) => {
39 static_assert!(
40 (-1 << ($bits - 1)) - 1 <= $imm && $imm < (1 << ($bits - 1)),
41 concat!(
42 stringify!($imm),
43 " doesn't fit in ",
44 stringify!($bits),
45 " bits",
46 )
47 )
48 };
49}
50
51#[allow(unused)]
52macro_rules! types {
53 ($(
54 $(#[$doc:meta])*
55 pub struct $name:ident($($fields:tt)*);
56 )*) => ($(
57 $(#[$doc])*
58 #[derive(Copy, Clone, Debug)]
59 #[allow(non_camel_case_types)]
60 #[repr(simd)]
61 #[allow(clippy::missing_inline_in_public_items)]
62 pub struct $name($($fields)*);
63 )*)
64}
65
66#[allow(unused)]
67macro_rules! simd_shuffle {
68 ($x:expr, $y:expr, $idx:expr $(,)?) => {{
69 simd_shuffle::<_, [u32; _], _>($x, $y, const { $idx })
70 }};
71}
72
73#[allow(unused)]
74macro_rules! simd_insert {
75 ($x:expr, $idx:expr, $val:expr $(,)?) => {{
76 simd_insert($x, const { $idx }, $val)
77 }};
78}
79
80#[allow(unused)]
81macro_rules! simd_extract {
82 ($x:expr, $idx:expr $(,)?) => {{
83 simd_extract($x, const { $idx })
84 }};
85 ($x:expr, $idx:expr, $ty:ty $(,)?) => {{
86 simd_extract::<_, $ty>($x, const { $idx })
87 }};
88}
89