]> Git Repo - qemu.git/blame - tcg/tcg-op.h
tcg/tcg.h: Duplicate global TCG variables in TCGContext
[qemu.git] / tcg / tcg-op.h
CommitLineData
c896fe29
FB
1/*
2 * Tiny Code Generator for QEMU
3 *
4 * Copyright (c) 2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24#include "tcg.h"
25
c896fe29
FB
26int gen_new_label(void);
27
212c328d
RH
28static inline void tcg_gen_op0(TCGOpcode opc)
29{
30 *gen_opc_ptr++ = opc;
31}
32
a9751609 33static inline void tcg_gen_op1_i32(TCGOpcode opc, TCGv_i32 arg1)
c896fe29
FB
34{
35 *gen_opc_ptr++ = opc;
a7812ae4
PB
36 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
37}
38
a9751609 39static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
a7812ae4
PB
40{
41 *gen_opc_ptr++ = opc;
42 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
c896fe29
FB
43}
44
a9751609 45static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg arg1)
c896fe29
FB
46{
47 *gen_opc_ptr++ = opc;
48 *gen_opparam_ptr++ = arg1;
c896fe29
FB
49}
50
a9751609 51static inline void tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2)
a7812ae4
PB
52{
53 *gen_opc_ptr++ = opc;
54 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
55 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
56}
57
a9751609 58static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
a7812ae4
PB
59{
60 *gen_opc_ptr++ = opc;
61 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
62 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
63}
64
a9751609 65static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
c896fe29
FB
66{
67 *gen_opc_ptr++ = opc;
a7812ae4
PB
68 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
69 *gen_opparam_ptr++ = arg2;
c896fe29
FB
70}
71
a9751609 72static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
c896fe29
FB
73{
74 *gen_opc_ptr++ = opc;
a7812ae4 75 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
c896fe29 76 *gen_opparam_ptr++ = arg2;
ac56dd48
PB
77}
78
a9751609 79static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg arg1, TCGArg arg2)
bcb0126f
PB
80{
81 *gen_opc_ptr++ = opc;
82 *gen_opparam_ptr++ = arg1;
83 *gen_opparam_ptr++ = arg2;
84}
85
a9751609 86static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
87 TCGv_i32 arg3)
88{
89 *gen_opc_ptr++ = opc;
90 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
91 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
92 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
93}
94
a9751609 95static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4
PB
96 TCGv_i64 arg3)
97{
98 *gen_opc_ptr++ = opc;
99 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
100 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
101 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
102}
103
a9751609
RH
104static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
105 TCGv_i32 arg2, TCGArg arg3)
ac56dd48
PB
106{
107 *gen_opc_ptr++ = opc;
a7812ae4
PB
108 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
109 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
110 *gen_opparam_ptr++ = arg3;
ac56dd48
PB
111}
112
a9751609
RH
113static inline void tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 arg1,
114 TCGv_i64 arg2, TCGArg arg3)
ac56dd48
PB
115{
116 *gen_opc_ptr++ = opc;
a7812ae4
PB
117 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
118 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
c896fe29 119 *gen_opparam_ptr++ = arg3;
ac56dd48
PB
120}
121
a9751609
RH
122static inline void tcg_gen_ldst_op_i32(TCGOpcode opc, TCGv_i32 val,
123 TCGv_ptr base, TCGArg offset)
a7812ae4
PB
124{
125 *gen_opc_ptr++ = opc;
126 *gen_opparam_ptr++ = GET_TCGV_I32(val);
127 *gen_opparam_ptr++ = GET_TCGV_PTR(base);
128 *gen_opparam_ptr++ = offset;
129}
130
a9751609
RH
131static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
132 TCGv_ptr base, TCGArg offset)
a7812ae4
PB
133{
134 *gen_opc_ptr++ = opc;
a810a2de 135 *gen_opparam_ptr++ = GET_TCGV_I64(val);
a7812ae4
PB
136 *gen_opparam_ptr++ = GET_TCGV_PTR(base);
137 *gen_opparam_ptr++ = offset;
138}
139
a9751609
RH
140static inline void tcg_gen_qemu_ldst_op_i64_i32(TCGOpcode opc, TCGv_i64 val,
141 TCGv_i32 addr, TCGArg mem_index)
a7812ae4
PB
142{
143 *gen_opc_ptr++ = opc;
144 *gen_opparam_ptr++ = GET_TCGV_I64(val);
145 *gen_opparam_ptr++ = GET_TCGV_I32(addr);
146 *gen_opparam_ptr++ = mem_index;
147}
148
a9751609
RH
149static inline void tcg_gen_qemu_ldst_op_i64_i64(TCGOpcode opc, TCGv_i64 val,
150 TCGv_i64 addr, TCGArg mem_index)
a7812ae4
PB
151{
152 *gen_opc_ptr++ = opc;
153 *gen_opparam_ptr++ = GET_TCGV_I64(val);
154 *gen_opparam_ptr++ = GET_TCGV_I64(addr);
155 *gen_opparam_ptr++ = mem_index;
156}
157
a9751609 158static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
159 TCGv_i32 arg3, TCGv_i32 arg4)
160{
161 *gen_opc_ptr++ = opc;
162 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
163 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
164 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
165 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
166}
167
a9751609 168static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a810a2de 169 TCGv_i64 arg3, TCGv_i64 arg4)
a7812ae4
PB
170{
171 *gen_opc_ptr++ = opc;
172 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
173 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
174 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
175 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
176}
177
a9751609 178static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
179 TCGv_i32 arg3, TCGArg arg4)
180{
181 *gen_opc_ptr++ = opc;
182 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
183 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
184 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
185 *gen_opparam_ptr++ = arg4;
186}
187
a9751609 188static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4 189 TCGv_i64 arg3, TCGArg arg4)
ac56dd48
PB
190{
191 *gen_opc_ptr++ = opc;
a7812ae4
PB
192 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
193 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
194 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
195 *gen_opparam_ptr++ = arg4;
ac56dd48
PB
196}
197
a9751609 198static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4 199 TCGArg arg3, TCGArg arg4)
ac56dd48
PB
200{
201 *gen_opc_ptr++ = opc;
a7812ae4
PB
202 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
203 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
204 *gen_opparam_ptr++ = arg3;
c896fe29
FB
205 *gen_opparam_ptr++ = arg4;
206}
207
a9751609 208static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4 209 TCGArg arg3, TCGArg arg4)
c896fe29
FB
210{
211 *gen_opc_ptr++ = opc;
a7812ae4
PB
212 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
213 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
c896fe29
FB
214 *gen_opparam_ptr++ = arg3;
215 *gen_opparam_ptr++ = arg4;
ac56dd48
PB
216}
217
a9751609 218static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
219 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
220{
221 *gen_opc_ptr++ = opc;
222 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
223 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
224 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
225 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
226 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
227}
228
a9751609 229static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4
PB
230 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
231{
232 *gen_opc_ptr++ = opc;
233 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
234 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
235 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
236 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
237 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
238}
239
a9751609 240static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4 241 TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
ac56dd48
PB
242{
243 *gen_opc_ptr++ = opc;
a7812ae4
PB
244 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
245 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
246 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
247 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
248 *gen_opparam_ptr++ = arg5;
ac56dd48
PB
249}
250
a9751609 251static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4 252 TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
ac56dd48
PB
253{
254 *gen_opc_ptr++ = opc;
a7812ae4
PB
255 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
256 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
257 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
258 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
c896fe29
FB
259 *gen_opparam_ptr++ = arg5;
260}
261
b7767f0f
RH
262static inline void tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 arg1,
263 TCGv_i32 arg2, TCGv_i32 arg3,
264 TCGArg arg4, TCGArg arg5)
265{
266 *gen_opc_ptr++ = opc;
267 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
268 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
269 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
270 *gen_opparam_ptr++ = arg4;
271 *gen_opparam_ptr++ = arg5;
272}
273
274static inline void tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 arg1,
275 TCGv_i64 arg2, TCGv_i64 arg3,
276 TCGArg arg4, TCGArg arg5)
277{
278 *gen_opc_ptr++ = opc;
279 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
280 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
281 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
282 *gen_opparam_ptr++ = arg4;
283 *gen_opparam_ptr++ = arg5;
284}
285
a9751609 286static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
287 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
288 TCGv_i32 arg6)
289{
290 *gen_opc_ptr++ = opc;
291 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
292 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
293 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
294 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
295 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
296 *gen_opparam_ptr++ = GET_TCGV_I32(arg6);
297}
298
a9751609 299static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4
PB
300 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
301 TCGv_i64 arg6)
c896fe29
FB
302{
303 *gen_opc_ptr++ = opc;
a7812ae4
PB
304 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
305 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
306 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
307 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
308 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
309 *gen_opparam_ptr++ = GET_TCGV_I64(arg6);
ac56dd48
PB
310}
311
a9751609 312static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
be210acb
RH
313 TCGv_i32 arg3, TCGv_i32 arg4,
314 TCGv_i32 arg5, TCGArg arg6)
315{
316 *gen_opc_ptr++ = opc;
317 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
318 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
319 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
320 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
321 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
322 *gen_opparam_ptr++ = arg6;
323}
324
a9751609 325static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
be210acb
RH
326 TCGv_i64 arg3, TCGv_i64 arg4,
327 TCGv_i64 arg5, TCGArg arg6)
328{
329 *gen_opc_ptr++ = opc;
330 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
331 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
332 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
333 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
334 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
335 *gen_opparam_ptr++ = arg6;
336}
337
a9751609
RH
338static 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)
ac56dd48
PB
341{
342 *gen_opc_ptr++ = opc;
a7812ae4
PB
343 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
344 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
345 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
346 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
347 *gen_opparam_ptr++ = arg5;
348 *gen_opparam_ptr++ = arg6;
349}
350
a9751609
RH
351static 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)
a7812ae4
PB
354{
355 *gen_opc_ptr++ = opc;
356 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
357 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
358 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
359 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
c896fe29
FB
360 *gen_opparam_ptr++ = arg5;
361 *gen_opparam_ptr++ = arg6;
362}
363
364static inline void gen_set_label(int n)
365{
ac56dd48 366 tcg_gen_op1i(INDEX_op_set_label, n);
c896fe29
FB
367}
368
fb50d413
BS
369static inline void tcg_gen_br(int label)
370{
371 tcg_gen_op1i(INDEX_op_br, label);
372}
373
a7812ae4 374static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 375{
fe75bcf7 376 if (!TCGV_EQUAL_I32(ret, arg))
a7812ae4 377 tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
c896fe29
FB
378}
379
a7812ae4 380static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
c896fe29 381{
a7812ae4 382 tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
c896fe29
FB
383}
384
2bece2c8
RH
385/* A version of dh_sizemask from def-helper.h that doesn't rely on
386 preprocessor magic. */
387static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
388{
389 return (is_64bit << n*2) | (is_signed << (n*2 + 1));
390}
391
c896fe29 392/* helper calls */
a7812ae4
PB
393static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
394 TCGArg ret, int nargs, TCGArg *args)
395{
396 TCGv_ptr fn;
73f5e313 397 fn = tcg_const_ptr(func);
a7812ae4
PB
398 tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
399 nargs, args);
400 tcg_temp_free_ptr(fn);
401}
c896fe29 402
dbfff4de 403/* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
78505279
AJ
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. */
2bece2c8 408static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
31d66551
AJ
409 TCGv_i32 a, TCGv_i32 b)
410{
411 TCGv_ptr fn;
412 TCGArg args[2];
73f5e313 413 fn = tcg_const_ptr(func);
31d66551
AJ
414 args[0] = GET_TCGV_I32(a);
415 args[1] = GET_TCGV_I32(b);
78505279
AJ
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);
31d66551
AJ
419 tcg_temp_free_ptr(fn);
420}
421
2bece2c8 422static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
a7812ae4 423 TCGv_i64 a, TCGv_i64 b)
c896fe29 424{
a7812ae4
PB
425 TCGv_ptr fn;
426 TCGArg args[2];
73f5e313 427 fn = tcg_const_ptr(func);
a7812ae4
PB
428 args[0] = GET_TCGV_I64(a);
429 args[1] = GET_TCGV_I64(b);
78505279
AJ
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);
a7812ae4 433 tcg_temp_free_ptr(fn);
f8422f52
BS
434}
435
c896fe29
FB
436/* 32 bit ops */
437
a7812ae4 438static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 439{
a7812ae4 440 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
c896fe29
FB
441}
442
a7812ae4 443static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 444{
a7812ae4 445 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
c896fe29
FB
446}
447
a7812ae4 448static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 449{
a7812ae4 450 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
c896fe29
FB
451}
452
a7812ae4 453static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 454{
a7812ae4 455 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
c896fe29
FB
456}
457
a7812ae4 458static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 459{
a7812ae4 460 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
c896fe29
FB
461}
462
a7812ae4 463static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 464{
a7812ae4 465 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
c896fe29
FB
466}
467
a7812ae4 468static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 469{
a7812ae4 470 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
c896fe29
FB
471}
472
a7812ae4 473static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 474{
a7812ae4 475 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
c896fe29
FB
476}
477
a7812ae4 478static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 479{
a7812ae4 480 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
c896fe29
FB
481}
482
a7812ae4 483static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 484{
7089442c
BS
485 /* some cases can be optimized here */
486 if (arg2 == 0) {
487 tcg_gen_mov_i32(ret, arg1);
488 } else {
a7812ae4 489 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 490 tcg_gen_add_i32(ret, arg1, t0);
a7812ae4 491 tcg_temp_free_i32(t0);
7089442c 492 }
c896fe29
FB
493}
494
a7812ae4 495static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 496{
a7812ae4 497 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
c896fe29
FB
498}
499
a7812ae4 500static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
0045734a 501{
a7812ae4 502 TCGv_i32 t0 = tcg_const_i32(arg1);
0045734a 503 tcg_gen_sub_i32(ret, t0, arg2);
a7812ae4 504 tcg_temp_free_i32(t0);
0045734a
AJ
505}
506
a7812ae4 507static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 508{
7089442c
BS
509 /* some cases can be optimized here */
510 if (arg2 == 0) {
511 tcg_gen_mov_i32(ret, arg1);
512 } else {
a7812ae4 513 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 514 tcg_gen_sub_i32(ret, arg1, t0);
a7812ae4 515 tcg_temp_free_i32(t0);
7089442c 516 }
c896fe29
FB
517}
518
a7812ae4 519static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 520{
7fc81051
AJ
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);
525 }
c896fe29
FB
526}
527
42ce3e20 528static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
c896fe29 529{
42ce3e20
RH
530 TCGv_i32 t0;
531 /* Some cases can be optimized here. */
532 switch (arg2) {
533 case 0:
c896fe29 534 tcg_gen_movi_i32(ret, 0);
42ce3e20
RH
535 return;
536 case 0xffffffffu:
c896fe29 537 tcg_gen_mov_i32(ret, arg1);
42ce3e20
RH
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;
544 }
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;
550 }
551 break;
c896fe29 552 }
42ce3e20
RH
553 t0 = tcg_const_i32(arg2);
554 tcg_gen_and_i32(ret, arg1, t0);
555 tcg_temp_free_i32(t0);
c896fe29
FB
556}
557
a7812ae4 558static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 559{
7fc81051
AJ
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);
564 }
c896fe29
FB
565}
566
a7812ae4 567static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 568{
d81ada7f
RH
569 /* Some cases can be optimized here. */
570 if (arg2 == -1) {
571 tcg_gen_movi_i32(ret, -1);
c896fe29
FB
572 } else if (arg2 == 0) {
573 tcg_gen_mov_i32(ret, arg1);
574 } else {
a7812ae4 575 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 576 tcg_gen_or_i32(ret, arg1, t0);
a7812ae4 577 tcg_temp_free_i32(t0);
c896fe29
FB
578 }
579}
580
a7812ae4 581static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 582{
7fc81051
AJ
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);
587 }
c896fe29
FB
588}
589
a7812ae4 590static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 591{
6f3bb33e 592 /* Some cases can be optimized here. */
c896fe29
FB
593 if (arg2 == 0) {
594 tcg_gen_mov_i32(ret, arg1);
6f3bb33e
RH
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);
c896fe29 598 } else {
a7812ae4 599 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 600 tcg_gen_xor_i32(ret, arg1, t0);
a7812ae4 601 tcg_temp_free_i32(t0);
c896fe29
FB
602 }
603}
604
a7812ae4 605static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 606{
a7812ae4 607 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
c896fe29
FB
608}
609
a7812ae4 610static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 611{
34151a20
FB
612 if (arg2 == 0) {
613 tcg_gen_mov_i32(ret, arg1);
614 } else {
a7812ae4 615 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 616 tcg_gen_shl_i32(ret, arg1, t0);
a7812ae4 617 tcg_temp_free_i32(t0);
34151a20 618 }
c896fe29
FB
619}
620
a7812ae4 621static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 622{
a7812ae4 623 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
c896fe29
FB
624}
625
a7812ae4 626static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 627{
34151a20
FB
628 if (arg2 == 0) {
629 tcg_gen_mov_i32(ret, arg1);
630 } else {
a7812ae4 631 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 632 tcg_gen_shr_i32(ret, arg1, t0);
a7812ae4 633 tcg_temp_free_i32(t0);
34151a20 634 }
c896fe29
FB
635}
636
a7812ae4 637static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 638{
a7812ae4 639 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
c896fe29
FB
640}
641
a7812ae4 642static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 643{
34151a20
FB
644 if (arg2 == 0) {
645 tcg_gen_mov_i32(ret, arg1);
646 } else {
a7812ae4 647 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 648 tcg_gen_sar_i32(ret, arg1, t0);
a7812ae4 649 tcg_temp_free_i32(t0);
34151a20 650 }
c896fe29
FB
651}
652
8a56e840
RH
653static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
654 TCGv_i32 arg2, int label_index)
c896fe29 655{
0aed257f
RH
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);
660 }
c896fe29
FB
661}
662
8a56e840
RH
663static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
664 int32_t arg2, int label_index)
cb63669a 665{
0aed257f
RH
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);
672 }
cb63669a
PB
673}
674
8a56e840 675static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
5105c556
AJ
676 TCGv_i32 arg1, TCGv_i32 arg2)
677{
0aed257f
RH
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);
684 }
5105c556
AJ
685}
686
8a56e840
RH
687static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
688 TCGv_i32 arg1, int32_t arg2)
5105c556 689{
0aed257f
RH
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);
698 }
5105c556
AJ
699}
700
a7812ae4 701static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 702{
a7812ae4 703 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
c896fe29
FB
704}
705
a7812ae4 706static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
f730fd27 707{
a7812ae4 708 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 709 tcg_gen_mul_i32(ret, arg1, t0);
a7812ae4 710 tcg_temp_free_i32(t0);
f730fd27
TS
711}
712
a7812ae4 713static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 714{
25c4d9cc
RH
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);
729 }
31d66551
AJ
730}
731
732static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
733{
25c4d9cc
RH
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);
748 }
31d66551
AJ
749}
750
751static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
752{
25c4d9cc
RH
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);
767 }
31d66551
AJ
768}
769
770static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
771{
25c4d9cc
RH
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);
786 }
31d66551 787}
c896fe29
FB
788
789#if TCG_TARGET_REG_BITS == 32
790
a7812ae4 791static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 792{
fe75bcf7 793 if (!TCGV_EQUAL_I64(ret, arg)) {
a7812ae4 794 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
4d07272d
BS
795 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
796 }
c896fe29
FB
797}
798
a7812ae4 799static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
c896fe29 800{
a7812ae4 801 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
ac56dd48 802 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
c896fe29
FB
803}
804
a7812ae4
PB
805static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
806 tcg_target_long offset)
c896fe29 807{
a7812ae4 808 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 809 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
810}
811
a7812ae4
PB
812static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
813 tcg_target_long offset)
c896fe29 814{
a7812ae4
PB
815 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
816 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
c896fe29
FB
817}
818
a7812ae4
PB
819static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
820 tcg_target_long offset)
c896fe29 821{
a747723b 822 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 823 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
824}
825
a7812ae4
PB
826static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
827 tcg_target_long offset)
c896fe29 828{
a7812ae4
PB
829 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
830 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
831}
832
a7812ae4
PB
833static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
834 tcg_target_long offset)
c896fe29 835{
a7812ae4 836 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 837 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
838}
839
a7812ae4
PB
840static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
841 tcg_target_long offset)
c896fe29 842{
a7812ae4
PB
843 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
844 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
845}
846
a7812ae4
PB
847static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
848 tcg_target_long offset)
c896fe29
FB
849{
850 /* since arg2 and ret have different types, they cannot be the
851 same temporary */
852#ifdef TCG_TARGET_WORDS_BIGENDIAN
ac56dd48 853 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
a7812ae4 854 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
c896fe29 855#else
a7812ae4 856 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 857 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
c896fe29
FB
858#endif
859}
860
a7812ae4
PB
861static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
862 tcg_target_long offset)
c896fe29 863{
a7812ae4 864 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
865}
866
a7812ae4
PB
867static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
868 tcg_target_long offset)
c896fe29 869{
a7812ae4 870 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
871}
872
a7812ae4
PB
873static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
874 tcg_target_long offset)
c896fe29 875{
a7812ae4 876 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
877}
878
a7812ae4
PB
879static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
880 tcg_target_long offset)
c896fe29
FB
881{
882#ifdef TCG_TARGET_WORDS_BIGENDIAN
ac56dd48 883 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
a7812ae4 884 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
c896fe29 885#else
a7812ae4 886 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
ac56dd48 887 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
c896fe29
FB
888#endif
889}
890
a7812ae4 891static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 892{
a7812ae4
PB
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));
212c328d
RH
896 /* Allow the optimizer room to replace add2 with two moves. */
897 tcg_gen_op0(INDEX_op_nop);
c896fe29
FB
898}
899
a7812ae4 900static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 901{
a7812ae4
PB
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));
212c328d
RH
905 /* Allow the optimizer room to replace sub2 with two moves. */
906 tcg_gen_op0(INDEX_op_nop);
c896fe29
FB
907}
908
a7812ae4 909static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 910{
a7812ae4 911 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
ac56dd48 912 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
913}
914
a7812ae4 915static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 916{
e5105083
AJ
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);
c896fe29
FB
919}
920
a7812ae4 921static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 922{
e5105083
AJ
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));
c896fe29
FB
925}
926
a7812ae4 927static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 928{
a7812ae4 929 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
ac56dd48 930 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
931}
932
a7812ae4 933static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 934{
e5105083
AJ
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));
c896fe29
FB
937}
938
a7812ae4 939static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 940{
a7812ae4 941 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
ac56dd48 942 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
943}
944
945/* XXX: use generic code when basic block handling is OK or CPU
946 specific code (x86) */
a7812ae4 947static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 948{
2bece2c8
RH
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);
954
955 tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
956}
957
a7812ae4 958static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
959{
960 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
961}
962
a7812ae4 963static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 964{
2bece2c8
RH
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);
970
971 tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
972}
973
a7812ae4 974static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
975{
976 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
977}
978
a7812ae4 979static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 980{
2bece2c8
RH
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);
986
987 tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
988}
989
a7812ae4 990static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
991{
992 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
993}
994
8a56e840
RH
995static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
996 TCGv_i64 arg2, int label_index)
c896fe29 997{
0aed257f
RH
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);
1004 }
c896fe29
FB
1005}
1006
8a56e840 1007static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
5105c556
AJ
1008 TCGv_i64 arg1, TCGv_i64 arg2)
1009{
0aed257f
RH
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);
1018 }
5105c556
AJ
1019 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1020}
1021
a7812ae4 1022static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1023{
a7812ae4
PB
1024 TCGv_i64 t0;
1025 TCGv_i32 t1;
c896fe29 1026
a7812ae4
PB
1027 t0 = tcg_temp_new_i64();
1028 t1 = tcg_temp_new_i32();
1029
1030 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
1031 TCGV_LOW(arg1), TCGV_LOW(arg2));
1414968a
RH
1032 /* Allow the optimizer room to replace mulu2 with two moves. */
1033 tcg_gen_op0(INDEX_op_nop);
a7812ae4
PB
1034
1035 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
ac56dd48 1036 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
a7812ae4 1037 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
ac56dd48 1038 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
a7812ae4 1039
c896fe29 1040 tcg_gen_mov_i64(ret, t0);
a7812ae4
PB
1041 tcg_temp_free_i64(t0);
1042 tcg_temp_free_i32(t1);
c896fe29
FB
1043}
1044
a7812ae4 1045static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1046{
2bece2c8
RH
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);
1052
1053 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1054}
1055
a7812ae4 1056static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1057{
2bece2c8
RH
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);
1063
1064 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1065}
1066
a7812ae4 1067static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1068{
2bece2c8
RH
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);
1074
1075 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1076}
1077
a7812ae4 1078static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1079{
2bece2c8
RH
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);
1085
1086 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1087}
1088
1089#else
1090
a7812ae4 1091static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1092{
fe75bcf7 1093 if (!TCGV_EQUAL_I64(ret, arg))
a7812ae4 1094 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
c896fe29
FB
1095}
1096
a7812ae4 1097static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
c896fe29 1098{
a7812ae4 1099 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
c896fe29
FB
1100}
1101
6bd4b08a 1102static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1103 tcg_target_long offset)
c896fe29 1104{
a7812ae4 1105 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
c896fe29
FB
1106}
1107
6bd4b08a 1108static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1109 tcg_target_long offset)
c896fe29 1110{
a7812ae4 1111 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
c896fe29
FB
1112}
1113
6bd4b08a 1114static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1115 tcg_target_long offset)
c896fe29 1116{
a7812ae4 1117 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
c896fe29
FB
1118}
1119
6bd4b08a 1120static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1121 tcg_target_long offset)
c896fe29 1122{
a7812ae4 1123 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
c896fe29
FB
1124}
1125
6bd4b08a 1126static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1127 tcg_target_long offset)
c896fe29 1128{
a7812ae4 1129 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
c896fe29
FB
1130}
1131
6bd4b08a 1132static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1133 tcg_target_long offset)
c896fe29 1134{
a7812ae4 1135 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
c896fe29
FB
1136}
1137
6bd4b08a 1138static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 1139{
a7812ae4 1140 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
c896fe29
FB
1141}
1142
6bd4b08a 1143static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1144 tcg_target_long offset)
c896fe29 1145{
a7812ae4 1146 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
c896fe29
FB
1147}
1148
6bd4b08a 1149static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1150 tcg_target_long offset)
c896fe29 1151{
a7812ae4 1152 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
c896fe29
FB
1153}
1154
6bd4b08a 1155static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1156 tcg_target_long offset)
c896fe29 1157{
a7812ae4 1158 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
c896fe29
FB
1159}
1160
6bd4b08a 1161static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 1162{
a7812ae4 1163 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
c896fe29
FB
1164}
1165
a7812ae4 1166static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1167{
a7812ae4 1168 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
c896fe29
FB
1169}
1170
a7812ae4 1171static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1172{
a7812ae4 1173 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
c896fe29
FB
1174}
1175
a7812ae4 1176static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1177{
7fc81051
AJ
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);
1182 }
c896fe29
FB
1183}
1184
42ce3e20 1185static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
c896fe29 1186{
42ce3e20
RH
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;
1201 }
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;
1207 }
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;
1213 }
1214 break;
1215 }
1216 t0 = tcg_const_i64(arg2);
e8996ee0 1217 tcg_gen_and_i64(ret, arg1, t0);
a7812ae4 1218 tcg_temp_free_i64(t0);
c896fe29
FB
1219}
1220
a7812ae4 1221static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1222{
7fc81051
AJ
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);
1227 }
c896fe29
FB
1228}
1229
a7812ae4 1230static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1231{
d81ada7f
RH
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);
1241 }
c896fe29
FB
1242}
1243
a7812ae4 1244static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1245{
7fc81051
AJ
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);
1250 }
c896fe29
FB
1251}
1252
a7812ae4 1253static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1254{
6f3bb33e
RH
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);
1265 }
c896fe29
FB
1266}
1267
a7812ae4 1268static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1269{
a7812ae4 1270 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
c896fe29
FB
1271}
1272
a7812ae4 1273static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1274{
34151a20
FB
1275 if (arg2 == 0) {
1276 tcg_gen_mov_i64(ret, arg1);
1277 } else {
a7812ae4 1278 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1279 tcg_gen_shl_i64(ret, arg1, t0);
a7812ae4 1280 tcg_temp_free_i64(t0);
34151a20 1281 }
c896fe29
FB
1282}
1283
a7812ae4 1284static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1285{
a7812ae4 1286 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
c896fe29
FB
1287}
1288
a7812ae4 1289static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1290{
34151a20
FB
1291 if (arg2 == 0) {
1292 tcg_gen_mov_i64(ret, arg1);
1293 } else {
a7812ae4 1294 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1295 tcg_gen_shr_i64(ret, arg1, t0);
a7812ae4 1296 tcg_temp_free_i64(t0);
34151a20 1297 }
c896fe29
FB
1298}
1299
a7812ae4 1300static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1301{
a7812ae4 1302 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
c896fe29
FB
1303}
1304
a7812ae4 1305static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1306{
34151a20
FB
1307 if (arg2 == 0) {
1308 tcg_gen_mov_i64(ret, arg1);
1309 } else {
a7812ae4 1310 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1311 tcg_gen_sar_i64(ret, arg1, t0);
a7812ae4 1312 tcg_temp_free_i64(t0);
34151a20 1313 }
c896fe29
FB
1314}
1315
8a56e840
RH
1316static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1317 TCGv_i64 arg2, int label_index)
c896fe29 1318{
0aed257f
RH
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);
1323 }
c896fe29
FB
1324}
1325
8a56e840 1326static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
5105c556
AJ
1327 TCGv_i64 arg1, TCGv_i64 arg2)
1328{
0aed257f
RH
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);
1335 }
5105c556
AJ
1336}
1337
a7812ae4 1338static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1339{
a7812ae4 1340 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
c896fe29
FB
1341}
1342
31d66551
AJ
1343static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1344{
25c4d9cc
RH
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);
1359 }
31d66551
AJ
1360}
1361
1362static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1363{
25c4d9cc
RH
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);
1378 }
31d66551
AJ
1379}
1380
1381static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1382{
25c4d9cc
RH
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);
1397 }
31d66551
AJ
1398}
1399
1400static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1401{
25c4d9cc
RH
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);
1416 }
31d66551 1417}
25c4d9cc 1418#endif /* TCG_TARGET_REG_BITS == 32 */
c896fe29 1419
a7812ae4 1420static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
6359706f
AJ
1421{
1422 /* some cases can be optimized here */
1423 if (arg2 == 0) {
1424 tcg_gen_mov_i64(ret, arg1);
1425 } else {
a7812ae4 1426 TCGv_i64 t0 = tcg_const_i64(arg2);
6359706f 1427 tcg_gen_add_i64(ret, arg1, t0);
a7812ae4 1428 tcg_temp_free_i64(t0);
6359706f
AJ
1429 }
1430}
1431
a7812ae4 1432static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
0045734a 1433{
a7812ae4 1434 TCGv_i64 t0 = tcg_const_i64(arg1);
0045734a 1435 tcg_gen_sub_i64(ret, t0, arg2);
a7812ae4 1436 tcg_temp_free_i64(t0);
0045734a
AJ
1437}
1438
a7812ae4 1439static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
6359706f
AJ
1440{
1441 /* some cases can be optimized here */
1442 if (arg2 == 0) {
1443 tcg_gen_mov_i64(ret, arg1);
1444 } else {
a7812ae4 1445 TCGv_i64 t0 = tcg_const_i64(arg2);
6359706f 1446 tcg_gen_sub_i64(ret, arg1, t0);
a7812ae4 1447 tcg_temp_free_i64(t0);
6359706f
AJ
1448 }
1449}
8a56e840
RH
1450static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1451 int64_t arg2, int label_index)
f02bb954 1452{
0aed257f
RH
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);
1459 }
f02bb954
AJ
1460}
1461
8a56e840
RH
1462static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1463 TCGv_i64 arg1, int64_t arg2)
5105c556
AJ
1464{
1465 TCGv_i64 t0 = tcg_const_i64(arg2);
1466 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1467 tcg_temp_free_i64(t0);
1468}
1469
a7812ae4 1470static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
f02bb954 1471{
a7812ae4 1472 TCGv_i64 t0 = tcg_const_i64(arg2);
f02bb954 1473 tcg_gen_mul_i64(ret, arg1, t0);
a7812ae4 1474 tcg_temp_free_i64(t0);
f02bb954
AJ
1475}
1476
6359706f 1477
c896fe29
FB
1478/***************************************/
1479/* optional operations */
1480
a7812ae4 1481static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1482{
25c4d9cc
RH
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);
1488 }
c896fe29
FB
1489}
1490
a7812ae4 1491static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1492{
25c4d9cc
RH
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);
1498 }
c896fe29
FB
1499}
1500
a7812ae4 1501static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
86831435 1502{
25c4d9cc
RH
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);
1507 }
86831435
PB
1508}
1509
a7812ae4 1510static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
86831435 1511{
25c4d9cc
RH
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);
1516 }
86831435
PB
1517}
1518
c896fe29 1519/* Note: we assume the two high bytes are set to zero */
a7812ae4 1520static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1521{
25c4d9cc
RH
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();
c896fe29 1526
25c4d9cc
RH
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);
1532 }
c896fe29
FB
1533}
1534
66896cb8 1535static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1536{
25c4d9cc
RH
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();
c896fe29 1543
25c4d9cc 1544 tcg_gen_shli_i32(t0, arg, 24);
c896fe29 1545
25c4d9cc
RH
1546 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1547 tcg_gen_shli_i32(t1, t1, 8);
1548 tcg_gen_or_i32(t0, t0, t1);
c896fe29 1549
25c4d9cc
RH
1550 tcg_gen_shri_i32(t1, arg, 8);
1551 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1552 tcg_gen_or_i32(t0, t0, t1);
c896fe29 1553
25c4d9cc
RH
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);
1558 }
c896fe29
FB
1559}
1560
1561#if TCG_TARGET_REG_BITS == 32
a7812ae4 1562static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1563{
a7812ae4
PB
1564 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1565 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1566}
1567
a7812ae4 1568static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1569{
a7812ae4
PB
1570 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1571 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1572}
1573
a7812ae4 1574static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1575{
a7812ae4
PB
1576 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1577 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1578}
1579
a7812ae4 1580static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1581{
a7812ae4 1582 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1583 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1584}
1585
a7812ae4 1586static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1587{
a7812ae4 1588 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1589 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1590}
1591
a7812ae4 1592static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1593{
a7812ae4 1594 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1595 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1596}
1597
a7812ae4 1598static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
c896fe29 1599{
a7812ae4 1600 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
c896fe29
FB
1601}
1602
a7812ae4 1603static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1604{
a7812ae4 1605 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
ac56dd48 1606 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1607}
1608
a7812ae4 1609static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1610{
a7812ae4
PB
1611 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1612 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1613}
1614
9a5c57fd
AJ
1615/* Note: we assume the six high bytes are set to zero */
1616static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1617{
1618 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1619 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1620}
1621
1622/* Note: we assume the four high bytes are set to zero */
1623static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1624{
1625 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1626 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1627}
1628
66896cb8 1629static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1630{
a7812ae4
PB
1631 TCGv_i32 t0, t1;
1632 t0 = tcg_temp_new_i32();
1633 t1 = tcg_temp_new_i32();
c896fe29 1634
66896cb8
AJ
1635 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1636 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
a7812ae4 1637 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
ac56dd48 1638 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
a7812ae4
PB
1639 tcg_temp_free_i32(t0);
1640 tcg_temp_free_i32(t1);
c896fe29
FB
1641}
1642#else
1643
a7812ae4 1644static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1645{
25c4d9cc
RH
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);
1651 }
c896fe29
FB
1652}
1653
a7812ae4 1654static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1655{
25c4d9cc
RH
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);
1661 }
c896fe29
FB
1662}
1663
a7812ae4 1664static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1665{
25c4d9cc
RH
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);
1671 }
c896fe29
FB
1672}
1673
a7812ae4 1674static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1675{
25c4d9cc
RH
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);
1680 }
86831435
PB
1681}
1682
a7812ae4 1683static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1684{
25c4d9cc
RH
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);
1689 }
86831435
PB
1690}
1691
a7812ae4 1692static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1693{
25c4d9cc
RH
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);
1698 }
86831435
PB
1699}
1700
c896fe29 1701/* Note: we assume the target supports move between 32 and 64 bit
ac56dd48 1702 registers. This will probably break MIPS64 targets. */
a7812ae4 1703static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
c896fe29 1704{
a7812ae4 1705 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
c896fe29
FB
1706}
1707
1708/* Note: we assume the target supports move between 32 and 64 bit
1709 registers */
a7812ae4 1710static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1711{
cfc86988 1712 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
c896fe29
FB
1713}
1714
1715/* Note: we assume the target supports move between 32 and 64 bit
1716 registers */
a7812ae4 1717static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1718{
a7812ae4 1719 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
c896fe29
FB
1720}
1721
9a5c57fd
AJ
1722/* Note: we assume the six high bytes are set to zero */
1723static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1724{
25c4d9cc
RH
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();
9a5c57fd 1729
25c4d9cc
RH
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);
1735 }
9a5c57fd
AJ
1736}
1737
1738/* Note: we assume the four high bytes are set to zero */
1739static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1740{
25c4d9cc
RH
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();
9a5c57fd 1747
25c4d9cc
RH
1748 tcg_gen_shli_i64(t0, arg, 24);
1749 tcg_gen_ext32u_i64(t0, t0);
9a5c57fd 1750
25c4d9cc
RH
1751 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1752 tcg_gen_shli_i64(t1, t1, 8);
1753 tcg_gen_or_i64(t0, t0, t1);
9a5c57fd 1754
25c4d9cc
RH
1755 tcg_gen_shri_i64(t1, arg, 8);
1756 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1757 tcg_gen_or_i64(t0, t0, t1);
9a5c57fd 1758
25c4d9cc
RH
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);
1763 }
9a5c57fd
AJ
1764}
1765
66896cb8 1766static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1767{
25c4d9cc
RH
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();
c896fe29 1773
25c4d9cc 1774 tcg_gen_shli_i64(t0, arg, 56);
c896fe29 1775
25c4d9cc
RH
1776 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1777 tcg_gen_shli_i64(t1, t1, 40);
1778 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1779
25c4d9cc
RH
1780 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1781 tcg_gen_shli_i64(t1, t1, 24);
1782 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1783
25c4d9cc
RH
1784 tcg_gen_andi_i64(t1, arg, 0xff000000);
1785 tcg_gen_shli_i64(t1, t1, 8);
1786 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1787
25c4d9cc
RH
1788 tcg_gen_shri_i64(t1, arg, 8);
1789 tcg_gen_andi_i64(t1, t1, 0xff000000);
1790 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1791
25c4d9cc
RH
1792 tcg_gen_shri_i64(t1, arg, 24);
1793 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1794 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1795
25c4d9cc
RH
1796 tcg_gen_shri_i64(t1, arg, 40);
1797 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1798 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1799
25c4d9cc
RH
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);
1804 }
c896fe29
FB
1805}
1806
1807#endif
1808
a7812ae4 1809static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
390efc54 1810{
25c4d9cc
RH
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);
1817 }
390efc54
PB
1818}
1819
a7812ae4 1820static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
390efc54 1821{
25c4d9cc
RH
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);
1828 }
390efc54
PB
1829}
1830
a7812ae4 1831static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
0b6ce4cf 1832{
25c4d9cc
RH
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);
1837 }
0b6ce4cf
FB
1838}
1839
a7812ae4 1840static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
0b6ce4cf 1841{
25c4d9cc
RH
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);
1847 }
1848#else
a10f9f4f
RH
1849 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1850 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
d2604285 1851#endif
0b6ce4cf 1852}
5ff9d6a4 1853
a7812ae4 1854static inline void tcg_gen_discard_i32(TCGv_i32 arg)
5ff9d6a4 1855{
a7812ae4 1856 tcg_gen_op1_i32(INDEX_op_discard, arg);
5ff9d6a4
FB
1857}
1858
a7812ae4 1859static inline void tcg_gen_discard_i64(TCGv_i64 arg)
5ff9d6a4 1860{
25c4d9cc 1861#if TCG_TARGET_REG_BITS == 32
a7812ae4 1862 tcg_gen_discard_i32(TCGV_LOW(arg));
5ff9d6a4 1863 tcg_gen_discard_i32(TCGV_HIGH(arg));
5ff9d6a4 1864#else
a7812ae4 1865 tcg_gen_op1_i64(INDEX_op_discard, arg);
5ff9d6a4 1866#endif
25c4d9cc 1867}
5ff9d6a4 1868
a7812ae4 1869static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1870{
25c4d9cc
RH
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);
1878 }
f24cb33e
AJ
1879}
1880
a7812ae4 1881static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1882{
25c4d9cc
RH
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);
1891 }
1892#else
241cbed4
RH
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));
241cbed4 1895#endif
f24cb33e
AJ
1896}
1897
a7812ae4 1898static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1899{
25c4d9cc
RH
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);
1905 }
f24cb33e
AJ
1906}
1907
a7812ae4 1908static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1909{
25c4d9cc
RH
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);
1916 }
1917#else
8d625cf1
RH
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));
8d625cf1 1920#endif
f24cb33e
AJ
1921}
1922
a7812ae4 1923static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1924{
25c4d9cc
RH
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);
1930 }
f24cb33e
AJ
1931}
1932
a7812ae4 1933static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1934{
25c4d9cc
RH
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);
1941 }
1942#else
9940a96b
RH
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));
9940a96b 1945#endif
f24cb33e
AJ
1946}
1947
a7812ae4 1948static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1949{
25c4d9cc
RH
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);
1955 }
f24cb33e
AJ
1956}
1957
a7812ae4 1958static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1959{
25c4d9cc
RH
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);
1966 }
1967#else
32d98fbd
RH
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));
32d98fbd 1970#endif
f24cb33e
AJ
1971}
1972
a7812ae4 1973static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1974{
25c4d9cc
RH
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);
1982 }
f24cb33e
AJ
1983}
1984
a7812ae4 1985static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1986{
25c4d9cc
RH
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);
1995 }
1996#else
791d1262
RH
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));
791d1262 1999#endif
f24cb33e
AJ
2000}
2001
a7812ae4 2002static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
15824571 2003{
25c4d9cc
RH
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;
15824571 2008
25c4d9cc
RH
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);
2017 }
15824571
AJ
2018}
2019
a7812ae4 2020static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
15824571 2021{
25c4d9cc
RH
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);
2034 }
15824571
AJ
2035}
2036
a7812ae4 2037static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
15824571
AJ
2038{
2039 /* some cases can be optimized here */
2040 if (arg2 == 0) {
2041 tcg_gen_mov_i32(ret, arg1);
25c4d9cc 2042 } else if (TCG_TARGET_HAS_rot_i32) {
d42f183c
AJ
2043 TCGv_i32 t0 = tcg_const_i32(arg2);
2044 tcg_gen_rotl_i32(ret, arg1, t0);
2045 tcg_temp_free_i32(t0);
25c4d9cc 2046 } else {
a7812ae4
PB
2047 TCGv_i32 t0, t1;
2048 t0 = tcg_temp_new_i32();
2049 t1 = tcg_temp_new_i32();
15824571
AJ
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);
a7812ae4
PB
2053 tcg_temp_free_i32(t0);
2054 tcg_temp_free_i32(t1);
15824571
AJ
2055 }
2056}
2057
a7812ae4 2058static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
15824571
AJ
2059{
2060 /* some cases can be optimized here */
2061 if (arg2 == 0) {
2062 tcg_gen_mov_i64(ret, arg1);
25c4d9cc 2063 } else if (TCG_TARGET_HAS_rot_i64) {
d42f183c
AJ
2064 TCGv_i64 t0 = tcg_const_i64(arg2);
2065 tcg_gen_rotl_i64(ret, arg1, t0);
2066 tcg_temp_free_i64(t0);
25c4d9cc 2067 } else {
a7812ae4
PB
2068 TCGv_i64 t0, t1;
2069 t0 = tcg_temp_new_i64();
2070 t1 = tcg_temp_new_i64();
15824571
AJ
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);
a7812ae4
PB
2074 tcg_temp_free_i64(t0);
2075 tcg_temp_free_i64(t1);
15824571
AJ
2076 }
2077}
2078
a7812ae4 2079static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
15824571 2080{
25c4d9cc
RH
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;
15824571 2085
25c4d9cc
RH
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);
2094 }
15824571
AJ
2095}
2096
a7812ae4 2097static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
15824571 2098{
25c4d9cc
RH
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);
2111 }
15824571
AJ
2112}
2113
a7812ae4 2114static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
15824571
AJ
2115{
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);
2121 }
2122}
2123
a7812ae4 2124static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
15824571
AJ
2125{
2126 /* some cases can be optimized here */
2127 if (arg2 == 0) {
de3526b2 2128 tcg_gen_mov_i64(ret, arg1);
15824571
AJ
2129 } else {
2130 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2131 }
2132}
2133
b7767f0f 2134static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
0756e71c
RH
2135 TCGv_i32 arg2, unsigned int ofs,
2136 unsigned int len)
b7767f0f 2137{
df072774
RH
2138 uint32_t mask;
2139 TCGv_i32 t1;
2140
717e7036
RH
2141 tcg_debug_assert(ofs < 32);
2142 tcg_debug_assert(len <= 32);
2143 tcg_debug_assert(ofs + len <= 32);
2144
df072774
RH
2145 if (ofs == 0 && len == 32) {
2146 tcg_gen_mov_i32(ret, arg2);
2147 return;
2148 }
a4773324 2149 if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
25c4d9cc 2150 tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
df072774
RH
2151 return;
2152 }
2153
2154 mask = (1u << len) - 1;
2155 t1 = tcg_temp_new_i32();
b7767f0f 2156
df072774 2157 if (ofs + len < 32) {
25c4d9cc
RH
2158 tcg_gen_andi_i32(t1, arg2, mask);
2159 tcg_gen_shli_i32(t1, t1, ofs);
df072774
RH
2160 } else {
2161 tcg_gen_shli_i32(t1, arg2, ofs);
25c4d9cc 2162 }
df072774
RH
2163 tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
2164 tcg_gen_or_i32(ret, ret, t1);
2165
2166 tcg_temp_free_i32(t1);
b7767f0f
RH
2167}
2168
2169static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
0756e71c
RH
2170 TCGv_i64 arg2, unsigned int ofs,
2171 unsigned int len)
b7767f0f 2172{
df072774
RH
2173 uint64_t mask;
2174 TCGv_i64 t1;
2175
717e7036
RH
2176 tcg_debug_assert(ofs < 64);
2177 tcg_debug_assert(len <= 64);
2178 tcg_debug_assert(ofs + len <= 64);
2179
df072774
RH
2180 if (ofs == 0 && len == 64) {
2181 tcg_gen_mov_i64(ret, arg2);
2182 return;
2183 }
a4773324 2184 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
25c4d9cc 2185 tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
df072774
RH
2186 return;
2187 }
b7767f0f 2188
df072774
RH
2189#if TCG_TARGET_REG_BITS == 32
2190 if (ofs >= 32) {
2f98c9db 2191 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
df072774
RH
2192 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2193 TCGV_LOW(arg2), ofs - 32, len);
2194 return;
2195 }
2196 if (ofs + len <= 32) {
2197 tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
2198 TCGV_LOW(arg2), ofs, len);
2f98c9db 2199 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
df072774
RH
2200 return;
2201 }
2202#endif
2203
2204 mask = (1ull << len) - 1;
2205 t1 = tcg_temp_new_i64();
2206
2207 if (ofs + len < 64) {
25c4d9cc
RH
2208 tcg_gen_andi_i64(t1, arg2, mask);
2209 tcg_gen_shli_i64(t1, t1, ofs);
df072774
RH
2210 } else {
2211 tcg_gen_shli_i64(t1, arg2, ofs);
25c4d9cc 2212 }
df072774
RH
2213 tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
2214 tcg_gen_or_i64(ret, ret, t1);
2215
2216 tcg_temp_free_i64(t1);
b7767f0f
RH
2217}
2218
77276f65
RH
2219static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
2220 TCGv_i32 high)
2221{
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);
2238 }
2239 tcg_temp_free_i64(tmp);
2240#endif
2241}
2242
2243static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low,
2244 TCGv_i64 high)
2245{
2246 tcg_gen_deposit_i64(dest, low, high, 32, 32);
2247}
2248
ffc5ea09
RH
2249static 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)
2252{
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);
2265 }
2266}
2267
2268static 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)
2271{
a463133e
RH
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);
a463133e 2278
a80a6b63
RH
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);
a463133e 2287
a80a6b63
RH
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);
a463133e 2291
a80a6b63
RH
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);
2295 }
a463133e
RH
2296 tcg_temp_free_i32(t0);
2297 tcg_temp_free_i32(t1);
2298#else
ffc5ea09
RH
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);
2311 }
a463133e 2312#endif
ffc5ea09
RH
2313}
2314
c896fe29
FB
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
2321
a7812ae4
PB
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
df9247b2 2327#define tcg_temp_local_new() tcg_temp_local_new_i32()
a7812ae4
PB
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)
fe75bcf7 2332#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
a7812ae4
PB
2333#else
2334#define TCGv TCGv_i64
2335#define tcg_temp_new() tcg_temp_new_i64()
2336#define tcg_global_reg_new tcg_global_reg_new_i64
2337#define tcg_global_mem_new tcg_global_mem_new_i64
df9247b2 2338#define tcg_temp_local_new() tcg_temp_local_new_i64()
a7812ae4
PB
2339#define tcg_temp_free tcg_temp_free_i64
2340#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
2341#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
2342#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
fe75bcf7 2343#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
a7812ae4
PB
2344#endif
2345
7e4597d7
FB
2346/* debug info: write the PC of the corresponding QEMU CPU instruction */
2347static inline void tcg_gen_debug_insn_start(uint64_t pc)
2348{
2349 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2350#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
bcb0126f
PB
2351 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2352 (uint32_t)(pc), (uint32_t)(pc >> 32));
7e4597d7
FB
2353#else
2354 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2355#endif
2356}
2357
c896fe29
FB
2358static inline void tcg_gen_exit_tb(tcg_target_long val)
2359{
ac56dd48 2360 tcg_gen_op1i(INDEX_op_exit_tb, val);
c896fe29
FB
2361}
2362
0a209d4b
RH
2363static inline void tcg_gen_goto_tb(unsigned idx)
2364{
2365 /* We only support two chained exits. */
2366 tcg_debug_assert(idx <= 1);
2367#ifdef CONFIG_DEBUG_TCG
2368 /* Verify that we havn't seen this numbered exit before. */
2369 tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
2370 tcg_ctx.goto_tb_issue_mask |= 1 << idx;
2371#endif
ac56dd48 2372 tcg_gen_op1i(INDEX_op_goto_tb, idx);
c896fe29
FB
2373}
2374
2375#if TCG_TARGET_REG_BITS == 32
ac56dd48 2376static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2377{
2378#if TARGET_LONG_BITS == 32
a7812ae4 2379 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29 2380#else
a7812ae4
PB
2381 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
2382 TCGV_HIGH(addr), mem_index);
ac56dd48 2383 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2384#endif
2385}
2386
ac56dd48 2387static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2388{
2389#if TARGET_LONG_BITS == 32
a7812ae4 2390 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29 2391#else
a7812ae4
PB
2392 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
2393 TCGV_HIGH(addr), mem_index);
2394 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2395#endif
2396}
2397
ac56dd48 2398static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2399{
2400#if TARGET_LONG_BITS == 32
a7812ae4 2401 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29 2402#else
a7812ae4
PB
2403 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
2404 TCGV_HIGH(addr), mem_index);
ac56dd48 2405 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2406#endif
2407}
2408
ac56dd48 2409static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2410{
2411#if TARGET_LONG_BITS == 32
a7812ae4 2412 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29 2413#else
a7812ae4
PB
2414 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
2415 TCGV_HIGH(addr), mem_index);
2416 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2417#endif
2418}
2419
ac56dd48 2420static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2421{
2422#if TARGET_LONG_BITS == 32
86feb1c8 2423 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
c896fe29 2424#else
86feb1c8 2425 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
a7812ae4 2426 TCGV_HIGH(addr), mem_index);
ac56dd48 2427 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2428#endif
2429}
2430
ac56dd48 2431static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2432{
2433#if TARGET_LONG_BITS == 32
86feb1c8 2434 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
c896fe29 2435#else
86feb1c8 2436 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
a7812ae4
PB
2437 TCGV_HIGH(addr), mem_index);
2438 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2439#endif
2440}
2441
a7812ae4 2442static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
c896fe29
FB
2443{
2444#if TARGET_LONG_BITS == 32
a7812ae4 2445 tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
c896fe29 2446#else
a7812ae4
PB
2447 tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
2448 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
c896fe29
FB
2449#endif
2450}
2451
ac56dd48 2452static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2453{
2454#if TARGET_LONG_BITS == 32
a7812ae4 2455 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29 2456#else
a7812ae4
PB
2457 tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
2458 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2459#endif
2460}
2461
ac56dd48 2462static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2463{
2464#if TARGET_LONG_BITS == 32
a7812ae4 2465 tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29 2466#else
a7812ae4
PB
2467 tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
2468 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2469#endif
2470}
2471
ac56dd48 2472static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2473{
2474#if TARGET_LONG_BITS == 32
a7812ae4 2475 tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29 2476#else
a7812ae4
PB
2477 tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
2478 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2479#endif
2480}
2481
a7812ae4 2482static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
c896fe29
FB
2483{
2484#if TARGET_LONG_BITS == 32
a7812ae4
PB
2485 tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
2486 mem_index);
c896fe29 2487#else
a7812ae4
PB
2488 tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
2489 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
c896fe29
FB
2490#endif
2491}
2492
ebecf363
PM
2493#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2494#define tcg_gen_discard_ptr(A) tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
f8422f52 2495
c896fe29
FB
2496#else /* TCG_TARGET_REG_BITS == 32 */
2497
ac56dd48 2498static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2499{
a7812ae4 2500 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29
FB
2501}
2502
ac56dd48 2503static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2504{
a7812ae4 2505 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29
FB
2506}
2507
ac56dd48 2508static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2509{
a7812ae4 2510 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29
FB
2511}
2512
ac56dd48 2513static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2514{
a7812ae4 2515 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29
FB
2516}
2517
ac56dd48 2518static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2519{
3e1dbadd
RH
2520#if TARGET_LONG_BITS == 32
2521 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2522#else
a7812ae4 2523 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
3e1dbadd 2524#endif
c896fe29
FB
2525}
2526
ac56dd48 2527static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2528{
3e1dbadd
RH
2529#if TARGET_LONG_BITS == 32
2530 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2531#else
a7812ae4 2532 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
3e1dbadd 2533#endif
c896fe29
FB
2534}
2535
a7812ae4 2536static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
c896fe29 2537{
a7812ae4 2538 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
c896fe29
FB
2539}
2540
ac56dd48 2541static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29 2542{
a7812ae4 2543 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29
FB
2544}
2545
ac56dd48 2546static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29 2547{
a7812ae4 2548 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29
FB
2549}
2550
ac56dd48 2551static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29 2552{
a7812ae4 2553 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29
FB
2554}
2555
a7812ae4 2556static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
c896fe29 2557{
a7812ae4 2558 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
c896fe29
FB
2559}
2560
ebecf363
PM
2561#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2562#define tcg_gen_discard_ptr(A) tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
f8422f52 2563
c896fe29 2564#endif /* TCG_TARGET_REG_BITS != 32 */
f8422f52
BS
2565
2566#if TARGET_LONG_BITS == 64
f8422f52
BS
2567#define tcg_gen_movi_tl tcg_gen_movi_i64
2568#define tcg_gen_mov_tl tcg_gen_mov_i64
2569#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2570#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2571#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2572#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2573#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2574#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2575#define tcg_gen_ld_tl tcg_gen_ld_i64
2576#define tcg_gen_st8_tl tcg_gen_st8_i64
2577#define tcg_gen_st16_tl tcg_gen_st16_i64
2578#define tcg_gen_st32_tl tcg_gen_st32_i64
2579#define tcg_gen_st_tl tcg_gen_st_i64
2580#define tcg_gen_add_tl tcg_gen_add_i64
2581#define tcg_gen_addi_tl tcg_gen_addi_i64
2582#define tcg_gen_sub_tl tcg_gen_sub_i64
390efc54 2583#define tcg_gen_neg_tl tcg_gen_neg_i64
10460c8a 2584#define tcg_gen_subfi_tl tcg_gen_subfi_i64
f8422f52
BS
2585#define tcg_gen_subi_tl tcg_gen_subi_i64
2586#define tcg_gen_and_tl tcg_gen_and_i64
2587#define tcg_gen_andi_tl tcg_gen_andi_i64
2588#define tcg_gen_or_tl tcg_gen_or_i64
2589#define tcg_gen_ori_tl tcg_gen_ori_i64
2590#define tcg_gen_xor_tl tcg_gen_xor_i64
2591#define tcg_gen_xori_tl tcg_gen_xori_i64
0b6ce4cf 2592#define tcg_gen_not_tl tcg_gen_not_i64
f8422f52
BS
2593#define tcg_gen_shl_tl tcg_gen_shl_i64
2594#define tcg_gen_shli_tl tcg_gen_shli_i64
2595#define tcg_gen_shr_tl tcg_gen_shr_i64
2596#define tcg_gen_shri_tl tcg_gen_shri_i64
2597#define tcg_gen_sar_tl tcg_gen_sar_i64
2598#define tcg_gen_sari_tl tcg_gen_sari_i64
0cf767d6 2599#define tcg_gen_brcond_tl tcg_gen_brcond_i64
cb63669a 2600#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
be210acb 2601#define tcg_gen_setcond_tl tcg_gen_setcond_i64
add1e7ea 2602#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
f730fd27
TS
2603#define tcg_gen_mul_tl tcg_gen_mul_i64
2604#define tcg_gen_muli_tl tcg_gen_muli_i64
ab36421e
AJ
2605#define tcg_gen_div_tl tcg_gen_div_i64
2606#define tcg_gen_rem_tl tcg_gen_rem_i64
864951af
AJ
2607#define tcg_gen_divu_tl tcg_gen_divu_i64
2608#define tcg_gen_remu_tl tcg_gen_remu_i64
a768e4b2 2609#define tcg_gen_discard_tl tcg_gen_discard_i64
e429073d
BS
2610#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2611#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2612#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2613#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2614#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2615#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
0b6ce4cf
FB
2616#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2617#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2618#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2619#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2620#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2621#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
911d79ba
AJ
2622#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2623#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2624#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
945ca823 2625#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
f24cb33e
AJ
2626#define tcg_gen_andc_tl tcg_gen_andc_i64
2627#define tcg_gen_eqv_tl tcg_gen_eqv_i64
2628#define tcg_gen_nand_tl tcg_gen_nand_i64
2629#define tcg_gen_nor_tl tcg_gen_nor_i64
2630#define tcg_gen_orc_tl tcg_gen_orc_i64
15824571
AJ
2631#define tcg_gen_rotl_tl tcg_gen_rotl_i64
2632#define tcg_gen_rotli_tl tcg_gen_rotli_i64
2633#define tcg_gen_rotr_tl tcg_gen_rotr_i64
2634#define tcg_gen_rotri_tl tcg_gen_rotri_i64
b7767f0f 2635#define tcg_gen_deposit_tl tcg_gen_deposit_i64
a98824ac 2636#define tcg_const_tl tcg_const_i64
bdffd4a9 2637#define tcg_const_local_tl tcg_const_local_i64
ffc5ea09 2638#define tcg_gen_movcond_tl tcg_gen_movcond_i64
f8422f52 2639#else
f8422f52
BS
2640#define tcg_gen_movi_tl tcg_gen_movi_i32
2641#define tcg_gen_mov_tl tcg_gen_mov_i32
2642#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2643#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2644#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2645#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2646#define tcg_gen_ld32u_tl tcg_gen_ld_i32
2647#define tcg_gen_ld32s_tl tcg_gen_ld_i32
2648#define tcg_gen_ld_tl tcg_gen_ld_i32
2649#define tcg_gen_st8_tl tcg_gen_st8_i32
2650#define tcg_gen_st16_tl tcg_gen_st16_i32
2651#define tcg_gen_st32_tl tcg_gen_st_i32
2652#define tcg_gen_st_tl tcg_gen_st_i32
2653#define tcg_gen_add_tl tcg_gen_add_i32
2654#define tcg_gen_addi_tl tcg_gen_addi_i32
2655#define tcg_gen_sub_tl tcg_gen_sub_i32
390efc54 2656#define tcg_gen_neg_tl tcg_gen_neg_i32
0045734a 2657#define tcg_gen_subfi_tl tcg_gen_subfi_i32
f8422f52
BS
2658#define tcg_gen_subi_tl tcg_gen_subi_i32
2659#define tcg_gen_and_tl tcg_gen_and_i32
2660#define tcg_gen_andi_tl tcg_gen_andi_i32
2661#define tcg_gen_or_tl tcg_gen_or_i32
2662#define tcg_gen_ori_tl tcg_gen_ori_i32
2663#define tcg_gen_xor_tl tcg_gen_xor_i32
2664#define tcg_gen_xori_tl tcg_gen_xori_i32
0b6ce4cf 2665#define tcg_gen_not_tl tcg_gen_not_i32
f8422f52
BS
2666#define tcg_gen_shl_tl tcg_gen_shl_i32
2667#define tcg_gen_shli_tl tcg_gen_shli_i32
2668#define tcg_gen_shr_tl tcg_gen_shr_i32
2669#define tcg_gen_shri_tl tcg_gen_shri_i32
2670#define tcg_gen_sar_tl tcg_gen_sar_i32
2671#define tcg_gen_sari_tl tcg_gen_sari_i32
0cf767d6 2672#define tcg_gen_brcond_tl tcg_gen_brcond_i32
cb63669a 2673#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
be210acb 2674#define tcg_gen_setcond_tl tcg_gen_setcond_i32
add1e7ea 2675#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
f730fd27
TS
2676#define tcg_gen_mul_tl tcg_gen_mul_i32
2677#define tcg_gen_muli_tl tcg_gen_muli_i32
ab36421e
AJ
2678#define tcg_gen_div_tl tcg_gen_div_i32
2679#define tcg_gen_rem_tl tcg_gen_rem_i32
864951af
AJ
2680#define tcg_gen_divu_tl tcg_gen_divu_i32
2681#define tcg_gen_remu_tl tcg_gen_remu_i32
a768e4b2 2682#define tcg_gen_discard_tl tcg_gen_discard_i32
e429073d
BS
2683#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2684#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2685#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2686#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2687#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2688#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
0b6ce4cf
FB
2689#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2690#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2691#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2692#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2693#define tcg_gen_ext32u_tl tcg_gen_mov_i32
2694#define tcg_gen_ext32s_tl tcg_gen_mov_i32
911d79ba
AJ
2695#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2696#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
945ca823 2697#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
f24cb33e
AJ
2698#define tcg_gen_andc_tl tcg_gen_andc_i32
2699#define tcg_gen_eqv_tl tcg_gen_eqv_i32
2700#define tcg_gen_nand_tl tcg_gen_nand_i32
2701#define tcg_gen_nor_tl tcg_gen_nor_i32
2702#define tcg_gen_orc_tl tcg_gen_orc_i32
15824571
AJ
2703#define tcg_gen_rotl_tl tcg_gen_rotl_i32
2704#define tcg_gen_rotli_tl tcg_gen_rotli_i32
2705#define tcg_gen_rotr_tl tcg_gen_rotr_i32
2706#define tcg_gen_rotri_tl tcg_gen_rotri_i32
b7767f0f 2707#define tcg_gen_deposit_tl tcg_gen_deposit_i32
a98824ac 2708#define tcg_const_tl tcg_const_i32
bdffd4a9 2709#define tcg_const_local_tl tcg_const_local_i32
ffc5ea09 2710#define tcg_gen_movcond_tl tcg_gen_movcond_i32
f8422f52 2711#endif
6ddbc6e4
PB
2712
2713#if TCG_TARGET_REG_BITS == 32
ebecf363
PM
2714#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), \
2715 TCGV_PTR_TO_NAT(A), \
2716 TCGV_PTR_TO_NAT(B))
2717#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), \
2718 TCGV_PTR_TO_NAT(A), (B))
2719#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
6ddbc6e4 2720#else /* TCG_TARGET_REG_BITS == 32 */
ebecf363
PM
2721#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), \
2722 TCGV_PTR_TO_NAT(A), \
2723 TCGV_PTR_TO_NAT(B))
2724#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), \
2725 TCGV_PTR_TO_NAT(A), (B))
2726#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
6ddbc6e4 2727#endif /* TCG_TARGET_REG_BITS != 32 */
This page took 1.060243 seconds and 4 git commands to generate.