use core::fmt;
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum VReg {
V0 = 0,
V1 = 1,
V2 = 2,
V3 = 3,
V4 = 4,
V5 = 5,
V6 = 6,
V7 = 7,
V8 = 8,
V9 = 9,
V10 = 10,
V11 = 11,
V12 = 12,
V13 = 13,
V14 = 14,
V15 = 15,
V16 = 16,
V17 = 17,
V18 = 18,
V19 = 19,
V20 = 20,
V21 = 21,
V22 = 22,
V23 = 23,
V24 = 24,
V25 = 25,
V26 = 26,
V27 = 27,
V28 = 28,
V29 = 29,
V30 = 30,
V31 = 31,
}
impl VReg {
#[inline(always)]
pub const fn from_bits(bits: u8) -> Option<Self> {
match bits {
0 => Some(Self::V0),
1 => Some(Self::V1),
2 => Some(Self::V2),
3 => Some(Self::V3),
4 => Some(Self::V4),
5 => Some(Self::V5),
6 => Some(Self::V6),
7 => Some(Self::V7),
8 => Some(Self::V8),
9 => Some(Self::V9),
10 => Some(Self::V10),
11 => Some(Self::V11),
12 => Some(Self::V12),
13 => Some(Self::V13),
14 => Some(Self::V14),
15 => Some(Self::V15),
16 => Some(Self::V16),
17 => Some(Self::V17),
18 => Some(Self::V18),
19 => Some(Self::V19),
20 => Some(Self::V20),
21 => Some(Self::V21),
22 => Some(Self::V22),
23 => Some(Self::V23),
24 => Some(Self::V24),
25 => Some(Self::V25),
26 => Some(Self::V26),
27 => Some(Self::V27),
28 => Some(Self::V28),
29 => Some(Self::V29),
30 => Some(Self::V30),
31 => Some(Self::V31),
_ => None,
}
}
#[inline(always)]
pub const fn bits(self) -> u8 {
self as u8
}
}
impl fmt::Display for VReg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "v{}", *self as u8)
}
}
impl fmt::Debug for VReg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u16)]
pub enum VCsr {
Vstart = 0x008,
Vxsat = 0x009,
Vxrm = 0x00A,
Vcsr = 0x00F,
Vl = 0xC20,
Vtype = 0xC21,
Vlenb = 0xC22,
}
impl VCsr {
#[inline(always)]
pub const fn from_index(index: u16) -> Option<Self> {
match index {
0x008 => Some(Self::Vstart),
0x009 => Some(Self::Vxsat),
0x00A => Some(Self::Vxrm),
0x00F => Some(Self::Vcsr),
0xC20 => Some(Self::Vl),
0xC21 => Some(Self::Vtype),
0xC22 => Some(Self::Vlenb),
_ => None,
}
}
}