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