]> git.proxmox.com Git - qemu.git/blame - tcg/tcg-op.h
compare fix
[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
26/* legacy dyngen operations */
27#include "gen-op.h"
28
29int gen_new_label(void);
30
ac56dd48 31static inline void tcg_gen_op1(int opc, TCGv arg1)
c896fe29
FB
32{
33 *gen_opc_ptr++ = opc;
ac56dd48 34 *gen_opparam_ptr++ = GET_TCGV(arg1);
c896fe29
FB
35}
36
ac56dd48 37static inline void tcg_gen_op1i(int opc, TCGArg arg1)
c896fe29
FB
38{
39 *gen_opc_ptr++ = opc;
40 *gen_opparam_ptr++ = arg1;
c896fe29
FB
41}
42
ac56dd48 43static inline void tcg_gen_op2(int opc, TCGv arg1, TCGv arg2)
c896fe29
FB
44{
45 *gen_opc_ptr++ = opc;
ac56dd48
PB
46 *gen_opparam_ptr++ = GET_TCGV(arg1);
47 *gen_opparam_ptr++ = GET_TCGV(arg2);
c896fe29
FB
48}
49
ac56dd48 50static inline void tcg_gen_op2i(int opc, TCGv arg1, TCGArg arg2)
c896fe29
FB
51{
52 *gen_opc_ptr++ = opc;
ac56dd48 53 *gen_opparam_ptr++ = GET_TCGV(arg1);
c896fe29 54 *gen_opparam_ptr++ = arg2;
ac56dd48
PB
55}
56
57static inline void tcg_gen_op3(int opc, TCGv arg1, TCGv arg2, TCGv arg3)
58{
59 *gen_opc_ptr++ = opc;
60 *gen_opparam_ptr++ = GET_TCGV(arg1);
61 *gen_opparam_ptr++ = GET_TCGV(arg2);
62 *gen_opparam_ptr++ = GET_TCGV(arg3);
63}
64
65static inline void tcg_gen_op3i(int opc, TCGv arg1, TCGv arg2, TCGArg arg3)
66{
67 *gen_opc_ptr++ = opc;
68 *gen_opparam_ptr++ = GET_TCGV(arg1);
69 *gen_opparam_ptr++ = GET_TCGV(arg2);
c896fe29 70 *gen_opparam_ptr++ = arg3;
ac56dd48
PB
71}
72
73static inline void tcg_gen_op4(int opc, TCGv arg1, TCGv arg2, TCGv arg3,
74 TCGv arg4)
75{
76 *gen_opc_ptr++ = opc;
77 *gen_opparam_ptr++ = GET_TCGV(arg1);
78 *gen_opparam_ptr++ = GET_TCGV(arg2);
79 *gen_opparam_ptr++ = GET_TCGV(arg3);
80 *gen_opparam_ptr++ = GET_TCGV(arg4);
81}
82
83static inline void tcg_gen_op4i(int opc, TCGv arg1, TCGv arg2, TCGv arg3,
84 TCGArg arg4)
85{
86 *gen_opc_ptr++ = opc;
87 *gen_opparam_ptr++ = GET_TCGV(arg1);
88 *gen_opparam_ptr++ = GET_TCGV(arg2);
89 *gen_opparam_ptr++ = GET_TCGV(arg3);
c896fe29
FB
90 *gen_opparam_ptr++ = arg4;
91}
92
ac56dd48
PB
93static inline void tcg_gen_op4ii(int opc, TCGv arg1, TCGv arg2, TCGArg arg3,
94 TCGArg arg4)
c896fe29
FB
95{
96 *gen_opc_ptr++ = opc;
ac56dd48
PB
97 *gen_opparam_ptr++ = GET_TCGV(arg1);
98 *gen_opparam_ptr++ = GET_TCGV(arg2);
c896fe29
FB
99 *gen_opparam_ptr++ = arg3;
100 *gen_opparam_ptr++ = arg4;
ac56dd48
PB
101}
102
103static inline void tcg_gen_op5(int opc, TCGv arg1, TCGv arg2,
104 TCGv arg3, TCGv arg4,
105 TCGv arg5)
106{
107 *gen_opc_ptr++ = opc;
108 *gen_opparam_ptr++ = GET_TCGV(arg1);
109 *gen_opparam_ptr++ = GET_TCGV(arg2);
110 *gen_opparam_ptr++ = GET_TCGV(arg3);
111 *gen_opparam_ptr++ = GET_TCGV(arg4);
112 *gen_opparam_ptr++ = GET_TCGV(arg5);
113}
114
115static inline void tcg_gen_op5i(int opc, TCGv arg1, TCGv arg2,
116 TCGv arg3, TCGv arg4,
117 TCGArg arg5)
118{
119 *gen_opc_ptr++ = opc;
120 *gen_opparam_ptr++ = GET_TCGV(arg1);
121 *gen_opparam_ptr++ = GET_TCGV(arg2);
122 *gen_opparam_ptr++ = GET_TCGV(arg3);
123 *gen_opparam_ptr++ = GET_TCGV(arg4);
c896fe29
FB
124 *gen_opparam_ptr++ = arg5;
125}
126
ac56dd48
PB
127static inline void tcg_gen_op6(int opc, TCGv arg1, TCGv arg2,
128 TCGv arg3, TCGv arg4,
129 TCGv arg5, TCGv arg6)
c896fe29
FB
130{
131 *gen_opc_ptr++ = opc;
ac56dd48
PB
132 *gen_opparam_ptr++ = GET_TCGV(arg1);
133 *gen_opparam_ptr++ = GET_TCGV(arg2);
134 *gen_opparam_ptr++ = GET_TCGV(arg3);
135 *gen_opparam_ptr++ = GET_TCGV(arg4);
136 *gen_opparam_ptr++ = GET_TCGV(arg5);
137 *gen_opparam_ptr++ = GET_TCGV(arg6);
138}
139
140static inline void tcg_gen_op6ii(int opc, TCGv arg1, TCGv arg2,
141 TCGv arg3, TCGv arg4,
142 TCGArg arg5, TCGArg arg6)
143{
144 *gen_opc_ptr++ = opc;
145 *gen_opparam_ptr++ = GET_TCGV(arg1);
146 *gen_opparam_ptr++ = GET_TCGV(arg2);
147 *gen_opparam_ptr++ = GET_TCGV(arg3);
148 *gen_opparam_ptr++ = GET_TCGV(arg4);
c896fe29
FB
149 *gen_opparam_ptr++ = arg5;
150 *gen_opparam_ptr++ = arg6;
151}
152
153static inline void gen_set_label(int n)
154{
ac56dd48 155 tcg_gen_op1i(INDEX_op_set_label, n);
c896fe29
FB
156}
157
ac56dd48 158static inline void tcg_gen_mov_i32(TCGv ret, TCGv arg)
c896fe29
FB
159{
160 tcg_gen_op2(INDEX_op_mov_i32, ret, arg);
161}
162
ac56dd48 163static inline void tcg_gen_movi_i32(TCGv ret, int32_t arg)
c896fe29 164{
ac56dd48 165 tcg_gen_op2i(INDEX_op_movi_i32, ret, arg);
c896fe29
FB
166}
167
168/* helper calls */
169#define TCG_HELPER_CALL_FLAGS 0
170
171static inline void tcg_gen_helper_0_0(void *func)
172{
173 tcg_gen_call(&tcg_ctx,
174 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
175 0, NULL, 0, NULL);
176}
177
ac56dd48 178static inline void tcg_gen_helper_0_1(void *func, TCGv arg)
c896fe29
FB
179{
180 tcg_gen_call(&tcg_ctx,
181 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
182 0, NULL, 1, &arg);
183}
184
ac56dd48 185static inline void tcg_gen_helper_0_2(void *func, TCGv arg1, TCGv arg2)
c896fe29 186{
ac56dd48 187 TCGv args[2];
c896fe29
FB
188 args[0] = arg1;
189 args[1] = arg2;
190 tcg_gen_call(&tcg_ctx,
191 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
192 0, NULL, 2, args);
193}
194
ac56dd48
PB
195static inline void tcg_gen_helper_1_2(void *func, TCGv ret,
196 TCGv arg1, TCGv arg2)
c896fe29 197{
ac56dd48 198 TCGv args[2];
c896fe29
FB
199 args[0] = arg1;
200 args[1] = arg2;
201 tcg_gen_call(&tcg_ctx,
202 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
203 1, &ret, 2, args);
204}
205
206/* 32 bit ops */
207
ac56dd48 208static inline void tcg_gen_ld8u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 209{
ac56dd48 210 tcg_gen_op3i(INDEX_op_ld8u_i32, ret, arg2, offset);
c896fe29
FB
211}
212
ac56dd48 213static inline void tcg_gen_ld8s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 214{
ac56dd48 215 tcg_gen_op3i(INDEX_op_ld8s_i32, ret, arg2, offset);
c896fe29
FB
216}
217
ac56dd48 218static inline void tcg_gen_ld16u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 219{
ac56dd48 220 tcg_gen_op3i(INDEX_op_ld16u_i32, ret, arg2, offset);
c896fe29
FB
221}
222
ac56dd48 223static inline void tcg_gen_ld16s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 224{
ac56dd48 225 tcg_gen_op3i(INDEX_op_ld16s_i32, ret, arg2, offset);
c896fe29
FB
226}
227
ac56dd48 228static inline void tcg_gen_ld_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 229{
ac56dd48 230 tcg_gen_op3i(INDEX_op_ld_i32, ret, arg2, offset);
c896fe29
FB
231}
232
ac56dd48 233static inline void tcg_gen_st8_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29 234{
ac56dd48 235 tcg_gen_op3i(INDEX_op_st8_i32, arg1, arg2, offset);
c896fe29
FB
236}
237
ac56dd48 238static inline void tcg_gen_st16_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29 239{
ac56dd48 240 tcg_gen_op3i(INDEX_op_st16_i32, arg1, arg2, offset);
c896fe29
FB
241}
242
ac56dd48 243static inline void tcg_gen_st_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29 244{
ac56dd48 245 tcg_gen_op3i(INDEX_op_st_i32, arg1, arg2, offset);
c896fe29
FB
246}
247
ac56dd48 248static inline void tcg_gen_add_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
249{
250 tcg_gen_op3(INDEX_op_add_i32, ret, arg1, arg2);
251}
252
ac56dd48 253static inline void tcg_gen_addi_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
254{
255 tcg_gen_add_i32(ret, arg1, tcg_const_i32(arg2));
256}
257
ac56dd48 258static inline void tcg_gen_sub_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
259{
260 tcg_gen_op3(INDEX_op_sub_i32, ret, arg1, arg2);
261}
262
ac56dd48 263static inline void tcg_gen_subi_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
264{
265 tcg_gen_sub_i32(ret, arg1, tcg_const_i32(arg2));
266}
267
ac56dd48 268static inline void tcg_gen_and_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
269{
270 tcg_gen_op3(INDEX_op_and_i32, ret, arg1, arg2);
271}
272
ac56dd48 273static inline void tcg_gen_andi_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
274{
275 /* some cases can be optimized here */
276 if (arg2 == 0) {
277 tcg_gen_movi_i32(ret, 0);
278 } else if (arg2 == 0xffffffff) {
279 tcg_gen_mov_i32(ret, arg1);
280 } else {
281 tcg_gen_and_i32(ret, arg1, tcg_const_i32(arg2));
282 }
283}
284
ac56dd48 285static inline void tcg_gen_or_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
286{
287 tcg_gen_op3(INDEX_op_or_i32, ret, arg1, arg2);
288}
289
ac56dd48 290static inline void tcg_gen_ori_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
291{
292 /* some cases can be optimized here */
293 if (arg2 == 0xffffffff) {
294 tcg_gen_movi_i32(ret, 0);
295 } else if (arg2 == 0) {
296 tcg_gen_mov_i32(ret, arg1);
297 } else {
298 tcg_gen_or_i32(ret, arg1, tcg_const_i32(arg2));
299 }
300}
301
ac56dd48 302static inline void tcg_gen_xor_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
303{
304 tcg_gen_op3(INDEX_op_xor_i32, ret, arg1, arg2);
305}
306
ac56dd48 307static inline void tcg_gen_xori_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
308{
309 /* some cases can be optimized here */
310 if (arg2 == 0) {
311 tcg_gen_mov_i32(ret, arg1);
312 } else {
313 tcg_gen_xor_i32(ret, arg1, tcg_const_i32(arg2));
314 }
315}
316
ac56dd48 317static inline void tcg_gen_shl_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
318{
319 tcg_gen_op3(INDEX_op_shl_i32, ret, arg1, arg2);
320}
321
ac56dd48 322static inline void tcg_gen_shli_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
323{
324 tcg_gen_shl_i32(ret, arg1, tcg_const_i32(arg2));
325}
326
ac56dd48 327static inline void tcg_gen_shr_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
328{
329 tcg_gen_op3(INDEX_op_shr_i32, ret, arg1, arg2);
330}
331
ac56dd48 332static inline void tcg_gen_shri_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
333{
334 tcg_gen_shr_i32(ret, arg1, tcg_const_i32(arg2));
335}
336
ac56dd48 337static inline void tcg_gen_sar_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
338{
339 tcg_gen_op3(INDEX_op_sar_i32, ret, arg1, arg2);
340}
341
ac56dd48 342static inline void tcg_gen_sari_i32(TCGv ret, TCGv arg1, int32_t arg2)
c896fe29
FB
343{
344 tcg_gen_sar_i32(ret, arg1, tcg_const_i32(arg2));
345}
346
ac56dd48 347static inline void tcg_gen_brcond_i32(int cond, TCGv arg1, TCGv arg2,
c896fe29
FB
348 int label_index)
349{
ac56dd48 350 tcg_gen_op4ii(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
c896fe29
FB
351}
352
ac56dd48 353static inline void tcg_gen_mul_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
354{
355 tcg_gen_op3(INDEX_op_mul_i32, ret, arg1, arg2);
356}
357
358#ifdef TCG_TARGET_HAS_div_i32
ac56dd48 359static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
360{
361 tcg_gen_op3(INDEX_op_div_i32, ret, arg1, arg2);
362}
363
ac56dd48 364static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
365{
366 tcg_gen_op3(INDEX_op_rem_i32, ret, arg1, arg2);
367}
368
ac56dd48 369static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
370{
371 tcg_gen_op3(INDEX_op_divu_i32, ret, arg1, arg2);
372}
373
ac56dd48 374static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
375{
376 tcg_gen_op3(INDEX_op_remu_i32, ret, arg1, arg2);
377}
378#else
ac56dd48 379static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 380{
ac56dd48 381 TCGv t0;
c896fe29
FB
382 t0 = tcg_temp_new(TCG_TYPE_I32);
383 tcg_gen_sari_i32(t0, arg1, 31);
384 tcg_gen_op5(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
385}
386
ac56dd48 387static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 388{
ac56dd48 389 TCGv t0;
c896fe29
FB
390 t0 = tcg_temp_new(TCG_TYPE_I32);
391 tcg_gen_sari_i32(t0, arg1, 31);
392 tcg_gen_op5(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
393}
394
ac56dd48 395static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 396{
ac56dd48 397 TCGv t0;
c896fe29
FB
398 t0 = tcg_temp_new(TCG_TYPE_I32);
399 tcg_gen_movi_i32(t0, 0);
400 tcg_gen_op5(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
401}
402
ac56dd48 403static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 404{
ac56dd48 405 TCGv t0;
c896fe29
FB
406 t0 = tcg_temp_new(TCG_TYPE_I32);
407 tcg_gen_movi_i32(t0, 0);
408 tcg_gen_op5(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
409}
410#endif
411
412#if TCG_TARGET_REG_BITS == 32
413
ac56dd48 414static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
c896fe29
FB
415{
416 tcg_gen_mov_i32(ret, arg);
ac56dd48 417 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
c896fe29
FB
418}
419
ac56dd48 420static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
c896fe29
FB
421{
422 tcg_gen_movi_i32(ret, arg);
ac56dd48 423 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
c896fe29
FB
424}
425
ac56dd48 426static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
427{
428 tcg_gen_ld8u_i32(ret, arg2, offset);
ac56dd48 429 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
430}
431
ac56dd48 432static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
433{
434 tcg_gen_ld8s_i32(ret, arg2, offset);
ac56dd48 435 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
436}
437
ac56dd48 438static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
439{
440 tcg_gen_ld16u_i32(ret, arg2, offset);
ac56dd48 441 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
442}
443
ac56dd48 444static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
445{
446 tcg_gen_ld16s_i32(ret, arg2, offset);
ac56dd48 447 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
448}
449
ac56dd48 450static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
451{
452 tcg_gen_ld_i32(ret, arg2, offset);
ac56dd48 453 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
454}
455
ac56dd48 456static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
457{
458 tcg_gen_ld_i32(ret, arg2, offset);
ac56dd48 459 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
460}
461
ac56dd48 462static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29
FB
463{
464 /* since arg2 and ret have different types, they cannot be the
465 same temporary */
466#ifdef TCG_TARGET_WORDS_BIGENDIAN
ac56dd48 467 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
c896fe29
FB
468 tcg_gen_ld_i32(ret, arg2, offset + 4);
469#else
470 tcg_gen_ld_i32(ret, arg2, offset);
ac56dd48 471 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
c896fe29
FB
472#endif
473}
474
ac56dd48 475static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29
FB
476{
477 tcg_gen_st8_i32(arg1, arg2, offset);
478}
479
ac56dd48 480static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29
FB
481{
482 tcg_gen_st16_i32(arg1, arg2, offset);
483}
484
ac56dd48 485static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29
FB
486{
487 tcg_gen_st_i32(arg1, arg2, offset);
488}
489
ac56dd48 490static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29
FB
491{
492#ifdef TCG_TARGET_WORDS_BIGENDIAN
ac56dd48 493 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
c896fe29
FB
494 tcg_gen_st_i32(arg1, arg2, offset + 4);
495#else
496 tcg_gen_st_i32(arg1, arg2, offset);
ac56dd48 497 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
c896fe29
FB
498#endif
499}
500
ac56dd48 501static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 502{
ac56dd48
PB
503 tcg_gen_op6(INDEX_op_add2_i32, ret, TCGV_HIGH(ret),
504 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
c896fe29
FB
505}
506
ac56dd48 507static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
508{
509 tcg_gen_add_i64(ret, arg1, tcg_const_i64(arg2));
510}
511
ac56dd48 512static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 513{
ac56dd48
PB
514 tcg_gen_op6(INDEX_op_sub2_i32, ret, TCGV_HIGH(ret),
515 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
c896fe29
FB
516}
517
ac56dd48 518static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
519{
520 tcg_gen_sub_i64(ret, arg1, tcg_const_i64(arg2));
521}
522
ac56dd48 523static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
524{
525 tcg_gen_and_i32(ret, arg1, arg2);
ac56dd48 526 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
527}
528
ac56dd48 529static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
530{
531 tcg_gen_andi_i32(ret, arg1, arg2);
ac56dd48 532 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
533}
534
ac56dd48 535static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
536{
537 tcg_gen_or_i32(ret, arg1, arg2);
ac56dd48 538 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
539}
540
ac56dd48 541static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
542{
543 tcg_gen_ori_i32(ret, arg1, arg2);
ac56dd48 544 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
545}
546
ac56dd48 547static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
548{
549 tcg_gen_xor_i32(ret, arg1, arg2);
ac56dd48 550 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
551}
552
ac56dd48 553static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
554{
555 tcg_gen_xori_i32(ret, arg1, arg2);
ac56dd48 556 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
557}
558
559/* XXX: use generic code when basic block handling is OK or CPU
560 specific code (x86) */
ac56dd48 561static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
562{
563 tcg_gen_helper_1_2(tcg_helper_shl_i64, ret, arg1, arg2);
564}
565
ac56dd48 566static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
567{
568 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
569}
570
ac56dd48 571static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
572{
573 tcg_gen_helper_1_2(tcg_helper_shr_i64, ret, arg1, arg2);
574}
575
ac56dd48 576static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
577{
578 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
579}
580
ac56dd48 581static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
582{
583 tcg_gen_helper_1_2(tcg_helper_sar_i64, ret, arg1, arg2);
584}
585
ac56dd48 586static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
587{
588 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
589}
590
ac56dd48 591static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2,
c896fe29
FB
592 int label_index)
593{
ac56dd48
PB
594 tcg_gen_op6ii(INDEX_op_brcond2_i32,
595 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2),
596 cond, label_index);
c896fe29
FB
597}
598
ac56dd48 599static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 600{
ac56dd48 601 TCGv t0, t1;
c896fe29
FB
602
603 t0 = tcg_temp_new(TCG_TYPE_I64);
604 t1 = tcg_temp_new(TCG_TYPE_I32);
605
ac56dd48 606 tcg_gen_op4(INDEX_op_mulu2_i32, t0, TCGV_HIGH(t0), arg1, arg2);
c896fe29 607
ac56dd48
PB
608 tcg_gen_mul_i32(t1, arg1, TCGV_HIGH(arg2));
609 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
610 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), arg2);
611 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
c896fe29
FB
612
613 tcg_gen_mov_i64(ret, t0);
614}
615
ac56dd48 616static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
617{
618 tcg_gen_helper_1_2(tcg_helper_div_i64, ret, arg1, arg2);
619}
620
ac56dd48 621static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
622{
623 tcg_gen_helper_1_2(tcg_helper_rem_i64, ret, arg1, arg2);
624}
625
ac56dd48 626static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
627{
628 tcg_gen_helper_1_2(tcg_helper_divu_i64, ret, arg1, arg2);
629}
630
ac56dd48 631static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
632{
633 tcg_gen_helper_1_2(tcg_helper_remu_i64, ret, arg1, arg2);
634}
635
636#else
637
ac56dd48 638static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
c896fe29
FB
639{
640 tcg_gen_op2(INDEX_op_mov_i64, ret, arg);
641}
642
ac56dd48 643static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
c896fe29 644{
ac56dd48 645 tcg_gen_op2i(INDEX_op_movi_i64, ret, arg);
c896fe29
FB
646}
647
ac56dd48
PB
648static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2,
649 tcg_target_long offset)
c896fe29 650{
ac56dd48 651 tcg_gen_op3i(INDEX_op_ld8u_i64, ret, arg2, offset);
c896fe29
FB
652}
653
ac56dd48
PB
654static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2,
655 tcg_target_long offset)
c896fe29 656{
ac56dd48 657 tcg_gen_op3i(INDEX_op_ld8s_i64, ret, arg2, offset);
c896fe29
FB
658}
659
ac56dd48
PB
660static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2,
661 tcg_target_long offset)
c896fe29 662{
ac56dd48 663 tcg_gen_op3i(INDEX_op_ld16u_i64, ret, arg2, offset);
c896fe29
FB
664}
665
ac56dd48
PB
666static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2,
667 tcg_target_long offset)
c896fe29 668{
ac56dd48 669 tcg_gen_op3i(INDEX_op_ld16s_i64, ret, arg2, offset);
c896fe29
FB
670}
671
ac56dd48
PB
672static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2,
673 tcg_target_long offset)
c896fe29 674{
ac56dd48 675 tcg_gen_op3i(INDEX_op_ld32u_i64, ret, arg2, offset);
c896fe29
FB
676}
677
ac56dd48
PB
678static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2,
679 tcg_target_long offset)
c896fe29 680{
ac56dd48 681 tcg_gen_op3i(INDEX_op_ld32s_i64, ret, arg2, offset);
c896fe29
FB
682}
683
ac56dd48 684static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
c896fe29 685{
ac56dd48 686 tcg_gen_op3i(INDEX_op_ld_i64, ret, arg2, offset);
c896fe29
FB
687}
688
ac56dd48
PB
689static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2,
690 tcg_target_long offset)
c896fe29 691{
ac56dd48 692 tcg_gen_op3i(INDEX_op_st8_i64, arg1, arg2, offset);
c896fe29
FB
693}
694
ac56dd48
PB
695static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2,
696 tcg_target_long offset)
c896fe29 697{
ac56dd48 698 tcg_gen_op3i(INDEX_op_st16_i64, arg1, arg2, offset);
c896fe29
FB
699}
700
ac56dd48
PB
701static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2,
702 tcg_target_long offset)
c896fe29 703{
ac56dd48 704 tcg_gen_op3i(INDEX_op_st32_i64, arg1, arg2, offset);
c896fe29
FB
705}
706
ac56dd48 707static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
c896fe29 708{
ac56dd48 709 tcg_gen_op3i(INDEX_op_st_i64, arg1, arg2, offset);
c896fe29
FB
710}
711
ac56dd48 712static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
713{
714 tcg_gen_op3(INDEX_op_add_i64, ret, arg1, arg2);
715}
716
ac56dd48 717static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
718{
719 tcg_gen_add_i64(ret, arg1, tcg_const_i64(arg2));
720}
721
ac56dd48 722static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
723{
724 tcg_gen_op3(INDEX_op_sub_i64, ret, arg1, arg2);
725}
726
ac56dd48 727static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
728{
729 tcg_gen_sub_i64(ret, arg1, tcg_const_i64(arg2));
730}
731
ac56dd48 732static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
733{
734 tcg_gen_op3(INDEX_op_and_i64, ret, arg1, arg2);
735}
736
ac56dd48 737static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
738{
739 tcg_gen_and_i64(ret, arg1, tcg_const_i64(arg2));
740}
741
ac56dd48 742static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
743{
744 tcg_gen_op3(INDEX_op_or_i64, ret, arg1, arg2);
745}
746
ac56dd48 747static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
748{
749 tcg_gen_or_i64(ret, arg1, tcg_const_i64(arg2));
750}
751
ac56dd48 752static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
753{
754 tcg_gen_op3(INDEX_op_xor_i64, ret, arg1, arg2);
755}
756
ac56dd48 757static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
758{
759 tcg_gen_xor_i64(ret, arg1, tcg_const_i64(arg2));
760}
761
ac56dd48 762static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
763{
764 tcg_gen_op3(INDEX_op_shl_i64, ret, arg1, arg2);
765}
766
ac56dd48 767static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
768{
769 tcg_gen_shl_i64(ret, arg1, tcg_const_i64(arg2));
770}
771
ac56dd48 772static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
773{
774 tcg_gen_op3(INDEX_op_shr_i64, ret, arg1, arg2);
775}
776
ac56dd48 777static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
778{
779 tcg_gen_shr_i64(ret, arg1, tcg_const_i64(arg2));
780}
781
ac56dd48 782static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
783{
784 tcg_gen_op3(INDEX_op_sar_i64, ret, arg1, arg2);
785}
786
ac56dd48 787static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
c896fe29
FB
788{
789 tcg_gen_sar_i64(ret, arg1, tcg_const_i64(arg2));
790}
791
ac56dd48 792static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2,
c896fe29
FB
793 int label_index)
794{
ac56dd48 795 tcg_gen_op4ii(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
c896fe29
FB
796}
797
ac56dd48 798static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
799{
800 tcg_gen_op3(INDEX_op_mul_i64, ret, arg1, arg2);
801}
802
803#ifdef TCG_TARGET_HAS_div_i64
ac56dd48 804static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
805{
806 tcg_gen_op3(INDEX_op_div_i64, ret, arg1, arg2);
807}
808
ac56dd48 809static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
810{
811 tcg_gen_op3(INDEX_op_rem_i64, ret, arg1, arg2);
812}
813
ac56dd48 814static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
815{
816 tcg_gen_op3(INDEX_op_divu_i64, ret, arg1, arg2);
817}
818
ac56dd48 819static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29
FB
820{
821 tcg_gen_op3(INDEX_op_remu_i64, ret, arg1, arg2);
822}
823#else
ac56dd48 824static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 825{
ac56dd48 826 TCGv t0;
c896fe29
FB
827 t0 = tcg_temp_new(TCG_TYPE_I64);
828 tcg_gen_sari_i64(t0, arg1, 63);
829 tcg_gen_op5(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
830}
831
ac56dd48 832static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 833{
ac56dd48 834 TCGv t0;
c896fe29
FB
835 t0 = tcg_temp_new(TCG_TYPE_I64);
836 tcg_gen_sari_i64(t0, arg1, 63);
837 tcg_gen_op5(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
838}
839
ac56dd48 840static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 841{
ac56dd48 842 TCGv t0;
c896fe29
FB
843 t0 = tcg_temp_new(TCG_TYPE_I64);
844 tcg_gen_movi_i64(t0, 0);
845 tcg_gen_op5(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
846}
847
ac56dd48 848static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
c896fe29 849{
ac56dd48 850 TCGv t0;
c896fe29
FB
851 t0 = tcg_temp_new(TCG_TYPE_I64);
852 tcg_gen_movi_i64(t0, 0);
853 tcg_gen_op5(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
854}
855#endif
856
857#endif
858
859/***************************************/
860/* optional operations */
861
ac56dd48 862static inline void tcg_gen_ext8s_i32(TCGv ret, TCGv arg)
c896fe29
FB
863{
864#ifdef TCG_TARGET_HAS_ext8s_i32
865 tcg_gen_op2(INDEX_op_ext8s_i32, ret, arg);
866#else
867 tcg_gen_shli_i32(ret, arg, 24);
868 tcg_gen_sari_i32(ret, arg, 24);
869#endif
870}
871
ac56dd48 872static inline void tcg_gen_ext16s_i32(TCGv ret, TCGv arg)
c896fe29
FB
873{
874#ifdef TCG_TARGET_HAS_ext16s_i32
875 tcg_gen_op2(INDEX_op_ext16s_i32, ret, arg);
876#else
877 tcg_gen_shli_i32(ret, arg, 16);
878 tcg_gen_sari_i32(ret, arg, 16);
879#endif
880}
881
882/* Note: we assume the two high bytes are set to zero */
ac56dd48 883static inline void tcg_gen_bswap16_i32(TCGv ret, TCGv arg)
c896fe29
FB
884{
885#ifdef TCG_TARGET_HAS_bswap16_i32
886 tcg_gen_op2(INDEX_op_bswap16_i32, ret, arg);
887#else
ac56dd48 888 TCGv t0, t1;
c896fe29
FB
889 t0 = tcg_temp_new(TCG_TYPE_I32);
890 t1 = tcg_temp_new(TCG_TYPE_I32);
891
892 tcg_gen_shri_i32(t0, arg, 8);
893 tcg_gen_andi_i32(t1, arg, 0x000000ff);
894 tcg_gen_shli_i32(t1, t1, 8);
895 tcg_gen_or_i32(ret, t0, t1);
896#endif
897}
898
ac56dd48 899static inline void tcg_gen_bswap_i32(TCGv ret, TCGv arg)
c896fe29
FB
900{
901#ifdef TCG_TARGET_HAS_bswap_i32
902 tcg_gen_op2(INDEX_op_bswap_i32, ret, arg);
903#else
ac56dd48 904 TCGv t0, t1;
c896fe29
FB
905 t0 = tcg_temp_new(TCG_TYPE_I32);
906 t1 = tcg_temp_new(TCG_TYPE_I32);
907
908 tcg_gen_shli_i32(t0, arg, 24);
909
910 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
911 tcg_gen_shli_i32(t1, t1, 8);
912 tcg_gen_or_i32(t0, t0, t1);
913
914 tcg_gen_shri_i32(t1, arg, 8);
915 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
916 tcg_gen_or_i32(t0, t0, t1);
917
918 tcg_gen_shri_i32(t1, arg, 24);
919 tcg_gen_or_i32(ret, t0, t1);
920#endif
921}
922
923#if TCG_TARGET_REG_BITS == 32
ac56dd48 924static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
c896fe29
FB
925{
926 tcg_gen_ext8s_i32(ret, arg);
ac56dd48 927 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
928}
929
ac56dd48 930static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
c896fe29
FB
931{
932 tcg_gen_ext16s_i32(ret, arg);
ac56dd48 933 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
934}
935
ac56dd48 936static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
c896fe29
FB
937{
938 tcg_gen_mov_i32(ret, arg);
ac56dd48 939 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
940}
941
ac56dd48 942static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
c896fe29
FB
943{
944 tcg_gen_mov_i32(ret, arg);
945}
946
ac56dd48 947static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
c896fe29
FB
948{
949 tcg_gen_mov_i32(ret, arg);
ac56dd48 950 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
951}
952
ac56dd48 953static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
c896fe29
FB
954{
955 tcg_gen_mov_i32(ret, arg);
ac56dd48 956 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
957}
958
ac56dd48 959static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
c896fe29 960{
ac56dd48 961 TCGv t0, t1;
c896fe29
FB
962 t0 = tcg_temp_new(TCG_TYPE_I32);
963 t1 = tcg_temp_new(TCG_TYPE_I32);
964
965 tcg_gen_bswap_i32(t0, arg);
ac56dd48 966 tcg_gen_bswap_i32(t1, TCGV_HIGH(arg));
c896fe29 967 tcg_gen_mov_i32(ret, t1);
ac56dd48 968 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
c896fe29
FB
969}
970#else
971
ac56dd48 972static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
c896fe29
FB
973{
974#ifdef TCG_TARGET_HAS_ext8s_i64
975 tcg_gen_op2(INDEX_op_ext8s_i64, ret, arg);
976#else
977 tcg_gen_shli_i64(ret, arg, 56);
978 tcg_gen_sari_i64(ret, arg, 56);
979#endif
980}
981
ac56dd48 982static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
c896fe29
FB
983{
984#ifdef TCG_TARGET_HAS_ext16s_i64
985 tcg_gen_op2(INDEX_op_ext16s_i64, ret, arg);
986#else
987 tcg_gen_shli_i64(ret, arg, 48);
988 tcg_gen_sari_i64(ret, arg, 48);
989#endif
990}
991
ac56dd48 992static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
c896fe29
FB
993{
994#ifdef TCG_TARGET_HAS_ext32s_i64
995 tcg_gen_op2(INDEX_op_ext32s_i64, ret, arg);
996#else
997 tcg_gen_shli_i64(ret, arg, 32);
998 tcg_gen_sari_i64(ret, arg, 32);
999#endif
1000}
1001
1002/* Note: we assume the target supports move between 32 and 64 bit
ac56dd48
PB
1003 registers. This will probably break MIPS64 targets. */
1004static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
c896fe29
FB
1005{
1006 tcg_gen_mov_i32(ret, arg);
1007}
1008
1009/* Note: we assume the target supports move between 32 and 64 bit
1010 registers */
ac56dd48 1011static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
c896fe29
FB
1012{
1013 tcg_gen_andi_i64(ret, arg, 0xffffffff);
1014}
1015
1016/* Note: we assume the target supports move between 32 and 64 bit
1017 registers */
ac56dd48 1018static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
c896fe29
FB
1019{
1020 tcg_gen_ext32s_i64(ret, arg);
1021}
1022
ac56dd48 1023static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
c896fe29
FB
1024{
1025#ifdef TCG_TARGET_HAS_bswap_i64
1026 tcg_gen_op2(INDEX_op_bswap_i64, ret, arg);
1027#else
ac56dd48 1028 TCGv t0, t1;
c896fe29
FB
1029 t0 = tcg_temp_new(TCG_TYPE_I32);
1030 t1 = tcg_temp_new(TCG_TYPE_I32);
1031
1032 tcg_gen_shli_i64(t0, arg, 56);
1033
1034 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1035 tcg_gen_shli_i64(t1, t1, 40);
1036 tcg_gen_or_i64(t0, t0, t1);
1037
1038 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1039 tcg_gen_shli_i64(t1, t1, 24);
1040 tcg_gen_or_i64(t0, t0, t1);
1041
1042 tcg_gen_andi_i64(t1, arg, 0xff000000);
1043 tcg_gen_shli_i64(t1, t1, 8);
1044 tcg_gen_or_i64(t0, t0, t1);
1045
1046 tcg_gen_shri_i64(t1, arg, 8);
1047 tcg_gen_andi_i64(t1, t1, 0xff000000);
1048 tcg_gen_or_i64(t0, t0, t1);
1049
1050 tcg_gen_shri_i64(t1, arg, 24);
1051 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1052 tcg_gen_or_i64(t0, t0, t1);
1053
1054 tcg_gen_shri_i64(t1, arg, 40);
1055 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1056 tcg_gen_or_i64(t0, t0, t1);
1057
1058 tcg_gen_shri_i64(t1, arg, 56);
1059 tcg_gen_or_i64(ret, t0, t1);
1060#endif
1061}
1062
1063#endif
1064
1065/***************************************/
ac56dd48 1066static inline void tcg_gen_macro_2(TCGv ret0, TCGv ret1, int macro_id)
c896fe29 1067{
ac56dd48 1068 tcg_gen_op3i(INDEX_op_macro_2, ret0, ret1, macro_id);
c896fe29
FB
1069}
1070
1071/***************************************/
1072/* QEMU specific operations. Their type depend on the QEMU CPU
1073 type. */
1074#ifndef TARGET_LONG_BITS
1075#error must include QEMU headers
1076#endif
1077
1078static inline void tcg_gen_exit_tb(tcg_target_long val)
1079{
ac56dd48 1080 tcg_gen_op1i(INDEX_op_exit_tb, val);
c896fe29
FB
1081}
1082
1083static inline void tcg_gen_goto_tb(int idx)
1084{
ac56dd48 1085 tcg_gen_op1i(INDEX_op_goto_tb, idx);
c896fe29
FB
1086}
1087
1088#if TCG_TARGET_REG_BITS == 32
ac56dd48 1089static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1090{
1091#if TARGET_LONG_BITS == 32
ac56dd48 1092 tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29 1093#else
ac56dd48
PB
1094 tcg_gen_op4i(INDEX_op_qemu_ld8u, ret, addr, TCGV_HIGH(addr), mem_index);
1095 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1096#endif
1097}
1098
ac56dd48 1099static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1100{
1101#if TARGET_LONG_BITS == 32
ac56dd48 1102 tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29 1103#else
ac56dd48
PB
1104 tcg_gen_op4i(INDEX_op_qemu_ld8s, ret, addr, TCGV_HIGH(addr), mem_index);
1105 tcg_gen_ext8s_i32(TCGV_HIGH(ret), ret);
c896fe29
FB
1106#endif
1107}
1108
ac56dd48 1109static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1110{
1111#if TARGET_LONG_BITS == 32
ac56dd48 1112 tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29 1113#else
ac56dd48
PB
1114 tcg_gen_op4i(INDEX_op_qemu_ld16u, ret, addr, TCGV_HIGH(addr), mem_index);
1115 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1116#endif
1117}
1118
ac56dd48 1119static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1120{
1121#if TARGET_LONG_BITS == 32
ac56dd48 1122 tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29 1123#else
ac56dd48
PB
1124 tcg_gen_op4i(INDEX_op_qemu_ld16s, ret, addr, TCGV_HIGH(addr), mem_index);
1125 tcg_gen_ext16s_i32(TCGV_HIGH(ret), ret);
c896fe29
FB
1126#endif
1127}
1128
ac56dd48 1129static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1130{
1131#if TARGET_LONG_BITS == 32
ac56dd48 1132 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
c896fe29 1133#else
ac56dd48
PB
1134 tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
1135 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1136#endif
1137}
1138
ac56dd48 1139static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1140{
1141#if TARGET_LONG_BITS == 32
ac56dd48 1142 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
c896fe29 1143#else
ac56dd48
PB
1144 tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
1145 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
c896fe29
FB
1146#endif
1147}
1148
ac56dd48 1149static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
1150{
1151#if TARGET_LONG_BITS == 32
ac56dd48 1152 tcg_gen_op4i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret), addr, mem_index);
c896fe29 1153#else
ac56dd48
PB
1154 tcg_gen_op5i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret),
1155 addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1156#endif
1157}
1158
ac56dd48 1159static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
1160{
1161#if TARGET_LONG_BITS == 32
ac56dd48 1162 tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29 1163#else
ac56dd48 1164 tcg_gen_op4i(INDEX_op_qemu_st8, arg, addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1165#endif
1166}
1167
ac56dd48 1168static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
1169{
1170#if TARGET_LONG_BITS == 32
ac56dd48 1171 tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29 1172#else
ac56dd48 1173 tcg_gen_op4i(INDEX_op_qemu_st16, arg, addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1174#endif
1175}
1176
ac56dd48 1177static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
1178{
1179#if TARGET_LONG_BITS == 32
ac56dd48 1180 tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29 1181#else
ac56dd48 1182 tcg_gen_op4i(INDEX_op_qemu_st32, arg, addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1183#endif
1184}
1185
ac56dd48 1186static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
1187{
1188#if TARGET_LONG_BITS == 32
ac56dd48 1189 tcg_gen_op4i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg), addr, mem_index);
c896fe29 1190#else
ac56dd48
PB
1191 tcg_gen_op5i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg),
1192 addr, TCGV_HIGH(addr), mem_index);
c896fe29
FB
1193#endif
1194}
1195
1196#else /* TCG_TARGET_REG_BITS == 32 */
1197
ac56dd48 1198static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29 1199{
ac56dd48 1200 tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29
FB
1201}
1202
ac56dd48 1203static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29 1204{
ac56dd48 1205 tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29
FB
1206}
1207
ac56dd48 1208static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29 1209{
ac56dd48 1210 tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29
FB
1211}
1212
ac56dd48 1213static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29 1214{
ac56dd48 1215 tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29
FB
1216}
1217
ac56dd48 1218static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29 1219{
ac56dd48 1220 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
c896fe29
FB
1221}
1222
ac56dd48 1223static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29 1224{
ac56dd48 1225 tcg_gen_op3i(INDEX_op_qemu_ld32s, ret, addr, mem_index);
c896fe29
FB
1226}
1227
ac56dd48 1228static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
c896fe29 1229{
ac56dd48 1230 tcg_gen_op3i(INDEX_op_qemu_ld64, ret, addr, mem_index);
c896fe29
FB
1231}
1232
ac56dd48 1233static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29 1234{
ac56dd48 1235 tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29
FB
1236}
1237
ac56dd48 1238static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29 1239{
ac56dd48 1240 tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29
FB
1241}
1242
ac56dd48 1243static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29 1244{
ac56dd48 1245 tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29
FB
1246}
1247
ac56dd48 1248static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
c896fe29 1249{
ac56dd48 1250 tcg_gen_op3i(INDEX_op_qemu_st64, arg, addr, mem_index);
c896fe29
FB
1251}
1252
1253#endif /* TCG_TARGET_REG_BITS != 32 */