#[repr(u8)]
#[derive(Copy, Debug)]
#[derive_const(
Clone,
Eq,
Ord,
PartialEq,
PartialOrd,
)]
pub enum An {
A0 = 0,
A1 = 1,
A2 = 2,
A3 = 3,
A4 = 4,
A5 = 5,
Fp = 6,
Sp = 7,
}
impl An {
pub const MIN: Self = Self::A0;
pub const MAX: Self = Self::Sp;
#[inline]
#[must_use]
pub const fn from_u8(mut index: u8) -> Self {
if cfg!(overflow_checks) {
assert!(
index <= Self::MAX.as_u8(),
"attempt to construct address register with index greater than `7`",
);
}
index &= 0b111;
match index {
0 => Self::A0,
1 => Self::A1,
2 => Self::A2,
3 => Self::A3,
4 => Self::A4,
5 => Self::A5,
6 => Self::Fp,
7 => Self::Sp,
_ => {
unreachable!();
}
}
}
#[inline(always)]
#[must_use]
pub const fn as_u8(self) -> u8 {
self as u8
}
#[inline]
#[must_use]
pub const fn as_usize(self) -> usize {
self as usize
}
#[inline]
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::A0 => "A0",
Self::A1 => "A1",
Self::A2 => "A2",
Self::A3 => "A3",
Self::A4 => "A4",
Self::A5 => "A5",
Self::Fp => "FP",
Self::Sp => "SP",
}
}
}