]>
Commit | Line | Data |
---|---|---|
477ba620 AJ |
1 | /* |
2 | * Tiny Code Generator for QEMU | |
3 | * | |
4 | * Copyright (c) 2009-2010 Aurelien Jarno <[email protected]> | |
5 | * Based on i386/tcg-target.c - Copyright (c) 2008 Fabrice Bellard | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
23 | * THE SOFTWARE. | |
24 | */ | |
25 | ||
3cf246f0 RH |
26 | #include "tcg-be-null.h" |
27 | ||
477ba620 AJ |
28 | /* |
29 | * Register definitions | |
30 | */ | |
31 | ||
32 | #ifndef NDEBUG | |
33 | static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { | |
34 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
35 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
36 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | |
37 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", | |
38 | "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", | |
39 | "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", | |
40 | "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55", | |
41 | "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63", | |
42 | }; | |
43 | #endif | |
44 | ||
6781d08d RH |
45 | #ifdef CONFIG_USE_GUEST_BASE |
46 | #define TCG_GUEST_BASE_REG TCG_REG_R55 | |
47 | #else | |
48 | #define TCG_GUEST_BASE_REG TCG_REG_R0 | |
49 | #endif | |
255108c0 RH |
50 | #ifndef GUEST_BASE |
51 | #define GUEST_BASE 0 | |
52 | #endif | |
6781d08d | 53 | |
477ba620 AJ |
54 | /* Branch registers */ |
55 | enum { | |
56 | TCG_REG_B0 = 0, | |
57 | TCG_REG_B1, | |
58 | TCG_REG_B2, | |
59 | TCG_REG_B3, | |
60 | TCG_REG_B4, | |
61 | TCG_REG_B5, | |
62 | TCG_REG_B6, | |
63 | TCG_REG_B7, | |
64 | }; | |
65 | ||
66 | /* Floating point registers */ | |
67 | enum { | |
68 | TCG_REG_F0 = 0, | |
69 | TCG_REG_F1, | |
70 | TCG_REG_F2, | |
71 | TCG_REG_F3, | |
72 | TCG_REG_F4, | |
73 | TCG_REG_F5, | |
74 | TCG_REG_F6, | |
75 | TCG_REG_F7, | |
76 | TCG_REG_F8, | |
77 | TCG_REG_F9, | |
78 | TCG_REG_F10, | |
79 | TCG_REG_F11, | |
80 | TCG_REG_F12, | |
81 | TCG_REG_F13, | |
82 | TCG_REG_F14, | |
83 | TCG_REG_F15, | |
84 | }; | |
85 | ||
86 | /* Predicate registers */ | |
87 | enum { | |
88 | TCG_REG_P0 = 0, | |
89 | TCG_REG_P1, | |
90 | TCG_REG_P2, | |
91 | TCG_REG_P3, | |
92 | TCG_REG_P4, | |
93 | TCG_REG_P5, | |
94 | TCG_REG_P6, | |
95 | TCG_REG_P7, | |
96 | TCG_REG_P8, | |
97 | TCG_REG_P9, | |
98 | TCG_REG_P10, | |
99 | TCG_REG_P11, | |
100 | TCG_REG_P12, | |
101 | TCG_REG_P13, | |
102 | TCG_REG_P14, | |
103 | TCG_REG_P15, | |
104 | }; | |
105 | ||
106 | /* Application registers */ | |
107 | enum { | |
108 | TCG_REG_PFS = 64, | |
109 | }; | |
110 | ||
111 | static const int tcg_target_reg_alloc_order[] = { | |
18d445b4 | 112 | TCG_REG_R33, |
477ba620 AJ |
113 | TCG_REG_R35, |
114 | TCG_REG_R36, | |
115 | TCG_REG_R37, | |
116 | TCG_REG_R38, | |
117 | TCG_REG_R39, | |
118 | TCG_REG_R40, | |
119 | TCG_REG_R41, | |
120 | TCG_REG_R42, | |
121 | TCG_REG_R43, | |
122 | TCG_REG_R44, | |
123 | TCG_REG_R45, | |
124 | TCG_REG_R46, | |
125 | TCG_REG_R47, | |
126 | TCG_REG_R48, | |
127 | TCG_REG_R49, | |
128 | TCG_REG_R50, | |
129 | TCG_REG_R51, | |
130 | TCG_REG_R52, | |
131 | TCG_REG_R53, | |
132 | TCG_REG_R54, | |
133 | TCG_REG_R55, | |
134 | TCG_REG_R14, | |
135 | TCG_REG_R15, | |
136 | TCG_REG_R16, | |
137 | TCG_REG_R17, | |
138 | TCG_REG_R18, | |
139 | TCG_REG_R19, | |
140 | TCG_REG_R20, | |
141 | TCG_REG_R21, | |
142 | TCG_REG_R22, | |
143 | TCG_REG_R23, | |
144 | TCG_REG_R24, | |
145 | TCG_REG_R25, | |
146 | TCG_REG_R26, | |
147 | TCG_REG_R27, | |
148 | TCG_REG_R28, | |
149 | TCG_REG_R29, | |
150 | TCG_REG_R30, | |
151 | TCG_REG_R31, | |
152 | TCG_REG_R56, | |
153 | TCG_REG_R57, | |
154 | TCG_REG_R58, | |
155 | TCG_REG_R59, | |
156 | TCG_REG_R60, | |
157 | TCG_REG_R61, | |
158 | TCG_REG_R62, | |
159 | TCG_REG_R63, | |
160 | TCG_REG_R8, | |
161 | TCG_REG_R9, | |
162 | TCG_REG_R10, | |
163 | TCG_REG_R11 | |
164 | }; | |
165 | ||
166 | static const int tcg_target_call_iarg_regs[8] = { | |
167 | TCG_REG_R56, | |
168 | TCG_REG_R57, | |
169 | TCG_REG_R58, | |
170 | TCG_REG_R59, | |
171 | TCG_REG_R60, | |
172 | TCG_REG_R61, | |
173 | TCG_REG_R62, | |
174 | TCG_REG_R63, | |
175 | }; | |
176 | ||
af15a623 SW |
177 | static const int tcg_target_call_oarg_regs[] = { |
178 | TCG_REG_R8 | |
477ba620 AJ |
179 | }; |
180 | ||
477ba620 AJ |
181 | /* |
182 | * opcode formation | |
183 | */ | |
184 | ||
185 | /* bundle templates: stops (double bar in the IA64 manual) are marked with | |
186 | an uppercase letter. */ | |
187 | enum { | |
188 | mii = 0x00, | |
189 | miI = 0x01, | |
190 | mIi = 0x02, | |
191 | mII = 0x03, | |
192 | mlx = 0x04, | |
193 | mLX = 0x05, | |
194 | mmi = 0x08, | |
195 | mmI = 0x09, | |
196 | Mmi = 0x0a, | |
197 | MmI = 0x0b, | |
198 | mfi = 0x0c, | |
199 | mfI = 0x0d, | |
200 | mmf = 0x0e, | |
201 | mmF = 0x0f, | |
202 | mib = 0x10, | |
203 | miB = 0x11, | |
204 | mbb = 0x12, | |
205 | mbB = 0x13, | |
206 | bbb = 0x16, | |
207 | bbB = 0x17, | |
208 | mmb = 0x18, | |
209 | mmB = 0x19, | |
210 | mfb = 0x1c, | |
211 | mfB = 0x1d, | |
212 | }; | |
213 | ||
214 | enum { | |
215 | OPC_ADD_A1 = 0x10000000000ull, | |
216 | OPC_AND_A1 = 0x10060000000ull, | |
217 | OPC_AND_A3 = 0x10160000000ull, | |
218 | OPC_ANDCM_A1 = 0x10068000000ull, | |
219 | OPC_ANDCM_A3 = 0x10168000000ull, | |
220 | OPC_ADDS_A4 = 0x10800000000ull, | |
221 | OPC_ADDL_A5 = 0x12000000000ull, | |
222 | OPC_ALLOC_M34 = 0x02c00000000ull, | |
223 | OPC_BR_DPTK_FEW_B1 = 0x08400000000ull, | |
224 | OPC_BR_SPTK_MANY_B1 = 0x08000001000ull, | |
225 | OPC_BR_SPTK_MANY_B4 = 0x00100001000ull, | |
226 | OPC_BR_CALL_SPTK_MANY_B5 = 0x02100001000ull, | |
227 | OPC_BR_RET_SPTK_MANY_B4 = 0x00108001100ull, | |
228 | OPC_BRL_SPTK_MANY_X3 = 0x18000001000ull, | |
229 | OPC_CMP_LT_A6 = 0x18000000000ull, | |
230 | OPC_CMP_LTU_A6 = 0x1a000000000ull, | |
231 | OPC_CMP_EQ_A6 = 0x1c000000000ull, | |
232 | OPC_CMP4_LT_A6 = 0x18400000000ull, | |
233 | OPC_CMP4_LTU_A6 = 0x1a400000000ull, | |
234 | OPC_CMP4_EQ_A6 = 0x1c400000000ull, | |
63975ea7 | 235 | OPC_DEP_I14 = 0x0ae00000000ull, |
c7d4475a | 236 | OPC_DEP_I15 = 0x08000000000ull, |
477ba620 AJ |
237 | OPC_DEP_Z_I12 = 0x0a600000000ull, |
238 | OPC_EXTR_I11 = 0x0a400002000ull, | |
239 | OPC_EXTR_U_I11 = 0x0a400000000ull, | |
240 | OPC_FCVT_FX_TRUNC_S1_F10 = 0x004d0000000ull, | |
241 | OPC_FCVT_FXU_TRUNC_S1_F10 = 0x004d8000000ull, | |
242 | OPC_FCVT_XF_F11 = 0x000e0000000ull, | |
243 | OPC_FMA_S1_F1 = 0x10400000000ull, | |
244 | OPC_FNMA_S1_F1 = 0x18400000000ull, | |
245 | OPC_FRCPA_S1_F6 = 0x00600000000ull, | |
246 | OPC_GETF_SIG_M19 = 0x08708000000ull, | |
247 | OPC_LD1_M1 = 0x08000000000ull, | |
248 | OPC_LD1_M3 = 0x0a000000000ull, | |
249 | OPC_LD2_M1 = 0x08040000000ull, | |
250 | OPC_LD2_M3 = 0x0a040000000ull, | |
251 | OPC_LD4_M1 = 0x08080000000ull, | |
252 | OPC_LD4_M3 = 0x0a080000000ull, | |
253 | OPC_LD8_M1 = 0x080c0000000ull, | |
254 | OPC_LD8_M3 = 0x0a0c0000000ull, | |
255 | OPC_MUX1_I3 = 0x0eca0000000ull, | |
256 | OPC_NOP_B9 = 0x04008000000ull, | |
257 | OPC_NOP_F16 = 0x00008000000ull, | |
258 | OPC_NOP_I18 = 0x00008000000ull, | |
259 | OPC_NOP_M48 = 0x00008000000ull, | |
260 | OPC_MOV_I21 = 0x00e00100000ull, | |
261 | OPC_MOV_RET_I21 = 0x00e00500000ull, | |
262 | OPC_MOV_I22 = 0x00188000000ull, | |
263 | OPC_MOV_I_I26 = 0x00150000000ull, | |
264 | OPC_MOVL_X2 = 0x0c000000000ull, | |
265 | OPC_OR_A1 = 0x10070000000ull, | |
266 | OPC_SETF_EXP_M18 = 0x0c748000000ull, | |
267 | OPC_SETF_SIG_M18 = 0x0c708000000ull, | |
268 | OPC_SHL_I7 = 0x0f240000000ull, | |
269 | OPC_SHR_I5 = 0x0f220000000ull, | |
270 | OPC_SHR_U_I5 = 0x0f200000000ull, | |
271 | OPC_SHRP_I10 = 0x0ac00000000ull, | |
272 | OPC_SXT1_I29 = 0x000a0000000ull, | |
273 | OPC_SXT2_I29 = 0x000a8000000ull, | |
274 | OPC_SXT4_I29 = 0x000b0000000ull, | |
275 | OPC_ST1_M4 = 0x08c00000000ull, | |
276 | OPC_ST2_M4 = 0x08c40000000ull, | |
277 | OPC_ST4_M4 = 0x08c80000000ull, | |
278 | OPC_ST8_M4 = 0x08cc0000000ull, | |
279 | OPC_SUB_A1 = 0x10028000000ull, | |
280 | OPC_SUB_A3 = 0x10128000000ull, | |
281 | OPC_UNPACK4_L_I2 = 0x0f860000000ull, | |
282 | OPC_XMA_L_F2 = 0x1d000000000ull, | |
283 | OPC_XOR_A1 = 0x10078000000ull, | |
284 | OPC_ZXT1_I29 = 0x00080000000ull, | |
285 | OPC_ZXT2_I29 = 0x00088000000ull, | |
286 | OPC_ZXT4_I29 = 0x00090000000ull, | |
5f7b1687 RH |
287 | |
288 | INSN_NOP_M = OPC_NOP_M48, /* nop.m 0 */ | |
289 | INSN_NOP_I = OPC_NOP_I18, /* nop.i 0 */ | |
477ba620 AJ |
290 | }; |
291 | ||
292 | static inline uint64_t tcg_opc_a1(int qp, uint64_t opc, int r1, | |
293 | int r2, int r3) | |
294 | { | |
295 | return opc | |
296 | | ((r3 & 0x7f) << 20) | |
297 | | ((r2 & 0x7f) << 13) | |
298 | | ((r1 & 0x7f) << 6) | |
299 | | (qp & 0x3f); | |
300 | } | |
301 | ||
302 | static inline uint64_t tcg_opc_a3(int qp, uint64_t opc, int r1, | |
303 | uint64_t imm, int r3) | |
304 | { | |
305 | return opc | |
306 | | ((imm & 0x80) << 29) /* s */ | |
307 | | ((imm & 0x7f) << 13) /* imm7b */ | |
308 | | ((r3 & 0x7f) << 20) | |
309 | | ((r1 & 0x7f) << 6) | |
310 | | (qp & 0x3f); | |
311 | } | |
312 | ||
313 | static inline uint64_t tcg_opc_a4(int qp, uint64_t opc, int r1, | |
314 | uint64_t imm, int r3) | |
315 | { | |
316 | return opc | |
317 | | ((imm & 0x2000) << 23) /* s */ | |
318 | | ((imm & 0x1f80) << 20) /* imm6d */ | |
319 | | ((imm & 0x007f) << 13) /* imm7b */ | |
320 | | ((r3 & 0x7f) << 20) | |
321 | | ((r1 & 0x7f) << 6) | |
322 | | (qp & 0x3f); | |
323 | } | |
324 | ||
325 | static inline uint64_t tcg_opc_a5(int qp, uint64_t opc, int r1, | |
326 | uint64_t imm, int r3) | |
327 | { | |
328 | return opc | |
329 | | ((imm & 0x200000) << 15) /* s */ | |
330 | | ((imm & 0x1f0000) << 6) /* imm5c */ | |
331 | | ((imm & 0x00ff80) << 20) /* imm9d */ | |
332 | | ((imm & 0x00007f) << 13) /* imm7b */ | |
333 | | ((r3 & 0x03) << 20) | |
334 | | ((r1 & 0x7f) << 6) | |
335 | | (qp & 0x3f); | |
336 | } | |
337 | ||
338 | static inline uint64_t tcg_opc_a6(int qp, uint64_t opc, int p1, | |
339 | int p2, int r2, int r3) | |
340 | { | |
341 | return opc | |
342 | | ((p2 & 0x3f) << 27) | |
343 | | ((r3 & 0x7f) << 20) | |
344 | | ((r2 & 0x7f) << 13) | |
345 | | ((p1 & 0x3f) << 6) | |
346 | | (qp & 0x3f); | |
347 | } | |
348 | ||
349 | static inline uint64_t tcg_opc_b1(int qp, uint64_t opc, uint64_t imm) | |
350 | { | |
351 | return opc | |
352 | | ((imm & 0x100000) << 16) /* s */ | |
353 | | ((imm & 0x0fffff) << 13) /* imm20b */ | |
354 | | (qp & 0x3f); | |
355 | } | |
356 | ||
357 | static inline uint64_t tcg_opc_b4(int qp, uint64_t opc, int b2) | |
358 | { | |
359 | return opc | |
360 | | ((b2 & 0x7) << 13) | |
361 | | (qp & 0x3f); | |
362 | } | |
363 | ||
364 | static inline uint64_t tcg_opc_b5(int qp, uint64_t opc, int b1, int b2) | |
365 | { | |
366 | return opc | |
367 | | ((b2 & 0x7) << 13) | |
368 | | ((b1 & 0x7) << 6) | |
369 | | (qp & 0x3f); | |
370 | } | |
371 | ||
372 | ||
373 | static inline uint64_t tcg_opc_b9(int qp, uint64_t opc, uint64_t imm) | |
374 | { | |
375 | return opc | |
376 | | ((imm & 0x100000) << 16) /* i */ | |
377 | | ((imm & 0x0fffff) << 6) /* imm20a */ | |
378 | | (qp & 0x3f); | |
379 | } | |
380 | ||
381 | static inline uint64_t tcg_opc_f1(int qp, uint64_t opc, int f1, | |
382 | int f3, int f4, int f2) | |
383 | { | |
384 | return opc | |
385 | | ((f4 & 0x7f) << 27) | |
386 | | ((f3 & 0x7f) << 20) | |
387 | | ((f2 & 0x7f) << 13) | |
388 | | ((f1 & 0x7f) << 6) | |
389 | | (qp & 0x3f); | |
390 | } | |
391 | ||
392 | static inline uint64_t tcg_opc_f2(int qp, uint64_t opc, int f1, | |
393 | int f3, int f4, int f2) | |
394 | { | |
395 | return opc | |
396 | | ((f4 & 0x7f) << 27) | |
397 | | ((f3 & 0x7f) << 20) | |
398 | | ((f2 & 0x7f) << 13) | |
399 | | ((f1 & 0x7f) << 6) | |
400 | | (qp & 0x3f); | |
401 | } | |
402 | ||
403 | static inline uint64_t tcg_opc_f6(int qp, uint64_t opc, int f1, | |
404 | int p2, int f2, int f3) | |
405 | { | |
406 | return opc | |
407 | | ((p2 & 0x3f) << 27) | |
408 | | ((f3 & 0x7f) << 20) | |
409 | | ((f2 & 0x7f) << 13) | |
410 | | ((f1 & 0x7f) << 6) | |
411 | | (qp & 0x3f); | |
412 | } | |
413 | ||
414 | static inline uint64_t tcg_opc_f10(int qp, uint64_t opc, int f1, int f2) | |
415 | { | |
416 | return opc | |
417 | | ((f2 & 0x7f) << 13) | |
418 | | ((f1 & 0x7f) << 6) | |
419 | | (qp & 0x3f); | |
420 | } | |
421 | ||
422 | static inline uint64_t tcg_opc_f11(int qp, uint64_t opc, int f1, int f2) | |
423 | { | |
424 | return opc | |
425 | | ((f2 & 0x7f) << 13) | |
426 | | ((f1 & 0x7f) << 6) | |
427 | | (qp & 0x3f); | |
428 | } | |
429 | ||
430 | static inline uint64_t tcg_opc_f16(int qp, uint64_t opc, uint64_t imm) | |
431 | { | |
432 | return opc | |
433 | | ((imm & 0x100000) << 16) /* i */ | |
434 | | ((imm & 0x0fffff) << 6) /* imm20a */ | |
435 | | (qp & 0x3f); | |
436 | } | |
437 | ||
438 | static inline uint64_t tcg_opc_i2(int qp, uint64_t opc, int r1, | |
439 | int r2, int r3) | |
440 | { | |
441 | return opc | |
442 | | ((r3 & 0x7f) << 20) | |
443 | | ((r2 & 0x7f) << 13) | |
444 | | ((r1 & 0x7f) << 6) | |
445 | | (qp & 0x3f); | |
446 | } | |
447 | ||
448 | static inline uint64_t tcg_opc_i3(int qp, uint64_t opc, int r1, | |
449 | int r2, int mbtype) | |
450 | { | |
451 | return opc | |
452 | | ((mbtype & 0x0f) << 20) | |
453 | | ((r2 & 0x7f) << 13) | |
454 | | ((r1 & 0x7f) << 6) | |
455 | | (qp & 0x3f); | |
456 | } | |
457 | ||
458 | static inline uint64_t tcg_opc_i5(int qp, uint64_t opc, int r1, | |
459 | int r3, int r2) | |
460 | { | |
461 | return opc | |
462 | | ((r3 & 0x7f) << 20) | |
463 | | ((r2 & 0x7f) << 13) | |
464 | | ((r1 & 0x7f) << 6) | |
465 | | (qp & 0x3f); | |
466 | } | |
467 | ||
468 | static inline uint64_t tcg_opc_i7(int qp, uint64_t opc, int r1, | |
469 | int r2, int r3) | |
470 | { | |
471 | return opc | |
472 | | ((r3 & 0x7f) << 20) | |
473 | | ((r2 & 0x7f) << 13) | |
474 | | ((r1 & 0x7f) << 6) | |
475 | | (qp & 0x3f); | |
476 | } | |
477 | ||
478 | static inline uint64_t tcg_opc_i10(int qp, uint64_t opc, int r1, | |
479 | int r2, int r3, uint64_t count) | |
480 | { | |
481 | return opc | |
482 | | ((count & 0x3f) << 27) | |
483 | | ((r3 & 0x7f) << 20) | |
484 | | ((r2 & 0x7f) << 13) | |
485 | | ((r1 & 0x7f) << 6) | |
486 | | (qp & 0x3f); | |
487 | } | |
488 | ||
489 | static inline uint64_t tcg_opc_i11(int qp, uint64_t opc, int r1, | |
490 | int r3, uint64_t pos, uint64_t len) | |
491 | { | |
492 | return opc | |
493 | | ((len & 0x3f) << 27) | |
494 | | ((r3 & 0x7f) << 20) | |
495 | | ((pos & 0x3f) << 14) | |
496 | | ((r1 & 0x7f) << 6) | |
497 | | (qp & 0x3f); | |
498 | } | |
499 | ||
500 | static inline uint64_t tcg_opc_i12(int qp, uint64_t opc, int r1, | |
501 | int r2, uint64_t pos, uint64_t len) | |
502 | { | |
503 | return opc | |
504 | | ((len & 0x3f) << 27) | |
505 | | ((pos & 0x3f) << 20) | |
506 | | ((r2 & 0x7f) << 13) | |
507 | | ((r1 & 0x7f) << 6) | |
508 | | (qp & 0x3f); | |
509 | } | |
510 | ||
63975ea7 AJ |
511 | static inline uint64_t tcg_opc_i14(int qp, uint64_t opc, int r1, uint64_t imm, |
512 | int r3, uint64_t pos, uint64_t len) | |
513 | { | |
514 | return opc | |
515 | | ((imm & 0x01) << 36) | |
516 | | ((len & 0x3f) << 27) | |
517 | | ((r3 & 0x7f) << 20) | |
518 | | ((pos & 0x3f) << 14) | |
519 | | ((r1 & 0x7f) << 6) | |
520 | | (qp & 0x3f); | |
521 | } | |
522 | ||
c7d4475a RH |
523 | static inline uint64_t tcg_opc_i15(int qp, uint64_t opc, int r1, int r2, |
524 | int r3, uint64_t pos, uint64_t len) | |
525 | { | |
526 | return opc | |
527 | | ((pos & 0x3f) << 31) | |
528 | | ((len & 0x0f) << 27) | |
529 | | ((r3 & 0x7f) << 20) | |
530 | | ((r2 & 0x7f) << 13) | |
531 | | ((r1 & 0x7f) << 6) | |
532 | | (qp & 0x3f); | |
533 | } | |
534 | ||
477ba620 AJ |
535 | static inline uint64_t tcg_opc_i18(int qp, uint64_t opc, uint64_t imm) |
536 | { | |
537 | return opc | |
538 | | ((imm & 0x100000) << 16) /* i */ | |
539 | | ((imm & 0x0fffff) << 6) /* imm20a */ | |
540 | | (qp & 0x3f); | |
541 | } | |
542 | ||
543 | static inline uint64_t tcg_opc_i21(int qp, uint64_t opc, int b1, | |
544 | int r2, uint64_t imm) | |
545 | { | |
546 | return opc | |
547 | | ((imm & 0x1ff) << 24) | |
548 | | ((r2 & 0x7f) << 13) | |
549 | | ((b1 & 0x7) << 6) | |
550 | | (qp & 0x3f); | |
551 | } | |
552 | ||
553 | static inline uint64_t tcg_opc_i22(int qp, uint64_t opc, int r1, int b2) | |
554 | { | |
555 | return opc | |
556 | | ((b2 & 0x7) << 13) | |
557 | | ((r1 & 0x7f) << 6) | |
558 | | (qp & 0x3f); | |
559 | } | |
560 | ||
561 | static inline uint64_t tcg_opc_i26(int qp, uint64_t opc, int ar3, int r2) | |
562 | { | |
563 | return opc | |
564 | | ((ar3 & 0x7f) << 20) | |
565 | | ((r2 & 0x7f) << 13) | |
566 | | (qp & 0x3f); | |
567 | } | |
568 | ||
569 | static inline uint64_t tcg_opc_i29(int qp, uint64_t opc, int r1, int r3) | |
570 | { | |
571 | return opc | |
572 | | ((r3 & 0x7f) << 20) | |
573 | | ((r1 & 0x7f) << 6) | |
574 | | (qp & 0x3f); | |
575 | } | |
576 | ||
577 | static inline uint64_t tcg_opc_l2(uint64_t imm) | |
578 | { | |
579 | return (imm & 0x7fffffffffc00000ull) >> 22; | |
580 | } | |
581 | ||
582 | static inline uint64_t tcg_opc_l3(uint64_t imm) | |
583 | { | |
584 | return (imm & 0x07fffffffff00000ull) >> 18; | |
585 | } | |
586 | ||
587 | static inline uint64_t tcg_opc_m1(int qp, uint64_t opc, int r1, int r3) | |
588 | { | |
589 | return opc | |
590 | | ((r3 & 0x7f) << 20) | |
591 | | ((r1 & 0x7f) << 6) | |
592 | | (qp & 0x3f); | |
593 | } | |
594 | ||
595 | static inline uint64_t tcg_opc_m3(int qp, uint64_t opc, int r1, | |
596 | int r3, uint64_t imm) | |
597 | { | |
598 | return opc | |
599 | | ((imm & 0x100) << 28) /* s */ | |
600 | | ((imm & 0x080) << 20) /* i */ | |
601 | | ((imm & 0x07f) << 13) /* imm7b */ | |
602 | | ((r3 & 0x7f) << 20) | |
603 | | ((r1 & 0x7f) << 6) | |
604 | | (qp & 0x3f); | |
605 | } | |
606 | ||
607 | static inline uint64_t tcg_opc_m4(int qp, uint64_t opc, int r2, int r3) | |
608 | { | |
609 | return opc | |
610 | | ((r3 & 0x7f) << 20) | |
611 | | ((r2 & 0x7f) << 13) | |
612 | | (qp & 0x3f); | |
613 | } | |
614 | ||
615 | static inline uint64_t tcg_opc_m18(int qp, uint64_t opc, int f1, int r2) | |
616 | { | |
617 | return opc | |
618 | | ((r2 & 0x7f) << 13) | |
619 | | ((f1 & 0x7f) << 6) | |
620 | | (qp & 0x3f); | |
621 | } | |
622 | ||
623 | static inline uint64_t tcg_opc_m19(int qp, uint64_t opc, int r1, int f2) | |
624 | { | |
625 | return opc | |
626 | | ((f2 & 0x7f) << 13) | |
627 | | ((r1 & 0x7f) << 6) | |
628 | | (qp & 0x3f); | |
629 | } | |
630 | ||
631 | static inline uint64_t tcg_opc_m34(int qp, uint64_t opc, int r1, | |
632 | int sof, int sol, int sor) | |
633 | { | |
634 | return opc | |
635 | | ((sor & 0x0f) << 27) | |
636 | | ((sol & 0x7f) << 20) | |
637 | | ((sof & 0x7f) << 13) | |
638 | | ((r1 & 0x7f) << 6) | |
639 | | (qp & 0x3f); | |
640 | } | |
641 | ||
642 | static inline uint64_t tcg_opc_m48(int qp, uint64_t opc, uint64_t imm) | |
643 | { | |
644 | return opc | |
645 | | ((imm & 0x100000) << 16) /* i */ | |
646 | | ((imm & 0x0fffff) << 6) /* imm20a */ | |
647 | | (qp & 0x3f); | |
648 | } | |
649 | ||
650 | static inline uint64_t tcg_opc_x2(int qp, uint64_t opc, | |
651 | int r1, uint64_t imm) | |
652 | { | |
653 | return opc | |
654 | | ((imm & 0x8000000000000000ull) >> 27) /* i */ | |
655 | | (imm & 0x0000000000200000ull) /* ic */ | |
656 | | ((imm & 0x00000000001f0000ull) << 6) /* imm5c */ | |
657 | | ((imm & 0x000000000000ff80ull) << 20) /* imm9d */ | |
658 | | ((imm & 0x000000000000007full) << 13) /* imm7b */ | |
659 | | ((r1 & 0x7f) << 6) | |
660 | | (qp & 0x3f); | |
661 | } | |
662 | ||
663 | static inline uint64_t tcg_opc_x3(int qp, uint64_t opc, uint64_t imm) | |
664 | { | |
665 | return opc | |
666 | | ((imm & 0x0800000000000000ull) >> 23) /* i */ | |
667 | | ((imm & 0x00000000000fffffull) << 13) /* imm20b */ | |
668 | | (qp & 0x3f); | |
669 | } | |
670 | ||
671 | ||
672 | /* | |
673 | * Relocations | |
674 | */ | |
675 | ||
2ba7fae2 | 676 | static inline void reloc_pcrel21b(void *pc, intptr_t target) |
477ba620 AJ |
677 | { |
678 | uint64_t imm; | |
679 | int64_t disp; | |
680 | int slot; | |
681 | ||
2ba7fae2 RH |
682 | slot = (intptr_t)pc & 3; |
683 | pc = (void *)((intptr_t)pc & ~3); | |
477ba620 | 684 | |
2ba7fae2 | 685 | disp = target - (intptr_t)pc; |
477ba620 AJ |
686 | imm = (uint64_t) disp >> 4; |
687 | ||
688 | switch(slot) { | |
689 | case 0: | |
690 | *(uint64_t *)(pc + 0) = (*(uint64_t *)(pc + 8) & 0xfffffdc00003ffffull) | |
691 | | ((imm & 0x100000) << 21) /* s */ | |
692 | | ((imm & 0x0fffff) << 18); /* imm20b */ | |
693 | break; | |
694 | case 1: | |
695 | *(uint64_t *)(pc + 8) = (*(uint64_t *)(pc + 8) & 0xfffffffffffb8000ull) | |
696 | | ((imm & 0x100000) >> 2) /* s */ | |
697 | | ((imm & 0x0fffe0) >> 5); /* imm20b */ | |
698 | *(uint64_t *)(pc + 0) = (*(uint64_t *)(pc + 0) & 0x07ffffffffffffffull) | |
699 | | ((imm & 0x00001f) << 59); /* imm20b */ | |
700 | break; | |
701 | case 2: | |
702 | *(uint64_t *)(pc + 8) = (*(uint64_t *)(pc + 8) & 0xf700000fffffffffull) | |
703 | | ((imm & 0x100000) << 39) /* s */ | |
704 | | ((imm & 0x0fffff) << 36); /* imm20b */ | |
705 | break; | |
706 | } | |
707 | } | |
708 | ||
709 | static inline uint64_t get_reloc_pcrel21b (void *pc) | |
710 | { | |
711 | int64_t low, high; | |
712 | int slot; | |
713 | ||
714 | slot = (tcg_target_long) pc & 3; | |
715 | pc = (void *)((tcg_target_long) pc & ~3); | |
716 | ||
717 | low = (*(uint64_t *)(pc + 0)); | |
718 | high = (*(uint64_t *)(pc + 8)); | |
719 | ||
720 | switch(slot) { | |
721 | case 0: | |
722 | return ((low >> 21) & 0x100000) + /* s */ | |
723 | ((low >> 18) & 0x0fffff); /* imm20b */ | |
724 | case 1: | |
725 | return ((high << 2) & 0x100000) + /* s */ | |
726 | ((high << 5) & 0x0fffe0) + /* imm20b */ | |
727 | ((low >> 59) & 0x00001f); /* imm20b */ | |
728 | case 2: | |
729 | return ((high >> 39) & 0x100000) + /* s */ | |
730 | ((high >> 36) & 0x0fffff); /* imm20b */ | |
731 | default: | |
732 | tcg_abort(); | |
733 | } | |
734 | } | |
735 | ||
2ba7fae2 | 736 | static inline void reloc_pcrel60b(void *pc, intptr_t target) |
477ba620 AJ |
737 | { |
738 | int64_t disp; | |
739 | uint64_t imm; | |
740 | ||
2ba7fae2 | 741 | disp = target - (intptr_t)pc; |
477ba620 AJ |
742 | imm = (uint64_t) disp >> 4; |
743 | ||
744 | *(uint64_t *)(pc + 8) = (*(uint64_t *)(pc + 8) & 0xf700000fff800000ull) | |
745 | | (imm & 0x0800000000000000ull) /* s */ | |
746 | | ((imm & 0x07fffff000000000ull) >> 36) /* imm39 */ | |
747 | | ((imm & 0x00000000000fffffull) << 36); /* imm20b */ | |
748 | *(uint64_t *)(pc + 0) = (*(uint64_t *)(pc + 0) & 0x00003fffffffffffull) | |
749 | | ((imm & 0x0000000ffff00000ull) << 28); /* imm39 */ | |
750 | } | |
751 | ||
752 | static inline uint64_t get_reloc_pcrel60b (void *pc) | |
753 | { | |
754 | int64_t low, high; | |
755 | ||
756 | low = (*(uint64_t *)(pc + 0)); | |
757 | high = (*(uint64_t *)(pc + 8)); | |
758 | ||
759 | return ((high) & 0x0800000000000000ull) + /* s */ | |
760 | ((high >> 36) & 0x00000000000fffffull) + /* imm20b */ | |
761 | ((high << 36) & 0x07fffff000000000ull) + /* imm39 */ | |
762 | ((low >> 28) & 0x0000000ffff00000ull); /* imm39 */ | |
763 | } | |
764 | ||
765 | ||
766 | static void patch_reloc(uint8_t *code_ptr, int type, | |
2ba7fae2 | 767 | intptr_t value, intptr_t addend) |
477ba620 AJ |
768 | { |
769 | value += addend; | |
770 | switch (type) { | |
771 | case R_IA64_PCREL21B: | |
772 | reloc_pcrel21b(code_ptr, value); | |
773 | break; | |
774 | case R_IA64_PCREL60B: | |
775 | reloc_pcrel60b(code_ptr, value); | |
776 | default: | |
777 | tcg_abort(); | |
778 | } | |
779 | } | |
780 | ||
781 | /* | |
782 | * Constraints | |
783 | */ | |
784 | ||
785 | /* parse target specific constraints */ | |
786 | static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str) | |
787 | { | |
788 | const char *ct_str; | |
789 | ||
790 | ct_str = *pct_str; | |
791 | switch(ct_str[0]) { | |
792 | case 'r': | |
793 | ct->ct |= TCG_CT_REG; | |
794 | tcg_regset_set(ct->u.regs, 0xffffffffffffffffull); | |
795 | break; | |
796 | case 'I': | |
797 | ct->ct |= TCG_CT_CONST_S22; | |
798 | break; | |
799 | case 'S': | |
800 | ct->ct |= TCG_CT_REG; | |
801 | tcg_regset_set(ct->u.regs, 0xffffffffffffffffull); | |
802 | #if defined(CONFIG_SOFTMMU) | |
803 | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R56); | |
804 | tcg_regset_reset_reg(ct->u.regs, TCG_REG_R57); | |
805 | #endif | |
806 | break; | |
807 | case 'Z': | |
808 | /* We are cheating a bit here, using the fact that the register | |
809 | r0 is also the register number 0. Hence there is no need | |
810 | to check for const_args in each instruction. */ | |
811 | ct->ct |= TCG_CT_CONST_ZERO; | |
812 | break; | |
813 | default: | |
814 | return -1; | |
815 | } | |
816 | ct_str++; | |
817 | *pct_str = ct_str; | |
818 | return 0; | |
819 | } | |
820 | ||
821 | /* test if a constant matches the constraint */ | |
822 | static inline int tcg_target_const_match(tcg_target_long val, | |
823 | const TCGArgConstraint *arg_ct) | |
824 | { | |
825 | int ct; | |
826 | ct = arg_ct->ct; | |
827 | if (ct & TCG_CT_CONST) | |
828 | return 1; | |
829 | else if ((ct & TCG_CT_CONST_ZERO) && val == 0) | |
830 | return 1; | |
831 | else if ((ct & TCG_CT_CONST_S22) && val == ((int32_t)val << 10) >> 10) | |
832 | return 1; | |
833 | else | |
834 | return 0; | |
835 | } | |
836 | ||
837 | /* | |
838 | * Code generation | |
839 | */ | |
840 | ||
841 | static uint8_t *tb_ret_addr; | |
842 | ||
843 | static inline void tcg_out_bundle(TCGContext *s, int template, | |
844 | uint64_t slot0, uint64_t slot1, | |
845 | uint64_t slot2) | |
846 | { | |
847 | template &= 0x1f; /* 5 bits */ | |
848 | slot0 &= 0x1ffffffffffull; /* 41 bits */ | |
849 | slot1 &= 0x1ffffffffffull; /* 41 bits */ | |
850 | slot2 &= 0x1ffffffffffull; /* 41 bits */ | |
851 | ||
852 | *(uint64_t *)(s->code_ptr + 0) = (slot1 << 46) | (slot0 << 5) | template; | |
853 | *(uint64_t *)(s->code_ptr + 8) = (slot2 << 23) | (slot1 >> 18); | |
854 | s->code_ptr += 16; | |
855 | } | |
856 | ||
3b6dac34 | 857 | static inline void tcg_out_mov(TCGContext *s, TCGType type, |
2a534aff | 858 | TCGReg ret, TCGReg arg) |
477ba620 AJ |
859 | { |
860 | tcg_out_bundle(s, mmI, | |
5f7b1687 RH |
861 | INSN_NOP_M, |
862 | INSN_NOP_M, | |
477ba620 AJ |
863 | tcg_opc_a4(TCG_REG_P0, OPC_ADDS_A4, ret, 0, arg)); |
864 | } | |
865 | ||
866 | static inline void tcg_out_movi(TCGContext *s, TCGType type, | |
2a534aff | 867 | TCGReg reg, tcg_target_long arg) |
477ba620 AJ |
868 | { |
869 | tcg_out_bundle(s, mLX, | |
5f7b1687 | 870 | INSN_NOP_M, |
477ba620 AJ |
871 | tcg_opc_l2 (arg), |
872 | tcg_opc_x2 (TCG_REG_P0, OPC_MOVL_X2, reg, arg)); | |
873 | } | |
874 | ||
477ba620 AJ |
875 | static void tcg_out_br(TCGContext *s, int label_index) |
876 | { | |
877 | TCGLabel *l = &s->labels[label_index]; | |
878 | ||
56779034 AJ |
879 | /* We pay attention here to not modify the branch target by reading |
880 | the existing value and using it again. This ensure that caches and | |
881 | memory are kept coherent during retranslation. */ | |
477ba620 | 882 | tcg_out_bundle(s, mmB, |
5f7b1687 RH |
883 | INSN_NOP_M, |
884 | INSN_NOP_M, | |
477ba620 AJ |
885 | tcg_opc_b1 (TCG_REG_P0, OPC_BR_SPTK_MANY_B1, |
886 | get_reloc_pcrel21b(s->code_ptr + 2))); | |
887 | ||
888 | if (l->has_value) { | |
889 | reloc_pcrel21b((s->code_ptr - 16) + 2, l->u.value); | |
890 | } else { | |
891 | tcg_out_reloc(s, (s->code_ptr - 16) + 2, | |
892 | R_IA64_PCREL21B, label_index, 0); | |
893 | } | |
894 | } | |
895 | ||
896 | static inline void tcg_out_call(TCGContext *s, TCGArg addr) | |
897 | { | |
898 | tcg_out_bundle(s, MmI, | |
899 | tcg_opc_m1 (TCG_REG_P0, OPC_LD8_M1, TCG_REG_R2, addr), | |
900 | tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4, TCG_REG_R3, 8, addr), | |
901 | tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21, | |
902 | TCG_REG_B6, TCG_REG_R2, 0)); | |
903 | tcg_out_bundle(s, mmB, | |
904 | tcg_opc_m1 (TCG_REG_P0, OPC_LD8_M1, TCG_REG_R1, TCG_REG_R3), | |
5f7b1687 | 905 | INSN_NOP_M, |
477ba620 AJ |
906 | tcg_opc_b5 (TCG_REG_P0, OPC_BR_CALL_SPTK_MANY_B5, |
907 | TCG_REG_B0, TCG_REG_B6)); | |
908 | } | |
909 | ||
910 | static void tcg_out_exit_tb(TCGContext *s, tcg_target_long arg) | |
911 | { | |
912 | int64_t disp; | |
913 | uint64_t imm; | |
914 | ||
915 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R8, arg); | |
916 | ||
917 | disp = tb_ret_addr - s->code_ptr; | |
918 | imm = (uint64_t)disp >> 4; | |
919 | ||
920 | tcg_out_bundle(s, mLX, | |
5f7b1687 | 921 | INSN_NOP_M, |
477ba620 AJ |
922 | tcg_opc_l3 (imm), |
923 | tcg_opc_x3 (TCG_REG_P0, OPC_BRL_SPTK_MANY_X3, imm)); | |
924 | } | |
925 | ||
926 | static inline void tcg_out_goto_tb(TCGContext *s, TCGArg arg) | |
927 | { | |
928 | if (s->tb_jmp_offset) { | |
929 | /* direct jump method */ | |
930 | tcg_abort(); | |
931 | } else { | |
932 | /* indirect jump method */ | |
933 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, | |
934 | (tcg_target_long)(s->tb_next + arg)); | |
935 | tcg_out_bundle(s, MmI, | |
936 | tcg_opc_m1 (TCG_REG_P0, OPC_LD8_M1, | |
937 | TCG_REG_R2, TCG_REG_R2), | |
5f7b1687 | 938 | INSN_NOP_M, |
477ba620 AJ |
939 | tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21, TCG_REG_B6, |
940 | TCG_REG_R2, 0)); | |
941 | tcg_out_bundle(s, mmB, | |
5f7b1687 RH |
942 | INSN_NOP_M, |
943 | INSN_NOP_M, | |
477ba620 AJ |
944 | tcg_opc_b4 (TCG_REG_P0, OPC_BR_SPTK_MANY_B4, |
945 | TCG_REG_B6)); | |
946 | } | |
947 | s->tb_next_offset[arg] = s->code_ptr - s->code_buf; | |
948 | } | |
949 | ||
950 | static inline void tcg_out_jmp(TCGContext *s, TCGArg addr) | |
951 | { | |
952 | tcg_out_bundle(s, mmI, | |
5f7b1687 RH |
953 | INSN_NOP_M, |
954 | INSN_NOP_M, | |
477ba620 AJ |
955 | tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21, TCG_REG_B6, addr, 0)); |
956 | tcg_out_bundle(s, mmB, | |
5f7b1687 RH |
957 | INSN_NOP_M, |
958 | INSN_NOP_M, | |
477ba620 AJ |
959 | tcg_opc_b4(TCG_REG_P0, OPC_BR_SPTK_MANY_B4, TCG_REG_B6)); |
960 | } | |
961 | ||
962 | static inline void tcg_out_ld_rel(TCGContext *s, uint64_t opc_m4, TCGArg arg, | |
963 | TCGArg arg1, tcg_target_long arg2) | |
964 | { | |
965 | if (arg2 == ((int16_t)arg2 >> 2) << 2) { | |
966 | tcg_out_bundle(s, MmI, | |
967 | tcg_opc_a4(TCG_REG_P0, OPC_ADDS_A4, | |
968 | TCG_REG_R2, arg2, arg1), | |
969 | tcg_opc_m1 (TCG_REG_P0, opc_m4, arg, TCG_REG_R2), | |
5f7b1687 | 970 | INSN_NOP_I); |
477ba620 AJ |
971 | } else { |
972 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, arg2); | |
973 | tcg_out_bundle(s, MmI, | |
974 | tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, | |
975 | TCG_REG_R2, TCG_REG_R2, arg1), | |
976 | tcg_opc_m1 (TCG_REG_P0, opc_m4, arg, TCG_REG_R2), | |
5f7b1687 | 977 | INSN_NOP_I); |
477ba620 AJ |
978 | } |
979 | } | |
980 | ||
981 | static inline void tcg_out_st_rel(TCGContext *s, uint64_t opc_m4, TCGArg arg, | |
982 | TCGArg arg1, tcg_target_long arg2) | |
983 | { | |
984 | if (arg2 == ((int16_t)arg2 >> 2) << 2) { | |
985 | tcg_out_bundle(s, MmI, | |
986 | tcg_opc_a4(TCG_REG_P0, OPC_ADDS_A4, | |
987 | TCG_REG_R2, arg2, arg1), | |
988 | tcg_opc_m4 (TCG_REG_P0, opc_m4, arg, TCG_REG_R2), | |
5f7b1687 | 989 | INSN_NOP_I); |
477ba620 AJ |
990 | } else { |
991 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, arg2); | |
992 | tcg_out_bundle(s, MmI, | |
993 | tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, | |
994 | TCG_REG_R2, TCG_REG_R2, arg1), | |
995 | tcg_opc_m4 (TCG_REG_P0, opc_m4, arg, TCG_REG_R2), | |
5f7b1687 | 996 | INSN_NOP_I); |
477ba620 AJ |
997 | } |
998 | } | |
999 | ||
2a534aff | 1000 | static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGReg arg, |
a05b5b9b | 1001 | TCGReg arg1, intptr_t arg2) |
477ba620 AJ |
1002 | { |
1003 | if (type == TCG_TYPE_I32) { | |
1004 | tcg_out_ld_rel(s, OPC_LD4_M1, arg, arg1, arg2); | |
1005 | } else { | |
1006 | tcg_out_ld_rel(s, OPC_LD8_M1, arg, arg1, arg2); | |
1007 | } | |
1008 | } | |
1009 | ||
2a534aff | 1010 | static inline void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, |
a05b5b9b | 1011 | TCGReg arg1, intptr_t arg2) |
477ba620 AJ |
1012 | { |
1013 | if (type == TCG_TYPE_I32) { | |
1014 | tcg_out_st_rel(s, OPC_ST4_M4, arg, arg1, arg2); | |
1015 | } else { | |
1016 | tcg_out_st_rel(s, OPC_ST8_M4, arg, arg1, arg2); | |
1017 | } | |
1018 | } | |
1019 | ||
1020 | static inline void tcg_out_alu(TCGContext *s, uint64_t opc_a1, TCGArg ret, | |
1021 | TCGArg arg1, int const_arg1, | |
1022 | TCGArg arg2, int const_arg2) | |
1023 | { | |
1024 | uint64_t opc1, opc2; | |
1025 | ||
1026 | if (const_arg1 && arg1 != 0) { | |
1027 | opc1 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5, | |
1028 | TCG_REG_R2, arg1, TCG_REG_R0); | |
1029 | arg1 = TCG_REG_R2; | |
1030 | } else { | |
5f7b1687 | 1031 | opc1 = INSN_NOP_M; |
477ba620 AJ |
1032 | } |
1033 | ||
1034 | if (const_arg2 && arg2 != 0) { | |
1035 | opc2 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5, | |
1036 | TCG_REG_R3, arg2, TCG_REG_R0); | |
1037 | arg2 = TCG_REG_R3; | |
1038 | } else { | |
5f7b1687 | 1039 | opc2 = INSN_NOP_I; |
477ba620 AJ |
1040 | } |
1041 | ||
1042 | tcg_out_bundle(s, mII, | |
1043 | opc1, | |
1044 | opc2, | |
1045 | tcg_opc_a1(TCG_REG_P0, opc_a1, ret, arg1, arg2)); | |
1046 | } | |
1047 | ||
1048 | static inline void tcg_out_eqv(TCGContext *s, TCGArg ret, | |
1049 | TCGArg arg1, int const_arg1, | |
1050 | TCGArg arg2, int const_arg2) | |
1051 | { | |
1052 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1053 | INSN_NOP_M, |
477ba620 AJ |
1054 | tcg_opc_a1 (TCG_REG_P0, OPC_XOR_A1, ret, arg1, arg2), |
1055 | tcg_opc_a3 (TCG_REG_P0, OPC_ANDCM_A3, ret, -1, ret)); | |
1056 | } | |
1057 | ||
1058 | static inline void tcg_out_nand(TCGContext *s, TCGArg ret, | |
1059 | TCGArg arg1, int const_arg1, | |
1060 | TCGArg arg2, int const_arg2) | |
1061 | { | |
1062 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1063 | INSN_NOP_M, |
477ba620 AJ |
1064 | tcg_opc_a1 (TCG_REG_P0, OPC_AND_A1, ret, arg1, arg2), |
1065 | tcg_opc_a3 (TCG_REG_P0, OPC_ANDCM_A3, ret, -1, ret)); | |
1066 | } | |
1067 | ||
1068 | static inline void tcg_out_nor(TCGContext *s, TCGArg ret, | |
1069 | TCGArg arg1, int const_arg1, | |
1070 | TCGArg arg2, int const_arg2) | |
1071 | { | |
1072 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1073 | INSN_NOP_M, |
477ba620 AJ |
1074 | tcg_opc_a1 (TCG_REG_P0, OPC_OR_A1, ret, arg1, arg2), |
1075 | tcg_opc_a3 (TCG_REG_P0, OPC_ANDCM_A3, ret, -1, ret)); | |
1076 | } | |
1077 | ||
1078 | static inline void tcg_out_orc(TCGContext *s, TCGArg ret, | |
1079 | TCGArg arg1, int const_arg1, | |
1080 | TCGArg arg2, int const_arg2) | |
1081 | { | |
1082 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1083 | INSN_NOP_M, |
477ba620 AJ |
1084 | tcg_opc_a3 (TCG_REG_P0, OPC_ANDCM_A3, TCG_REG_R2, -1, arg2), |
1085 | tcg_opc_a1 (TCG_REG_P0, OPC_OR_A1, ret, arg1, TCG_REG_R2)); | |
1086 | } | |
1087 | ||
1088 | static inline void tcg_out_mul(TCGContext *s, TCGArg ret, | |
1089 | TCGArg arg1, TCGArg arg2) | |
1090 | { | |
1091 | tcg_out_bundle(s, mmI, | |
1092 | tcg_opc_m18(TCG_REG_P0, OPC_SETF_SIG_M18, TCG_REG_F6, arg1), | |
1093 | tcg_opc_m18(TCG_REG_P0, OPC_SETF_SIG_M18, TCG_REG_F7, arg2), | |
5f7b1687 | 1094 | INSN_NOP_I); |
477ba620 | 1095 | tcg_out_bundle(s, mmF, |
5f7b1687 RH |
1096 | INSN_NOP_M, |
1097 | INSN_NOP_M, | |
477ba620 AJ |
1098 | tcg_opc_f2 (TCG_REG_P0, OPC_XMA_L_F2, TCG_REG_F6, TCG_REG_F6, |
1099 | TCG_REG_F7, TCG_REG_F0)); | |
1100 | tcg_out_bundle(s, miI, | |
1101 | tcg_opc_m19(TCG_REG_P0, OPC_GETF_SIG_M19, ret, TCG_REG_F6), | |
5f7b1687 RH |
1102 | INSN_NOP_I, |
1103 | INSN_NOP_I); | |
477ba620 AJ |
1104 | } |
1105 | ||
1106 | static inline void tcg_out_sar_i32(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1107 | TCGArg arg2, int const_arg2) | |
1108 | { | |
1109 | if (const_arg2) { | |
1110 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1111 | INSN_NOP_M, |
1112 | INSN_NOP_I, | |
477ba620 AJ |
1113 | tcg_opc_i11(TCG_REG_P0, OPC_EXTR_I11, |
1114 | ret, arg1, arg2, 31 - arg2)); | |
1115 | } else { | |
1116 | tcg_out_bundle(s, mII, | |
1117 | tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, | |
1118 | TCG_REG_R3, 0x1f, arg2), | |
1119 | tcg_opc_i29(TCG_REG_P0, OPC_SXT4_I29, TCG_REG_R2, arg1), | |
1120 | tcg_opc_i5 (TCG_REG_P0, OPC_SHR_I5, ret, | |
1121 | TCG_REG_R2, TCG_REG_R3)); | |
1122 | } | |
1123 | } | |
1124 | ||
1125 | static inline void tcg_out_sar_i64(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1126 | TCGArg arg2, int const_arg2) | |
1127 | { | |
1128 | if (const_arg2) { | |
1129 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1130 | INSN_NOP_M, |
1131 | INSN_NOP_I, | |
477ba620 AJ |
1132 | tcg_opc_i11(TCG_REG_P0, OPC_EXTR_I11, |
1133 | ret, arg1, arg2, 63 - arg2)); | |
1134 | } else { | |
1135 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1136 | INSN_NOP_M, |
1137 | INSN_NOP_I, | |
477ba620 AJ |
1138 | tcg_opc_i5 (TCG_REG_P0, OPC_SHR_I5, ret, arg1, arg2)); |
1139 | } | |
1140 | } | |
1141 | ||
1142 | static inline void tcg_out_shl_i32(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1143 | TCGArg arg2, int const_arg2) | |
1144 | { | |
1145 | if (const_arg2) { | |
1146 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1147 | INSN_NOP_M, |
1148 | INSN_NOP_I, | |
477ba620 AJ |
1149 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, ret, |
1150 | arg1, 63 - arg2, 31 - arg2)); | |
1151 | } else { | |
1152 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1153 | INSN_NOP_M, |
477ba620 AJ |
1154 | tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, TCG_REG_R2, |
1155 | 0x1f, arg2), | |
1156 | tcg_opc_i7 (TCG_REG_P0, OPC_SHL_I7, ret, | |
1157 | arg1, TCG_REG_R2)); | |
1158 | } | |
1159 | } | |
1160 | ||
1161 | static inline void tcg_out_shl_i64(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1162 | TCGArg arg2, int const_arg2) | |
1163 | { | |
1164 | if (const_arg2) { | |
1165 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1166 | INSN_NOP_M, |
1167 | INSN_NOP_I, | |
477ba620 AJ |
1168 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, ret, |
1169 | arg1, 63 - arg2, 63 - arg2)); | |
1170 | } else { | |
1171 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1172 | INSN_NOP_M, |
1173 | INSN_NOP_I, | |
477ba620 AJ |
1174 | tcg_opc_i7 (TCG_REG_P0, OPC_SHL_I7, ret, |
1175 | arg1, arg2)); | |
1176 | } | |
1177 | } | |
1178 | ||
1179 | static inline void tcg_out_shr_i32(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1180 | TCGArg arg2, int const_arg2) | |
1181 | { | |
1182 | if (const_arg2) { | |
1183 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1184 | INSN_NOP_M, |
1185 | INSN_NOP_I, | |
477ba620 AJ |
1186 | tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, ret, |
1187 | arg1, arg2, 31 - arg2)); | |
1188 | } else { | |
1189 | tcg_out_bundle(s, mII, | |
1190 | tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, TCG_REG_R3, | |
1191 | 0x1f, arg2), | |
1192 | tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29, TCG_REG_R2, arg1), | |
1193 | tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, ret, | |
1194 | TCG_REG_R2, TCG_REG_R3)); | |
1195 | } | |
1196 | } | |
1197 | ||
1198 | static inline void tcg_out_shr_i64(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1199 | TCGArg arg2, int const_arg2) | |
1200 | { | |
1201 | if (const_arg2) { | |
1202 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1203 | INSN_NOP_M, |
1204 | INSN_NOP_I, | |
477ba620 AJ |
1205 | tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, ret, |
1206 | arg1, arg2, 63 - arg2)); | |
1207 | } else { | |
1208 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1209 | INSN_NOP_M, |
1210 | INSN_NOP_I, | |
477ba620 AJ |
1211 | tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, ret, |
1212 | arg1, arg2)); | |
1213 | } | |
1214 | } | |
1215 | ||
1216 | static inline void tcg_out_rotl_i32(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1217 | TCGArg arg2, int const_arg2) | |
1218 | { | |
1219 | if (const_arg2) { | |
1220 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1221 | INSN_NOP_M, |
477ba620 AJ |
1222 | tcg_opc_i2 (TCG_REG_P0, OPC_UNPACK4_L_I2, |
1223 | TCG_REG_R2, arg1, arg1), | |
1224 | tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, ret, | |
1225 | TCG_REG_R2, 32 - arg2, 31)); | |
1226 | } else { | |
1227 | tcg_out_bundle(s, miI, | |
5f7b1687 | 1228 | INSN_NOP_M, |
477ba620 AJ |
1229 | tcg_opc_i2 (TCG_REG_P0, OPC_UNPACK4_L_I2, |
1230 | TCG_REG_R2, arg1, arg1), | |
1231 | tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, TCG_REG_R3, | |
1232 | 0x1f, arg2)); | |
1233 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1234 | INSN_NOP_M, |
477ba620 AJ |
1235 | tcg_opc_a3 (TCG_REG_P0, OPC_SUB_A3, TCG_REG_R3, |
1236 | 0x20, TCG_REG_R3), | |
1237 | tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, ret, | |
1238 | TCG_REG_R2, TCG_REG_R3)); | |
1239 | } | |
1240 | } | |
1241 | ||
1242 | static inline void tcg_out_rotl_i64(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1243 | TCGArg arg2, int const_arg2) | |
1244 | { | |
1245 | if (const_arg2) { | |
1246 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1247 | INSN_NOP_M, |
1248 | INSN_NOP_I, | |
477ba620 AJ |
1249 | tcg_opc_i10(TCG_REG_P0, OPC_SHRP_I10, ret, arg1, |
1250 | arg1, 0x40 - arg2)); | |
1251 | } else { | |
1252 | tcg_out_bundle(s, mII, | |
1253 | tcg_opc_a3 (TCG_REG_P0, OPC_SUB_A3, TCG_REG_R2, | |
1254 | 0x40, arg2), | |
1255 | tcg_opc_i7 (TCG_REG_P0, OPC_SHL_I7, TCG_REG_R3, | |
1256 | arg1, arg2), | |
1257 | tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, TCG_REG_R2, | |
1258 | arg1, TCG_REG_R2)); | |
1259 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1260 | INSN_NOP_M, |
1261 | INSN_NOP_I, | |
477ba620 AJ |
1262 | tcg_opc_a1 (TCG_REG_P0, OPC_OR_A1, ret, |
1263 | TCG_REG_R2, TCG_REG_R3)); | |
1264 | } | |
1265 | } | |
1266 | ||
1267 | static inline void tcg_out_rotr_i32(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1268 | TCGArg arg2, int const_arg2) | |
1269 | { | |
1270 | if (const_arg2) { | |
1271 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1272 | INSN_NOP_M, |
477ba620 AJ |
1273 | tcg_opc_i2 (TCG_REG_P0, OPC_UNPACK4_L_I2, |
1274 | TCG_REG_R2, arg1, arg1), | |
1275 | tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, ret, | |
1276 | TCG_REG_R2, arg2, 31)); | |
1277 | } else { | |
1278 | tcg_out_bundle(s, mII, | |
1279 | tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, TCG_REG_R3, | |
1280 | 0x1f, arg2), | |
1281 | tcg_opc_i2 (TCG_REG_P0, OPC_UNPACK4_L_I2, | |
1282 | TCG_REG_R2, arg1, arg1), | |
1283 | tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, ret, | |
1284 | TCG_REG_R2, TCG_REG_R3)); | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | static inline void tcg_out_rotr_i64(TCGContext *s, TCGArg ret, TCGArg arg1, | |
1289 | TCGArg arg2, int const_arg2) | |
1290 | { | |
1291 | if (const_arg2) { | |
1292 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1293 | INSN_NOP_M, |
1294 | INSN_NOP_I, | |
477ba620 AJ |
1295 | tcg_opc_i10(TCG_REG_P0, OPC_SHRP_I10, ret, arg1, |
1296 | arg1, arg2)); | |
1297 | } else { | |
1298 | tcg_out_bundle(s, mII, | |
1299 | tcg_opc_a3 (TCG_REG_P0, OPC_SUB_A3, TCG_REG_R2, | |
1300 | 0x40, arg2), | |
1301 | tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, TCG_REG_R3, | |
1302 | arg1, arg2), | |
1303 | tcg_opc_i7 (TCG_REG_P0, OPC_SHL_I7, TCG_REG_R2, | |
1304 | arg1, TCG_REG_R2)); | |
1305 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1306 | INSN_NOP_M, |
1307 | INSN_NOP_I, | |
477ba620 AJ |
1308 | tcg_opc_a1 (TCG_REG_P0, OPC_OR_A1, ret, |
1309 | TCG_REG_R2, TCG_REG_R3)); | |
1310 | } | |
1311 | } | |
1312 | ||
1313 | static inline void tcg_out_ext(TCGContext *s, uint64_t opc_i29, | |
1314 | TCGArg ret, TCGArg arg) | |
1315 | { | |
1316 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1317 | INSN_NOP_M, |
1318 | INSN_NOP_I, | |
477ba620 AJ |
1319 | tcg_opc_i29(TCG_REG_P0, opc_i29, ret, arg)); |
1320 | } | |
1321 | ||
1322 | static inline void tcg_out_bswap16(TCGContext *s, TCGArg ret, TCGArg arg) | |
1323 | { | |
1324 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1325 | INSN_NOP_M, |
477ba620 AJ |
1326 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, ret, arg, 15, 15), |
1327 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, ret, ret, 0xb)); | |
1328 | } | |
1329 | ||
1330 | static inline void tcg_out_bswap32(TCGContext *s, TCGArg ret, TCGArg arg) | |
1331 | { | |
1332 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1333 | INSN_NOP_M, |
477ba620 AJ |
1334 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, ret, arg, 31, 31), |
1335 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, ret, ret, 0xb)); | |
1336 | } | |
1337 | ||
1338 | static inline void tcg_out_bswap64(TCGContext *s, TCGArg ret, TCGArg arg) | |
1339 | { | |
a3e28aa5 | 1340 | tcg_out_bundle(s, miI, |
5f7b1687 RH |
1341 | INSN_NOP_M, |
1342 | INSN_NOP_I, | |
477ba620 AJ |
1343 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, ret, arg, 0xb)); |
1344 | } | |
1345 | ||
c7d4475a RH |
1346 | static inline void tcg_out_deposit(TCGContext *s, TCGArg ret, TCGArg a1, |
1347 | TCGArg a2, int const_a2, int pos, int len) | |
1348 | { | |
1349 | uint64_t i1 = 0, i2 = 0; | |
1350 | int cpos = 63 - pos, lm1 = len - 1; | |
1351 | ||
1352 | if (const_a2) { | |
1353 | /* Truncate the value of a constant a2 to the width of the field. */ | |
1354 | int mask = (1u << len) - 1; | |
1355 | a2 &= mask; | |
1356 | ||
1357 | if (a2 == 0 || a2 == mask) { | |
1358 | /* 1-bit signed constant inserted into register. */ | |
1359 | i2 = tcg_opc_i14(TCG_REG_P0, OPC_DEP_I14, ret, a2, a1, cpos, lm1); | |
1360 | } else { | |
1361 | /* Otherwise, load any constant into a temporary. Do this into | |
1362 | the first I slot to help out with cross-unit delays. */ | |
1363 | i1 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5, | |
1364 | TCG_REG_R2, a2, TCG_REG_R0); | |
1365 | a2 = TCG_REG_R2; | |
1366 | } | |
1367 | } | |
1368 | if (i2 == 0) { | |
1369 | i2 = tcg_opc_i15(TCG_REG_P0, OPC_DEP_I15, ret, a2, a1, cpos, lm1); | |
1370 | } | |
1371 | tcg_out_bundle(s, (i1 ? mII : miI), | |
5f7b1687 RH |
1372 | INSN_NOP_M, |
1373 | i1 ? i1 : INSN_NOP_I, | |
c7d4475a RH |
1374 | i2); |
1375 | } | |
1376 | ||
477ba620 AJ |
1377 | static inline uint64_t tcg_opc_cmp_a(int qp, TCGCond cond, TCGArg arg1, |
1378 | TCGArg arg2, int cmp4) | |
1379 | { | |
1380 | uint64_t opc_eq_a6, opc_lt_a6, opc_ltu_a6; | |
1381 | ||
1382 | if (cmp4) { | |
1383 | opc_eq_a6 = OPC_CMP4_EQ_A6; | |
1384 | opc_lt_a6 = OPC_CMP4_LT_A6; | |
1385 | opc_ltu_a6 = OPC_CMP4_LTU_A6; | |
1386 | } else { | |
1387 | opc_eq_a6 = OPC_CMP_EQ_A6; | |
1388 | opc_lt_a6 = OPC_CMP_LT_A6; | |
1389 | opc_ltu_a6 = OPC_CMP_LTU_A6; | |
1390 | } | |
1391 | ||
1392 | switch (cond) { | |
1393 | case TCG_COND_EQ: | |
1394 | return tcg_opc_a6 (qp, opc_eq_a6, TCG_REG_P6, TCG_REG_P7, arg1, arg2); | |
1395 | case TCG_COND_NE: | |
1396 | return tcg_opc_a6 (qp, opc_eq_a6, TCG_REG_P7, TCG_REG_P6, arg1, arg2); | |
1397 | case TCG_COND_LT: | |
1398 | return tcg_opc_a6 (qp, opc_lt_a6, TCG_REG_P6, TCG_REG_P7, arg1, arg2); | |
1399 | case TCG_COND_LTU: | |
1400 | return tcg_opc_a6 (qp, opc_ltu_a6, TCG_REG_P6, TCG_REG_P7, arg1, arg2); | |
1401 | case TCG_COND_GE: | |
1402 | return tcg_opc_a6 (qp, opc_lt_a6, TCG_REG_P7, TCG_REG_P6, arg1, arg2); | |
1403 | case TCG_COND_GEU: | |
1404 | return tcg_opc_a6 (qp, opc_ltu_a6, TCG_REG_P7, TCG_REG_P6, arg1, arg2); | |
1405 | case TCG_COND_LE: | |
1406 | return tcg_opc_a6 (qp, opc_lt_a6, TCG_REG_P7, TCG_REG_P6, arg2, arg1); | |
1407 | case TCG_COND_LEU: | |
1408 | return tcg_opc_a6 (qp, opc_ltu_a6, TCG_REG_P7, TCG_REG_P6, arg2, arg1); | |
1409 | case TCG_COND_GT: | |
1410 | return tcg_opc_a6 (qp, opc_lt_a6, TCG_REG_P6, TCG_REG_P7, arg2, arg1); | |
1411 | case TCG_COND_GTU: | |
1412 | return tcg_opc_a6 (qp, opc_ltu_a6, TCG_REG_P6, TCG_REG_P7, arg2, arg1); | |
1413 | default: | |
1414 | tcg_abort(); | |
1415 | break; | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | static inline void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGArg arg1, | |
1420 | int const_arg1, TCGArg arg2, int const_arg2, | |
1421 | int label_index, int cmp4) | |
1422 | { | |
1423 | TCGLabel *l = &s->labels[label_index]; | |
1424 | uint64_t opc1, opc2; | |
1425 | ||
1426 | if (const_arg1 && arg1 != 0) { | |
1427 | opc1 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5, TCG_REG_R2, | |
1428 | arg1, TCG_REG_R0); | |
1429 | arg1 = TCG_REG_R2; | |
1430 | } else { | |
5f7b1687 | 1431 | opc1 = INSN_NOP_M; |
477ba620 AJ |
1432 | } |
1433 | ||
1434 | if (const_arg2 && arg2 != 0) { | |
1435 | opc2 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5, TCG_REG_R3, | |
1436 | arg2, TCG_REG_R0); | |
1437 | arg2 = TCG_REG_R3; | |
1438 | } else { | |
5f7b1687 | 1439 | opc2 = INSN_NOP_I; |
477ba620 AJ |
1440 | } |
1441 | ||
1442 | tcg_out_bundle(s, mII, | |
1443 | opc1, | |
1444 | opc2, | |
1445 | tcg_opc_cmp_a(TCG_REG_P0, cond, arg1, arg2, cmp4)); | |
1446 | tcg_out_bundle(s, mmB, | |
5f7b1687 RH |
1447 | INSN_NOP_M, |
1448 | INSN_NOP_M, | |
477ba620 AJ |
1449 | tcg_opc_b1 (TCG_REG_P6, OPC_BR_DPTK_FEW_B1, |
1450 | get_reloc_pcrel21b(s->code_ptr + 2))); | |
1451 | ||
1452 | if (l->has_value) { | |
1453 | reloc_pcrel21b((s->code_ptr - 16) + 2, l->u.value); | |
1454 | } else { | |
1455 | tcg_out_reloc(s, (s->code_ptr - 16) + 2, | |
1456 | R_IA64_PCREL21B, label_index, 0); | |
1457 | } | |
1458 | } | |
1459 | ||
1460 | static inline void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGArg ret, | |
1461 | TCGArg arg1, TCGArg arg2, int cmp4) | |
1462 | { | |
1463 | tcg_out_bundle(s, MmI, | |
1464 | tcg_opc_cmp_a(TCG_REG_P0, cond, arg1, arg2, cmp4), | |
1465 | tcg_opc_a5(TCG_REG_P6, OPC_ADDL_A5, ret, 1, TCG_REG_R0), | |
1466 | tcg_opc_a5(TCG_REG_P7, OPC_ADDL_A5, ret, 0, TCG_REG_R0)); | |
1467 | } | |
1468 | ||
b90cf716 AJ |
1469 | static inline void tcg_out_movcond(TCGContext *s, TCGCond cond, TCGArg ret, |
1470 | TCGArg c1, TCGArg c2, | |
1471 | TCGArg v1, int const_v1, | |
1472 | TCGArg v2, int const_v2, int cmp4) | |
1473 | { | |
1474 | uint64_t opc1, opc2; | |
1475 | ||
1476 | if (const_v1) { | |
1477 | opc1 = tcg_opc_a5(TCG_REG_P6, OPC_ADDL_A5, ret, v1, TCG_REG_R0); | |
1478 | } else if (ret == v1) { | |
5f7b1687 | 1479 | opc1 = INSN_NOP_M; |
b90cf716 AJ |
1480 | } else { |
1481 | opc1 = tcg_opc_a4(TCG_REG_P6, OPC_ADDS_A4, ret, 0, v1); | |
1482 | } | |
1483 | if (const_v2) { | |
1484 | opc2 = tcg_opc_a5(TCG_REG_P7, OPC_ADDL_A5, ret, v2, TCG_REG_R0); | |
1485 | } else if (ret == v2) { | |
5f7b1687 | 1486 | opc2 = INSN_NOP_I; |
b90cf716 AJ |
1487 | } else { |
1488 | opc2 = tcg_opc_a4(TCG_REG_P7, OPC_ADDS_A4, ret, 0, v2); | |
1489 | } | |
1490 | ||
1491 | tcg_out_bundle(s, MmI, | |
1492 | tcg_opc_cmp_a(TCG_REG_P0, cond, c1, c2, cmp4), | |
1493 | opc1, | |
1494 | opc2); | |
1495 | } | |
1496 | ||
477ba620 | 1497 | #if defined(CONFIG_SOFTMMU) |
477ba620 AJ |
1498 | /* Load and compare a TLB entry, and return the result in (p6, p7). |
1499 | R2 is loaded with the address of the addend TLB entry. | |
2174d1e1 | 1500 | R57 is loaded with the address, zero extented on 32-bit targets. */ |
477ba620 | 1501 | static inline void tcg_out_qemu_tlb(TCGContext *s, TCGArg addr_reg, |
e3afa1c4 | 1502 | TCGMemOp s_bits, uint64_t offset_rw, |
477ba620 AJ |
1503 | uint64_t offset_addend) |
1504 | { | |
1505 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1506 | INSN_NOP_M, |
477ba620 AJ |
1507 | tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, TCG_REG_R2, |
1508 | addr_reg, TARGET_PAGE_BITS, CPU_TLB_BITS - 1), | |
1509 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, TCG_REG_R2, | |
1510 | TCG_REG_R2, 63 - CPU_TLB_ENTRY_BITS, | |
1511 | 63 - CPU_TLB_ENTRY_BITS)); | |
1512 | tcg_out_bundle(s, mII, | |
1513 | tcg_opc_a5 (TCG_REG_P0, OPC_ADDL_A5, TCG_REG_R2, | |
1514 | offset_rw, TCG_REG_R2), | |
1515 | #if TARGET_LONG_BITS == 32 | |
2174d1e1 | 1516 | tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29, TCG_REG_R57, addr_reg), |
477ba620 | 1517 | #else |
2174d1e1 | 1518 | tcg_opc_a4(TCG_REG_P0, OPC_ADDS_A4, TCG_REG_R57, |
477ba620 AJ |
1519 | 0, addr_reg), |
1520 | #endif | |
1521 | tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2, | |
1522 | TCG_REG_R2, TCG_AREG0)); | |
1523 | tcg_out_bundle(s, mII, | |
650a217a RH |
1524 | tcg_opc_m3 (TCG_REG_P0, |
1525 | (TARGET_LONG_BITS == 32 | |
2174d1e1 | 1526 | ? OPC_LD4_M3 : OPC_LD8_M3), TCG_REG_R56, |
477ba620 | 1527 | TCG_REG_R2, offset_addend - offset_rw), |
63975ea7 AJ |
1528 | tcg_opc_i14(TCG_REG_P0, OPC_DEP_I14, TCG_REG_R3, 0, |
1529 | TCG_REG_R57, 63 - s_bits, | |
1530 | TARGET_PAGE_BITS - s_bits - 1), | |
477ba620 | 1531 | tcg_opc_a6 (TCG_REG_P0, OPC_CMP_EQ_A6, TCG_REG_P6, |
2174d1e1 | 1532 | TCG_REG_P7, TCG_REG_R3, TCG_REG_R56)); |
477ba620 AJ |
1533 | } |
1534 | ||
e141ab52 BS |
1535 | /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr, |
1536 | int mmu_idx) */ | |
1537 | static const void * const qemu_ld_helpers[4] = { | |
1538 | helper_ldb_mmu, | |
1539 | helper_ldw_mmu, | |
1540 | helper_ldl_mmu, | |
1541 | helper_ldq_mmu, | |
1542 | }; | |
477ba620 | 1543 | |
e3afa1c4 RH |
1544 | static inline void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, |
1545 | TCGMemOp opc) | |
477ba620 | 1546 | { |
e3afa1c4 RH |
1547 | static const uint64_t opc_ld_m1[4] = { |
1548 | OPC_LD1_M1, OPC_LD2_M1, OPC_LD4_M1, OPC_LD8_M1 | |
1549 | }; | |
1550 | static const uint64_t opc_ext_i29[8] = { | |
1551 | OPC_ZXT1_I29, OPC_ZXT2_I29, OPC_ZXT4_I29, 0, | |
1552 | OPC_SXT1_I29, OPC_SXT2_I29, OPC_SXT4_I29, 0 | |
1553 | }; | |
1554 | int addr_reg, data_reg, mem_index; | |
1555 | TCGMemOp s_bits, bswap; | |
477ba620 AJ |
1556 | |
1557 | data_reg = *args++; | |
1558 | addr_reg = *args++; | |
1559 | mem_index = *args; | |
e3afa1c4 RH |
1560 | s_bits = opc & MO_SIZE; |
1561 | bswap = opc & MO_BSWAP; | |
477ba620 AJ |
1562 | |
1563 | /* Read the TLB entry */ | |
1564 | tcg_out_qemu_tlb(s, addr_reg, s_bits, | |
9349b4f9 AF |
1565 | offsetof(CPUArchState, tlb_table[mem_index][0].addr_read), |
1566 | offsetof(CPUArchState, tlb_table[mem_index][0].addend)); | |
477ba620 AJ |
1567 | |
1568 | /* P6 is the fast path, and P7 the slow path */ | |
1569 | tcg_out_bundle(s, mLX, | |
2174d1e1 AJ |
1570 | tcg_opc_a4 (TCG_REG_P7, OPC_ADDS_A4, |
1571 | TCG_REG_R56, 0, TCG_AREG0), | |
477ba620 AJ |
1572 | tcg_opc_l2 ((tcg_target_long) qemu_ld_helpers[s_bits]), |
1573 | tcg_opc_x2 (TCG_REG_P7, OPC_MOVL_X2, TCG_REG_R2, | |
1574 | (tcg_target_long) qemu_ld_helpers[s_bits])); | |
1575 | tcg_out_bundle(s, MmI, | |
1576 | tcg_opc_m3 (TCG_REG_P0, OPC_LD8_M3, TCG_REG_R3, | |
1577 | TCG_REG_R2, 8), | |
1578 | tcg_opc_a1 (TCG_REG_P6, OPC_ADD_A1, TCG_REG_R3, | |
2174d1e1 | 1579 | TCG_REG_R3, TCG_REG_R57), |
477ba620 AJ |
1580 | tcg_opc_i21(TCG_REG_P7, OPC_MOV_I21, TCG_REG_B6, |
1581 | TCG_REG_R3, 0)); | |
e3afa1c4 | 1582 | if (bswap && s_bits == MO_16) { |
477ba620 AJ |
1583 | tcg_out_bundle(s, MmI, |
1584 | tcg_opc_m1 (TCG_REG_P6, opc_ld_m1[s_bits], | |
1585 | TCG_REG_R8, TCG_REG_R3), | |
1586 | tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, TCG_REG_R1, TCG_REG_R2), | |
1587 | tcg_opc_i12(TCG_REG_P6, OPC_DEP_Z_I12, | |
1588 | TCG_REG_R8, TCG_REG_R8, 15, 15)); | |
e3afa1c4 | 1589 | } else if (bswap && s_bits == MO_32) { |
477ba620 AJ |
1590 | tcg_out_bundle(s, MmI, |
1591 | tcg_opc_m1 (TCG_REG_P6, opc_ld_m1[s_bits], | |
1592 | TCG_REG_R8, TCG_REG_R3), | |
1593 | tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, TCG_REG_R1, TCG_REG_R2), | |
1594 | tcg_opc_i12(TCG_REG_P6, OPC_DEP_Z_I12, | |
1595 | TCG_REG_R8, TCG_REG_R8, 31, 31)); | |
1596 | } else { | |
1597 | tcg_out_bundle(s, mmI, | |
1598 | tcg_opc_m1 (TCG_REG_P6, opc_ld_m1[s_bits], | |
1599 | TCG_REG_R8, TCG_REG_R3), | |
1600 | tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, TCG_REG_R1, TCG_REG_R2), | |
5f7b1687 | 1601 | INSN_NOP_I); |
477ba620 | 1602 | } |
e3afa1c4 | 1603 | if (!bswap) { |
477ba620 | 1604 | tcg_out_bundle(s, miB, |
2174d1e1 AJ |
1605 | tcg_opc_a5 (TCG_REG_P7, OPC_ADDL_A5, TCG_REG_R58, |
1606 | mem_index, TCG_REG_R0), | |
5f7b1687 | 1607 | INSN_NOP_I, |
477ba620 AJ |
1608 | tcg_opc_b5 (TCG_REG_P7, OPC_BR_CALL_SPTK_MANY_B5, |
1609 | TCG_REG_B0, TCG_REG_B6)); | |
1610 | } else { | |
1611 | tcg_out_bundle(s, miB, | |
2174d1e1 AJ |
1612 | tcg_opc_a5 (TCG_REG_P7, OPC_ADDL_A5, TCG_REG_R58, |
1613 | mem_index, TCG_REG_R0), | |
477ba620 AJ |
1614 | tcg_opc_i3 (TCG_REG_P6, OPC_MUX1_I3, |
1615 | TCG_REG_R8, TCG_REG_R8, 0xb), | |
1616 | tcg_opc_b5 (TCG_REG_P7, OPC_BR_CALL_SPTK_MANY_B5, | |
1617 | TCG_REG_B0, TCG_REG_B6)); | |
1618 | } | |
1619 | ||
e3afa1c4 | 1620 | if (s_bits == MO_64) { |
477ba620 | 1621 | tcg_out_bundle(s, miI, |
5f7b1687 RH |
1622 | INSN_NOP_M, |
1623 | INSN_NOP_I, | |
477ba620 AJ |
1624 | tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4, |
1625 | data_reg, 0, TCG_REG_R8)); | |
1626 | } else { | |
1627 | tcg_out_bundle(s, miI, | |
5f7b1687 RH |
1628 | INSN_NOP_M, |
1629 | INSN_NOP_I, | |
e3afa1c4 | 1630 | tcg_opc_i29(TCG_REG_P0, opc_ext_i29[opc & MO_SSIZE], |
477ba620 AJ |
1631 | data_reg, TCG_REG_R8)); |
1632 | } | |
1633 | } | |
1634 | ||
e141ab52 BS |
1635 | /* helper signature: helper_st_mmu(CPUState *env, target_ulong addr, |
1636 | uintxx_t val, int mmu_idx) */ | |
1637 | static const void * const qemu_st_helpers[4] = { | |
1638 | helper_stb_mmu, | |
1639 | helper_stw_mmu, | |
1640 | helper_stl_mmu, | |
1641 | helper_stq_mmu, | |
1642 | }; | |
477ba620 | 1643 | |
e3afa1c4 RH |
1644 | static inline void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, |
1645 | TCGMemOp opc) | |
477ba620 | 1646 | { |
e3afa1c4 RH |
1647 | static const uint64_t opc_st_m4[4] = { |
1648 | OPC_ST1_M4, OPC_ST2_M4, OPC_ST4_M4, OPC_ST8_M4 | |
1649 | }; | |
1650 | int addr_reg, data_reg, mem_index; | |
1651 | TCGMemOp s_bits; | |
477ba620 AJ |
1652 | |
1653 | data_reg = *args++; | |
1654 | addr_reg = *args++; | |
1655 | mem_index = *args; | |
e3afa1c4 | 1656 | s_bits = opc & MO_SIZE; |
477ba620 | 1657 | |
e3afa1c4 | 1658 | tcg_out_qemu_tlb(s, addr_reg, s_bits, |
9349b4f9 AF |
1659 | offsetof(CPUArchState, tlb_table[mem_index][0].addr_write), |
1660 | offsetof(CPUArchState, tlb_table[mem_index][0].addend)); | |
477ba620 AJ |
1661 | |
1662 | /* P6 is the fast path, and P7 the slow path */ | |
1663 | tcg_out_bundle(s, mLX, | |
2174d1e1 AJ |
1664 | tcg_opc_a4 (TCG_REG_P7, OPC_ADDS_A4, |
1665 | TCG_REG_R56, 0, TCG_AREG0), | |
e3afa1c4 | 1666 | tcg_opc_l2 ((tcg_target_long) qemu_st_helpers[s_bits]), |
477ba620 | 1667 | tcg_opc_x2 (TCG_REG_P7, OPC_MOVL_X2, TCG_REG_R2, |
e3afa1c4 | 1668 | (tcg_target_long) qemu_st_helpers[s_bits])); |
477ba620 AJ |
1669 | tcg_out_bundle(s, MmI, |
1670 | tcg_opc_m3 (TCG_REG_P0, OPC_LD8_M3, TCG_REG_R3, | |
1671 | TCG_REG_R2, 8), | |
1672 | tcg_opc_a1 (TCG_REG_P6, OPC_ADD_A1, TCG_REG_R3, | |
2174d1e1 | 1673 | TCG_REG_R3, TCG_REG_R57), |
477ba620 AJ |
1674 | tcg_opc_i21(TCG_REG_P7, OPC_MOV_I21, TCG_REG_B6, |
1675 | TCG_REG_R3, 0)); | |
1676 | ||
e3afa1c4 RH |
1677 | switch (opc) { |
1678 | case MO_8: | |
1679 | case MO_16: | |
1680 | case MO_32: | |
1681 | case MO_64: | |
2174d1e1 | 1682 | tcg_out_bundle(s, mii, |
477ba620 AJ |
1683 | tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, |
1684 | TCG_REG_R1, TCG_REG_R2), | |
2174d1e1 AJ |
1685 | tcg_opc_a4 (TCG_REG_P7, OPC_ADDS_A4, TCG_REG_R58, |
1686 | 0, data_reg), | |
5f7b1687 | 1687 | INSN_NOP_I); |
e3afa1c4 RH |
1688 | break; |
1689 | ||
1690 | case MO_16 | MO_BSWAP: | |
2174d1e1 | 1691 | tcg_out_bundle(s, miI, |
477ba620 AJ |
1692 | tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, |
1693 | TCG_REG_R1, TCG_REG_R2), | |
5f7b1687 | 1694 | INSN_NOP_I, |
477ba620 | 1695 | tcg_opc_i12(TCG_REG_P6, OPC_DEP_Z_I12, |
2174d1e1 AJ |
1696 | TCG_REG_R2, data_reg, 15, 15)); |
1697 | tcg_out_bundle(s, miI, | |
1698 | tcg_opc_a4 (TCG_REG_P7, OPC_ADDS_A4, TCG_REG_R58, | |
1699 | 0, data_reg), | |
5f7b1687 | 1700 | INSN_NOP_I, |
477ba620 AJ |
1701 | tcg_opc_i3 (TCG_REG_P6, OPC_MUX1_I3, |
1702 | TCG_REG_R2, TCG_REG_R2, 0xb)); | |
1703 | data_reg = TCG_REG_R2; | |
e3afa1c4 RH |
1704 | break; |
1705 | ||
1706 | case MO_32 | MO_BSWAP: | |
2174d1e1 | 1707 | tcg_out_bundle(s, miI, |
477ba620 AJ |
1708 | tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, |
1709 | TCG_REG_R1, TCG_REG_R2), | |
5f7b1687 | 1710 | INSN_NOP_I, |
477ba620 | 1711 | tcg_opc_i12(TCG_REG_P6, OPC_DEP_Z_I12, |
2174d1e1 AJ |
1712 | TCG_REG_R2, data_reg, 31, 31)); |
1713 | tcg_out_bundle(s, miI, | |
1714 | tcg_opc_a4 (TCG_REG_P7, OPC_ADDS_A4, TCG_REG_R58, | |
1715 | 0, data_reg), | |
5f7b1687 | 1716 | INSN_NOP_I, |
477ba620 AJ |
1717 | tcg_opc_i3 (TCG_REG_P6, OPC_MUX1_I3, |
1718 | TCG_REG_R2, TCG_REG_R2, 0xb)); | |
1719 | data_reg = TCG_REG_R2; | |
e3afa1c4 RH |
1720 | break; |
1721 | ||
1722 | case MO_64 | MO_BSWAP: | |
477ba620 AJ |
1723 | tcg_out_bundle(s, miI, |
1724 | tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, | |
1725 | TCG_REG_R1, TCG_REG_R2), | |
2174d1e1 AJ |
1726 | tcg_opc_a4 (TCG_REG_P7, OPC_ADDS_A4, TCG_REG_R58, |
1727 | 0, data_reg), | |
477ba620 AJ |
1728 | tcg_opc_i3 (TCG_REG_P6, OPC_MUX1_I3, |
1729 | TCG_REG_R2, data_reg, 0xb)); | |
1730 | data_reg = TCG_REG_R2; | |
e3afa1c4 RH |
1731 | break; |
1732 | ||
1733 | default: | |
1734 | tcg_abort(); | |
477ba620 AJ |
1735 | } |
1736 | ||
d03c98d8 | 1737 | tcg_out_bundle(s, miB, |
e3afa1c4 | 1738 | tcg_opc_m4 (TCG_REG_P6, opc_st_m4[s_bits], |
d03c98d8 | 1739 | data_reg, TCG_REG_R3), |
2174d1e1 AJ |
1740 | tcg_opc_a5 (TCG_REG_P7, OPC_ADDL_A5, TCG_REG_R59, |
1741 | mem_index, TCG_REG_R0), | |
d03c98d8 AJ |
1742 | tcg_opc_b5 (TCG_REG_P7, OPC_BR_CALL_SPTK_MANY_B5, |
1743 | TCG_REG_B0, TCG_REG_B6)); | |
477ba620 AJ |
1744 | } |
1745 | ||
1746 | #else /* !CONFIG_SOFTMMU */ | |
1747 | ||
e3afa1c4 RH |
1748 | static inline void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, |
1749 | TCGMemOp opc) | |
477ba620 | 1750 | { |
6781d08d RH |
1751 | static uint64_t const opc_ld_m1[4] = { |
1752 | OPC_LD1_M1, OPC_LD2_M1, OPC_LD4_M1, OPC_LD8_M1 | |
1753 | }; | |
1754 | static uint64_t const opc_sxt_i29[4] = { | |
1755 | OPC_SXT1_I29, OPC_SXT2_I29, OPC_SXT4_I29, 0 | |
1756 | }; | |
e3afa1c4 RH |
1757 | int addr_reg, data_reg; |
1758 | TCGMemOp s_bits, bswap; | |
477ba620 AJ |
1759 | |
1760 | data_reg = *args++; | |
1761 | addr_reg = *args++; | |
e3afa1c4 RH |
1762 | s_bits = opc & MO_SIZE; |
1763 | bswap = opc & MO_BSWAP; | |
477ba620 | 1764 | |
477ba620 | 1765 | #if TARGET_LONG_BITS == 32 |
6781d08d RH |
1766 | if (GUEST_BASE != 0) { |
1767 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1768 | INSN_NOP_M, |
6781d08d RH |
1769 | tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29, |
1770 | TCG_REG_R3, addr_reg), | |
1771 | tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2, | |
1772 | TCG_GUEST_BASE_REG, TCG_REG_R3)); | |
1773 | } else { | |
1774 | tcg_out_bundle(s, miI, | |
5f7b1687 | 1775 | INSN_NOP_M, |
6781d08d RH |
1776 | tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29, |
1777 | TCG_REG_R2, addr_reg), | |
5f7b1687 | 1778 | INSN_NOP_I); |
6781d08d | 1779 | } |
477ba620 | 1780 | |
e3afa1c4 RH |
1781 | if (!bswap) { |
1782 | if (!(opc & MO_SIGN)) { | |
477ba620 AJ |
1783 | tcg_out_bundle(s, miI, |
1784 | tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits], | |
1785 | data_reg, TCG_REG_R2), | |
5f7b1687 RH |
1786 | INSN_NOP_I, |
1787 | INSN_NOP_I); | |
477ba620 AJ |
1788 | } else { |
1789 | tcg_out_bundle(s, mII, | |
1790 | tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits], | |
1791 | data_reg, TCG_REG_R2), | |
5f7b1687 | 1792 | INSN_NOP_I, |
477ba620 AJ |
1793 | tcg_opc_i29(TCG_REG_P0, opc_sxt_i29[s_bits], |
1794 | data_reg, data_reg)); | |
1795 | } | |
e3afa1c4 | 1796 | } else if (s_bits == MO_64) { |
477ba620 AJ |
1797 | tcg_out_bundle(s, mII, |
1798 | tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits], | |
1799 | data_reg, TCG_REG_R2), | |
5f7b1687 | 1800 | INSN_NOP_I, |
477ba620 AJ |
1801 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, |
1802 | data_reg, data_reg, 0xb)); | |
1803 | } else { | |
e3afa1c4 | 1804 | if (s_bits == MO_16) { |
477ba620 AJ |
1805 | tcg_out_bundle(s, mII, |
1806 | tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits], | |
1807 | data_reg, TCG_REG_R2), | |
5f7b1687 | 1808 | INSN_NOP_I, |
477ba620 AJ |
1809 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, |
1810 | data_reg, data_reg, 15, 15)); | |
1811 | } else { | |
1812 | tcg_out_bundle(s, mII, | |
1813 | tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits], | |
1814 | data_reg, TCG_REG_R2), | |
5f7b1687 | 1815 | INSN_NOP_I, |
477ba620 AJ |
1816 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, |
1817 | data_reg, data_reg, 31, 31)); | |
1818 | } | |
e3afa1c4 | 1819 | if (!(opc & MO_SIGN)) { |
477ba620 | 1820 | tcg_out_bundle(s, miI, |
5f7b1687 RH |
1821 | INSN_NOP_M, |
1822 | INSN_NOP_I, | |
477ba620 AJ |
1823 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, |
1824 | data_reg, data_reg, 0xb)); | |
1825 | } else { | |
1826 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1827 | INSN_NOP_M, |
477ba620 AJ |
1828 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, |
1829 | data_reg, data_reg, 0xb), | |
1830 | tcg_opc_i29(TCG_REG_P0, opc_sxt_i29[s_bits], | |
1831 | data_reg, data_reg)); | |
1832 | } | |
1833 | } | |
1834 | #else | |
6781d08d RH |
1835 | if (GUEST_BASE != 0) { |
1836 | tcg_out_bundle(s, MmI, | |
1837 | tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2, | |
1838 | TCG_GUEST_BASE_REG, addr_reg), | |
1839 | tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits], | |
1840 | data_reg, TCG_REG_R2), | |
5f7b1687 | 1841 | INSN_NOP_I); |
6781d08d RH |
1842 | } else { |
1843 | tcg_out_bundle(s, mmI, | |
5f7b1687 | 1844 | INSN_NOP_M, |
6781d08d RH |
1845 | tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits], |
1846 | data_reg, addr_reg), | |
5f7b1687 | 1847 | INSN_NOP_I); |
6781d08d | 1848 | } |
477ba620 | 1849 | |
e3afa1c4 | 1850 | if (bswap && s_bits == MO_16) { |
477ba620 | 1851 | tcg_out_bundle(s, mII, |
5f7b1687 | 1852 | INSN_NOP_M, |
477ba620 AJ |
1853 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, |
1854 | data_reg, data_reg, 15, 15), | |
1855 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, | |
1856 | data_reg, data_reg, 0xb)); | |
e3afa1c4 | 1857 | } else if (bswap && s_bits == MO_32) { |
477ba620 | 1858 | tcg_out_bundle(s, mII, |
5f7b1687 | 1859 | INSN_NOP_M, |
477ba620 AJ |
1860 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, |
1861 | data_reg, data_reg, 31, 31), | |
1862 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, | |
1863 | data_reg, data_reg, 0xb)); | |
e3afa1c4 | 1864 | } else if (bswap && s_bits == MO_64) { |
477ba620 | 1865 | tcg_out_bundle(s, miI, |
5f7b1687 RH |
1866 | INSN_NOP_M, |
1867 | INSN_NOP_I, | |
477ba620 AJ |
1868 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, |
1869 | data_reg, data_reg, 0xb)); | |
1870 | } | |
e3afa1c4 | 1871 | if (opc & MO_SIGN) { |
477ba620 | 1872 | tcg_out_bundle(s, miI, |
5f7b1687 RH |
1873 | INSN_NOP_M, |
1874 | INSN_NOP_I, | |
477ba620 AJ |
1875 | tcg_opc_i29(TCG_REG_P0, opc_sxt_i29[s_bits], |
1876 | data_reg, data_reg)); | |
1877 | } | |
1878 | #endif | |
1879 | } | |
1880 | ||
e3afa1c4 RH |
1881 | static inline void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, |
1882 | TCGMemOp opc) | |
477ba620 | 1883 | { |
6781d08d RH |
1884 | static uint64_t const opc_st_m4[4] = { |
1885 | OPC_ST1_M4, OPC_ST2_M4, OPC_ST4_M4, OPC_ST8_M4 | |
1886 | }; | |
e3afa1c4 | 1887 | int addr_reg, data_reg; |
6781d08d RH |
1888 | #if TARGET_LONG_BITS == 64 |
1889 | uint64_t add_guest_base; | |
1890 | #endif | |
e3afa1c4 | 1891 | TCGMemOp s_bits, bswap; |
477ba620 AJ |
1892 | |
1893 | data_reg = *args++; | |
1894 | addr_reg = *args++; | |
e3afa1c4 RH |
1895 | s_bits = opc & MO_SIZE; |
1896 | bswap = opc & MO_BSWAP; | |
477ba620 | 1897 | |
477ba620 | 1898 | #if TARGET_LONG_BITS == 32 |
6781d08d RH |
1899 | if (GUEST_BASE != 0) { |
1900 | tcg_out_bundle(s, mII, | |
5f7b1687 | 1901 | INSN_NOP_M, |
6781d08d RH |
1902 | tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29, |
1903 | TCG_REG_R3, addr_reg), | |
1904 | tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2, | |
1905 | TCG_GUEST_BASE_REG, TCG_REG_R3)); | |
1906 | } else { | |
1907 | tcg_out_bundle(s, miI, | |
5f7b1687 | 1908 | INSN_NOP_M, |
6781d08d | 1909 | tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29, |
07f59737 | 1910 | TCG_REG_R2, addr_reg), |
5f7b1687 | 1911 | INSN_NOP_I); |
6781d08d RH |
1912 | } |
1913 | ||
477ba620 | 1914 | if (bswap) { |
e3afa1c4 | 1915 | if (s_bits == MO_16) { |
477ba620 | 1916 | tcg_out_bundle(s, mII, |
5f7b1687 | 1917 | INSN_NOP_M, |
477ba620 AJ |
1918 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, |
1919 | TCG_REG_R3, data_reg, 15, 15), | |
1920 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, | |
1921 | TCG_REG_R3, TCG_REG_R3, 0xb)); | |
1922 | data_reg = TCG_REG_R3; | |
e3afa1c4 | 1923 | } else if (s_bits == MO_32) { |
477ba620 | 1924 | tcg_out_bundle(s, mII, |
5f7b1687 | 1925 | INSN_NOP_M, |
477ba620 AJ |
1926 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, |
1927 | TCG_REG_R3, data_reg, 31, 31), | |
1928 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, | |
1929 | TCG_REG_R3, TCG_REG_R3, 0xb)); | |
1930 | data_reg = TCG_REG_R3; | |
e3afa1c4 | 1931 | } else if (s_bits == MO_64) { |
477ba620 | 1932 | tcg_out_bundle(s, miI, |
5f7b1687 RH |
1933 | INSN_NOP_M, |
1934 | INSN_NOP_I, | |
477ba620 AJ |
1935 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, |
1936 | TCG_REG_R3, data_reg, 0xb)); | |
1937 | data_reg = TCG_REG_R3; | |
1938 | } | |
1939 | } | |
1940 | tcg_out_bundle(s, mmI, | |
e3afa1c4 | 1941 | tcg_opc_m4 (TCG_REG_P0, opc_st_m4[s_bits], |
477ba620 | 1942 | data_reg, TCG_REG_R2), |
5f7b1687 RH |
1943 | INSN_NOP_M, |
1944 | INSN_NOP_I); | |
477ba620 | 1945 | #else |
6781d08d RH |
1946 | if (GUEST_BASE != 0) { |
1947 | add_guest_base = tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2, | |
1948 | TCG_GUEST_BASE_REG, addr_reg); | |
1949 | addr_reg = TCG_REG_R2; | |
1950 | } else { | |
5f7b1687 | 1951 | add_guest_base = INSN_NOP_M; |
6781d08d RH |
1952 | } |
1953 | ||
e3afa1c4 | 1954 | if (!bswap) { |
6781d08d RH |
1955 | tcg_out_bundle(s, (GUEST_BASE ? MmI : mmI), |
1956 | add_guest_base, | |
e3afa1c4 | 1957 | tcg_opc_m4 (TCG_REG_P0, opc_st_m4[s_bits], |
6781d08d | 1958 | data_reg, addr_reg), |
5f7b1687 | 1959 | INSN_NOP_I); |
477ba620 | 1960 | } else { |
e3afa1c4 | 1961 | if (s_bits == MO_16) { |
477ba620 | 1962 | tcg_out_bundle(s, mII, |
6781d08d | 1963 | add_guest_base, |
477ba620 AJ |
1964 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, |
1965 | TCG_REG_R3, data_reg, 15, 15), | |
1966 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, | |
1967 | TCG_REG_R3, TCG_REG_R3, 0xb)); | |
1968 | data_reg = TCG_REG_R3; | |
e3afa1c4 | 1969 | } else if (s_bits == MO_32) { |
477ba620 | 1970 | tcg_out_bundle(s, mII, |
6781d08d | 1971 | add_guest_base, |
477ba620 AJ |
1972 | tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, |
1973 | TCG_REG_R3, data_reg, 31, 31), | |
1974 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, | |
1975 | TCG_REG_R3, TCG_REG_R3, 0xb)); | |
1976 | data_reg = TCG_REG_R3; | |
e3afa1c4 | 1977 | } else if (s_bits == MO_64) { |
477ba620 | 1978 | tcg_out_bundle(s, miI, |
6781d08d | 1979 | add_guest_base, |
5f7b1687 | 1980 | INSN_NOP_I, |
477ba620 AJ |
1981 | tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, |
1982 | TCG_REG_R3, data_reg, 0xb)); | |
1983 | data_reg = TCG_REG_R3; | |
1984 | } | |
1985 | tcg_out_bundle(s, miI, | |
e3afa1c4 | 1986 | tcg_opc_m4 (TCG_REG_P0, opc_st_m4[s_bits], |
6781d08d | 1987 | data_reg, addr_reg), |
5f7b1687 RH |
1988 | INSN_NOP_I, |
1989 | INSN_NOP_I); | |
477ba620 AJ |
1990 | } |
1991 | #endif | |
1992 | } | |
1993 | ||
1994 | #endif | |
1995 | ||
1996 | static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, | |
1997 | const TCGArg *args, const int *const_args) | |
1998 | { | |
1999 | switch(opc) { | |
2000 | case INDEX_op_exit_tb: | |
2001 | tcg_out_exit_tb(s, args[0]); | |
2002 | break; | |
2003 | case INDEX_op_br: | |
2004 | tcg_out_br(s, args[0]); | |
2005 | break; | |
2006 | case INDEX_op_call: | |
2007 | tcg_out_call(s, args[0]); | |
2008 | break; | |
2009 | case INDEX_op_goto_tb: | |
2010 | tcg_out_goto_tb(s, args[0]); | |
2011 | break; | |
477ba620 AJ |
2012 | |
2013 | case INDEX_op_movi_i32: | |
2014 | tcg_out_movi(s, TCG_TYPE_I32, args[0], args[1]); | |
2015 | break; | |
2016 | case INDEX_op_movi_i64: | |
2017 | tcg_out_movi(s, TCG_TYPE_I64, args[0], args[1]); | |
2018 | break; | |
2019 | ||
2020 | case INDEX_op_ld8u_i32: | |
2021 | case INDEX_op_ld8u_i64: | |
2022 | tcg_out_ld_rel(s, OPC_LD1_M1, args[0], args[1], args[2]); | |
2023 | break; | |
2024 | case INDEX_op_ld8s_i32: | |
2025 | case INDEX_op_ld8s_i64: | |
2026 | tcg_out_ld_rel(s, OPC_LD1_M1, args[0], args[1], args[2]); | |
2027 | tcg_out_ext(s, OPC_SXT1_I29, args[0], args[0]); | |
2028 | break; | |
2029 | case INDEX_op_ld16u_i32: | |
2030 | case INDEX_op_ld16u_i64: | |
2031 | tcg_out_ld_rel(s, OPC_LD2_M1, args[0], args[1], args[2]); | |
2032 | break; | |
2033 | case INDEX_op_ld16s_i32: | |
2034 | case INDEX_op_ld16s_i64: | |
2035 | tcg_out_ld_rel(s, OPC_LD2_M1, args[0], args[1], args[2]); | |
2036 | tcg_out_ext(s, OPC_SXT2_I29, args[0], args[0]); | |
2037 | break; | |
2038 | case INDEX_op_ld_i32: | |
2039 | case INDEX_op_ld32u_i64: | |
2040 | tcg_out_ld_rel(s, OPC_LD4_M1, args[0], args[1], args[2]); | |
2041 | break; | |
2042 | case INDEX_op_ld32s_i64: | |
2043 | tcg_out_ld_rel(s, OPC_LD4_M1, args[0], args[1], args[2]); | |
2044 | tcg_out_ext(s, OPC_SXT4_I29, args[0], args[0]); | |
2045 | break; | |
2046 | case INDEX_op_ld_i64: | |
2047 | tcg_out_ld_rel(s, OPC_LD8_M1, args[0], args[1], args[2]); | |
2048 | break; | |
2049 | case INDEX_op_st8_i32: | |
2050 | case INDEX_op_st8_i64: | |
2051 | tcg_out_st_rel(s, OPC_ST1_M4, args[0], args[1], args[2]); | |
2052 | break; | |
2053 | case INDEX_op_st16_i32: | |
2054 | case INDEX_op_st16_i64: | |
2055 | tcg_out_st_rel(s, OPC_ST2_M4, args[0], args[1], args[2]); | |
2056 | break; | |
2057 | case INDEX_op_st_i32: | |
2058 | case INDEX_op_st32_i64: | |
2059 | tcg_out_st_rel(s, OPC_ST4_M4, args[0], args[1], args[2]); | |
2060 | break; | |
2061 | case INDEX_op_st_i64: | |
2062 | tcg_out_st_rel(s, OPC_ST8_M4, args[0], args[1], args[2]); | |
2063 | break; | |
2064 | ||
2065 | case INDEX_op_add_i32: | |
2066 | case INDEX_op_add_i64: | |
2067 | tcg_out_alu(s, OPC_ADD_A1, args[0], args[1], const_args[1], | |
2068 | args[2], const_args[2]); | |
2069 | break; | |
2070 | case INDEX_op_sub_i32: | |
2071 | case INDEX_op_sub_i64: | |
2072 | tcg_out_alu(s, OPC_SUB_A1, args[0], args[1], const_args[1], | |
2073 | args[2], const_args[2]); | |
2074 | break; | |
2075 | ||
2076 | case INDEX_op_and_i32: | |
2077 | case INDEX_op_and_i64: | |
2078 | tcg_out_alu(s, OPC_AND_A1, args[0], args[1], const_args[1], | |
2079 | args[2], const_args[2]); | |
2080 | break; | |
2081 | case INDEX_op_andc_i32: | |
2082 | case INDEX_op_andc_i64: | |
2083 | tcg_out_alu(s, OPC_ANDCM_A1, args[0], args[1], const_args[1], | |
2084 | args[2], const_args[2]); | |
2085 | break; | |
2086 | case INDEX_op_eqv_i32: | |
2087 | case INDEX_op_eqv_i64: | |
2088 | tcg_out_eqv(s, args[0], args[1], const_args[1], | |
2089 | args[2], const_args[2]); | |
2090 | break; | |
2091 | case INDEX_op_nand_i32: | |
2092 | case INDEX_op_nand_i64: | |
2093 | tcg_out_nand(s, args[0], args[1], const_args[1], | |
2094 | args[2], const_args[2]); | |
2095 | break; | |
2096 | case INDEX_op_nor_i32: | |
2097 | case INDEX_op_nor_i64: | |
2098 | tcg_out_nor(s, args[0], args[1], const_args[1], | |
2099 | args[2], const_args[2]); | |
2100 | break; | |
2101 | case INDEX_op_or_i32: | |
2102 | case INDEX_op_or_i64: | |
2103 | tcg_out_alu(s, OPC_OR_A1, args[0], args[1], const_args[1], | |
2104 | args[2], const_args[2]); | |
2105 | break; | |
2106 | case INDEX_op_orc_i32: | |
2107 | case INDEX_op_orc_i64: | |
2108 | tcg_out_orc(s, args[0], args[1], const_args[1], | |
2109 | args[2], const_args[2]); | |
2110 | break; | |
2111 | case INDEX_op_xor_i32: | |
2112 | case INDEX_op_xor_i64: | |
2113 | tcg_out_alu(s, OPC_XOR_A1, args[0], args[1], const_args[1], | |
2114 | args[2], const_args[2]); | |
2115 | break; | |
2116 | ||
2117 | case INDEX_op_mul_i32: | |
2118 | case INDEX_op_mul_i64: | |
2119 | tcg_out_mul(s, args[0], args[1], args[2]); | |
2120 | break; | |
2121 | ||
2122 | case INDEX_op_sar_i32: | |
2123 | tcg_out_sar_i32(s, args[0], args[1], args[2], const_args[2]); | |
2124 | break; | |
2125 | case INDEX_op_sar_i64: | |
2126 | tcg_out_sar_i64(s, args[0], args[1], args[2], const_args[2]); | |
2127 | break; | |
2128 | case INDEX_op_shl_i32: | |
2129 | tcg_out_shl_i32(s, args[0], args[1], args[2], const_args[2]); | |
2130 | break; | |
2131 | case INDEX_op_shl_i64: | |
2132 | tcg_out_shl_i64(s, args[0], args[1], args[2], const_args[2]); | |
2133 | break; | |
2134 | case INDEX_op_shr_i32: | |
2135 | tcg_out_shr_i32(s, args[0], args[1], args[2], const_args[2]); | |
2136 | break; | |
2137 | case INDEX_op_shr_i64: | |
2138 | tcg_out_shr_i64(s, args[0], args[1], args[2], const_args[2]); | |
2139 | break; | |
2140 | case INDEX_op_rotl_i32: | |
2141 | tcg_out_rotl_i32(s, args[0], args[1], args[2], const_args[2]); | |
2142 | break; | |
2143 | case INDEX_op_rotl_i64: | |
2144 | tcg_out_rotl_i64(s, args[0], args[1], args[2], const_args[2]); | |
2145 | break; | |
2146 | case INDEX_op_rotr_i32: | |
2147 | tcg_out_rotr_i32(s, args[0], args[1], args[2], const_args[2]); | |
2148 | break; | |
2149 | case INDEX_op_rotr_i64: | |
2150 | tcg_out_rotr_i64(s, args[0], args[1], args[2], const_args[2]); | |
2151 | break; | |
2152 | ||
2153 | case INDEX_op_ext8s_i32: | |
2154 | case INDEX_op_ext8s_i64: | |
2155 | tcg_out_ext(s, OPC_SXT1_I29, args[0], args[1]); | |
2156 | break; | |
2157 | case INDEX_op_ext8u_i32: | |
2158 | case INDEX_op_ext8u_i64: | |
2159 | tcg_out_ext(s, OPC_ZXT1_I29, args[0], args[1]); | |
2160 | break; | |
2161 | case INDEX_op_ext16s_i32: | |
2162 | case INDEX_op_ext16s_i64: | |
2163 | tcg_out_ext(s, OPC_SXT2_I29, args[0], args[1]); | |
2164 | break; | |
2165 | case INDEX_op_ext16u_i32: | |
2166 | case INDEX_op_ext16u_i64: | |
2167 | tcg_out_ext(s, OPC_ZXT2_I29, args[0], args[1]); | |
2168 | break; | |
2169 | case INDEX_op_ext32s_i64: | |
2170 | tcg_out_ext(s, OPC_SXT4_I29, args[0], args[1]); | |
2171 | break; | |
2172 | case INDEX_op_ext32u_i64: | |
2173 | tcg_out_ext(s, OPC_ZXT4_I29, args[0], args[1]); | |
2174 | break; | |
2175 | ||
2176 | case INDEX_op_bswap16_i32: | |
2177 | case INDEX_op_bswap16_i64: | |
2178 | tcg_out_bswap16(s, args[0], args[1]); | |
2179 | break; | |
2180 | case INDEX_op_bswap32_i32: | |
2181 | case INDEX_op_bswap32_i64: | |
2182 | tcg_out_bswap32(s, args[0], args[1]); | |
2183 | break; | |
2184 | case INDEX_op_bswap64_i64: | |
2185 | tcg_out_bswap64(s, args[0], args[1]); | |
2186 | break; | |
2187 | ||
c7d4475a RH |
2188 | case INDEX_op_deposit_i32: |
2189 | case INDEX_op_deposit_i64: | |
2190 | tcg_out_deposit(s, args[0], args[1], args[2], const_args[2], | |
2191 | args[3], args[4]); | |
2192 | break; | |
2193 | ||
477ba620 AJ |
2194 | case INDEX_op_brcond_i32: |
2195 | tcg_out_brcond(s, args[2], args[0], const_args[0], | |
2196 | args[1], const_args[1], args[3], 1); | |
2197 | break; | |
2198 | case INDEX_op_brcond_i64: | |
2199 | tcg_out_brcond(s, args[2], args[0], const_args[0], | |
2200 | args[1], const_args[1], args[3], 0); | |
2201 | break; | |
2202 | case INDEX_op_setcond_i32: | |
2203 | tcg_out_setcond(s, args[3], args[0], args[1], args[2], 1); | |
2204 | break; | |
2205 | case INDEX_op_setcond_i64: | |
2206 | tcg_out_setcond(s, args[3], args[0], args[1], args[2], 0); | |
2207 | break; | |
b90cf716 AJ |
2208 | case INDEX_op_movcond_i32: |
2209 | tcg_out_movcond(s, args[5], args[0], args[1], args[2], | |
2210 | args[3], const_args[3], args[4], const_args[4], 1); | |
2211 | break; | |
2212 | case INDEX_op_movcond_i64: | |
2213 | tcg_out_movcond(s, args[5], args[0], args[1], args[2], | |
2214 | args[3], const_args[3], args[4], const_args[4], 0); | |
2215 | break; | |
477ba620 AJ |
2216 | |
2217 | case INDEX_op_qemu_ld8u: | |
e3afa1c4 | 2218 | tcg_out_qemu_ld(s, args, MO_UB); |
477ba620 AJ |
2219 | break; |
2220 | case INDEX_op_qemu_ld8s: | |
e3afa1c4 | 2221 | tcg_out_qemu_ld(s, args, MO_SB); |
477ba620 AJ |
2222 | break; |
2223 | case INDEX_op_qemu_ld16u: | |
e3afa1c4 | 2224 | tcg_out_qemu_ld(s, args, MO_TEUW); |
477ba620 AJ |
2225 | break; |
2226 | case INDEX_op_qemu_ld16s: | |
e3afa1c4 | 2227 | tcg_out_qemu_ld(s, args, MO_TESW); |
477ba620 | 2228 | break; |
b3b0091f | 2229 | case INDEX_op_qemu_ld32: |
477ba620 | 2230 | case INDEX_op_qemu_ld32u: |
e3afa1c4 | 2231 | tcg_out_qemu_ld(s, args, MO_TEUL); |
477ba620 AJ |
2232 | break; |
2233 | case INDEX_op_qemu_ld32s: | |
e3afa1c4 | 2234 | tcg_out_qemu_ld(s, args, MO_TESL); |
477ba620 AJ |
2235 | break; |
2236 | case INDEX_op_qemu_ld64: | |
e3afa1c4 | 2237 | tcg_out_qemu_ld(s, args, MO_TEQ); |
477ba620 AJ |
2238 | break; |
2239 | ||
2240 | case INDEX_op_qemu_st8: | |
e3afa1c4 | 2241 | tcg_out_qemu_st(s, args, MO_UB); |
477ba620 AJ |
2242 | break; |
2243 | case INDEX_op_qemu_st16: | |
e3afa1c4 | 2244 | tcg_out_qemu_st(s, args, MO_TEUW); |
477ba620 AJ |
2245 | break; |
2246 | case INDEX_op_qemu_st32: | |
e3afa1c4 | 2247 | tcg_out_qemu_st(s, args, MO_TEUL); |
477ba620 AJ |
2248 | break; |
2249 | case INDEX_op_qemu_st64: | |
e3afa1c4 | 2250 | tcg_out_qemu_st(s, args, MO_TEQ); |
477ba620 AJ |
2251 | break; |
2252 | ||
2253 | default: | |
2254 | tcg_abort(); | |
2255 | } | |
2256 | } | |
2257 | ||
2258 | static const TCGTargetOpDef ia64_op_defs[] = { | |
2259 | { INDEX_op_br, { } }, | |
2260 | { INDEX_op_call, { "r" } }, | |
2261 | { INDEX_op_exit_tb, { } }, | |
2262 | { INDEX_op_goto_tb, { } }, | |
477ba620 AJ |
2263 | |
2264 | { INDEX_op_mov_i32, { "r", "r" } }, | |
2265 | { INDEX_op_movi_i32, { "r" } }, | |
2266 | ||
2267 | { INDEX_op_ld8u_i32, { "r", "r" } }, | |
2268 | { INDEX_op_ld8s_i32, { "r", "r" } }, | |
2269 | { INDEX_op_ld16u_i32, { "r", "r" } }, | |
2270 | { INDEX_op_ld16s_i32, { "r", "r" } }, | |
2271 | { INDEX_op_ld_i32, { "r", "r" } }, | |
2272 | { INDEX_op_st8_i32, { "rZ", "r" } }, | |
2273 | { INDEX_op_st16_i32, { "rZ", "r" } }, | |
2274 | { INDEX_op_st_i32, { "rZ", "r" } }, | |
2275 | ||
2276 | { INDEX_op_add_i32, { "r", "rI", "rI" } }, | |
2277 | { INDEX_op_sub_i32, { "r", "rI", "rI" } }, | |
2278 | ||
2279 | { INDEX_op_and_i32, { "r", "rI", "rI" } }, | |
2280 | { INDEX_op_andc_i32, { "r", "rI", "rI" } }, | |
2281 | { INDEX_op_eqv_i32, { "r", "rZ", "rZ" } }, | |
2282 | { INDEX_op_nand_i32, { "r", "rZ", "rZ" } }, | |
2283 | { INDEX_op_nor_i32, { "r", "rZ", "rZ" } }, | |
2284 | { INDEX_op_or_i32, { "r", "rI", "rI" } }, | |
2285 | { INDEX_op_orc_i32, { "r", "rZ", "rZ" } }, | |
2286 | { INDEX_op_xor_i32, { "r", "rI", "rI" } }, | |
2287 | ||
2288 | { INDEX_op_mul_i32, { "r", "rZ", "rZ" } }, | |
2289 | ||
2290 | { INDEX_op_sar_i32, { "r", "rZ", "ri" } }, | |
2291 | { INDEX_op_shl_i32, { "r", "rZ", "ri" } }, | |
2292 | { INDEX_op_shr_i32, { "r", "rZ", "ri" } }, | |
2293 | { INDEX_op_rotl_i32, { "r", "rZ", "ri" } }, | |
2294 | { INDEX_op_rotr_i32, { "r", "rZ", "ri" } }, | |
2295 | ||
2296 | { INDEX_op_ext8s_i32, { "r", "rZ"} }, | |
2297 | { INDEX_op_ext8u_i32, { "r", "rZ"} }, | |
2298 | { INDEX_op_ext16s_i32, { "r", "rZ"} }, | |
2299 | { INDEX_op_ext16u_i32, { "r", "rZ"} }, | |
2300 | ||
2301 | { INDEX_op_bswap16_i32, { "r", "rZ" } }, | |
2302 | { INDEX_op_bswap32_i32, { "r", "rZ" } }, | |
2303 | ||
2304 | { INDEX_op_brcond_i32, { "rI", "rI" } }, | |
2305 | { INDEX_op_setcond_i32, { "r", "rZ", "rZ" } }, | |
b90cf716 | 2306 | { INDEX_op_movcond_i32, { "r", "rZ", "rZ", "rI", "rI" } }, |
477ba620 AJ |
2307 | |
2308 | { INDEX_op_mov_i64, { "r", "r" } }, | |
2309 | { INDEX_op_movi_i64, { "r" } }, | |
2310 | ||
2311 | { INDEX_op_ld8u_i64, { "r", "r" } }, | |
2312 | { INDEX_op_ld8s_i64, { "r", "r" } }, | |
2313 | { INDEX_op_ld16u_i64, { "r", "r" } }, | |
2314 | { INDEX_op_ld16s_i64, { "r", "r" } }, | |
2315 | { INDEX_op_ld32u_i64, { "r", "r" } }, | |
2316 | { INDEX_op_ld32s_i64, { "r", "r" } }, | |
2317 | { INDEX_op_ld_i64, { "r", "r" } }, | |
2318 | { INDEX_op_st8_i64, { "rZ", "r" } }, | |
2319 | { INDEX_op_st16_i64, { "rZ", "r" } }, | |
2320 | { INDEX_op_st32_i64, { "rZ", "r" } }, | |
2321 | { INDEX_op_st_i64, { "rZ", "r" } }, | |
2322 | ||
2323 | { INDEX_op_add_i64, { "r", "rI", "rI" } }, | |
2324 | { INDEX_op_sub_i64, { "r", "rI", "rI" } }, | |
2325 | ||
2326 | { INDEX_op_and_i64, { "r", "rI", "rI" } }, | |
2327 | { INDEX_op_andc_i64, { "r", "rI", "rI" } }, | |
2328 | { INDEX_op_eqv_i64, { "r", "rZ", "rZ" } }, | |
2329 | { INDEX_op_nand_i64, { "r", "rZ", "rZ" } }, | |
2330 | { INDEX_op_nor_i64, { "r", "rZ", "rZ" } }, | |
2331 | { INDEX_op_or_i64, { "r", "rI", "rI" } }, | |
2332 | { INDEX_op_orc_i64, { "r", "rZ", "rZ" } }, | |
2333 | { INDEX_op_xor_i64, { "r", "rI", "rI" } }, | |
2334 | ||
2335 | { INDEX_op_mul_i64, { "r", "rZ", "rZ" } }, | |
2336 | ||
2337 | { INDEX_op_sar_i64, { "r", "rZ", "ri" } }, | |
2338 | { INDEX_op_shl_i64, { "r", "rZ", "ri" } }, | |
2339 | { INDEX_op_shr_i64, { "r", "rZ", "ri" } }, | |
2340 | { INDEX_op_rotl_i64, { "r", "rZ", "ri" } }, | |
2341 | { INDEX_op_rotr_i64, { "r", "rZ", "ri" } }, | |
2342 | ||
2343 | { INDEX_op_ext8s_i64, { "r", "rZ"} }, | |
2344 | { INDEX_op_ext8u_i64, { "r", "rZ"} }, | |
2345 | { INDEX_op_ext16s_i64, { "r", "rZ"} }, | |
2346 | { INDEX_op_ext16u_i64, { "r", "rZ"} }, | |
2347 | { INDEX_op_ext32s_i64, { "r", "rZ"} }, | |
2348 | { INDEX_op_ext32u_i64, { "r", "rZ"} }, | |
2349 | ||
2350 | { INDEX_op_bswap16_i64, { "r", "rZ" } }, | |
2351 | { INDEX_op_bswap32_i64, { "r", "rZ" } }, | |
2352 | { INDEX_op_bswap64_i64, { "r", "rZ" } }, | |
2353 | ||
2354 | { INDEX_op_brcond_i64, { "rI", "rI" } }, | |
2355 | { INDEX_op_setcond_i64, { "r", "rZ", "rZ" } }, | |
b90cf716 | 2356 | { INDEX_op_movcond_i64, { "r", "rZ", "rZ", "rI", "rI" } }, |
477ba620 | 2357 | |
c7d4475a RH |
2358 | { INDEX_op_deposit_i32, { "r", "rZ", "ri" } }, |
2359 | { INDEX_op_deposit_i64, { "r", "rZ", "ri" } }, | |
2360 | ||
477ba620 AJ |
2361 | { INDEX_op_qemu_ld8u, { "r", "r" } }, |
2362 | { INDEX_op_qemu_ld8s, { "r", "r" } }, | |
2363 | { INDEX_op_qemu_ld16u, { "r", "r" } }, | |
2364 | { INDEX_op_qemu_ld16s, { "r", "r" } }, | |
2365 | { INDEX_op_qemu_ld32, { "r", "r" } }, | |
2366 | { INDEX_op_qemu_ld32u, { "r", "r" } }, | |
2367 | { INDEX_op_qemu_ld32s, { "r", "r" } }, | |
2368 | { INDEX_op_qemu_ld64, { "r", "r" } }, | |
2369 | ||
2370 | { INDEX_op_qemu_st8, { "SZ", "r" } }, | |
2371 | { INDEX_op_qemu_st16, { "SZ", "r" } }, | |
2372 | { INDEX_op_qemu_st32, { "SZ", "r" } }, | |
2373 | { INDEX_op_qemu_st64, { "SZ", "r" } }, | |
2374 | ||
2375 | { -1 }, | |
2376 | }; | |
2377 | ||
2378 | /* Generate global QEMU prologue and epilogue code */ | |
e4d58b41 | 2379 | static void tcg_target_qemu_prologue(TCGContext *s) |
477ba620 AJ |
2380 | { |
2381 | int frame_size; | |
2382 | ||
2383 | /* reserve some stack space */ | |
da897bf5 BS |
2384 | frame_size = TCG_STATIC_CALL_ARGS_SIZE + |
2385 | CPU_TEMP_BUF_NLONGS * sizeof(long); | |
477ba620 AJ |
2386 | frame_size = (frame_size + TCG_TARGET_STACK_ALIGN - 1) & |
2387 | ~(TCG_TARGET_STACK_ALIGN - 1); | |
da897bf5 BS |
2388 | tcg_set_frame(s, TCG_REG_CALL_STACK, TCG_STATIC_CALL_ARGS_SIZE, |
2389 | CPU_TEMP_BUF_NLONGS * sizeof(long)); | |
477ba620 AJ |
2390 | |
2391 | /* First emit adhoc function descriptor */ | |
2392 | *(uint64_t *)(s->code_ptr) = (uint64_t)s->code_ptr + 16; /* entry point */ | |
2393 | s->code_ptr += 16; /* skip GP */ | |
2394 | ||
2395 | /* prologue */ | |
18d445b4 | 2396 | tcg_out_bundle(s, miI, |
477ba620 | 2397 | tcg_opc_m34(TCG_REG_P0, OPC_ALLOC_M34, |
18d445b4 AJ |
2398 | TCG_REG_R34, 32, 24, 0), |
2399 | tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4, | |
2400 | TCG_AREG0, 0, TCG_REG_R32), | |
477ba620 | 2401 | tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21, |
18d445b4 | 2402 | TCG_REG_B6, TCG_REG_R33, 0)); |
6781d08d RH |
2403 | |
2404 | /* ??? If GUEST_BASE < 0x200000, we could load the register via | |
2405 | an ADDL in the M slot of the next bundle. */ | |
2406 | if (GUEST_BASE != 0) { | |
2407 | tcg_out_bundle(s, mlx, | |
5f7b1687 | 2408 | INSN_NOP_M, |
6781d08d RH |
2409 | tcg_opc_l2 (GUEST_BASE), |
2410 | tcg_opc_x2 (TCG_REG_P0, OPC_MOVL_X2, | |
2411 | TCG_GUEST_BASE_REG, GUEST_BASE)); | |
2412 | tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG); | |
2413 | } | |
2414 | ||
477ba620 | 2415 | tcg_out_bundle(s, miB, |
477ba620 AJ |
2416 | tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4, |
2417 | TCG_REG_R12, -frame_size, TCG_REG_R12), | |
18d445b4 AJ |
2418 | tcg_opc_i22(TCG_REG_P0, OPC_MOV_I22, |
2419 | TCG_REG_R32, TCG_REG_B0), | |
477ba620 AJ |
2420 | tcg_opc_b4 (TCG_REG_P0, OPC_BR_SPTK_MANY_B4, TCG_REG_B6)); |
2421 | ||
2422 | /* epilogue */ | |
2423 | tb_ret_addr = s->code_ptr; | |
2424 | tcg_out_bundle(s, miI, | |
5f7b1687 | 2425 | INSN_NOP_M, |
477ba620 AJ |
2426 | tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21, |
2427 | TCG_REG_B0, TCG_REG_R32, 0), | |
2428 | tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4, | |
2429 | TCG_REG_R12, frame_size, TCG_REG_R12)); | |
2430 | tcg_out_bundle(s, miB, | |
5f7b1687 | 2431 | INSN_NOP_M, |
477ba620 | 2432 | tcg_opc_i26(TCG_REG_P0, OPC_MOV_I_I26, |
18d445b4 | 2433 | TCG_REG_PFS, TCG_REG_R34), |
477ba620 AJ |
2434 | tcg_opc_b4 (TCG_REG_P0, OPC_BR_RET_SPTK_MANY_B4, |
2435 | TCG_REG_B0)); | |
2436 | } | |
2437 | ||
e4d58b41 | 2438 | static void tcg_target_init(TCGContext *s) |
477ba620 AJ |
2439 | { |
2440 | tcg_regset_set(tcg_target_available_regs[TCG_TYPE_I32], | |
2441 | 0xffffffffffffffffull); | |
2442 | tcg_regset_set(tcg_target_available_regs[TCG_TYPE_I64], | |
2443 | 0xffffffffffffffffull); | |
477ba620 | 2444 | |
7221f058 RH |
2445 | tcg_regset_clear(tcg_target_call_clobber_regs); |
2446 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R8); | |
2447 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R9); | |
2448 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R10); | |
2449 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R11); | |
2450 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R14); | |
2451 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R15); | |
2452 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R16); | |
2453 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R17); | |
2454 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R18); | |
2455 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R19); | |
2456 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R20); | |
2457 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R21); | |
2458 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R22); | |
2459 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R23); | |
2460 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R24); | |
2461 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R25); | |
2462 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R26); | |
2463 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R27); | |
2464 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R28); | |
2465 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R29); | |
2466 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R30); | |
2467 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R31); | |
2468 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R56); | |
2469 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R57); | |
2470 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R58); | |
2471 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R59); | |
2472 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R60); | |
2473 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R61); | |
2474 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R62); | |
2475 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R63); | |
2476 | ||
2477 | tcg_regset_clear(s->reserved_regs); | |
477ba620 AJ |
2478 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R0); /* zero register */ |
2479 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R1); /* global pointer */ | |
2480 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R2); /* internal use */ | |
2481 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R3); /* internal use */ | |
2482 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R12); /* stack pointer */ | |
7221f058 | 2483 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R13); /* thread pointer */ |
477ba620 | 2484 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R32); /* return address */ |
18d445b4 | 2485 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R34); /* PFS */ |
477ba620 | 2486 | |
7221f058 RH |
2487 | /* The following 3 are not in use, are call-saved, but *not* saved |
2488 | by the prologue. Therefore we cannot use them without modifying | |
2489 | the prologue. There doesn't seem to be any good reason to use | |
2490 | these as opposed to the windowed registers. */ | |
2491 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R4); | |
2492 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R5); | |
2493 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R6); | |
2494 | ||
477ba620 AJ |
2495 | tcg_add_target_add_op_defs(ia64_op_defs); |
2496 | } |