Skip to content

Commit b8465c0

Browse files
committed
Add imm5 and imm_s5 to the common macros
1 parent 2b239c1 commit b8465c0

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

crates/core_arch/src/macros.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,90 @@ macro_rules! constify_imm8 {
265265
};
266266
}
267267

268+
//immediate value: 0:31
269+
#[allow(unused)]
270+
macro_rules! constify_imm5 {
271+
($imm8:expr, $expand:ident) => {
272+
#[allow(overflowing_literals)]
273+
match ($imm8) & 0b1_1111 {
274+
0 => $expand!(0),
275+
1 => $expand!(1),
276+
2 => $expand!(2),
277+
3 => $expand!(3),
278+
4 => $expand!(4),
279+
5 => $expand!(5),
280+
6 => $expand!(6),
281+
7 => $expand!(7),
282+
8 => $expand!(8),
283+
9 => $expand!(9),
284+
10 => $expand!(10),
285+
11 => $expand!(11),
286+
12 => $expand!(12),
287+
13 => $expand!(13),
288+
14 => $expand!(14),
289+
15 => $expand!(15),
290+
16 => $expand!(16),
291+
17 => $expand!(17),
292+
18 => $expand!(18),
293+
19 => $expand!(19),
294+
20 => $expand!(20),
295+
21 => $expand!(21),
296+
22 => $expand!(22),
297+
23 => $expand!(23),
298+
24 => $expand!(24),
299+
25 => $expand!(25),
300+
26 => $expand!(26),
301+
27 => $expand!(27),
302+
28 => $expand!(28),
303+
29 => $expand!(29),
304+
30 => $expand!(30),
305+
_ => $expand!(31),
306+
}
307+
};
308+
}
309+
310+
//immediate value: -16:15
311+
#[allow(unused)]
312+
macro_rules! constify_imm5 {
313+
($imm8:expr, $expand:ident) => {
314+
#[allow(overflowing_literals)]
315+
match ($imm8) & 0b1_1111 {
316+
0 => $expand!(0),
317+
1 => $expand!(1),
318+
2 => $expand!(2),
319+
3 => $expand!(3),
320+
4 => $expand!(4),
321+
5 => $expand!(5),
322+
6 => $expand!(6),
323+
7 => $expand!(7),
324+
8 => $expand!(8),
325+
9 => $expand!(9),
326+
10 => $expand!(10),
327+
11 => $expand!(11),
328+
12 => $expand!(12),
329+
13 => $expand!(13),
330+
14 => $expand!(14),
331+
15 => $expand!(15),
332+
16 => $expand!(16),
333+
17 => $expand!(17),
334+
18 => $expand!(18),
335+
19 => $expand!(19),
336+
20 => $expand!(20),
337+
21 => $expand!(21),
338+
22 => $expand!(22),
339+
23 => $expand!(23),
340+
24 => $expand!(24),
341+
25 => $expand!(25),
342+
26 => $expand!(26),
343+
27 => $expand!(27),
344+
28 => $expand!(28),
345+
29 => $expand!(29),
346+
30 => $expand!(30),
347+
_ => $expand!(31),
348+
}
349+
};
350+
}
351+
268352
#[allow(unused)]
269353
macro_rules! types {
270354
($(

0 commit comments

Comments
 (0)