ab_riscv_primitives/
hart.rs1#[cfg(test)]
4mod tests;
5
6use crate::instructions::v::{Elen, Vlen};
7use crate::registers::general_purpose::Register;
8use core::fmt;
9use core::marker::PhantomData;
10
11#[derive(Debug, Clone, Copy)]
13#[derive_const(PartialEq, Eq)]
14pub struct VectorLengths {
15 pub mut(self) elen: Elen,
17 pub mut(self) vlen: Vlen,
19}
20
21impl VectorLengths {
22 #[inline(always)]
24 pub const fn new(elen: Elen, vlen: Vlen) -> Option<Self> {
25 if u32::from(elen) > u32::from(vlen) {
26 return None;
27 }
28 Some(Self { elen, vlen })
29 }
30}
31
32pub const trait HartConfig: fmt::Debug + Copy + Eq + Send + Sync + 'static {
37 type Reg: [const] Register;
39}
40
41pub const trait VectorHartConfig: [const] HartConfig {
45 const VECTOR_LENGTHS: VectorLengths;
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
51pub struct BasicHart<Reg>(PhantomData<Reg>);
52
53const impl<Reg> HartConfig for BasicHart<Reg>
54where
55 Reg: [const] Register,
56{
57 type Reg = Reg;
58}
59
60#[derive(Debug, Clone, Copy, PartialEq, Eq)]
62pub struct BasicVectorHart<Reg, const ELEN: Elen, const VLEN: Vlen>(PhantomData<Reg>);
63
64const impl<Reg, const ELEN: Elen, const VLEN: Vlen> HartConfig for BasicVectorHart<Reg, ELEN, VLEN>
65where
66 Reg: [const] Register,
67{
68 type Reg = Reg;
69}
70
71const impl<Reg, const ELEN: Elen, const VLEN: Vlen> VectorHartConfig
72 for BasicVectorHart<Reg, ELEN, VLEN>
73where
74 Reg: [const] Register,
75{
76 const VECTOR_LENGTHS: VectorLengths =
77 VectorLengths::new(ELEN, VLEN).expect("`ELEN` must be <= `VLEN`");
78}