ab_riscv_primitives/instructions/zvbb/
zvkb.rs1#[cfg(test)]
4mod tests;
5
6use crate::instructions::Instruction;
7use crate::instructions::v::zvexx::ZveXxInstruction;
8use crate::instructions::v::zvexx::arith::ZveXxArithInstruction;
9use crate::instructions::v::zvexx::carry::ZveXxCarryInstruction;
10use crate::instructions::v::zvexx::config::ZveXxConfigInstruction;
11use crate::instructions::v::zvexx::fixed_point::ZveXxFixedPointInstruction;
12use crate::instructions::v::zvexx::load::{LoadStoreNreg, Nf, SegVmNf, ZveXxLoadInstruction};
13use crate::instructions::v::zvexx::mask::ZveXxMaskInstruction;
14use crate::instructions::v::zvexx::muldiv::ZveXxMulDivInstruction;
15use crate::instructions::v::zvexx::perm::ZveXxPermInstruction;
16use crate::instructions::v::zvexx::reduction::ZveXxReductionInstruction;
17use crate::instructions::v::zvexx::store::ZveXxStoreInstruction;
18use crate::instructions::v::zvexx::widen_narrow::ZveXxWidenNarrowInstruction;
19use crate::instructions::v::{Eew, V};
20use crate::instructions::zicsr::ZicsrInstruction;
21use crate::registers::general_purpose::Register;
22use crate::registers::vector::VReg;
23use ab_riscv_macros::instruction;
24use core::fmt;
25
26#[instruction(
41 inherit = [ZveXxInstruction],
42)]
43#[derive(Debug, Clone, Copy)]
44#[derive_const(PartialEq, Eq)]
45#[rustfmt::skip]
46pub enum ZvkbInstruction<Reg> {
47 VandnVv { vd: VReg, vs2: VReg, vs1: VReg, vm: bool },
52 VandnVx { vd: VReg, vs2: VReg, rs1: Reg, vm: bool },
54
55 Vbrev8V { vd: VReg, vs2: VReg, vm: bool },
59
60 Vrev8V { vd: VReg, vs2: VReg, vm: bool },
64
65 VrolVv { vd: VReg, vs2: VReg, vs1: VReg, vm: bool },
69 VrolVx { vd: VReg, vs2: VReg, rs1: Reg, vm: bool },
71
72 VrorVv { vd: VReg, vs2: VReg, vs1: VReg, vm: bool },
78 VrorVx { vd: VReg, vs2: VReg, rs1: Reg, vm: bool },
80 VrorVi { vd: VReg, vs2: VReg, uimm: u8, vm: bool },
83}
84
85#[instruction]
86const impl<Reg> Instruction for ZvkbInstruction<Reg>
87where
88 Reg: [const] Register,
89{
90 type Reg = Reg;
91
92 #[inline(always)]
93 #[cfg_attr(feature = "no-panic", no_panic_const::no_panic(const))]
94 fn try_decode(instruction: u32) -> Option<Self> {
95 let opcode = (instruction & 0b111_1111) as u8;
96
97 if opcode != 0b101_0111 {
98 None?;
99 }
100
101 let vd_bits = ((instruction >> 7) & 0x1f) as u8;
102 let funct3 = ((instruction >> 12) & 0b111) as u8;
103 let vs1_bits = ((instruction >> 15) & 0x1f) as u8;
104 let vs2_bits = ((instruction >> 20) & 0x1f) as u8;
105 let vm = ((instruction >> 25) & 1) as u8 == 1;
107 let funct6 = ((instruction >> 26) & 0b11_1111) as u8;
108
109 let vd = VReg::from_bits(vd_bits)?;
110 let vs2 = VReg::from_bits(vs2_bits)?;
111
112 match funct3 {
113 0b000 => {
115 let vs1 = VReg::from_bits(vs1_bits)?;
116 match funct6 {
117 0b00_0001 => Some(Self::VandnVv { vd, vs2, vs1, vm }),
118 0b01_0100 => Some(Self::VrorVv { vd, vs2, vs1, vm }),
119 0b01_0101 => Some(Self::VrolVv { vd, vs2, vs1, vm }),
120 _ => None,
121 }
122 }
123 0b100 => {
125 let rs1 = Reg::from_bits(vs1_bits)?;
126 match funct6 {
127 0b00_0001 => Some(Self::VandnVx { vd, vs2, rs1, vm }),
128 0b01_0100 => Some(Self::VrorVx { vd, vs2, rs1, vm }),
129 0b01_0101 => Some(Self::VrolVx { vd, vs2, rs1, vm }),
130 _ => None,
131 }
132 }
133 0b011 => {
136 if funct6 != 0b01_0100 {
137 None?;
138 }
139 let uimm = vs1_bits;
142 Some(Self::VrorVi { vd, vs2, uimm, vm })
143 }
144 0b010 => {
148 if funct6 != 0b01_0010 {
149 None?;
150 }
151 match vs1_bits {
152 0b01000 => Some(Self::Vbrev8V { vd, vs2, vm }),
153 0b01001 => Some(Self::Vrev8V { vd, vs2, vm }),
154 _ => None,
155 }
156 }
157 _ => None,
158 }
159 }
160
161 #[inline(always)]
162 fn alignment() -> u8 {
163 align_of::<u32>() as u8
164 }
165
166 #[inline(always)]
167 fn size(&self) -> u8 {
168 size_of::<u32>() as u8
169 }
170}
171
172#[instruction]
173impl<Reg> fmt::Display for ZvkbInstruction<Reg>
174where
175 Reg: fmt::Display + Copy,
176{
177 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
178 #[rustfmt::skip]
179 match self {
180 Self::VandnVv { vd, vs2, vs1, vm } => write!(f, "vandn.vv {vd}, {vs2}, {vs1}{}", mask_suffix(vm)),
181 Self::VandnVx { vd, vs2, rs1, vm } => write!(f, "vandn.vx {vd}, {vs2}, {rs1}{}", mask_suffix(vm)),
182 Self::Vbrev8V { vd, vs2, vm } => write!(f, "vbrev8.v {vd}, {vs2}{}", mask_suffix(vm)),
183 Self::Vrev8V { vd, vs2, vm } => write!(f, "vrev8.v {vd}, {vs2}{}", mask_suffix(vm)),
184 Self::VrolVv { vd, vs2, vs1, vm } => write!(f, "vrol.vv {vd}, {vs2}, {vs1}{}", mask_suffix(vm)),
185 Self::VrolVx { vd, vs2, rs1, vm } => write!(f, "vrol.vx {vd}, {vs2}, {rs1}{}", mask_suffix(vm)),
186 Self::VrorVv { vd, vs2, vs1, vm } => write!(f, "vror.vv {vd}, {vs2}, {vs1}{}", mask_suffix(vm)),
187 Self::VrorVx { vd, vs2, rs1, vm } => write!(f, "vror.vx {vd}, {vs2}, {rs1}{}", mask_suffix(vm)),
188 Self::VrorVi { vd, vs2, uimm, vm } => write!(f, "vror.vi {vd}, {vs2}, {uimm}{}", mask_suffix(vm)),
189 }
190 }
191}
192
193#[inline(always)]
195fn mask_suffix(vm: &bool) -> &'static str {
196 if *vm { "" } else { ", v0.t" }
197}