]> git.proxmox.com Git - rustc.git/blob - src/stdsimd/crates/core_arch/src/x86/macros.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / src / stdsimd / crates / core_arch / src / x86 / macros.rs
1 //! Utility macros.
2
3 macro_rules! constify_imm6 {
4 ($imm8:expr, $expand:ident) => {
5 #[allow(overflowing_literals)]
6 match ($imm8) & 0b1_1111 {
7 0 => $expand!(0),
8 1 => $expand!(1),
9 2 => $expand!(2),
10 3 => $expand!(3),
11 4 => $expand!(4),
12 5 => $expand!(5),
13 6 => $expand!(6),
14 7 => $expand!(7),
15 8 => $expand!(8),
16 9 => $expand!(9),
17 10 => $expand!(10),
18 11 => $expand!(11),
19 12 => $expand!(12),
20 13 => $expand!(13),
21 14 => $expand!(14),
22 15 => $expand!(15),
23 16 => $expand!(16),
24 17 => $expand!(17),
25 18 => $expand!(18),
26 19 => $expand!(19),
27 20 => $expand!(20),
28 21 => $expand!(21),
29 22 => $expand!(22),
30 23 => $expand!(23),
31 24 => $expand!(24),
32 25 => $expand!(25),
33 26 => $expand!(26),
34 27 => $expand!(27),
35 28 => $expand!(28),
36 29 => $expand!(29),
37 30 => $expand!(30),
38 _ => $expand!(31),
39 }
40 };
41 }
42
43 macro_rules! constify_imm4 {
44 ($imm8:expr, $expand:ident) => {
45 #[allow(overflowing_literals)]
46 match ($imm8) & 0b1111 {
47 0 => $expand!(0),
48 1 => $expand!(1),
49 2 => $expand!(2),
50 3 => $expand!(3),
51 4 => $expand!(4),
52 5 => $expand!(5),
53 6 => $expand!(6),
54 7 => $expand!(7),
55 8 => $expand!(8),
56 9 => $expand!(9),
57 10 => $expand!(10),
58 11 => $expand!(11),
59 12 => $expand!(12),
60 13 => $expand!(13),
61 14 => $expand!(14),
62 _ => $expand!(15),
63 }
64 };
65 }
66
67 macro_rules! constify_imm3 {
68 ($imm8:expr, $expand:ident) => {
69 #[allow(overflowing_literals)]
70 match ($imm8) & 0b111 {
71 0 => $expand!(0),
72 1 => $expand!(1),
73 2 => $expand!(2),
74 3 => $expand!(3),
75 4 => $expand!(4),
76 5 => $expand!(5),
77 6 => $expand!(6),
78 _ => $expand!(7),
79 }
80 };
81 }
82
83 macro_rules! constify_imm2 {
84 ($imm8:expr, $expand:ident) => {
85 #[allow(overflowing_literals)]
86 match ($imm8) & 0b11 {
87 0 => $expand!(0),
88 1 => $expand!(1),
89 2 => $expand!(2),
90 _ => $expand!(3),
91 }
92 };
93 }
94
95 #[cfg(test)]
96 macro_rules! assert_approx_eq {
97 ($a:expr, $b:expr, $eps:expr) => {{
98 let (a, b) = (&$a, &$b);
99 assert!(
100 (*a - *b).abs() < $eps,
101 "assertion failed: `(left !== right)` \
102 (left: `{:?}`, right: `{:?}`, expect diff: `{:?}`, real diff: `{:?}`)",
103 *a,
104 *b,
105 $eps,
106 (*a - *b).abs()
107 );
108 }};
109 }