]> git.proxmox.com Git - qemu.git/blame - tcg/tcg-op.h
qxl: Call spice_qxl_driver_unload from qxl_enter_vga_mode
[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{
efd7f486 30 *tcg_ctx.gen_opc_ptr++ = opc;
212c328d
RH
31}
32
a9751609 33static inline void tcg_gen_op1_i32(TCGOpcode opc, TCGv_i32 arg1)
c896fe29 34{
efd7f486 35 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4 36 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
a7812ae4
PB
37}
38
a9751609 39static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
a7812ae4 40{
efd7f486 41 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4 42 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
c896fe29
FB
43}
44
a9751609 45static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg arg1)
c896fe29 46{
efd7f486 47 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4 48 *tcg_ctx.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 52{
efd7f486 53 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
54 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
55 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
a7812ae4
PB
56}
57
a9751609 58static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
a7812ae4 59{
efd7f486 60 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
61 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
62 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
a7812ae4
PB
63}
64
a9751609 65static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
c896fe29 66{
efd7f486 67 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
68 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
69 *tcg_ctx.gen_opparam_ptr++ = arg2;
c896fe29
FB
70}
71
a9751609 72static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
c896fe29 73{
efd7f486 74 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
75 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
76 *tcg_ctx.gen_opparam_ptr++ = arg2;
ac56dd48
PB
77}
78
a9751609 79static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg arg1, TCGArg arg2)
bcb0126f 80{
efd7f486 81 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
82 *tcg_ctx.gen_opparam_ptr++ = arg1;
83 *tcg_ctx.gen_opparam_ptr++ = arg2;
bcb0126f
PB
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{
efd7f486 89 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
90 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
91 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
92 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
a7812ae4
PB
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{
efd7f486 98 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
99 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
100 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
101 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
a7812ae4
PB
102}
103
a9751609
RH
104static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
105 TCGv_i32 arg2, TCGArg arg3)
ac56dd48 106{
efd7f486 107 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
108 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
109 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
110 *tcg_ctx.gen_opparam_ptr++ = arg3;
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 115{
efd7f486 116 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
117 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
118 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
119 *tcg_ctx.gen_opparam_ptr++ = arg3;
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 124{
efd7f486 125 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
126 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(val);
127 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_PTR(base);
128 *tcg_ctx.gen_opparam_ptr++ = offset;
a7812ae4
PB
129}
130
a9751609
RH
131static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
132 TCGv_ptr base, TCGArg offset)
a7812ae4 133{
efd7f486 134 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
135 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
136 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_PTR(base);
137 *tcg_ctx.gen_opparam_ptr++ = offset;
a7812ae4
PB
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 142{
efd7f486 143 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
144 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
145 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(addr);
146 *tcg_ctx.gen_opparam_ptr++ = mem_index;
a7812ae4
PB
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 151{
efd7f486 152 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
153 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
154 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(addr);
155 *tcg_ctx.gen_opparam_ptr++ = mem_index;
a7812ae4
PB
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{
efd7f486 161 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
162 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
163 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
164 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
165 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
a7812ae4
PB
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 170{
efd7f486 171 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
172 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
173 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
174 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
175 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
a7812ae4
PB
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{
efd7f486 181 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
182 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
183 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
184 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
185 *tcg_ctx.gen_opparam_ptr++ = arg4;
a7812ae4
PB
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 190{
efd7f486 191 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
192 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
193 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
194 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
195 *tcg_ctx.gen_opparam_ptr++ = arg4;
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 200{
efd7f486 201 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
202 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
203 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
204 *tcg_ctx.gen_opparam_ptr++ = arg3;
205 *tcg_ctx.gen_opparam_ptr++ = arg4;
c896fe29
FB
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 210{
efd7f486 211 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
212 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
213 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
214 *tcg_ctx.gen_opparam_ptr++ = arg3;
215 *tcg_ctx.gen_opparam_ptr++ = arg4;
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{
efd7f486 221 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
222 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
223 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
224 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
225 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
226 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
a7812ae4
PB
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{
efd7f486 232 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
233 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
234 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
235 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
236 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
237 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
a7812ae4
PB
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 242{
efd7f486 243 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
244 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
245 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
246 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
247 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
248 *tcg_ctx.gen_opparam_ptr++ = arg5;
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 253{
efd7f486 254 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
255 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
256 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
257 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
258 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
259 *tcg_ctx.gen_opparam_ptr++ = arg5;
c896fe29
FB
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{
efd7f486 266 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
267 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
268 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
269 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
270 *tcg_ctx.gen_opparam_ptr++ = arg4;
271 *tcg_ctx.gen_opparam_ptr++ = arg5;
b7767f0f
RH
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{
efd7f486 278 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
279 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
280 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
281 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
282 *tcg_ctx.gen_opparam_ptr++ = arg4;
283 *tcg_ctx.gen_opparam_ptr++ = arg5;
b7767f0f
RH
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{
efd7f486 290 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
291 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
292 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
293 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
294 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
295 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
296 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg6);
a7812ae4
PB
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 302{
efd7f486 303 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
304 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
305 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
306 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
307 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
308 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
309 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg6);
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{
efd7f486 316 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
317 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
318 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
319 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
320 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
321 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
322 *tcg_ctx.gen_opparam_ptr++ = arg6;
be210acb
RH
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{
efd7f486 329 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
330 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
331 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
332 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
333 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
334 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
335 *tcg_ctx.gen_opparam_ptr++ = arg6;
be210acb
RH
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 341{
efd7f486 342 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
343 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
344 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
345 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
346 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
347 *tcg_ctx.gen_opparam_ptr++ = arg5;
348 *tcg_ctx.gen_opparam_ptr++ = arg6;
a7812ae4
PB
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 354{
efd7f486 355 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
356 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
357 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
358 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
359 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
360 *tcg_ctx.gen_opparam_ptr++ = arg5;
361 *tcg_ctx.gen_opparam_ptr++ = arg6;
c896fe29
FB
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) {
2191 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2192 TCGV_LOW(arg2), ofs - 32, len);
ed605126 2193 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
df072774
RH
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
3c51a985
RH
2249static inline void tcg_gen_extr_i64_i32(TCGv_i32 lo, TCGv_i32 hi, TCGv_i64 arg)
2250{
2251#if TCG_TARGET_REG_BITS == 32
2252 tcg_gen_mov_i32(lo, TCGV_LOW(arg));
2253 tcg_gen_mov_i32(hi, TCGV_HIGH(arg));
2254#else
2255 TCGv_i64 t0 = tcg_temp_new_i64();
2256 tcg_gen_trunc_i64_i32(lo, arg);
2257 tcg_gen_shri_i64(t0, arg, 32);
2258 tcg_gen_trunc_i64_i32(hi, t0);
2259 tcg_temp_free_i64(t0);
2260#endif
2261}
2262
2263static inline void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)
2264{
2265 tcg_gen_ext32u_i64(lo, arg);
2266 tcg_gen_shri_i64(hi, arg, 32);
2267}
2268
ffc5ea09
RH
2269static inline void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret,
2270 TCGv_i32 c1, TCGv_i32 c2,
2271 TCGv_i32 v1, TCGv_i32 v2)
2272{
2273 if (TCG_TARGET_HAS_movcond_i32) {
2274 tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond);
2275 } else {
2276 TCGv_i32 t0 = tcg_temp_new_i32();
2277 TCGv_i32 t1 = tcg_temp_new_i32();
2278 tcg_gen_setcond_i32(cond, t0, c1, c2);
2279 tcg_gen_neg_i32(t0, t0);
2280 tcg_gen_and_i32(t1, v1, t0);
2281 tcg_gen_andc_i32(ret, v2, t0);
2282 tcg_gen_or_i32(ret, ret, t1);
2283 tcg_temp_free_i32(t0);
2284 tcg_temp_free_i32(t1);
2285 }
2286}
2287
2288static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
2289 TCGv_i64 c1, TCGv_i64 c2,
2290 TCGv_i64 v1, TCGv_i64 v2)
2291{
a463133e
RH
2292#if TCG_TARGET_REG_BITS == 32
2293 TCGv_i32 t0 = tcg_temp_new_i32();
2294 TCGv_i32 t1 = tcg_temp_new_i32();
2295 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
2296 TCGV_LOW(c1), TCGV_HIGH(c1),
2297 TCGV_LOW(c2), TCGV_HIGH(c2), cond);
a463133e 2298
a80a6b63
RH
2299 if (TCG_TARGET_HAS_movcond_i32) {
2300 tcg_gen_movi_i32(t1, 0);
2301 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
2302 TCGV_LOW(v1), TCGV_LOW(v2));
2303 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
2304 TCGV_HIGH(v1), TCGV_HIGH(v2));
2305 } else {
2306 tcg_gen_neg_i32(t0, t0);
a463133e 2307
a80a6b63
RH
2308 tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
2309 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
2310 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
a463133e 2311
a80a6b63
RH
2312 tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
2313 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
2314 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
2315 }
a463133e
RH
2316 tcg_temp_free_i32(t0);
2317 tcg_temp_free_i32(t1);
2318#else
ffc5ea09
RH
2319 if (TCG_TARGET_HAS_movcond_i64) {
2320 tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond);
2321 } else {
2322 TCGv_i64 t0 = tcg_temp_new_i64();
2323 TCGv_i64 t1 = tcg_temp_new_i64();
2324 tcg_gen_setcond_i64(cond, t0, c1, c2);
2325 tcg_gen_neg_i64(t0, t0);
2326 tcg_gen_and_i64(t1, v1, t0);
2327 tcg_gen_andc_i64(ret, v2, t0);
2328 tcg_gen_or_i64(ret, ret, t1);
2329 tcg_temp_free_i64(t0);
2330 tcg_temp_free_i64(t1);
2331 }
a463133e 2332#endif
ffc5ea09
RH
2333}
2334
f6953a73
RH
2335static inline void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2336 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2337{
2338 if (TCG_TARGET_HAS_add2_i32) {
2339 tcg_gen_op6_i32(INDEX_op_add2_i32, rl, rh, al, ah, bl, bh);
2340 /* Allow the optimizer room to replace add2 with two moves. */
2341 tcg_gen_op0(INDEX_op_nop);
2342 } else {
2343 TCGv_i64 t0 = tcg_temp_new_i64();
2344 TCGv_i64 t1 = tcg_temp_new_i64();
2345 tcg_gen_concat_i32_i64(t0, al, ah);
2346 tcg_gen_concat_i32_i64(t1, bl, bh);
2347 tcg_gen_add_i64(t0, t0, t1);
2348 tcg_gen_extr_i64_i32(rl, rh, t0);
2349 tcg_temp_free_i64(t0);
2350 tcg_temp_free_i64(t1);
2351 }
2352}
2353
2354static inline void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2355 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2356{
2357 if (TCG_TARGET_HAS_sub2_i32) {
2358 tcg_gen_op6_i32(INDEX_op_sub2_i32, rl, rh, al, ah, bl, bh);
2359 /* Allow the optimizer room to replace sub2 with two moves. */
2360 tcg_gen_op0(INDEX_op_nop);
2361 } else {
2362 TCGv_i64 t0 = tcg_temp_new_i64();
2363 TCGv_i64 t1 = tcg_temp_new_i64();
2364 tcg_gen_concat_i32_i64(t0, al, ah);
2365 tcg_gen_concat_i32_i64(t1, bl, bh);
2366 tcg_gen_sub_i64(t0, t0, t1);
2367 tcg_gen_extr_i64_i32(rl, rh, t0);
2368 tcg_temp_free_i64(t0);
2369 tcg_temp_free_i64(t1);
2370 }
2371}
2372
696a8be6
RH
2373static inline void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh,
2374 TCGv_i32 arg1, TCGv_i32 arg2)
2375{
2376 if (TCG_TARGET_HAS_mulu2_i32) {
2377 tcg_gen_op4_i32(INDEX_op_mulu2_i32, rl, rh, arg1, arg2);
2378 /* Allow the optimizer room to replace mulu2 with two moves. */
2379 tcg_gen_op0(INDEX_op_nop);
2380 } else {
2381 TCGv_i64 t0 = tcg_temp_new_i64();
2382 TCGv_i64 t1 = tcg_temp_new_i64();
2383 tcg_gen_extu_i32_i64(t0, arg1);
2384 tcg_gen_extu_i32_i64(t1, arg2);
2385 tcg_gen_mul_i64(t0, t0, t1);
2386 tcg_gen_extr_i64_i32(rl, rh, t0);
2387 tcg_temp_free_i64(t0);
2388 tcg_temp_free_i64(t1);
2389 }
2390}
2391
2392static inline void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh,
2393 TCGv_i32 arg1, TCGv_i32 arg2)
2394{
2395 if (TCG_TARGET_HAS_muls2_i32) {
2396 tcg_gen_op4_i32(INDEX_op_muls2_i32, rl, rh, arg1, arg2);
2397 /* Allow the optimizer room to replace muls2 with two moves. */
2398 tcg_gen_op0(INDEX_op_nop);
f402f38f
RH
2399 } else if (TCG_TARGET_REG_BITS == 32 && TCG_TARGET_HAS_mulu2_i32) {
2400 TCGv_i32 t0 = tcg_temp_new_i32();
2401 TCGv_i32 t1 = tcg_temp_new_i32();
2402 TCGv_i32 t2 = tcg_temp_new_i32();
2403 TCGv_i32 t3 = tcg_temp_new_i32();
2404 tcg_gen_op4_i32(INDEX_op_mulu2_i32, t0, t1, arg1, arg2);
2405 /* Allow the optimizer room to replace mulu2 with two moves. */
2406 tcg_gen_op0(INDEX_op_nop);
2407 /* Adjust for negative inputs. */
2408 tcg_gen_sari_i32(t2, arg1, 31);
2409 tcg_gen_sari_i32(t3, arg2, 31);
2410 tcg_gen_and_i32(t2, t2, arg2);
2411 tcg_gen_and_i32(t3, t3, arg1);
2412 tcg_gen_sub_i32(rh, t1, t2);
2413 tcg_gen_sub_i32(rh, rh, t3);
2414 tcg_gen_mov_i32(rl, t0);
2415 tcg_temp_free_i32(t0);
2416 tcg_temp_free_i32(t1);
2417 tcg_temp_free_i32(t2);
2418 tcg_temp_free_i32(t3);
696a8be6
RH
2419 } else {
2420 TCGv_i64 t0 = tcg_temp_new_i64();
2421 TCGv_i64 t1 = tcg_temp_new_i64();
2422 tcg_gen_ext_i32_i64(t0, arg1);
2423 tcg_gen_ext_i32_i64(t1, arg2);
2424 tcg_gen_mul_i64(t0, t0, t1);
2425 tcg_gen_extr_i64_i32(rl, rh, t0);
2426 tcg_temp_free_i64(t0);
2427 tcg_temp_free_i64(t1);
2428 }
2429}
2430
f6953a73
RH
2431static inline void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2432 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2433{
2434 if (TCG_TARGET_HAS_add2_i64) {
2435 tcg_gen_op6_i64(INDEX_op_add2_i64, rl, rh, al, ah, bl, bh);
2436 /* Allow the optimizer room to replace add2 with two moves. */
2437 tcg_gen_op0(INDEX_op_nop);
2438 } else {
2439 TCGv_i64 t0 = tcg_temp_new_i64();
2440 TCGv_i64 t1 = tcg_temp_new_i64();
2441 tcg_gen_add_i64(t0, al, bl);
2442 tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, al);
2443 tcg_gen_add_i64(rh, ah, bh);
2444 tcg_gen_add_i64(rh, rh, t1);
2445 tcg_gen_mov_i64(rl, t0);
2446 tcg_temp_free_i64(t0);
2447 tcg_temp_free_i64(t1);
2448 }
2449}
2450
2451static inline void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2452 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2453{
2454 if (TCG_TARGET_HAS_sub2_i64) {
2455 tcg_gen_op6_i64(INDEX_op_sub2_i64, rl, rh, al, ah, bl, bh);
2456 /* Allow the optimizer room to replace sub2 with two moves. */
2457 tcg_gen_op0(INDEX_op_nop);
2458 } else {
2459 TCGv_i64 t0 = tcg_temp_new_i64();
2460 TCGv_i64 t1 = tcg_temp_new_i64();
2461 tcg_gen_sub_i64(t0, al, bl);
2462 tcg_gen_setcond_i64(TCG_COND_LTU, t1, al, bl);
2463 tcg_gen_sub_i64(rh, ah, bh);
2464 tcg_gen_sub_i64(rh, rh, t1);
2465 tcg_gen_mov_i64(rl, t0);
2466 tcg_temp_free_i64(t0);
2467 tcg_temp_free_i64(t1);
2468 }
2469}
2470
696a8be6
RH
2471static inline void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh,
2472 TCGv_i64 arg1, TCGv_i64 arg2)
2473{
2474 if (TCG_TARGET_HAS_mulu2_i64) {
2475 tcg_gen_op4_i64(INDEX_op_mulu2_i64, rl, rh, arg1, arg2);
2476 /* Allow the optimizer room to replace mulu2 with two moves. */
2477 tcg_gen_op0(INDEX_op_nop);
f402f38f
RH
2478 } else if (TCG_TARGET_HAS_mulu2_i64) {
2479 TCGv_i64 t0 = tcg_temp_new_i64();
2480 TCGv_i64 t1 = tcg_temp_new_i64();
2481 TCGv_i64 t2 = tcg_temp_new_i64();
2482 TCGv_i64 t3 = tcg_temp_new_i64();
2483 tcg_gen_op4_i64(INDEX_op_mulu2_i64, t0, t1, arg1, arg2);
2484 /* Allow the optimizer room to replace mulu2 with two moves. */
2485 tcg_gen_op0(INDEX_op_nop);
2486 /* Adjust for negative inputs. */
2487 tcg_gen_sari_i64(t2, arg1, 63);
2488 tcg_gen_sari_i64(t3, arg2, 63);
2489 tcg_gen_and_i64(t2, t2, arg2);
2490 tcg_gen_and_i64(t3, t3, arg1);
2491 tcg_gen_sub_i64(rh, t1, t2);
2492 tcg_gen_sub_i64(rh, rh, t3);
2493 tcg_gen_mov_i64(rl, t0);
2494 tcg_temp_free_i64(t0);
2495 tcg_temp_free_i64(t1);
2496 tcg_temp_free_i64(t2);
2497 tcg_temp_free_i64(t3);
696a8be6
RH
2498 } else {
2499 TCGv_i64 t0 = tcg_temp_new_i64();
2500 int sizemask = 0;
2501 /* Return value and both arguments are 64-bit and unsigned. */
2502 sizemask |= tcg_gen_sizemask(0, 1, 0);
2503 sizemask |= tcg_gen_sizemask(1, 1, 0);
2504 sizemask |= tcg_gen_sizemask(2, 1, 0);
2505 tcg_gen_mul_i64(t0, arg1, arg2);
2506 tcg_gen_helper64(tcg_helper_muluh_i64, sizemask, rh, arg1, arg2);
2507 tcg_gen_mov_i64(rl, t0);
2508 tcg_temp_free_i64(t0);
2509 }
2510}
2511
2512static inline void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh,
2513 TCGv_i64 arg1, TCGv_i64 arg2)
2514{
2515 if (TCG_TARGET_HAS_muls2_i64) {
2516 tcg_gen_op4_i64(INDEX_op_muls2_i64, rl, rh, arg1, arg2);
2517 /* Allow the optimizer room to replace muls2 with two moves. */
2518 tcg_gen_op0(INDEX_op_nop);
2519 } else {
2520 TCGv_i64 t0 = tcg_temp_new_i64();
2521 int sizemask = 0;
2522 /* Return value and both arguments are 64-bit and signed. */
2523 sizemask |= tcg_gen_sizemask(0, 1, 1);
2524 sizemask |= tcg_gen_sizemask(1, 1, 1);
2525 sizemask |= tcg_gen_sizemask(2, 1, 1);
2526 tcg_gen_mul_i64(t0, arg1, arg2);
2527 tcg_gen_helper64(tcg_helper_mulsh_i64, sizemask, rh, arg1, arg2);
2528 tcg_gen_mov_i64(rl, t0);
2529 tcg_temp_free_i64(t0);
2530 }
2531}
2532
c896fe29
FB
2533/***************************************/
2534/* QEMU specific operations. Their type depend on the QEMU CPU
2535 type. */
2536#ifndef TARGET_LONG_BITS
2537#error must include QEMU headers
2538#endif
2539
a7812ae4
PB
2540#if TARGET_LONG_BITS == 32
2541#define TCGv TCGv_i32
2542#define tcg_temp_new() tcg_temp_new_i32()
2543#define tcg_global_reg_new tcg_global_reg_new_i32
2544#define tcg_global_mem_new tcg_global_mem_new_i32
df9247b2 2545#define tcg_temp_local_new() tcg_temp_local_new_i32()
a7812ae4
PB
2546#define tcg_temp_free tcg_temp_free_i32
2547#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
2548#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
2549#define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
afcb92be 2550#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I32(x)
fe75bcf7 2551#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
a7812ae4
PB
2552#else
2553#define TCGv TCGv_i64
2554#define tcg_temp_new() tcg_temp_new_i64()
2555#define tcg_global_reg_new tcg_global_reg_new_i64
2556#define tcg_global_mem_new tcg_global_mem_new_i64
df9247b2 2557#define tcg_temp_local_new() tcg_temp_local_new_i64()
a7812ae4
PB
2558#define tcg_temp_free tcg_temp_free_i64
2559#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
2560#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
2561#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
afcb92be 2562#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I64(x)
fe75bcf7 2563#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
a7812ae4
PB
2564#endif
2565
7e4597d7
FB
2566/* debug info: write the PC of the corresponding QEMU CPU instruction */
2567static inline void tcg_gen_debug_insn_start(uint64_t pc)
2568{
2569 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2570#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
bcb0126f
PB
2571 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2572 (uint32_t)(pc), (uint32_t)(pc >> 32));
7e4597d7
FB
2573#else
2574 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2575#endif
2576}
2577
c896fe29
FB
2578static inline void tcg_gen_exit_tb(tcg_target_long val)
2579{
ac56dd48 2580 tcg_gen_op1i(INDEX_op_exit_tb, val);
c896fe29
FB
2581}
2582
0a209d4b
RH
2583static inline void tcg_gen_goto_tb(unsigned idx)
2584{
2585 /* We only support two chained exits. */
2586 tcg_debug_assert(idx <= 1);
2587#ifdef CONFIG_DEBUG_TCG
2588 /* Verify that we havn't seen this numbered exit before. */
2589 tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
2590 tcg_ctx.goto_tb_issue_mask |= 1 << idx;
2591#endif
ac56dd48 2592 tcg_gen_op1i(INDEX_op_goto_tb, idx);
c896fe29
FB
2593}
2594
2595#if TCG_TARGET_REG_BITS == 32
ac56dd48 2596static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2597{
2598#if TARGET_LONG_BITS == 32
a7812ae4 2599 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29 2600#else
a7812ae4
PB
2601 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
2602 TCGV_HIGH(addr), mem_index);
ac56dd48 2603 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2604#endif
2605}
2606
ac56dd48 2607static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2608{
2609#if TARGET_LONG_BITS == 32
a7812ae4 2610 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29 2611#else
a7812ae4
PB
2612 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
2613 TCGV_HIGH(addr), mem_index);
2614 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2615#endif
2616}
2617
ac56dd48 2618static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2619{
2620#if TARGET_LONG_BITS == 32
a7812ae4 2621 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29 2622#else
a7812ae4
PB
2623 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
2624 TCGV_HIGH(addr), mem_index);
ac56dd48 2625 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2626#endif
2627}
2628
ac56dd48 2629static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2630{
2631#if TARGET_LONG_BITS == 32
a7812ae4 2632 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29 2633#else
a7812ae4
PB
2634 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
2635 TCGV_HIGH(addr), mem_index);
2636 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2637#endif
2638}
2639
ac56dd48 2640static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2641{
2642#if TARGET_LONG_BITS == 32
86feb1c8 2643 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
c896fe29 2644#else
86feb1c8 2645 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
a7812ae4 2646 TCGV_HIGH(addr), mem_index);
ac56dd48 2647 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2648#endif
2649}
2650
ac56dd48 2651static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2652{
2653#if TARGET_LONG_BITS == 32
86feb1c8 2654 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
c896fe29 2655#else
86feb1c8 2656 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
a7812ae4
PB
2657 TCGV_HIGH(addr), mem_index);
2658 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2659#endif
2660}
2661
a7812ae4 2662static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
c896fe29
FB
2663{
2664#if TARGET_LONG_BITS == 32
a7812ae4 2665 tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
c896fe29 2666#else
a7812ae4
PB
2667 tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
2668 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
c896fe29
FB
2669#endif
2670}
2671
ac56dd48 2672static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2673{
2674#if TARGET_LONG_BITS == 32
a7812ae4 2675 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29 2676#else
a7812ae4
PB
2677 tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
2678 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2679#endif
2680}
2681
ac56dd48 2682static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2683{
2684#if TARGET_LONG_BITS == 32
a7812ae4 2685 tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29 2686#else
a7812ae4
PB
2687 tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
2688 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2689#endif
2690}
2691
ac56dd48 2692static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2693{
2694#if TARGET_LONG_BITS == 32
a7812ae4 2695 tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29 2696#else
a7812ae4
PB
2697 tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
2698 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2699#endif
2700}
2701
a7812ae4 2702static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
c896fe29
FB
2703{
2704#if TARGET_LONG_BITS == 32
a7812ae4
PB
2705 tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
2706 mem_index);
c896fe29 2707#else
a7812ae4
PB
2708 tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
2709 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
c896fe29
FB
2710#endif
2711}
2712
ebecf363
PM
2713#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2714#define tcg_gen_discard_ptr(A) tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
f8422f52 2715
c896fe29
FB
2716#else /* TCG_TARGET_REG_BITS == 32 */
2717
ac56dd48 2718static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2719{
a7812ae4 2720 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29
FB
2721}
2722
ac56dd48 2723static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2724{
a7812ae4 2725 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29
FB
2726}
2727
ac56dd48 2728static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2729{
a7812ae4 2730 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29
FB
2731}
2732
ac56dd48 2733static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2734{
a7812ae4 2735 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29
FB
2736}
2737
ac56dd48 2738static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2739{
3e1dbadd
RH
2740#if TARGET_LONG_BITS == 32
2741 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2742#else
a7812ae4 2743 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
3e1dbadd 2744#endif
c896fe29
FB
2745}
2746
ac56dd48 2747static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2748{
3e1dbadd
RH
2749#if TARGET_LONG_BITS == 32
2750 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2751#else
a7812ae4 2752 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
3e1dbadd 2753#endif
c896fe29
FB
2754}
2755
a7812ae4 2756static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
c896fe29 2757{
a7812ae4 2758 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
c896fe29
FB
2759}
2760
ac56dd48 2761static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29 2762{
a7812ae4 2763 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29
FB
2764}
2765
ac56dd48 2766static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29 2767{
a7812ae4 2768 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29
FB
2769}
2770
ac56dd48 2771static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29 2772{
a7812ae4 2773 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29
FB
2774}
2775
a7812ae4 2776static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
c896fe29 2777{
a7812ae4 2778 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
c896fe29
FB
2779}
2780
ebecf363
PM
2781#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2782#define tcg_gen_discard_ptr(A) tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
f8422f52 2783
c896fe29 2784#endif /* TCG_TARGET_REG_BITS != 32 */
f8422f52
BS
2785
2786#if TARGET_LONG_BITS == 64
f8422f52
BS
2787#define tcg_gen_movi_tl tcg_gen_movi_i64
2788#define tcg_gen_mov_tl tcg_gen_mov_i64
2789#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2790#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2791#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2792#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2793#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2794#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2795#define tcg_gen_ld_tl tcg_gen_ld_i64
2796#define tcg_gen_st8_tl tcg_gen_st8_i64
2797#define tcg_gen_st16_tl tcg_gen_st16_i64
2798#define tcg_gen_st32_tl tcg_gen_st32_i64
2799#define tcg_gen_st_tl tcg_gen_st_i64
2800#define tcg_gen_add_tl tcg_gen_add_i64
2801#define tcg_gen_addi_tl tcg_gen_addi_i64
2802#define tcg_gen_sub_tl tcg_gen_sub_i64
390efc54 2803#define tcg_gen_neg_tl tcg_gen_neg_i64
10460c8a 2804#define tcg_gen_subfi_tl tcg_gen_subfi_i64
f8422f52
BS
2805#define tcg_gen_subi_tl tcg_gen_subi_i64
2806#define tcg_gen_and_tl tcg_gen_and_i64
2807#define tcg_gen_andi_tl tcg_gen_andi_i64
2808#define tcg_gen_or_tl tcg_gen_or_i64
2809#define tcg_gen_ori_tl tcg_gen_ori_i64
2810#define tcg_gen_xor_tl tcg_gen_xor_i64
2811#define tcg_gen_xori_tl tcg_gen_xori_i64
0b6ce4cf 2812#define tcg_gen_not_tl tcg_gen_not_i64
f8422f52
BS
2813#define tcg_gen_shl_tl tcg_gen_shl_i64
2814#define tcg_gen_shli_tl tcg_gen_shli_i64
2815#define tcg_gen_shr_tl tcg_gen_shr_i64
2816#define tcg_gen_shri_tl tcg_gen_shri_i64
2817#define tcg_gen_sar_tl tcg_gen_sar_i64
2818#define tcg_gen_sari_tl tcg_gen_sari_i64
0cf767d6 2819#define tcg_gen_brcond_tl tcg_gen_brcond_i64
cb63669a 2820#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
be210acb 2821#define tcg_gen_setcond_tl tcg_gen_setcond_i64
add1e7ea 2822#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
f730fd27
TS
2823#define tcg_gen_mul_tl tcg_gen_mul_i64
2824#define tcg_gen_muli_tl tcg_gen_muli_i64
ab36421e
AJ
2825#define tcg_gen_div_tl tcg_gen_div_i64
2826#define tcg_gen_rem_tl tcg_gen_rem_i64
864951af
AJ
2827#define tcg_gen_divu_tl tcg_gen_divu_i64
2828#define tcg_gen_remu_tl tcg_gen_remu_i64
a768e4b2 2829#define tcg_gen_discard_tl tcg_gen_discard_i64
e429073d
BS
2830#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2831#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2832#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2833#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2834#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2835#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
0b6ce4cf
FB
2836#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2837#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2838#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2839#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2840#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2841#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
911d79ba
AJ
2842#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2843#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2844#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
945ca823 2845#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
3c51a985 2846#define tcg_gen_extr_i64_tl tcg_gen_extr32_i64
f24cb33e
AJ
2847#define tcg_gen_andc_tl tcg_gen_andc_i64
2848#define tcg_gen_eqv_tl tcg_gen_eqv_i64
2849#define tcg_gen_nand_tl tcg_gen_nand_i64
2850#define tcg_gen_nor_tl tcg_gen_nor_i64
2851#define tcg_gen_orc_tl tcg_gen_orc_i64
15824571
AJ
2852#define tcg_gen_rotl_tl tcg_gen_rotl_i64
2853#define tcg_gen_rotli_tl tcg_gen_rotli_i64
2854#define tcg_gen_rotr_tl tcg_gen_rotr_i64
2855#define tcg_gen_rotri_tl tcg_gen_rotri_i64
b7767f0f 2856#define tcg_gen_deposit_tl tcg_gen_deposit_i64
a98824ac 2857#define tcg_const_tl tcg_const_i64
bdffd4a9 2858#define tcg_const_local_tl tcg_const_local_i64
ffc5ea09 2859#define tcg_gen_movcond_tl tcg_gen_movcond_i64
f6953a73
RH
2860#define tcg_gen_add2_tl tcg_gen_add2_i64
2861#define tcg_gen_sub2_tl tcg_gen_sub2_i64
696a8be6
RH
2862#define tcg_gen_mulu2_tl tcg_gen_mulu2_i64
2863#define tcg_gen_muls2_tl tcg_gen_muls2_i64
f8422f52 2864#else
f8422f52
BS
2865#define tcg_gen_movi_tl tcg_gen_movi_i32
2866#define tcg_gen_mov_tl tcg_gen_mov_i32
2867#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2868#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2869#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2870#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2871#define tcg_gen_ld32u_tl tcg_gen_ld_i32
2872#define tcg_gen_ld32s_tl tcg_gen_ld_i32
2873#define tcg_gen_ld_tl tcg_gen_ld_i32
2874#define tcg_gen_st8_tl tcg_gen_st8_i32
2875#define tcg_gen_st16_tl tcg_gen_st16_i32
2876#define tcg_gen_st32_tl tcg_gen_st_i32
2877#define tcg_gen_st_tl tcg_gen_st_i32
2878#define tcg_gen_add_tl tcg_gen_add_i32
2879#define tcg_gen_addi_tl tcg_gen_addi_i32
2880#define tcg_gen_sub_tl tcg_gen_sub_i32
390efc54 2881#define tcg_gen_neg_tl tcg_gen_neg_i32
0045734a 2882#define tcg_gen_subfi_tl tcg_gen_subfi_i32
f8422f52
BS
2883#define tcg_gen_subi_tl tcg_gen_subi_i32
2884#define tcg_gen_and_tl tcg_gen_and_i32
2885#define tcg_gen_andi_tl tcg_gen_andi_i32
2886#define tcg_gen_or_tl tcg_gen_or_i32
2887#define tcg_gen_ori_tl tcg_gen_ori_i32
2888#define tcg_gen_xor_tl tcg_gen_xor_i32
2889#define tcg_gen_xori_tl tcg_gen_xori_i32
0b6ce4cf 2890#define tcg_gen_not_tl tcg_gen_not_i32
f8422f52
BS
2891#define tcg_gen_shl_tl tcg_gen_shl_i32
2892#define tcg_gen_shli_tl tcg_gen_shli_i32
2893#define tcg_gen_shr_tl tcg_gen_shr_i32
2894#define tcg_gen_shri_tl tcg_gen_shri_i32
2895#define tcg_gen_sar_tl tcg_gen_sar_i32
2896#define tcg_gen_sari_tl tcg_gen_sari_i32
0cf767d6 2897#define tcg_gen_brcond_tl tcg_gen_brcond_i32
cb63669a 2898#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
be210acb 2899#define tcg_gen_setcond_tl tcg_gen_setcond_i32
add1e7ea 2900#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
f730fd27
TS
2901#define tcg_gen_mul_tl tcg_gen_mul_i32
2902#define tcg_gen_muli_tl tcg_gen_muli_i32
ab36421e
AJ
2903#define tcg_gen_div_tl tcg_gen_div_i32
2904#define tcg_gen_rem_tl tcg_gen_rem_i32
864951af
AJ
2905#define tcg_gen_divu_tl tcg_gen_divu_i32
2906#define tcg_gen_remu_tl tcg_gen_remu_i32
a768e4b2 2907#define tcg_gen_discard_tl tcg_gen_discard_i32
e429073d
BS
2908#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2909#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2910#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2911#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2912#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2913#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
0b6ce4cf
FB
2914#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2915#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2916#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2917#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2918#define tcg_gen_ext32u_tl tcg_gen_mov_i32
2919#define tcg_gen_ext32s_tl tcg_gen_mov_i32
911d79ba
AJ
2920#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2921#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
945ca823 2922#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
3c51a985 2923#define tcg_gen_extr_tl_i64 tcg_gen_extr_i32_i64
f24cb33e
AJ
2924#define tcg_gen_andc_tl tcg_gen_andc_i32
2925#define tcg_gen_eqv_tl tcg_gen_eqv_i32
2926#define tcg_gen_nand_tl tcg_gen_nand_i32
2927#define tcg_gen_nor_tl tcg_gen_nor_i32
2928#define tcg_gen_orc_tl tcg_gen_orc_i32
15824571
AJ
2929#define tcg_gen_rotl_tl tcg_gen_rotl_i32
2930#define tcg_gen_rotli_tl tcg_gen_rotli_i32
2931#define tcg_gen_rotr_tl tcg_gen_rotr_i32
2932#define tcg_gen_rotri_tl tcg_gen_rotri_i32
b7767f0f 2933#define tcg_gen_deposit_tl tcg_gen_deposit_i32
a98824ac 2934#define tcg_const_tl tcg_const_i32
bdffd4a9 2935#define tcg_const_local_tl tcg_const_local_i32
ffc5ea09 2936#define tcg_gen_movcond_tl tcg_gen_movcond_i32
f6953a73
RH
2937#define tcg_gen_add2_tl tcg_gen_add2_i32
2938#define tcg_gen_sub2_tl tcg_gen_sub2_i32
696a8be6
RH
2939#define tcg_gen_mulu2_tl tcg_gen_mulu2_i32
2940#define tcg_gen_muls2_tl tcg_gen_muls2_i32
f8422f52 2941#endif
6ddbc6e4
PB
2942
2943#if TCG_TARGET_REG_BITS == 32
ebecf363
PM
2944#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), \
2945 TCGV_PTR_TO_NAT(A), \
2946 TCGV_PTR_TO_NAT(B))
2947#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), \
2948 TCGV_PTR_TO_NAT(A), (B))
2949#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
6ddbc6e4 2950#else /* TCG_TARGET_REG_BITS == 32 */
ebecf363
PM
2951#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), \
2952 TCGV_PTR_TO_NAT(A), \
2953 TCGV_PTR_TO_NAT(B))
2954#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), \
2955 TCGV_PTR_TO_NAT(A), (B))
2956#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
6ddbc6e4 2957#endif /* TCG_TARGET_REG_BITS != 32 */