tests: Add intel-hda qtests
[qemu/kevin.git] / tcg / tcg-op.h
blob6dbbb38838524352214615ca1d7480e0c6b5895e
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_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
141 TCGv_i32 arg3, TCGv_i32 arg4)
143 *tcg_ctx.gen_opc_ptr++ = opc;
144 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
145 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
146 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
147 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
150 static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
151 TCGv_i64 arg3, TCGv_i64 arg4)
153 *tcg_ctx.gen_opc_ptr++ = opc;
154 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
155 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
156 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
157 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
160 static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
161 TCGv_i32 arg3, TCGArg arg4)
163 *tcg_ctx.gen_opc_ptr++ = opc;
164 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
165 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
166 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
167 *tcg_ctx.gen_opparam_ptr++ = arg4;
170 static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
171 TCGv_i64 arg3, TCGArg arg4)
173 *tcg_ctx.gen_opc_ptr++ = opc;
174 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
175 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
176 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
177 *tcg_ctx.gen_opparam_ptr++ = arg4;
180 static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
181 TCGArg arg3, TCGArg arg4)
183 *tcg_ctx.gen_opc_ptr++ = opc;
184 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
185 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
186 *tcg_ctx.gen_opparam_ptr++ = arg3;
187 *tcg_ctx.gen_opparam_ptr++ = arg4;
190 static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
191 TCGArg arg3, TCGArg arg4)
193 *tcg_ctx.gen_opc_ptr++ = opc;
194 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
195 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
196 *tcg_ctx.gen_opparam_ptr++ = arg3;
197 *tcg_ctx.gen_opparam_ptr++ = arg4;
200 static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
201 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
203 *tcg_ctx.gen_opc_ptr++ = opc;
204 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
205 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
206 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
207 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
208 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
211 static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
212 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
214 *tcg_ctx.gen_opc_ptr++ = opc;
215 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
216 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
217 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
218 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
219 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
222 static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
223 TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
225 *tcg_ctx.gen_opc_ptr++ = opc;
226 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
227 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
228 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
229 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
230 *tcg_ctx.gen_opparam_ptr++ = arg5;
233 static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
234 TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
236 *tcg_ctx.gen_opc_ptr++ = opc;
237 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
238 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
239 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
240 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
241 *tcg_ctx.gen_opparam_ptr++ = arg5;
244 static inline void tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 arg1,
245 TCGv_i32 arg2, TCGv_i32 arg3,
246 TCGArg arg4, TCGArg arg5)
248 *tcg_ctx.gen_opc_ptr++ = opc;
249 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
250 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
251 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
252 *tcg_ctx.gen_opparam_ptr++ = arg4;
253 *tcg_ctx.gen_opparam_ptr++ = arg5;
256 static inline void tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 arg1,
257 TCGv_i64 arg2, TCGv_i64 arg3,
258 TCGArg arg4, TCGArg arg5)
260 *tcg_ctx.gen_opc_ptr++ = opc;
261 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
262 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
263 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
264 *tcg_ctx.gen_opparam_ptr++ = arg4;
265 *tcg_ctx.gen_opparam_ptr++ = arg5;
268 static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
269 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
270 TCGv_i32 arg6)
272 *tcg_ctx.gen_opc_ptr++ = opc;
273 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
274 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
275 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
276 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
277 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
278 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg6);
281 static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
282 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
283 TCGv_i64 arg6)
285 *tcg_ctx.gen_opc_ptr++ = opc;
286 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
287 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
288 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
289 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
290 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
291 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg6);
294 static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
295 TCGv_i32 arg3, TCGv_i32 arg4,
296 TCGv_i32 arg5, TCGArg arg6)
298 *tcg_ctx.gen_opc_ptr++ = opc;
299 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
300 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
301 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
302 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
303 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
304 *tcg_ctx.gen_opparam_ptr++ = arg6;
307 static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
308 TCGv_i64 arg3, TCGv_i64 arg4,
309 TCGv_i64 arg5, TCGArg arg6)
311 *tcg_ctx.gen_opc_ptr++ = opc;
312 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
313 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
314 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
315 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
316 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
317 *tcg_ctx.gen_opparam_ptr++ = arg6;
320 static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 arg1,
321 TCGv_i32 arg2, TCGv_i32 arg3,
322 TCGv_i32 arg4, TCGArg arg5, TCGArg arg6)
324 *tcg_ctx.gen_opc_ptr++ = opc;
325 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
326 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
327 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
328 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
329 *tcg_ctx.gen_opparam_ptr++ = arg5;
330 *tcg_ctx.gen_opparam_ptr++ = arg6;
333 static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 arg1,
334 TCGv_i64 arg2, TCGv_i64 arg3,
335 TCGv_i64 arg4, TCGArg arg5, TCGArg arg6)
337 *tcg_ctx.gen_opc_ptr++ = opc;
338 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
339 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
340 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
341 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
342 *tcg_ctx.gen_opparam_ptr++ = arg5;
343 *tcg_ctx.gen_opparam_ptr++ = arg6;
346 static inline void tcg_add_param_i32(TCGv_i32 val)
348 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(val);
351 static inline void tcg_add_param_i64(TCGv_i64 val)
353 #if TCG_TARGET_REG_BITS == 32
354 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(TCGV_LOW(val));
355 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(TCGV_HIGH(val));
356 #else
357 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
358 #endif
361 static inline void gen_set_label(int n)
363 tcg_gen_op1i(INDEX_op_set_label, n);
366 static inline void tcg_gen_br(int label)
368 tcg_gen_op1i(INDEX_op_br, label);
371 static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
373 if (!TCGV_EQUAL_I32(ret, arg))
374 tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
377 static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
379 tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
382 /* A version of dh_sizemask from def-helper.h that doesn't rely on
383 preprocessor magic. */
384 static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
386 return (is_64bit << n*2) | (is_signed << (n*2 + 1));
389 /* helper calls */
390 static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
391 TCGArg ret, int nargs, TCGArg *args)
393 TCGv_ptr fn;
394 fn = tcg_const_ptr(func);
395 tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
396 nargs, args);
397 tcg_temp_free_ptr(fn);
400 /* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
401 reserved for helpers in tcg-runtime.c. These helpers all do not read
402 globals and do not have side effects, hence the call to tcg_gen_callN()
403 with TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS. This may need
404 to be adjusted if these functions start to be used with other helpers. */
405 static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
406 TCGv_i32 a, TCGv_i32 b)
408 TCGv_ptr fn;
409 TCGArg args[2];
410 fn = tcg_const_ptr(func);
411 args[0] = GET_TCGV_I32(a);
412 args[1] = GET_TCGV_I32(b);
413 tcg_gen_callN(&tcg_ctx, fn,
414 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
415 sizemask, GET_TCGV_I32(ret), 2, args);
416 tcg_temp_free_ptr(fn);
419 static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
420 TCGv_i64 a, TCGv_i64 b)
422 TCGv_ptr fn;
423 TCGArg args[2];
424 fn = tcg_const_ptr(func);
425 args[0] = GET_TCGV_I64(a);
426 args[1] = GET_TCGV_I64(b);
427 tcg_gen_callN(&tcg_ctx, fn,
428 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
429 sizemask, GET_TCGV_I64(ret), 2, args);
430 tcg_temp_free_ptr(fn);
433 /* 32 bit ops */
435 static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
437 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
440 static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
442 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
445 static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
447 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
450 static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
452 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
455 static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
457 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
460 static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
462 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
465 static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
467 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
470 static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
472 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
475 static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
477 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
480 static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
482 /* some cases can be optimized here */
483 if (arg2 == 0) {
484 tcg_gen_mov_i32(ret, arg1);
485 } else {
486 TCGv_i32 t0 = tcg_const_i32(arg2);
487 tcg_gen_add_i32(ret, arg1, t0);
488 tcg_temp_free_i32(t0);
492 static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
494 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
497 static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
499 TCGv_i32 t0 = tcg_const_i32(arg1);
500 tcg_gen_sub_i32(ret, t0, arg2);
501 tcg_temp_free_i32(t0);
504 static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
506 /* some cases can be optimized here */
507 if (arg2 == 0) {
508 tcg_gen_mov_i32(ret, arg1);
509 } else {
510 TCGv_i32 t0 = tcg_const_i32(arg2);
511 tcg_gen_sub_i32(ret, arg1, t0);
512 tcg_temp_free_i32(t0);
516 static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
518 if (TCGV_EQUAL_I32(arg1, arg2)) {
519 tcg_gen_mov_i32(ret, arg1);
520 } else {
521 tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
525 static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
527 TCGv_i32 t0;
528 /* Some cases can be optimized here. */
529 switch (arg2) {
530 case 0:
531 tcg_gen_movi_i32(ret, 0);
532 return;
533 case 0xffffffffu:
534 tcg_gen_mov_i32(ret, arg1);
535 return;
536 case 0xffu:
537 /* Don't recurse with tcg_gen_ext8u_i32. */
538 if (TCG_TARGET_HAS_ext8u_i32) {
539 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg1);
540 return;
542 break;
543 case 0xffffu:
544 if (TCG_TARGET_HAS_ext16u_i32) {
545 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg1);
546 return;
548 break;
550 t0 = tcg_const_i32(arg2);
551 tcg_gen_and_i32(ret, arg1, t0);
552 tcg_temp_free_i32(t0);
555 static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
557 if (TCGV_EQUAL_I32(arg1, arg2)) {
558 tcg_gen_mov_i32(ret, arg1);
559 } else {
560 tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
564 static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
566 /* Some cases can be optimized here. */
567 if (arg2 == -1) {
568 tcg_gen_movi_i32(ret, -1);
569 } else if (arg2 == 0) {
570 tcg_gen_mov_i32(ret, arg1);
571 } else {
572 TCGv_i32 t0 = tcg_const_i32(arg2);
573 tcg_gen_or_i32(ret, arg1, t0);
574 tcg_temp_free_i32(t0);
578 static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
580 if (TCGV_EQUAL_I32(arg1, arg2)) {
581 tcg_gen_movi_i32(ret, 0);
582 } else {
583 tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
587 static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
589 /* Some cases can be optimized here. */
590 if (arg2 == 0) {
591 tcg_gen_mov_i32(ret, arg1);
592 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i32) {
593 /* Don't recurse with tcg_gen_not_i32. */
594 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg1);
595 } else {
596 TCGv_i32 t0 = tcg_const_i32(arg2);
597 tcg_gen_xor_i32(ret, arg1, t0);
598 tcg_temp_free_i32(t0);
602 static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
604 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
607 static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
609 if (arg2 == 0) {
610 tcg_gen_mov_i32(ret, arg1);
611 } else {
612 TCGv_i32 t0 = tcg_const_i32(arg2);
613 tcg_gen_shl_i32(ret, arg1, t0);
614 tcg_temp_free_i32(t0);
618 static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
620 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
623 static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
625 if (arg2 == 0) {
626 tcg_gen_mov_i32(ret, arg1);
627 } else {
628 TCGv_i32 t0 = tcg_const_i32(arg2);
629 tcg_gen_shr_i32(ret, arg1, t0);
630 tcg_temp_free_i32(t0);
634 static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
636 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
639 static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
641 if (arg2 == 0) {
642 tcg_gen_mov_i32(ret, arg1);
643 } else {
644 TCGv_i32 t0 = tcg_const_i32(arg2);
645 tcg_gen_sar_i32(ret, arg1, t0);
646 tcg_temp_free_i32(t0);
650 static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
651 TCGv_i32 arg2, int label_index)
653 if (cond == TCG_COND_ALWAYS) {
654 tcg_gen_br(label_index);
655 } else if (cond != TCG_COND_NEVER) {
656 tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
660 static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
661 int32_t arg2, int label_index)
663 if (cond == TCG_COND_ALWAYS) {
664 tcg_gen_br(label_index);
665 } else if (cond != TCG_COND_NEVER) {
666 TCGv_i32 t0 = tcg_const_i32(arg2);
667 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
668 tcg_temp_free_i32(t0);
672 static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
673 TCGv_i32 arg1, TCGv_i32 arg2)
675 if (cond == TCG_COND_ALWAYS) {
676 tcg_gen_movi_i32(ret, 1);
677 } else if (cond == TCG_COND_NEVER) {
678 tcg_gen_movi_i32(ret, 0);
679 } else {
680 tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
684 static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
685 TCGv_i32 arg1, int32_t arg2)
687 if (cond == TCG_COND_ALWAYS) {
688 tcg_gen_movi_i32(ret, 1);
689 } else if (cond == TCG_COND_NEVER) {
690 tcg_gen_movi_i32(ret, 0);
691 } else {
692 TCGv_i32 t0 = tcg_const_i32(arg2);
693 tcg_gen_setcond_i32(cond, ret, arg1, t0);
694 tcg_temp_free_i32(t0);
698 static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
700 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
703 static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
705 TCGv_i32 t0 = tcg_const_i32(arg2);
706 tcg_gen_mul_i32(ret, arg1, t0);
707 tcg_temp_free_i32(t0);
710 static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
712 if (TCG_TARGET_HAS_div_i32) {
713 tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
714 } else if (TCG_TARGET_HAS_div2_i32) {
715 TCGv_i32 t0 = tcg_temp_new_i32();
716 tcg_gen_sari_i32(t0, arg1, 31);
717 tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
718 tcg_temp_free_i32(t0);
719 } else {
720 int sizemask = 0;
721 /* Return value and both arguments are 32-bit and signed. */
722 sizemask |= tcg_gen_sizemask(0, 0, 1);
723 sizemask |= tcg_gen_sizemask(1, 0, 1);
724 sizemask |= tcg_gen_sizemask(2, 0, 1);
725 tcg_gen_helper32(tcg_helper_div_i32, sizemask, ret, arg1, arg2);
729 static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
731 if (TCG_TARGET_HAS_rem_i32) {
732 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
733 } else if (TCG_TARGET_HAS_div_i32) {
734 TCGv_i32 t0 = tcg_temp_new_i32();
735 tcg_gen_op3_i32(INDEX_op_div_i32, t0, arg1, arg2);
736 tcg_gen_mul_i32(t0, t0, arg2);
737 tcg_gen_sub_i32(ret, arg1, t0);
738 tcg_temp_free_i32(t0);
739 } else if (TCG_TARGET_HAS_div2_i32) {
740 TCGv_i32 t0 = tcg_temp_new_i32();
741 tcg_gen_sari_i32(t0, arg1, 31);
742 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
743 tcg_temp_free_i32(t0);
744 } else {
745 int sizemask = 0;
746 /* Return value and both arguments are 32-bit and signed. */
747 sizemask |= tcg_gen_sizemask(0, 0, 1);
748 sizemask |= tcg_gen_sizemask(1, 0, 1);
749 sizemask |= tcg_gen_sizemask(2, 0, 1);
750 tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2);
754 static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
756 if (TCG_TARGET_HAS_div_i32) {
757 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
758 } else if (TCG_TARGET_HAS_div2_i32) {
759 TCGv_i32 t0 = tcg_temp_new_i32();
760 tcg_gen_movi_i32(t0, 0);
761 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
762 tcg_temp_free_i32(t0);
763 } else {
764 int sizemask = 0;
765 /* Return value and both arguments are 32-bit and unsigned. */
766 sizemask |= tcg_gen_sizemask(0, 0, 0);
767 sizemask |= tcg_gen_sizemask(1, 0, 0);
768 sizemask |= tcg_gen_sizemask(2, 0, 0);
769 tcg_gen_helper32(tcg_helper_divu_i32, sizemask, ret, arg1, arg2);
773 static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
775 if (TCG_TARGET_HAS_rem_i32) {
776 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
777 } else if (TCG_TARGET_HAS_div_i32) {
778 TCGv_i32 t0 = tcg_temp_new_i32();
779 tcg_gen_op3_i32(INDEX_op_divu_i32, t0, arg1, arg2);
780 tcg_gen_mul_i32(t0, t0, arg2);
781 tcg_gen_sub_i32(ret, arg1, t0);
782 tcg_temp_free_i32(t0);
783 } else if (TCG_TARGET_HAS_div2_i32) {
784 TCGv_i32 t0 = tcg_temp_new_i32();
785 tcg_gen_movi_i32(t0, 0);
786 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
787 tcg_temp_free_i32(t0);
788 } else {
789 int sizemask = 0;
790 /* Return value and both arguments are 32-bit and unsigned. */
791 sizemask |= tcg_gen_sizemask(0, 0, 0);
792 sizemask |= tcg_gen_sizemask(1, 0, 0);
793 sizemask |= tcg_gen_sizemask(2, 0, 0);
794 tcg_gen_helper32(tcg_helper_remu_i32, sizemask, ret, arg1, arg2);
798 #if TCG_TARGET_REG_BITS == 32
800 static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
802 if (!TCGV_EQUAL_I64(ret, arg)) {
803 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
804 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
808 static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
810 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
811 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
814 static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
815 tcg_target_long offset)
817 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
818 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
821 static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
822 tcg_target_long offset)
824 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
825 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
828 static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
829 tcg_target_long offset)
831 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
832 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
835 static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
836 tcg_target_long offset)
838 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
839 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
842 static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
843 tcg_target_long offset)
845 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
846 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
849 static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
850 tcg_target_long offset)
852 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
853 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
856 static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
857 tcg_target_long offset)
859 /* since arg2 and ret have different types, they cannot be the
860 same temporary */
861 #ifdef HOST_WORDS_BIGENDIAN
862 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
863 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
864 #else
865 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
866 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
867 #endif
870 static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
871 tcg_target_long offset)
873 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
876 static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
877 tcg_target_long offset)
879 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
882 static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
883 tcg_target_long offset)
885 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
888 static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
889 tcg_target_long offset)
891 #ifdef HOST_WORDS_BIGENDIAN
892 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
893 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
894 #else
895 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
896 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
897 #endif
900 static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
902 tcg_gen_op6_i32(INDEX_op_add2_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 add2 with two moves. */
906 tcg_gen_op0(INDEX_op_nop);
909 static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
911 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
912 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
913 TCGV_HIGH(arg2));
914 /* Allow the optimizer room to replace sub2 with two moves. */
915 tcg_gen_op0(INDEX_op_nop);
918 static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
920 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
921 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
924 static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
926 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
927 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
930 static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
932 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
933 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
936 static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
938 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
939 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
942 static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
944 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
945 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
948 static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
950 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
951 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
954 /* XXX: use generic code when basic block handling is OK or CPU
955 specific code (x86) */
956 static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
958 int sizemask = 0;
959 /* Return value and both arguments are 64-bit and signed. */
960 sizemask |= tcg_gen_sizemask(0, 1, 1);
961 sizemask |= tcg_gen_sizemask(1, 1, 1);
962 sizemask |= tcg_gen_sizemask(2, 1, 1);
964 tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
967 static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
969 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
972 static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
974 int sizemask = 0;
975 /* Return value and both arguments are 64-bit and signed. */
976 sizemask |= tcg_gen_sizemask(0, 1, 1);
977 sizemask |= tcg_gen_sizemask(1, 1, 1);
978 sizemask |= tcg_gen_sizemask(2, 1, 1);
980 tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
983 static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
985 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
988 static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
990 int sizemask = 0;
991 /* Return value and both arguments are 64-bit and signed. */
992 sizemask |= tcg_gen_sizemask(0, 1, 1);
993 sizemask |= tcg_gen_sizemask(1, 1, 1);
994 sizemask |= tcg_gen_sizemask(2, 1, 1);
996 tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
999 static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1001 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
1004 static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1005 TCGv_i64 arg2, int label_index)
1007 if (cond == TCG_COND_ALWAYS) {
1008 tcg_gen_br(label_index);
1009 } else if (cond != TCG_COND_NEVER) {
1010 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
1011 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
1012 TCGV_HIGH(arg2), cond, label_index);
1016 static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1017 TCGv_i64 arg1, TCGv_i64 arg2)
1019 if (cond == TCG_COND_ALWAYS) {
1020 tcg_gen_movi_i32(TCGV_LOW(ret), 1);
1021 } else if (cond == TCG_COND_NEVER) {
1022 tcg_gen_movi_i32(TCGV_LOW(ret), 0);
1023 } else {
1024 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
1025 TCGV_LOW(arg1), TCGV_HIGH(arg1),
1026 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
1028 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1031 static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1033 TCGv_i64 t0;
1034 TCGv_i32 t1;
1036 t0 = tcg_temp_new_i64();
1037 t1 = tcg_temp_new_i32();
1039 if (TCG_TARGET_HAS_mulu2_i32) {
1040 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
1041 TCGV_LOW(arg1), TCGV_LOW(arg2));
1042 /* Allow the optimizer room to replace mulu2 with two moves. */
1043 tcg_gen_op0(INDEX_op_nop);
1044 } else {
1045 tcg_debug_assert(TCG_TARGET_HAS_muluh_i32);
1046 tcg_gen_op3_i32(INDEX_op_mul_i32, TCGV_LOW(t0),
1047 TCGV_LOW(arg1), TCGV_LOW(arg2));
1048 tcg_gen_op3_i32(INDEX_op_muluh_i32, TCGV_HIGH(t0),
1049 TCGV_LOW(arg1), TCGV_LOW(arg2));
1052 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
1053 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
1054 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
1055 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
1057 tcg_gen_mov_i64(ret, t0);
1058 tcg_temp_free_i64(t0);
1059 tcg_temp_free_i32(t1);
1062 static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1064 int sizemask = 0;
1065 /* Return value and both arguments are 64-bit and signed. */
1066 sizemask |= tcg_gen_sizemask(0, 1, 1);
1067 sizemask |= tcg_gen_sizemask(1, 1, 1);
1068 sizemask |= tcg_gen_sizemask(2, 1, 1);
1070 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
1073 static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1075 int sizemask = 0;
1076 /* Return value and both arguments are 64-bit and signed. */
1077 sizemask |= tcg_gen_sizemask(0, 1, 1);
1078 sizemask |= tcg_gen_sizemask(1, 1, 1);
1079 sizemask |= tcg_gen_sizemask(2, 1, 1);
1081 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1084 static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1086 int sizemask = 0;
1087 /* Return value and both arguments are 64-bit and unsigned. */
1088 sizemask |= tcg_gen_sizemask(0, 1, 0);
1089 sizemask |= tcg_gen_sizemask(1, 1, 0);
1090 sizemask |= tcg_gen_sizemask(2, 1, 0);
1092 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1095 static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1097 int sizemask = 0;
1098 /* Return value and both arguments are 64-bit and unsigned. */
1099 sizemask |= tcg_gen_sizemask(0, 1, 0);
1100 sizemask |= tcg_gen_sizemask(1, 1, 0);
1101 sizemask |= tcg_gen_sizemask(2, 1, 0);
1103 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1106 #else
1108 static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
1110 if (!TCGV_EQUAL_I64(ret, arg))
1111 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
1114 static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
1116 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
1119 static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1120 tcg_target_long offset)
1122 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
1125 static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1126 tcg_target_long offset)
1128 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
1131 static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1132 tcg_target_long offset)
1134 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
1137 static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1138 tcg_target_long offset)
1140 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
1143 static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1144 tcg_target_long offset)
1146 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
1149 static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1150 tcg_target_long offset)
1152 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
1155 static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
1157 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
1160 static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1161 tcg_target_long offset)
1163 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
1166 static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1167 tcg_target_long offset)
1169 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
1172 static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1173 tcg_target_long offset)
1175 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
1178 static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
1180 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
1183 static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1185 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
1188 static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1190 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
1193 static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1195 if (TCGV_EQUAL_I64(arg1, arg2)) {
1196 tcg_gen_mov_i64(ret, arg1);
1197 } else {
1198 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1202 static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
1204 TCGv_i64 t0;
1205 /* Some cases can be optimized here. */
1206 switch (arg2) {
1207 case 0:
1208 tcg_gen_movi_i64(ret, 0);
1209 return;
1210 case 0xffffffffffffffffull:
1211 tcg_gen_mov_i64(ret, arg1);
1212 return;
1213 case 0xffull:
1214 /* Don't recurse with tcg_gen_ext8u_i32. */
1215 if (TCG_TARGET_HAS_ext8u_i64) {
1216 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg1);
1217 return;
1219 break;
1220 case 0xffffu:
1221 if (TCG_TARGET_HAS_ext16u_i64) {
1222 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg1);
1223 return;
1225 break;
1226 case 0xffffffffull:
1227 if (TCG_TARGET_HAS_ext32u_i64) {
1228 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg1);
1229 return;
1231 break;
1233 t0 = tcg_const_i64(arg2);
1234 tcg_gen_and_i64(ret, arg1, t0);
1235 tcg_temp_free_i64(t0);
1238 static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1240 if (TCGV_EQUAL_I64(arg1, arg2)) {
1241 tcg_gen_mov_i64(ret, arg1);
1242 } else {
1243 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1247 static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1249 /* Some cases can be optimized here. */
1250 if (arg2 == -1) {
1251 tcg_gen_movi_i64(ret, -1);
1252 } else if (arg2 == 0) {
1253 tcg_gen_mov_i64(ret, arg1);
1254 } else {
1255 TCGv_i64 t0 = tcg_const_i64(arg2);
1256 tcg_gen_or_i64(ret, arg1, t0);
1257 tcg_temp_free_i64(t0);
1261 static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1263 if (TCGV_EQUAL_I64(arg1, arg2)) {
1264 tcg_gen_movi_i64(ret, 0);
1265 } else {
1266 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1270 static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1272 /* Some cases can be optimized here. */
1273 if (arg2 == 0) {
1274 tcg_gen_mov_i64(ret, arg1);
1275 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i64) {
1276 /* Don't recurse with tcg_gen_not_i64. */
1277 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
1278 } else {
1279 TCGv_i64 t0 = tcg_const_i64(arg2);
1280 tcg_gen_xor_i64(ret, arg1, t0);
1281 tcg_temp_free_i64(t0);
1285 static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1287 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
1290 static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1292 if (arg2 == 0) {
1293 tcg_gen_mov_i64(ret, arg1);
1294 } else {
1295 TCGv_i64 t0 = tcg_const_i64(arg2);
1296 tcg_gen_shl_i64(ret, arg1, t0);
1297 tcg_temp_free_i64(t0);
1301 static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1303 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
1306 static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1308 if (arg2 == 0) {
1309 tcg_gen_mov_i64(ret, arg1);
1310 } else {
1311 TCGv_i64 t0 = tcg_const_i64(arg2);
1312 tcg_gen_shr_i64(ret, arg1, t0);
1313 tcg_temp_free_i64(t0);
1317 static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1319 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
1322 static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1324 if (arg2 == 0) {
1325 tcg_gen_mov_i64(ret, arg1);
1326 } else {
1327 TCGv_i64 t0 = tcg_const_i64(arg2);
1328 tcg_gen_sar_i64(ret, arg1, t0);
1329 tcg_temp_free_i64(t0);
1333 static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1334 TCGv_i64 arg2, int label_index)
1336 if (cond == TCG_COND_ALWAYS) {
1337 tcg_gen_br(label_index);
1338 } else if (cond != TCG_COND_NEVER) {
1339 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
1343 static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1344 TCGv_i64 arg1, TCGv_i64 arg2)
1346 if (cond == TCG_COND_ALWAYS) {
1347 tcg_gen_movi_i64(ret, 1);
1348 } else if (cond == TCG_COND_NEVER) {
1349 tcg_gen_movi_i64(ret, 0);
1350 } else {
1351 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1355 static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1357 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
1360 static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1362 if (TCG_TARGET_HAS_div_i64) {
1363 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
1364 } else if (TCG_TARGET_HAS_div2_i64) {
1365 TCGv_i64 t0 = tcg_temp_new_i64();
1366 tcg_gen_sari_i64(t0, arg1, 63);
1367 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1368 tcg_temp_free_i64(t0);
1369 } else {
1370 int sizemask = 0;
1371 /* Return value and both arguments are 64-bit and signed. */
1372 sizemask |= tcg_gen_sizemask(0, 1, 1);
1373 sizemask |= tcg_gen_sizemask(1, 1, 1);
1374 sizemask |= tcg_gen_sizemask(2, 1, 1);
1375 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
1379 static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1381 if (TCG_TARGET_HAS_rem_i64) {
1382 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
1383 } else if (TCG_TARGET_HAS_div_i64) {
1384 TCGv_i64 t0 = tcg_temp_new_i64();
1385 tcg_gen_op3_i64(INDEX_op_div_i64, t0, arg1, arg2);
1386 tcg_gen_mul_i64(t0, t0, arg2);
1387 tcg_gen_sub_i64(ret, arg1, t0);
1388 tcg_temp_free_i64(t0);
1389 } else if (TCG_TARGET_HAS_div2_i64) {
1390 TCGv_i64 t0 = tcg_temp_new_i64();
1391 tcg_gen_sari_i64(t0, arg1, 63);
1392 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1393 tcg_temp_free_i64(t0);
1394 } else {
1395 int sizemask = 0;
1396 /* Return value and both arguments are 64-bit and signed. */
1397 sizemask |= tcg_gen_sizemask(0, 1, 1);
1398 sizemask |= tcg_gen_sizemask(1, 1, 1);
1399 sizemask |= tcg_gen_sizemask(2, 1, 1);
1400 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1404 static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1406 if (TCG_TARGET_HAS_div_i64) {
1407 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
1408 } else if (TCG_TARGET_HAS_div2_i64) {
1409 TCGv_i64 t0 = tcg_temp_new_i64();
1410 tcg_gen_movi_i64(t0, 0);
1411 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1412 tcg_temp_free_i64(t0);
1413 } else {
1414 int sizemask = 0;
1415 /* Return value and both arguments are 64-bit and unsigned. */
1416 sizemask |= tcg_gen_sizemask(0, 1, 0);
1417 sizemask |= tcg_gen_sizemask(1, 1, 0);
1418 sizemask |= tcg_gen_sizemask(2, 1, 0);
1419 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1423 static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1425 if (TCG_TARGET_HAS_rem_i64) {
1426 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
1427 } else if (TCG_TARGET_HAS_div_i64) {
1428 TCGv_i64 t0 = tcg_temp_new_i64();
1429 tcg_gen_op3_i64(INDEX_op_divu_i64, t0, arg1, arg2);
1430 tcg_gen_mul_i64(t0, t0, arg2);
1431 tcg_gen_sub_i64(ret, arg1, t0);
1432 tcg_temp_free_i64(t0);
1433 } else if (TCG_TARGET_HAS_div2_i64) {
1434 TCGv_i64 t0 = tcg_temp_new_i64();
1435 tcg_gen_movi_i64(t0, 0);
1436 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1437 tcg_temp_free_i64(t0);
1438 } else {
1439 int sizemask = 0;
1440 /* Return value and both arguments are 64-bit and unsigned. */
1441 sizemask |= tcg_gen_sizemask(0, 1, 0);
1442 sizemask |= tcg_gen_sizemask(1, 1, 0);
1443 sizemask |= tcg_gen_sizemask(2, 1, 0);
1444 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1447 #endif /* TCG_TARGET_REG_BITS == 32 */
1449 static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1451 /* some cases can be optimized here */
1452 if (arg2 == 0) {
1453 tcg_gen_mov_i64(ret, arg1);
1454 } else {
1455 TCGv_i64 t0 = tcg_const_i64(arg2);
1456 tcg_gen_add_i64(ret, arg1, t0);
1457 tcg_temp_free_i64(t0);
1461 static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
1463 TCGv_i64 t0 = tcg_const_i64(arg1);
1464 tcg_gen_sub_i64(ret, t0, arg2);
1465 tcg_temp_free_i64(t0);
1468 static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1470 /* some cases can be optimized here */
1471 if (arg2 == 0) {
1472 tcg_gen_mov_i64(ret, arg1);
1473 } else {
1474 TCGv_i64 t0 = tcg_const_i64(arg2);
1475 tcg_gen_sub_i64(ret, arg1, t0);
1476 tcg_temp_free_i64(t0);
1479 static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1480 int64_t arg2, int label_index)
1482 if (cond == TCG_COND_ALWAYS) {
1483 tcg_gen_br(label_index);
1484 } else if (cond != TCG_COND_NEVER) {
1485 TCGv_i64 t0 = tcg_const_i64(arg2);
1486 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1487 tcg_temp_free_i64(t0);
1491 static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1492 TCGv_i64 arg1, int64_t arg2)
1494 TCGv_i64 t0 = tcg_const_i64(arg2);
1495 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1496 tcg_temp_free_i64(t0);
1499 static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1501 TCGv_i64 t0 = tcg_const_i64(arg2);
1502 tcg_gen_mul_i64(ret, arg1, t0);
1503 tcg_temp_free_i64(t0);
1507 /***************************************/
1508 /* optional operations */
1510 static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
1512 if (TCG_TARGET_HAS_ext8s_i32) {
1513 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
1514 } else {
1515 tcg_gen_shli_i32(ret, arg, 24);
1516 tcg_gen_sari_i32(ret, ret, 24);
1520 static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
1522 if (TCG_TARGET_HAS_ext16s_i32) {
1523 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
1524 } else {
1525 tcg_gen_shli_i32(ret, arg, 16);
1526 tcg_gen_sari_i32(ret, ret, 16);
1530 static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
1532 if (TCG_TARGET_HAS_ext8u_i32) {
1533 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1534 } else {
1535 tcg_gen_andi_i32(ret, arg, 0xffu);
1539 static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
1541 if (TCG_TARGET_HAS_ext16u_i32) {
1542 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1543 } else {
1544 tcg_gen_andi_i32(ret, arg, 0xffffu);
1548 /* Note: we assume the two high bytes are set to zero */
1549 static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
1551 if (TCG_TARGET_HAS_bswap16_i32) {
1552 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
1553 } else {
1554 TCGv_i32 t0 = tcg_temp_new_i32();
1556 tcg_gen_ext8u_i32(t0, arg);
1557 tcg_gen_shli_i32(t0, t0, 8);
1558 tcg_gen_shri_i32(ret, arg, 8);
1559 tcg_gen_or_i32(ret, ret, t0);
1560 tcg_temp_free_i32(t0);
1564 static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
1566 if (TCG_TARGET_HAS_bswap32_i32) {
1567 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
1568 } else {
1569 TCGv_i32 t0, t1;
1570 t0 = tcg_temp_new_i32();
1571 t1 = tcg_temp_new_i32();
1573 tcg_gen_shli_i32(t0, arg, 24);
1575 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1576 tcg_gen_shli_i32(t1, t1, 8);
1577 tcg_gen_or_i32(t0, t0, t1);
1579 tcg_gen_shri_i32(t1, arg, 8);
1580 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1581 tcg_gen_or_i32(t0, t0, t1);
1583 tcg_gen_shri_i32(t1, arg, 24);
1584 tcg_gen_or_i32(ret, t0, t1);
1585 tcg_temp_free_i32(t0);
1586 tcg_temp_free_i32(t1);
1590 #if TCG_TARGET_REG_BITS == 32
1591 static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
1593 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1594 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1597 static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
1599 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1600 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1603 static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
1605 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1606 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1609 static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
1611 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1612 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1615 static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
1617 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1618 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1621 static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
1623 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1624 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1627 static inline void tcg_gen_trunc_shr_i64_i32(TCGv_i32 ret, TCGv_i64 arg,
1628 unsigned int count)
1630 tcg_debug_assert(count < 64);
1631 if (count >= 32) {
1632 tcg_gen_shri_i32(ret, TCGV_HIGH(arg), count - 32);
1633 } else if (count == 0) {
1634 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
1635 } else {
1636 TCGv_i64 t = tcg_temp_new_i64();
1637 tcg_gen_shri_i64(t, arg, count);
1638 tcg_gen_mov_i32(ret, TCGV_LOW(t));
1639 tcg_temp_free_i64(t);
1643 static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1645 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1646 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1649 static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1651 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1652 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1655 /* Note: we assume the six high bytes are set to zero */
1656 static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1658 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1659 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1662 /* Note: we assume the four high bytes are set to zero */
1663 static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1665 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1666 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1669 static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
1671 TCGv_i32 t0, t1;
1672 t0 = tcg_temp_new_i32();
1673 t1 = tcg_temp_new_i32();
1675 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1676 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
1677 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
1678 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
1679 tcg_temp_free_i32(t0);
1680 tcg_temp_free_i32(t1);
1682 #else
1684 static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
1686 if (TCG_TARGET_HAS_ext8s_i64) {
1687 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
1688 } else {
1689 tcg_gen_shli_i64(ret, arg, 56);
1690 tcg_gen_sari_i64(ret, ret, 56);
1694 static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
1696 if (TCG_TARGET_HAS_ext16s_i64) {
1697 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
1698 } else {
1699 tcg_gen_shli_i64(ret, arg, 48);
1700 tcg_gen_sari_i64(ret, ret, 48);
1704 static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
1706 if (TCG_TARGET_HAS_ext32s_i64) {
1707 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
1708 } else {
1709 tcg_gen_shli_i64(ret, arg, 32);
1710 tcg_gen_sari_i64(ret, ret, 32);
1714 static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
1716 if (TCG_TARGET_HAS_ext8u_i64) {
1717 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1718 } else {
1719 tcg_gen_andi_i64(ret, arg, 0xffu);
1723 static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
1725 if (TCG_TARGET_HAS_ext16u_i64) {
1726 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1727 } else {
1728 tcg_gen_andi_i64(ret, arg, 0xffffu);
1732 static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
1734 if (TCG_TARGET_HAS_ext32u_i64) {
1735 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1736 } else {
1737 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1741 static inline void tcg_gen_trunc_shr_i64_i32(TCGv_i32 ret, TCGv_i64 arg,
1742 unsigned int count)
1744 tcg_debug_assert(count < 64);
1745 if (TCG_TARGET_HAS_trunc_shr_i32) {
1746 tcg_gen_op3i_i32(INDEX_op_trunc_shr_i32, ret,
1747 MAKE_TCGV_I32(GET_TCGV_I64(arg)), count);
1748 } else if (count == 0) {
1749 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
1750 } else {
1751 TCGv_i64 t = tcg_temp_new_i64();
1752 tcg_gen_shri_i64(t, arg, count);
1753 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(t)));
1754 tcg_temp_free_i64(t);
1758 /* Note: we assume the target supports move between 32 and 64 bit
1759 registers */
1760 static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1762 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
1765 /* Note: we assume the target supports move between 32 and 64 bit
1766 registers */
1767 static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1769 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
1772 /* Note: we assume the six high bytes are set to zero */
1773 static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1775 if (TCG_TARGET_HAS_bswap16_i64) {
1776 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1777 } else {
1778 TCGv_i64 t0 = tcg_temp_new_i64();
1780 tcg_gen_ext8u_i64(t0, arg);
1781 tcg_gen_shli_i64(t0, t0, 8);
1782 tcg_gen_shri_i64(ret, arg, 8);
1783 tcg_gen_or_i64(ret, ret, t0);
1784 tcg_temp_free_i64(t0);
1788 /* Note: we assume the four high bytes are set to zero */
1789 static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1791 if (TCG_TARGET_HAS_bswap32_i64) {
1792 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1793 } else {
1794 TCGv_i64 t0, t1;
1795 t0 = tcg_temp_new_i64();
1796 t1 = tcg_temp_new_i64();
1798 tcg_gen_shli_i64(t0, arg, 24);
1799 tcg_gen_ext32u_i64(t0, t0);
1801 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1802 tcg_gen_shli_i64(t1, t1, 8);
1803 tcg_gen_or_i64(t0, t0, t1);
1805 tcg_gen_shri_i64(t1, arg, 8);
1806 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1807 tcg_gen_or_i64(t0, t0, t1);
1809 tcg_gen_shri_i64(t1, arg, 24);
1810 tcg_gen_or_i64(ret, t0, t1);
1811 tcg_temp_free_i64(t0);
1812 tcg_temp_free_i64(t1);
1816 static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
1818 if (TCG_TARGET_HAS_bswap64_i64) {
1819 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
1820 } else {
1821 TCGv_i64 t0 = tcg_temp_new_i64();
1822 TCGv_i64 t1 = tcg_temp_new_i64();
1824 tcg_gen_shli_i64(t0, arg, 56);
1826 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1827 tcg_gen_shli_i64(t1, t1, 40);
1828 tcg_gen_or_i64(t0, t0, t1);
1830 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1831 tcg_gen_shli_i64(t1, t1, 24);
1832 tcg_gen_or_i64(t0, t0, t1);
1834 tcg_gen_andi_i64(t1, arg, 0xff000000);
1835 tcg_gen_shli_i64(t1, t1, 8);
1836 tcg_gen_or_i64(t0, t0, t1);
1838 tcg_gen_shri_i64(t1, arg, 8);
1839 tcg_gen_andi_i64(t1, t1, 0xff000000);
1840 tcg_gen_or_i64(t0, t0, t1);
1842 tcg_gen_shri_i64(t1, arg, 24);
1843 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1844 tcg_gen_or_i64(t0, t0, t1);
1846 tcg_gen_shri_i64(t1, arg, 40);
1847 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1848 tcg_gen_or_i64(t0, t0, t1);
1850 tcg_gen_shri_i64(t1, arg, 56);
1851 tcg_gen_or_i64(ret, t0, t1);
1852 tcg_temp_free_i64(t0);
1853 tcg_temp_free_i64(t1);
1857 #endif
1859 static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
1861 if (TCG_TARGET_HAS_neg_i32) {
1862 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
1863 } else {
1864 TCGv_i32 t0 = tcg_const_i32(0);
1865 tcg_gen_sub_i32(ret, t0, arg);
1866 tcg_temp_free_i32(t0);
1870 static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
1872 if (TCG_TARGET_HAS_neg_i64) {
1873 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
1874 } else {
1875 TCGv_i64 t0 = tcg_const_i64(0);
1876 tcg_gen_sub_i64(ret, t0, arg);
1877 tcg_temp_free_i64(t0);
1881 static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
1883 if (TCG_TARGET_HAS_not_i32) {
1884 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1885 } else {
1886 tcg_gen_xori_i32(ret, arg, -1);
1890 static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
1892 #if TCG_TARGET_REG_BITS == 64
1893 if (TCG_TARGET_HAS_not_i64) {
1894 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
1895 } else {
1896 tcg_gen_xori_i64(ret, arg, -1);
1898 #else
1899 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1900 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1901 #endif
1904 static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1906 tcg_gen_op1_i32(INDEX_op_discard, arg);
1909 static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1911 #if TCG_TARGET_REG_BITS == 32
1912 tcg_gen_discard_i32(TCGV_LOW(arg));
1913 tcg_gen_discard_i32(TCGV_HIGH(arg));
1914 #else
1915 tcg_gen_op1_i64(INDEX_op_discard, arg);
1916 #endif
1919 static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1921 if (TCG_TARGET_HAS_andc_i32) {
1922 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1923 } else {
1924 TCGv_i32 t0 = tcg_temp_new_i32();
1925 tcg_gen_not_i32(t0, arg2);
1926 tcg_gen_and_i32(ret, arg1, t0);
1927 tcg_temp_free_i32(t0);
1931 static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1933 #if TCG_TARGET_REG_BITS == 64
1934 if (TCG_TARGET_HAS_andc_i64) {
1935 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1936 } else {
1937 TCGv_i64 t0 = tcg_temp_new_i64();
1938 tcg_gen_not_i64(t0, arg2);
1939 tcg_gen_and_i64(ret, arg1, t0);
1940 tcg_temp_free_i64(t0);
1942 #else
1943 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1944 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1945 #endif
1948 static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1950 if (TCG_TARGET_HAS_eqv_i32) {
1951 tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
1952 } else {
1953 tcg_gen_xor_i32(ret, arg1, arg2);
1954 tcg_gen_not_i32(ret, ret);
1958 static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1960 #if TCG_TARGET_REG_BITS == 64
1961 if (TCG_TARGET_HAS_eqv_i64) {
1962 tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
1963 } else {
1964 tcg_gen_xor_i64(ret, arg1, arg2);
1965 tcg_gen_not_i64(ret, ret);
1967 #else
1968 tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1969 tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1970 #endif
1973 static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1975 if (TCG_TARGET_HAS_nand_i32) {
1976 tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
1977 } else {
1978 tcg_gen_and_i32(ret, arg1, arg2);
1979 tcg_gen_not_i32(ret, ret);
1983 static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1985 #if TCG_TARGET_REG_BITS == 64
1986 if (TCG_TARGET_HAS_nand_i64) {
1987 tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
1988 } else {
1989 tcg_gen_and_i64(ret, arg1, arg2);
1990 tcg_gen_not_i64(ret, ret);
1992 #else
1993 tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1994 tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1995 #endif
1998 static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2000 if (TCG_TARGET_HAS_nor_i32) {
2001 tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
2002 } else {
2003 tcg_gen_or_i32(ret, arg1, arg2);
2004 tcg_gen_not_i32(ret, ret);
2008 static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2010 #if TCG_TARGET_REG_BITS == 64
2011 if (TCG_TARGET_HAS_nor_i64) {
2012 tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
2013 } else {
2014 tcg_gen_or_i64(ret, arg1, arg2);
2015 tcg_gen_not_i64(ret, ret);
2017 #else
2018 tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
2019 tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
2020 #endif
2023 static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2025 if (TCG_TARGET_HAS_orc_i32) {
2026 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
2027 } else {
2028 TCGv_i32 t0 = tcg_temp_new_i32();
2029 tcg_gen_not_i32(t0, arg2);
2030 tcg_gen_or_i32(ret, arg1, t0);
2031 tcg_temp_free_i32(t0);
2035 static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2037 #if TCG_TARGET_REG_BITS == 64
2038 if (TCG_TARGET_HAS_orc_i64) {
2039 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
2040 } else {
2041 TCGv_i64 t0 = tcg_temp_new_i64();
2042 tcg_gen_not_i64(t0, arg2);
2043 tcg_gen_or_i64(ret, arg1, t0);
2044 tcg_temp_free_i64(t0);
2046 #else
2047 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
2048 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
2049 #endif
2052 static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2054 if (TCG_TARGET_HAS_rot_i32) {
2055 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
2056 } else {
2057 TCGv_i32 t0, t1;
2059 t0 = tcg_temp_new_i32();
2060 t1 = tcg_temp_new_i32();
2061 tcg_gen_shl_i32(t0, arg1, arg2);
2062 tcg_gen_subfi_i32(t1, 32, arg2);
2063 tcg_gen_shr_i32(t1, arg1, t1);
2064 tcg_gen_or_i32(ret, t0, t1);
2065 tcg_temp_free_i32(t0);
2066 tcg_temp_free_i32(t1);
2070 static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2072 if (TCG_TARGET_HAS_rot_i64) {
2073 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
2074 } else {
2075 TCGv_i64 t0, t1;
2076 t0 = tcg_temp_new_i64();
2077 t1 = tcg_temp_new_i64();
2078 tcg_gen_shl_i64(t0, arg1, arg2);
2079 tcg_gen_subfi_i64(t1, 64, arg2);
2080 tcg_gen_shr_i64(t1, arg1, t1);
2081 tcg_gen_or_i64(ret, t0, t1);
2082 tcg_temp_free_i64(t0);
2083 tcg_temp_free_i64(t1);
2087 static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2089 /* some cases can be optimized here */
2090 if (arg2 == 0) {
2091 tcg_gen_mov_i32(ret, arg1);
2092 } else if (TCG_TARGET_HAS_rot_i32) {
2093 TCGv_i32 t0 = tcg_const_i32(arg2);
2094 tcg_gen_rotl_i32(ret, arg1, t0);
2095 tcg_temp_free_i32(t0);
2096 } else {
2097 TCGv_i32 t0, t1;
2098 t0 = tcg_temp_new_i32();
2099 t1 = tcg_temp_new_i32();
2100 tcg_gen_shli_i32(t0, arg1, arg2);
2101 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
2102 tcg_gen_or_i32(ret, t0, t1);
2103 tcg_temp_free_i32(t0);
2104 tcg_temp_free_i32(t1);
2108 static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2110 /* some cases can be optimized here */
2111 if (arg2 == 0) {
2112 tcg_gen_mov_i64(ret, arg1);
2113 } else if (TCG_TARGET_HAS_rot_i64) {
2114 TCGv_i64 t0 = tcg_const_i64(arg2);
2115 tcg_gen_rotl_i64(ret, arg1, t0);
2116 tcg_temp_free_i64(t0);
2117 } else {
2118 TCGv_i64 t0, t1;
2119 t0 = tcg_temp_new_i64();
2120 t1 = tcg_temp_new_i64();
2121 tcg_gen_shli_i64(t0, arg1, arg2);
2122 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
2123 tcg_gen_or_i64(ret, t0, t1);
2124 tcg_temp_free_i64(t0);
2125 tcg_temp_free_i64(t1);
2129 static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2131 if (TCG_TARGET_HAS_rot_i32) {
2132 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
2133 } else {
2134 TCGv_i32 t0, t1;
2136 t0 = tcg_temp_new_i32();
2137 t1 = tcg_temp_new_i32();
2138 tcg_gen_shr_i32(t0, arg1, arg2);
2139 tcg_gen_subfi_i32(t1, 32, arg2);
2140 tcg_gen_shl_i32(t1, arg1, t1);
2141 tcg_gen_or_i32(ret, t0, t1);
2142 tcg_temp_free_i32(t0);
2143 tcg_temp_free_i32(t1);
2147 static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2149 if (TCG_TARGET_HAS_rot_i64) {
2150 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
2151 } else {
2152 TCGv_i64 t0, t1;
2153 t0 = tcg_temp_new_i64();
2154 t1 = tcg_temp_new_i64();
2155 tcg_gen_shr_i64(t0, arg1, arg2);
2156 tcg_gen_subfi_i64(t1, 64, arg2);
2157 tcg_gen_shl_i64(t1, arg1, t1);
2158 tcg_gen_or_i64(ret, t0, t1);
2159 tcg_temp_free_i64(t0);
2160 tcg_temp_free_i64(t1);
2164 static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2166 /* some cases can be optimized here */
2167 if (arg2 == 0) {
2168 tcg_gen_mov_i32(ret, arg1);
2169 } else {
2170 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
2174 static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2176 /* some cases can be optimized here */
2177 if (arg2 == 0) {
2178 tcg_gen_mov_i64(ret, arg1);
2179 } else {
2180 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2184 static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
2185 TCGv_i32 arg2, unsigned int ofs,
2186 unsigned int len)
2188 uint32_t mask;
2189 TCGv_i32 t1;
2191 tcg_debug_assert(ofs < 32);
2192 tcg_debug_assert(len <= 32);
2193 tcg_debug_assert(ofs + len <= 32);
2195 if (ofs == 0 && len == 32) {
2196 tcg_gen_mov_i32(ret, arg2);
2197 return;
2199 if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
2200 tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
2201 return;
2204 mask = (1u << len) - 1;
2205 t1 = tcg_temp_new_i32();
2207 if (ofs + len < 32) {
2208 tcg_gen_andi_i32(t1, arg2, mask);
2209 tcg_gen_shli_i32(t1, t1, ofs);
2210 } else {
2211 tcg_gen_shli_i32(t1, arg2, ofs);
2213 tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
2214 tcg_gen_or_i32(ret, ret, t1);
2216 tcg_temp_free_i32(t1);
2219 static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
2220 TCGv_i64 arg2, unsigned int ofs,
2221 unsigned int len)
2223 uint64_t mask;
2224 TCGv_i64 t1;
2226 tcg_debug_assert(ofs < 64);
2227 tcg_debug_assert(len <= 64);
2228 tcg_debug_assert(ofs + len <= 64);
2230 if (ofs == 0 && len == 64) {
2231 tcg_gen_mov_i64(ret, arg2);
2232 return;
2234 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
2235 tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
2236 return;
2239 #if TCG_TARGET_REG_BITS == 32
2240 if (ofs >= 32) {
2241 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2242 TCGV_LOW(arg2), ofs - 32, len);
2243 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
2244 return;
2246 if (ofs + len <= 32) {
2247 tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
2248 TCGV_LOW(arg2), ofs, len);
2249 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
2250 return;
2252 #endif
2254 mask = (1ull << len) - 1;
2255 t1 = tcg_temp_new_i64();
2257 if (ofs + len < 64) {
2258 tcg_gen_andi_i64(t1, arg2, mask);
2259 tcg_gen_shli_i64(t1, t1, ofs);
2260 } else {
2261 tcg_gen_shli_i64(t1, arg2, ofs);
2263 tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
2264 tcg_gen_or_i64(ret, ret, t1);
2266 tcg_temp_free_i64(t1);
2269 static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
2270 TCGv_i32 high)
2272 #if TCG_TARGET_REG_BITS == 32
2273 tcg_gen_mov_i32(TCGV_LOW(dest), low);
2274 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
2275 #else
2276 TCGv_i64 tmp = tcg_temp_new_i64();
2277 /* These extensions are only needed for type correctness.
2278 We may be able to do better given target specific information. */
2279 tcg_gen_extu_i32_i64(tmp, high);
2280 tcg_gen_extu_i32_i64(dest, low);
2281 /* If deposit is available, use it. Otherwise use the extra
2282 knowledge that we have of the zero-extensions above. */
2283 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(32, 32)) {
2284 tcg_gen_deposit_i64(dest, dest, tmp, 32, 32);
2285 } else {
2286 tcg_gen_shli_i64(tmp, tmp, 32);
2287 tcg_gen_or_i64(dest, dest, tmp);
2289 tcg_temp_free_i64(tmp);
2290 #endif
2293 static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low,
2294 TCGv_i64 high)
2296 tcg_gen_deposit_i64(dest, low, high, 32, 32);
2299 static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
2301 tcg_gen_trunc_shr_i64_i32(ret, arg, 0);
2304 static inline void tcg_gen_extr_i64_i32(TCGv_i32 lo, TCGv_i32 hi, TCGv_i64 arg)
2306 tcg_gen_trunc_shr_i64_i32(lo, arg, 0);
2307 tcg_gen_trunc_shr_i64_i32(hi, arg, 32);
2310 static inline void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)
2312 tcg_gen_ext32u_i64(lo, arg);
2313 tcg_gen_shri_i64(hi, arg, 32);
2316 static inline void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret,
2317 TCGv_i32 c1, TCGv_i32 c2,
2318 TCGv_i32 v1, TCGv_i32 v2)
2320 if (TCG_TARGET_HAS_movcond_i32) {
2321 tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond);
2322 } else {
2323 TCGv_i32 t0 = tcg_temp_new_i32();
2324 TCGv_i32 t1 = tcg_temp_new_i32();
2325 tcg_gen_setcond_i32(cond, t0, c1, c2);
2326 tcg_gen_neg_i32(t0, t0);
2327 tcg_gen_and_i32(t1, v1, t0);
2328 tcg_gen_andc_i32(ret, v2, t0);
2329 tcg_gen_or_i32(ret, ret, t1);
2330 tcg_temp_free_i32(t0);
2331 tcg_temp_free_i32(t1);
2335 static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
2336 TCGv_i64 c1, TCGv_i64 c2,
2337 TCGv_i64 v1, TCGv_i64 v2)
2339 #if TCG_TARGET_REG_BITS == 32
2340 TCGv_i32 t0 = tcg_temp_new_i32();
2341 TCGv_i32 t1 = tcg_temp_new_i32();
2342 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
2343 TCGV_LOW(c1), TCGV_HIGH(c1),
2344 TCGV_LOW(c2), TCGV_HIGH(c2), cond);
2346 if (TCG_TARGET_HAS_movcond_i32) {
2347 tcg_gen_movi_i32(t1, 0);
2348 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
2349 TCGV_LOW(v1), TCGV_LOW(v2));
2350 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
2351 TCGV_HIGH(v1), TCGV_HIGH(v2));
2352 } else {
2353 tcg_gen_neg_i32(t0, t0);
2355 tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
2356 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
2357 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
2359 tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
2360 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
2361 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
2363 tcg_temp_free_i32(t0);
2364 tcg_temp_free_i32(t1);
2365 #else
2366 if (TCG_TARGET_HAS_movcond_i64) {
2367 tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond);
2368 } else {
2369 TCGv_i64 t0 = tcg_temp_new_i64();
2370 TCGv_i64 t1 = tcg_temp_new_i64();
2371 tcg_gen_setcond_i64(cond, t0, c1, c2);
2372 tcg_gen_neg_i64(t0, t0);
2373 tcg_gen_and_i64(t1, v1, t0);
2374 tcg_gen_andc_i64(ret, v2, t0);
2375 tcg_gen_or_i64(ret, ret, t1);
2376 tcg_temp_free_i64(t0);
2377 tcg_temp_free_i64(t1);
2379 #endif
2382 static inline void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2383 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2385 if (TCG_TARGET_HAS_add2_i32) {
2386 tcg_gen_op6_i32(INDEX_op_add2_i32, rl, rh, al, ah, bl, bh);
2387 /* Allow the optimizer room to replace add2 with two moves. */
2388 tcg_gen_op0(INDEX_op_nop);
2389 } else {
2390 TCGv_i64 t0 = tcg_temp_new_i64();
2391 TCGv_i64 t1 = tcg_temp_new_i64();
2392 tcg_gen_concat_i32_i64(t0, al, ah);
2393 tcg_gen_concat_i32_i64(t1, bl, bh);
2394 tcg_gen_add_i64(t0, t0, t1);
2395 tcg_gen_extr_i64_i32(rl, rh, t0);
2396 tcg_temp_free_i64(t0);
2397 tcg_temp_free_i64(t1);
2401 static inline void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2402 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2404 if (TCG_TARGET_HAS_sub2_i32) {
2405 tcg_gen_op6_i32(INDEX_op_sub2_i32, rl, rh, al, ah, bl, bh);
2406 /* Allow the optimizer room to replace sub2 with two moves. */
2407 tcg_gen_op0(INDEX_op_nop);
2408 } else {
2409 TCGv_i64 t0 = tcg_temp_new_i64();
2410 TCGv_i64 t1 = tcg_temp_new_i64();
2411 tcg_gen_concat_i32_i64(t0, al, ah);
2412 tcg_gen_concat_i32_i64(t1, bl, bh);
2413 tcg_gen_sub_i64(t0, t0, t1);
2414 tcg_gen_extr_i64_i32(rl, rh, t0);
2415 tcg_temp_free_i64(t0);
2416 tcg_temp_free_i64(t1);
2420 static inline void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh,
2421 TCGv_i32 arg1, TCGv_i32 arg2)
2423 if (TCG_TARGET_HAS_mulu2_i32) {
2424 tcg_gen_op4_i32(INDEX_op_mulu2_i32, rl, rh, arg1, arg2);
2425 /* Allow the optimizer room to replace mulu2 with two moves. */
2426 tcg_gen_op0(INDEX_op_nop);
2427 } else if (TCG_TARGET_HAS_muluh_i32) {
2428 TCGv_i32 t = tcg_temp_new_i32();
2429 tcg_gen_op3_i32(INDEX_op_mul_i32, t, arg1, arg2);
2430 tcg_gen_op3_i32(INDEX_op_muluh_i32, rh, arg1, arg2);
2431 tcg_gen_mov_i32(rl, t);
2432 tcg_temp_free_i32(t);
2433 } else {
2434 TCGv_i64 t0 = tcg_temp_new_i64();
2435 TCGv_i64 t1 = tcg_temp_new_i64();
2436 tcg_gen_extu_i32_i64(t0, arg1);
2437 tcg_gen_extu_i32_i64(t1, arg2);
2438 tcg_gen_mul_i64(t0, t0, t1);
2439 tcg_gen_extr_i64_i32(rl, rh, t0);
2440 tcg_temp_free_i64(t0);
2441 tcg_temp_free_i64(t1);
2445 static inline void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh,
2446 TCGv_i32 arg1, TCGv_i32 arg2)
2448 if (TCG_TARGET_HAS_muls2_i32) {
2449 tcg_gen_op4_i32(INDEX_op_muls2_i32, rl, rh, arg1, arg2);
2450 /* Allow the optimizer room to replace muls2 with two moves. */
2451 tcg_gen_op0(INDEX_op_nop);
2452 } else if (TCG_TARGET_HAS_mulsh_i32) {
2453 TCGv_i32 t = tcg_temp_new_i32();
2454 tcg_gen_op3_i32(INDEX_op_mul_i32, t, arg1, arg2);
2455 tcg_gen_op3_i32(INDEX_op_mulsh_i32, rh, arg1, arg2);
2456 tcg_gen_mov_i32(rl, t);
2457 tcg_temp_free_i32(t);
2458 } else if (TCG_TARGET_REG_BITS == 32) {
2459 TCGv_i32 t0 = tcg_temp_new_i32();
2460 TCGv_i32 t1 = tcg_temp_new_i32();
2461 TCGv_i32 t2 = tcg_temp_new_i32();
2462 TCGv_i32 t3 = tcg_temp_new_i32();
2463 tcg_gen_mulu2_i32(t0, t1, arg1, arg2);
2464 /* Adjust for negative inputs. */
2465 tcg_gen_sari_i32(t2, arg1, 31);
2466 tcg_gen_sari_i32(t3, arg2, 31);
2467 tcg_gen_and_i32(t2, t2, arg2);
2468 tcg_gen_and_i32(t3, t3, arg1);
2469 tcg_gen_sub_i32(rh, t1, t2);
2470 tcg_gen_sub_i32(rh, rh, t3);
2471 tcg_gen_mov_i32(rl, t0);
2472 tcg_temp_free_i32(t0);
2473 tcg_temp_free_i32(t1);
2474 tcg_temp_free_i32(t2);
2475 tcg_temp_free_i32(t3);
2476 } else {
2477 TCGv_i64 t0 = tcg_temp_new_i64();
2478 TCGv_i64 t1 = tcg_temp_new_i64();
2479 tcg_gen_ext_i32_i64(t0, arg1);
2480 tcg_gen_ext_i32_i64(t1, arg2);
2481 tcg_gen_mul_i64(t0, t0, t1);
2482 tcg_gen_extr_i64_i32(rl, rh, t0);
2483 tcg_temp_free_i64(t0);
2484 tcg_temp_free_i64(t1);
2488 static inline void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2489 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2491 if (TCG_TARGET_HAS_add2_i64) {
2492 tcg_gen_op6_i64(INDEX_op_add2_i64, rl, rh, al, ah, bl, bh);
2493 /* Allow the optimizer room to replace add2 with two moves. */
2494 tcg_gen_op0(INDEX_op_nop);
2495 } else {
2496 TCGv_i64 t0 = tcg_temp_new_i64();
2497 TCGv_i64 t1 = tcg_temp_new_i64();
2498 tcg_gen_add_i64(t0, al, bl);
2499 tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, al);
2500 tcg_gen_add_i64(rh, ah, bh);
2501 tcg_gen_add_i64(rh, rh, t1);
2502 tcg_gen_mov_i64(rl, t0);
2503 tcg_temp_free_i64(t0);
2504 tcg_temp_free_i64(t1);
2508 static inline void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2509 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2511 if (TCG_TARGET_HAS_sub2_i64) {
2512 tcg_gen_op6_i64(INDEX_op_sub2_i64, rl, rh, al, ah, bl, bh);
2513 /* Allow the optimizer room to replace sub2 with two moves. */
2514 tcg_gen_op0(INDEX_op_nop);
2515 } else {
2516 TCGv_i64 t0 = tcg_temp_new_i64();
2517 TCGv_i64 t1 = tcg_temp_new_i64();
2518 tcg_gen_sub_i64(t0, al, bl);
2519 tcg_gen_setcond_i64(TCG_COND_LTU, t1, al, bl);
2520 tcg_gen_sub_i64(rh, ah, bh);
2521 tcg_gen_sub_i64(rh, rh, t1);
2522 tcg_gen_mov_i64(rl, t0);
2523 tcg_temp_free_i64(t0);
2524 tcg_temp_free_i64(t1);
2528 static inline void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh,
2529 TCGv_i64 arg1, TCGv_i64 arg2)
2531 if (TCG_TARGET_HAS_mulu2_i64) {
2532 tcg_gen_op4_i64(INDEX_op_mulu2_i64, rl, rh, arg1, arg2);
2533 /* Allow the optimizer room to replace mulu2 with two moves. */
2534 tcg_gen_op0(INDEX_op_nop);
2535 } else if (TCG_TARGET_HAS_muluh_i64) {
2536 TCGv_i64 t = tcg_temp_new_i64();
2537 tcg_gen_op3_i64(INDEX_op_mul_i64, t, arg1, arg2);
2538 tcg_gen_op3_i64(INDEX_op_muluh_i64, rh, arg1, arg2);
2539 tcg_gen_mov_i64(rl, t);
2540 tcg_temp_free_i64(t);
2541 } else {
2542 TCGv_i64 t0 = tcg_temp_new_i64();
2543 int sizemask = 0;
2544 /* Return value and both arguments are 64-bit and unsigned. */
2545 sizemask |= tcg_gen_sizemask(0, 1, 0);
2546 sizemask |= tcg_gen_sizemask(1, 1, 0);
2547 sizemask |= tcg_gen_sizemask(2, 1, 0);
2548 tcg_gen_mul_i64(t0, arg1, arg2);
2549 tcg_gen_helper64(tcg_helper_muluh_i64, sizemask, rh, arg1, arg2);
2550 tcg_gen_mov_i64(rl, t0);
2551 tcg_temp_free_i64(t0);
2555 static inline void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh,
2556 TCGv_i64 arg1, TCGv_i64 arg2)
2558 if (TCG_TARGET_HAS_muls2_i64) {
2559 tcg_gen_op4_i64(INDEX_op_muls2_i64, rl, rh, arg1, arg2);
2560 /* Allow the optimizer room to replace muls2 with two moves. */
2561 tcg_gen_op0(INDEX_op_nop);
2562 } else if (TCG_TARGET_HAS_mulsh_i64) {
2563 TCGv_i64 t = tcg_temp_new_i64();
2564 tcg_gen_op3_i64(INDEX_op_mul_i64, t, arg1, arg2);
2565 tcg_gen_op3_i64(INDEX_op_mulsh_i64, rh, arg1, arg2);
2566 tcg_gen_mov_i64(rl, t);
2567 tcg_temp_free_i64(t);
2568 } else if (TCG_TARGET_HAS_mulu2_i64 || TCG_TARGET_HAS_muluh_i64) {
2569 TCGv_i64 t0 = tcg_temp_new_i64();
2570 TCGv_i64 t1 = tcg_temp_new_i64();
2571 TCGv_i64 t2 = tcg_temp_new_i64();
2572 TCGv_i64 t3 = tcg_temp_new_i64();
2573 tcg_gen_mulu2_i64(t0, t1, arg1, arg2);
2574 /* Adjust for negative inputs. */
2575 tcg_gen_sari_i64(t2, arg1, 63);
2576 tcg_gen_sari_i64(t3, arg2, 63);
2577 tcg_gen_and_i64(t2, t2, arg2);
2578 tcg_gen_and_i64(t3, t3, arg1);
2579 tcg_gen_sub_i64(rh, t1, t2);
2580 tcg_gen_sub_i64(rh, rh, t3);
2581 tcg_gen_mov_i64(rl, t0);
2582 tcg_temp_free_i64(t0);
2583 tcg_temp_free_i64(t1);
2584 tcg_temp_free_i64(t2);
2585 tcg_temp_free_i64(t3);
2586 } else {
2587 TCGv_i64 t0 = tcg_temp_new_i64();
2588 int sizemask = 0;
2589 /* Return value and both arguments are 64-bit and signed. */
2590 sizemask |= tcg_gen_sizemask(0, 1, 1);
2591 sizemask |= tcg_gen_sizemask(1, 1, 1);
2592 sizemask |= tcg_gen_sizemask(2, 1, 1);
2593 tcg_gen_mul_i64(t0, arg1, arg2);
2594 tcg_gen_helper64(tcg_helper_mulsh_i64, sizemask, rh, arg1, arg2);
2595 tcg_gen_mov_i64(rl, t0);
2596 tcg_temp_free_i64(t0);
2600 /***************************************/
2601 /* QEMU specific operations. Their type depend on the QEMU CPU
2602 type. */
2603 #ifndef TARGET_LONG_BITS
2604 #error must include QEMU headers
2605 #endif
2607 #if TARGET_LONG_BITS == 32
2608 #define TCGv TCGv_i32
2609 #define tcg_temp_new() tcg_temp_new_i32()
2610 #define tcg_global_reg_new tcg_global_reg_new_i32
2611 #define tcg_global_mem_new tcg_global_mem_new_i32
2612 #define tcg_temp_local_new() tcg_temp_local_new_i32()
2613 #define tcg_temp_free tcg_temp_free_i32
2614 #define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
2615 #define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I32(x)
2616 #define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
2617 #define tcg_add_param_tl tcg_add_param_i32
2618 #define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i32
2619 #define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i32
2620 #else
2621 #define TCGv TCGv_i64
2622 #define tcg_temp_new() tcg_temp_new_i64()
2623 #define tcg_global_reg_new tcg_global_reg_new_i64
2624 #define tcg_global_mem_new tcg_global_mem_new_i64
2625 #define tcg_temp_local_new() tcg_temp_local_new_i64()
2626 #define tcg_temp_free tcg_temp_free_i64
2627 #define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
2628 #define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I64(x)
2629 #define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
2630 #define tcg_add_param_tl tcg_add_param_i64
2631 #define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i64
2632 #define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i64
2633 #endif
2635 /* debug info: write the PC of the corresponding QEMU CPU instruction */
2636 static inline void tcg_gen_debug_insn_start(uint64_t pc)
2638 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2639 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
2640 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2641 (uint32_t)(pc), (uint32_t)(pc >> 32));
2642 #else
2643 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2644 #endif
2647 static inline void tcg_gen_exit_tb(uintptr_t val)
2649 tcg_gen_op1i(INDEX_op_exit_tb, val);
2652 static inline void tcg_gen_goto_tb(unsigned idx)
2654 /* We only support two chained exits. */
2655 tcg_debug_assert(idx <= 1);
2656 #ifdef CONFIG_DEBUG_TCG
2657 /* Verify that we havn't seen this numbered exit before. */
2658 tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
2659 tcg_ctx.goto_tb_issue_mask |= 1 << idx;
2660 #endif
2661 tcg_gen_op1i(INDEX_op_goto_tb, idx);
2665 void tcg_gen_qemu_ld_i32(TCGv_i32, TCGv, TCGArg, TCGMemOp);
2666 void tcg_gen_qemu_st_i32(TCGv_i32, TCGv, TCGArg, TCGMemOp);
2667 void tcg_gen_qemu_ld_i64(TCGv_i64, TCGv, TCGArg, TCGMemOp);
2668 void tcg_gen_qemu_st_i64(TCGv_i64, TCGv, TCGArg, TCGMemOp);
2670 static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
2672 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_UB);
2675 static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
2677 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_SB);
2680 static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
2682 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TEUW);
2685 static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
2687 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TESW);
2690 static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
2692 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TEUL);
2695 static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
2697 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TESL);
2700 static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
2702 tcg_gen_qemu_ld_i64(ret, addr, mem_index, MO_TEQ);
2705 static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
2707 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_UB);
2710 static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
2712 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_TEUW);
2715 static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
2717 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_TEUL);
2720 static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
2722 tcg_gen_qemu_st_i64(arg, addr, mem_index, MO_TEQ);
2725 #if TARGET_LONG_BITS == 64
2726 #define tcg_gen_movi_tl tcg_gen_movi_i64
2727 #define tcg_gen_mov_tl tcg_gen_mov_i64
2728 #define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2729 #define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2730 #define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2731 #define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2732 #define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2733 #define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2734 #define tcg_gen_ld_tl tcg_gen_ld_i64
2735 #define tcg_gen_st8_tl tcg_gen_st8_i64
2736 #define tcg_gen_st16_tl tcg_gen_st16_i64
2737 #define tcg_gen_st32_tl tcg_gen_st32_i64
2738 #define tcg_gen_st_tl tcg_gen_st_i64
2739 #define tcg_gen_add_tl tcg_gen_add_i64
2740 #define tcg_gen_addi_tl tcg_gen_addi_i64
2741 #define tcg_gen_sub_tl tcg_gen_sub_i64
2742 #define tcg_gen_neg_tl tcg_gen_neg_i64
2743 #define tcg_gen_subfi_tl tcg_gen_subfi_i64
2744 #define tcg_gen_subi_tl tcg_gen_subi_i64
2745 #define tcg_gen_and_tl tcg_gen_and_i64
2746 #define tcg_gen_andi_tl tcg_gen_andi_i64
2747 #define tcg_gen_or_tl tcg_gen_or_i64
2748 #define tcg_gen_ori_tl tcg_gen_ori_i64
2749 #define tcg_gen_xor_tl tcg_gen_xor_i64
2750 #define tcg_gen_xori_tl tcg_gen_xori_i64
2751 #define tcg_gen_not_tl tcg_gen_not_i64
2752 #define tcg_gen_shl_tl tcg_gen_shl_i64
2753 #define tcg_gen_shli_tl tcg_gen_shli_i64
2754 #define tcg_gen_shr_tl tcg_gen_shr_i64
2755 #define tcg_gen_shri_tl tcg_gen_shri_i64
2756 #define tcg_gen_sar_tl tcg_gen_sar_i64
2757 #define tcg_gen_sari_tl tcg_gen_sari_i64
2758 #define tcg_gen_brcond_tl tcg_gen_brcond_i64
2759 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2760 #define tcg_gen_setcond_tl tcg_gen_setcond_i64
2761 #define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
2762 #define tcg_gen_mul_tl tcg_gen_mul_i64
2763 #define tcg_gen_muli_tl tcg_gen_muli_i64
2764 #define tcg_gen_div_tl tcg_gen_div_i64
2765 #define tcg_gen_rem_tl tcg_gen_rem_i64
2766 #define tcg_gen_divu_tl tcg_gen_divu_i64
2767 #define tcg_gen_remu_tl tcg_gen_remu_i64
2768 #define tcg_gen_discard_tl tcg_gen_discard_i64
2769 #define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2770 #define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2771 #define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2772 #define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2773 #define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2774 #define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
2775 #define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2776 #define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2777 #define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2778 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2779 #define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2780 #define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
2781 #define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2782 #define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2783 #define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
2784 #define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2785 #define tcg_gen_extr_i64_tl tcg_gen_extr32_i64
2786 #define tcg_gen_andc_tl tcg_gen_andc_i64
2787 #define tcg_gen_eqv_tl tcg_gen_eqv_i64
2788 #define tcg_gen_nand_tl tcg_gen_nand_i64
2789 #define tcg_gen_nor_tl tcg_gen_nor_i64
2790 #define tcg_gen_orc_tl tcg_gen_orc_i64
2791 #define tcg_gen_rotl_tl tcg_gen_rotl_i64
2792 #define tcg_gen_rotli_tl tcg_gen_rotli_i64
2793 #define tcg_gen_rotr_tl tcg_gen_rotr_i64
2794 #define tcg_gen_rotri_tl tcg_gen_rotri_i64
2795 #define tcg_gen_deposit_tl tcg_gen_deposit_i64
2796 #define tcg_const_tl tcg_const_i64
2797 #define tcg_const_local_tl tcg_const_local_i64
2798 #define tcg_gen_movcond_tl tcg_gen_movcond_i64
2799 #define tcg_gen_add2_tl tcg_gen_add2_i64
2800 #define tcg_gen_sub2_tl tcg_gen_sub2_i64
2801 #define tcg_gen_mulu2_tl tcg_gen_mulu2_i64
2802 #define tcg_gen_muls2_tl tcg_gen_muls2_i64
2803 #else
2804 #define tcg_gen_movi_tl tcg_gen_movi_i32
2805 #define tcg_gen_mov_tl tcg_gen_mov_i32
2806 #define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2807 #define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2808 #define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2809 #define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2810 #define tcg_gen_ld32u_tl tcg_gen_ld_i32
2811 #define tcg_gen_ld32s_tl tcg_gen_ld_i32
2812 #define tcg_gen_ld_tl tcg_gen_ld_i32
2813 #define tcg_gen_st8_tl tcg_gen_st8_i32
2814 #define tcg_gen_st16_tl tcg_gen_st16_i32
2815 #define tcg_gen_st32_tl tcg_gen_st_i32
2816 #define tcg_gen_st_tl tcg_gen_st_i32
2817 #define tcg_gen_add_tl tcg_gen_add_i32
2818 #define tcg_gen_addi_tl tcg_gen_addi_i32
2819 #define tcg_gen_sub_tl tcg_gen_sub_i32
2820 #define tcg_gen_neg_tl tcg_gen_neg_i32
2821 #define tcg_gen_subfi_tl tcg_gen_subfi_i32
2822 #define tcg_gen_subi_tl tcg_gen_subi_i32
2823 #define tcg_gen_and_tl tcg_gen_and_i32
2824 #define tcg_gen_andi_tl tcg_gen_andi_i32
2825 #define tcg_gen_or_tl tcg_gen_or_i32
2826 #define tcg_gen_ori_tl tcg_gen_ori_i32
2827 #define tcg_gen_xor_tl tcg_gen_xor_i32
2828 #define tcg_gen_xori_tl tcg_gen_xori_i32
2829 #define tcg_gen_not_tl tcg_gen_not_i32
2830 #define tcg_gen_shl_tl tcg_gen_shl_i32
2831 #define tcg_gen_shli_tl tcg_gen_shli_i32
2832 #define tcg_gen_shr_tl tcg_gen_shr_i32
2833 #define tcg_gen_shri_tl tcg_gen_shri_i32
2834 #define tcg_gen_sar_tl tcg_gen_sar_i32
2835 #define tcg_gen_sari_tl tcg_gen_sari_i32
2836 #define tcg_gen_brcond_tl tcg_gen_brcond_i32
2837 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2838 #define tcg_gen_setcond_tl tcg_gen_setcond_i32
2839 #define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
2840 #define tcg_gen_mul_tl tcg_gen_mul_i32
2841 #define tcg_gen_muli_tl tcg_gen_muli_i32
2842 #define tcg_gen_div_tl tcg_gen_div_i32
2843 #define tcg_gen_rem_tl tcg_gen_rem_i32
2844 #define tcg_gen_divu_tl tcg_gen_divu_i32
2845 #define tcg_gen_remu_tl tcg_gen_remu_i32
2846 #define tcg_gen_discard_tl tcg_gen_discard_i32
2847 #define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2848 #define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2849 #define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2850 #define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2851 #define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2852 #define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
2853 #define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2854 #define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2855 #define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2856 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2857 #define tcg_gen_ext32u_tl tcg_gen_mov_i32
2858 #define tcg_gen_ext32s_tl tcg_gen_mov_i32
2859 #define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2860 #define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2861 #define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2862 #define tcg_gen_extr_tl_i64 tcg_gen_extr_i32_i64
2863 #define tcg_gen_andc_tl tcg_gen_andc_i32
2864 #define tcg_gen_eqv_tl tcg_gen_eqv_i32
2865 #define tcg_gen_nand_tl tcg_gen_nand_i32
2866 #define tcg_gen_nor_tl tcg_gen_nor_i32
2867 #define tcg_gen_orc_tl tcg_gen_orc_i32
2868 #define tcg_gen_rotl_tl tcg_gen_rotl_i32
2869 #define tcg_gen_rotli_tl tcg_gen_rotli_i32
2870 #define tcg_gen_rotr_tl tcg_gen_rotr_i32
2871 #define tcg_gen_rotri_tl tcg_gen_rotri_i32
2872 #define tcg_gen_deposit_tl tcg_gen_deposit_i32
2873 #define tcg_const_tl tcg_const_i32
2874 #define tcg_const_local_tl tcg_const_local_i32
2875 #define tcg_gen_movcond_tl tcg_gen_movcond_i32
2876 #define tcg_gen_add2_tl tcg_gen_add2_i32
2877 #define tcg_gen_sub2_tl tcg_gen_sub2_i32
2878 #define tcg_gen_mulu2_tl tcg_gen_mulu2_i32
2879 #define tcg_gen_muls2_tl tcg_gen_muls2_i32
2880 #endif
2882 #if UINTPTR_MAX == UINT32_MAX
2883 # define tcg_gen_ld_ptr(R, A, O) \
2884 tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2885 # define tcg_gen_discard_ptr(A) \
2886 tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
2887 # define tcg_gen_add_ptr(R, A, B) \
2888 tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), TCGV_PTR_TO_NAT(B))
2889 # define tcg_gen_addi_ptr(R, A, B) \
2890 tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), (B))
2891 # define tcg_gen_ext_i32_ptr(R, A) \
2892 tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
2893 #else
2894 # define tcg_gen_ld_ptr(R, A, O) \
2895 tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2896 # define tcg_gen_discard_ptr(A) \
2897 tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
2898 # define tcg_gen_add_ptr(R, A, B) \
2899 tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), TCGV_PTR_TO_NAT(B))
2900 # define tcg_gen_addi_ptr(R, A, B) \
2901 tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), (B))
2902 # define tcg_gen_ext_i32_ptr(R, A) \
2903 tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
2904 #endif /* UINTPTR_MAX == UINT32_MAX */