Skip to main content

ab_riscv_primitives/instructions/
zkr.rs

1//! Zkr extension
2
3#[cfg(test)]
4mod tests;
5
6use crate::instructions::Instruction;
7use crate::instructions::zicsr::ZicsrInstruction;
8use crate::registers::general_purpose::Register;
9use ab_riscv_macros::instruction;
10use core::fmt;
11
12// TODO: CSR composition?
13/// CSR index of the `seed` register defined by the `Zkr` extension
14pub const SEED_CSR_INDEX: u16 = 0x015;
15
16/// RISC-V Zkr instruction.
17///
18/// `Zkr` (the entropy source extension) defines no instructions of its own: it only adds the
19/// `seed` CSR (see [`SEED_CSR_INDEX`]), which is accessed through ordinary `Zicsr` instructions.
20#[instruction(inherit = [ZicsrInstruction])]
21#[derive(Debug, Clone, Copy)]
22#[derive_const(PartialEq, Eq)]
23pub enum ZkrInstruction<Reg> {}
24
25#[instruction]
26const impl<Reg> Instruction for ZkrInstruction<Reg>
27where
28    Reg: [const] Register,
29{
30    type Reg = Reg;
31
32    #[inline(always)]
33    #[cfg_attr(feature = "no-panic", no_panic_const::no_panic(const))]
34    fn try_decode(instruction: u32) -> Option<Self> {
35        None
36    }
37
38    #[inline(always)]
39    fn alignment() -> u8 {
40        align_of::<u32>() as u8
41    }
42
43    #[inline(always)]
44    fn size(&self) -> u8 {
45        size_of::<u32>() as u8
46    }
47}
48
49#[instruction]
50impl<Reg> fmt::Display for ZkrInstruction<Reg>
51where
52    Reg: fmt::Display + Copy,
53{
54    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55        match self {}
56    }
57}