ab_riscv_interpreter/rv32/zk/
zbkb.rs1pub mod rv32_zbkb_helpers;
4#[cfg(test)]
5mod tests;
6
7use crate::{ExecutableInstruction, ExecutionError, RegisterFile};
8use ab_riscv_macros::instruction_execution;
9use ab_riscv_primitives::prelude::*;
10use core::ops::ControlFlow;
11
12#[instruction_execution]
13impl<Reg, Regs, ExtState, Memory, PC, InstructionHandler, CustomError>
14 ExecutableInstruction<Regs, ExtState, Memory, PC, InstructionHandler, CustomError>
15 for Rv32ZbkbInstruction<Reg>
16where
17 Reg: Register<Type = u32>,
18 Regs: RegisterFile<Reg>,
19{
20 #[inline(always)]
21 fn execute(
22 self,
23 regs: &mut Regs,
24 _ext_state: &mut ExtState,
25 _memory: &mut Memory,
26 _program_counter: &mut PC,
27 _system_instruction_handler: &mut InstructionHandler,
28 ) -> Result<ControlFlow<()>, ExecutionError<Reg::Type, CustomError>> {
29 match self {
30 Self::Pack { rd, rs1, rs2 } => {
31 let lo = regs.read(rs1) & 0x0000_FFFFu32;
34 let hi = (regs.read(rs2) & 0x0000_FFFFu32) << 16;
35 regs.write(rd, lo | hi);
36 }
37 Self::Packh { rd, rs1, rs2 } => {
38 let lo = regs.read(rs1) & 0xFF;
41 let hi = (regs.read(rs2) & 0xFF) << 8;
42 regs.write(rd, lo | hi);
43 }
44 Self::Brev8 { rd, rs1 } => {
45 let src = regs.read(rs1);
47 let mut bytes = src.to_le_bytes();
48 for byte in &mut bytes {
49 *byte = byte.reverse_bits();
50 }
51 regs.write(rd, u32::from_le_bytes(bytes));
52 }
53 Self::Zip { rd, rs1 } => {
54 let src = regs.read(rs1);
59
60 regs.write(rd, rv32_zbkb_helpers::zip(src));
61 }
62 Self::Unzip { rd, rs1 } => {
63 let src = regs.read(rs1);
68
69 regs.write(rd, rv32_zbkb_helpers::unzip(src));
70 }
71 }
72
73 Ok(ControlFlow::Continue(()))
74 }
75}