Skip to main content

ab_riscv_interpreter/rv32/zk/zkn/
zkne.rs

1//! RV32 Zkne extension
2
3pub mod rv32_zkne_helpers;
4#[cfg(test)]
5mod tests;
6
7use crate::{
8    ExecutableInstruction, ExecutableInstructionCsr, ExecutableInstructionOperands, ExecutionError,
9    ExecutionResult, FetchInstructionResult, InstructionFetcher, OpaqueThreadedExecutionResult,
10    RegisterFile, Rs1Rs2OperandValues, Rs1Rs2Operands, ThreadedExecutableInstruction,
11    ThreadedExecutionResult,
12};
13use ab_riscv_macros::instruction_execution;
14use ab_riscv_primitives::prelude::*;
15
16#[instruction_execution]
17const impl<Reg, Hart> ExecutableInstructionOperands for Rv32ZkneInstruction<Hart>
18where
19    Reg: Register<Type = u32>,
20    Hart: HartConfig<Reg = Reg>,
21{
22}
23
24#[instruction_execution]
25const impl<Reg, Hart, Env> ExecutableInstructionCsr<Env> for Rv32ZkneInstruction<Hart>
26where
27    Reg: Register<Type = u32>,
28    Hart: HartConfig<Reg = Reg>,
29{
30}
31
32#[instruction_execution]
33const impl<Reg, Hart, Regs, Env, Memory, PC> ExecutableInstruction<Regs, Env, Memory, PC>
34    for Rv32ZkneInstruction<Hart>
35where
36    Reg: [const] Register<Type = u32>,
37    Hart: HartConfig<Reg = Reg>,
38    Regs: [const] RegisterFile<Reg>,
39{
40    #[inline(always)]
41    #[cfg_attr(feature = "no-panic", no_panic_const::no_panic(const))]
42    fn execute(
43        self,
44        Rs1Rs2OperandValues {
45            rs1_value,
46            rs2_value,
47        }: Rs1Rs2OperandValues<Reg::Type>,
48        _regs: &mut Regs,
49        _env: &mut Env,
50        _memory: &mut Memory,
51        _program_counter: &PC,
52    ) -> ExecutionResult<Reg> {
53        match self {
54            Self::Aes32Esi {
55                rd,
56                rs1: _,
57                rs2: _,
58                bs,
59            } => {
60                let v1 = rs1_value;
61                let v2 = rs2_value;
62                ExecutionResult::Continue {
63                    rd,
64                    value: rv32_zkne_helpers::aes32esi(v1, v2, bs),
65                }
66            }
67            Self::Aes32Esmi {
68                rd,
69                rs1: _,
70                rs2: _,
71                bs,
72            } => {
73                let v1 = rs1_value;
74                let v2 = rs2_value;
75                ExecutionResult::Continue {
76                    rd,
77                    value: rv32_zkne_helpers::aes32esmi(v1, v2, bs),
78                }
79            }
80        }
81    }
82}