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