update VERSION for 1.4.1
[qemu.git] / tcg / tcg-op.h
blob91c9d80dd582c6a9e2cee9e737b138159e86b5b8
1 /*
2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2008 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 #include "tcg.h"
26 int gen_new_label(void);
28 static inline void tcg_gen_op0(TCGOpcode opc)
30 *tcg_ctx.gen_opc_ptr++ = opc;
33 static inline void tcg_gen_op1_i32(TCGOpcode opc, TCGv_i32 arg1)
35 *tcg_ctx.gen_opc_ptr++ = opc;
36 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
39 static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
41 *tcg_ctx.gen_opc_ptr++ = opc;
42 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
45 static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg arg1)
47 *tcg_ctx.gen_opc_ptr++ = opc;
48 *tcg_ctx.gen_opparam_ptr++ = arg1;
51 static inline void tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2)
53 *tcg_ctx.gen_opc_ptr++ = opc;
54 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
55 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
58 static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
60 *tcg_ctx.gen_opc_ptr++ = opc;
61 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
62 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
65 static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
67 *tcg_ctx.gen_opc_ptr++ = opc;
68 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
69 *tcg_ctx.gen_opparam_ptr++ = arg2;
72 static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
74 *tcg_ctx.gen_opc_ptr++ = opc;
75 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
76 *tcg_ctx.gen_opparam_ptr++ = arg2;
79 static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg arg1, TCGArg arg2)
81 *tcg_ctx.gen_opc_ptr++ = opc;
82 *tcg_ctx.gen_opparam_ptr++ = arg1;
83 *tcg_ctx.gen_opparam_ptr++ = arg2;
86 static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
87 TCGv_i32 arg3)
89 *tcg_ctx.gen_opc_ptr++ = opc;
90 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
91 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
92 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
95 static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
96 TCGv_i64 arg3)
98 *tcg_ctx.gen_opc_ptr++ = opc;
99 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
100 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
101 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
104 static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
105 TCGv_i32 arg2, TCGArg arg3)
107 *tcg_ctx.gen_opc_ptr++ = opc;
108 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
109 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
110 *tcg_ctx.gen_opparam_ptr++ = arg3;
113 static inline void tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 arg1,
114 TCGv_i64 arg2, TCGArg arg3)
116 *tcg_ctx.gen_opc_ptr++ = opc;
117 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
118 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
119 *tcg_ctx.gen_opparam_ptr++ = arg3;
122 static inline void tcg_gen_ldst_op_i32(TCGOpcode opc, TCGv_i32 val,
123 TCGv_ptr base, TCGArg offset)
125 *tcg_ctx.gen_opc_ptr++ = opc;
126 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(val);
127 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_PTR(base);
128 *tcg_ctx.gen_opparam_ptr++ = offset;
131 static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
132 TCGv_ptr base, TCGArg offset)
134 *tcg_ctx.gen_opc_ptr++ = opc;
135 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
136 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_PTR(base);
137 *tcg_ctx.gen_opparam_ptr++ = offset;
140 static inline void tcg_gen_qemu_ldst_op_i64_i32(TCGOpcode opc, TCGv_i64 val,
141 TCGv_i32 addr, TCGArg mem_index)
143 *tcg_ctx.gen_opc_ptr++ = opc;
144 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
145 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(addr);
146 *tcg_ctx.gen_opparam_ptr++ = mem_index;
149 static inline void tcg_gen_qemu_ldst_op_i64_i64(TCGOpcode opc, TCGv_i64 val,
150 TCGv_i64 addr, TCGArg mem_index)
152 *tcg_ctx.gen_opc_ptr++ = opc;
153 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
154 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(addr);
155 *tcg_ctx.gen_opparam_ptr++ = mem_index;
158 static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
159 TCGv_i32 arg3, TCGv_i32 arg4)
161 *tcg_ctx.gen_opc_ptr++ = opc;
162 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
163 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
164 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
165 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
168 static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
169 TCGv_i64 arg3, TCGv_i64 arg4)
171 *tcg_ctx.gen_opc_ptr++ = opc;
172 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
173 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
174 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
175 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
178 static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
179 TCGv_i32 arg3, TCGArg arg4)
181 *tcg_ctx.gen_opc_ptr++ = opc;
182 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
183 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
184 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
185 *tcg_ctx.gen_opparam_ptr++ = arg4;
188 static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
189 TCGv_i64 arg3, TCGArg arg4)
191 *tcg_ctx.gen_opc_ptr++ = opc;
192 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
193 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
194 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
195 *tcg_ctx.gen_opparam_ptr++ = arg4;
198 static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
199 TCGArg arg3, TCGArg arg4)
201 *tcg_ctx.gen_opc_ptr++ = opc;
202 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
203 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
204 *tcg_ctx.gen_opparam_ptr++ = arg3;
205 *tcg_ctx.gen_opparam_ptr++ = arg4;
208 static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
209 TCGArg arg3, TCGArg arg4)
211 *tcg_ctx.gen_opc_ptr++ = opc;
212 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
213 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
214 *tcg_ctx.gen_opparam_ptr++ = arg3;
215 *tcg_ctx.gen_opparam_ptr++ = arg4;
218 static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
219 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
221 *tcg_ctx.gen_opc_ptr++ = opc;
222 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
223 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
224 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
225 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
226 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
229 static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
230 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
232 *tcg_ctx.gen_opc_ptr++ = opc;
233 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
234 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
235 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
236 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
237 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
240 static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
241 TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
243 *tcg_ctx.gen_opc_ptr++ = opc;
244 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
245 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
246 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
247 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
248 *tcg_ctx.gen_opparam_ptr++ = arg5;
251 static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
252 TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
254 *tcg_ctx.gen_opc_ptr++ = opc;
255 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
256 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
257 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
258 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
259 *tcg_ctx.gen_opparam_ptr++ = arg5;
262 static inline void tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 arg1,
263 TCGv_i32 arg2, TCGv_i32 arg3,
264 TCGArg arg4, TCGArg arg5)
266 *tcg_ctx.gen_opc_ptr++ = opc;
267 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
268 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
269 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
270 *tcg_ctx.gen_opparam_ptr++ = arg4;
271 *tcg_ctx.gen_opparam_ptr++ = arg5;
274 static inline void tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 arg1,
275 TCGv_i64 arg2, TCGv_i64 arg3,
276 TCGArg arg4, TCGArg arg5)
278 *tcg_ctx.gen_opc_ptr++ = opc;
279 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
280 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
281 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
282 *tcg_ctx.gen_opparam_ptr++ = arg4;
283 *tcg_ctx.gen_opparam_ptr++ = arg5;
286 static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
287 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
288 TCGv_i32 arg6)
290 *tcg_ctx.gen_opc_ptr++ = opc;
291 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
292 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
293 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
294 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
295 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
296 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg6);
299 static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
300 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
301 TCGv_i64 arg6)
303 *tcg_ctx.gen_opc_ptr++ = opc;
304 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
305 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
306 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
307 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
308 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
309 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg6);
312 static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
313 TCGv_i32 arg3, TCGv_i32 arg4,
314 TCGv_i32 arg5, TCGArg arg6)
316 *tcg_ctx.gen_opc_ptr++ = opc;
317 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
318 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
319 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
320 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
321 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
322 *tcg_ctx.gen_opparam_ptr++ = arg6;
325 static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
326 TCGv_i64 arg3, TCGv_i64 arg4,
327 TCGv_i64 arg5, TCGArg arg6)
329 *tcg_ctx.gen_opc_ptr++ = opc;
330 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
331 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
332 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
333 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
334 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
335 *tcg_ctx.gen_opparam_ptr++ = arg6;
338 static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 arg1,
339 TCGv_i32 arg2, TCGv_i32 arg3,
340 TCGv_i32 arg4, TCGArg arg5, TCGArg arg6)
342 *tcg_ctx.gen_opc_ptr++ = opc;
343 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
344 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
345 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
346 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
347 *tcg_ctx.gen_opparam_ptr++ = arg5;
348 *tcg_ctx.gen_opparam_ptr++ = arg6;
351 static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 arg1,
352 TCGv_i64 arg2, TCGv_i64 arg3,
353 TCGv_i64 arg4, TCGArg arg5, TCGArg arg6)
355 *tcg_ctx.gen_opc_ptr++ = opc;
356 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
357 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
358 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
359 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
360 *tcg_ctx.gen_opparam_ptr++ = arg5;
361 *tcg_ctx.gen_opparam_ptr++ = arg6;
364 static inline void gen_set_label(int n)
366 tcg_gen_op1i(INDEX_op_set_label, n);
369 static inline void tcg_gen_br(int label)
371 tcg_gen_op1i(INDEX_op_br, label);
374 static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
376 if (!TCGV_EQUAL_I32(ret, arg))
377 tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
380 static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
382 tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
385 /* A version of dh_sizemask from def-helper.h that doesn't rely on
386 preprocessor magic. */
387 static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
389 return (is_64bit << n*2) | (is_signed << (n*2 + 1));
392 /* helper calls */
393 static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
394 TCGArg ret, int nargs, TCGArg *args)
396 TCGv_ptr fn;
397 fn = tcg_const_ptr(func);
398 tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
399 nargs, args);
400 tcg_temp_free_ptr(fn);
403 /* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
404 reserved for helpers in tcg-runtime.c. These helpers all do not read
405 globals and do not have side effects, hence the call to tcg_gen_callN()
406 with TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS. This may need
407 to be adjusted if these functions start to be used with other helpers. */
408 static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
409 TCGv_i32 a, TCGv_i32 b)
411 TCGv_ptr fn;
412 TCGArg args[2];
413 fn = tcg_const_ptr(func);
414 args[0] = GET_TCGV_I32(a);
415 args[1] = GET_TCGV_I32(b);
416 tcg_gen_callN(&tcg_ctx, fn,
417 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
418 sizemask, GET_TCGV_I32(ret), 2, args);
419 tcg_temp_free_ptr(fn);
422 static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
423 TCGv_i64 a, TCGv_i64 b)
425 TCGv_ptr fn;
426 TCGArg args[2];
427 fn = tcg_const_ptr(func);
428 args[0] = GET_TCGV_I64(a);
429 args[1] = GET_TCGV_I64(b);
430 tcg_gen_callN(&tcg_ctx, fn,
431 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
432 sizemask, GET_TCGV_I64(ret), 2, args);
433 tcg_temp_free_ptr(fn);
436 /* 32 bit ops */
438 static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
440 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
443 static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
445 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
448 static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
450 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
453 static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
455 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
458 static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
460 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
463 static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
465 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
468 static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
470 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
473 static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
475 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
478 static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
480 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
483 static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
485 /* some cases can be optimized here */
486 if (arg2 == 0) {
487 tcg_gen_mov_i32(ret, arg1);
488 } else {
489 TCGv_i32 t0 = tcg_const_i32(arg2);
490 tcg_gen_add_i32(ret, arg1, t0);
491 tcg_temp_free_i32(t0);
495 static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
497 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
500 static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
502 TCGv_i32 t0 = tcg_const_i32(arg1);
503 tcg_gen_sub_i32(ret, t0, arg2);
504 tcg_temp_free_i32(t0);
507 static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
509 /* some cases can be optimized here */
510 if (arg2 == 0) {
511 tcg_gen_mov_i32(ret, arg1);
512 } else {
513 TCGv_i32 t0 = tcg_const_i32(arg2);
514 tcg_gen_sub_i32(ret, arg1, t0);
515 tcg_temp_free_i32(t0);
519 static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
521 if (TCGV_EQUAL_I32(arg1, arg2)) {
522 tcg_gen_mov_i32(ret, arg1);
523 } else {
524 tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
528 static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
530 TCGv_i32 t0;
531 /* Some cases can be optimized here. */
532 switch (arg2) {
533 case 0:
534 tcg_gen_movi_i32(ret, 0);
535 return;
536 case 0xffffffffu:
537 tcg_gen_mov_i32(ret, arg1);
538 return;
539 case 0xffu:
540 /* Don't recurse with tcg_gen_ext8u_i32. */
541 if (TCG_TARGET_HAS_ext8u_i32) {
542 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg1);
543 return;
545 break;
546 case 0xffffu:
547 if (TCG_TARGET_HAS_ext16u_i32) {
548 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg1);
549 return;
551 break;
553 t0 = tcg_const_i32(arg2);
554 tcg_gen_and_i32(ret, arg1, t0);
555 tcg_temp_free_i32(t0);
558 static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
560 if (TCGV_EQUAL_I32(arg1, arg2)) {
561 tcg_gen_mov_i32(ret, arg1);
562 } else {
563 tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
567 static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
569 /* Some cases can be optimized here. */
570 if (arg2 == -1) {
571 tcg_gen_movi_i32(ret, -1);
572 } else if (arg2 == 0) {
573 tcg_gen_mov_i32(ret, arg1);
574 } else {
575 TCGv_i32 t0 = tcg_const_i32(arg2);
576 tcg_gen_or_i32(ret, arg1, t0);
577 tcg_temp_free_i32(t0);
581 static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
583 if (TCGV_EQUAL_I32(arg1, arg2)) {
584 tcg_gen_movi_i32(ret, 0);
585 } else {
586 tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
590 static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
592 /* Some cases can be optimized here. */
593 if (arg2 == 0) {
594 tcg_gen_mov_i32(ret, arg1);
595 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i32) {
596 /* Don't recurse with tcg_gen_not_i32. */
597 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg1);
598 } else {
599 TCGv_i32 t0 = tcg_const_i32(arg2);
600 tcg_gen_xor_i32(ret, arg1, t0);
601 tcg_temp_free_i32(t0);
605 static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
607 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
610 static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
612 if (arg2 == 0) {
613 tcg_gen_mov_i32(ret, arg1);
614 } else {
615 TCGv_i32 t0 = tcg_const_i32(arg2);
616 tcg_gen_shl_i32(ret, arg1, t0);
617 tcg_temp_free_i32(t0);
621 static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
623 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
626 static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
628 if (arg2 == 0) {
629 tcg_gen_mov_i32(ret, arg1);
630 } else {
631 TCGv_i32 t0 = tcg_const_i32(arg2);
632 tcg_gen_shr_i32(ret, arg1, t0);
633 tcg_temp_free_i32(t0);
637 static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
639 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
642 static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
644 if (arg2 == 0) {
645 tcg_gen_mov_i32(ret, arg1);
646 } else {
647 TCGv_i32 t0 = tcg_const_i32(arg2);
648 tcg_gen_sar_i32(ret, arg1, t0);
649 tcg_temp_free_i32(t0);
653 static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
654 TCGv_i32 arg2, int label_index)
656 if (cond == TCG_COND_ALWAYS) {
657 tcg_gen_br(label_index);
658 } else if (cond != TCG_COND_NEVER) {
659 tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
663 static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
664 int32_t arg2, int label_index)
666 if (cond == TCG_COND_ALWAYS) {
667 tcg_gen_br(label_index);
668 } else if (cond != TCG_COND_NEVER) {
669 TCGv_i32 t0 = tcg_const_i32(arg2);
670 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
671 tcg_temp_free_i32(t0);
675 static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
676 TCGv_i32 arg1, TCGv_i32 arg2)
678 if (cond == TCG_COND_ALWAYS) {
679 tcg_gen_movi_i32(ret, 1);
680 } else if (cond == TCG_COND_NEVER) {
681 tcg_gen_movi_i32(ret, 0);
682 } else {
683 tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
687 static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
688 TCGv_i32 arg1, int32_t arg2)
690 if (cond == TCG_COND_ALWAYS) {
691 tcg_gen_movi_i32(ret, 1);
692 } else if (cond == TCG_COND_NEVER) {
693 tcg_gen_movi_i32(ret, 0);
694 } else {
695 TCGv_i32 t0 = tcg_const_i32(arg2);
696 tcg_gen_setcond_i32(cond, ret, arg1, t0);
697 tcg_temp_free_i32(t0);
701 static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
703 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
706 static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
708 TCGv_i32 t0 = tcg_const_i32(arg2);
709 tcg_gen_mul_i32(ret, arg1, t0);
710 tcg_temp_free_i32(t0);
713 static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
715 if (TCG_TARGET_HAS_div_i32) {
716 tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
717 } else if (TCG_TARGET_HAS_div2_i32) {
718 TCGv_i32 t0 = tcg_temp_new_i32();
719 tcg_gen_sari_i32(t0, arg1, 31);
720 tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
721 tcg_temp_free_i32(t0);
722 } else {
723 int sizemask = 0;
724 /* Return value and both arguments are 32-bit and signed. */
725 sizemask |= tcg_gen_sizemask(0, 0, 1);
726 sizemask |= tcg_gen_sizemask(1, 0, 1);
727 sizemask |= tcg_gen_sizemask(2, 0, 1);
728 tcg_gen_helper32(tcg_helper_div_i32, sizemask, ret, arg1, arg2);
732 static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
734 if (TCG_TARGET_HAS_div_i32) {
735 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
736 } else if (TCG_TARGET_HAS_div2_i32) {
737 TCGv_i32 t0 = tcg_temp_new_i32();
738 tcg_gen_sari_i32(t0, arg1, 31);
739 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
740 tcg_temp_free_i32(t0);
741 } else {
742 int sizemask = 0;
743 /* Return value and both arguments are 32-bit and signed. */
744 sizemask |= tcg_gen_sizemask(0, 0, 1);
745 sizemask |= tcg_gen_sizemask(1, 0, 1);
746 sizemask |= tcg_gen_sizemask(2, 0, 1);
747 tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2);
751 static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
753 if (TCG_TARGET_HAS_div_i32) {
754 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
755 } else if (TCG_TARGET_HAS_div2_i32) {
756 TCGv_i32 t0 = tcg_temp_new_i32();
757 tcg_gen_movi_i32(t0, 0);
758 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
759 tcg_temp_free_i32(t0);
760 } else {
761 int sizemask = 0;
762 /* Return value and both arguments are 32-bit and unsigned. */
763 sizemask |= tcg_gen_sizemask(0, 0, 0);
764 sizemask |= tcg_gen_sizemask(1, 0, 0);
765 sizemask |= tcg_gen_sizemask(2, 0, 0);
766 tcg_gen_helper32(tcg_helper_divu_i32, sizemask, ret, arg1, arg2);
770 static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
772 if (TCG_TARGET_HAS_div_i32) {
773 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
774 } else if (TCG_TARGET_HAS_div2_i32) {
775 TCGv_i32 t0 = tcg_temp_new_i32();
776 tcg_gen_movi_i32(t0, 0);
777 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
778 tcg_temp_free_i32(t0);
779 } else {
780 int sizemask = 0;
781 /* Return value and both arguments are 32-bit and unsigned. */
782 sizemask |= tcg_gen_sizemask(0, 0, 0);
783 sizemask |= tcg_gen_sizemask(1, 0, 0);
784 sizemask |= tcg_gen_sizemask(2, 0, 0);
785 tcg_gen_helper32(tcg_helper_remu_i32, sizemask, ret, arg1, arg2);
789 #if TCG_TARGET_REG_BITS == 32
791 static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
793 if (!TCGV_EQUAL_I64(ret, arg)) {
794 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
795 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
799 static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
801 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
802 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
805 static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
806 tcg_target_long offset)
808 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
809 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
812 static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
813 tcg_target_long offset)
815 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
816 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
819 static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
820 tcg_target_long offset)
822 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
823 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
826 static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
827 tcg_target_long offset)
829 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
830 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
833 static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
834 tcg_target_long offset)
836 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
837 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
840 static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
841 tcg_target_long offset)
843 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
844 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
847 static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
848 tcg_target_long offset)
850 /* since arg2 and ret have different types, they cannot be the
851 same temporary */
852 #ifdef TCG_TARGET_WORDS_BIGENDIAN
853 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
854 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
855 #else
856 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
857 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
858 #endif
861 static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
862 tcg_target_long offset)
864 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
867 static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
868 tcg_target_long offset)
870 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
873 static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
874 tcg_target_long offset)
876 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
879 static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
880 tcg_target_long offset)
882 #ifdef TCG_TARGET_WORDS_BIGENDIAN
883 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
884 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
885 #else
886 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
887 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
888 #endif
891 static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
893 tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
894 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
895 TCGV_HIGH(arg2));
896 /* Allow the optimizer room to replace add2 with two moves. */
897 tcg_gen_op0(INDEX_op_nop);
900 static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
902 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
903 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
904 TCGV_HIGH(arg2));
905 /* Allow the optimizer room to replace sub2 with two moves. */
906 tcg_gen_op0(INDEX_op_nop);
909 static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
911 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
912 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
915 static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
917 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
918 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
921 static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
923 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
924 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
927 static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
929 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
930 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
933 static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
935 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
936 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
939 static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
941 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
942 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
945 /* XXX: use generic code when basic block handling is OK or CPU
946 specific code (x86) */
947 static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
949 int sizemask = 0;
950 /* Return value and both arguments are 64-bit and signed. */
951 sizemask |= tcg_gen_sizemask(0, 1, 1);
952 sizemask |= tcg_gen_sizemask(1, 1, 1);
953 sizemask |= tcg_gen_sizemask(2, 1, 1);
955 tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
958 static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
960 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
963 static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
965 int sizemask = 0;
966 /* Return value and both arguments are 64-bit and signed. */
967 sizemask |= tcg_gen_sizemask(0, 1, 1);
968 sizemask |= tcg_gen_sizemask(1, 1, 1);
969 sizemask |= tcg_gen_sizemask(2, 1, 1);
971 tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
974 static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
976 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
979 static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
981 int sizemask = 0;
982 /* Return value and both arguments are 64-bit and signed. */
983 sizemask |= tcg_gen_sizemask(0, 1, 1);
984 sizemask |= tcg_gen_sizemask(1, 1, 1);
985 sizemask |= tcg_gen_sizemask(2, 1, 1);
987 tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
990 static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
992 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
995 static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
996 TCGv_i64 arg2, int label_index)
998 if (cond == TCG_COND_ALWAYS) {
999 tcg_gen_br(label_index);
1000 } else if (cond != TCG_COND_NEVER) {
1001 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
1002 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
1003 TCGV_HIGH(arg2), cond, label_index);
1007 static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1008 TCGv_i64 arg1, TCGv_i64 arg2)
1010 if (cond == TCG_COND_ALWAYS) {
1011 tcg_gen_movi_i32(TCGV_LOW(ret), 1);
1012 } else if (cond == TCG_COND_NEVER) {
1013 tcg_gen_movi_i32(TCGV_LOW(ret), 0);
1014 } else {
1015 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
1016 TCGV_LOW(arg1), TCGV_HIGH(arg1),
1017 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
1019 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1022 static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1024 TCGv_i64 t0;
1025 TCGv_i32 t1;
1027 t0 = tcg_temp_new_i64();
1028 t1 = tcg_temp_new_i32();
1030 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
1031 TCGV_LOW(arg1), TCGV_LOW(arg2));
1032 /* Allow the optimizer room to replace mulu2 with two moves. */
1033 tcg_gen_op0(INDEX_op_nop);
1035 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
1036 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
1037 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
1038 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
1040 tcg_gen_mov_i64(ret, t0);
1041 tcg_temp_free_i64(t0);
1042 tcg_temp_free_i32(t1);
1045 static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1047 int sizemask = 0;
1048 /* Return value and both arguments are 64-bit and signed. */
1049 sizemask |= tcg_gen_sizemask(0, 1, 1);
1050 sizemask |= tcg_gen_sizemask(1, 1, 1);
1051 sizemask |= tcg_gen_sizemask(2, 1, 1);
1053 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
1056 static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1058 int sizemask = 0;
1059 /* Return value and both arguments are 64-bit and signed. */
1060 sizemask |= tcg_gen_sizemask(0, 1, 1);
1061 sizemask |= tcg_gen_sizemask(1, 1, 1);
1062 sizemask |= tcg_gen_sizemask(2, 1, 1);
1064 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1067 static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1069 int sizemask = 0;
1070 /* Return value and both arguments are 64-bit and unsigned. */
1071 sizemask |= tcg_gen_sizemask(0, 1, 0);
1072 sizemask |= tcg_gen_sizemask(1, 1, 0);
1073 sizemask |= tcg_gen_sizemask(2, 1, 0);
1075 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1078 static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1080 int sizemask = 0;
1081 /* Return value and both arguments are 64-bit and unsigned. */
1082 sizemask |= tcg_gen_sizemask(0, 1, 0);
1083 sizemask |= tcg_gen_sizemask(1, 1, 0);
1084 sizemask |= tcg_gen_sizemask(2, 1, 0);
1086 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1089 #else
1091 static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
1093 if (!TCGV_EQUAL_I64(ret, arg))
1094 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
1097 static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
1099 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
1102 static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1103 tcg_target_long offset)
1105 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
1108 static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1109 tcg_target_long offset)
1111 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
1114 static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1115 tcg_target_long offset)
1117 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
1120 static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1121 tcg_target_long offset)
1123 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
1126 static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1127 tcg_target_long offset)
1129 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
1132 static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1133 tcg_target_long offset)
1135 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
1138 static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
1140 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
1143 static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1144 tcg_target_long offset)
1146 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
1149 static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1150 tcg_target_long offset)
1152 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
1155 static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1156 tcg_target_long offset)
1158 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
1161 static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
1163 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
1166 static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1168 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
1171 static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1173 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
1176 static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1178 if (TCGV_EQUAL_I64(arg1, arg2)) {
1179 tcg_gen_mov_i64(ret, arg1);
1180 } else {
1181 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1185 static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
1187 TCGv_i64 t0;
1188 /* Some cases can be optimized here. */
1189 switch (arg2) {
1190 case 0:
1191 tcg_gen_movi_i64(ret, 0);
1192 return;
1193 case 0xffffffffffffffffull:
1194 tcg_gen_mov_i64(ret, arg1);
1195 return;
1196 case 0xffull:
1197 /* Don't recurse with tcg_gen_ext8u_i32. */
1198 if (TCG_TARGET_HAS_ext8u_i64) {
1199 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg1);
1200 return;
1202 break;
1203 case 0xffffu:
1204 if (TCG_TARGET_HAS_ext16u_i64) {
1205 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg1);
1206 return;
1208 break;
1209 case 0xffffffffull:
1210 if (TCG_TARGET_HAS_ext32u_i64) {
1211 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg1);
1212 return;
1214 break;
1216 t0 = tcg_const_i64(arg2);
1217 tcg_gen_and_i64(ret, arg1, t0);
1218 tcg_temp_free_i64(t0);
1221 static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1223 if (TCGV_EQUAL_I64(arg1, arg2)) {
1224 tcg_gen_mov_i64(ret, arg1);
1225 } else {
1226 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1230 static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1232 /* Some cases can be optimized here. */
1233 if (arg2 == -1) {
1234 tcg_gen_movi_i64(ret, -1);
1235 } else if (arg2 == 0) {
1236 tcg_gen_mov_i64(ret, arg1);
1237 } else {
1238 TCGv_i64 t0 = tcg_const_i64(arg2);
1239 tcg_gen_or_i64(ret, arg1, t0);
1240 tcg_temp_free_i64(t0);
1244 static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1246 if (TCGV_EQUAL_I64(arg1, arg2)) {
1247 tcg_gen_movi_i64(ret, 0);
1248 } else {
1249 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1253 static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1255 /* Some cases can be optimized here. */
1256 if (arg2 == 0) {
1257 tcg_gen_mov_i64(ret, arg1);
1258 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i64) {
1259 /* Don't recurse with tcg_gen_not_i64. */
1260 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
1261 } else {
1262 TCGv_i64 t0 = tcg_const_i64(arg2);
1263 tcg_gen_xor_i64(ret, arg1, t0);
1264 tcg_temp_free_i64(t0);
1268 static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1270 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
1273 static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1275 if (arg2 == 0) {
1276 tcg_gen_mov_i64(ret, arg1);
1277 } else {
1278 TCGv_i64 t0 = tcg_const_i64(arg2);
1279 tcg_gen_shl_i64(ret, arg1, t0);
1280 tcg_temp_free_i64(t0);
1284 static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1286 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
1289 static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1291 if (arg2 == 0) {
1292 tcg_gen_mov_i64(ret, arg1);
1293 } else {
1294 TCGv_i64 t0 = tcg_const_i64(arg2);
1295 tcg_gen_shr_i64(ret, arg1, t0);
1296 tcg_temp_free_i64(t0);
1300 static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1302 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
1305 static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1307 if (arg2 == 0) {
1308 tcg_gen_mov_i64(ret, arg1);
1309 } else {
1310 TCGv_i64 t0 = tcg_const_i64(arg2);
1311 tcg_gen_sar_i64(ret, arg1, t0);
1312 tcg_temp_free_i64(t0);
1316 static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1317 TCGv_i64 arg2, int label_index)
1319 if (cond == TCG_COND_ALWAYS) {
1320 tcg_gen_br(label_index);
1321 } else if (cond != TCG_COND_NEVER) {
1322 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
1326 static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1327 TCGv_i64 arg1, TCGv_i64 arg2)
1329 if (cond == TCG_COND_ALWAYS) {
1330 tcg_gen_movi_i64(ret, 1);
1331 } else if (cond == TCG_COND_NEVER) {
1332 tcg_gen_movi_i64(ret, 0);
1333 } else {
1334 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1338 static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1340 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
1343 static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1345 if (TCG_TARGET_HAS_div_i64) {
1346 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
1347 } else if (TCG_TARGET_HAS_div2_i64) {
1348 TCGv_i64 t0 = tcg_temp_new_i64();
1349 tcg_gen_sari_i64(t0, arg1, 63);
1350 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1351 tcg_temp_free_i64(t0);
1352 } else {
1353 int sizemask = 0;
1354 /* Return value and both arguments are 64-bit and signed. */
1355 sizemask |= tcg_gen_sizemask(0, 1, 1);
1356 sizemask |= tcg_gen_sizemask(1, 1, 1);
1357 sizemask |= tcg_gen_sizemask(2, 1, 1);
1358 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
1362 static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1364 if (TCG_TARGET_HAS_div_i64) {
1365 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
1366 } else if (TCG_TARGET_HAS_div2_i64) {
1367 TCGv_i64 t0 = tcg_temp_new_i64();
1368 tcg_gen_sari_i64(t0, arg1, 63);
1369 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1370 tcg_temp_free_i64(t0);
1371 } else {
1372 int sizemask = 0;
1373 /* Return value and both arguments are 64-bit and signed. */
1374 sizemask |= tcg_gen_sizemask(0, 1, 1);
1375 sizemask |= tcg_gen_sizemask(1, 1, 1);
1376 sizemask |= tcg_gen_sizemask(2, 1, 1);
1377 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1381 static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1383 if (TCG_TARGET_HAS_div_i64) {
1384 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
1385 } else if (TCG_TARGET_HAS_div2_i64) {
1386 TCGv_i64 t0 = tcg_temp_new_i64();
1387 tcg_gen_movi_i64(t0, 0);
1388 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1389 tcg_temp_free_i64(t0);
1390 } else {
1391 int sizemask = 0;
1392 /* Return value and both arguments are 64-bit and unsigned. */
1393 sizemask |= tcg_gen_sizemask(0, 1, 0);
1394 sizemask |= tcg_gen_sizemask(1, 1, 0);
1395 sizemask |= tcg_gen_sizemask(2, 1, 0);
1396 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1400 static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1402 if (TCG_TARGET_HAS_div_i64) {
1403 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
1404 } else if (TCG_TARGET_HAS_div2_i64) {
1405 TCGv_i64 t0 = tcg_temp_new_i64();
1406 tcg_gen_movi_i64(t0, 0);
1407 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1408 tcg_temp_free_i64(t0);
1409 } else {
1410 int sizemask = 0;
1411 /* Return value and both arguments are 64-bit and unsigned. */
1412 sizemask |= tcg_gen_sizemask(0, 1, 0);
1413 sizemask |= tcg_gen_sizemask(1, 1, 0);
1414 sizemask |= tcg_gen_sizemask(2, 1, 0);
1415 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1418 #endif /* TCG_TARGET_REG_BITS == 32 */
1420 static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1422 /* some cases can be optimized here */
1423 if (arg2 == 0) {
1424 tcg_gen_mov_i64(ret, arg1);
1425 } else {
1426 TCGv_i64 t0 = tcg_const_i64(arg2);
1427 tcg_gen_add_i64(ret, arg1, t0);
1428 tcg_temp_free_i64(t0);
1432 static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
1434 TCGv_i64 t0 = tcg_const_i64(arg1);
1435 tcg_gen_sub_i64(ret, t0, arg2);
1436 tcg_temp_free_i64(t0);
1439 static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1441 /* some cases can be optimized here */
1442 if (arg2 == 0) {
1443 tcg_gen_mov_i64(ret, arg1);
1444 } else {
1445 TCGv_i64 t0 = tcg_const_i64(arg2);
1446 tcg_gen_sub_i64(ret, arg1, t0);
1447 tcg_temp_free_i64(t0);
1450 static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1451 int64_t arg2, int label_index)
1453 if (cond == TCG_COND_ALWAYS) {
1454 tcg_gen_br(label_index);
1455 } else if (cond != TCG_COND_NEVER) {
1456 TCGv_i64 t0 = tcg_const_i64(arg2);
1457 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1458 tcg_temp_free_i64(t0);
1462 static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1463 TCGv_i64 arg1, int64_t arg2)
1465 TCGv_i64 t0 = tcg_const_i64(arg2);
1466 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1467 tcg_temp_free_i64(t0);
1470 static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1472 TCGv_i64 t0 = tcg_const_i64(arg2);
1473 tcg_gen_mul_i64(ret, arg1, t0);
1474 tcg_temp_free_i64(t0);
1478 /***************************************/
1479 /* optional operations */
1481 static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
1483 if (TCG_TARGET_HAS_ext8s_i32) {
1484 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
1485 } else {
1486 tcg_gen_shli_i32(ret, arg, 24);
1487 tcg_gen_sari_i32(ret, ret, 24);
1491 static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
1493 if (TCG_TARGET_HAS_ext16s_i32) {
1494 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
1495 } else {
1496 tcg_gen_shli_i32(ret, arg, 16);
1497 tcg_gen_sari_i32(ret, ret, 16);
1501 static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
1503 if (TCG_TARGET_HAS_ext8u_i32) {
1504 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1505 } else {
1506 tcg_gen_andi_i32(ret, arg, 0xffu);
1510 static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
1512 if (TCG_TARGET_HAS_ext16u_i32) {
1513 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1514 } else {
1515 tcg_gen_andi_i32(ret, arg, 0xffffu);
1519 /* Note: we assume the two high bytes are set to zero */
1520 static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
1522 if (TCG_TARGET_HAS_bswap16_i32) {
1523 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
1524 } else {
1525 TCGv_i32 t0 = tcg_temp_new_i32();
1527 tcg_gen_ext8u_i32(t0, arg);
1528 tcg_gen_shli_i32(t0, t0, 8);
1529 tcg_gen_shri_i32(ret, arg, 8);
1530 tcg_gen_or_i32(ret, ret, t0);
1531 tcg_temp_free_i32(t0);
1535 static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
1537 if (TCG_TARGET_HAS_bswap32_i32) {
1538 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
1539 } else {
1540 TCGv_i32 t0, t1;
1541 t0 = tcg_temp_new_i32();
1542 t1 = tcg_temp_new_i32();
1544 tcg_gen_shli_i32(t0, arg, 24);
1546 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1547 tcg_gen_shli_i32(t1, t1, 8);
1548 tcg_gen_or_i32(t0, t0, t1);
1550 tcg_gen_shri_i32(t1, arg, 8);
1551 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1552 tcg_gen_or_i32(t0, t0, t1);
1554 tcg_gen_shri_i32(t1, arg, 24);
1555 tcg_gen_or_i32(ret, t0, t1);
1556 tcg_temp_free_i32(t0);
1557 tcg_temp_free_i32(t1);
1561 #if TCG_TARGET_REG_BITS == 32
1562 static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
1564 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1565 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1568 static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
1570 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1571 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1574 static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
1576 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1577 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1580 static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
1582 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1583 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1586 static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
1588 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1589 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1592 static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
1594 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1595 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1598 static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
1600 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
1603 static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1605 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1606 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1609 static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1611 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1612 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1615 /* Note: we assume the six high bytes are set to zero */
1616 static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1618 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1619 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1622 /* Note: we assume the four high bytes are set to zero */
1623 static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1625 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1626 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1629 static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
1631 TCGv_i32 t0, t1;
1632 t0 = tcg_temp_new_i32();
1633 t1 = tcg_temp_new_i32();
1635 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1636 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
1637 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
1638 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
1639 tcg_temp_free_i32(t0);
1640 tcg_temp_free_i32(t1);
1642 #else
1644 static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
1646 if (TCG_TARGET_HAS_ext8s_i64) {
1647 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
1648 } else {
1649 tcg_gen_shli_i64(ret, arg, 56);
1650 tcg_gen_sari_i64(ret, ret, 56);
1654 static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
1656 if (TCG_TARGET_HAS_ext16s_i64) {
1657 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
1658 } else {
1659 tcg_gen_shli_i64(ret, arg, 48);
1660 tcg_gen_sari_i64(ret, ret, 48);
1664 static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
1666 if (TCG_TARGET_HAS_ext32s_i64) {
1667 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
1668 } else {
1669 tcg_gen_shli_i64(ret, arg, 32);
1670 tcg_gen_sari_i64(ret, ret, 32);
1674 static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
1676 if (TCG_TARGET_HAS_ext8u_i64) {
1677 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1678 } else {
1679 tcg_gen_andi_i64(ret, arg, 0xffu);
1683 static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
1685 if (TCG_TARGET_HAS_ext16u_i64) {
1686 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1687 } else {
1688 tcg_gen_andi_i64(ret, arg, 0xffffu);
1692 static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
1694 if (TCG_TARGET_HAS_ext32u_i64) {
1695 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1696 } else {
1697 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1701 /* Note: we assume the target supports move between 32 and 64 bit
1702 registers. This will probably break MIPS64 targets. */
1703 static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
1705 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
1708 /* Note: we assume the target supports move between 32 and 64 bit
1709 registers */
1710 static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1712 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
1715 /* Note: we assume the target supports move between 32 and 64 bit
1716 registers */
1717 static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1719 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
1722 /* Note: we assume the six high bytes are set to zero */
1723 static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1725 if (TCG_TARGET_HAS_bswap16_i64) {
1726 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1727 } else {
1728 TCGv_i64 t0 = tcg_temp_new_i64();
1730 tcg_gen_ext8u_i64(t0, arg);
1731 tcg_gen_shli_i64(t0, t0, 8);
1732 tcg_gen_shri_i64(ret, arg, 8);
1733 tcg_gen_or_i64(ret, ret, t0);
1734 tcg_temp_free_i64(t0);
1738 /* Note: we assume the four high bytes are set to zero */
1739 static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1741 if (TCG_TARGET_HAS_bswap32_i64) {
1742 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1743 } else {
1744 TCGv_i64 t0, t1;
1745 t0 = tcg_temp_new_i64();
1746 t1 = tcg_temp_new_i64();
1748 tcg_gen_shli_i64(t0, arg, 24);
1749 tcg_gen_ext32u_i64(t0, t0);
1751 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1752 tcg_gen_shli_i64(t1, t1, 8);
1753 tcg_gen_or_i64(t0, t0, t1);
1755 tcg_gen_shri_i64(t1, arg, 8);
1756 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1757 tcg_gen_or_i64(t0, t0, t1);
1759 tcg_gen_shri_i64(t1, arg, 24);
1760 tcg_gen_or_i64(ret, t0, t1);
1761 tcg_temp_free_i64(t0);
1762 tcg_temp_free_i64(t1);
1766 static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
1768 if (TCG_TARGET_HAS_bswap64_i64) {
1769 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
1770 } else {
1771 TCGv_i64 t0 = tcg_temp_new_i64();
1772 TCGv_i64 t1 = tcg_temp_new_i64();
1774 tcg_gen_shli_i64(t0, arg, 56);
1776 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1777 tcg_gen_shli_i64(t1, t1, 40);
1778 tcg_gen_or_i64(t0, t0, t1);
1780 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1781 tcg_gen_shli_i64(t1, t1, 24);
1782 tcg_gen_or_i64(t0, t0, t1);
1784 tcg_gen_andi_i64(t1, arg, 0xff000000);
1785 tcg_gen_shli_i64(t1, t1, 8);
1786 tcg_gen_or_i64(t0, t0, t1);
1788 tcg_gen_shri_i64(t1, arg, 8);
1789 tcg_gen_andi_i64(t1, t1, 0xff000000);
1790 tcg_gen_or_i64(t0, t0, t1);
1792 tcg_gen_shri_i64(t1, arg, 24);
1793 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1794 tcg_gen_or_i64(t0, t0, t1);
1796 tcg_gen_shri_i64(t1, arg, 40);
1797 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1798 tcg_gen_or_i64(t0, t0, t1);
1800 tcg_gen_shri_i64(t1, arg, 56);
1801 tcg_gen_or_i64(ret, t0, t1);
1802 tcg_temp_free_i64(t0);
1803 tcg_temp_free_i64(t1);
1807 #endif
1809 static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
1811 if (TCG_TARGET_HAS_neg_i32) {
1812 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
1813 } else {
1814 TCGv_i32 t0 = tcg_const_i32(0);
1815 tcg_gen_sub_i32(ret, t0, arg);
1816 tcg_temp_free_i32(t0);
1820 static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
1822 if (TCG_TARGET_HAS_neg_i64) {
1823 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
1824 } else {
1825 TCGv_i64 t0 = tcg_const_i64(0);
1826 tcg_gen_sub_i64(ret, t0, arg);
1827 tcg_temp_free_i64(t0);
1831 static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
1833 if (TCG_TARGET_HAS_not_i32) {
1834 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1835 } else {
1836 tcg_gen_xori_i32(ret, arg, -1);
1840 static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
1842 #if TCG_TARGET_REG_BITS == 64
1843 if (TCG_TARGET_HAS_not_i64) {
1844 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
1845 } else {
1846 tcg_gen_xori_i64(ret, arg, -1);
1848 #else
1849 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1850 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1851 #endif
1854 static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1856 tcg_gen_op1_i32(INDEX_op_discard, arg);
1859 static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1861 #if TCG_TARGET_REG_BITS == 32
1862 tcg_gen_discard_i32(TCGV_LOW(arg));
1863 tcg_gen_discard_i32(TCGV_HIGH(arg));
1864 #else
1865 tcg_gen_op1_i64(INDEX_op_discard, arg);
1866 #endif
1869 static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1871 if (TCG_TARGET_HAS_andc_i32) {
1872 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1873 } else {
1874 TCGv_i32 t0 = tcg_temp_new_i32();
1875 tcg_gen_not_i32(t0, arg2);
1876 tcg_gen_and_i32(ret, arg1, t0);
1877 tcg_temp_free_i32(t0);
1881 static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1883 #if TCG_TARGET_REG_BITS == 64
1884 if (TCG_TARGET_HAS_andc_i64) {
1885 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1886 } else {
1887 TCGv_i64 t0 = tcg_temp_new_i64();
1888 tcg_gen_not_i64(t0, arg2);
1889 tcg_gen_and_i64(ret, arg1, t0);
1890 tcg_temp_free_i64(t0);
1892 #else
1893 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1894 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1895 #endif
1898 static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1900 if (TCG_TARGET_HAS_eqv_i32) {
1901 tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
1902 } else {
1903 tcg_gen_xor_i32(ret, arg1, arg2);
1904 tcg_gen_not_i32(ret, ret);
1908 static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1910 #if TCG_TARGET_REG_BITS == 64
1911 if (TCG_TARGET_HAS_eqv_i64) {
1912 tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
1913 } else {
1914 tcg_gen_xor_i64(ret, arg1, arg2);
1915 tcg_gen_not_i64(ret, ret);
1917 #else
1918 tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1919 tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1920 #endif
1923 static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1925 if (TCG_TARGET_HAS_nand_i32) {
1926 tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
1927 } else {
1928 tcg_gen_and_i32(ret, arg1, arg2);
1929 tcg_gen_not_i32(ret, ret);
1933 static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1935 #if TCG_TARGET_REG_BITS == 64
1936 if (TCG_TARGET_HAS_nand_i64) {
1937 tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
1938 } else {
1939 tcg_gen_and_i64(ret, arg1, arg2);
1940 tcg_gen_not_i64(ret, ret);
1942 #else
1943 tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1944 tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1945 #endif
1948 static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1950 if (TCG_TARGET_HAS_nor_i32) {
1951 tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
1952 } else {
1953 tcg_gen_or_i32(ret, arg1, arg2);
1954 tcg_gen_not_i32(ret, ret);
1958 static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1960 #if TCG_TARGET_REG_BITS == 64
1961 if (TCG_TARGET_HAS_nor_i64) {
1962 tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
1963 } else {
1964 tcg_gen_or_i64(ret, arg1, arg2);
1965 tcg_gen_not_i64(ret, ret);
1967 #else
1968 tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1969 tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1970 #endif
1973 static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1975 if (TCG_TARGET_HAS_orc_i32) {
1976 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
1977 } else {
1978 TCGv_i32 t0 = tcg_temp_new_i32();
1979 tcg_gen_not_i32(t0, arg2);
1980 tcg_gen_or_i32(ret, arg1, t0);
1981 tcg_temp_free_i32(t0);
1985 static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1987 #if TCG_TARGET_REG_BITS == 64
1988 if (TCG_TARGET_HAS_orc_i64) {
1989 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
1990 } else {
1991 TCGv_i64 t0 = tcg_temp_new_i64();
1992 tcg_gen_not_i64(t0, arg2);
1993 tcg_gen_or_i64(ret, arg1, t0);
1994 tcg_temp_free_i64(t0);
1996 #else
1997 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1998 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1999 #endif
2002 static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2004 if (TCG_TARGET_HAS_rot_i32) {
2005 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
2006 } else {
2007 TCGv_i32 t0, t1;
2009 t0 = tcg_temp_new_i32();
2010 t1 = tcg_temp_new_i32();
2011 tcg_gen_shl_i32(t0, arg1, arg2);
2012 tcg_gen_subfi_i32(t1, 32, arg2);
2013 tcg_gen_shr_i32(t1, arg1, t1);
2014 tcg_gen_or_i32(ret, t0, t1);
2015 tcg_temp_free_i32(t0);
2016 tcg_temp_free_i32(t1);
2020 static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2022 if (TCG_TARGET_HAS_rot_i64) {
2023 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
2024 } else {
2025 TCGv_i64 t0, t1;
2026 t0 = tcg_temp_new_i64();
2027 t1 = tcg_temp_new_i64();
2028 tcg_gen_shl_i64(t0, arg1, arg2);
2029 tcg_gen_subfi_i64(t1, 64, arg2);
2030 tcg_gen_shr_i64(t1, arg1, t1);
2031 tcg_gen_or_i64(ret, t0, t1);
2032 tcg_temp_free_i64(t0);
2033 tcg_temp_free_i64(t1);
2037 static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2039 /* some cases can be optimized here */
2040 if (arg2 == 0) {
2041 tcg_gen_mov_i32(ret, arg1);
2042 } else if (TCG_TARGET_HAS_rot_i32) {
2043 TCGv_i32 t0 = tcg_const_i32(arg2);
2044 tcg_gen_rotl_i32(ret, arg1, t0);
2045 tcg_temp_free_i32(t0);
2046 } else {
2047 TCGv_i32 t0, t1;
2048 t0 = tcg_temp_new_i32();
2049 t1 = tcg_temp_new_i32();
2050 tcg_gen_shli_i32(t0, arg1, arg2);
2051 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
2052 tcg_gen_or_i32(ret, t0, t1);
2053 tcg_temp_free_i32(t0);
2054 tcg_temp_free_i32(t1);
2058 static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2060 /* some cases can be optimized here */
2061 if (arg2 == 0) {
2062 tcg_gen_mov_i64(ret, arg1);
2063 } else if (TCG_TARGET_HAS_rot_i64) {
2064 TCGv_i64 t0 = tcg_const_i64(arg2);
2065 tcg_gen_rotl_i64(ret, arg1, t0);
2066 tcg_temp_free_i64(t0);
2067 } else {
2068 TCGv_i64 t0, t1;
2069 t0 = tcg_temp_new_i64();
2070 t1 = tcg_temp_new_i64();
2071 tcg_gen_shli_i64(t0, arg1, arg2);
2072 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
2073 tcg_gen_or_i64(ret, t0, t1);
2074 tcg_temp_free_i64(t0);
2075 tcg_temp_free_i64(t1);
2079 static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2081 if (TCG_TARGET_HAS_rot_i32) {
2082 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
2083 } else {
2084 TCGv_i32 t0, t1;
2086 t0 = tcg_temp_new_i32();
2087 t1 = tcg_temp_new_i32();
2088 tcg_gen_shr_i32(t0, arg1, arg2);
2089 tcg_gen_subfi_i32(t1, 32, arg2);
2090 tcg_gen_shl_i32(t1, arg1, t1);
2091 tcg_gen_or_i32(ret, t0, t1);
2092 tcg_temp_free_i32(t0);
2093 tcg_temp_free_i32(t1);
2097 static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2099 if (TCG_TARGET_HAS_rot_i64) {
2100 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
2101 } else {
2102 TCGv_i64 t0, t1;
2103 t0 = tcg_temp_new_i64();
2104 t1 = tcg_temp_new_i64();
2105 tcg_gen_shr_i64(t0, arg1, arg2);
2106 tcg_gen_subfi_i64(t1, 64, arg2);
2107 tcg_gen_shl_i64(t1, arg1, t1);
2108 tcg_gen_or_i64(ret, t0, t1);
2109 tcg_temp_free_i64(t0);
2110 tcg_temp_free_i64(t1);
2114 static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2116 /* some cases can be optimized here */
2117 if (arg2 == 0) {
2118 tcg_gen_mov_i32(ret, arg1);
2119 } else {
2120 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
2124 static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2126 /* some cases can be optimized here */
2127 if (arg2 == 0) {
2128 tcg_gen_mov_i64(ret, arg1);
2129 } else {
2130 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2134 static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
2135 TCGv_i32 arg2, unsigned int ofs,
2136 unsigned int len)
2138 uint32_t mask;
2139 TCGv_i32 t1;
2141 tcg_debug_assert(ofs < 32);
2142 tcg_debug_assert(len <= 32);
2143 tcg_debug_assert(ofs + len <= 32);
2145 if (ofs == 0 && len == 32) {
2146 tcg_gen_mov_i32(ret, arg2);
2147 return;
2149 if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
2150 tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
2151 return;
2154 mask = (1u << len) - 1;
2155 t1 = tcg_temp_new_i32();
2157 if (ofs + len < 32) {
2158 tcg_gen_andi_i32(t1, arg2, mask);
2159 tcg_gen_shli_i32(t1, t1, ofs);
2160 } else {
2161 tcg_gen_shli_i32(t1, arg2, ofs);
2163 tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
2164 tcg_gen_or_i32(ret, ret, t1);
2166 tcg_temp_free_i32(t1);
2169 static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
2170 TCGv_i64 arg2, unsigned int ofs,
2171 unsigned int len)
2173 uint64_t mask;
2174 TCGv_i64 t1;
2176 tcg_debug_assert(ofs < 64);
2177 tcg_debug_assert(len <= 64);
2178 tcg_debug_assert(ofs + len <= 64);
2180 if (ofs == 0 && len == 64) {
2181 tcg_gen_mov_i64(ret, arg2);
2182 return;
2184 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
2185 tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
2186 return;
2189 #if TCG_TARGET_REG_BITS == 32
2190 if (ofs >= 32) {
2191 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
2192 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2193 TCGV_LOW(arg2), ofs - 32, len);
2194 return;
2196 if (ofs + len <= 32) {
2197 tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
2198 TCGV_LOW(arg2), ofs, len);
2199 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
2200 return;
2202 #endif
2204 mask = (1ull << len) - 1;
2205 t1 = tcg_temp_new_i64();
2207 if (ofs + len < 64) {
2208 tcg_gen_andi_i64(t1, arg2, mask);
2209 tcg_gen_shli_i64(t1, t1, ofs);
2210 } else {
2211 tcg_gen_shli_i64(t1, arg2, ofs);
2213 tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
2214 tcg_gen_or_i64(ret, ret, t1);
2216 tcg_temp_free_i64(t1);
2219 static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
2220 TCGv_i32 high)
2222 #if TCG_TARGET_REG_BITS == 32
2223 tcg_gen_mov_i32(TCGV_LOW(dest), low);
2224 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
2225 #else
2226 TCGv_i64 tmp = tcg_temp_new_i64();
2227 /* These extensions are only needed for type correctness.
2228 We may be able to do better given target specific information. */
2229 tcg_gen_extu_i32_i64(tmp, high);
2230 tcg_gen_extu_i32_i64(dest, low);
2231 /* If deposit is available, use it. Otherwise use the extra
2232 knowledge that we have of the zero-extensions above. */
2233 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(32, 32)) {
2234 tcg_gen_deposit_i64(dest, dest, tmp, 32, 32);
2235 } else {
2236 tcg_gen_shli_i64(tmp, tmp, 32);
2237 tcg_gen_or_i64(dest, dest, tmp);
2239 tcg_temp_free_i64(tmp);
2240 #endif
2243 static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low,
2244 TCGv_i64 high)
2246 tcg_gen_deposit_i64(dest, low, high, 32, 32);
2249 static inline void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret,
2250 TCGv_i32 c1, TCGv_i32 c2,
2251 TCGv_i32 v1, TCGv_i32 v2)
2253 if (TCG_TARGET_HAS_movcond_i32) {
2254 tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond);
2255 } else {
2256 TCGv_i32 t0 = tcg_temp_new_i32();
2257 TCGv_i32 t1 = tcg_temp_new_i32();
2258 tcg_gen_setcond_i32(cond, t0, c1, c2);
2259 tcg_gen_neg_i32(t0, t0);
2260 tcg_gen_and_i32(t1, v1, t0);
2261 tcg_gen_andc_i32(ret, v2, t0);
2262 tcg_gen_or_i32(ret, ret, t1);
2263 tcg_temp_free_i32(t0);
2264 tcg_temp_free_i32(t1);
2268 static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
2269 TCGv_i64 c1, TCGv_i64 c2,
2270 TCGv_i64 v1, TCGv_i64 v2)
2272 #if TCG_TARGET_REG_BITS == 32
2273 TCGv_i32 t0 = tcg_temp_new_i32();
2274 TCGv_i32 t1 = tcg_temp_new_i32();
2275 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
2276 TCGV_LOW(c1), TCGV_HIGH(c1),
2277 TCGV_LOW(c2), TCGV_HIGH(c2), cond);
2279 if (TCG_TARGET_HAS_movcond_i32) {
2280 tcg_gen_movi_i32(t1, 0);
2281 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
2282 TCGV_LOW(v1), TCGV_LOW(v2));
2283 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
2284 TCGV_HIGH(v1), TCGV_HIGH(v2));
2285 } else {
2286 tcg_gen_neg_i32(t0, t0);
2288 tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
2289 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
2290 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
2292 tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
2293 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
2294 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
2296 tcg_temp_free_i32(t0);
2297 tcg_temp_free_i32(t1);
2298 #else
2299 if (TCG_TARGET_HAS_movcond_i64) {
2300 tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond);
2301 } else {
2302 TCGv_i64 t0 = tcg_temp_new_i64();
2303 TCGv_i64 t1 = tcg_temp_new_i64();
2304 tcg_gen_setcond_i64(cond, t0, c1, c2);
2305 tcg_gen_neg_i64(t0, t0);
2306 tcg_gen_and_i64(t1, v1, t0);
2307 tcg_gen_andc_i64(ret, v2, t0);
2308 tcg_gen_or_i64(ret, ret, t1);
2309 tcg_temp_free_i64(t0);
2310 tcg_temp_free_i64(t1);
2312 #endif
2315 /***************************************/
2316 /* QEMU specific operations. Their type depend on the QEMU CPU
2317 type. */
2318 #ifndef TARGET_LONG_BITS
2319 #error must include QEMU headers
2320 #endif
2322 #if TARGET_LONG_BITS == 32
2323 #define TCGv TCGv_i32
2324 #define tcg_temp_new() tcg_temp_new_i32()
2325 #define tcg_global_reg_new tcg_global_reg_new_i32
2326 #define tcg_global_mem_new tcg_global_mem_new_i32
2327 #define tcg_temp_local_new() tcg_temp_local_new_i32()
2328 #define tcg_temp_free tcg_temp_free_i32
2329 #define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
2330 #define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
2331 #define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
2332 #define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I32(x)
2333 #define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
2334 #else
2335 #define TCGv TCGv_i64
2336 #define tcg_temp_new() tcg_temp_new_i64()
2337 #define tcg_global_reg_new tcg_global_reg_new_i64
2338 #define tcg_global_mem_new tcg_global_mem_new_i64
2339 #define tcg_temp_local_new() tcg_temp_local_new_i64()
2340 #define tcg_temp_free tcg_temp_free_i64
2341 #define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
2342 #define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
2343 #define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
2344 #define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I64(x)
2345 #define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
2346 #endif
2348 /* debug info: write the PC of the corresponding QEMU CPU instruction */
2349 static inline void tcg_gen_debug_insn_start(uint64_t pc)
2351 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2352 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
2353 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2354 (uint32_t)(pc), (uint32_t)(pc >> 32));
2355 #else
2356 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2357 #endif
2360 static inline void tcg_gen_exit_tb(tcg_target_long val)
2362 tcg_gen_op1i(INDEX_op_exit_tb, val);
2365 static inline void tcg_gen_goto_tb(unsigned idx)
2367 /* We only support two chained exits. */
2368 tcg_debug_assert(idx <= 1);
2369 #ifdef CONFIG_DEBUG_TCG
2370 /* Verify that we havn't seen this numbered exit before. */
2371 tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
2372 tcg_ctx.goto_tb_issue_mask |= 1 << idx;
2373 #endif
2374 tcg_gen_op1i(INDEX_op_goto_tb, idx);
2377 #if TCG_TARGET_REG_BITS == 32
2378 static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
2380 #if TARGET_LONG_BITS == 32
2381 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
2382 #else
2383 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
2384 TCGV_HIGH(addr), mem_index);
2385 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
2386 #endif
2389 static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
2391 #if TARGET_LONG_BITS == 32
2392 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
2393 #else
2394 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
2395 TCGV_HIGH(addr), mem_index);
2396 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
2397 #endif
2400 static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
2402 #if TARGET_LONG_BITS == 32
2403 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
2404 #else
2405 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
2406 TCGV_HIGH(addr), mem_index);
2407 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
2408 #endif
2411 static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
2413 #if TARGET_LONG_BITS == 32
2414 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
2415 #else
2416 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
2417 TCGV_HIGH(addr), mem_index);
2418 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
2419 #endif
2422 static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
2424 #if TARGET_LONG_BITS == 32
2425 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
2426 #else
2427 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
2428 TCGV_HIGH(addr), mem_index);
2429 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
2430 #endif
2433 static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
2435 #if TARGET_LONG_BITS == 32
2436 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
2437 #else
2438 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
2439 TCGV_HIGH(addr), mem_index);
2440 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
2441 #endif
2444 static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
2446 #if TARGET_LONG_BITS == 32
2447 tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
2448 #else
2449 tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
2450 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
2451 #endif
2454 static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
2456 #if TARGET_LONG_BITS == 32
2457 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
2458 #else
2459 tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
2460 TCGV_HIGH(addr), mem_index);
2461 #endif
2464 static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
2466 #if TARGET_LONG_BITS == 32
2467 tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
2468 #else
2469 tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
2470 TCGV_HIGH(addr), mem_index);
2471 #endif
2474 static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
2476 #if TARGET_LONG_BITS == 32
2477 tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
2478 #else
2479 tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
2480 TCGV_HIGH(addr), mem_index);
2481 #endif
2484 static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
2486 #if TARGET_LONG_BITS == 32
2487 tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
2488 mem_index);
2489 #else
2490 tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
2491 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
2492 #endif
2495 #define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2496 #define tcg_gen_discard_ptr(A) tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
2498 #else /* TCG_TARGET_REG_BITS == 32 */
2500 static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
2502 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
2505 static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
2507 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
2510 static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
2512 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
2515 static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
2517 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
2520 static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
2522 #if TARGET_LONG_BITS == 32
2523 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2524 #else
2525 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
2526 #endif
2529 static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
2531 #if TARGET_LONG_BITS == 32
2532 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2533 #else
2534 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
2535 #endif
2538 static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
2540 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
2543 static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
2545 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
2548 static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
2550 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
2553 static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
2555 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
2558 static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
2560 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
2563 #define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2564 #define tcg_gen_discard_ptr(A) tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
2566 #endif /* TCG_TARGET_REG_BITS != 32 */
2568 #if TARGET_LONG_BITS == 64
2569 #define tcg_gen_movi_tl tcg_gen_movi_i64
2570 #define tcg_gen_mov_tl tcg_gen_mov_i64
2571 #define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2572 #define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2573 #define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2574 #define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2575 #define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2576 #define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2577 #define tcg_gen_ld_tl tcg_gen_ld_i64
2578 #define tcg_gen_st8_tl tcg_gen_st8_i64
2579 #define tcg_gen_st16_tl tcg_gen_st16_i64
2580 #define tcg_gen_st32_tl tcg_gen_st32_i64
2581 #define tcg_gen_st_tl tcg_gen_st_i64
2582 #define tcg_gen_add_tl tcg_gen_add_i64
2583 #define tcg_gen_addi_tl tcg_gen_addi_i64
2584 #define tcg_gen_sub_tl tcg_gen_sub_i64
2585 #define tcg_gen_neg_tl tcg_gen_neg_i64
2586 #define tcg_gen_subfi_tl tcg_gen_subfi_i64
2587 #define tcg_gen_subi_tl tcg_gen_subi_i64
2588 #define tcg_gen_and_tl tcg_gen_and_i64
2589 #define tcg_gen_andi_tl tcg_gen_andi_i64
2590 #define tcg_gen_or_tl tcg_gen_or_i64
2591 #define tcg_gen_ori_tl tcg_gen_ori_i64
2592 #define tcg_gen_xor_tl tcg_gen_xor_i64
2593 #define tcg_gen_xori_tl tcg_gen_xori_i64
2594 #define tcg_gen_not_tl tcg_gen_not_i64
2595 #define tcg_gen_shl_tl tcg_gen_shl_i64
2596 #define tcg_gen_shli_tl tcg_gen_shli_i64
2597 #define tcg_gen_shr_tl tcg_gen_shr_i64
2598 #define tcg_gen_shri_tl tcg_gen_shri_i64
2599 #define tcg_gen_sar_tl tcg_gen_sar_i64
2600 #define tcg_gen_sari_tl tcg_gen_sari_i64
2601 #define tcg_gen_brcond_tl tcg_gen_brcond_i64
2602 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2603 #define tcg_gen_setcond_tl tcg_gen_setcond_i64
2604 #define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
2605 #define tcg_gen_mul_tl tcg_gen_mul_i64
2606 #define tcg_gen_muli_tl tcg_gen_muli_i64
2607 #define tcg_gen_div_tl tcg_gen_div_i64
2608 #define tcg_gen_rem_tl tcg_gen_rem_i64
2609 #define tcg_gen_divu_tl tcg_gen_divu_i64
2610 #define tcg_gen_remu_tl tcg_gen_remu_i64
2611 #define tcg_gen_discard_tl tcg_gen_discard_i64
2612 #define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2613 #define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2614 #define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2615 #define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2616 #define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2617 #define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
2618 #define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2619 #define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2620 #define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2621 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2622 #define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2623 #define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
2624 #define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2625 #define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2626 #define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
2627 #define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2628 #define tcg_gen_andc_tl tcg_gen_andc_i64
2629 #define tcg_gen_eqv_tl tcg_gen_eqv_i64
2630 #define tcg_gen_nand_tl tcg_gen_nand_i64
2631 #define tcg_gen_nor_tl tcg_gen_nor_i64
2632 #define tcg_gen_orc_tl tcg_gen_orc_i64
2633 #define tcg_gen_rotl_tl tcg_gen_rotl_i64
2634 #define tcg_gen_rotli_tl tcg_gen_rotli_i64
2635 #define tcg_gen_rotr_tl tcg_gen_rotr_i64
2636 #define tcg_gen_rotri_tl tcg_gen_rotri_i64
2637 #define tcg_gen_deposit_tl tcg_gen_deposit_i64
2638 #define tcg_const_tl tcg_const_i64
2639 #define tcg_const_local_tl tcg_const_local_i64
2640 #define tcg_gen_movcond_tl tcg_gen_movcond_i64
2641 #else
2642 #define tcg_gen_movi_tl tcg_gen_movi_i32
2643 #define tcg_gen_mov_tl tcg_gen_mov_i32
2644 #define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2645 #define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2646 #define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2647 #define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2648 #define tcg_gen_ld32u_tl tcg_gen_ld_i32
2649 #define tcg_gen_ld32s_tl tcg_gen_ld_i32
2650 #define tcg_gen_ld_tl tcg_gen_ld_i32
2651 #define tcg_gen_st8_tl tcg_gen_st8_i32
2652 #define tcg_gen_st16_tl tcg_gen_st16_i32
2653 #define tcg_gen_st32_tl tcg_gen_st_i32
2654 #define tcg_gen_st_tl tcg_gen_st_i32
2655 #define tcg_gen_add_tl tcg_gen_add_i32
2656 #define tcg_gen_addi_tl tcg_gen_addi_i32
2657 #define tcg_gen_sub_tl tcg_gen_sub_i32
2658 #define tcg_gen_neg_tl tcg_gen_neg_i32
2659 #define tcg_gen_subfi_tl tcg_gen_subfi_i32
2660 #define tcg_gen_subi_tl tcg_gen_subi_i32
2661 #define tcg_gen_and_tl tcg_gen_and_i32
2662 #define tcg_gen_andi_tl tcg_gen_andi_i32
2663 #define tcg_gen_or_tl tcg_gen_or_i32
2664 #define tcg_gen_ori_tl tcg_gen_ori_i32
2665 #define tcg_gen_xor_tl tcg_gen_xor_i32
2666 #define tcg_gen_xori_tl tcg_gen_xori_i32
2667 #define tcg_gen_not_tl tcg_gen_not_i32
2668 #define tcg_gen_shl_tl tcg_gen_shl_i32
2669 #define tcg_gen_shli_tl tcg_gen_shli_i32
2670 #define tcg_gen_shr_tl tcg_gen_shr_i32
2671 #define tcg_gen_shri_tl tcg_gen_shri_i32
2672 #define tcg_gen_sar_tl tcg_gen_sar_i32
2673 #define tcg_gen_sari_tl tcg_gen_sari_i32
2674 #define tcg_gen_brcond_tl tcg_gen_brcond_i32
2675 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2676 #define tcg_gen_setcond_tl tcg_gen_setcond_i32
2677 #define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
2678 #define tcg_gen_mul_tl tcg_gen_mul_i32
2679 #define tcg_gen_muli_tl tcg_gen_muli_i32
2680 #define tcg_gen_div_tl tcg_gen_div_i32
2681 #define tcg_gen_rem_tl tcg_gen_rem_i32
2682 #define tcg_gen_divu_tl tcg_gen_divu_i32
2683 #define tcg_gen_remu_tl tcg_gen_remu_i32
2684 #define tcg_gen_discard_tl tcg_gen_discard_i32
2685 #define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2686 #define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2687 #define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2688 #define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2689 #define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2690 #define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
2691 #define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2692 #define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2693 #define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2694 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2695 #define tcg_gen_ext32u_tl tcg_gen_mov_i32
2696 #define tcg_gen_ext32s_tl tcg_gen_mov_i32
2697 #define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2698 #define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2699 #define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2700 #define tcg_gen_andc_tl tcg_gen_andc_i32
2701 #define tcg_gen_eqv_tl tcg_gen_eqv_i32
2702 #define tcg_gen_nand_tl tcg_gen_nand_i32
2703 #define tcg_gen_nor_tl tcg_gen_nor_i32
2704 #define tcg_gen_orc_tl tcg_gen_orc_i32
2705 #define tcg_gen_rotl_tl tcg_gen_rotl_i32
2706 #define tcg_gen_rotli_tl tcg_gen_rotli_i32
2707 #define tcg_gen_rotr_tl tcg_gen_rotr_i32
2708 #define tcg_gen_rotri_tl tcg_gen_rotri_i32
2709 #define tcg_gen_deposit_tl tcg_gen_deposit_i32
2710 #define tcg_const_tl tcg_const_i32
2711 #define tcg_const_local_tl tcg_const_local_i32
2712 #define tcg_gen_movcond_tl tcg_gen_movcond_i32
2713 #endif
2715 #if TCG_TARGET_REG_BITS == 32
2716 #define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), \
2717 TCGV_PTR_TO_NAT(A), \
2718 TCGV_PTR_TO_NAT(B))
2719 #define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), \
2720 TCGV_PTR_TO_NAT(A), (B))
2721 #define tcg_gen_ext_i32_ptr(R, A) tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
2722 #else /* TCG_TARGET_REG_BITS == 32 */
2723 #define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), \
2724 TCGV_PTR_TO_NAT(A), \
2725 TCGV_PTR_TO_NAT(B))
2726 #define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), \
2727 TCGV_PTR_TO_NAT(A), (B))
2728 #define tcg_gen_ext_i32_ptr(R, A) tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
2729 #endif /* TCG_TARGET_REG_BITS != 32 */