Skip to main content

ab_riscv_interpreter/rv64/zk/zkn/
zkne.rs

1//! RV64 Zkne extension
2
3pub mod rv64_zkne_helpers;
4// TODO: `llvm.aarch64.crypto.aes*` is not supported in Miri yet:
5//  https://github.com/rust-lang/miri/issues/3172#issuecomment-3730602707
6#[cfg(not(all(miri, target_arch = "aarch64")))]
7#[cfg(test)]
8mod tests;
9
10use crate::rv64::zk::zkn::zknd::rv64_zknd_helpers;
11use crate::{
12    ExecutableInstruction, ExecutableInstructionCsr, ExecutableInstructionOperands, ExecutionError,
13    ExecutionResult, FetchInstructionResult, InstructionFetcher, OpaqueThreadedExecutionResult,
14    RegisterFile, Rs1Rs2OperandValues, Rs1Rs2Operands, ThreadedExecutableInstruction,
15    ThreadedExecutionResult,
16};
17use ab_riscv_macros::instruction_execution;
18use ab_riscv_primitives::prelude::*;
19
20#[instruction_execution]
21const impl<Reg, Hart> ExecutableInstructionOperands for Rv64ZkneInstruction<Hart>
22where
23    Reg: Register<Type = u64>,
24    Hart: HartConfig<Reg = Reg>,
25{
26}
27
28#[instruction_execution]
29const impl<Reg, Hart, Env> ExecutableInstructionCsr<Env> for Rv64ZkneInstruction<Hart>
30where
31    Reg: Register<Type = u64>,
32    Hart: HartConfig<Reg = Reg>,
33{
34}
35
36#[instruction_execution]
37const impl<Reg, Hart, Regs, Env, Memory, PC> ExecutableInstruction<Regs, Env, Memory, PC>
38    for Rv64ZkneInstruction<Hart>
39where
40    Reg: [const] Register<Type = u64>,
41    Hart: HartConfig<Reg = Reg>,
42    Regs: [const] RegisterFile<Reg>,
43{
44    #[inline(always)]
45    #[cfg_attr(feature = "no-panic", no_panic_const::no_panic(const))]
46    fn execute(
47        self,
48        Rs1Rs2OperandValues {
49            rs1_value,
50            rs2_value,
51        }: Rs1Rs2OperandValues<Reg::Type>,
52        _regs: &mut Regs,
53        _env: &mut Env,
54        _memory: &mut Memory,
55        _program_counter: &PC,
56    ) -> ExecutionResult<Reg> {
57        match self {
58            Self::Aes64Es { rd, rs1: _, rs2: _ } => {
59                let v1 = rs1_value;
60                let v2 = rs2_value;
61                ExecutionResult::Continue {
62                    rd,
63                    value: rv64_zkne_helpers::aes64es(v1, v2),
64                }
65            }
66            Self::Aes64Esm { rd, rs1: _, rs2: _ } => {
67                let v1 = rs1_value;
68                let v2 = rs2_value;
69                ExecutionResult::Continue {
70                    rd,
71                    value: rv64_zkne_helpers::aes64esm(v1, v2),
72                }
73            }
74        }
75    }
76}