ab_riscv_primitives/instruction/rv64/
b.rs1pub mod zba;
4pub mod zbb;
5pub mod zbc;
6pub mod zbs;
7
8use crate::instruction::Instruction;
9use crate::instruction::rv64::Rv64Instruction;
10use crate::instruction::rv64::b::zba::Rv64ZbaInstruction;
11use crate::instruction::rv64::b::zbb::Rv64ZbbInstruction;
12use crate::instruction::rv64::b::zbc::Rv64ZbcInstruction;
13use crate::instruction::rv64::b::zbs::Rv64ZbsInstruction;
14use crate::registers::Register;
15use core::fmt;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum Rv64BInstruction<Reg> {
20 Zba(Rv64ZbaInstruction<Reg>),
21 Zbb(Rv64ZbbInstruction<Reg>),
22 Zbs(Rv64ZbsInstruction<Reg>),
23}
24
25impl<Reg> const Instruction for Rv64BInstruction<Reg>
26where
27 Reg: [const] Register<Type = u64>,
28{
29 type Base = Rv64Instruction<Reg>;
30
31 #[inline(always)]
32 fn try_decode(instruction: u32) -> Option<Self> {
33 if let Some(instruction) = Rv64ZbaInstruction::<Reg>::try_decode(instruction) {
34 Some(Self::Zba(instruction))
35 } else if let Some(instruction) = Rv64ZbbInstruction::<Reg>::try_decode(instruction) {
36 Some(Self::Zbb(instruction))
37 } else if let Some(instruction) = Rv64ZbsInstruction::<Reg>::try_decode(instruction) {
38 Some(Self::Zbs(instruction))
39 } else {
40 None
41 }
42 }
43
44 #[inline(always)]
45 fn size(&self) -> u8 {
46 size_of::<u32>() as u8
47 }
48}
49
50impl<Reg> fmt::Display for Rv64BInstruction<Reg>
51where
52 Reg: fmt::Display,
53{
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 match self {
56 Rv64BInstruction::Zba(instruction) => instruction.fmt(f),
57 Rv64BInstruction::Zbb(instruction) => instruction.fmt(f),
58 Rv64BInstruction::Zbs(instruction) => instruction.fmt(f),
59 }
60 }
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum Rv64BZbcInstruction<Reg> {
66 Zba(Rv64ZbaInstruction<Reg>),
67 Zbb(Rv64ZbbInstruction<Reg>),
68 Zbc(Rv64ZbcInstruction<Reg>),
69 Zbs(Rv64ZbsInstruction<Reg>),
70}
71
72impl<Reg> const Instruction for Rv64BZbcInstruction<Reg>
73where
74 Reg: [const] Register<Type = u64>,
75{
76 type Base = Rv64Instruction<Reg>;
77
78 #[inline(always)]
79 fn try_decode(instruction: u32) -> Option<Self> {
80 if let Some(instruction) = Rv64ZbaInstruction::<Reg>::try_decode(instruction) {
81 Some(Self::Zba(instruction))
82 } else if let Some(instruction) = Rv64ZbbInstruction::<Reg>::try_decode(instruction) {
83 Some(Self::Zbb(instruction))
84 } else if let Some(instruction) = Rv64ZbcInstruction::<Reg>::try_decode(instruction) {
85 Some(Self::Zbc(instruction))
86 } else if let Some(instruction) = Rv64ZbsInstruction::<Reg>::try_decode(instruction) {
87 Some(Self::Zbs(instruction))
88 } else {
89 None
90 }
91 }
92
93 #[inline(always)]
94 fn size(&self) -> u8 {
95 size_of::<u32>() as u8
96 }
97}
98
99impl<Reg> fmt::Display for Rv64BZbcInstruction<Reg>
100where
101 Reg: fmt::Display,
102{
103 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104 match self {
105 Rv64BZbcInstruction::Zba(instruction) => instruction.fmt(f),
106 Rv64BZbcInstruction::Zbb(instruction) => instruction.fmt(f),
107 Rv64BZbcInstruction::Zbc(instruction) => instruction.fmt(f),
108 Rv64BZbcInstruction::Zbs(instruction) => instruction.fmt(f),
109 }
110 }
111}