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