]> git.proxmox.com Git - qemu.git/blame - tcg/tcg-op.h
Fix ARM conditional branch bug.
[qemu.git] / tcg / tcg-op.h
CommitLineData
c896fe29
FB
1/*
2 * Tiny Code Generator for QEMU
3 *
4 * Copyright (c) 2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24#include "tcg.h"
25
bf6247fb 26#ifdef CONFIG_DYNGEN_OP
c896fe29
FB
27/* legacy dyngen operations */
28#include "gen-op.h"
cf2be984 29#endif
c896fe29
FB
30
31int gen_new_label(void);
32
ac56dd48 33static inline void tcg_gen_op1(int opc, TCGv arg1)
c896fe29
FB
34{
35 *gen_opc_ptr++ = opc;
ac56dd48 36 *gen_opparam_ptr++ = GET_TCGV(arg1);
c896fe29
FB
37}
38
ac56dd48 39static inline void tcg_gen_op1i(int opc, TCGArg arg1)
c896fe29
FB
40{
41 *gen_opc_ptr++ = opc;
42 *gen_opparam_ptr++ = arg1;
c896fe29
FB
43}
44
ac56dd48 45static inline void tcg_gen_op2(int opc, TCGv arg1, TCGv arg2)
c896fe29
FB
46{
47 *gen_opc_ptr++ = opc;
ac56dd48
PB
48 *gen_opparam_ptr++ = GET_TCGV(arg1);
49 *gen_opparam_ptr++ = GET_TCGV(arg2);
c896fe29
FB
50}
51
ac56dd48 52static inline void tcg_gen_op2i(int opc, TCGv arg1, TCGArg arg2)
c896fe29
FB
53{
54 *gen_opc_ptr++ = opc;
ac56dd48 55 *gen_opparam_ptr++ = GET_TCGV(arg1);
c896fe29 56 *gen_opparam_ptr++ = arg2;
ac56dd48
PB
57}
58
59static inline void tcg_gen_op3(int opc, TCGv arg1, TCGv arg2, TCGv arg3)
60{
61 *gen_opc_ptr++ = opc;
62 *gen_opparam_ptr++ = GET_TCGV(arg1);
63 *gen_opparam_ptr++ = GET_TCGV(arg2);
64 *gen_opparam_ptr++ = GET_TCGV(arg3);
65}
66
67static inline void tcg_gen_op3i(int opc, TCGv arg1, TCGv arg2, TCGArg arg3)
68{
69 *gen_opc_ptr++ = opc;
70 *gen_opparam_ptr++ = GET_TCGV(arg1);
71 *gen_opparam_ptr++ = GET_TCGV(arg2);
c896fe29 72 *gen_opparam_ptr++ = arg3;
ac56dd48
PB
73}
74
75static inline void tcg_gen_op4(int opc, TCGv arg1, TCGv arg2, TCGv arg3,
76 TCGv arg4)
77{
78 *gen_opc_ptr++ = opc;
79 *gen_opparam_ptr++ = GET_TCGV(arg1);
80 *gen_opparam_ptr++ = GET_TCGV(arg2);
81 *gen_opparam_ptr++ = GET_TCGV(arg3);
82 *gen_opparam_ptr++ = GET_TCGV(arg4);
83}
84
85static inline void tcg_gen_op4i(int opc, TCGv arg1, TCGv arg2, TCGv arg3,
86 TCGArg arg4)
87{
88 *gen_opc_ptr++ = opc;
89 *gen_opparam_ptr++ = GET_TCGV(arg1);
90 *gen_opparam_ptr++ = GET_TCGV(arg2);
91 *gen_opparam_ptr++ = GET_TCGV(arg3);
c896fe29
FB
92 *gen_opparam_ptr++ = arg4;
93}
94
ac56dd48
PB
95static inline void tcg_gen_op4ii(int opc, TCGv arg1, TCGv arg2, TCGArg arg3,
96 TCGArg arg4)
c896fe29
FB
97{
98 *gen_opc_ptr++ = opc;
ac56dd48
PB
99 *gen_opparam_ptr++ = GET_TCGV(arg1);
100 *gen_opparam_ptr++ = GET_TCGV(arg2);
c896fe29
FB
101 *gen_opparam_ptr++ = arg3;
102 *gen_opparam_ptr++ = arg4;
ac56dd48
PB
103}
104
105static inline void tcg_gen_op5(int opc, TCGv arg1, TCGv arg2,
106 TCGv arg3, TCGv arg4,
107 TCGv arg5)
108{
109 *gen_opc_ptr++ = opc;
110 *gen_opparam_ptr++ = GET_TCGV(arg1);
111 *gen_opparam_ptr++ = GET_TCGV(arg2);
112 *gen_opparam_ptr++ = GET_TCGV(arg3);
113 *gen_opparam_ptr++ = GET_TCGV(arg4);
114 *gen_opparam_ptr++ = GET_TCGV(arg5);
115}
116
117static inline void tcg_gen_op5i(int opc, TCGv arg1, TCGv arg2,
118 TCGv arg3, TCGv arg4,
119 TCGArg arg5)
120{
121 *gen_opc_ptr++ = opc;
122 *gen_opparam_ptr++ = GET_TCGV(arg1);
123 *gen_opparam_ptr++ = GET_TCGV(arg2);
124 *gen_opparam_ptr++ = GET_TCGV(arg3);
125 *gen_opparam_ptr++ = GET_TCGV(arg4);
c896fe29
FB
126 *gen_opparam_ptr++ = arg5;
127}
128
ac56dd48
PB
129static inline void tcg_gen_op6(int opc, TCGv arg1, TCGv arg2,
130 TCGv arg3, TCGv arg4,
131 TCGv arg5, TCGv arg6)
c896fe29
FB
132{
133 *gen_opc_ptr++ = opc;
ac56dd48
PB
134 *gen_opparam_ptr++ = GET_TCGV(arg1);
135 *gen_opparam_ptr++ = GET_TCGV(arg2);
136 *gen_opparam_ptr++ = GET_TCGV(arg3);
137 *gen_opparam_ptr++ = GET_TCGV(arg4);
138 *gen_opparam_ptr++ = GET_TCGV(arg5);
139 *gen_opparam_ptr++ = GET_TCGV(arg6);
140}
141
142static inline void tcg_gen_op6ii(int opc, TCGv arg1, TCGv arg2,
143 TCGv arg3, TCGv arg4,
144 TCGArg arg5, TCGArg arg6)
145{
146 *gen_opc_ptr++ = opc;
147 *gen_opparam_ptr++ = GET_TCGV(arg1);
148 *gen_opparam_ptr++ = GET_TCGV(arg2);
149 *gen_opparam_ptr++ = GET_TCGV(arg3);
150 *gen_opparam_ptr++ = GET_TCGV(arg4);
c896fe29
FB
151 *gen_opparam_ptr++ = arg5;
152 *gen_opparam_ptr++ = arg6;
153}
154
155static inline void gen_set_label(int n)
156{
ac56dd48 157 tcg_gen_op1i(INDEX_op_set_label, n);
c896fe29
FB
158}
159
fb50d413
BS
160static inline void tcg_gen_br(int label)
161{
162 tcg_gen_op1i(INDEX_op_br, label);
163}
164
ac56dd48 165static inline void tcg_gen_mov_i32(TCGv ret, TCGv arg)
c896fe29 166{
98156423 167 if (GET_TCGV(ret) != GET_TCGV(arg))
4d07272d 168 tcg_gen_op2(INDEX_op_mov_i32, ret, arg);
c896fe29
FB
169}
170
ac56dd48 171static inline void tcg_gen_movi_i32(TCGv ret, int32_t arg)
c896fe29 172{
ac56dd48 173 tcg_gen_op2i(INDEX_op_movi_i32, ret, arg);
c896fe29
FB
174}
175
176/* helper calls */
177#define TCG_HELPER_CALL_FLAGS 0
178
179static inline void tcg_gen_helper_0_0(void *func)
180{
e8996ee0
FB
181 TCGv t0;
182 t0 = tcg_const_ptr((tcg_target_long)func);
c896fe29 183 tcg_gen_call(&tcg_ctx,
e8996ee0 184 t0, TCG_HELPER_CALL_FLAGS,
c896fe29 185 0, NULL, 0, NULL);
e8996ee0 186 tcg_temp_free(t0);
c896fe29
FB
187}
188
ac56dd48 189static inline void tcg_gen_helper_0_1(void *func, TCGv arg)
c896fe29 190{
e8996ee0
FB
191 TCGv t0;
192 t0 = tcg_const_ptr((tcg_target_long)func);
c896fe29 193 tcg_gen_call(&tcg_ctx,
e8996ee0 194 t0, TCG_HELPER_CALL_FLAGS,
c896fe29 195 0, NULL, 1, &arg);
e8996ee0 196 tcg_temp_free(t0);
c896fe29
FB
197}
198
ac56dd48 199static inline void tcg_gen_helper_0_2(void *func, TCGv arg1, TCGv arg2)
c896fe29 200{
ac56dd48 201 TCGv args[2];
e8996ee0 202 TCGv t0;
c896fe29
FB
203 args[0] = arg1;
204 args[1] = arg2;
e8996ee0 205 t0 = tcg_const_ptr((tcg_target_long)func);
c896fe29 206 tcg_gen_call(&tcg_ctx,
e8996ee0 207 t0, TCG_HELPER_CALL_FLAGS,
c896fe29 208 0, NULL, 2, args);
e8996ee0 209 tcg_temp_free(t0);
c896fe29
FB
210}
211
b0109805
PB
212static inline void tcg_gen_helper_0_3(void *func,
213 TCGv arg1, TCGv arg2, TCGv arg3)
214{
215 TCGv args[3];
e8996ee0 216 TCGv t0;
b0109805
PB
217 args[0] = arg1;
218 args[1] = arg2;
219 args[2] = arg3;
e8996ee0 220 t0 = tcg_const_ptr((tcg_target_long)func);
b0109805 221 tcg_gen_call(&tcg_ctx,
e8996ee0 222 t0, TCG_HELPER_CALL_FLAGS,
b0109805 223 0, NULL, 3, args);
e8996ee0 224 tcg_temp_free(t0);
b0109805
PB
225}
226
f8422f52
BS
227static inline void tcg_gen_helper_0_4(void *func, TCGv arg1, TCGv arg2,
228 TCGv arg3, TCGv arg4)
229{
230 TCGv args[4];
e8996ee0 231 TCGv t0;
f8422f52
BS
232 args[0] = arg1;
233 args[1] = arg2;
234 args[2] = arg3;
235 args[3] = arg4;
e8996ee0 236 t0 = tcg_const_ptr((tcg_target_long)func);
f8422f52 237 tcg_gen_call(&tcg_ctx,
e8996ee0 238 t0, TCG_HELPER_CALL_FLAGS,
f8422f52 239 0, NULL, 4, args);
e8996ee0 240 tcg_temp_free(t0);
f8422f52
BS
241}
242
243static inline void tcg_gen_helper_1_0(void *func, TCGv ret)
244{
e8996ee0
FB
245 TCGv t0;
246 t0 = tcg_const_ptr((tcg_target_long)func);
f8422f52 247 tcg_gen_call(&tcg_ctx,
e8996ee0 248 t0, TCG_HELPER_CALL_FLAGS,
f8422f52 249 1, &ret, 0, NULL);
e8996ee0 250 tcg_temp_free(t0);
f8422f52
BS
251}
252
253static inline void tcg_gen_helper_1_1(void *func, TCGv ret, TCGv arg1)
254{
e8996ee0
FB
255 TCGv t0;
256 t0 = tcg_const_ptr((tcg_target_long)func);
f8422f52 257 tcg_gen_call(&tcg_ctx,
e8996ee0 258 t0, TCG_HELPER_CALL_FLAGS,
f8422f52 259 1, &ret, 1, &arg1);
e8996ee0 260 tcg_temp_free(t0);
f8422f52
BS
261}
262
ac56dd48
PB
263static inline void tcg_gen_helper_1_2(void *func, TCGv ret,
264 TCGv arg1, TCGv arg2)
c896fe29 265{
ac56dd48 266 TCGv args[2];
e8996ee0 267 TCGv t0;
c896fe29
FB
268 args[0] = arg1;
269 args[1] = arg2;
e8996ee0 270 t0 = tcg_const_ptr((tcg_target_long)func);
c896fe29 271 tcg_gen_call(&tcg_ctx,
e8996ee0 272 t0, TCG_HELPER_CALL_FLAGS,
c896fe29 273 1, &ret, 2, args);
e8996ee0 274 tcg_temp_free(t0);
c896fe29
FB
275}
276
6ddbc6e4
PB
277static inline void tcg_gen_helper_1_3(void *func, TCGv ret,
278 TCGv arg1, TCGv arg2, TCGv arg3)
279{
280 TCGv args[3];
e8996ee0 281 TCGv t0;
6ddbc6e4
PB
282 args[0] = arg1;
283 args[1] = arg2;
284 args[2] = arg3;
e8996ee0 285 t0 = tcg_const_ptr((tcg_target_long)func);
6ddbc6e4 286 tcg_gen_call(&tcg_ctx,
e8996ee0 287 t0, TCG_HELPER_CALL_FLAGS,
6ddbc6e4 288 1, &ret, 3, args);
e8996ee0 289 tcg_temp_free(t0);
6ddbc6e4
PB
290}
291
f8422f52
BS
292static inline void tcg_gen_helper_1_4(void *func, TCGv ret,
293 TCGv arg1, TCGv arg2, TCGv arg3,
294 TCGv arg4)
295{
296 TCGv args[4];
e8996ee0 297 TCGv t0;
f8422f52
BS
298 args[0] = arg1;
299 args[1] = arg2;
300 args[2] = arg3;
301 args[3] = arg4;
e8996ee0 302 t0 = tcg_const_ptr((tcg_target_long)func);
f8422f52 303 tcg_gen_call(&tcg_ctx,
e8996ee0 304 t0, TCG_HELPER_CALL_FLAGS,
f8422f52 305 1, &ret, 4, args);
e8996ee0 306 tcg_temp_free(t0);
f8422f52
BS
307}
308
c896fe29
FB
309/* 32 bit ops */
310
ac56dd48 311static inline void tcg_gen_ld8u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 312{
ac56dd48 313 tcg_gen_op3i(INDEX_op_ld8u_i32, ret, arg2, offset);
c896fe29
FB
314}
315
ac56dd48 316static inline void tcg_gen_ld8s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 317{
ac56dd48 318 tcg_gen_op3i(INDEX_op_ld8s_i32, ret, arg2, offset);
c896fe29
FB
319}
320
ac56dd48 321static inline void tcg_gen_ld16u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 322{
ac56dd48 323 tcg_gen_op3i(INDEX_op_ld16u_i32, ret, arg2, offset);
c896fe29
FB
324}
325
ac56dd48 326static inline void tcg_gen_ld16s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 327{
ac56dd48 328 tcg_gen_op3i(INDEX_op_ld16s_i32, ret, arg2, offset);
c896fe29
FB
329}
330
ac56dd48 331static inline void tcg_gen_ld_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 332{
ac56dd48 333 tcg_gen_op3i(INDEX_op_ld_i32, ret, arg2, offset);
c896fe29
FB
334}
335
ac56dd48 336static inline void tcg_gen_st8_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29 337{
ac56dd48 338 tcg_gen_op3i(INDEX_op_st8_i32, arg1, arg2, offset);
c896fe29
FB
339}
340
ac56dd48 341static inline void tcg_gen_st16_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29 342{
ac56dd48 343 tcg_gen_op3i(INDEX_op_st16_i32, arg1, arg2, offset);
c896fe29
FB
344}
345
ac56dd48 346static inline void tcg_gen_st_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29 347{
ac56dd48 348 tcg_gen_op3i(INDEX_op_st_i32, arg1, arg2, offset);
c896fe29
FB
349}
350
ac56dd48 351static inline void tcg_gen_add_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
352{
353 tcg_gen_op3(INDEX_op_add_i32, ret, arg1, arg2);
354}
355
ac56dd48 356static inline void tcg_gen_addi_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29 357{
7089442c
BS
358 /* some cases can be optimized here */
359 if (arg2 == 0) {
360 tcg_gen_mov_i32(ret, arg1);
361 } else {
e8996ee0
FB
362 TCGv t0 = tcg_const_i32(arg2);
363 tcg_gen_add_i32(ret, arg1, t0);
364 tcg_temp_free(t0);
7089442c 365 }
c896fe29
FB
366}
367
ac56dd48 368static inline void tcg_gen_sub_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
369{
370 tcg_gen_op3(INDEX_op_sub_i32, ret, arg1, arg2);
371}
372
ac56dd48 373static inline void tcg_gen_subi_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29 374{
7089442c
BS
375 /* some cases can be optimized here */
376 if (arg2 == 0) {
377 tcg_gen_mov_i32(ret, arg1);
378 } else {
e8996ee0
FB
379 TCGv t0 = tcg_const_i32(arg2);
380 tcg_gen_sub_i32(ret, arg1, t0);
381 tcg_temp_free(t0);
7089442c 382 }
c896fe29
FB
383}
384
ac56dd48 385static inline void tcg_gen_and_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
386{
387 tcg_gen_op3(INDEX_op_and_i32, ret, arg1, arg2);
388}
389
ac56dd48 390static inline void tcg_gen_andi_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
391{
392 /* some cases can be optimized here */
393 if (arg2 == 0) {
394 tcg_gen_movi_i32(ret, 0);
395 } else if (arg2 == 0xffffffff) {
396 tcg_gen_mov_i32(ret, arg1);
397 } else {
e8996ee0
FB
398 TCGv t0 = tcg_const_i32(arg2);
399 tcg_gen_and_i32(ret, arg1, t0);
400 tcg_temp_free(t0);
c896fe29
FB
401 }
402}
403
ac56dd48 404static inline void tcg_gen_or_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
405{
406 tcg_gen_op3(INDEX_op_or_i32, ret, arg1, arg2);
407}
408
ac56dd48 409static inline void tcg_gen_ori_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
410{
411 /* some cases can be optimized here */
412 if (arg2 == 0xffffffff) {
7089442c 413 tcg_gen_movi_i32(ret, 0xffffffff);
c896fe29
FB
414 } else if (arg2 == 0) {
415 tcg_gen_mov_i32(ret, arg1);
416 } else {
e8996ee0
FB
417 TCGv t0 = tcg_const_i32(arg2);
418 tcg_gen_or_i32(ret, arg1, t0);
419 tcg_temp_free(t0);
c896fe29
FB
420 }
421}
422
ac56dd48 423static inline void tcg_gen_xor_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
424{
425 tcg_gen_op3(INDEX_op_xor_i32, ret, arg1, arg2);
426}
427
ac56dd48 428static inline void tcg_gen_xori_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
429{
430 /* some cases can be optimized here */
431 if (arg2 == 0) {
432 tcg_gen_mov_i32(ret, arg1);
433 } else {
e8996ee0
FB
434 TCGv t0 = tcg_const_i32(arg2);
435 tcg_gen_xor_i32(ret, arg1, t0);
436 tcg_temp_free(t0);
c896fe29
FB
437 }
438}
439
ac56dd48 440static inline void tcg_gen_shl_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
441{
442 tcg_gen_op3(INDEX_op_shl_i32, ret, arg1, arg2);
443}
444
ac56dd48 445static inline void tcg_gen_shli_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29 446{
34151a20
FB
447 if (arg2 == 0) {
448 tcg_gen_mov_i32(ret, arg1);
449 } else {
e8996ee0
FB
450 TCGv t0 = tcg_const_i32(arg2);
451 tcg_gen_shl_i32(ret, arg1, t0);
452 tcg_temp_free(t0);
34151a20 453 }
c896fe29
FB
454}
455
ac56dd48 456static inline void tcg_gen_shr_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
457{
458 tcg_gen_op3(INDEX_op_shr_i32, ret, arg1, arg2);
459}
460
ac56dd48 461static inline void tcg_gen_shri_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29 462{
34151a20
FB
463 if (arg2 == 0) {
464 tcg_gen_mov_i32(ret, arg1);
465 } else {
e8996ee0
FB
466 TCGv t0 = tcg_const_i32(arg2);
467 tcg_gen_shr_i32(ret, arg1, t0);
468 tcg_temp_free(t0);
34151a20 469 }
c896fe29
FB
470}
471
ac56dd48 472static inline void tcg_gen_sar_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
473{
474 tcg_gen_op3(INDEX_op_sar_i32, ret, arg1, arg2);
475}
476
ac56dd48 477static inline void tcg_gen_sari_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29 478{
34151a20
FB
479 if (arg2 == 0) {
480 tcg_gen_mov_i32(ret, arg1);
481 } else {
e8996ee0
FB
482 TCGv t0 = tcg_const_i32(arg2);
483 tcg_gen_sar_i32(ret, arg1, t0);
484 tcg_temp_free(t0);
34151a20 485 }
c896fe29
FB
486}
487
ac56dd48 488static inline void tcg_gen_brcond_i32(int cond, TCGv arg1, TCGv arg2,
c896fe29
FB
489 int label_index)
490{
ac56dd48 491 tcg_gen_op4ii(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
c896fe29
FB
492}
493
cb63669a
PB
494static inline void tcg_gen_brcondi_i32(int cond, TCGv arg1, int32_t arg2,
495 int label_index)
496{
497 TCGv t0 = tcg_const_i32(arg2);
498 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
499 tcg_temp_free(t0);
500}
501
ac56dd48 502static inline void tcg_gen_mul_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
503{
504 tcg_gen_op3(INDEX_op_mul_i32, ret, arg1, arg2);
505}
506
f730fd27
TS
507static inline void tcg_gen_muli_i32(TCGv ret, TCGv arg1, int32_t arg2)
508{
e8996ee0
FB
509 TCGv t0 = tcg_const_i32(arg2);
510 tcg_gen_mul_i32(ret, arg1, t0);
511 tcg_temp_free(t0);
f730fd27
TS
512}
513
c896fe29 514#ifdef TCG_TARGET_HAS_div_i32
ac56dd48 515static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
516{
517 tcg_gen_op3(INDEX_op_div_i32, ret, arg1, arg2);
518}
519
ac56dd48 520static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
521{
522 tcg_gen_op3(INDEX_op_rem_i32, ret, arg1, arg2);
523}
524
ac56dd48 525static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
526{
527 tcg_gen_op3(INDEX_op_divu_i32, ret, arg1, arg2);
528}
529
ac56dd48 530static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
531{
532 tcg_gen_op3(INDEX_op_remu_i32, ret, arg1, arg2);
533}
534#else
ac56dd48 535static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 536{
ac56dd48 537 TCGv t0;
c896fe29
FB
538 t0 = tcg_temp_new(TCG_TYPE_I32);
539 tcg_gen_sari_i32(t0, arg1, 31);
540 tcg_gen_op5(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
e8996ee0 541 tcg_temp_free(t0);
c896fe29
FB
542}
543
ac56dd48 544static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 545{
ac56dd48 546 TCGv t0;
c896fe29
FB
547 t0 = tcg_temp_new(TCG_TYPE_I32);
548 tcg_gen_sari_i32(t0, arg1, 31);
549 tcg_gen_op5(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
e8996ee0 550 tcg_temp_free(t0);
c896fe29
FB
551}
552
ac56dd48 553static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 554{
ac56dd48 555 TCGv t0;
c896fe29
FB
556 t0 = tcg_temp_new(TCG_TYPE_I32);
557 tcg_gen_movi_i32(t0, 0);
558 tcg_gen_op5(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
e8996ee0 559 tcg_temp_free(t0);
c896fe29
FB
560}
561
ac56dd48 562static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 563{
ac56dd48 564 TCGv t0;
c896fe29
FB
565 t0 = tcg_temp_new(TCG_TYPE_I32);
566 tcg_gen_movi_i32(t0, 0);
567 tcg_gen_op5(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
e8996ee0 568 tcg_temp_free(t0);
c896fe29
FB
569}
570#endif
571
572#if TCG_TARGET_REG_BITS == 32
573
ac56dd48 574static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
c896fe29 575{
98156423 576 if (GET_TCGV(ret) != GET_TCGV(arg)) {
4d07272d
BS
577 tcg_gen_mov_i32(ret, arg);
578 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
579 }
c896fe29
FB
580}
581
ac56dd48 582static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
c896fe29
FB
583{
584 tcg_gen_movi_i32(ret, arg);
ac56dd48 585 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
c896fe29
FB
586}
587
ac56dd48 588static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
589{
590 tcg_gen_ld8u_i32(ret, arg2, offset);
ac56dd48 591 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
592}
593
ac56dd48 594static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
595{
596 tcg_gen_ld8s_i32(ret, arg2, offset);
ac56dd48 597 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
598}
599
ac56dd48 600static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
601{
602 tcg_gen_ld16u_i32(ret, arg2, offset);
ac56dd48 603 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
604}
605
ac56dd48 606static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
607{
608 tcg_gen_ld16s_i32(ret, arg2, offset);
ac56dd48 609 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
610}
611
ac56dd48 612static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
613{
614 tcg_gen_ld_i32(ret, arg2, offset);
ac56dd48 615 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
616}
617
ac56dd48 618static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
619{
620 tcg_gen_ld_i32(ret, arg2, offset);
ac56dd48 621 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
622}
623
ac56dd48 624static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
625{
626 /* since arg2 and ret have different types, they cannot be the
627 same temporary */
628#ifdef TCG_TARGET_WORDS_BIGENDIAN
ac56dd48 629 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
c896fe29
FB
630 tcg_gen_ld_i32(ret, arg2, offset + 4);
631#else
632 tcg_gen_ld_i32(ret, arg2, offset);
ac56dd48 633 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
c896fe29
FB
634#endif
635}
636
ac56dd48 637static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29
FB
638{
639 tcg_gen_st8_i32(arg1, arg2, offset);
640}
641
ac56dd48 642static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29
FB
643{
644 tcg_gen_st16_i32(arg1, arg2, offset);
645}
646
ac56dd48 647static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29
FB
648{
649 tcg_gen_st_i32(arg1, arg2, offset);
650}
651
ac56dd48 652static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29
FB
653{
654#ifdef TCG_TARGET_WORDS_BIGENDIAN
ac56dd48 655 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
c896fe29
FB
656 tcg_gen_st_i32(arg1, arg2, offset + 4);
657#else
658 tcg_gen_st_i32(arg1, arg2, offset);
ac56dd48 659 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
c896fe29
FB
660#endif
661}
662
ac56dd48 663static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 664{
ac56dd48
PB
665 tcg_gen_op6(INDEX_op_add2_i32, ret, TCGV_HIGH(ret),
666 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
c896fe29
FB
667}
668
ac56dd48 669static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 670{
e8996ee0
FB
671 TCGv t0 = tcg_const_i64(arg2);
672 tcg_gen_add_i64(ret, arg1, t0);
673 tcg_temp_free(t0);
c896fe29
FB
674}
675
ac56dd48 676static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 677{
ac56dd48
PB
678 tcg_gen_op6(INDEX_op_sub2_i32, ret, TCGV_HIGH(ret),
679 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
c896fe29
FB
680}
681
ac56dd48 682static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 683{
e8996ee0
FB
684 TCGv t0 = tcg_const_i64(arg2);
685 tcg_gen_sub_i64(ret, arg1, t0);
686 tcg_temp_free(t0);
c896fe29
FB
687}
688
ac56dd48 689static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
690{
691 tcg_gen_and_i32(ret, arg1, arg2);
ac56dd48 692 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
693}
694
ac56dd48 695static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
696{
697 tcg_gen_andi_i32(ret, arg1, arg2);
ac56dd48 698 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
699}
700
ac56dd48 701static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
702{
703 tcg_gen_or_i32(ret, arg1, arg2);
ac56dd48 704 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
705}
706
ac56dd48 707static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
708{
709 tcg_gen_ori_i32(ret, arg1, arg2);
ac56dd48 710 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
711}
712
ac56dd48 713static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
714{
715 tcg_gen_xor_i32(ret, arg1, arg2);
ac56dd48 716 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
717}
718
ac56dd48 719static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
720{
721 tcg_gen_xori_i32(ret, arg1, arg2);
ac56dd48 722 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
723}
724
725/* XXX: use generic code when basic block handling is OK or CPU
726 specific code (x86) */
ac56dd48 727static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
728{
729 tcg_gen_helper_1_2(tcg_helper_shl_i64, ret, arg1, arg2);
730}
731
ac56dd48 732static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
733{
734 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
735}
736
ac56dd48 737static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
738{
739 tcg_gen_helper_1_2(tcg_helper_shr_i64, ret, arg1, arg2);
740}
741
ac56dd48 742static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
743{
744 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
745}
746
ac56dd48 747static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
748{
749 tcg_gen_helper_1_2(tcg_helper_sar_i64, ret, arg1, arg2);
750}
751
ac56dd48 752static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
753{
754 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
755}
756
ac56dd48 757static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2,
c896fe29
FB
758 int label_index)
759{
ac56dd48
PB
760 tcg_gen_op6ii(INDEX_op_brcond2_i32,
761 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2),
762 cond, label_index);
c896fe29
FB
763}
764
ac56dd48 765static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 766{
ac56dd48 767 TCGv t0, t1;
c896fe29
FB
768
769 t0 = tcg_temp_new(TCG_TYPE_I64);
770 t1 = tcg_temp_new(TCG_TYPE_I32);
771
ac56dd48 772 tcg_gen_op4(INDEX_op_mulu2_i32, t0, TCGV_HIGH(t0), arg1, arg2);
c896fe29 773
ac56dd48
PB
774 tcg_gen_mul_i32(t1, arg1, TCGV_HIGH(arg2));
775 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
776 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), arg2);
777 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
c896fe29
FB
778
779 tcg_gen_mov_i64(ret, t0);
e8996ee0
FB
780 tcg_temp_free(t0);
781 tcg_temp_free(t1);
c896fe29
FB
782}
783
f730fd27
TS
784static inline void tcg_gen_muli_i64(TCGv ret, TCGv arg1, int64_t arg2)
785{
e8996ee0
FB
786 TCGv t0 = tcg_const_i64(arg2);
787 tcg_gen_mul_i64(ret, arg1, t0);
788 tcg_temp_free(t0);
f730fd27
TS
789}
790
ac56dd48 791static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
792{
793 tcg_gen_helper_1_2(tcg_helper_div_i64, ret, arg1, arg2);
794}
795
ac56dd48 796static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
797{
798 tcg_gen_helper_1_2(tcg_helper_rem_i64, ret, arg1, arg2);
799}
800
ac56dd48 801static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
802{
803 tcg_gen_helper_1_2(tcg_helper_divu_i64, ret, arg1, arg2);
804}
805
ac56dd48 806static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
807{
808 tcg_gen_helper_1_2(tcg_helper_remu_i64, ret, arg1, arg2);
809}
810
811#else
812
ac56dd48 813static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
c896fe29 814{
98156423 815 if (GET_TCGV(ret) != GET_TCGV(arg))
4d07272d 816 tcg_gen_op2(INDEX_op_mov_i64, ret, arg);
c896fe29
FB
817}
818
ac56dd48 819static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
c896fe29 820{
ac56dd48 821 tcg_gen_op2i(INDEX_op_movi_i64, ret, arg);
c896fe29
FB
822}
823
ac56dd48
PB
824static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2,
825 tcg_target_long offset)
c896fe29 826{
ac56dd48 827 tcg_gen_op3i(INDEX_op_ld8u_i64, ret, arg2, offset);
c896fe29
FB
828}
829
ac56dd48
PB
830static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2,
831 tcg_target_long offset)
c896fe29 832{
ac56dd48 833 tcg_gen_op3i(INDEX_op_ld8s_i64, ret, arg2, offset);
c896fe29
FB
834}
835
ac56dd48
PB
836static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2,
837 tcg_target_long offset)
c896fe29 838{
ac56dd48 839 tcg_gen_op3i(INDEX_op_ld16u_i64, ret, arg2, offset);
c896fe29
FB
840}
841
ac56dd48
PB
842static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2,
843 tcg_target_long offset)
c896fe29 844{
ac56dd48 845 tcg_gen_op3i(INDEX_op_ld16s_i64, ret, arg2, offset);
c896fe29
FB
846}
847
ac56dd48
PB
848static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2,
849 tcg_target_long offset)
c896fe29 850{
ac56dd48 851 tcg_gen_op3i(INDEX_op_ld32u_i64, ret, arg2, offset);
c896fe29
FB
852}
853
ac56dd48
PB
854static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2,
855 tcg_target_long offset)
c896fe29 856{
ac56dd48 857 tcg_gen_op3i(INDEX_op_ld32s_i64, ret, arg2, offset);
c896fe29
FB
858}
859
ac56dd48 860static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 861{
ac56dd48 862 tcg_gen_op3i(INDEX_op_ld_i64, ret, arg2, offset);
c896fe29
FB
863}
864
ac56dd48
PB
865static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2,
866 tcg_target_long offset)
c896fe29 867{
ac56dd48 868 tcg_gen_op3i(INDEX_op_st8_i64, arg1, arg2, offset);
c896fe29
FB
869}
870
ac56dd48
PB
871static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2,
872 tcg_target_long offset)
c896fe29 873{
ac56dd48 874 tcg_gen_op3i(INDEX_op_st16_i64, arg1, arg2, offset);
c896fe29
FB
875}
876
ac56dd48
PB
877static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2,
878 tcg_target_long offset)
c896fe29 879{
ac56dd48 880 tcg_gen_op3i(INDEX_op_st32_i64, arg1, arg2, offset);
c896fe29
FB
881}
882
ac56dd48 883static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29 884{
ac56dd48 885 tcg_gen_op3i(INDEX_op_st_i64, arg1, arg2, offset);
c896fe29
FB
886}
887
ac56dd48 888static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
889{
890 tcg_gen_op3(INDEX_op_add_i64, ret, arg1, arg2);
891}
892
ac56dd48 893static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 894{
e8996ee0
FB
895 TCGv t0 = tcg_const_i64(arg2);
896 tcg_gen_add_i64(ret, arg1, t0);
897 tcg_temp_free(t0);
c896fe29
FB
898}
899
ac56dd48 900static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
901{
902 tcg_gen_op3(INDEX_op_sub_i64, ret, arg1, arg2);
903}
904
ac56dd48 905static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 906{
e8996ee0
FB
907 TCGv t0 = tcg_const_i64(arg2);
908 tcg_gen_sub_i64(ret, arg1, t0);
909 tcg_temp_free(t0);
c896fe29
FB
910}
911
ac56dd48 912static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
913{
914 tcg_gen_op3(INDEX_op_and_i64, ret, arg1, arg2);
915}
916
ac56dd48 917static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 918{
e8996ee0
FB
919 TCGv t0 = tcg_const_i64(arg2);
920 tcg_gen_and_i64(ret, arg1, t0);
921 tcg_temp_free(t0);
c896fe29
FB
922}
923
ac56dd48 924static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
925{
926 tcg_gen_op3(INDEX_op_or_i64, ret, arg1, arg2);
927}
928
ac56dd48 929static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 930{
e8996ee0
FB
931 TCGv t0 = tcg_const_i64(arg2);
932 tcg_gen_or_i64(ret, arg1, t0);
933 tcg_temp_free(t0);
c896fe29
FB
934}
935
ac56dd48 936static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
937{
938 tcg_gen_op3(INDEX_op_xor_i64, ret, arg1, arg2);
939}
940
ac56dd48 941static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 942{
e8996ee0
FB
943 TCGv t0 = tcg_const_i64(arg2);
944 tcg_gen_xor_i64(ret, arg1, t0);
945 tcg_temp_free(t0);
c896fe29
FB
946}
947
ac56dd48 948static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
949{
950 tcg_gen_op3(INDEX_op_shl_i64, ret, arg1, arg2);
951}
952
ac56dd48 953static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 954{
34151a20
FB
955 if (arg2 == 0) {
956 tcg_gen_mov_i64(ret, arg1);
957 } else {
e8996ee0
FB
958 TCGv t0 = tcg_const_i64(arg2);
959 tcg_gen_shl_i64(ret, arg1, t0);
960 tcg_temp_free(t0);
34151a20 961 }
c896fe29
FB
962}
963
ac56dd48 964static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
965{
966 tcg_gen_op3(INDEX_op_shr_i64, ret, arg1, arg2);
967}
968
ac56dd48 969static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 970{
34151a20
FB
971 if (arg2 == 0) {
972 tcg_gen_mov_i64(ret, arg1);
973 } else {
e8996ee0
FB
974 TCGv t0 = tcg_const_i64(arg2);
975 tcg_gen_shr_i64(ret, arg1, t0);
976 tcg_temp_free(t0);
34151a20 977 }
c896fe29
FB
978}
979
ac56dd48 980static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
981{
982 tcg_gen_op3(INDEX_op_sar_i64, ret, arg1, arg2);
983}
984
ac56dd48 985static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29 986{
34151a20
FB
987 if (arg2 == 0) {
988 tcg_gen_mov_i64(ret, arg1);
989 } else {
e8996ee0
FB
990 TCGv t0 = tcg_const_i64(arg2);
991 tcg_gen_sar_i64(ret, arg1, t0);
992 tcg_temp_free(t0);
34151a20 993 }
c896fe29
FB
994}
995
ac56dd48 996static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2,
c896fe29
FB
997 int label_index)
998{
ac56dd48 999 tcg_gen_op4ii(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
c896fe29
FB
1000}
1001
ac56dd48 1002static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
1003{
1004 tcg_gen_op3(INDEX_op_mul_i64, ret, arg1, arg2);
1005}
1006
f730fd27
TS
1007static inline void tcg_gen_muli_i64(TCGv ret, TCGv arg1, int64_t arg2)
1008{
e8996ee0
FB
1009 TCGv t0 = tcg_const_i64(arg2);
1010 tcg_gen_mul_i64(ret, arg1, t0);
1011 tcg_temp_free(t0);
f730fd27
TS
1012}
1013
c896fe29 1014#ifdef TCG_TARGET_HAS_div_i64
ac56dd48 1015static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
1016{
1017 tcg_gen_op3(INDEX_op_div_i64, ret, arg1, arg2);
1018}
1019
ac56dd48 1020static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
1021{
1022 tcg_gen_op3(INDEX_op_rem_i64, ret, arg1, arg2);
1023}
1024
ac56dd48 1025static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
1026{
1027 tcg_gen_op3(INDEX_op_divu_i64, ret, arg1, arg2);
1028}
1029
ac56dd48 1030static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
1031{
1032 tcg_gen_op3(INDEX_op_remu_i64, ret, arg1, arg2);
1033}
1034#else
ac56dd48 1035static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 1036{
ac56dd48 1037 TCGv t0;
c896fe29
FB
1038 t0 = tcg_temp_new(TCG_TYPE_I64);
1039 tcg_gen_sari_i64(t0, arg1, 63);
1040 tcg_gen_op5(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
e8996ee0 1041 tcg_temp_free(t0);
c896fe29
FB
1042}
1043
ac56dd48 1044static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 1045{
ac56dd48 1046 TCGv t0;
c896fe29
FB
1047 t0 = tcg_temp_new(TCG_TYPE_I64);
1048 tcg_gen_sari_i64(t0, arg1, 63);
1049 tcg_gen_op5(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
e8996ee0 1050 tcg_temp_free(t0);
c896fe29
FB
1051}
1052
ac56dd48 1053static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 1054{
ac56dd48 1055 TCGv t0;
c896fe29
FB
1056 t0 = tcg_temp_new(TCG_TYPE_I64);
1057 tcg_gen_movi_i64(t0, 0);
1058 tcg_gen_op5(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
e8996ee0 1059 tcg_temp_free(t0);
c896fe29
FB
1060}
1061
ac56dd48 1062static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 1063{
ac56dd48 1064 TCGv t0;
c896fe29
FB
1065 t0 = tcg_temp_new(TCG_TYPE_I64);
1066 tcg_gen_movi_i64(t0, 0);
1067 tcg_gen_op5(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
e8996ee0 1068 tcg_temp_free(t0);
c896fe29
FB
1069}
1070#endif
1071
1072#endif
1073
cb63669a
PB
1074static inline void tcg_gen_brcondi_i64(int cond, TCGv arg1, int64_t arg2,
1075 int label_index)
1076{
1077 TCGv t0 = tcg_const_i64(arg2);
1078 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1079 tcg_temp_free(t0);
1080}
1081
c896fe29
FB
1082/***************************************/
1083/* optional operations */
1084
ac56dd48 1085static inline void tcg_gen_ext8s_i32(TCGv ret, TCGv arg)
c896fe29
FB
1086{
1087#ifdef TCG_TARGET_HAS_ext8s_i32
1088 tcg_gen_op2(INDEX_op_ext8s_i32, ret, arg);
1089#else
1090 tcg_gen_shli_i32(ret, arg, 24);
5ff9d6a4 1091 tcg_gen_sari_i32(ret, ret, 24);
c896fe29
FB
1092#endif
1093}
1094
ac56dd48 1095static inline void tcg_gen_ext16s_i32(TCGv ret, TCGv arg)
c896fe29
FB
1096{
1097#ifdef TCG_TARGET_HAS_ext16s_i32
1098 tcg_gen_op2(INDEX_op_ext16s_i32, ret, arg);
1099#else
1100 tcg_gen_shli_i32(ret, arg, 16);
5ff9d6a4 1101 tcg_gen_sari_i32(ret, ret, 16);
c896fe29
FB
1102#endif
1103}
1104
86831435
PB
1105/* These are currently just for convenience.
1106 We assume a target will recognise these automatically . */
1107static inline void tcg_gen_ext8u_i32(TCGv ret, TCGv arg)
1108{
1109 tcg_gen_andi_i32(ret, arg, 0xffu);
1110}
1111
1112static inline void tcg_gen_ext16u_i32(TCGv ret, TCGv arg)
1113{
1114 tcg_gen_andi_i32(ret, arg, 0xffffu);
1115}
1116
c896fe29 1117/* Note: we assume the two high bytes are set to zero */
ac56dd48 1118static inline void tcg_gen_bswap16_i32(TCGv ret, TCGv arg)
c896fe29
FB
1119{
1120#ifdef TCG_TARGET_HAS_bswap16_i32
1121 tcg_gen_op2(INDEX_op_bswap16_i32, ret, arg);
1122#else
ac56dd48 1123 TCGv t0, t1;
c896fe29
FB
1124 t0 = tcg_temp_new(TCG_TYPE_I32);
1125 t1 = tcg_temp_new(TCG_TYPE_I32);
1126
1127 tcg_gen_shri_i32(t0, arg, 8);
1128 tcg_gen_andi_i32(t1, arg, 0x000000ff);
1129 tcg_gen_shli_i32(t1, t1, 8);
1130 tcg_gen_or_i32(ret, t0, t1);
e8996ee0
FB
1131 tcg_temp_free(t0);
1132 tcg_temp_free(t1);
c896fe29
FB
1133#endif
1134}
1135
ac56dd48 1136static inline void tcg_gen_bswap_i32(TCGv ret, TCGv arg)
c896fe29
FB
1137{
1138#ifdef TCG_TARGET_HAS_bswap_i32
1139 tcg_gen_op2(INDEX_op_bswap_i32, ret, arg);
1140#else
ac56dd48 1141 TCGv t0, t1;
c896fe29
FB
1142 t0 = tcg_temp_new(TCG_TYPE_I32);
1143 t1 = tcg_temp_new(TCG_TYPE_I32);
1144
1145 tcg_gen_shli_i32(t0, arg, 24);
1146
1147 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1148 tcg_gen_shli_i32(t1, t1, 8);
1149 tcg_gen_or_i32(t0, t0, t1);
1150
1151 tcg_gen_shri_i32(t1, arg, 8);
1152 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1153 tcg_gen_or_i32(t0, t0, t1);
1154
1155 tcg_gen_shri_i32(t1, arg, 24);
1156 tcg_gen_or_i32(ret, t0, t1);
e8996ee0
FB
1157 tcg_temp_free(t0);
1158 tcg_temp_free(t1);
c896fe29
FB
1159#endif
1160}
1161
1162#if TCG_TARGET_REG_BITS == 32
ac56dd48 1163static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
c896fe29
FB
1164{
1165 tcg_gen_ext8s_i32(ret, arg);
ac56dd48 1166 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
1167}
1168
ac56dd48 1169static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
c896fe29
FB
1170{
1171 tcg_gen_ext16s_i32(ret, arg);
ac56dd48 1172 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
1173}
1174
ac56dd48 1175static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
c896fe29
FB
1176{
1177 tcg_gen_mov_i32(ret, arg);
ac56dd48 1178 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
1179}
1180
86831435
PB
1181static inline void tcg_gen_ext8u_i64(TCGv ret, TCGv arg)
1182{
1183 tcg_gen_ext8u_i32(ret, arg);
1184 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1185}
1186
1187static inline void tcg_gen_ext16u_i64(TCGv ret, TCGv arg)
1188{
1189 tcg_gen_ext16u_i32(ret, arg);
1190 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1191}
1192
1193static inline void tcg_gen_ext32u_i64(TCGv ret, TCGv arg)
1194{
1195 tcg_gen_mov_i32(ret, arg);
1196 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1197}
1198
ac56dd48 1199static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
c896fe29
FB
1200{
1201 tcg_gen_mov_i32(ret, arg);
1202}
1203
ac56dd48 1204static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
c896fe29
FB
1205{
1206 tcg_gen_mov_i32(ret, arg);
ac56dd48 1207 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1208}
1209
ac56dd48 1210static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
c896fe29
FB
1211{
1212 tcg_gen_mov_i32(ret, arg);
ac56dd48 1213 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
1214}
1215
ac56dd48 1216static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
c896fe29 1217{
ac56dd48 1218 TCGv t0, t1;
c896fe29
FB
1219 t0 = tcg_temp_new(TCG_TYPE_I32);
1220 t1 = tcg_temp_new(TCG_TYPE_I32);
1221
1222 tcg_gen_bswap_i32(t0, arg);
ac56dd48 1223 tcg_gen_bswap_i32(t1, TCGV_HIGH(arg));
c896fe29 1224 tcg_gen_mov_i32(ret, t1);
ac56dd48 1225 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
e8996ee0
FB
1226 tcg_temp_free(t0);
1227 tcg_temp_free(t1);
c896fe29
FB
1228}
1229#else
1230
ac56dd48 1231static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
c896fe29
FB
1232{
1233#ifdef TCG_TARGET_HAS_ext8s_i64
1234 tcg_gen_op2(INDEX_op_ext8s_i64, ret, arg);
1235#else
1236 tcg_gen_shli_i64(ret, arg, 56);
5ff9d6a4 1237 tcg_gen_sari_i64(ret, ret, 56);
c896fe29
FB
1238#endif
1239}
1240
ac56dd48 1241static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
c896fe29
FB
1242{
1243#ifdef TCG_TARGET_HAS_ext16s_i64
1244 tcg_gen_op2(INDEX_op_ext16s_i64, ret, arg);
1245#else
1246 tcg_gen_shli_i64(ret, arg, 48);
5ff9d6a4 1247 tcg_gen_sari_i64(ret, ret, 48);
c896fe29
FB
1248#endif
1249}
1250
ac56dd48 1251static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
c896fe29
FB
1252{
1253#ifdef TCG_TARGET_HAS_ext32s_i64
1254 tcg_gen_op2(INDEX_op_ext32s_i64, ret, arg);
1255#else
1256 tcg_gen_shli_i64(ret, arg, 32);
5ff9d6a4 1257 tcg_gen_sari_i64(ret, ret, 32);
c896fe29
FB
1258#endif
1259}
1260
86831435
PB
1261static inline void tcg_gen_ext8u_i64(TCGv ret, TCGv arg)
1262{
1263 tcg_gen_andi_i64(ret, arg, 0xffu);
1264}
1265
1266static inline void tcg_gen_ext16u_i64(TCGv ret, TCGv arg)
1267{
1268 tcg_gen_andi_i64(ret, arg, 0xffffu);
1269}
1270
1271static inline void tcg_gen_ext32u_i64(TCGv ret, TCGv arg)
1272{
1273 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1274}
1275
c896fe29 1276/* Note: we assume the target supports move between 32 and 64 bit
ac56dd48
PB
1277 registers. This will probably break MIPS64 targets. */
1278static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
c896fe29
FB
1279{
1280 tcg_gen_mov_i32(ret, arg);
1281}
1282
1283/* Note: we assume the target supports move between 32 and 64 bit
1284 registers */
ac56dd48 1285static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
c896fe29 1286{
86831435 1287 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
c896fe29
FB
1288}
1289
1290/* Note: we assume the target supports move between 32 and 64 bit
1291 registers */
ac56dd48 1292static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
c896fe29
FB
1293{
1294 tcg_gen_ext32s_i64(ret, arg);
1295}
1296
ac56dd48 1297static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
c896fe29
FB
1298{
1299#ifdef TCG_TARGET_HAS_bswap_i64
1300 tcg_gen_op2(INDEX_op_bswap_i64, ret, arg);
1301#else
ac56dd48 1302 TCGv t0, t1;
c896fe29
FB
1303 t0 = tcg_temp_new(TCG_TYPE_I32);
1304 t1 = tcg_temp_new(TCG_TYPE_I32);
1305
1306 tcg_gen_shli_i64(t0, arg, 56);
1307
1308 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1309 tcg_gen_shli_i64(t1, t1, 40);
1310 tcg_gen_or_i64(t0, t0, t1);
1311
1312 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1313 tcg_gen_shli_i64(t1, t1, 24);
1314 tcg_gen_or_i64(t0, t0, t1);
1315
1316 tcg_gen_andi_i64(t1, arg, 0xff000000);
1317 tcg_gen_shli_i64(t1, t1, 8);
1318 tcg_gen_or_i64(t0, t0, t1);
1319
1320 tcg_gen_shri_i64(t1, arg, 8);
1321 tcg_gen_andi_i64(t1, t1, 0xff000000);
1322 tcg_gen_or_i64(t0, t0, t1);
1323
1324 tcg_gen_shri_i64(t1, arg, 24);
1325 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1326 tcg_gen_or_i64(t0, t0, t1);
1327
1328 tcg_gen_shri_i64(t1, arg, 40);
1329 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1330 tcg_gen_or_i64(t0, t0, t1);
1331
1332 tcg_gen_shri_i64(t1, arg, 56);
1333 tcg_gen_or_i64(ret, t0, t1);
e8996ee0
FB
1334 tcg_temp_free(t0);
1335 tcg_temp_free(t1);
c896fe29
FB
1336#endif
1337}
1338
1339#endif
1340
390efc54
PB
1341static inline void tcg_gen_neg_i32(TCGv ret, TCGv arg)
1342{
1343#ifdef TCG_TARGET_HAS_neg_i32
1344 tcg_gen_op2(INDEX_op_neg_i32, ret, arg);
1345#else
e8996ee0
FB
1346 TCGv t0 = tcg_const_i32(0);
1347 tcg_gen_sub_i32(ret, t0, arg);
1348 tcg_temp_free(t0);
390efc54
PB
1349#endif
1350}
1351
1352static inline void tcg_gen_neg_i64(TCGv ret, TCGv arg)
1353{
1354#ifdef TCG_TARGET_HAS_neg_i64
1355 tcg_gen_op2(INDEX_op_neg_i64, ret, arg);
1356#else
e8996ee0
FB
1357 TCGv t0 = tcg_const_i64(0);
1358 tcg_gen_sub_i64(ret, t0, arg);
1359 tcg_temp_free(t0);
390efc54
PB
1360#endif
1361}
1362
0b6ce4cf
FB
1363static inline void tcg_gen_not_i32(TCGv ret, TCGv arg)
1364{
e8996ee0 1365 tcg_gen_xori_i32(ret, arg, -1);
0b6ce4cf
FB
1366}
1367
1368static inline void tcg_gen_not_i64(TCGv ret, TCGv arg)
1369{
e8996ee0 1370 tcg_gen_xori_i64(ret, arg, -1);
0b6ce4cf 1371}
5ff9d6a4
FB
1372
1373static inline void tcg_gen_discard_i32(TCGv arg)
1374{
1375 tcg_gen_op1(INDEX_op_discard, arg);
1376}
1377
1378#if TCG_TARGET_REG_BITS == 32
1379static inline void tcg_gen_discard_i64(TCGv arg)
1380{
1381 tcg_gen_discard_i32(arg);
1382 tcg_gen_discard_i32(TCGV_HIGH(arg));
1383}
1384#else
1385static inline void tcg_gen_discard_i64(TCGv arg)
1386{
1387 tcg_gen_op1(INDEX_op_discard, arg);
1388}
1389#endif
1390
c896fe29 1391/***************************************/
ac56dd48 1392static inline void tcg_gen_macro_2(TCGv ret0, TCGv ret1, int macro_id)
c896fe29 1393{
ac56dd48 1394 tcg_gen_op3i(INDEX_op_macro_2, ret0, ret1, macro_id);
c896fe29
FB
1395}
1396
1397/***************************************/
1398/* QEMU specific operations. Their type depend on the QEMU CPU
1399 type. */
1400#ifndef TARGET_LONG_BITS
1401#error must include QEMU headers
1402#endif
1403
7e4597d7
FB
1404/* debug info: write the PC of the corresponding QEMU CPU instruction */
1405static inline void tcg_gen_debug_insn_start(uint64_t pc)
1406{
1407 /* XXX: must really use a 32 bit size for TCGArg in all cases */
1408#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
1409 tcg_gen_op2i(INDEX_op_debug_insn_start,
1410 (uint32_t)(pc), (uint32_t)(pc >> 32));
1411#else
1412 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
1413#endif
1414}
1415
c896fe29
FB
1416static inline void tcg_gen_exit_tb(tcg_target_long val)
1417{
ac56dd48 1418 tcg_gen_op1i(INDEX_op_exit_tb, val);
c896fe29
FB
1419}
1420
1421static inline void tcg_gen_goto_tb(int idx)
1422{
ac56dd48 1423 tcg_gen_op1i(INDEX_op_goto_tb, idx);
c896fe29
FB
1424}
1425
1426#if TCG_TARGET_REG_BITS == 32
ac56dd48 1427static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1428{
1429#if TARGET_LONG_BITS == 32
ac56dd48 1430 tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29 1431#else
ac56dd48
PB
1432 tcg_gen_op4i(INDEX_op_qemu_ld8u, ret, addr, TCGV_HIGH(addr), mem_index);
1433 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1434#endif
1435}
1436
ac56dd48 1437static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1438{
1439#if TARGET_LONG_BITS == 32
ac56dd48 1440 tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29 1441#else
ac56dd48 1442 tcg_gen_op4i(INDEX_op_qemu_ld8s, ret, addr, TCGV_HIGH(addr), mem_index);
21fc3cfc 1443 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
1444#endif
1445}
1446
ac56dd48 1447static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1448{
1449#if TARGET_LONG_BITS == 32
ac56dd48 1450 tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29 1451#else
ac56dd48
PB
1452 tcg_gen_op4i(INDEX_op_qemu_ld16u, ret, addr, TCGV_HIGH(addr), mem_index);
1453 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1454#endif
1455}
1456
ac56dd48 1457static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1458{
1459#if TARGET_LONG_BITS == 32
ac56dd48 1460 tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29 1461#else
ac56dd48 1462 tcg_gen_op4i(INDEX_op_qemu_ld16s, ret, addr, TCGV_HIGH(addr), mem_index);
21fc3cfc 1463 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
1464#endif
1465}
1466
ac56dd48 1467static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1468{
1469#if TARGET_LONG_BITS == 32
ac56dd48 1470 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
c896fe29 1471#else
ac56dd48
PB
1472 tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
1473 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1474#endif
1475}
1476
ac56dd48 1477static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1478{
1479#if TARGET_LONG_BITS == 32
ac56dd48 1480 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
c896fe29 1481#else
ac56dd48
PB
1482 tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
1483 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
1484#endif
1485}
1486
ac56dd48 1487static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1488{
1489#if TARGET_LONG_BITS == 32
ac56dd48 1490 tcg_gen_op4i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret), addr, mem_index);
c896fe29 1491#else
ac56dd48
PB
1492 tcg_gen_op5i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret),
1493 addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1494#endif
1495}
1496
ac56dd48 1497static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
1498{
1499#if TARGET_LONG_BITS == 32
ac56dd48 1500 tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29 1501#else
ac56dd48 1502 tcg_gen_op4i(INDEX_op_qemu_st8, arg, addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1503#endif
1504}
1505
ac56dd48 1506static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
1507{
1508#if TARGET_LONG_BITS == 32
ac56dd48 1509 tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29 1510#else
ac56dd48 1511 tcg_gen_op4i(INDEX_op_qemu_st16, arg, addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1512#endif
1513}
1514
ac56dd48 1515static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
1516{
1517#if TARGET_LONG_BITS == 32
ac56dd48 1518 tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29 1519#else
ac56dd48 1520 tcg_gen_op4i(INDEX_op_qemu_st32, arg, addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1521#endif
1522}
1523
ac56dd48 1524static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
1525{
1526#if TARGET_LONG_BITS == 32
ac56dd48 1527 tcg_gen_op4i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg), addr, mem_index);
c896fe29 1528#else
ac56dd48
PB
1529 tcg_gen_op5i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg),
1530 addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1531#endif
1532}
1533
56b8f567 1534#define tcg_gen_ld_ptr tcg_gen_ld_i32
a768e4b2 1535#define tcg_gen_discard_ptr tcg_gen_discard_i32
f8422f52 1536
c896fe29
FB
1537#else /* TCG_TARGET_REG_BITS == 32 */
1538
ac56dd48 1539static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29 1540{
ac56dd48 1541 tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29
FB
1542}
1543
ac56dd48 1544static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29 1545{
ac56dd48 1546 tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29
FB
1547}
1548
ac56dd48 1549static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29 1550{
ac56dd48 1551 tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29
FB
1552}
1553
ac56dd48 1554static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29 1555{
ac56dd48 1556 tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29
FB
1557}
1558
ac56dd48 1559static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29 1560{
ac56dd48 1561 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
c896fe29
FB
1562}
1563
ac56dd48 1564static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29 1565{
ac56dd48 1566 tcg_gen_op3i(INDEX_op_qemu_ld32s, ret, addr, mem_index);
c896fe29
FB
1567}
1568
ac56dd48 1569static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
c896fe29 1570{
ac56dd48 1571 tcg_gen_op3i(INDEX_op_qemu_ld64, ret, addr, mem_index);
c896fe29
FB
1572}
1573
ac56dd48 1574static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29 1575{
ac56dd48 1576 tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29
FB
1577}
1578
ac56dd48 1579static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29 1580{
ac56dd48 1581 tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29
FB
1582}
1583
ac56dd48 1584static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29 1585{
ac56dd48 1586 tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29
FB
1587}
1588
ac56dd48 1589static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
c896fe29 1590{
ac56dd48 1591 tcg_gen_op3i(INDEX_op_qemu_st64, arg, addr, mem_index);
c896fe29
FB
1592}
1593
56b8f567 1594#define tcg_gen_ld_ptr tcg_gen_ld_i64
a768e4b2 1595#define tcg_gen_discard_ptr tcg_gen_discard_i64
f8422f52 1596
c896fe29 1597#endif /* TCG_TARGET_REG_BITS != 32 */
f8422f52
BS
1598
1599#if TARGET_LONG_BITS == 64
1600#define TCG_TYPE_TL TCG_TYPE_I64
1601#define tcg_gen_movi_tl tcg_gen_movi_i64
1602#define tcg_gen_mov_tl tcg_gen_mov_i64
1603#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
1604#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
1605#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
1606#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
1607#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
1608#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
1609#define tcg_gen_ld_tl tcg_gen_ld_i64
1610#define tcg_gen_st8_tl tcg_gen_st8_i64
1611#define tcg_gen_st16_tl tcg_gen_st16_i64
1612#define tcg_gen_st32_tl tcg_gen_st32_i64
1613#define tcg_gen_st_tl tcg_gen_st_i64
1614#define tcg_gen_add_tl tcg_gen_add_i64
1615#define tcg_gen_addi_tl tcg_gen_addi_i64
1616#define tcg_gen_sub_tl tcg_gen_sub_i64
390efc54 1617#define tcg_gen_neg_tl tcg_gen_neg_i64
f8422f52
BS
1618#define tcg_gen_subi_tl tcg_gen_subi_i64
1619#define tcg_gen_and_tl tcg_gen_and_i64
1620#define tcg_gen_andi_tl tcg_gen_andi_i64
1621#define tcg_gen_or_tl tcg_gen_or_i64
1622#define tcg_gen_ori_tl tcg_gen_ori_i64
1623#define tcg_gen_xor_tl tcg_gen_xor_i64
1624#define tcg_gen_xori_tl tcg_gen_xori_i64
0b6ce4cf 1625#define tcg_gen_not_tl tcg_gen_not_i64
f8422f52
BS
1626#define tcg_gen_shl_tl tcg_gen_shl_i64
1627#define tcg_gen_shli_tl tcg_gen_shli_i64
1628#define tcg_gen_shr_tl tcg_gen_shr_i64
1629#define tcg_gen_shri_tl tcg_gen_shri_i64
1630#define tcg_gen_sar_tl tcg_gen_sar_i64
1631#define tcg_gen_sari_tl tcg_gen_sari_i64
0cf767d6 1632#define tcg_gen_brcond_tl tcg_gen_brcond_i64
cb63669a 1633#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
f730fd27
TS
1634#define tcg_gen_mul_tl tcg_gen_mul_i64
1635#define tcg_gen_muli_tl tcg_gen_muli_i64
a768e4b2 1636#define tcg_gen_discard_tl tcg_gen_discard_i64
e429073d
BS
1637#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
1638#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
1639#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
1640#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
1641#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
1642#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
0b6ce4cf
FB
1643#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
1644#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
1645#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
1646#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
1647#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
1648#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
a98824ac 1649#define tcg_const_tl tcg_const_i64
f8422f52
BS
1650#else
1651#define TCG_TYPE_TL TCG_TYPE_I32
1652#define tcg_gen_movi_tl tcg_gen_movi_i32
1653#define tcg_gen_mov_tl tcg_gen_mov_i32
1654#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
1655#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
1656#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
1657#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
1658#define tcg_gen_ld32u_tl tcg_gen_ld_i32
1659#define tcg_gen_ld32s_tl tcg_gen_ld_i32
1660#define tcg_gen_ld_tl tcg_gen_ld_i32
1661#define tcg_gen_st8_tl tcg_gen_st8_i32
1662#define tcg_gen_st16_tl tcg_gen_st16_i32
1663#define tcg_gen_st32_tl tcg_gen_st_i32
1664#define tcg_gen_st_tl tcg_gen_st_i32
1665#define tcg_gen_add_tl tcg_gen_add_i32
1666#define tcg_gen_addi_tl tcg_gen_addi_i32
1667#define tcg_gen_sub_tl tcg_gen_sub_i32
390efc54 1668#define tcg_gen_neg_tl tcg_gen_neg_i32
f8422f52
BS
1669#define tcg_gen_subi_tl tcg_gen_subi_i32
1670#define tcg_gen_and_tl tcg_gen_and_i32
1671#define tcg_gen_andi_tl tcg_gen_andi_i32
1672#define tcg_gen_or_tl tcg_gen_or_i32
1673#define tcg_gen_ori_tl tcg_gen_ori_i32
1674#define tcg_gen_xor_tl tcg_gen_xor_i32
1675#define tcg_gen_xori_tl tcg_gen_xori_i32
0b6ce4cf 1676#define tcg_gen_not_tl tcg_gen_not_i32
f8422f52
BS
1677#define tcg_gen_shl_tl tcg_gen_shl_i32
1678#define tcg_gen_shli_tl tcg_gen_shli_i32
1679#define tcg_gen_shr_tl tcg_gen_shr_i32
1680#define tcg_gen_shri_tl tcg_gen_shri_i32
1681#define tcg_gen_sar_tl tcg_gen_sar_i32
1682#define tcg_gen_sari_tl tcg_gen_sari_i32
0cf767d6 1683#define tcg_gen_brcond_tl tcg_gen_brcond_i32
cb63669a 1684#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
f730fd27
TS
1685#define tcg_gen_mul_tl tcg_gen_mul_i32
1686#define tcg_gen_muli_tl tcg_gen_muli_i32
a768e4b2 1687#define tcg_gen_discard_tl tcg_gen_discard_i32
e429073d
BS
1688#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
1689#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
1690#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
1691#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
1692#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
1693#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
0b6ce4cf
FB
1694#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
1695#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
1696#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
1697#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
1698#define tcg_gen_ext32u_tl tcg_gen_mov_i32
1699#define tcg_gen_ext32s_tl tcg_gen_mov_i32
a98824ac 1700#define tcg_const_tl tcg_const_i32
f8422f52 1701#endif
6ddbc6e4
PB
1702
1703#if TCG_TARGET_REG_BITS == 32
48d38ca5 1704#define tcg_gen_add_ptr tcg_gen_add_i32
6ddbc6e4 1705#define tcg_gen_addi_ptr tcg_gen_addi_i32
48d38ca5 1706#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
6ddbc6e4 1707#else /* TCG_TARGET_REG_BITS == 32 */
48d38ca5 1708#define tcg_gen_add_ptr tcg_gen_add_i64
6ddbc6e4 1709#define tcg_gen_addi_ptr tcg_gen_addi_i64
48d38ca5 1710#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
6ddbc6e4
PB
1711#endif /* TCG_TARGET_REG_BITS != 32 */
1712