/src/wasmtime/winch/codegen/src/isa/x64/regs.rs
Line | Count | Source |
1 | | //! X64 register definition. |
2 | | |
3 | | use crate::isa::reg::Reg; |
4 | | use crate::regset::RegBitSet; |
5 | | use regalloc2::{PReg, RegClass}; |
6 | | |
7 | | const ENC_RAX: u8 = 0; |
8 | | const ENC_RCX: u8 = 1; |
9 | | const ENC_RDX: u8 = 2; |
10 | | const ENC_RBX: u8 = 3; |
11 | | const ENC_RSP: u8 = 4; |
12 | | const ENC_RBP: u8 = 5; |
13 | | const ENC_RSI: u8 = 6; |
14 | | const ENC_RDI: u8 = 7; |
15 | | const ENC_R8: u8 = 8; |
16 | | const ENC_R9: u8 = 9; |
17 | | const ENC_R10: u8 = 10; |
18 | | const ENC_R11: u8 = 11; |
19 | | const ENC_R12: u8 = 12; |
20 | | const ENC_R13: u8 = 13; |
21 | | const ENC_R14: u8 = 14; |
22 | | const ENC_R15: u8 = 15; |
23 | | |
24 | 8.47M | fn gpr(enc: u8) -> Reg { |
25 | 8.47M | Reg::new(PReg::new(enc as usize, RegClass::Int)) |
26 | 8.47M | } |
27 | | |
28 | | /// Constructors for GPR. |
29 | | |
30 | 120k | pub(crate) fn rsi() -> Reg { |
31 | 120k | gpr(ENC_RSI) |
32 | 120k | } |
33 | 130k | pub(crate) fn rdi() -> Reg { |
34 | 130k | gpr(ENC_RDI) |
35 | 130k | } |
36 | 372k | pub(crate) fn rax() -> Reg { |
37 | 372k | gpr(ENC_RAX) |
38 | 372k | } |
39 | 47.1k | pub(crate) fn rcx() -> Reg { |
40 | 47.1k | gpr(ENC_RCX) |
41 | 47.1k | } |
42 | 81.2k | pub(crate) fn rdx() -> Reg { |
43 | 81.2k | gpr(ENC_RDX) |
44 | 81.2k | } |
45 | 33.7k | pub(crate) fn r8() -> Reg { |
46 | 33.7k | gpr(ENC_R8) |
47 | 33.7k | } |
48 | 29.3k | pub(crate) fn r9() -> Reg { |
49 | 29.3k | gpr(ENC_R9) |
50 | 29.3k | } |
51 | 0 | pub(crate) fn r10() -> Reg { |
52 | 0 | gpr(ENC_R10) |
53 | 0 | } |
54 | 0 | pub(crate) fn r12() -> Reg { |
55 | 0 | gpr(ENC_R12) |
56 | 0 | } |
57 | 0 | pub(crate) fn r13() -> Reg { |
58 | 0 | gpr(ENC_R13) |
59 | 0 | } |
60 | | /// Used as a pinned register to hold |
61 | | /// the `VMContext`. |
62 | | /// Non-allocatable in Winch's default ABI. |
63 | 2.07M | pub(crate) fn r14() -> Reg { |
64 | 2.07M | gpr(ENC_R14) |
65 | 2.07M | } |
66 | | |
67 | 2.07M | pub(crate) fn vmctx() -> Reg { |
68 | 2.07M | r14() |
69 | 2.07M | } |
70 | | |
71 | 0 | pub(crate) fn rbx() -> Reg { |
72 | 0 | gpr(ENC_RBX) |
73 | 0 | } |
74 | | |
75 | 0 | pub(crate) fn r15() -> Reg { |
76 | 0 | gpr(ENC_R15) |
77 | 0 | } |
78 | | |
79 | 5.02M | pub(crate) fn rsp() -> Reg { |
80 | 5.02M | gpr(ENC_RSP) |
81 | 5.02M | } |
82 | 556k | pub(crate) fn rbp() -> Reg { |
83 | 556k | gpr(ENC_RBP) |
84 | 556k | } |
85 | | |
86 | | /// Used as the scratch register. |
87 | | /// Non-allocatable in Winch's default |
88 | | /// ABI. |
89 | 0 | pub(crate) fn r11() -> Reg { |
90 | 0 | gpr(ENC_R11) |
91 | 0 | } |
92 | | |
93 | 331k | fn fpr(enc: u8) -> Reg { |
94 | 331k | Reg::new(PReg::new(enc as usize, RegClass::Float)) |
95 | 331k | } |
96 | | |
97 | | /// Constructors for FPR. |
98 | | |
99 | 156k | pub(crate) fn xmm0() -> Reg { |
100 | 156k | fpr(0) |
101 | 156k | } |
102 | 29.4k | pub(crate) fn xmm1() -> Reg { |
103 | 29.4k | fpr(1) |
104 | 29.4k | } |
105 | 27.2k | pub(crate) fn xmm2() -> Reg { |
106 | 27.2k | fpr(2) |
107 | 27.2k | } |
108 | 25.7k | pub(crate) fn xmm3() -> Reg { |
109 | 25.7k | fpr(3) |
110 | 25.7k | } |
111 | 24.5k | pub(crate) fn xmm4() -> Reg { |
112 | 24.5k | fpr(4) |
113 | 24.5k | } |
114 | 23.9k | pub(crate) fn xmm5() -> Reg { |
115 | 23.9k | fpr(5) |
116 | 23.9k | } |
117 | 22.1k | pub(crate) fn xmm6() -> Reg { |
118 | 22.1k | fpr(6) |
119 | 22.1k | } |
120 | 21.9k | pub(crate) fn xmm7() -> Reg { |
121 | 21.9k | fpr(7) |
122 | 21.9k | } |
123 | 0 | pub(crate) fn xmm8() -> Reg { |
124 | 0 | fpr(8) |
125 | 0 | } |
126 | 0 | pub(crate) fn xmm9() -> Reg { |
127 | 0 | fpr(9) |
128 | 0 | } |
129 | 0 | pub(crate) fn xmm10() -> Reg { |
130 | 0 | fpr(10) |
131 | 0 | } |
132 | 0 | pub(crate) fn xmm11() -> Reg { |
133 | 0 | fpr(11) |
134 | 0 | } |
135 | 0 | pub(crate) fn xmm12() -> Reg { |
136 | 0 | fpr(12) |
137 | 0 | } |
138 | 0 | pub(crate) fn xmm13() -> Reg { |
139 | 0 | fpr(13) |
140 | 0 | } |
141 | 0 | pub(crate) fn xmm14() -> Reg { |
142 | 0 | fpr(14) |
143 | 0 | } |
144 | 0 | pub(crate) fn xmm15() -> Reg { |
145 | 0 | fpr(15) |
146 | 0 | } |
147 | | |
148 | | /// GPR count. |
149 | | const GPR: u32 = 16; |
150 | | /// FPR count. |
151 | | const FPR: u32 = 16; |
152 | | /// GPR index bound. |
153 | | const MAX_GPR: u32 = GPR; |
154 | | /// GPR index bound. |
155 | | const MAX_FPR: u32 = FPR; |
156 | | const ALL_GPR: u32 = (1 << GPR) - 1; |
157 | | const ALL_FPR: u32 = (1 << FPR) - 1; |
158 | | /// Bitmask of non-alloctable GPRs. |
159 | | // R11: Is used as the scratch register. |
160 | | // R14: Is a pinned register, used as the instance register. |
161 | | const SCRATCH: u32 = 1 << ENC_R11; |
162 | | const INSTANCE: u32 = 1 << ENC_R14; |
163 | | pub(crate) const NON_ALLOCATABLE_GPR: u32 = (1 << ENC_RBP) | (1 << ENC_RSP) | SCRATCH | INSTANCE; |
164 | | |
165 | | /// Bitmask of non-alloctable FPRs. |
166 | | // xmm15: Is used as the scratch register. |
167 | | const SCRATCH_FPR: u32 = 1 << 15; |
168 | | const NON_ALLOCATABLE_FPR: u32 = SCRATCH_FPR; |
169 | | |
170 | | /// Bitmask to represent the available general purpose registers. |
171 | | const ALLOCATABLE_GPR: u32 = ALL_GPR & !NON_ALLOCATABLE_GPR; |
172 | | /// Bitmask to represent the available floating point registers. |
173 | | const ALLOCATABLE_FPR: u32 = ALL_FPR & !NON_ALLOCATABLE_FPR; |
174 | | |
175 | | /// Allocatable scratch general purpose registers. |
176 | | const ALLOCATABLE_SCRATCH_GPR: u32 = SCRATCH; |
177 | | /// Non-allocatable scratch general purpose registers. |
178 | | const NON_ALLOCATABLE_SCRATCH_GPR: u32 = ALL_GPR & !SCRATCH; |
179 | | |
180 | | /// Allocatable scratch floating-point registers. |
181 | | const ALLOCATABLE_SCRATCH_FPR: u32 = SCRATCH_FPR; |
182 | | /// Non-allocatable scratch floating-point registers. |
183 | | const NON_ALLOCATABLE_SCRATCH_FPR: u32 = ALL_FPR & !SCRATCH_FPR; |
184 | | |
185 | | /// Bitset for allocatable general purpose registers. |
186 | 103k | pub fn gpr_bit_set() -> RegBitSet { |
187 | 103k | RegBitSet::int( |
188 | 103k | ALLOCATABLE_GPR.into(), |
189 | 103k | NON_ALLOCATABLE_GPR.into(), |
190 | 103k | usize::try_from(MAX_GPR).unwrap(), |
191 | | ) |
192 | 103k | } |
193 | | |
194 | | /// Bitset for allocatable floating point registers. |
195 | 103k | pub fn fpr_bit_set() -> RegBitSet { |
196 | 103k | RegBitSet::float( |
197 | 103k | ALLOCATABLE_FPR.into(), |
198 | 103k | NON_ALLOCATABLE_FPR.into(), |
199 | 103k | usize::try_from(MAX_FPR).unwrap(), |
200 | | ) |
201 | 103k | } |
202 | | |
203 | | /// Bitset for allocatable scratch general purpose registers. |
204 | 103k | pub fn scratch_gpr_bitset() -> RegBitSet { |
205 | 103k | RegBitSet::int( |
206 | 103k | ALLOCATABLE_SCRATCH_GPR.into(), |
207 | 103k | NON_ALLOCATABLE_SCRATCH_GPR.into(), |
208 | 103k | usize::try_from(MAX_GPR).unwrap(), |
209 | | ) |
210 | 103k | } |
211 | | |
212 | | /// Bitset for allocatable scratch floating point registers. |
213 | 103k | pub fn scratch_fpr_bitset() -> RegBitSet { |
214 | 103k | RegBitSet::float( |
215 | 103k | ALLOCATABLE_SCRATCH_FPR.into(), |
216 | 103k | NON_ALLOCATABLE_SCRATCH_FPR.into(), |
217 | 103k | usize::try_from(MAX_FPR).unwrap(), |
218 | | ) |
219 | 103k | } |