]> git.proxmox.com Git - qemu.git/blame - tcg/tcg-op.h
po/Makefile: Fix generation of messages.po
[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{
ca675f46 734 if (TCG_TARGET_HAS_rem_i32) {
25c4d9cc 735 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
ca675f46
RH
736 } else if (TCG_TARGET_HAS_div_i32) {
737 TCGv_i32 t0 = tcg_temp_new_i32();
738 tcg_gen_op3_i32(INDEX_op_div_i32, t0, arg1, arg2);
739 tcg_gen_mul_i32(t0, t0, arg2);
740 tcg_gen_sub_i32(ret, arg1, t0);
741 tcg_temp_free_i32(t0);
25c4d9cc
RH
742 } else if (TCG_TARGET_HAS_div2_i32) {
743 TCGv_i32 t0 = tcg_temp_new_i32();
744 tcg_gen_sari_i32(t0, arg1, 31);
745 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
746 tcg_temp_free_i32(t0);
747 } else {
748 int sizemask = 0;
749 /* Return value and both arguments are 32-bit and signed. */
750 sizemask |= tcg_gen_sizemask(0, 0, 1);
751 sizemask |= tcg_gen_sizemask(1, 0, 1);
752 sizemask |= tcg_gen_sizemask(2, 0, 1);
753 tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2);
754 }
31d66551
AJ
755}
756
757static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
758{
25c4d9cc
RH
759 if (TCG_TARGET_HAS_div_i32) {
760 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
761 } else if (TCG_TARGET_HAS_div2_i32) {
762 TCGv_i32 t0 = tcg_temp_new_i32();
763 tcg_gen_movi_i32(t0, 0);
764 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
765 tcg_temp_free_i32(t0);
766 } else {
767 int sizemask = 0;
768 /* Return value and both arguments are 32-bit and unsigned. */
769 sizemask |= tcg_gen_sizemask(0, 0, 0);
770 sizemask |= tcg_gen_sizemask(1, 0, 0);
771 sizemask |= tcg_gen_sizemask(2, 0, 0);
772 tcg_gen_helper32(tcg_helper_divu_i32, sizemask, ret, arg1, arg2);
773 }
31d66551
AJ
774}
775
776static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
777{
ca675f46 778 if (TCG_TARGET_HAS_rem_i32) {
25c4d9cc 779 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
ca675f46
RH
780 } else if (TCG_TARGET_HAS_div_i32) {
781 TCGv_i32 t0 = tcg_temp_new_i32();
782 tcg_gen_op3_i32(INDEX_op_divu_i32, t0, arg1, arg2);
783 tcg_gen_mul_i32(t0, t0, arg2);
784 tcg_gen_sub_i32(ret, arg1, t0);
785 tcg_temp_free_i32(t0);
25c4d9cc
RH
786 } else if (TCG_TARGET_HAS_div2_i32) {
787 TCGv_i32 t0 = tcg_temp_new_i32();
788 tcg_gen_movi_i32(t0, 0);
789 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
790 tcg_temp_free_i32(t0);
791 } else {
792 int sizemask = 0;
793 /* Return value and both arguments are 32-bit and unsigned. */
794 sizemask |= tcg_gen_sizemask(0, 0, 0);
795 sizemask |= tcg_gen_sizemask(1, 0, 0);
796 sizemask |= tcg_gen_sizemask(2, 0, 0);
797 tcg_gen_helper32(tcg_helper_remu_i32, sizemask, ret, arg1, arg2);
798 }
31d66551 799}
c896fe29
FB
800
801#if TCG_TARGET_REG_BITS == 32
802
a7812ae4 803static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 804{
fe75bcf7 805 if (!TCGV_EQUAL_I64(ret, arg)) {
a7812ae4 806 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
4d07272d
BS
807 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
808 }
c896fe29
FB
809}
810
a7812ae4 811static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
c896fe29 812{
a7812ae4 813 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
ac56dd48 814 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
c896fe29
FB
815}
816
a7812ae4
PB
817static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
818 tcg_target_long offset)
c896fe29 819{
a7812ae4 820 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 821 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
822}
823
a7812ae4
PB
824static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
825 tcg_target_long offset)
c896fe29 826{
a7812ae4
PB
827 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
828 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
c896fe29
FB
829}
830
a7812ae4
PB
831static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
832 tcg_target_long offset)
c896fe29 833{
a747723b 834 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 835 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
836}
837
a7812ae4
PB
838static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
839 tcg_target_long offset)
c896fe29 840{
a7812ae4
PB
841 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
842 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
843}
844
a7812ae4
PB
845static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
846 tcg_target_long offset)
c896fe29 847{
a7812ae4 848 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 849 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
850}
851
a7812ae4
PB
852static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
853 tcg_target_long offset)
c896fe29 854{
a7812ae4
PB
855 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
856 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
857}
858
a7812ae4
PB
859static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
860 tcg_target_long offset)
c896fe29
FB
861{
862 /* since arg2 and ret have different types, they cannot be the
863 same temporary */
864#ifdef TCG_TARGET_WORDS_BIGENDIAN
ac56dd48 865 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
a7812ae4 866 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
c896fe29 867#else
a7812ae4 868 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 869 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
c896fe29
FB
870#endif
871}
872
a7812ae4
PB
873static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
874 tcg_target_long offset)
c896fe29 875{
a7812ae4 876 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
877}
878
a7812ae4
PB
879static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
880 tcg_target_long offset)
c896fe29 881{
a7812ae4 882 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
883}
884
a7812ae4
PB
885static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
886 tcg_target_long offset)
c896fe29 887{
a7812ae4 888 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
889}
890
a7812ae4
PB
891static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
892 tcg_target_long offset)
c896fe29
FB
893{
894#ifdef TCG_TARGET_WORDS_BIGENDIAN
ac56dd48 895 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
a7812ae4 896 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
c896fe29 897#else
a7812ae4 898 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
ac56dd48 899 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
c896fe29
FB
900#endif
901}
902
a7812ae4 903static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 904{
a7812ae4
PB
905 tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
906 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
907 TCGV_HIGH(arg2));
212c328d
RH
908 /* Allow the optimizer room to replace add2 with two moves. */
909 tcg_gen_op0(INDEX_op_nop);
c896fe29
FB
910}
911
a7812ae4 912static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 913{
a7812ae4
PB
914 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
915 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
916 TCGV_HIGH(arg2));
212c328d
RH
917 /* Allow the optimizer room to replace sub2 with two moves. */
918 tcg_gen_op0(INDEX_op_nop);
c896fe29
FB
919}
920
a7812ae4 921static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 922{
a7812ae4 923 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
ac56dd48 924 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
925}
926
a7812ae4 927static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 928{
e5105083
AJ
929 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
930 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
931}
932
a7812ae4 933static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 934{
e5105083
AJ
935 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
936 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
937}
938
a7812ae4 939static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 940{
a7812ae4 941 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
ac56dd48 942 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
943}
944
a7812ae4 945static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 946{
e5105083
AJ
947 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
948 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
949}
950
a7812ae4 951static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 952{
a7812ae4 953 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
ac56dd48 954 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
955}
956
957/* XXX: use generic code when basic block handling is OK or CPU
958 specific code (x86) */
a7812ae4 959static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 960{
2bece2c8
RH
961 int sizemask = 0;
962 /* Return value and both arguments are 64-bit and signed. */
963 sizemask |= tcg_gen_sizemask(0, 1, 1);
964 sizemask |= tcg_gen_sizemask(1, 1, 1);
965 sizemask |= tcg_gen_sizemask(2, 1, 1);
966
967 tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
968}
969
a7812ae4 970static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
971{
972 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
973}
974
a7812ae4 975static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 976{
2bece2c8
RH
977 int sizemask = 0;
978 /* Return value and both arguments are 64-bit and signed. */
979 sizemask |= tcg_gen_sizemask(0, 1, 1);
980 sizemask |= tcg_gen_sizemask(1, 1, 1);
981 sizemask |= tcg_gen_sizemask(2, 1, 1);
982
983 tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
984}
985
a7812ae4 986static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
987{
988 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
989}
990
a7812ae4 991static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 992{
2bece2c8
RH
993 int sizemask = 0;
994 /* Return value and both arguments are 64-bit and signed. */
995 sizemask |= tcg_gen_sizemask(0, 1, 1);
996 sizemask |= tcg_gen_sizemask(1, 1, 1);
997 sizemask |= tcg_gen_sizemask(2, 1, 1);
998
999 tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1000}
1001
a7812ae4 1002static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
1003{
1004 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
1005}
1006
8a56e840
RH
1007static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1008 TCGv_i64 arg2, int label_index)
c896fe29 1009{
0aed257f
RH
1010 if (cond == TCG_COND_ALWAYS) {
1011 tcg_gen_br(label_index);
1012 } else if (cond != TCG_COND_NEVER) {
1013 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
1014 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
1015 TCGV_HIGH(arg2), cond, label_index);
1016 }
c896fe29
FB
1017}
1018
8a56e840 1019static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
5105c556
AJ
1020 TCGv_i64 arg1, TCGv_i64 arg2)
1021{
0aed257f
RH
1022 if (cond == TCG_COND_ALWAYS) {
1023 tcg_gen_movi_i32(TCGV_LOW(ret), 1);
1024 } else if (cond == TCG_COND_NEVER) {
1025 tcg_gen_movi_i32(TCGV_LOW(ret), 0);
1026 } else {
1027 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
1028 TCGV_LOW(arg1), TCGV_HIGH(arg1),
1029 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
1030 }
5105c556
AJ
1031 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1032}
1033
a7812ae4 1034static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1035{
a7812ae4
PB
1036 TCGv_i64 t0;
1037 TCGv_i32 t1;
c896fe29 1038
a7812ae4
PB
1039 t0 = tcg_temp_new_i64();
1040 t1 = tcg_temp_new_i32();
1041
1042 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
1043 TCGV_LOW(arg1), TCGV_LOW(arg2));
1414968a
RH
1044 /* Allow the optimizer room to replace mulu2 with two moves. */
1045 tcg_gen_op0(INDEX_op_nop);
a7812ae4
PB
1046
1047 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
ac56dd48 1048 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
a7812ae4 1049 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
ac56dd48 1050 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
a7812ae4 1051
c896fe29 1052 tcg_gen_mov_i64(ret, t0);
a7812ae4
PB
1053 tcg_temp_free_i64(t0);
1054 tcg_temp_free_i32(t1);
c896fe29
FB
1055}
1056
a7812ae4 1057static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1058{
2bece2c8
RH
1059 int sizemask = 0;
1060 /* Return value and both arguments are 64-bit and signed. */
1061 sizemask |= tcg_gen_sizemask(0, 1, 1);
1062 sizemask |= tcg_gen_sizemask(1, 1, 1);
1063 sizemask |= tcg_gen_sizemask(2, 1, 1);
1064
1065 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1066}
1067
a7812ae4 1068static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1069{
2bece2c8
RH
1070 int sizemask = 0;
1071 /* Return value and both arguments are 64-bit and signed. */
1072 sizemask |= tcg_gen_sizemask(0, 1, 1);
1073 sizemask |= tcg_gen_sizemask(1, 1, 1);
1074 sizemask |= tcg_gen_sizemask(2, 1, 1);
1075
1076 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1077}
1078
a7812ae4 1079static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1080{
2bece2c8
RH
1081 int sizemask = 0;
1082 /* Return value and both arguments are 64-bit and unsigned. */
1083 sizemask |= tcg_gen_sizemask(0, 1, 0);
1084 sizemask |= tcg_gen_sizemask(1, 1, 0);
1085 sizemask |= tcg_gen_sizemask(2, 1, 0);
1086
1087 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1088}
1089
a7812ae4 1090static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1091{
2bece2c8
RH
1092 int sizemask = 0;
1093 /* Return value and both arguments are 64-bit and unsigned. */
1094 sizemask |= tcg_gen_sizemask(0, 1, 0);
1095 sizemask |= tcg_gen_sizemask(1, 1, 0);
1096 sizemask |= tcg_gen_sizemask(2, 1, 0);
1097
1098 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1099}
1100
1101#else
1102
a7812ae4 1103static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1104{
fe75bcf7 1105 if (!TCGV_EQUAL_I64(ret, arg))
a7812ae4 1106 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
c896fe29
FB
1107}
1108
a7812ae4 1109static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
c896fe29 1110{
a7812ae4 1111 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
c896fe29
FB
1112}
1113
6bd4b08a 1114static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1115 tcg_target_long offset)
c896fe29 1116{
a7812ae4 1117 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
c896fe29
FB
1118}
1119
6bd4b08a 1120static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1121 tcg_target_long offset)
c896fe29 1122{
a7812ae4 1123 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
c896fe29
FB
1124}
1125
6bd4b08a 1126static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1127 tcg_target_long offset)
c896fe29 1128{
a7812ae4 1129 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
c896fe29
FB
1130}
1131
6bd4b08a 1132static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1133 tcg_target_long offset)
c896fe29 1134{
a7812ae4 1135 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
c896fe29
FB
1136}
1137
6bd4b08a 1138static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1139 tcg_target_long offset)
c896fe29 1140{
a7812ae4 1141 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
c896fe29
FB
1142}
1143
6bd4b08a 1144static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1145 tcg_target_long offset)
c896fe29 1146{
a7812ae4 1147 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
c896fe29
FB
1148}
1149
6bd4b08a 1150static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 1151{
a7812ae4 1152 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
c896fe29
FB
1153}
1154
6bd4b08a 1155static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1156 tcg_target_long offset)
c896fe29 1157{
a7812ae4 1158 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
c896fe29
FB
1159}
1160
6bd4b08a 1161static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1162 tcg_target_long offset)
c896fe29 1163{
a7812ae4 1164 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
c896fe29
FB
1165}
1166
6bd4b08a 1167static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1168 tcg_target_long offset)
c896fe29 1169{
a7812ae4 1170 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
c896fe29
FB
1171}
1172
6bd4b08a 1173static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 1174{
a7812ae4 1175 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
c896fe29
FB
1176}
1177
a7812ae4 1178static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1179{
a7812ae4 1180 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
c896fe29
FB
1181}
1182
a7812ae4 1183static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1184{
a7812ae4 1185 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
c896fe29
FB
1186}
1187
a7812ae4 1188static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1189{
7fc81051
AJ
1190 if (TCGV_EQUAL_I64(arg1, arg2)) {
1191 tcg_gen_mov_i64(ret, arg1);
1192 } else {
1193 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1194 }
c896fe29
FB
1195}
1196
42ce3e20 1197static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
c896fe29 1198{
42ce3e20
RH
1199 TCGv_i64 t0;
1200 /* Some cases can be optimized here. */
1201 switch (arg2) {
1202 case 0:
1203 tcg_gen_movi_i64(ret, 0);
1204 return;
1205 case 0xffffffffffffffffull:
1206 tcg_gen_mov_i64(ret, arg1);
1207 return;
1208 case 0xffull:
1209 /* Don't recurse with tcg_gen_ext8u_i32. */
1210 if (TCG_TARGET_HAS_ext8u_i64) {
1211 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg1);
1212 return;
1213 }
1214 break;
1215 case 0xffffu:
1216 if (TCG_TARGET_HAS_ext16u_i64) {
1217 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg1);
1218 return;
1219 }
1220 break;
1221 case 0xffffffffull:
1222 if (TCG_TARGET_HAS_ext32u_i64) {
1223 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg1);
1224 return;
1225 }
1226 break;
1227 }
1228 t0 = tcg_const_i64(arg2);
e8996ee0 1229 tcg_gen_and_i64(ret, arg1, t0);
a7812ae4 1230 tcg_temp_free_i64(t0);
c896fe29
FB
1231}
1232
a7812ae4 1233static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1234{
7fc81051
AJ
1235 if (TCGV_EQUAL_I64(arg1, arg2)) {
1236 tcg_gen_mov_i64(ret, arg1);
1237 } else {
1238 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1239 }
c896fe29
FB
1240}
1241
a7812ae4 1242static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1243{
d81ada7f
RH
1244 /* Some cases can be optimized here. */
1245 if (arg2 == -1) {
1246 tcg_gen_movi_i64(ret, -1);
1247 } else if (arg2 == 0) {
1248 tcg_gen_mov_i64(ret, arg1);
1249 } else {
1250 TCGv_i64 t0 = tcg_const_i64(arg2);
1251 tcg_gen_or_i64(ret, arg1, t0);
1252 tcg_temp_free_i64(t0);
1253 }
c896fe29
FB
1254}
1255
a7812ae4 1256static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1257{
7fc81051
AJ
1258 if (TCGV_EQUAL_I64(arg1, arg2)) {
1259 tcg_gen_movi_i64(ret, 0);
1260 } else {
1261 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1262 }
c896fe29
FB
1263}
1264
a7812ae4 1265static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1266{
6f3bb33e
RH
1267 /* Some cases can be optimized here. */
1268 if (arg2 == 0) {
1269 tcg_gen_mov_i64(ret, arg1);
1270 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i64) {
1271 /* Don't recurse with tcg_gen_not_i64. */
1272 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
1273 } else {
1274 TCGv_i64 t0 = tcg_const_i64(arg2);
1275 tcg_gen_xor_i64(ret, arg1, t0);
1276 tcg_temp_free_i64(t0);
1277 }
c896fe29
FB
1278}
1279
a7812ae4 1280static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1281{
a7812ae4 1282 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
c896fe29
FB
1283}
1284
a7812ae4 1285static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1286{
34151a20
FB
1287 if (arg2 == 0) {
1288 tcg_gen_mov_i64(ret, arg1);
1289 } else {
a7812ae4 1290 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1291 tcg_gen_shl_i64(ret, arg1, t0);
a7812ae4 1292 tcg_temp_free_i64(t0);
34151a20 1293 }
c896fe29
FB
1294}
1295
a7812ae4 1296static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1297{
a7812ae4 1298 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
c896fe29
FB
1299}
1300
a7812ae4 1301static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1302{
34151a20
FB
1303 if (arg2 == 0) {
1304 tcg_gen_mov_i64(ret, arg1);
1305 } else {
a7812ae4 1306 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1307 tcg_gen_shr_i64(ret, arg1, t0);
a7812ae4 1308 tcg_temp_free_i64(t0);
34151a20 1309 }
c896fe29
FB
1310}
1311
a7812ae4 1312static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1313{
a7812ae4 1314 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
c896fe29
FB
1315}
1316
a7812ae4 1317static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1318{
34151a20
FB
1319 if (arg2 == 0) {
1320 tcg_gen_mov_i64(ret, arg1);
1321 } else {
a7812ae4 1322 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1323 tcg_gen_sar_i64(ret, arg1, t0);
a7812ae4 1324 tcg_temp_free_i64(t0);
34151a20 1325 }
c896fe29
FB
1326}
1327
8a56e840
RH
1328static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1329 TCGv_i64 arg2, int label_index)
c896fe29 1330{
0aed257f
RH
1331 if (cond == TCG_COND_ALWAYS) {
1332 tcg_gen_br(label_index);
1333 } else if (cond != TCG_COND_NEVER) {
1334 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
1335 }
c896fe29
FB
1336}
1337
8a56e840 1338static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
5105c556
AJ
1339 TCGv_i64 arg1, TCGv_i64 arg2)
1340{
0aed257f
RH
1341 if (cond == TCG_COND_ALWAYS) {
1342 tcg_gen_movi_i64(ret, 1);
1343 } else if (cond == TCG_COND_NEVER) {
1344 tcg_gen_movi_i64(ret, 0);
1345 } else {
1346 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1347 }
5105c556
AJ
1348}
1349
a7812ae4 1350static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1351{
a7812ae4 1352 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
c896fe29
FB
1353}
1354
31d66551
AJ
1355static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1356{
25c4d9cc
RH
1357 if (TCG_TARGET_HAS_div_i64) {
1358 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
1359 } else if (TCG_TARGET_HAS_div2_i64) {
1360 TCGv_i64 t0 = tcg_temp_new_i64();
1361 tcg_gen_sari_i64(t0, arg1, 63);
1362 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1363 tcg_temp_free_i64(t0);
1364 } else {
1365 int sizemask = 0;
1366 /* Return value and both arguments are 64-bit and signed. */
1367 sizemask |= tcg_gen_sizemask(0, 1, 1);
1368 sizemask |= tcg_gen_sizemask(1, 1, 1);
1369 sizemask |= tcg_gen_sizemask(2, 1, 1);
1370 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
1371 }
31d66551
AJ
1372}
1373
1374static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1375{
ca675f46 1376 if (TCG_TARGET_HAS_rem_i64) {
25c4d9cc 1377 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
ca675f46
RH
1378 } else if (TCG_TARGET_HAS_div_i64) {
1379 TCGv_i64 t0 = tcg_temp_new_i64();
1380 tcg_gen_op3_i64(INDEX_op_div_i64, t0, arg1, arg2);
1381 tcg_gen_mul_i64(t0, t0, arg2);
1382 tcg_gen_sub_i64(ret, arg1, t0);
1383 tcg_temp_free_i64(t0);
25c4d9cc
RH
1384 } else if (TCG_TARGET_HAS_div2_i64) {
1385 TCGv_i64 t0 = tcg_temp_new_i64();
1386 tcg_gen_sari_i64(t0, arg1, 63);
1387 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1388 tcg_temp_free_i64(t0);
1389 } else {
1390 int sizemask = 0;
1391 /* Return value and both arguments are 64-bit and signed. */
1392 sizemask |= tcg_gen_sizemask(0, 1, 1);
1393 sizemask |= tcg_gen_sizemask(1, 1, 1);
1394 sizemask |= tcg_gen_sizemask(2, 1, 1);
1395 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1396 }
31d66551
AJ
1397}
1398
1399static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1400{
25c4d9cc
RH
1401 if (TCG_TARGET_HAS_div_i64) {
1402 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
1403 } else if (TCG_TARGET_HAS_div2_i64) {
1404 TCGv_i64 t0 = tcg_temp_new_i64();
1405 tcg_gen_movi_i64(t0, 0);
1406 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1407 tcg_temp_free_i64(t0);
1408 } else {
1409 int sizemask = 0;
1410 /* Return value and both arguments are 64-bit and unsigned. */
1411 sizemask |= tcg_gen_sizemask(0, 1, 0);
1412 sizemask |= tcg_gen_sizemask(1, 1, 0);
1413 sizemask |= tcg_gen_sizemask(2, 1, 0);
1414 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1415 }
31d66551
AJ
1416}
1417
1418static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1419{
ca675f46 1420 if (TCG_TARGET_HAS_rem_i64) {
25c4d9cc 1421 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
ca675f46
RH
1422 } else if (TCG_TARGET_HAS_div_i64) {
1423 TCGv_i64 t0 = tcg_temp_new_i64();
1424 tcg_gen_op3_i64(INDEX_op_divu_i64, t0, arg1, arg2);
1425 tcg_gen_mul_i64(t0, t0, arg2);
1426 tcg_gen_sub_i64(ret, arg1, t0);
1427 tcg_temp_free_i64(t0);
25c4d9cc
RH
1428 } else if (TCG_TARGET_HAS_div2_i64) {
1429 TCGv_i64 t0 = tcg_temp_new_i64();
1430 tcg_gen_movi_i64(t0, 0);
1431 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1432 tcg_temp_free_i64(t0);
1433 } else {
1434 int sizemask = 0;
1435 /* Return value and both arguments are 64-bit and unsigned. */
1436 sizemask |= tcg_gen_sizemask(0, 1, 0);
1437 sizemask |= tcg_gen_sizemask(1, 1, 0);
1438 sizemask |= tcg_gen_sizemask(2, 1, 0);
1439 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1440 }
31d66551 1441}
25c4d9cc 1442#endif /* TCG_TARGET_REG_BITS == 32 */
c896fe29 1443
a7812ae4 1444static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
6359706f
AJ
1445{
1446 /* some cases can be optimized here */
1447 if (arg2 == 0) {
1448 tcg_gen_mov_i64(ret, arg1);
1449 } else {
a7812ae4 1450 TCGv_i64 t0 = tcg_const_i64(arg2);
6359706f 1451 tcg_gen_add_i64(ret, arg1, t0);
a7812ae4 1452 tcg_temp_free_i64(t0);
6359706f
AJ
1453 }
1454}
1455
a7812ae4 1456static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
0045734a 1457{
a7812ae4 1458 TCGv_i64 t0 = tcg_const_i64(arg1);
0045734a 1459 tcg_gen_sub_i64(ret, t0, arg2);
a7812ae4 1460 tcg_temp_free_i64(t0);
0045734a
AJ
1461}
1462
a7812ae4 1463static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
6359706f
AJ
1464{
1465 /* some cases can be optimized here */
1466 if (arg2 == 0) {
1467 tcg_gen_mov_i64(ret, arg1);
1468 } else {
a7812ae4 1469 TCGv_i64 t0 = tcg_const_i64(arg2);
6359706f 1470 tcg_gen_sub_i64(ret, arg1, t0);
a7812ae4 1471 tcg_temp_free_i64(t0);
6359706f
AJ
1472 }
1473}
8a56e840
RH
1474static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1475 int64_t arg2, int label_index)
f02bb954 1476{
0aed257f
RH
1477 if (cond == TCG_COND_ALWAYS) {
1478 tcg_gen_br(label_index);
1479 } else if (cond != TCG_COND_NEVER) {
1480 TCGv_i64 t0 = tcg_const_i64(arg2);
1481 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1482 tcg_temp_free_i64(t0);
1483 }
f02bb954
AJ
1484}
1485
8a56e840
RH
1486static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1487 TCGv_i64 arg1, int64_t arg2)
5105c556
AJ
1488{
1489 TCGv_i64 t0 = tcg_const_i64(arg2);
1490 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1491 tcg_temp_free_i64(t0);
1492}
1493
a7812ae4 1494static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
f02bb954 1495{
a7812ae4 1496 TCGv_i64 t0 = tcg_const_i64(arg2);
f02bb954 1497 tcg_gen_mul_i64(ret, arg1, t0);
a7812ae4 1498 tcg_temp_free_i64(t0);
f02bb954
AJ
1499}
1500
6359706f 1501
c896fe29
FB
1502/***************************************/
1503/* optional operations */
1504
a7812ae4 1505static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1506{
25c4d9cc
RH
1507 if (TCG_TARGET_HAS_ext8s_i32) {
1508 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
1509 } else {
1510 tcg_gen_shli_i32(ret, arg, 24);
1511 tcg_gen_sari_i32(ret, ret, 24);
1512 }
c896fe29
FB
1513}
1514
a7812ae4 1515static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1516{
25c4d9cc
RH
1517 if (TCG_TARGET_HAS_ext16s_i32) {
1518 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
1519 } else {
1520 tcg_gen_shli_i32(ret, arg, 16);
1521 tcg_gen_sari_i32(ret, ret, 16);
1522 }
c896fe29
FB
1523}
1524
a7812ae4 1525static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
86831435 1526{
25c4d9cc
RH
1527 if (TCG_TARGET_HAS_ext8u_i32) {
1528 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1529 } else {
1530 tcg_gen_andi_i32(ret, arg, 0xffu);
1531 }
86831435
PB
1532}
1533
a7812ae4 1534static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
86831435 1535{
25c4d9cc
RH
1536 if (TCG_TARGET_HAS_ext16u_i32) {
1537 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1538 } else {
1539 tcg_gen_andi_i32(ret, arg, 0xffffu);
1540 }
86831435
PB
1541}
1542
c896fe29 1543/* Note: we assume the two high bytes are set to zero */
a7812ae4 1544static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1545{
25c4d9cc
RH
1546 if (TCG_TARGET_HAS_bswap16_i32) {
1547 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
1548 } else {
1549 TCGv_i32 t0 = tcg_temp_new_i32();
c896fe29 1550
25c4d9cc
RH
1551 tcg_gen_ext8u_i32(t0, arg);
1552 tcg_gen_shli_i32(t0, t0, 8);
1553 tcg_gen_shri_i32(ret, arg, 8);
1554 tcg_gen_or_i32(ret, ret, t0);
1555 tcg_temp_free_i32(t0);
1556 }
c896fe29
FB
1557}
1558
66896cb8 1559static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1560{
25c4d9cc
RH
1561 if (TCG_TARGET_HAS_bswap32_i32) {
1562 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
1563 } else {
1564 TCGv_i32 t0, t1;
1565 t0 = tcg_temp_new_i32();
1566 t1 = tcg_temp_new_i32();
c896fe29 1567
25c4d9cc 1568 tcg_gen_shli_i32(t0, arg, 24);
c896fe29 1569
25c4d9cc
RH
1570 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1571 tcg_gen_shli_i32(t1, t1, 8);
1572 tcg_gen_or_i32(t0, t0, t1);
c896fe29 1573
25c4d9cc
RH
1574 tcg_gen_shri_i32(t1, arg, 8);
1575 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1576 tcg_gen_or_i32(t0, t0, t1);
c896fe29 1577
25c4d9cc
RH
1578 tcg_gen_shri_i32(t1, arg, 24);
1579 tcg_gen_or_i32(ret, t0, t1);
1580 tcg_temp_free_i32(t0);
1581 tcg_temp_free_i32(t1);
1582 }
c896fe29
FB
1583}
1584
1585#if TCG_TARGET_REG_BITS == 32
a7812ae4 1586static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1587{
a7812ae4
PB
1588 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1589 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1590}
1591
a7812ae4 1592static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1593{
a7812ae4
PB
1594 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1595 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1596}
1597
a7812ae4 1598static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1599{
a7812ae4
PB
1600 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1601 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1602}
1603
a7812ae4 1604static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1605{
a7812ae4 1606 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1607 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1608}
1609
a7812ae4 1610static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1611{
a7812ae4 1612 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1613 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1614}
1615
a7812ae4 1616static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1617{
a7812ae4 1618 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1619 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1620}
1621
a7812ae4 1622static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
c896fe29 1623{
a7812ae4 1624 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
c896fe29
FB
1625}
1626
a7812ae4 1627static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1628{
a7812ae4 1629 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
ac56dd48 1630 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1631}
1632
a7812ae4 1633static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1634{
a7812ae4
PB
1635 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1636 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1637}
1638
9a5c57fd
AJ
1639/* Note: we assume the six high bytes are set to zero */
1640static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1641{
1642 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1643 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1644}
1645
1646/* Note: we assume the four high bytes are set to zero */
1647static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1648{
1649 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1650 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1651}
1652
66896cb8 1653static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1654{
a7812ae4
PB
1655 TCGv_i32 t0, t1;
1656 t0 = tcg_temp_new_i32();
1657 t1 = tcg_temp_new_i32();
c896fe29 1658
66896cb8
AJ
1659 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1660 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
a7812ae4 1661 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
ac56dd48 1662 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
a7812ae4
PB
1663 tcg_temp_free_i32(t0);
1664 tcg_temp_free_i32(t1);
c896fe29
FB
1665}
1666#else
1667
a7812ae4 1668static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1669{
25c4d9cc
RH
1670 if (TCG_TARGET_HAS_ext8s_i64) {
1671 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
1672 } else {
1673 tcg_gen_shli_i64(ret, arg, 56);
1674 tcg_gen_sari_i64(ret, ret, 56);
1675 }
c896fe29
FB
1676}
1677
a7812ae4 1678static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1679{
25c4d9cc
RH
1680 if (TCG_TARGET_HAS_ext16s_i64) {
1681 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
1682 } else {
1683 tcg_gen_shli_i64(ret, arg, 48);
1684 tcg_gen_sari_i64(ret, ret, 48);
1685 }
c896fe29
FB
1686}
1687
a7812ae4 1688static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1689{
25c4d9cc
RH
1690 if (TCG_TARGET_HAS_ext32s_i64) {
1691 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
1692 } else {
1693 tcg_gen_shli_i64(ret, arg, 32);
1694 tcg_gen_sari_i64(ret, ret, 32);
1695 }
c896fe29
FB
1696}
1697
a7812ae4 1698static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1699{
25c4d9cc
RH
1700 if (TCG_TARGET_HAS_ext8u_i64) {
1701 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1702 } else {
1703 tcg_gen_andi_i64(ret, arg, 0xffu);
1704 }
86831435
PB
1705}
1706
a7812ae4 1707static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1708{
25c4d9cc
RH
1709 if (TCG_TARGET_HAS_ext16u_i64) {
1710 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1711 } else {
1712 tcg_gen_andi_i64(ret, arg, 0xffffu);
1713 }
86831435
PB
1714}
1715
a7812ae4 1716static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1717{
25c4d9cc
RH
1718 if (TCG_TARGET_HAS_ext32u_i64) {
1719 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1720 } else {
1721 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1722 }
86831435
PB
1723}
1724
c896fe29 1725/* Note: we assume the target supports move between 32 and 64 bit
ac56dd48 1726 registers. This will probably break MIPS64 targets. */
a7812ae4 1727static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
c896fe29 1728{
a7812ae4 1729 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
c896fe29
FB
1730}
1731
1732/* Note: we assume the target supports move between 32 and 64 bit
1733 registers */
a7812ae4 1734static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1735{
cfc86988 1736 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
c896fe29
FB
1737}
1738
1739/* Note: we assume the target supports move between 32 and 64 bit
1740 registers */
a7812ae4 1741static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1742{
a7812ae4 1743 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
c896fe29
FB
1744}
1745
9a5c57fd
AJ
1746/* Note: we assume the six high bytes are set to zero */
1747static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1748{
25c4d9cc
RH
1749 if (TCG_TARGET_HAS_bswap16_i64) {
1750 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1751 } else {
1752 TCGv_i64 t0 = tcg_temp_new_i64();
9a5c57fd 1753
25c4d9cc
RH
1754 tcg_gen_ext8u_i64(t0, arg);
1755 tcg_gen_shli_i64(t0, t0, 8);
1756 tcg_gen_shri_i64(ret, arg, 8);
1757 tcg_gen_or_i64(ret, ret, t0);
1758 tcg_temp_free_i64(t0);
1759 }
9a5c57fd
AJ
1760}
1761
1762/* Note: we assume the four high bytes are set to zero */
1763static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1764{
25c4d9cc
RH
1765 if (TCG_TARGET_HAS_bswap32_i64) {
1766 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1767 } else {
1768 TCGv_i64 t0, t1;
1769 t0 = tcg_temp_new_i64();
1770 t1 = tcg_temp_new_i64();
9a5c57fd 1771
25c4d9cc
RH
1772 tcg_gen_shli_i64(t0, arg, 24);
1773 tcg_gen_ext32u_i64(t0, t0);
9a5c57fd 1774
25c4d9cc
RH
1775 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1776 tcg_gen_shli_i64(t1, t1, 8);
1777 tcg_gen_or_i64(t0, t0, t1);
9a5c57fd 1778
25c4d9cc
RH
1779 tcg_gen_shri_i64(t1, arg, 8);
1780 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1781 tcg_gen_or_i64(t0, t0, t1);
9a5c57fd 1782
25c4d9cc
RH
1783 tcg_gen_shri_i64(t1, arg, 24);
1784 tcg_gen_or_i64(ret, t0, t1);
1785 tcg_temp_free_i64(t0);
1786 tcg_temp_free_i64(t1);
1787 }
9a5c57fd
AJ
1788}
1789
66896cb8 1790static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1791{
25c4d9cc
RH
1792 if (TCG_TARGET_HAS_bswap64_i64) {
1793 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
1794 } else {
1795 TCGv_i64 t0 = tcg_temp_new_i64();
1796 TCGv_i64 t1 = tcg_temp_new_i64();
c896fe29 1797
25c4d9cc 1798 tcg_gen_shli_i64(t0, arg, 56);
c896fe29 1799
25c4d9cc
RH
1800 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1801 tcg_gen_shli_i64(t1, t1, 40);
1802 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1803
25c4d9cc
RH
1804 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1805 tcg_gen_shli_i64(t1, t1, 24);
1806 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1807
25c4d9cc
RH
1808 tcg_gen_andi_i64(t1, arg, 0xff000000);
1809 tcg_gen_shli_i64(t1, t1, 8);
1810 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1811
25c4d9cc
RH
1812 tcg_gen_shri_i64(t1, arg, 8);
1813 tcg_gen_andi_i64(t1, t1, 0xff000000);
1814 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1815
25c4d9cc
RH
1816 tcg_gen_shri_i64(t1, arg, 24);
1817 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1818 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1819
25c4d9cc
RH
1820 tcg_gen_shri_i64(t1, arg, 40);
1821 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1822 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1823
25c4d9cc
RH
1824 tcg_gen_shri_i64(t1, arg, 56);
1825 tcg_gen_or_i64(ret, t0, t1);
1826 tcg_temp_free_i64(t0);
1827 tcg_temp_free_i64(t1);
1828 }
c896fe29
FB
1829}
1830
1831#endif
1832
a7812ae4 1833static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
390efc54 1834{
25c4d9cc
RH
1835 if (TCG_TARGET_HAS_neg_i32) {
1836 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
1837 } else {
1838 TCGv_i32 t0 = tcg_const_i32(0);
1839 tcg_gen_sub_i32(ret, t0, arg);
1840 tcg_temp_free_i32(t0);
1841 }
390efc54
PB
1842}
1843
a7812ae4 1844static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
390efc54 1845{
25c4d9cc
RH
1846 if (TCG_TARGET_HAS_neg_i64) {
1847 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
1848 } else {
1849 TCGv_i64 t0 = tcg_const_i64(0);
1850 tcg_gen_sub_i64(ret, t0, arg);
1851 tcg_temp_free_i64(t0);
1852 }
390efc54
PB
1853}
1854
a7812ae4 1855static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
0b6ce4cf 1856{
25c4d9cc
RH
1857 if (TCG_TARGET_HAS_not_i32) {
1858 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1859 } else {
1860 tcg_gen_xori_i32(ret, arg, -1);
1861 }
0b6ce4cf
FB
1862}
1863
a7812ae4 1864static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
0b6ce4cf 1865{
25c4d9cc
RH
1866#if TCG_TARGET_REG_BITS == 64
1867 if (TCG_TARGET_HAS_not_i64) {
1868 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
1869 } else {
1870 tcg_gen_xori_i64(ret, arg, -1);
1871 }
1872#else
a10f9f4f
RH
1873 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1874 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
d2604285 1875#endif
0b6ce4cf 1876}
5ff9d6a4 1877
a7812ae4 1878static inline void tcg_gen_discard_i32(TCGv_i32 arg)
5ff9d6a4 1879{
a7812ae4 1880 tcg_gen_op1_i32(INDEX_op_discard, arg);
5ff9d6a4
FB
1881}
1882
a7812ae4 1883static inline void tcg_gen_discard_i64(TCGv_i64 arg)
5ff9d6a4 1884{
25c4d9cc 1885#if TCG_TARGET_REG_BITS == 32
a7812ae4 1886 tcg_gen_discard_i32(TCGV_LOW(arg));
5ff9d6a4 1887 tcg_gen_discard_i32(TCGV_HIGH(arg));
5ff9d6a4 1888#else
a7812ae4 1889 tcg_gen_op1_i64(INDEX_op_discard, arg);
5ff9d6a4 1890#endif
25c4d9cc 1891}
5ff9d6a4 1892
a7812ae4 1893static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1894{
25c4d9cc
RH
1895 if (TCG_TARGET_HAS_andc_i32) {
1896 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1897 } else {
1898 TCGv_i32 t0 = tcg_temp_new_i32();
1899 tcg_gen_not_i32(t0, arg2);
1900 tcg_gen_and_i32(ret, arg1, t0);
1901 tcg_temp_free_i32(t0);
1902 }
f24cb33e
AJ
1903}
1904
a7812ae4 1905static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1906{
25c4d9cc
RH
1907#if TCG_TARGET_REG_BITS == 64
1908 if (TCG_TARGET_HAS_andc_i64) {
1909 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1910 } else {
1911 TCGv_i64 t0 = tcg_temp_new_i64();
1912 tcg_gen_not_i64(t0, arg2);
1913 tcg_gen_and_i64(ret, arg1, t0);
1914 tcg_temp_free_i64(t0);
1915 }
1916#else
241cbed4
RH
1917 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1918 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
241cbed4 1919#endif
f24cb33e
AJ
1920}
1921
a7812ae4 1922static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1923{
25c4d9cc
RH
1924 if (TCG_TARGET_HAS_eqv_i32) {
1925 tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
1926 } else {
1927 tcg_gen_xor_i32(ret, arg1, arg2);
1928 tcg_gen_not_i32(ret, ret);
1929 }
f24cb33e
AJ
1930}
1931
a7812ae4 1932static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1933{
25c4d9cc
RH
1934#if TCG_TARGET_REG_BITS == 64
1935 if (TCG_TARGET_HAS_eqv_i64) {
1936 tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
1937 } else {
1938 tcg_gen_xor_i64(ret, arg1, arg2);
1939 tcg_gen_not_i64(ret, ret);
1940 }
1941#else
8d625cf1
RH
1942 tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1943 tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
8d625cf1 1944#endif
f24cb33e
AJ
1945}
1946
a7812ae4 1947static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1948{
25c4d9cc
RH
1949 if (TCG_TARGET_HAS_nand_i32) {
1950 tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
1951 } else {
1952 tcg_gen_and_i32(ret, arg1, arg2);
1953 tcg_gen_not_i32(ret, ret);
1954 }
f24cb33e
AJ
1955}
1956
a7812ae4 1957static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1958{
25c4d9cc
RH
1959#if TCG_TARGET_REG_BITS == 64
1960 if (TCG_TARGET_HAS_nand_i64) {
1961 tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
1962 } else {
1963 tcg_gen_and_i64(ret, arg1, arg2);
1964 tcg_gen_not_i64(ret, ret);
1965 }
1966#else
9940a96b
RH
1967 tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1968 tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
9940a96b 1969#endif
f24cb33e
AJ
1970}
1971
a7812ae4 1972static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1973{
25c4d9cc
RH
1974 if (TCG_TARGET_HAS_nor_i32) {
1975 tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
1976 } else {
1977 tcg_gen_or_i32(ret, arg1, arg2);
1978 tcg_gen_not_i32(ret, ret);
1979 }
f24cb33e
AJ
1980}
1981
a7812ae4 1982static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1983{
25c4d9cc
RH
1984#if TCG_TARGET_REG_BITS == 64
1985 if (TCG_TARGET_HAS_nor_i64) {
1986 tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
1987 } else {
1988 tcg_gen_or_i64(ret, arg1, arg2);
1989 tcg_gen_not_i64(ret, ret);
1990 }
1991#else
32d98fbd
RH
1992 tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1993 tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
32d98fbd 1994#endif
f24cb33e
AJ
1995}
1996
a7812ae4 1997static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1998{
25c4d9cc
RH
1999 if (TCG_TARGET_HAS_orc_i32) {
2000 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
2001 } else {
2002 TCGv_i32 t0 = tcg_temp_new_i32();
2003 tcg_gen_not_i32(t0, arg2);
2004 tcg_gen_or_i32(ret, arg1, t0);
2005 tcg_temp_free_i32(t0);
2006 }
f24cb33e
AJ
2007}
2008
a7812ae4 2009static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 2010{
25c4d9cc
RH
2011#if TCG_TARGET_REG_BITS == 64
2012 if (TCG_TARGET_HAS_orc_i64) {
2013 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
2014 } else {
2015 TCGv_i64 t0 = tcg_temp_new_i64();
2016 tcg_gen_not_i64(t0, arg2);
2017 tcg_gen_or_i64(ret, arg1, t0);
2018 tcg_temp_free_i64(t0);
2019 }
2020#else
791d1262
RH
2021 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
2022 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
791d1262 2023#endif
f24cb33e
AJ
2024}
2025
a7812ae4 2026static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
15824571 2027{
25c4d9cc
RH
2028 if (TCG_TARGET_HAS_rot_i32) {
2029 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
2030 } else {
2031 TCGv_i32 t0, t1;
15824571 2032
25c4d9cc
RH
2033 t0 = tcg_temp_new_i32();
2034 t1 = tcg_temp_new_i32();
2035 tcg_gen_shl_i32(t0, arg1, arg2);
2036 tcg_gen_subfi_i32(t1, 32, arg2);
2037 tcg_gen_shr_i32(t1, arg1, t1);
2038 tcg_gen_or_i32(ret, t0, t1);
2039 tcg_temp_free_i32(t0);
2040 tcg_temp_free_i32(t1);
2041 }
15824571
AJ
2042}
2043
a7812ae4 2044static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
15824571 2045{
25c4d9cc
RH
2046 if (TCG_TARGET_HAS_rot_i64) {
2047 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
2048 } else {
2049 TCGv_i64 t0, t1;
2050 t0 = tcg_temp_new_i64();
2051 t1 = tcg_temp_new_i64();
2052 tcg_gen_shl_i64(t0, arg1, arg2);
2053 tcg_gen_subfi_i64(t1, 64, arg2);
2054 tcg_gen_shr_i64(t1, arg1, t1);
2055 tcg_gen_or_i64(ret, t0, t1);
2056 tcg_temp_free_i64(t0);
2057 tcg_temp_free_i64(t1);
2058 }
15824571
AJ
2059}
2060
a7812ae4 2061static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
15824571
AJ
2062{
2063 /* some cases can be optimized here */
2064 if (arg2 == 0) {
2065 tcg_gen_mov_i32(ret, arg1);
25c4d9cc 2066 } else if (TCG_TARGET_HAS_rot_i32) {
d42f183c
AJ
2067 TCGv_i32 t0 = tcg_const_i32(arg2);
2068 tcg_gen_rotl_i32(ret, arg1, t0);
2069 tcg_temp_free_i32(t0);
25c4d9cc 2070 } else {
a7812ae4
PB
2071 TCGv_i32 t0, t1;
2072 t0 = tcg_temp_new_i32();
2073 t1 = tcg_temp_new_i32();
15824571
AJ
2074 tcg_gen_shli_i32(t0, arg1, arg2);
2075 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
2076 tcg_gen_or_i32(ret, t0, t1);
a7812ae4
PB
2077 tcg_temp_free_i32(t0);
2078 tcg_temp_free_i32(t1);
15824571
AJ
2079 }
2080}
2081
a7812ae4 2082static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
15824571
AJ
2083{
2084 /* some cases can be optimized here */
2085 if (arg2 == 0) {
2086 tcg_gen_mov_i64(ret, arg1);
25c4d9cc 2087 } else if (TCG_TARGET_HAS_rot_i64) {
d42f183c
AJ
2088 TCGv_i64 t0 = tcg_const_i64(arg2);
2089 tcg_gen_rotl_i64(ret, arg1, t0);
2090 tcg_temp_free_i64(t0);
25c4d9cc 2091 } else {
a7812ae4
PB
2092 TCGv_i64 t0, t1;
2093 t0 = tcg_temp_new_i64();
2094 t1 = tcg_temp_new_i64();
15824571
AJ
2095 tcg_gen_shli_i64(t0, arg1, arg2);
2096 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
2097 tcg_gen_or_i64(ret, t0, t1);
a7812ae4
PB
2098 tcg_temp_free_i64(t0);
2099 tcg_temp_free_i64(t1);
15824571
AJ
2100 }
2101}
2102
a7812ae4 2103static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
15824571 2104{
25c4d9cc
RH
2105 if (TCG_TARGET_HAS_rot_i32) {
2106 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
2107 } else {
2108 TCGv_i32 t0, t1;
15824571 2109
25c4d9cc
RH
2110 t0 = tcg_temp_new_i32();
2111 t1 = tcg_temp_new_i32();
2112 tcg_gen_shr_i32(t0, arg1, arg2);
2113 tcg_gen_subfi_i32(t1, 32, arg2);
2114 tcg_gen_shl_i32(t1, arg1, t1);
2115 tcg_gen_or_i32(ret, t0, t1);
2116 tcg_temp_free_i32(t0);
2117 tcg_temp_free_i32(t1);
2118 }
15824571
AJ
2119}
2120
a7812ae4 2121static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
15824571 2122{
25c4d9cc
RH
2123 if (TCG_TARGET_HAS_rot_i64) {
2124 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
2125 } else {
2126 TCGv_i64 t0, t1;
2127 t0 = tcg_temp_new_i64();
2128 t1 = tcg_temp_new_i64();
2129 tcg_gen_shr_i64(t0, arg1, arg2);
2130 tcg_gen_subfi_i64(t1, 64, arg2);
2131 tcg_gen_shl_i64(t1, arg1, t1);
2132 tcg_gen_or_i64(ret, t0, t1);
2133 tcg_temp_free_i64(t0);
2134 tcg_temp_free_i64(t1);
2135 }
15824571
AJ
2136}
2137
a7812ae4 2138static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
15824571
AJ
2139{
2140 /* some cases can be optimized here */
2141 if (arg2 == 0) {
2142 tcg_gen_mov_i32(ret, arg1);
2143 } else {
2144 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
2145 }
2146}
2147
a7812ae4 2148static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
15824571
AJ
2149{
2150 /* some cases can be optimized here */
2151 if (arg2 == 0) {
de3526b2 2152 tcg_gen_mov_i64(ret, arg1);
15824571
AJ
2153 } else {
2154 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2155 }
2156}
2157
b7767f0f 2158static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
0756e71c
RH
2159 TCGv_i32 arg2, unsigned int ofs,
2160 unsigned int len)
b7767f0f 2161{
df072774
RH
2162 uint32_t mask;
2163 TCGv_i32 t1;
2164
717e7036
RH
2165 tcg_debug_assert(ofs < 32);
2166 tcg_debug_assert(len <= 32);
2167 tcg_debug_assert(ofs + len <= 32);
2168
df072774
RH
2169 if (ofs == 0 && len == 32) {
2170 tcg_gen_mov_i32(ret, arg2);
2171 return;
2172 }
a4773324 2173 if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
25c4d9cc 2174 tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
df072774
RH
2175 return;
2176 }
2177
2178 mask = (1u << len) - 1;
2179 t1 = tcg_temp_new_i32();
b7767f0f 2180
df072774 2181 if (ofs + len < 32) {
25c4d9cc
RH
2182 tcg_gen_andi_i32(t1, arg2, mask);
2183 tcg_gen_shli_i32(t1, t1, ofs);
df072774
RH
2184 } else {
2185 tcg_gen_shli_i32(t1, arg2, ofs);
25c4d9cc 2186 }
df072774
RH
2187 tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
2188 tcg_gen_or_i32(ret, ret, t1);
2189
2190 tcg_temp_free_i32(t1);
b7767f0f
RH
2191}
2192
2193static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
0756e71c
RH
2194 TCGv_i64 arg2, unsigned int ofs,
2195 unsigned int len)
b7767f0f 2196{
df072774
RH
2197 uint64_t mask;
2198 TCGv_i64 t1;
2199
717e7036
RH
2200 tcg_debug_assert(ofs < 64);
2201 tcg_debug_assert(len <= 64);
2202 tcg_debug_assert(ofs + len <= 64);
2203
df072774
RH
2204 if (ofs == 0 && len == 64) {
2205 tcg_gen_mov_i64(ret, arg2);
2206 return;
2207 }
a4773324 2208 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
25c4d9cc 2209 tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
df072774
RH
2210 return;
2211 }
b7767f0f 2212
df072774
RH
2213#if TCG_TARGET_REG_BITS == 32
2214 if (ofs >= 32) {
2215 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2216 TCGV_LOW(arg2), ofs - 32, len);
ed605126 2217 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
df072774
RH
2218 return;
2219 }
2220 if (ofs + len <= 32) {
2221 tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
2222 TCGV_LOW(arg2), ofs, len);
2f98c9db 2223 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
df072774
RH
2224 return;
2225 }
2226#endif
2227
2228 mask = (1ull << len) - 1;
2229 t1 = tcg_temp_new_i64();
2230
2231 if (ofs + len < 64) {
25c4d9cc
RH
2232 tcg_gen_andi_i64(t1, arg2, mask);
2233 tcg_gen_shli_i64(t1, t1, ofs);
df072774
RH
2234 } else {
2235 tcg_gen_shli_i64(t1, arg2, ofs);
25c4d9cc 2236 }
df072774
RH
2237 tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
2238 tcg_gen_or_i64(ret, ret, t1);
2239
2240 tcg_temp_free_i64(t1);
b7767f0f
RH
2241}
2242
77276f65
RH
2243static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
2244 TCGv_i32 high)
2245{
2246#if TCG_TARGET_REG_BITS == 32
2247 tcg_gen_mov_i32(TCGV_LOW(dest), low);
2248 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
2249#else
2250 TCGv_i64 tmp = tcg_temp_new_i64();
2251 /* These extensions are only needed for type correctness.
2252 We may be able to do better given target specific information. */
2253 tcg_gen_extu_i32_i64(tmp, high);
2254 tcg_gen_extu_i32_i64(dest, low);
2255 /* If deposit is available, use it. Otherwise use the extra
2256 knowledge that we have of the zero-extensions above. */
2257 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(32, 32)) {
2258 tcg_gen_deposit_i64(dest, dest, tmp, 32, 32);
2259 } else {
2260 tcg_gen_shli_i64(tmp, tmp, 32);
2261 tcg_gen_or_i64(dest, dest, tmp);
2262 }
2263 tcg_temp_free_i64(tmp);
2264#endif
2265}
2266
2267static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low,
2268 TCGv_i64 high)
2269{
2270 tcg_gen_deposit_i64(dest, low, high, 32, 32);
2271}
2272
3c51a985
RH
2273static inline void tcg_gen_extr_i64_i32(TCGv_i32 lo, TCGv_i32 hi, TCGv_i64 arg)
2274{
2275#if TCG_TARGET_REG_BITS == 32
2276 tcg_gen_mov_i32(lo, TCGV_LOW(arg));
2277 tcg_gen_mov_i32(hi, TCGV_HIGH(arg));
2278#else
2279 TCGv_i64 t0 = tcg_temp_new_i64();
2280 tcg_gen_trunc_i64_i32(lo, arg);
2281 tcg_gen_shri_i64(t0, arg, 32);
2282 tcg_gen_trunc_i64_i32(hi, t0);
2283 tcg_temp_free_i64(t0);
2284#endif
2285}
2286
2287static inline void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)
2288{
2289 tcg_gen_ext32u_i64(lo, arg);
2290 tcg_gen_shri_i64(hi, arg, 32);
2291}
2292
ffc5ea09
RH
2293static inline void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret,
2294 TCGv_i32 c1, TCGv_i32 c2,
2295 TCGv_i32 v1, TCGv_i32 v2)
2296{
2297 if (TCG_TARGET_HAS_movcond_i32) {
2298 tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond);
2299 } else {
2300 TCGv_i32 t0 = tcg_temp_new_i32();
2301 TCGv_i32 t1 = tcg_temp_new_i32();
2302 tcg_gen_setcond_i32(cond, t0, c1, c2);
2303 tcg_gen_neg_i32(t0, t0);
2304 tcg_gen_and_i32(t1, v1, t0);
2305 tcg_gen_andc_i32(ret, v2, t0);
2306 tcg_gen_or_i32(ret, ret, t1);
2307 tcg_temp_free_i32(t0);
2308 tcg_temp_free_i32(t1);
2309 }
2310}
2311
2312static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
2313 TCGv_i64 c1, TCGv_i64 c2,
2314 TCGv_i64 v1, TCGv_i64 v2)
2315{
a463133e
RH
2316#if TCG_TARGET_REG_BITS == 32
2317 TCGv_i32 t0 = tcg_temp_new_i32();
2318 TCGv_i32 t1 = tcg_temp_new_i32();
2319 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
2320 TCGV_LOW(c1), TCGV_HIGH(c1),
2321 TCGV_LOW(c2), TCGV_HIGH(c2), cond);
a463133e 2322
a80a6b63
RH
2323 if (TCG_TARGET_HAS_movcond_i32) {
2324 tcg_gen_movi_i32(t1, 0);
2325 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
2326 TCGV_LOW(v1), TCGV_LOW(v2));
2327 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
2328 TCGV_HIGH(v1), TCGV_HIGH(v2));
2329 } else {
2330 tcg_gen_neg_i32(t0, t0);
a463133e 2331
a80a6b63
RH
2332 tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
2333 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
2334 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
a463133e 2335
a80a6b63
RH
2336 tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
2337 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
2338 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
2339 }
a463133e
RH
2340 tcg_temp_free_i32(t0);
2341 tcg_temp_free_i32(t1);
2342#else
ffc5ea09
RH
2343 if (TCG_TARGET_HAS_movcond_i64) {
2344 tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond);
2345 } else {
2346 TCGv_i64 t0 = tcg_temp_new_i64();
2347 TCGv_i64 t1 = tcg_temp_new_i64();
2348 tcg_gen_setcond_i64(cond, t0, c1, c2);
2349 tcg_gen_neg_i64(t0, t0);
2350 tcg_gen_and_i64(t1, v1, t0);
2351 tcg_gen_andc_i64(ret, v2, t0);
2352 tcg_gen_or_i64(ret, ret, t1);
2353 tcg_temp_free_i64(t0);
2354 tcg_temp_free_i64(t1);
2355 }
a463133e 2356#endif
ffc5ea09
RH
2357}
2358
f6953a73
RH
2359static inline void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2360 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2361{
2362 if (TCG_TARGET_HAS_add2_i32) {
2363 tcg_gen_op6_i32(INDEX_op_add2_i32, rl, rh, al, ah, bl, bh);
2364 /* Allow the optimizer room to replace add2 with two moves. */
2365 tcg_gen_op0(INDEX_op_nop);
2366 } else {
2367 TCGv_i64 t0 = tcg_temp_new_i64();
2368 TCGv_i64 t1 = tcg_temp_new_i64();
2369 tcg_gen_concat_i32_i64(t0, al, ah);
2370 tcg_gen_concat_i32_i64(t1, bl, bh);
2371 tcg_gen_add_i64(t0, t0, t1);
2372 tcg_gen_extr_i64_i32(rl, rh, t0);
2373 tcg_temp_free_i64(t0);
2374 tcg_temp_free_i64(t1);
2375 }
2376}
2377
2378static inline void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2379 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2380{
2381 if (TCG_TARGET_HAS_sub2_i32) {
2382 tcg_gen_op6_i32(INDEX_op_sub2_i32, rl, rh, al, ah, bl, bh);
2383 /* Allow the optimizer room to replace sub2 with two moves. */
2384 tcg_gen_op0(INDEX_op_nop);
2385 } else {
2386 TCGv_i64 t0 = tcg_temp_new_i64();
2387 TCGv_i64 t1 = tcg_temp_new_i64();
2388 tcg_gen_concat_i32_i64(t0, al, ah);
2389 tcg_gen_concat_i32_i64(t1, bl, bh);
2390 tcg_gen_sub_i64(t0, t0, t1);
2391 tcg_gen_extr_i64_i32(rl, rh, t0);
2392 tcg_temp_free_i64(t0);
2393 tcg_temp_free_i64(t1);
2394 }
2395}
2396
696a8be6
RH
2397static inline void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh,
2398 TCGv_i32 arg1, TCGv_i32 arg2)
2399{
2400 if (TCG_TARGET_HAS_mulu2_i32) {
2401 tcg_gen_op4_i32(INDEX_op_mulu2_i32, rl, rh, arg1, arg2);
2402 /* Allow the optimizer room to replace mulu2 with two moves. */
2403 tcg_gen_op0(INDEX_op_nop);
2404 } else {
2405 TCGv_i64 t0 = tcg_temp_new_i64();
2406 TCGv_i64 t1 = tcg_temp_new_i64();
2407 tcg_gen_extu_i32_i64(t0, arg1);
2408 tcg_gen_extu_i32_i64(t1, arg2);
2409 tcg_gen_mul_i64(t0, t0, t1);
2410 tcg_gen_extr_i64_i32(rl, rh, t0);
2411 tcg_temp_free_i64(t0);
2412 tcg_temp_free_i64(t1);
2413 }
2414}
2415
2416static inline void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh,
2417 TCGv_i32 arg1, TCGv_i32 arg2)
2418{
2419 if (TCG_TARGET_HAS_muls2_i32) {
2420 tcg_gen_op4_i32(INDEX_op_muls2_i32, rl, rh, arg1, arg2);
2421 /* Allow the optimizer room to replace muls2 with two moves. */
2422 tcg_gen_op0(INDEX_op_nop);
f402f38f
RH
2423 } else if (TCG_TARGET_REG_BITS == 32 && TCG_TARGET_HAS_mulu2_i32) {
2424 TCGv_i32 t0 = tcg_temp_new_i32();
2425 TCGv_i32 t1 = tcg_temp_new_i32();
2426 TCGv_i32 t2 = tcg_temp_new_i32();
2427 TCGv_i32 t3 = tcg_temp_new_i32();
2428 tcg_gen_op4_i32(INDEX_op_mulu2_i32, t0, t1, arg1, arg2);
2429 /* Allow the optimizer room to replace mulu2 with two moves. */
2430 tcg_gen_op0(INDEX_op_nop);
2431 /* Adjust for negative inputs. */
2432 tcg_gen_sari_i32(t2, arg1, 31);
2433 tcg_gen_sari_i32(t3, arg2, 31);
2434 tcg_gen_and_i32(t2, t2, arg2);
2435 tcg_gen_and_i32(t3, t3, arg1);
2436 tcg_gen_sub_i32(rh, t1, t2);
2437 tcg_gen_sub_i32(rh, rh, t3);
2438 tcg_gen_mov_i32(rl, t0);
2439 tcg_temp_free_i32(t0);
2440 tcg_temp_free_i32(t1);
2441 tcg_temp_free_i32(t2);
2442 tcg_temp_free_i32(t3);
696a8be6
RH
2443 } else {
2444 TCGv_i64 t0 = tcg_temp_new_i64();
2445 TCGv_i64 t1 = tcg_temp_new_i64();
2446 tcg_gen_ext_i32_i64(t0, arg1);
2447 tcg_gen_ext_i32_i64(t1, arg2);
2448 tcg_gen_mul_i64(t0, t0, t1);
2449 tcg_gen_extr_i64_i32(rl, rh, t0);
2450 tcg_temp_free_i64(t0);
2451 tcg_temp_free_i64(t1);
2452 }
2453}
2454
f6953a73
RH
2455static inline void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2456 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2457{
2458 if (TCG_TARGET_HAS_add2_i64) {
2459 tcg_gen_op6_i64(INDEX_op_add2_i64, rl, rh, al, ah, bl, bh);
2460 /* Allow the optimizer room to replace add2 with two moves. */
2461 tcg_gen_op0(INDEX_op_nop);
2462 } else {
2463 TCGv_i64 t0 = tcg_temp_new_i64();
2464 TCGv_i64 t1 = tcg_temp_new_i64();
2465 tcg_gen_add_i64(t0, al, bl);
2466 tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, al);
2467 tcg_gen_add_i64(rh, ah, bh);
2468 tcg_gen_add_i64(rh, rh, t1);
2469 tcg_gen_mov_i64(rl, t0);
2470 tcg_temp_free_i64(t0);
2471 tcg_temp_free_i64(t1);
2472 }
2473}
2474
2475static inline void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2476 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2477{
2478 if (TCG_TARGET_HAS_sub2_i64) {
2479 tcg_gen_op6_i64(INDEX_op_sub2_i64, rl, rh, al, ah, bl, bh);
2480 /* Allow the optimizer room to replace sub2 with two moves. */
2481 tcg_gen_op0(INDEX_op_nop);
2482 } else {
2483 TCGv_i64 t0 = tcg_temp_new_i64();
2484 TCGv_i64 t1 = tcg_temp_new_i64();
2485 tcg_gen_sub_i64(t0, al, bl);
2486 tcg_gen_setcond_i64(TCG_COND_LTU, t1, al, bl);
2487 tcg_gen_sub_i64(rh, ah, bh);
2488 tcg_gen_sub_i64(rh, rh, t1);
2489 tcg_gen_mov_i64(rl, t0);
2490 tcg_temp_free_i64(t0);
2491 tcg_temp_free_i64(t1);
2492 }
2493}
2494
696a8be6
RH
2495static inline void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh,
2496 TCGv_i64 arg1, TCGv_i64 arg2)
2497{
2498 if (TCG_TARGET_HAS_mulu2_i64) {
2499 tcg_gen_op4_i64(INDEX_op_mulu2_i64, rl, rh, arg1, arg2);
2500 /* Allow the optimizer room to replace mulu2 with two moves. */
2501 tcg_gen_op0(INDEX_op_nop);
f402f38f
RH
2502 } else if (TCG_TARGET_HAS_mulu2_i64) {
2503 TCGv_i64 t0 = tcg_temp_new_i64();
2504 TCGv_i64 t1 = tcg_temp_new_i64();
2505 TCGv_i64 t2 = tcg_temp_new_i64();
2506 TCGv_i64 t3 = tcg_temp_new_i64();
2507 tcg_gen_op4_i64(INDEX_op_mulu2_i64, t0, t1, arg1, arg2);
2508 /* Allow the optimizer room to replace mulu2 with two moves. */
2509 tcg_gen_op0(INDEX_op_nop);
2510 /* Adjust for negative inputs. */
2511 tcg_gen_sari_i64(t2, arg1, 63);
2512 tcg_gen_sari_i64(t3, arg2, 63);
2513 tcg_gen_and_i64(t2, t2, arg2);
2514 tcg_gen_and_i64(t3, t3, arg1);
2515 tcg_gen_sub_i64(rh, t1, t2);
2516 tcg_gen_sub_i64(rh, rh, t3);
2517 tcg_gen_mov_i64(rl, t0);
2518 tcg_temp_free_i64(t0);
2519 tcg_temp_free_i64(t1);
2520 tcg_temp_free_i64(t2);
2521 tcg_temp_free_i64(t3);
696a8be6
RH
2522 } else {
2523 TCGv_i64 t0 = tcg_temp_new_i64();
2524 int sizemask = 0;
2525 /* Return value and both arguments are 64-bit and unsigned. */
2526 sizemask |= tcg_gen_sizemask(0, 1, 0);
2527 sizemask |= tcg_gen_sizemask(1, 1, 0);
2528 sizemask |= tcg_gen_sizemask(2, 1, 0);
2529 tcg_gen_mul_i64(t0, arg1, arg2);
2530 tcg_gen_helper64(tcg_helper_muluh_i64, sizemask, rh, arg1, arg2);
2531 tcg_gen_mov_i64(rl, t0);
2532 tcg_temp_free_i64(t0);
2533 }
2534}
2535
2536static inline void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh,
2537 TCGv_i64 arg1, TCGv_i64 arg2)
2538{
2539 if (TCG_TARGET_HAS_muls2_i64) {
2540 tcg_gen_op4_i64(INDEX_op_muls2_i64, rl, rh, arg1, arg2);
2541 /* Allow the optimizer room to replace muls2 with two moves. */
2542 tcg_gen_op0(INDEX_op_nop);
2543 } else {
2544 TCGv_i64 t0 = tcg_temp_new_i64();
2545 int sizemask = 0;
2546 /* Return value and both arguments are 64-bit and signed. */
2547 sizemask |= tcg_gen_sizemask(0, 1, 1);
2548 sizemask |= tcg_gen_sizemask(1, 1, 1);
2549 sizemask |= tcg_gen_sizemask(2, 1, 1);
2550 tcg_gen_mul_i64(t0, arg1, arg2);
2551 tcg_gen_helper64(tcg_helper_mulsh_i64, sizemask, rh, arg1, arg2);
2552 tcg_gen_mov_i64(rl, t0);
2553 tcg_temp_free_i64(t0);
2554 }
2555}
2556
c896fe29
FB
2557/***************************************/
2558/* QEMU specific operations. Their type depend on the QEMU CPU
2559 type. */
2560#ifndef TARGET_LONG_BITS
2561#error must include QEMU headers
2562#endif
2563
a7812ae4
PB
2564#if TARGET_LONG_BITS == 32
2565#define TCGv TCGv_i32
2566#define tcg_temp_new() tcg_temp_new_i32()
2567#define tcg_global_reg_new tcg_global_reg_new_i32
2568#define tcg_global_mem_new tcg_global_mem_new_i32
df9247b2 2569#define tcg_temp_local_new() tcg_temp_local_new_i32()
a7812ae4
PB
2570#define tcg_temp_free tcg_temp_free_i32
2571#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
2572#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
2573#define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
afcb92be 2574#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I32(x)
fe75bcf7 2575#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
a7812ae4
PB
2576#else
2577#define TCGv TCGv_i64
2578#define tcg_temp_new() tcg_temp_new_i64()
2579#define tcg_global_reg_new tcg_global_reg_new_i64
2580#define tcg_global_mem_new tcg_global_mem_new_i64
df9247b2 2581#define tcg_temp_local_new() tcg_temp_local_new_i64()
a7812ae4
PB
2582#define tcg_temp_free tcg_temp_free_i64
2583#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
2584#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
2585#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
afcb92be 2586#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I64(x)
fe75bcf7 2587#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
a7812ae4
PB
2588#endif
2589
7e4597d7
FB
2590/* debug info: write the PC of the corresponding QEMU CPU instruction */
2591static inline void tcg_gen_debug_insn_start(uint64_t pc)
2592{
2593 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2594#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
bcb0126f
PB
2595 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2596 (uint32_t)(pc), (uint32_t)(pc >> 32));
7e4597d7
FB
2597#else
2598 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2599#endif
2600}
2601
c896fe29
FB
2602static inline void tcg_gen_exit_tb(tcg_target_long val)
2603{
ac56dd48 2604 tcg_gen_op1i(INDEX_op_exit_tb, val);
c896fe29
FB
2605}
2606
0a209d4b
RH
2607static inline void tcg_gen_goto_tb(unsigned idx)
2608{
2609 /* We only support two chained exits. */
2610 tcg_debug_assert(idx <= 1);
2611#ifdef CONFIG_DEBUG_TCG
2612 /* Verify that we havn't seen this numbered exit before. */
2613 tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
2614 tcg_ctx.goto_tb_issue_mask |= 1 << idx;
2615#endif
ac56dd48 2616 tcg_gen_op1i(INDEX_op_goto_tb, idx);
c896fe29
FB
2617}
2618
2619#if TCG_TARGET_REG_BITS == 32
ac56dd48 2620static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2621{
2622#if TARGET_LONG_BITS == 32
a7812ae4 2623 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29 2624#else
a7812ae4
PB
2625 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
2626 TCGV_HIGH(addr), mem_index);
ac56dd48 2627 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2628#endif
2629}
2630
ac56dd48 2631static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2632{
2633#if TARGET_LONG_BITS == 32
a7812ae4 2634 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29 2635#else
a7812ae4
PB
2636 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
2637 TCGV_HIGH(addr), mem_index);
2638 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2639#endif
2640}
2641
ac56dd48 2642static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2643{
2644#if TARGET_LONG_BITS == 32
a7812ae4 2645 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29 2646#else
a7812ae4
PB
2647 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
2648 TCGV_HIGH(addr), mem_index);
ac56dd48 2649 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2650#endif
2651}
2652
ac56dd48 2653static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2654{
2655#if TARGET_LONG_BITS == 32
a7812ae4 2656 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29 2657#else
a7812ae4
PB
2658 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
2659 TCGV_HIGH(addr), mem_index);
2660 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2661#endif
2662}
2663
ac56dd48 2664static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2665{
2666#if TARGET_LONG_BITS == 32
86feb1c8 2667 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
c896fe29 2668#else
86feb1c8 2669 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
a7812ae4 2670 TCGV_HIGH(addr), mem_index);
ac56dd48 2671 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
2672#endif
2673}
2674
ac56dd48 2675static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29
FB
2676{
2677#if TARGET_LONG_BITS == 32
86feb1c8 2678 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
c896fe29 2679#else
86feb1c8 2680 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
a7812ae4
PB
2681 TCGV_HIGH(addr), mem_index);
2682 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
2683#endif
2684}
2685
a7812ae4 2686static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
c896fe29
FB
2687{
2688#if TARGET_LONG_BITS == 32
a7812ae4 2689 tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
c896fe29 2690#else
a7812ae4
PB
2691 tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
2692 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
c896fe29
FB
2693#endif
2694}
2695
ac56dd48 2696static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2697{
2698#if TARGET_LONG_BITS == 32
a7812ae4 2699 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29 2700#else
a7812ae4
PB
2701 tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
2702 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2703#endif
2704}
2705
ac56dd48 2706static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2707{
2708#if TARGET_LONG_BITS == 32
a7812ae4 2709 tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29 2710#else
a7812ae4
PB
2711 tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
2712 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2713#endif
2714}
2715
ac56dd48 2716static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29
FB
2717{
2718#if TARGET_LONG_BITS == 32
a7812ae4 2719 tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29 2720#else
a7812ae4
PB
2721 tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
2722 TCGV_HIGH(addr), mem_index);
c896fe29
FB
2723#endif
2724}
2725
a7812ae4 2726static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
c896fe29
FB
2727{
2728#if TARGET_LONG_BITS == 32
a7812ae4
PB
2729 tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
2730 mem_index);
c896fe29 2731#else
a7812ae4
PB
2732 tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
2733 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
c896fe29
FB
2734#endif
2735}
2736
ebecf363
PM
2737#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2738#define tcg_gen_discard_ptr(A) tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
f8422f52 2739
c896fe29
FB
2740#else /* TCG_TARGET_REG_BITS == 32 */
2741
ac56dd48 2742static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2743{
a7812ae4 2744 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
c896fe29
FB
2745}
2746
ac56dd48 2747static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2748{
a7812ae4 2749 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
c896fe29
FB
2750}
2751
ac56dd48 2752static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2753{
a7812ae4 2754 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
c896fe29
FB
2755}
2756
ac56dd48 2757static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2758{
a7812ae4 2759 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
c896fe29
FB
2760}
2761
ac56dd48 2762static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2763{
3e1dbadd
RH
2764#if TARGET_LONG_BITS == 32
2765 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2766#else
a7812ae4 2767 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
3e1dbadd 2768#endif
c896fe29
FB
2769}
2770
ac56dd48 2771static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2772{
3e1dbadd
RH
2773#if TARGET_LONG_BITS == 32
2774 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2775#else
a7812ae4 2776 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
3e1dbadd 2777#endif
c896fe29
FB
2778}
2779
a7812ae4 2780static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
c896fe29 2781{
a7812ae4 2782 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
c896fe29
FB
2783}
2784
ac56dd48 2785static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29 2786{
a7812ae4 2787 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
c896fe29
FB
2788}
2789
ac56dd48 2790static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29 2791{
a7812ae4 2792 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
c896fe29
FB
2793}
2794
ac56dd48 2795static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29 2796{
a7812ae4 2797 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
c896fe29
FB
2798}
2799
a7812ae4 2800static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
c896fe29 2801{
a7812ae4 2802 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
c896fe29
FB
2803}
2804
ebecf363
PM
2805#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2806#define tcg_gen_discard_ptr(A) tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
f8422f52 2807
c896fe29 2808#endif /* TCG_TARGET_REG_BITS != 32 */
f8422f52
BS
2809
2810#if TARGET_LONG_BITS == 64
f8422f52
BS
2811#define tcg_gen_movi_tl tcg_gen_movi_i64
2812#define tcg_gen_mov_tl tcg_gen_mov_i64
2813#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2814#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2815#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2816#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2817#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2818#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2819#define tcg_gen_ld_tl tcg_gen_ld_i64
2820#define tcg_gen_st8_tl tcg_gen_st8_i64
2821#define tcg_gen_st16_tl tcg_gen_st16_i64
2822#define tcg_gen_st32_tl tcg_gen_st32_i64
2823#define tcg_gen_st_tl tcg_gen_st_i64
2824#define tcg_gen_add_tl tcg_gen_add_i64
2825#define tcg_gen_addi_tl tcg_gen_addi_i64
2826#define tcg_gen_sub_tl tcg_gen_sub_i64
390efc54 2827#define tcg_gen_neg_tl tcg_gen_neg_i64
10460c8a 2828#define tcg_gen_subfi_tl tcg_gen_subfi_i64
f8422f52
BS
2829#define tcg_gen_subi_tl tcg_gen_subi_i64
2830#define tcg_gen_and_tl tcg_gen_and_i64
2831#define tcg_gen_andi_tl tcg_gen_andi_i64
2832#define tcg_gen_or_tl tcg_gen_or_i64
2833#define tcg_gen_ori_tl tcg_gen_ori_i64
2834#define tcg_gen_xor_tl tcg_gen_xor_i64
2835#define tcg_gen_xori_tl tcg_gen_xori_i64
0b6ce4cf 2836#define tcg_gen_not_tl tcg_gen_not_i64
f8422f52
BS
2837#define tcg_gen_shl_tl tcg_gen_shl_i64
2838#define tcg_gen_shli_tl tcg_gen_shli_i64
2839#define tcg_gen_shr_tl tcg_gen_shr_i64
2840#define tcg_gen_shri_tl tcg_gen_shri_i64
2841#define tcg_gen_sar_tl tcg_gen_sar_i64
2842#define tcg_gen_sari_tl tcg_gen_sari_i64
0cf767d6 2843#define tcg_gen_brcond_tl tcg_gen_brcond_i64
cb63669a 2844#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
be210acb 2845#define tcg_gen_setcond_tl tcg_gen_setcond_i64
add1e7ea 2846#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
f730fd27
TS
2847#define tcg_gen_mul_tl tcg_gen_mul_i64
2848#define tcg_gen_muli_tl tcg_gen_muli_i64
ab36421e
AJ
2849#define tcg_gen_div_tl tcg_gen_div_i64
2850#define tcg_gen_rem_tl tcg_gen_rem_i64
864951af
AJ
2851#define tcg_gen_divu_tl tcg_gen_divu_i64
2852#define tcg_gen_remu_tl tcg_gen_remu_i64
a768e4b2 2853#define tcg_gen_discard_tl tcg_gen_discard_i64
e429073d
BS
2854#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2855#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2856#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2857#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2858#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2859#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
0b6ce4cf
FB
2860#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2861#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2862#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2863#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2864#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2865#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
911d79ba
AJ
2866#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2867#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2868#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
945ca823 2869#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
3c51a985 2870#define tcg_gen_extr_i64_tl tcg_gen_extr32_i64
f24cb33e
AJ
2871#define tcg_gen_andc_tl tcg_gen_andc_i64
2872#define tcg_gen_eqv_tl tcg_gen_eqv_i64
2873#define tcg_gen_nand_tl tcg_gen_nand_i64
2874#define tcg_gen_nor_tl tcg_gen_nor_i64
2875#define tcg_gen_orc_tl tcg_gen_orc_i64
15824571
AJ
2876#define tcg_gen_rotl_tl tcg_gen_rotl_i64
2877#define tcg_gen_rotli_tl tcg_gen_rotli_i64
2878#define tcg_gen_rotr_tl tcg_gen_rotr_i64
2879#define tcg_gen_rotri_tl tcg_gen_rotri_i64
b7767f0f 2880#define tcg_gen_deposit_tl tcg_gen_deposit_i64
a98824ac 2881#define tcg_const_tl tcg_const_i64
bdffd4a9 2882#define tcg_const_local_tl tcg_const_local_i64
ffc5ea09 2883#define tcg_gen_movcond_tl tcg_gen_movcond_i64
f6953a73
RH
2884#define tcg_gen_add2_tl tcg_gen_add2_i64
2885#define tcg_gen_sub2_tl tcg_gen_sub2_i64
696a8be6
RH
2886#define tcg_gen_mulu2_tl tcg_gen_mulu2_i64
2887#define tcg_gen_muls2_tl tcg_gen_muls2_i64
f8422f52 2888#else
f8422f52
BS
2889#define tcg_gen_movi_tl tcg_gen_movi_i32
2890#define tcg_gen_mov_tl tcg_gen_mov_i32
2891#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2892#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2893#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2894#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2895#define tcg_gen_ld32u_tl tcg_gen_ld_i32
2896#define tcg_gen_ld32s_tl tcg_gen_ld_i32
2897#define tcg_gen_ld_tl tcg_gen_ld_i32
2898#define tcg_gen_st8_tl tcg_gen_st8_i32
2899#define tcg_gen_st16_tl tcg_gen_st16_i32
2900#define tcg_gen_st32_tl tcg_gen_st_i32
2901#define tcg_gen_st_tl tcg_gen_st_i32
2902#define tcg_gen_add_tl tcg_gen_add_i32
2903#define tcg_gen_addi_tl tcg_gen_addi_i32
2904#define tcg_gen_sub_tl tcg_gen_sub_i32
390efc54 2905#define tcg_gen_neg_tl tcg_gen_neg_i32
0045734a 2906#define tcg_gen_subfi_tl tcg_gen_subfi_i32
f8422f52
BS
2907#define tcg_gen_subi_tl tcg_gen_subi_i32
2908#define tcg_gen_and_tl tcg_gen_and_i32
2909#define tcg_gen_andi_tl tcg_gen_andi_i32
2910#define tcg_gen_or_tl tcg_gen_or_i32
2911#define tcg_gen_ori_tl tcg_gen_ori_i32
2912#define tcg_gen_xor_tl tcg_gen_xor_i32
2913#define tcg_gen_xori_tl tcg_gen_xori_i32
0b6ce4cf 2914#define tcg_gen_not_tl tcg_gen_not_i32
f8422f52
BS
2915#define tcg_gen_shl_tl tcg_gen_shl_i32
2916#define tcg_gen_shli_tl tcg_gen_shli_i32
2917#define tcg_gen_shr_tl tcg_gen_shr_i32
2918#define tcg_gen_shri_tl tcg_gen_shri_i32
2919#define tcg_gen_sar_tl tcg_gen_sar_i32
2920#define tcg_gen_sari_tl tcg_gen_sari_i32
0cf767d6 2921#define tcg_gen_brcond_tl tcg_gen_brcond_i32
cb63669a 2922#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
be210acb 2923#define tcg_gen_setcond_tl tcg_gen_setcond_i32
add1e7ea 2924#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
f730fd27
TS
2925#define tcg_gen_mul_tl tcg_gen_mul_i32
2926#define tcg_gen_muli_tl tcg_gen_muli_i32
ab36421e
AJ
2927#define tcg_gen_div_tl tcg_gen_div_i32
2928#define tcg_gen_rem_tl tcg_gen_rem_i32
864951af
AJ
2929#define tcg_gen_divu_tl tcg_gen_divu_i32
2930#define tcg_gen_remu_tl tcg_gen_remu_i32
a768e4b2 2931#define tcg_gen_discard_tl tcg_gen_discard_i32
e429073d
BS
2932#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2933#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2934#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2935#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2936#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2937#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
0b6ce4cf
FB
2938#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2939#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2940#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2941#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2942#define tcg_gen_ext32u_tl tcg_gen_mov_i32
2943#define tcg_gen_ext32s_tl tcg_gen_mov_i32
911d79ba
AJ
2944#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2945#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
945ca823 2946#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
3c51a985 2947#define tcg_gen_extr_tl_i64 tcg_gen_extr_i32_i64
f24cb33e
AJ
2948#define tcg_gen_andc_tl tcg_gen_andc_i32
2949#define tcg_gen_eqv_tl tcg_gen_eqv_i32
2950#define tcg_gen_nand_tl tcg_gen_nand_i32
2951#define tcg_gen_nor_tl tcg_gen_nor_i32
2952#define tcg_gen_orc_tl tcg_gen_orc_i32
15824571
AJ
2953#define tcg_gen_rotl_tl tcg_gen_rotl_i32
2954#define tcg_gen_rotli_tl tcg_gen_rotli_i32
2955#define tcg_gen_rotr_tl tcg_gen_rotr_i32
2956#define tcg_gen_rotri_tl tcg_gen_rotri_i32
b7767f0f 2957#define tcg_gen_deposit_tl tcg_gen_deposit_i32
a98824ac 2958#define tcg_const_tl tcg_const_i32
bdffd4a9 2959#define tcg_const_local_tl tcg_const_local_i32
ffc5ea09 2960#define tcg_gen_movcond_tl tcg_gen_movcond_i32
f6953a73
RH
2961#define tcg_gen_add2_tl tcg_gen_add2_i32
2962#define tcg_gen_sub2_tl tcg_gen_sub2_i32
696a8be6
RH
2963#define tcg_gen_mulu2_tl tcg_gen_mulu2_i32
2964#define tcg_gen_muls2_tl tcg_gen_muls2_i32
f8422f52 2965#endif
6ddbc6e4
PB
2966
2967#if TCG_TARGET_REG_BITS == 32
ebecf363
PM
2968#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), \
2969 TCGV_PTR_TO_NAT(A), \
2970 TCGV_PTR_TO_NAT(B))
2971#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), \
2972 TCGV_PTR_TO_NAT(A), (B))
2973#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
6ddbc6e4 2974#else /* TCG_TARGET_REG_BITS == 32 */
ebecf363
PM
2975#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), \
2976 TCGV_PTR_TO_NAT(A), \
2977 TCGV_PTR_TO_NAT(B))
2978#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), \
2979 TCGV_PTR_TO_NAT(A), (B))
2980#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
6ddbc6e4 2981#endif /* TCG_TARGET_REG_BITS != 32 */