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)]
137#[repr(u8)]
138pub enum Eew {
139 E8 = 0b000,
141 E16 = 0b101,
143 E32 = 0b110,
145 E64 = 0b111,
147}
148
149impl Eew {
150 #[inline(always)]
152 pub const fn from_width(width: u8) -> Option<Self> {
153 match width {
154 0b000 => Some(Self::E8),
155 0b101 => Some(Self::E16),
156 0b110 => Some(Self::E32),
157 0b111 => Some(Self::E64),
158 _ => None,
159 }
160 }
161
162 #[inline(always)]
164 pub const fn bits(self) -> u16 {
165 match self {
166 Self::E8 => 8,
167 Self::E16 => 16,
168 Self::E32 => 32,
169 Self::E64 => 64,
170 }
171 }
172}
173
174impl fmt::Display for Eew {
175 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176 self.bits().fmt(f)
177 }
178}