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    const ALIGNMENT: u8 = align_of::<u32>() as u8;
31
32    type Reg = Reg;
33
34    #[inline(always)]
35    #[cfg_attr(feature = "no-panic", no_panic_const::no_panic(const))]
36    fn try_decode(instruction: u32) -> Option<Self> {
37        None
38    }
39
40    #[inline(always)]
41    fn size(&self) -> u8 {
42        size_of::<u32>() as u8
43    }
44}
45
46#[instruction]
47impl<Reg> fmt::Display for ZkrInstruction<Reg>
48where
49    Reg: fmt::Display + Copy,
50{
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        match self {}
53    }
54}