ab_riscv_interpreter/rv64/zk/zkn/
zknd.rs1pub mod rv64_zknd_helpers;
4#[cfg(test)]
5mod tests;
6
7use crate::{
8 ExecutableInstruction, ExecutableInstructionCsr, ExecutableInstructionOperands, ExecutionError,
9 RegisterFile, Rs1Rs2OperandValues, Rs1Rs2Operands,
10};
11use ab_riscv_macros::instruction_execution;
12use ab_riscv_primitives::prelude::*;
13use core::ops::ControlFlow;
14
15#[instruction_execution]
16impl<Reg> ExecutableInstructionOperands for Rv64ZkndInstruction<Reg> where Reg: Register<Type = u64> {}
17
18#[instruction_execution]
19impl<Reg, ExtState, CustomError> ExecutableInstructionCsr<ExtState, CustomError>
20 for Rv64ZkndInstruction<Reg>
21where
22 Reg: Register<Type = u64>,
23{
24}
25
26#[instruction_execution]
27impl<Reg, Regs, ExtState, Memory, PC, InstructionHandler, CustomError>
28 ExecutableInstruction<Regs, ExtState, Memory, PC, InstructionHandler, CustomError>
29 for Rv64ZkndInstruction<Reg>
30where
31 Reg: Register<Type = u64>,
32 Regs: RegisterFile<Reg>,
33{
34 #[inline(always)]
35 fn execute(
36 self,
37 Rs1Rs2OperandValues {
38 rs1_value,
39 rs2_value,
40 }: Rs1Rs2OperandValues<<Self::Reg as Register>::Type>,
41 _regs: &mut Regs,
42 _ext_state: &mut ExtState,
43 _memory: &mut Memory,
44 _program_counter: &mut PC,
45 _system_instruction_handler: &mut InstructionHandler,
46 ) -> Result<
47 ControlFlow<(), (Self::Reg, <Self::Reg as Register>::Type)>,
48 ExecutionError<Reg::Type, CustomError>,
49 > {
50 match self {
51 Self::Aes64Ds { rd, rs1: _, rs2: _ } => {
52 let v1 = rs1_value;
53 let v2 = rs2_value;
54 Ok(ControlFlow::Continue((
55 rd,
56 rv64_zknd_helpers::aes64ds(v1, v2),
57 )))
58 }
59 Self::Aes64Dsm { rd, rs1: _, rs2: _ } => {
60 let v1 = rs1_value;
61 let v2 = rs2_value;
62 Ok(ControlFlow::Continue((
63 rd,
64 rv64_zknd_helpers::aes64dsm(v1, v2),
65 )))
66 }
67 Self::Aes64Im { rd, rs1: _ } => {
68 let v1 = rs1_value;
69 Ok(ControlFlow::Continue((rd, rv64_zknd_helpers::aes64im(v1))))
70 }
71 Self::Aes64Ks1i { rd, rs1: _, rnum } => {
72 let v1 = rs1_value;
73 Ok(ControlFlow::Continue((
74 rd,
75 rv64_zknd_helpers::aes64ks1i(v1, rnum),
76 )))
77 }
78 Self::Aes64Ks2 { rd, rs1: _, rs2: _ } => {
79 let v1 = rs1_value;
80 let v2 = rs2_value;
81 Ok(ControlFlow::Continue((
82 rd,
83 rv64_zknd_helpers::aes64ks2(v1, v2),
84 )))
85 }
86 }
87 }
88}