1 | //! Utility macros. |
2 | |
3 | #[allow (unused)] |
4 | macro_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)] |
18 | macro_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) - 1, |
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)] |
37 | macro_rules! static_assert_simm_bits { |
38 | ($imm:ident, $bits:expr) => { |
39 | static_assert!( |
40 | (-1 << ($bits - 1)) - 1 <= $imm && $imm <= (1 << ($bits - 1)) - 1, |
41 | concat!( |
42 | stringify!($imm), |
43 | " doesn't fit in " , |
44 | stringify!($bits), |
45 | " bits" , |
46 | ) |
47 | ) |
48 | }; |
49 | } |
50 | |
51 | #[allow (unused)] |
52 | macro_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)] |
67 | macro_rules! simd_shuffle { |
68 | ($x:expr, $y:expr, $idx:expr $(,)?) => {{ |
69 | simd_shuffle( |
70 | $x, |
71 | $y, |
72 | const { |
73 | let v: [u32; _] = $idx; |
74 | v |
75 | }, |
76 | ) |
77 | }}; |
78 | } |
79 | |