ab_riscv_primitives/instructions/
zvbb.rs1#[cfg(test)]
4mod tests;
5pub mod zvkb;
6
7use crate::instructions::Instruction;
8use crate::instructions::v::Eew;
9use crate::instructions::v::zvexx::arith::ZveXxArithInstruction;
10use crate::instructions::v::zvexx::carry::ZveXxCarryInstruction;
11use crate::instructions::v::zvexx::config::ZveXxConfigInstruction;
12use crate::instructions::v::zvexx::fixed_point::ZveXxFixedPointInstruction;
13use crate::instructions::v::zvexx::load::{LoadStoreNreg, Nf, SegVmNf, ZveXxLoadInstruction};
14use crate::instructions::v::zvexx::mask::ZveXxMaskInstruction;
15use crate::instructions::v::zvexx::muldiv::ZveXxMulDivInstruction;
16use crate::instructions::v::zvexx::perm::ZveXxPermInstruction;
17use crate::instructions::v::zvexx::reduction::ZveXxReductionInstruction;
18use crate::instructions::v::zvexx::store::ZveXxStoreInstruction;
19use crate::instructions::v::zvexx::widen_narrow::ZveXxWidenNarrowInstruction;
20use crate::instructions::zicsr::ZicsrInstruction;
21use crate::instructions::zvbb::zvkb::ZvkbInstruction;
22use crate::registers::general_purpose::Register;
23use crate::registers::vector::VReg;
24use ab_riscv_macros::instruction;
25use core::fmt;
26
27#[instruction(
52 inherit = [ZvkbInstruction],
53)]
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55#[rustfmt::skip]
56pub enum ZvbbInstruction<Reg> {
57 VbrevV { vd: VReg, vs2: VReg, vm: bool },
60 VclzV { vd: VReg, vs2: VReg, vm: bool },
63 VctzV { vd: VReg, vs2: VReg, vm: bool },
66 VcpopV { vd: VReg, vs2: VReg, vm: bool },
69 VwsllVv { vd: VReg, vs2: VReg, vs1: VReg, vm: bool },
72 VwsllVx { vd: VReg, vs2: VReg, rs1: Reg, vm: bool },
74 VwsllVi { vd: VReg, vs2: VReg, uimm: u8, vm: bool },
77}
78
79#[instruction]
80const impl<Reg> Instruction for ZvbbInstruction<Reg>
81where
82 Reg: [const] Register,
83{
84 type Reg = Reg;
85
86 #[inline(always)]
87 #[cfg_attr(feature = "no-panic", no_panic_const::no_panic(const))]
88 fn try_decode(instruction: u32) -> Option<Self> {
89 let opcode = (instruction & 0b111_1111) as u8;
90
91 if opcode != 0b101_0111 {
92 None?;
93 }
94
95 let vd_bits = ((instruction >> 7) & 0x1f) as u8;
96 let funct3 = ((instruction >> 12) & 0b111) as u8;
97 let vs1_bits = ((instruction >> 15) & 0x1f) as u8;
98 let vs2_bits = ((instruction >> 20) & 0x1f) as u8;
99 let vm = ((instruction >> 25) & 1) as u8 == 1;
101 let funct6 = ((instruction >> 26) & 0b11_1111) as u8;
102
103 let vd = VReg::from_bits(vd_bits)?;
104 let vs2 = VReg::from_bits(vs2_bits)?;
105
106 match funct3 {
107 0b000 => {
109 if funct6 != 0b11_0101 {
110 None?;
111 }
112 let vs1 = VReg::from_bits(vs1_bits)?;
113 Some(Self::VwsllVv { vd, vs2, vs1, vm })
114 }
115 0b100 => {
117 if funct6 != 0b11_0101 {
118 None?;
119 }
120 let rs1 = Reg::from_bits(vs1_bits)?;
121 Some(Self::VwsllVx { vd, vs2, rs1, vm })
122 }
123 0b011 => {
125 if funct6 != 0b11_0101 {
126 None?;
127 }
128 let uimm = vs1_bits;
129 Some(Self::VwsllVi { vd, vs2, uimm, vm })
130 }
131 0b010 => {
135 if funct6 != 0b01_0010 {
136 None?;
137 }
138 match vs1_bits {
139 0b01010 => Some(Self::VbrevV { vd, vs2, vm }),
140 0b01100 => Some(Self::VclzV { vd, vs2, vm }),
141 0b01101 => Some(Self::VctzV { vd, vs2, vm }),
142 0b01110 => Some(Self::VcpopV { vd, vs2, vm }),
143 _ => None,
144 }
145 }
146 _ => None,
147 }
148 }
149
150 #[inline(always)]
151 fn alignment() -> u8 {
152 align_of::<u32>() as u8
153 }
154
155 #[inline(always)]
156 fn size(&self) -> u8 {
157 size_of::<u32>() as u8
158 }
159}
160
161#[instruction]
162impl<Reg> fmt::Display for ZvbbInstruction<Reg>
163where
164 Reg: fmt::Display + Copy,
165{
166 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
167 #[rustfmt::skip]
168 match self {
169 Self::VbrevV { vd, vs2, vm } => write!(f, "vbrev.v {vd}, {vs2}{}", mask_suffix(vm)),
170 Self::VclzV { vd, vs2, vm } => write!(f, "vclz.v {vd}, {vs2}{}", mask_suffix(vm)),
171 Self::VctzV { vd, vs2, vm } => write!(f, "vctz.v {vd}, {vs2}{}", mask_suffix(vm)),
172 Self::VcpopV { vd, vs2, vm } => write!(f, "vcpop.v {vd}, {vs2}{}", mask_suffix(vm)),
173 Self::VwsllVv { vd, vs2, vs1, vm } => write!(f, "vwsll.vv {vd}, {vs2}, {vs1}{}", mask_suffix(vm)),
174 Self::VwsllVx { vd, vs2, rs1, vm } => write!(f, "vwsll.vx {vd}, {vs2}, {rs1}{}", mask_suffix(vm)),
175 Self::VwsllVi { vd, vs2, uimm, vm } => write!(f, "vwsll.vi {vd}, {vs2}, {uimm}{}", mask_suffix(vm)),
176 }
177 }
178}
179
180#[inline(always)]
182fn mask_suffix(vm: &bool) -> &'static str {
183 if *vm { "" } else { ", v0.t" }
184}