osom_encoders_x86_64/models/
gpr_kind.rs1use core::mem::transmute;
2
3use super::Size;
4
5#[repr(u8)]
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
8#[must_use]
9pub enum GPRKind {
10 Bit8High = 1, Bit8 = 2,
15
16 Bit16 = 3,
18
19 Bit32 = 4,
21
22 Bit64 = 5,
24}
25
26impl GPRKind {
27 #[inline(always)]
29 #[must_use]
30 pub const fn equals(self, other: Self) -> bool {
31 self.as_u8() == other.as_u8()
32 }
33
34 pub const fn size(self) -> Size {
36 match self {
37 Self::Bit8High | Self::Bit8 => Size::Bit8,
38 Self::Bit16 => Size::Bit16,
39 Self::Bit32 => Size::Bit32,
40 Self::Bit64 => Size::Bit64,
41 }
42 }
43
44 #[inline(always)]
45 #[must_use]
46 pub(crate) const fn as_u8(self) -> u8 {
47 unsafe {
48 let result = transmute::<Self, u8>(self);
49 core::hint::assert_unchecked(result > 0);
50 core::hint::assert_unchecked(result <= 5);
51 result
52 }
53 }
54
55 #[inline]
56 #[allow(dead_code)]
57 pub(crate) const fn from_u8(value: u8) -> Self {
58 debug_assert!(value > 0 && value <= 5, "Invalid GPRKind value");
59 unsafe { core::mem::transmute(value) }
60 }
61}