ab_riscv_primitives/registers/
vector.rs1use core::fmt;
4
5#[derive(Clone, Copy, PartialEq, Eq)]
7#[repr(u8)]
8pub enum VReg {
9 V0 = 0,
11 V1 = 1,
13 V2 = 2,
15 V3 = 3,
17 V4 = 4,
19 V5 = 5,
21 V6 = 6,
23 V7 = 7,
25 V8 = 8,
27 V9 = 9,
29 V10 = 10,
31 V11 = 11,
33 V12 = 12,
35 V13 = 13,
37 V14 = 14,
39 V15 = 15,
41 V16 = 16,
43 V17 = 17,
45 V18 = 18,
47 V19 = 19,
49 V20 = 20,
51 V21 = 21,
53 V22 = 22,
55 V23 = 23,
57 V24 = 24,
59 V25 = 25,
61 V26 = 26,
63 V27 = 27,
65 V28 = 28,
67 V29 = 29,
69 V30 = 30,
71 V31 = 31,
73}
74
75impl VReg {
76 #[inline(always)]
78 pub const fn from_bits(bits: u8) -> Option<Self> {
79 match bits {
80 0 => Some(Self::V0),
81 1 => Some(Self::V1),
82 2 => Some(Self::V2),
83 3 => Some(Self::V3),
84 4 => Some(Self::V4),
85 5 => Some(Self::V5),
86 6 => Some(Self::V6),
87 7 => Some(Self::V7),
88 8 => Some(Self::V8),
89 9 => Some(Self::V9),
90 10 => Some(Self::V10),
91 11 => Some(Self::V11),
92 12 => Some(Self::V12),
93 13 => Some(Self::V13),
94 14 => Some(Self::V14),
95 15 => Some(Self::V15),
96 16 => Some(Self::V16),
97 17 => Some(Self::V17),
98 18 => Some(Self::V18),
99 19 => Some(Self::V19),
100 20 => Some(Self::V20),
101 21 => Some(Self::V21),
102 22 => Some(Self::V22),
103 23 => Some(Self::V23),
104 24 => Some(Self::V24),
105 25 => Some(Self::V25),
106 26 => Some(Self::V26),
107 27 => Some(Self::V27),
108 28 => Some(Self::V28),
109 29 => Some(Self::V29),
110 30 => Some(Self::V30),
111 31 => Some(Self::V31),
112 _ => None,
113 }
114 }
115
116 #[inline(always)]
118 pub const fn bits(self) -> u8 {
119 self as u8
120 }
121}
122
123impl fmt::Display for VReg {
124 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
125 write!(f, "v{}", *self as u8)
126 }
127}
128
129impl fmt::Debug for VReg {
130 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
131 fmt::Display::fmt(self, f)
132 }
133}
134
135#[derive(Debug, Clone, Copy, PartialEq, Eq)]
138#[repr(u16)]
139pub enum VCsr {
140 Vstart = 0x008,
142 Vxsat = 0x009,
144 Vxrm = 0x00A,
146 Vcsr = 0x00F,
148 Vl = 0xC20,
150 Vtype = 0xC21,
152 Vlenb = 0xC22,
154}
155
156impl VCsr {
157 #[inline(always)]
159 pub const fn from_index(index: u16) -> Option<Self> {
160 match index {
161 0x008 => Some(Self::Vstart),
162 0x009 => Some(Self::Vxsat),
163 0x00A => Some(Self::Vxrm),
164 0x00F => Some(Self::Vcsr),
165 0xC20 => Some(Self::Vl),
166 0xC21 => Some(Self::Vtype),
167 0xC22 => Some(Self::Vlenb),
168 _ => None,
169 }
170 }
171}