1use crate::enums::size_x_64::SizeX64;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4#[repr(C)]
5pub struct RegisterX64 {
6 pub(crate) bits: u8,
7}
8
9#[allow(non_upper_case_globals)]
14impl RegisterX64 {
15 pub(crate) const SIZE_MASK: u8 = 0x07;
16 pub(crate) const INDEX_MASK: u8 = 0xF8;
17 pub(crate) const INDEX_SHIFT: u32 = 3;
18
19 const fn make(size: SizeX64, index: u8) -> Self {
21 RegisterX64 {
22 bits: (index << Self::INDEX_SHIFT) | (size as u8),
23 }
24 }
25
26 pub fn size(&self) -> SizeX64 {
27 unsafe { core::mem::transmute(self.bits & Self::SIZE_MASK) }
28 }
29
30 pub const fn index(&self) -> u8 {
31 (self.bits & Self::INDEX_MASK) >> Self::INDEX_SHIFT
32 }
33
34 pub const noreg: RegisterX64 = Self::make(SizeX64::none, 16);
36 pub const rip: RegisterX64 = Self::make(SizeX64::none, 0);
37
38 pub const al: RegisterX64 = Self::make(SizeX64::byte, 0);
40 pub const cl: RegisterX64 = Self::make(SizeX64::byte, 1);
41 pub const dl: RegisterX64 = Self::make(SizeX64::byte, 2);
42 pub const bl: RegisterX64 = Self::make(SizeX64::byte, 3);
43 pub const spl: RegisterX64 = Self::make(SizeX64::byte, 4);
44 pub const bpl: RegisterX64 = Self::make(SizeX64::byte, 5);
45 pub const sil: RegisterX64 = Self::make(SizeX64::byte, 6);
46 pub const dil: RegisterX64 = Self::make(SizeX64::byte, 7);
47 pub const r8b: RegisterX64 = Self::make(SizeX64::byte, 8);
48 pub const r9b: RegisterX64 = Self::make(SizeX64::byte, 9);
49 pub const r10b: RegisterX64 = Self::make(SizeX64::byte, 10);
50 pub const r11b: RegisterX64 = Self::make(SizeX64::byte, 11);
51 pub const r12b: RegisterX64 = Self::make(SizeX64::byte, 12);
52 pub const r13b: RegisterX64 = Self::make(SizeX64::byte, 13);
53 pub const r14b: RegisterX64 = Self::make(SizeX64::byte, 14);
54 pub const r15b: RegisterX64 = Self::make(SizeX64::byte, 15);
55
56 pub const eax: RegisterX64 = Self::make(SizeX64::dword, 0);
58 pub const ecx: RegisterX64 = Self::make(SizeX64::dword, 1);
59 pub const edx: RegisterX64 = Self::make(SizeX64::dword, 2);
60 pub const ebx: RegisterX64 = Self::make(SizeX64::dword, 3);
61 pub const esp: RegisterX64 = Self::make(SizeX64::dword, 4);
62 pub const ebp: RegisterX64 = Self::make(SizeX64::dword, 5);
63 pub const esi: RegisterX64 = Self::make(SizeX64::dword, 6);
64 pub const edi: RegisterX64 = Self::make(SizeX64::dword, 7);
65 pub const r8d: RegisterX64 = Self::make(SizeX64::dword, 8);
66 pub const r9d: RegisterX64 = Self::make(SizeX64::dword, 9);
67 pub const r10d: RegisterX64 = Self::make(SizeX64::dword, 10);
68 pub const r11d: RegisterX64 = Self::make(SizeX64::dword, 11);
69 pub const r12d: RegisterX64 = Self::make(SizeX64::dword, 12);
70 pub const r13d: RegisterX64 = Self::make(SizeX64::dword, 13);
71 pub const r14d: RegisterX64 = Self::make(SizeX64::dword, 14);
72 pub const r15d: RegisterX64 = Self::make(SizeX64::dword, 15);
73
74 pub const rax: RegisterX64 = Self::make(SizeX64::qword, 0);
76 pub const rcx: RegisterX64 = Self::make(SizeX64::qword, 1);
77 pub const rdx: RegisterX64 = Self::make(SizeX64::qword, 2);
78 pub const rbx: RegisterX64 = Self::make(SizeX64::qword, 3);
79 pub const rsp: RegisterX64 = Self::make(SizeX64::qword, 4);
80 pub const rbp: RegisterX64 = Self::make(SizeX64::qword, 5);
81 pub const rsi: RegisterX64 = Self::make(SizeX64::qword, 6);
82 pub const rdi: RegisterX64 = Self::make(SizeX64::qword, 7);
83 pub const r8: RegisterX64 = Self::make(SizeX64::qword, 8);
84 pub const r9: RegisterX64 = Self::make(SizeX64::qword, 9);
85 pub const r10: RegisterX64 = Self::make(SizeX64::qword, 10);
86 pub const r11: RegisterX64 = Self::make(SizeX64::qword, 11);
87 pub const r12: RegisterX64 = Self::make(SizeX64::qword, 12);
88 pub const r13: RegisterX64 = Self::make(SizeX64::qword, 13);
89 pub const r14: RegisterX64 = Self::make(SizeX64::qword, 14);
90 pub const r15: RegisterX64 = Self::make(SizeX64::qword, 15);
91
92 pub const xmm0: RegisterX64 = Self::make(SizeX64::xmmword, 0);
94 pub const xmm1: RegisterX64 = Self::make(SizeX64::xmmword, 1);
95 pub const xmm2: RegisterX64 = Self::make(SizeX64::xmmword, 2);
96 pub const xmm3: RegisterX64 = Self::make(SizeX64::xmmword, 3);
97 pub const xmm4: RegisterX64 = Self::make(SizeX64::xmmword, 4);
98 pub const xmm5: RegisterX64 = Self::make(SizeX64::xmmword, 5);
99 pub const xmm6: RegisterX64 = Self::make(SizeX64::xmmword, 6);
100 pub const xmm7: RegisterX64 = Self::make(SizeX64::xmmword, 7);
101 pub const xmm8: RegisterX64 = Self::make(SizeX64::xmmword, 8);
102 pub const xmm9: RegisterX64 = Self::make(SizeX64::xmmword, 9);
103 pub const xmm10: RegisterX64 = Self::make(SizeX64::xmmword, 10);
104 pub const xmm11: RegisterX64 = Self::make(SizeX64::xmmword, 11);
105 pub const xmm12: RegisterX64 = Self::make(SizeX64::xmmword, 12);
106 pub const xmm13: RegisterX64 = Self::make(SizeX64::xmmword, 13);
107 pub const xmm14: RegisterX64 = Self::make(SizeX64::xmmword, 14);
108 pub const xmm15: RegisterX64 = Self::make(SizeX64::xmmword, 15);
109
110 pub const ymm0: RegisterX64 = Self::make(SizeX64::ymmword, 0);
112 pub const ymm1: RegisterX64 = Self::make(SizeX64::ymmword, 1);
113 pub const ymm2: RegisterX64 = Self::make(SizeX64::ymmword, 2);
114 pub const ymm3: RegisterX64 = Self::make(SizeX64::ymmword, 3);
115 pub const ymm4: RegisterX64 = Self::make(SizeX64::ymmword, 4);
116 pub const ymm5: RegisterX64 = Self::make(SizeX64::ymmword, 5);
117 pub const ymm6: RegisterX64 = Self::make(SizeX64::ymmword, 6);
118 pub const ymm7: RegisterX64 = Self::make(SizeX64::ymmword, 7);
119 pub const ymm8: RegisterX64 = Self::make(SizeX64::ymmword, 8);
120 pub const ymm9: RegisterX64 = Self::make(SizeX64::ymmword, 9);
121 pub const ymm10: RegisterX64 = Self::make(SizeX64::ymmword, 10);
122 pub const ymm11: RegisterX64 = Self::make(SizeX64::ymmword, 11);
123 pub const ymm12: RegisterX64 = Self::make(SizeX64::ymmword, 12);
124 pub const ymm13: RegisterX64 = Self::make(SizeX64::ymmword, 13);
125 pub const ymm14: RegisterX64 = Self::make(SizeX64::ymmword, 14);
126 pub const ymm15: RegisterX64 = Self::make(SizeX64::ymmword, 15);
127}
128
129impl Default for RegisterX64 {
130 fn default() -> Self {
131 Self {
132 bits: SizeX64::none as u8,
133 }
134 }
135}