]> Git Repo - qemu.git/blame - tcg/tcg-op.h
tcg: Push tcg-runtime routines into exec/helper-*
[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"
944eea96 25#include "exec/helper-proto.h"
c896fe29 26
c896fe29
FB
27int gen_new_label(void);
28
212c328d
RH
29static inline void tcg_gen_op0(TCGOpcode opc)
30{
efd7f486 31 *tcg_ctx.gen_opc_ptr++ = opc;
212c328d
RH
32}
33
a9751609 34static inline void tcg_gen_op1_i32(TCGOpcode opc, TCGv_i32 arg1)
c896fe29 35{
efd7f486 36 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4 37 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
a7812ae4
PB
38}
39
a9751609 40static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
a7812ae4 41{
efd7f486 42 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4 43 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
c896fe29
FB
44}
45
a9751609 46static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg arg1)
c896fe29 47{
efd7f486 48 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4 49 *tcg_ctx.gen_opparam_ptr++ = arg1;
c896fe29
FB
50}
51
a9751609 52static inline void tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2)
a7812ae4 53{
efd7f486 54 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
55 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
56 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
a7812ae4
PB
57}
58
a9751609 59static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
a7812ae4 60{
efd7f486 61 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
62 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
63 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
a7812ae4
PB
64}
65
a9751609 66static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
c896fe29 67{
efd7f486 68 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
69 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
70 *tcg_ctx.gen_opparam_ptr++ = arg2;
c896fe29
FB
71}
72
a9751609 73static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
c896fe29 74{
efd7f486 75 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
76 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
77 *tcg_ctx.gen_opparam_ptr++ = arg2;
ac56dd48
PB
78}
79
a9751609 80static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg arg1, TCGArg arg2)
bcb0126f 81{
efd7f486 82 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
83 *tcg_ctx.gen_opparam_ptr++ = arg1;
84 *tcg_ctx.gen_opparam_ptr++ = arg2;
bcb0126f
PB
85}
86
a9751609 87static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
88 TCGv_i32 arg3)
89{
efd7f486 90 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
91 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
92 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
93 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
a7812ae4
PB
94}
95
a9751609 96static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4
PB
97 TCGv_i64 arg3)
98{
efd7f486 99 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
100 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
101 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
102 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
a7812ae4
PB
103}
104
a9751609
RH
105static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
106 TCGv_i32 arg2, TCGArg arg3)
ac56dd48 107{
efd7f486 108 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
109 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
110 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
111 *tcg_ctx.gen_opparam_ptr++ = arg3;
ac56dd48
PB
112}
113
a9751609
RH
114static inline void tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 arg1,
115 TCGv_i64 arg2, TCGArg arg3)
ac56dd48 116{
efd7f486 117 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
118 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
119 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
120 *tcg_ctx.gen_opparam_ptr++ = arg3;
ac56dd48
PB
121}
122
a9751609
RH
123static inline void tcg_gen_ldst_op_i32(TCGOpcode opc, TCGv_i32 val,
124 TCGv_ptr base, TCGArg offset)
a7812ae4 125{
efd7f486 126 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
127 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(val);
128 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_PTR(base);
129 *tcg_ctx.gen_opparam_ptr++ = offset;
a7812ae4
PB
130}
131
a9751609
RH
132static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
133 TCGv_ptr base, TCGArg offset)
a7812ae4 134{
efd7f486 135 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
136 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
137 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_PTR(base);
138 *tcg_ctx.gen_opparam_ptr++ = offset;
a7812ae4
PB
139}
140
a9751609 141static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
142 TCGv_i32 arg3, TCGv_i32 arg4)
143{
efd7f486 144 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
145 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
146 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
147 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
148 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
a7812ae4
PB
149}
150
a9751609 151static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a810a2de 152 TCGv_i64 arg3, TCGv_i64 arg4)
a7812ae4 153{
efd7f486 154 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
155 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
156 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
157 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
158 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
a7812ae4
PB
159}
160
a9751609 161static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
162 TCGv_i32 arg3, TCGArg arg4)
163{
efd7f486 164 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
165 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
166 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
167 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
168 *tcg_ctx.gen_opparam_ptr++ = arg4;
a7812ae4
PB
169}
170
a9751609 171static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4 172 TCGv_i64 arg3, TCGArg arg4)
ac56dd48 173{
efd7f486 174 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
175 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
176 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
177 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
178 *tcg_ctx.gen_opparam_ptr++ = arg4;
ac56dd48
PB
179}
180
a9751609 181static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4 182 TCGArg arg3, TCGArg arg4)
ac56dd48 183{
efd7f486 184 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
185 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
186 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
187 *tcg_ctx.gen_opparam_ptr++ = arg3;
188 *tcg_ctx.gen_opparam_ptr++ = arg4;
c896fe29
FB
189}
190
a9751609 191static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4 192 TCGArg arg3, TCGArg arg4)
c896fe29 193{
efd7f486 194 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
195 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
196 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
197 *tcg_ctx.gen_opparam_ptr++ = arg3;
198 *tcg_ctx.gen_opparam_ptr++ = arg4;
ac56dd48
PB
199}
200
a9751609 201static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
202 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
203{
efd7f486 204 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
205 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
206 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
207 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
208 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
209 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
a7812ae4
PB
210}
211
a9751609 212static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4
PB
213 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
214{
efd7f486 215 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
216 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
217 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
218 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
219 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
220 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
a7812ae4
PB
221}
222
a9751609 223static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4 224 TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
ac56dd48 225{
efd7f486 226 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
227 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
228 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
229 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
230 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
231 *tcg_ctx.gen_opparam_ptr++ = arg5;
ac56dd48
PB
232}
233
a9751609 234static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4 235 TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
ac56dd48 236{
efd7f486 237 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
238 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
239 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
240 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
241 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
242 *tcg_ctx.gen_opparam_ptr++ = arg5;
c896fe29
FB
243}
244
b7767f0f
RH
245static inline void tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 arg1,
246 TCGv_i32 arg2, TCGv_i32 arg3,
247 TCGArg arg4, TCGArg arg5)
248{
efd7f486 249 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
250 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
251 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
252 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
253 *tcg_ctx.gen_opparam_ptr++ = arg4;
254 *tcg_ctx.gen_opparam_ptr++ = arg5;
b7767f0f
RH
255}
256
257static inline void tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 arg1,
258 TCGv_i64 arg2, TCGv_i64 arg3,
259 TCGArg arg4, TCGArg arg5)
260{
efd7f486 261 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
262 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
263 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
264 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
265 *tcg_ctx.gen_opparam_ptr++ = arg4;
266 *tcg_ctx.gen_opparam_ptr++ = arg5;
b7767f0f
RH
267}
268
a9751609 269static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
a7812ae4
PB
270 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
271 TCGv_i32 arg6)
272{
efd7f486 273 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
274 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
275 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
276 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
277 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
278 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
279 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg6);
a7812ae4
PB
280}
281
a9751609 282static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
a7812ae4
PB
283 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
284 TCGv_i64 arg6)
c896fe29 285{
efd7f486 286 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
287 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
288 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
289 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
290 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
291 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
292 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg6);
ac56dd48
PB
293}
294
a9751609 295static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
be210acb
RH
296 TCGv_i32 arg3, TCGv_i32 arg4,
297 TCGv_i32 arg5, TCGArg arg6)
298{
efd7f486 299 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
300 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
301 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
302 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
303 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
304 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
305 *tcg_ctx.gen_opparam_ptr++ = arg6;
be210acb
RH
306}
307
a9751609 308static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
be210acb
RH
309 TCGv_i64 arg3, TCGv_i64 arg4,
310 TCGv_i64 arg5, TCGArg arg6)
311{
efd7f486 312 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
313 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
314 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
315 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
316 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
317 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
318 *tcg_ctx.gen_opparam_ptr++ = arg6;
be210acb
RH
319}
320
a9751609
RH
321static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 arg1,
322 TCGv_i32 arg2, TCGv_i32 arg3,
323 TCGv_i32 arg4, TCGArg arg5, TCGArg arg6)
ac56dd48 324{
efd7f486 325 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
326 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
327 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
328 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
329 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
330 *tcg_ctx.gen_opparam_ptr++ = arg5;
331 *tcg_ctx.gen_opparam_ptr++ = arg6;
a7812ae4
PB
332}
333
a9751609
RH
334static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 arg1,
335 TCGv_i64 arg2, TCGv_i64 arg3,
336 TCGv_i64 arg4, TCGArg arg5, TCGArg arg6)
a7812ae4 337{
efd7f486 338 *tcg_ctx.gen_opc_ptr++ = opc;
c4afe5c4
EV
339 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
340 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
341 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
342 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
343 *tcg_ctx.gen_opparam_ptr++ = arg5;
344 *tcg_ctx.gen_opparam_ptr++ = arg6;
c896fe29
FB
345}
346
f713d6ad
RH
347static inline void tcg_add_param_i32(TCGv_i32 val)
348{
349 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(val);
350}
351
352static inline void tcg_add_param_i64(TCGv_i64 val)
353{
354#if TCG_TARGET_REG_BITS == 32
355 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(TCGV_LOW(val));
356 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(TCGV_HIGH(val));
357#else
358 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
359#endif
360}
361
c896fe29
FB
362static inline void gen_set_label(int n)
363{
ac56dd48 364 tcg_gen_op1i(INDEX_op_set_label, n);
c896fe29
FB
365}
366
fb50d413
BS
367static inline void tcg_gen_br(int label)
368{
369 tcg_gen_op1i(INDEX_op_br, label);
370}
371
a7812ae4 372static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 373{
fe75bcf7 374 if (!TCGV_EQUAL_I32(ret, arg))
a7812ae4 375 tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
c896fe29
FB
376}
377
a7812ae4 378static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
c896fe29 379{
a7812ae4 380 tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
c896fe29
FB
381}
382
2bece2c8
RH
383/* A version of dh_sizemask from def-helper.h that doesn't rely on
384 preprocessor magic. */
385static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
386{
387 return (is_64bit << n*2) | (is_signed << (n*2 + 1));
388}
389
c896fe29 390/* helper calls */
a7812ae4
PB
391static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
392 TCGArg ret, int nargs, TCGArg *args)
393{
cf066674 394 tcg_gen_callN(&tcg_ctx, func, flags, sizemask, ret, nargs, args);
a7812ae4 395}
c896fe29 396
dbfff4de 397/* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
78505279
AJ
398 reserved for helpers in tcg-runtime.c. These helpers all do not read
399 globals and do not have side effects, hence the call to tcg_gen_callN()
400 with TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS. This may need
401 to be adjusted if these functions start to be used with other helpers. */
2bece2c8 402static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
31d66551
AJ
403 TCGv_i32 a, TCGv_i32 b)
404{
31d66551 405 TCGArg args[2];
31d66551
AJ
406 args[0] = GET_TCGV_I32(a);
407 args[1] = GET_TCGV_I32(b);
cf066674 408 tcg_gen_callN(&tcg_ctx, func,
78505279
AJ
409 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
410 sizemask, GET_TCGV_I32(ret), 2, args);
31d66551
AJ
411}
412
2bece2c8 413static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
a7812ae4 414 TCGv_i64 a, TCGv_i64 b)
c896fe29 415{
a7812ae4 416 TCGArg args[2];
a7812ae4
PB
417 args[0] = GET_TCGV_I64(a);
418 args[1] = GET_TCGV_I64(b);
cf066674 419 tcg_gen_callN(&tcg_ctx, func,
78505279
AJ
420 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
421 sizemask, GET_TCGV_I64(ret), 2, args);
f8422f52
BS
422}
423
c896fe29
FB
424/* 32 bit ops */
425
a7812ae4 426static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 427{
a7812ae4 428 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
c896fe29
FB
429}
430
a7812ae4 431static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 432{
a7812ae4 433 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
c896fe29
FB
434}
435
a7812ae4 436static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 437{
a7812ae4 438 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
c896fe29
FB
439}
440
a7812ae4 441static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 442{
a7812ae4 443 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
c896fe29
FB
444}
445
a7812ae4 446static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 447{
a7812ae4 448 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
c896fe29
FB
449}
450
a7812ae4 451static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 452{
a7812ae4 453 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
c896fe29
FB
454}
455
a7812ae4 456static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 457{
a7812ae4 458 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
c896fe29
FB
459}
460
a7812ae4 461static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 462{
a7812ae4 463 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
c896fe29
FB
464}
465
a7812ae4 466static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 467{
a7812ae4 468 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
c896fe29
FB
469}
470
a7812ae4 471static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 472{
7089442c
BS
473 /* some cases can be optimized here */
474 if (arg2 == 0) {
475 tcg_gen_mov_i32(ret, arg1);
476 } else {
a7812ae4 477 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 478 tcg_gen_add_i32(ret, arg1, t0);
a7812ae4 479 tcg_temp_free_i32(t0);
7089442c 480 }
c896fe29
FB
481}
482
a7812ae4 483static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 484{
a7812ae4 485 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
c896fe29
FB
486}
487
a7812ae4 488static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
0045734a 489{
a7812ae4 490 TCGv_i32 t0 = tcg_const_i32(arg1);
0045734a 491 tcg_gen_sub_i32(ret, t0, arg2);
a7812ae4 492 tcg_temp_free_i32(t0);
0045734a
AJ
493}
494
a7812ae4 495static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 496{
7089442c
BS
497 /* some cases can be optimized here */
498 if (arg2 == 0) {
499 tcg_gen_mov_i32(ret, arg1);
500 } else {
a7812ae4 501 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 502 tcg_gen_sub_i32(ret, arg1, t0);
a7812ae4 503 tcg_temp_free_i32(t0);
7089442c 504 }
c896fe29
FB
505}
506
a7812ae4 507static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 508{
7fc81051
AJ
509 if (TCGV_EQUAL_I32(arg1, arg2)) {
510 tcg_gen_mov_i32(ret, arg1);
511 } else {
512 tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
513 }
c896fe29
FB
514}
515
42ce3e20 516static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
c896fe29 517{
42ce3e20
RH
518 TCGv_i32 t0;
519 /* Some cases can be optimized here. */
520 switch (arg2) {
521 case 0:
c896fe29 522 tcg_gen_movi_i32(ret, 0);
42ce3e20
RH
523 return;
524 case 0xffffffffu:
c896fe29 525 tcg_gen_mov_i32(ret, arg1);
42ce3e20
RH
526 return;
527 case 0xffu:
528 /* Don't recurse with tcg_gen_ext8u_i32. */
529 if (TCG_TARGET_HAS_ext8u_i32) {
530 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg1);
531 return;
532 }
533 break;
534 case 0xffffu:
535 if (TCG_TARGET_HAS_ext16u_i32) {
536 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg1);
537 return;
538 }
539 break;
c896fe29 540 }
42ce3e20
RH
541 t0 = tcg_const_i32(arg2);
542 tcg_gen_and_i32(ret, arg1, t0);
543 tcg_temp_free_i32(t0);
c896fe29
FB
544}
545
a7812ae4 546static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 547{
7fc81051
AJ
548 if (TCGV_EQUAL_I32(arg1, arg2)) {
549 tcg_gen_mov_i32(ret, arg1);
550 } else {
551 tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
552 }
c896fe29
FB
553}
554
a7812ae4 555static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 556{
d81ada7f
RH
557 /* Some cases can be optimized here. */
558 if (arg2 == -1) {
559 tcg_gen_movi_i32(ret, -1);
c896fe29
FB
560 } else if (arg2 == 0) {
561 tcg_gen_mov_i32(ret, arg1);
562 } else {
a7812ae4 563 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 564 tcg_gen_or_i32(ret, arg1, t0);
a7812ae4 565 tcg_temp_free_i32(t0);
c896fe29
FB
566 }
567}
568
a7812ae4 569static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 570{
7fc81051
AJ
571 if (TCGV_EQUAL_I32(arg1, arg2)) {
572 tcg_gen_movi_i32(ret, 0);
573 } else {
574 tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
575 }
c896fe29
FB
576}
577
a7812ae4 578static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 579{
6f3bb33e 580 /* Some cases can be optimized here. */
c896fe29
FB
581 if (arg2 == 0) {
582 tcg_gen_mov_i32(ret, arg1);
6f3bb33e
RH
583 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i32) {
584 /* Don't recurse with tcg_gen_not_i32. */
585 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg1);
c896fe29 586 } else {
a7812ae4 587 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 588 tcg_gen_xor_i32(ret, arg1, t0);
a7812ae4 589 tcg_temp_free_i32(t0);
c896fe29
FB
590 }
591}
592
a7812ae4 593static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 594{
a7812ae4 595 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
c896fe29
FB
596}
597
a7812ae4 598static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 599{
34151a20
FB
600 if (arg2 == 0) {
601 tcg_gen_mov_i32(ret, arg1);
602 } else {
a7812ae4 603 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 604 tcg_gen_shl_i32(ret, arg1, t0);
a7812ae4 605 tcg_temp_free_i32(t0);
34151a20 606 }
c896fe29
FB
607}
608
a7812ae4 609static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 610{
a7812ae4 611 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
c896fe29
FB
612}
613
a7812ae4 614static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 615{
34151a20
FB
616 if (arg2 == 0) {
617 tcg_gen_mov_i32(ret, arg1);
618 } else {
a7812ae4 619 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 620 tcg_gen_shr_i32(ret, arg1, t0);
a7812ae4 621 tcg_temp_free_i32(t0);
34151a20 622 }
c896fe29
FB
623}
624
a7812ae4 625static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 626{
a7812ae4 627 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
c896fe29
FB
628}
629
a7812ae4 630static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
c896fe29 631{
34151a20
FB
632 if (arg2 == 0) {
633 tcg_gen_mov_i32(ret, arg1);
634 } else {
a7812ae4 635 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 636 tcg_gen_sar_i32(ret, arg1, t0);
a7812ae4 637 tcg_temp_free_i32(t0);
34151a20 638 }
c896fe29
FB
639}
640
8a56e840
RH
641static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
642 TCGv_i32 arg2, int label_index)
c896fe29 643{
0aed257f
RH
644 if (cond == TCG_COND_ALWAYS) {
645 tcg_gen_br(label_index);
646 } else if (cond != TCG_COND_NEVER) {
647 tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
648 }
c896fe29
FB
649}
650
8a56e840
RH
651static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
652 int32_t arg2, int label_index)
cb63669a 653{
0aed257f
RH
654 if (cond == TCG_COND_ALWAYS) {
655 tcg_gen_br(label_index);
656 } else if (cond != TCG_COND_NEVER) {
657 TCGv_i32 t0 = tcg_const_i32(arg2);
658 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
659 tcg_temp_free_i32(t0);
660 }
cb63669a
PB
661}
662
8a56e840 663static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
5105c556
AJ
664 TCGv_i32 arg1, TCGv_i32 arg2)
665{
0aed257f
RH
666 if (cond == TCG_COND_ALWAYS) {
667 tcg_gen_movi_i32(ret, 1);
668 } else if (cond == TCG_COND_NEVER) {
669 tcg_gen_movi_i32(ret, 0);
670 } else {
671 tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
672 }
5105c556
AJ
673}
674
8a56e840
RH
675static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
676 TCGv_i32 arg1, int32_t arg2)
5105c556 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 TCGv_i32 t0 = tcg_const_i32(arg2);
684 tcg_gen_setcond_i32(cond, ret, arg1, t0);
685 tcg_temp_free_i32(t0);
686 }
5105c556
AJ
687}
688
a7812ae4 689static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 690{
a7812ae4 691 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
c896fe29
FB
692}
693
a7812ae4 694static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
f730fd27 695{
a7812ae4 696 TCGv_i32 t0 = tcg_const_i32(arg2);
e8996ee0 697 tcg_gen_mul_i32(ret, arg1, t0);
a7812ae4 698 tcg_temp_free_i32(t0);
f730fd27
TS
699}
700
a7812ae4 701static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
c896fe29 702{
25c4d9cc
RH
703 if (TCG_TARGET_HAS_div_i32) {
704 tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
705 } else if (TCG_TARGET_HAS_div2_i32) {
706 TCGv_i32 t0 = tcg_temp_new_i32();
707 tcg_gen_sari_i32(t0, arg1, 31);
708 tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
709 tcg_temp_free_i32(t0);
710 } else {
711 int sizemask = 0;
712 /* Return value and both arguments are 32-bit and signed. */
713 sizemask |= tcg_gen_sizemask(0, 0, 1);
714 sizemask |= tcg_gen_sizemask(1, 0, 1);
715 sizemask |= tcg_gen_sizemask(2, 0, 1);
944eea96 716 tcg_gen_helper32(helper_div_i32, sizemask, ret, arg1, arg2);
25c4d9cc 717 }
31d66551
AJ
718}
719
720static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
721{
ca675f46 722 if (TCG_TARGET_HAS_rem_i32) {
25c4d9cc 723 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
ca675f46
RH
724 } else if (TCG_TARGET_HAS_div_i32) {
725 TCGv_i32 t0 = tcg_temp_new_i32();
726 tcg_gen_op3_i32(INDEX_op_div_i32, t0, arg1, arg2);
727 tcg_gen_mul_i32(t0, t0, arg2);
728 tcg_gen_sub_i32(ret, arg1, t0);
729 tcg_temp_free_i32(t0);
25c4d9cc
RH
730 } else if (TCG_TARGET_HAS_div2_i32) {
731 TCGv_i32 t0 = tcg_temp_new_i32();
732 tcg_gen_sari_i32(t0, arg1, 31);
733 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
734 tcg_temp_free_i32(t0);
735 } else {
736 int sizemask = 0;
737 /* Return value and both arguments are 32-bit and signed. */
738 sizemask |= tcg_gen_sizemask(0, 0, 1);
739 sizemask |= tcg_gen_sizemask(1, 0, 1);
740 sizemask |= tcg_gen_sizemask(2, 0, 1);
944eea96 741 tcg_gen_helper32(helper_rem_i32, sizemask, ret, arg1, arg2);
25c4d9cc 742 }
31d66551
AJ
743}
744
745static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
746{
25c4d9cc
RH
747 if (TCG_TARGET_HAS_div_i32) {
748 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
749 } else if (TCG_TARGET_HAS_div2_i32) {
750 TCGv_i32 t0 = tcg_temp_new_i32();
751 tcg_gen_movi_i32(t0, 0);
752 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
753 tcg_temp_free_i32(t0);
754 } else {
755 int sizemask = 0;
756 /* Return value and both arguments are 32-bit and unsigned. */
757 sizemask |= tcg_gen_sizemask(0, 0, 0);
758 sizemask |= tcg_gen_sizemask(1, 0, 0);
759 sizemask |= tcg_gen_sizemask(2, 0, 0);
944eea96 760 tcg_gen_helper32(helper_divu_i32, sizemask, ret, arg1, arg2);
25c4d9cc 761 }
31d66551
AJ
762}
763
764static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
765{
ca675f46 766 if (TCG_TARGET_HAS_rem_i32) {
25c4d9cc 767 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
ca675f46
RH
768 } else if (TCG_TARGET_HAS_div_i32) {
769 TCGv_i32 t0 = tcg_temp_new_i32();
770 tcg_gen_op3_i32(INDEX_op_divu_i32, t0, arg1, arg2);
771 tcg_gen_mul_i32(t0, t0, arg2);
772 tcg_gen_sub_i32(ret, arg1, t0);
773 tcg_temp_free_i32(t0);
25c4d9cc
RH
774 } else if (TCG_TARGET_HAS_div2_i32) {
775 TCGv_i32 t0 = tcg_temp_new_i32();
776 tcg_gen_movi_i32(t0, 0);
777 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
778 tcg_temp_free_i32(t0);
779 } else {
780 int sizemask = 0;
781 /* Return value and both arguments are 32-bit and unsigned. */
782 sizemask |= tcg_gen_sizemask(0, 0, 0);
783 sizemask |= tcg_gen_sizemask(1, 0, 0);
784 sizemask |= tcg_gen_sizemask(2, 0, 0);
944eea96 785 tcg_gen_helper32(helper_remu_i32, sizemask, ret, arg1, arg2);
25c4d9cc 786 }
31d66551 787}
c896fe29
FB
788
789#if TCG_TARGET_REG_BITS == 32
790
a7812ae4 791static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 792{
fe75bcf7 793 if (!TCGV_EQUAL_I64(ret, arg)) {
a7812ae4 794 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
4d07272d
BS
795 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
796 }
c896fe29
FB
797}
798
a7812ae4 799static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
c896fe29 800{
a7812ae4 801 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
ac56dd48 802 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
c896fe29
FB
803}
804
a7812ae4
PB
805static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
806 tcg_target_long offset)
c896fe29 807{
a7812ae4 808 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 809 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
810}
811
a7812ae4
PB
812static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
813 tcg_target_long offset)
c896fe29 814{
a7812ae4
PB
815 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
816 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
c896fe29
FB
817}
818
a7812ae4
PB
819static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
820 tcg_target_long offset)
c896fe29 821{
a747723b 822 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 823 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
824}
825
a7812ae4
PB
826static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
827 tcg_target_long offset)
c896fe29 828{
a7812ae4
PB
829 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
830 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
831}
832
a7812ae4
PB
833static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
834 tcg_target_long offset)
c896fe29 835{
a7812ae4 836 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 837 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
838}
839
a7812ae4
PB
840static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
841 tcg_target_long offset)
c896fe29 842{
a7812ae4
PB
843 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
844 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
845}
846
a7812ae4
PB
847static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
848 tcg_target_long offset)
c896fe29
FB
849{
850 /* since arg2 and ret have different types, they cannot be the
851 same temporary */
02eb19d0 852#ifdef HOST_WORDS_BIGENDIAN
ac56dd48 853 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
a7812ae4 854 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
c896fe29 855#else
a7812ae4 856 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
ac56dd48 857 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
c896fe29
FB
858#endif
859}
860
a7812ae4
PB
861static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
862 tcg_target_long offset)
c896fe29 863{
a7812ae4 864 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
865}
866
a7812ae4
PB
867static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
868 tcg_target_long offset)
c896fe29 869{
a7812ae4 870 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
871}
872
a7812ae4
PB
873static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
874 tcg_target_long offset)
c896fe29 875{
a7812ae4 876 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
c896fe29
FB
877}
878
a7812ae4
PB
879static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
880 tcg_target_long offset)
c896fe29 881{
02eb19d0 882#ifdef HOST_WORDS_BIGENDIAN
ac56dd48 883 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
a7812ae4 884 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
c896fe29 885#else
a7812ae4 886 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
ac56dd48 887 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
c896fe29
FB
888#endif
889}
890
a7812ae4 891static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 892{
a7812ae4
PB
893 tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
894 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
895 TCGV_HIGH(arg2));
212c328d
RH
896 /* Allow the optimizer room to replace add2 with two moves. */
897 tcg_gen_op0(INDEX_op_nop);
c896fe29
FB
898}
899
a7812ae4 900static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 901{
a7812ae4
PB
902 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
903 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
904 TCGV_HIGH(arg2));
212c328d
RH
905 /* Allow the optimizer room to replace sub2 with two moves. */
906 tcg_gen_op0(INDEX_op_nop);
c896fe29
FB
907}
908
a7812ae4 909static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 910{
a7812ae4 911 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
ac56dd48 912 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
913}
914
a7812ae4 915static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 916{
e5105083
AJ
917 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
918 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
919}
920
a7812ae4 921static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 922{
e5105083
AJ
923 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
924 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
925}
926
a7812ae4 927static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 928{
a7812ae4 929 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
ac56dd48 930 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
931}
932
a7812ae4 933static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 934{
e5105083
AJ
935 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
936 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
c896fe29
FB
937}
938
a7812ae4 939static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 940{
a7812ae4 941 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
ac56dd48 942 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
c896fe29
FB
943}
944
945/* XXX: use generic code when basic block handling is OK or CPU
946 specific code (x86) */
a7812ae4 947static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 948{
2bece2c8
RH
949 int sizemask = 0;
950 /* Return value and both arguments are 64-bit and signed. */
951 sizemask |= tcg_gen_sizemask(0, 1, 1);
952 sizemask |= tcg_gen_sizemask(1, 1, 1);
953 sizemask |= tcg_gen_sizemask(2, 1, 1);
954
944eea96 955 tcg_gen_helper64(helper_shl_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
956}
957
a7812ae4 958static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
959{
960 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
961}
962
a7812ae4 963static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 964{
2bece2c8
RH
965 int sizemask = 0;
966 /* Return value and both arguments are 64-bit and signed. */
967 sizemask |= tcg_gen_sizemask(0, 1, 1);
968 sizemask |= tcg_gen_sizemask(1, 1, 1);
969 sizemask |= tcg_gen_sizemask(2, 1, 1);
970
944eea96 971 tcg_gen_helper64(helper_shr_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
972}
973
a7812ae4 974static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
975{
976 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
977}
978
a7812ae4 979static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 980{
2bece2c8
RH
981 int sizemask = 0;
982 /* Return value and both arguments are 64-bit and signed. */
983 sizemask |= tcg_gen_sizemask(0, 1, 1);
984 sizemask |= tcg_gen_sizemask(1, 1, 1);
985 sizemask |= tcg_gen_sizemask(2, 1, 1);
986
944eea96 987 tcg_gen_helper64(helper_sar_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
988}
989
a7812ae4 990static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29
FB
991{
992 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
993}
994
8a56e840
RH
995static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
996 TCGv_i64 arg2, int label_index)
c896fe29 997{
0aed257f
RH
998 if (cond == TCG_COND_ALWAYS) {
999 tcg_gen_br(label_index);
1000 } else if (cond != TCG_COND_NEVER) {
1001 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
1002 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
1003 TCGV_HIGH(arg2), cond, label_index);
1004 }
c896fe29
FB
1005}
1006
8a56e840 1007static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
5105c556
AJ
1008 TCGv_i64 arg1, TCGv_i64 arg2)
1009{
0aed257f
RH
1010 if (cond == TCG_COND_ALWAYS) {
1011 tcg_gen_movi_i32(TCGV_LOW(ret), 1);
1012 } else if (cond == TCG_COND_NEVER) {
1013 tcg_gen_movi_i32(TCGV_LOW(ret), 0);
1014 } else {
1015 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
1016 TCGV_LOW(arg1), TCGV_HIGH(arg1),
1017 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
1018 }
5105c556
AJ
1019 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1020}
1021
a7812ae4 1022static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1023{
a7812ae4
PB
1024 TCGv_i64 t0;
1025 TCGv_i32 t1;
c896fe29 1026
a7812ae4
PB
1027 t0 = tcg_temp_new_i64();
1028 t1 = tcg_temp_new_i32();
1029
03271524
RH
1030 if (TCG_TARGET_HAS_mulu2_i32) {
1031 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
1032 TCGV_LOW(arg1), TCGV_LOW(arg2));
1033 /* Allow the optimizer room to replace mulu2 with two moves. */
1034 tcg_gen_op0(INDEX_op_nop);
1035 } else {
1036 tcg_debug_assert(TCG_TARGET_HAS_muluh_i32);
1037 tcg_gen_op3_i32(INDEX_op_mul_i32, TCGV_LOW(t0),
1038 TCGV_LOW(arg1), TCGV_LOW(arg2));
1039 tcg_gen_op3_i32(INDEX_op_muluh_i32, TCGV_HIGH(t0),
1040 TCGV_LOW(arg1), TCGV_LOW(arg2));
1041 }
a7812ae4
PB
1042
1043 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
ac56dd48 1044 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
a7812ae4 1045 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
ac56dd48 1046 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
a7812ae4 1047
c896fe29 1048 tcg_gen_mov_i64(ret, t0);
a7812ae4
PB
1049 tcg_temp_free_i64(t0);
1050 tcg_temp_free_i32(t1);
c896fe29
FB
1051}
1052
a7812ae4 1053static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1054{
2bece2c8
RH
1055 int sizemask = 0;
1056 /* Return value and both arguments are 64-bit and signed. */
1057 sizemask |= tcg_gen_sizemask(0, 1, 1);
1058 sizemask |= tcg_gen_sizemask(1, 1, 1);
1059 sizemask |= tcg_gen_sizemask(2, 1, 1);
1060
944eea96 1061 tcg_gen_helper64(helper_div_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1062}
1063
a7812ae4 1064static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1065{
2bece2c8
RH
1066 int sizemask = 0;
1067 /* Return value and both arguments are 64-bit and signed. */
1068 sizemask |= tcg_gen_sizemask(0, 1, 1);
1069 sizemask |= tcg_gen_sizemask(1, 1, 1);
1070 sizemask |= tcg_gen_sizemask(2, 1, 1);
1071
944eea96 1072 tcg_gen_helper64(helper_rem_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1073}
1074
a7812ae4 1075static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1076{
2bece2c8
RH
1077 int sizemask = 0;
1078 /* Return value and both arguments are 64-bit and unsigned. */
1079 sizemask |= tcg_gen_sizemask(0, 1, 0);
1080 sizemask |= tcg_gen_sizemask(1, 1, 0);
1081 sizemask |= tcg_gen_sizemask(2, 1, 0);
1082
944eea96 1083 tcg_gen_helper64(helper_divu_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1084}
1085
a7812ae4 1086static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1087{
2bece2c8
RH
1088 int sizemask = 0;
1089 /* Return value and both arguments are 64-bit and unsigned. */
1090 sizemask |= tcg_gen_sizemask(0, 1, 0);
1091 sizemask |= tcg_gen_sizemask(1, 1, 0);
1092 sizemask |= tcg_gen_sizemask(2, 1, 0);
1093
944eea96 1094 tcg_gen_helper64(helper_remu_i64, sizemask, ret, arg1, arg2);
c896fe29
FB
1095}
1096
1097#else
1098
a7812ae4 1099static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1100{
fe75bcf7 1101 if (!TCGV_EQUAL_I64(ret, arg))
a7812ae4 1102 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
c896fe29
FB
1103}
1104
a7812ae4 1105static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
c896fe29 1106{
a7812ae4 1107 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
c896fe29
FB
1108}
1109
6bd4b08a 1110static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1111 tcg_target_long offset)
c896fe29 1112{
a7812ae4 1113 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
c896fe29
FB
1114}
1115
6bd4b08a 1116static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1117 tcg_target_long offset)
c896fe29 1118{
a7812ae4 1119 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
c896fe29
FB
1120}
1121
6bd4b08a 1122static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1123 tcg_target_long offset)
c896fe29 1124{
a7812ae4 1125 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
c896fe29
FB
1126}
1127
6bd4b08a 1128static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1129 tcg_target_long offset)
c896fe29 1130{
a7812ae4 1131 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
c896fe29
FB
1132}
1133
6bd4b08a 1134static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1135 tcg_target_long offset)
c896fe29 1136{
a7812ae4 1137 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
c896fe29
FB
1138}
1139
6bd4b08a 1140static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
ac56dd48 1141 tcg_target_long offset)
c896fe29 1142{
a7812ae4 1143 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
c896fe29
FB
1144}
1145
6bd4b08a 1146static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 1147{
a7812ae4 1148 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
c896fe29
FB
1149}
1150
6bd4b08a 1151static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1152 tcg_target_long offset)
c896fe29 1153{
a7812ae4 1154 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
c896fe29
FB
1155}
1156
6bd4b08a 1157static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1158 tcg_target_long offset)
c896fe29 1159{
a7812ae4 1160 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
c896fe29
FB
1161}
1162
6bd4b08a 1163static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
ac56dd48 1164 tcg_target_long offset)
c896fe29 1165{
a7812ae4 1166 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
c896fe29
FB
1167}
1168
6bd4b08a 1169static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
c896fe29 1170{
a7812ae4 1171 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
c896fe29
FB
1172}
1173
a7812ae4 1174static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1175{
a7812ae4 1176 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
c896fe29
FB
1177}
1178
a7812ae4 1179static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1180{
a7812ae4 1181 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
c896fe29
FB
1182}
1183
a7812ae4 1184static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1185{
7fc81051
AJ
1186 if (TCGV_EQUAL_I64(arg1, arg2)) {
1187 tcg_gen_mov_i64(ret, arg1);
1188 } else {
1189 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1190 }
c896fe29
FB
1191}
1192
42ce3e20 1193static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
c896fe29 1194{
42ce3e20
RH
1195 TCGv_i64 t0;
1196 /* Some cases can be optimized here. */
1197 switch (arg2) {
1198 case 0:
1199 tcg_gen_movi_i64(ret, 0);
1200 return;
1201 case 0xffffffffffffffffull:
1202 tcg_gen_mov_i64(ret, arg1);
1203 return;
1204 case 0xffull:
1205 /* Don't recurse with tcg_gen_ext8u_i32. */
1206 if (TCG_TARGET_HAS_ext8u_i64) {
1207 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg1);
1208 return;
1209 }
1210 break;
1211 case 0xffffu:
1212 if (TCG_TARGET_HAS_ext16u_i64) {
1213 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg1);
1214 return;
1215 }
1216 break;
1217 case 0xffffffffull:
1218 if (TCG_TARGET_HAS_ext32u_i64) {
1219 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg1);
1220 return;
1221 }
1222 break;
1223 }
1224 t0 = tcg_const_i64(arg2);
e8996ee0 1225 tcg_gen_and_i64(ret, arg1, t0);
a7812ae4 1226 tcg_temp_free_i64(t0);
c896fe29
FB
1227}
1228
a7812ae4 1229static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1230{
7fc81051
AJ
1231 if (TCGV_EQUAL_I64(arg1, arg2)) {
1232 tcg_gen_mov_i64(ret, arg1);
1233 } else {
1234 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1235 }
c896fe29
FB
1236}
1237
a7812ae4 1238static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1239{
d81ada7f
RH
1240 /* Some cases can be optimized here. */
1241 if (arg2 == -1) {
1242 tcg_gen_movi_i64(ret, -1);
1243 } else if (arg2 == 0) {
1244 tcg_gen_mov_i64(ret, arg1);
1245 } else {
1246 TCGv_i64 t0 = tcg_const_i64(arg2);
1247 tcg_gen_or_i64(ret, arg1, t0);
1248 tcg_temp_free_i64(t0);
1249 }
c896fe29
FB
1250}
1251
a7812ae4 1252static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1253{
7fc81051
AJ
1254 if (TCGV_EQUAL_I64(arg1, arg2)) {
1255 tcg_gen_movi_i64(ret, 0);
1256 } else {
1257 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1258 }
c896fe29
FB
1259}
1260
a7812ae4 1261static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1262{
6f3bb33e
RH
1263 /* Some cases can be optimized here. */
1264 if (arg2 == 0) {
1265 tcg_gen_mov_i64(ret, arg1);
1266 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i64) {
1267 /* Don't recurse with tcg_gen_not_i64. */
1268 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
1269 } else {
1270 TCGv_i64 t0 = tcg_const_i64(arg2);
1271 tcg_gen_xor_i64(ret, arg1, t0);
1272 tcg_temp_free_i64(t0);
1273 }
c896fe29
FB
1274}
1275
a7812ae4 1276static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1277{
a7812ae4 1278 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
c896fe29
FB
1279}
1280
a7812ae4 1281static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1282{
34151a20
FB
1283 if (arg2 == 0) {
1284 tcg_gen_mov_i64(ret, arg1);
1285 } else {
a7812ae4 1286 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1287 tcg_gen_shl_i64(ret, arg1, t0);
a7812ae4 1288 tcg_temp_free_i64(t0);
34151a20 1289 }
c896fe29
FB
1290}
1291
a7812ae4 1292static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1293{
a7812ae4 1294 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
c896fe29
FB
1295}
1296
a7812ae4 1297static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1298{
34151a20
FB
1299 if (arg2 == 0) {
1300 tcg_gen_mov_i64(ret, arg1);
1301 } else {
a7812ae4 1302 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1303 tcg_gen_shr_i64(ret, arg1, t0);
a7812ae4 1304 tcg_temp_free_i64(t0);
34151a20 1305 }
c896fe29
FB
1306}
1307
a7812ae4 1308static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1309{
a7812ae4 1310 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
c896fe29
FB
1311}
1312
a7812ae4 1313static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
c896fe29 1314{
34151a20
FB
1315 if (arg2 == 0) {
1316 tcg_gen_mov_i64(ret, arg1);
1317 } else {
a7812ae4 1318 TCGv_i64 t0 = tcg_const_i64(arg2);
e8996ee0 1319 tcg_gen_sar_i64(ret, arg1, t0);
a7812ae4 1320 tcg_temp_free_i64(t0);
34151a20 1321 }
c896fe29
FB
1322}
1323
8a56e840
RH
1324static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1325 TCGv_i64 arg2, int label_index)
c896fe29 1326{
0aed257f
RH
1327 if (cond == TCG_COND_ALWAYS) {
1328 tcg_gen_br(label_index);
1329 } else if (cond != TCG_COND_NEVER) {
1330 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
1331 }
c896fe29
FB
1332}
1333
8a56e840 1334static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
5105c556
AJ
1335 TCGv_i64 arg1, TCGv_i64 arg2)
1336{
0aed257f
RH
1337 if (cond == TCG_COND_ALWAYS) {
1338 tcg_gen_movi_i64(ret, 1);
1339 } else if (cond == TCG_COND_NEVER) {
1340 tcg_gen_movi_i64(ret, 0);
1341 } else {
1342 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1343 }
5105c556
AJ
1344}
1345
a7812ae4 1346static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
c896fe29 1347{
a7812ae4 1348 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
c896fe29
FB
1349}
1350
31d66551
AJ
1351static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1352{
25c4d9cc
RH
1353 if (TCG_TARGET_HAS_div_i64) {
1354 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
1355 } else if (TCG_TARGET_HAS_div2_i64) {
1356 TCGv_i64 t0 = tcg_temp_new_i64();
1357 tcg_gen_sari_i64(t0, arg1, 63);
1358 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1359 tcg_temp_free_i64(t0);
1360 } else {
1361 int sizemask = 0;
1362 /* Return value and both arguments are 64-bit and signed. */
1363 sizemask |= tcg_gen_sizemask(0, 1, 1);
1364 sizemask |= tcg_gen_sizemask(1, 1, 1);
1365 sizemask |= tcg_gen_sizemask(2, 1, 1);
944eea96 1366 tcg_gen_helper64(helper_div_i64, sizemask, ret, arg1, arg2);
25c4d9cc 1367 }
31d66551
AJ
1368}
1369
1370static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1371{
ca675f46 1372 if (TCG_TARGET_HAS_rem_i64) {
25c4d9cc 1373 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
ca675f46
RH
1374 } else if (TCG_TARGET_HAS_div_i64) {
1375 TCGv_i64 t0 = tcg_temp_new_i64();
1376 tcg_gen_op3_i64(INDEX_op_div_i64, t0, arg1, arg2);
1377 tcg_gen_mul_i64(t0, t0, arg2);
1378 tcg_gen_sub_i64(ret, arg1, t0);
1379 tcg_temp_free_i64(t0);
25c4d9cc
RH
1380 } else if (TCG_TARGET_HAS_div2_i64) {
1381 TCGv_i64 t0 = tcg_temp_new_i64();
1382 tcg_gen_sari_i64(t0, arg1, 63);
1383 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1384 tcg_temp_free_i64(t0);
1385 } else {
1386 int sizemask = 0;
1387 /* Return value and both arguments are 64-bit and signed. */
1388 sizemask |= tcg_gen_sizemask(0, 1, 1);
1389 sizemask |= tcg_gen_sizemask(1, 1, 1);
1390 sizemask |= tcg_gen_sizemask(2, 1, 1);
944eea96 1391 tcg_gen_helper64(helper_rem_i64, sizemask, ret, arg1, arg2);
25c4d9cc 1392 }
31d66551
AJ
1393}
1394
1395static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1396{
25c4d9cc
RH
1397 if (TCG_TARGET_HAS_div_i64) {
1398 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
1399 } else if (TCG_TARGET_HAS_div2_i64) {
1400 TCGv_i64 t0 = tcg_temp_new_i64();
1401 tcg_gen_movi_i64(t0, 0);
1402 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1403 tcg_temp_free_i64(t0);
1404 } else {
1405 int sizemask = 0;
1406 /* Return value and both arguments are 64-bit and unsigned. */
1407 sizemask |= tcg_gen_sizemask(0, 1, 0);
1408 sizemask |= tcg_gen_sizemask(1, 1, 0);
1409 sizemask |= tcg_gen_sizemask(2, 1, 0);
944eea96 1410 tcg_gen_helper64(helper_divu_i64, sizemask, ret, arg1, arg2);
25c4d9cc 1411 }
31d66551
AJ
1412}
1413
1414static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1415{
ca675f46 1416 if (TCG_TARGET_HAS_rem_i64) {
25c4d9cc 1417 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
ca675f46
RH
1418 } else if (TCG_TARGET_HAS_div_i64) {
1419 TCGv_i64 t0 = tcg_temp_new_i64();
1420 tcg_gen_op3_i64(INDEX_op_divu_i64, t0, arg1, arg2);
1421 tcg_gen_mul_i64(t0, t0, arg2);
1422 tcg_gen_sub_i64(ret, arg1, t0);
1423 tcg_temp_free_i64(t0);
25c4d9cc
RH
1424 } else if (TCG_TARGET_HAS_div2_i64) {
1425 TCGv_i64 t0 = tcg_temp_new_i64();
1426 tcg_gen_movi_i64(t0, 0);
1427 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1428 tcg_temp_free_i64(t0);
1429 } else {
1430 int sizemask = 0;
1431 /* Return value and both arguments are 64-bit and unsigned. */
1432 sizemask |= tcg_gen_sizemask(0, 1, 0);
1433 sizemask |= tcg_gen_sizemask(1, 1, 0);
1434 sizemask |= tcg_gen_sizemask(2, 1, 0);
944eea96 1435 tcg_gen_helper64(helper_remu_i64, sizemask, ret, arg1, arg2);
25c4d9cc 1436 }
31d66551 1437}
25c4d9cc 1438#endif /* TCG_TARGET_REG_BITS == 32 */
c896fe29 1439
a7812ae4 1440static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
6359706f
AJ
1441{
1442 /* some cases can be optimized here */
1443 if (arg2 == 0) {
1444 tcg_gen_mov_i64(ret, arg1);
1445 } else {
a7812ae4 1446 TCGv_i64 t0 = tcg_const_i64(arg2);
6359706f 1447 tcg_gen_add_i64(ret, arg1, t0);
a7812ae4 1448 tcg_temp_free_i64(t0);
6359706f
AJ
1449 }
1450}
1451
a7812ae4 1452static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
0045734a 1453{
a7812ae4 1454 TCGv_i64 t0 = tcg_const_i64(arg1);
0045734a 1455 tcg_gen_sub_i64(ret, t0, arg2);
a7812ae4 1456 tcg_temp_free_i64(t0);
0045734a
AJ
1457}
1458
a7812ae4 1459static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
6359706f
AJ
1460{
1461 /* some cases can be optimized here */
1462 if (arg2 == 0) {
1463 tcg_gen_mov_i64(ret, arg1);
1464 } else {
a7812ae4 1465 TCGv_i64 t0 = tcg_const_i64(arg2);
6359706f 1466 tcg_gen_sub_i64(ret, arg1, t0);
a7812ae4 1467 tcg_temp_free_i64(t0);
6359706f
AJ
1468 }
1469}
8a56e840
RH
1470static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1471 int64_t arg2, int label_index)
f02bb954 1472{
0aed257f
RH
1473 if (cond == TCG_COND_ALWAYS) {
1474 tcg_gen_br(label_index);
1475 } else if (cond != TCG_COND_NEVER) {
1476 TCGv_i64 t0 = tcg_const_i64(arg2);
1477 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1478 tcg_temp_free_i64(t0);
1479 }
f02bb954
AJ
1480}
1481
8a56e840
RH
1482static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1483 TCGv_i64 arg1, int64_t arg2)
5105c556
AJ
1484{
1485 TCGv_i64 t0 = tcg_const_i64(arg2);
1486 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1487 tcg_temp_free_i64(t0);
1488}
1489
a7812ae4 1490static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
f02bb954 1491{
a7812ae4 1492 TCGv_i64 t0 = tcg_const_i64(arg2);
f02bb954 1493 tcg_gen_mul_i64(ret, arg1, t0);
a7812ae4 1494 tcg_temp_free_i64(t0);
f02bb954
AJ
1495}
1496
6359706f 1497
c896fe29
FB
1498/***************************************/
1499/* optional operations */
1500
a7812ae4 1501static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1502{
25c4d9cc
RH
1503 if (TCG_TARGET_HAS_ext8s_i32) {
1504 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
1505 } else {
1506 tcg_gen_shli_i32(ret, arg, 24);
1507 tcg_gen_sari_i32(ret, ret, 24);
1508 }
c896fe29
FB
1509}
1510
a7812ae4 1511static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1512{
25c4d9cc
RH
1513 if (TCG_TARGET_HAS_ext16s_i32) {
1514 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
1515 } else {
1516 tcg_gen_shli_i32(ret, arg, 16);
1517 tcg_gen_sari_i32(ret, ret, 16);
1518 }
c896fe29
FB
1519}
1520
a7812ae4 1521static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
86831435 1522{
25c4d9cc
RH
1523 if (TCG_TARGET_HAS_ext8u_i32) {
1524 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1525 } else {
1526 tcg_gen_andi_i32(ret, arg, 0xffu);
1527 }
86831435
PB
1528}
1529
a7812ae4 1530static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
86831435 1531{
25c4d9cc
RH
1532 if (TCG_TARGET_HAS_ext16u_i32) {
1533 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1534 } else {
1535 tcg_gen_andi_i32(ret, arg, 0xffffu);
1536 }
86831435
PB
1537}
1538
c896fe29 1539/* Note: we assume the two high bytes are set to zero */
a7812ae4 1540static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1541{
25c4d9cc
RH
1542 if (TCG_TARGET_HAS_bswap16_i32) {
1543 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
1544 } else {
1545 TCGv_i32 t0 = tcg_temp_new_i32();
c896fe29 1546
25c4d9cc
RH
1547 tcg_gen_ext8u_i32(t0, arg);
1548 tcg_gen_shli_i32(t0, t0, 8);
1549 tcg_gen_shri_i32(ret, arg, 8);
1550 tcg_gen_or_i32(ret, ret, t0);
1551 tcg_temp_free_i32(t0);
1552 }
c896fe29
FB
1553}
1554
66896cb8 1555static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
c896fe29 1556{
25c4d9cc
RH
1557 if (TCG_TARGET_HAS_bswap32_i32) {
1558 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
1559 } else {
1560 TCGv_i32 t0, t1;
1561 t0 = tcg_temp_new_i32();
1562 t1 = tcg_temp_new_i32();
c896fe29 1563
25c4d9cc 1564 tcg_gen_shli_i32(t0, arg, 24);
c896fe29 1565
25c4d9cc
RH
1566 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1567 tcg_gen_shli_i32(t1, t1, 8);
1568 tcg_gen_or_i32(t0, t0, t1);
c896fe29 1569
25c4d9cc
RH
1570 tcg_gen_shri_i32(t1, arg, 8);
1571 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1572 tcg_gen_or_i32(t0, t0, t1);
c896fe29 1573
25c4d9cc
RH
1574 tcg_gen_shri_i32(t1, arg, 24);
1575 tcg_gen_or_i32(ret, t0, t1);
1576 tcg_temp_free_i32(t0);
1577 tcg_temp_free_i32(t1);
1578 }
c896fe29
FB
1579}
1580
1581#if TCG_TARGET_REG_BITS == 32
a7812ae4 1582static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1583{
a7812ae4
PB
1584 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1585 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1586}
1587
a7812ae4 1588static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1589{
a7812ae4
PB
1590 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1591 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1592}
1593
a7812ae4 1594static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1595{
a7812ae4
PB
1596 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1597 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1598}
1599
a7812ae4 1600static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1601{
a7812ae4 1602 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1603 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1604}
1605
a7812ae4 1606static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1607{
a7812ae4 1608 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1609 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1610}
1611
a7812ae4 1612static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1613{
a7812ae4 1614 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
86831435
PB
1615 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1616}
1617
4bb7a41e
RH
1618static inline void tcg_gen_trunc_shr_i64_i32(TCGv_i32 ret, TCGv_i64 arg,
1619 unsigned int count)
c896fe29 1620{
4bb7a41e
RH
1621 tcg_debug_assert(count < 64);
1622 if (count >= 32) {
1623 tcg_gen_shri_i32(ret, TCGV_HIGH(arg), count - 32);
1624 } else if (count == 0) {
1625 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
1626 } else {
1627 TCGv_i64 t = tcg_temp_new_i64();
1628 tcg_gen_shri_i64(t, arg, count);
1629 tcg_gen_mov_i32(ret, TCGV_LOW(t));
1630 tcg_temp_free_i64(t);
1631 }
c896fe29
FB
1632}
1633
a7812ae4 1634static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1635{
a7812ae4 1636 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
ac56dd48 1637 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
c896fe29
FB
1638}
1639
a7812ae4 1640static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1641{
a7812ae4
PB
1642 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1643 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
c896fe29
FB
1644}
1645
9a5c57fd
AJ
1646/* Note: we assume the six high bytes are set to zero */
1647static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1648{
1649 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1650 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1651}
1652
1653/* Note: we assume the four high bytes are set to zero */
1654static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1655{
1656 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1657 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1658}
1659
66896cb8 1660static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1661{
a7812ae4
PB
1662 TCGv_i32 t0, t1;
1663 t0 = tcg_temp_new_i32();
1664 t1 = tcg_temp_new_i32();
c896fe29 1665
66896cb8
AJ
1666 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1667 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
a7812ae4 1668 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
ac56dd48 1669 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
a7812ae4
PB
1670 tcg_temp_free_i32(t0);
1671 tcg_temp_free_i32(t1);
c896fe29
FB
1672}
1673#else
1674
a7812ae4 1675static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1676{
25c4d9cc
RH
1677 if (TCG_TARGET_HAS_ext8s_i64) {
1678 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
1679 } else {
1680 tcg_gen_shli_i64(ret, arg, 56);
1681 tcg_gen_sari_i64(ret, ret, 56);
1682 }
c896fe29
FB
1683}
1684
a7812ae4 1685static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1686{
25c4d9cc
RH
1687 if (TCG_TARGET_HAS_ext16s_i64) {
1688 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
1689 } else {
1690 tcg_gen_shli_i64(ret, arg, 48);
1691 tcg_gen_sari_i64(ret, ret, 48);
1692 }
c896fe29
FB
1693}
1694
a7812ae4 1695static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1696{
25c4d9cc
RH
1697 if (TCG_TARGET_HAS_ext32s_i64) {
1698 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
1699 } else {
1700 tcg_gen_shli_i64(ret, arg, 32);
1701 tcg_gen_sari_i64(ret, ret, 32);
1702 }
c896fe29
FB
1703}
1704
a7812ae4 1705static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1706{
25c4d9cc
RH
1707 if (TCG_TARGET_HAS_ext8u_i64) {
1708 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1709 } else {
1710 tcg_gen_andi_i64(ret, arg, 0xffu);
1711 }
86831435
PB
1712}
1713
a7812ae4 1714static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1715{
25c4d9cc
RH
1716 if (TCG_TARGET_HAS_ext16u_i64) {
1717 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1718 } else {
1719 tcg_gen_andi_i64(ret, arg, 0xffffu);
1720 }
86831435
PB
1721}
1722
a7812ae4 1723static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
86831435 1724{
25c4d9cc
RH
1725 if (TCG_TARGET_HAS_ext32u_i64) {
1726 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1727 } else {
1728 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1729 }
86831435
PB
1730}
1731
4bb7a41e
RH
1732static inline void tcg_gen_trunc_shr_i64_i32(TCGv_i32 ret, TCGv_i64 arg,
1733 unsigned int count)
c896fe29 1734{
4bb7a41e
RH
1735 tcg_debug_assert(count < 64);
1736 if (TCG_TARGET_HAS_trunc_shr_i32) {
1737 tcg_gen_op3i_i32(INDEX_op_trunc_shr_i32, ret,
1738 MAKE_TCGV_I32(GET_TCGV_I64(arg)), count);
1739 } else if (count == 0) {
1740 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
1741 } else {
1742 TCGv_i64 t = tcg_temp_new_i64();
1743 tcg_gen_shri_i64(t, arg, count);
1744 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(t)));
1745 tcg_temp_free_i64(t);
1746 }
c896fe29
FB
1747}
1748
1749/* Note: we assume the target supports move between 32 and 64 bit
1750 registers */
a7812ae4 1751static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1752{
cfc86988 1753 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
c896fe29
FB
1754}
1755
1756/* Note: we assume the target supports move between 32 and 64 bit
1757 registers */
a7812ae4 1758static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
c896fe29 1759{
a7812ae4 1760 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
c896fe29
FB
1761}
1762
9a5c57fd
AJ
1763/* Note: we assume the six high bytes are set to zero */
1764static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1765{
25c4d9cc
RH
1766 if (TCG_TARGET_HAS_bswap16_i64) {
1767 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1768 } else {
1769 TCGv_i64 t0 = tcg_temp_new_i64();
9a5c57fd 1770
25c4d9cc
RH
1771 tcg_gen_ext8u_i64(t0, arg);
1772 tcg_gen_shli_i64(t0, t0, 8);
1773 tcg_gen_shri_i64(ret, arg, 8);
1774 tcg_gen_or_i64(ret, ret, t0);
1775 tcg_temp_free_i64(t0);
1776 }
9a5c57fd
AJ
1777}
1778
1779/* Note: we assume the four high bytes are set to zero */
1780static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1781{
25c4d9cc
RH
1782 if (TCG_TARGET_HAS_bswap32_i64) {
1783 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1784 } else {
1785 TCGv_i64 t0, t1;
1786 t0 = tcg_temp_new_i64();
1787 t1 = tcg_temp_new_i64();
9a5c57fd 1788
25c4d9cc
RH
1789 tcg_gen_shli_i64(t0, arg, 24);
1790 tcg_gen_ext32u_i64(t0, t0);
9a5c57fd 1791
25c4d9cc
RH
1792 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1793 tcg_gen_shli_i64(t1, t1, 8);
1794 tcg_gen_or_i64(t0, t0, t1);
9a5c57fd 1795
25c4d9cc
RH
1796 tcg_gen_shri_i64(t1, arg, 8);
1797 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1798 tcg_gen_or_i64(t0, t0, t1);
9a5c57fd 1799
25c4d9cc
RH
1800 tcg_gen_shri_i64(t1, arg, 24);
1801 tcg_gen_or_i64(ret, t0, t1);
1802 tcg_temp_free_i64(t0);
1803 tcg_temp_free_i64(t1);
1804 }
9a5c57fd
AJ
1805}
1806
66896cb8 1807static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
c896fe29 1808{
25c4d9cc
RH
1809 if (TCG_TARGET_HAS_bswap64_i64) {
1810 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
1811 } else {
1812 TCGv_i64 t0 = tcg_temp_new_i64();
1813 TCGv_i64 t1 = tcg_temp_new_i64();
c896fe29 1814
25c4d9cc 1815 tcg_gen_shli_i64(t0, arg, 56);
c896fe29 1816
25c4d9cc
RH
1817 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1818 tcg_gen_shli_i64(t1, t1, 40);
1819 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1820
25c4d9cc
RH
1821 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1822 tcg_gen_shli_i64(t1, t1, 24);
1823 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1824
25c4d9cc
RH
1825 tcg_gen_andi_i64(t1, arg, 0xff000000);
1826 tcg_gen_shli_i64(t1, t1, 8);
1827 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1828
25c4d9cc
RH
1829 tcg_gen_shri_i64(t1, arg, 8);
1830 tcg_gen_andi_i64(t1, t1, 0xff000000);
1831 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1832
25c4d9cc
RH
1833 tcg_gen_shri_i64(t1, arg, 24);
1834 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1835 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1836
25c4d9cc
RH
1837 tcg_gen_shri_i64(t1, arg, 40);
1838 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1839 tcg_gen_or_i64(t0, t0, t1);
c896fe29 1840
25c4d9cc
RH
1841 tcg_gen_shri_i64(t1, arg, 56);
1842 tcg_gen_or_i64(ret, t0, t1);
1843 tcg_temp_free_i64(t0);
1844 tcg_temp_free_i64(t1);
1845 }
c896fe29
FB
1846}
1847
1848#endif
1849
a7812ae4 1850static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
390efc54 1851{
25c4d9cc
RH
1852 if (TCG_TARGET_HAS_neg_i32) {
1853 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
1854 } else {
1855 TCGv_i32 t0 = tcg_const_i32(0);
1856 tcg_gen_sub_i32(ret, t0, arg);
1857 tcg_temp_free_i32(t0);
1858 }
390efc54
PB
1859}
1860
a7812ae4 1861static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
390efc54 1862{
25c4d9cc
RH
1863 if (TCG_TARGET_HAS_neg_i64) {
1864 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
1865 } else {
1866 TCGv_i64 t0 = tcg_const_i64(0);
1867 tcg_gen_sub_i64(ret, t0, arg);
1868 tcg_temp_free_i64(t0);
1869 }
390efc54
PB
1870}
1871
a7812ae4 1872static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
0b6ce4cf 1873{
25c4d9cc
RH
1874 if (TCG_TARGET_HAS_not_i32) {
1875 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1876 } else {
1877 tcg_gen_xori_i32(ret, arg, -1);
1878 }
0b6ce4cf
FB
1879}
1880
a7812ae4 1881static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
0b6ce4cf 1882{
25c4d9cc
RH
1883#if TCG_TARGET_REG_BITS == 64
1884 if (TCG_TARGET_HAS_not_i64) {
1885 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
1886 } else {
1887 tcg_gen_xori_i64(ret, arg, -1);
1888 }
1889#else
a10f9f4f
RH
1890 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1891 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
d2604285 1892#endif
0b6ce4cf 1893}
5ff9d6a4 1894
a7812ae4 1895static inline void tcg_gen_discard_i32(TCGv_i32 arg)
5ff9d6a4 1896{
a7812ae4 1897 tcg_gen_op1_i32(INDEX_op_discard, arg);
5ff9d6a4
FB
1898}
1899
a7812ae4 1900static inline void tcg_gen_discard_i64(TCGv_i64 arg)
5ff9d6a4 1901{
25c4d9cc 1902#if TCG_TARGET_REG_BITS == 32
a7812ae4 1903 tcg_gen_discard_i32(TCGV_LOW(arg));
5ff9d6a4 1904 tcg_gen_discard_i32(TCGV_HIGH(arg));
5ff9d6a4 1905#else
a7812ae4 1906 tcg_gen_op1_i64(INDEX_op_discard, arg);
5ff9d6a4 1907#endif
25c4d9cc 1908}
5ff9d6a4 1909
a7812ae4 1910static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1911{
25c4d9cc
RH
1912 if (TCG_TARGET_HAS_andc_i32) {
1913 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1914 } else {
1915 TCGv_i32 t0 = tcg_temp_new_i32();
1916 tcg_gen_not_i32(t0, arg2);
1917 tcg_gen_and_i32(ret, arg1, t0);
1918 tcg_temp_free_i32(t0);
1919 }
f24cb33e
AJ
1920}
1921
a7812ae4 1922static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1923{
25c4d9cc
RH
1924#if TCG_TARGET_REG_BITS == 64
1925 if (TCG_TARGET_HAS_andc_i64) {
1926 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1927 } else {
1928 TCGv_i64 t0 = tcg_temp_new_i64();
1929 tcg_gen_not_i64(t0, arg2);
1930 tcg_gen_and_i64(ret, arg1, t0);
1931 tcg_temp_free_i64(t0);
1932 }
1933#else
241cbed4
RH
1934 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1935 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
241cbed4 1936#endif
f24cb33e
AJ
1937}
1938
a7812ae4 1939static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1940{
25c4d9cc
RH
1941 if (TCG_TARGET_HAS_eqv_i32) {
1942 tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
1943 } else {
1944 tcg_gen_xor_i32(ret, arg1, arg2);
1945 tcg_gen_not_i32(ret, ret);
1946 }
f24cb33e
AJ
1947}
1948
a7812ae4 1949static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1950{
25c4d9cc
RH
1951#if TCG_TARGET_REG_BITS == 64
1952 if (TCG_TARGET_HAS_eqv_i64) {
1953 tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
1954 } else {
1955 tcg_gen_xor_i64(ret, arg1, arg2);
1956 tcg_gen_not_i64(ret, ret);
1957 }
1958#else
8d625cf1
RH
1959 tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1960 tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
8d625cf1 1961#endif
f24cb33e
AJ
1962}
1963
a7812ae4 1964static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1965{
25c4d9cc
RH
1966 if (TCG_TARGET_HAS_nand_i32) {
1967 tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
1968 } else {
1969 tcg_gen_and_i32(ret, arg1, arg2);
1970 tcg_gen_not_i32(ret, ret);
1971 }
f24cb33e
AJ
1972}
1973
a7812ae4 1974static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 1975{
25c4d9cc
RH
1976#if TCG_TARGET_REG_BITS == 64
1977 if (TCG_TARGET_HAS_nand_i64) {
1978 tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
1979 } else {
1980 tcg_gen_and_i64(ret, arg1, arg2);
1981 tcg_gen_not_i64(ret, ret);
1982 }
1983#else
9940a96b
RH
1984 tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1985 tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
9940a96b 1986#endif
f24cb33e
AJ
1987}
1988
a7812ae4 1989static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 1990{
25c4d9cc
RH
1991 if (TCG_TARGET_HAS_nor_i32) {
1992 tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
1993 } else {
1994 tcg_gen_or_i32(ret, arg1, arg2);
1995 tcg_gen_not_i32(ret, ret);
1996 }
f24cb33e
AJ
1997}
1998
a7812ae4 1999static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 2000{
25c4d9cc
RH
2001#if TCG_TARGET_REG_BITS == 64
2002 if (TCG_TARGET_HAS_nor_i64) {
2003 tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
2004 } else {
2005 tcg_gen_or_i64(ret, arg1, arg2);
2006 tcg_gen_not_i64(ret, ret);
2007 }
2008#else
32d98fbd
RH
2009 tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
2010 tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
32d98fbd 2011#endif
f24cb33e
AJ
2012}
2013
a7812ae4 2014static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
f24cb33e 2015{
25c4d9cc
RH
2016 if (TCG_TARGET_HAS_orc_i32) {
2017 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
2018 } else {
2019 TCGv_i32 t0 = tcg_temp_new_i32();
2020 tcg_gen_not_i32(t0, arg2);
2021 tcg_gen_or_i32(ret, arg1, t0);
2022 tcg_temp_free_i32(t0);
2023 }
f24cb33e
AJ
2024}
2025
a7812ae4 2026static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
f24cb33e 2027{
25c4d9cc
RH
2028#if TCG_TARGET_REG_BITS == 64
2029 if (TCG_TARGET_HAS_orc_i64) {
2030 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
2031 } else {
2032 TCGv_i64 t0 = tcg_temp_new_i64();
2033 tcg_gen_not_i64(t0, arg2);
2034 tcg_gen_or_i64(ret, arg1, t0);
2035 tcg_temp_free_i64(t0);
2036 }
2037#else
791d1262
RH
2038 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
2039 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
791d1262 2040#endif
f24cb33e
AJ
2041}
2042
a7812ae4 2043static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
15824571 2044{
25c4d9cc
RH
2045 if (TCG_TARGET_HAS_rot_i32) {
2046 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
2047 } else {
2048 TCGv_i32 t0, t1;
15824571 2049
25c4d9cc
RH
2050 t0 = tcg_temp_new_i32();
2051 t1 = tcg_temp_new_i32();
2052 tcg_gen_shl_i32(t0, arg1, arg2);
2053 tcg_gen_subfi_i32(t1, 32, arg2);
2054 tcg_gen_shr_i32(t1, arg1, t1);
2055 tcg_gen_or_i32(ret, t0, t1);
2056 tcg_temp_free_i32(t0);
2057 tcg_temp_free_i32(t1);
2058 }
15824571
AJ
2059}
2060
a7812ae4 2061static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
15824571 2062{
25c4d9cc
RH
2063 if (TCG_TARGET_HAS_rot_i64) {
2064 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
2065 } else {
2066 TCGv_i64 t0, t1;
2067 t0 = tcg_temp_new_i64();
2068 t1 = tcg_temp_new_i64();
2069 tcg_gen_shl_i64(t0, arg1, arg2);
2070 tcg_gen_subfi_i64(t1, 64, arg2);
2071 tcg_gen_shr_i64(t1, arg1, t1);
2072 tcg_gen_or_i64(ret, t0, t1);
2073 tcg_temp_free_i64(t0);
2074 tcg_temp_free_i64(t1);
2075 }
15824571
AJ
2076}
2077
a7812ae4 2078static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
15824571
AJ
2079{
2080 /* some cases can be optimized here */
2081 if (arg2 == 0) {
2082 tcg_gen_mov_i32(ret, arg1);
25c4d9cc 2083 } else if (TCG_TARGET_HAS_rot_i32) {
d42f183c
AJ
2084 TCGv_i32 t0 = tcg_const_i32(arg2);
2085 tcg_gen_rotl_i32(ret, arg1, t0);
2086 tcg_temp_free_i32(t0);
25c4d9cc 2087 } else {
a7812ae4
PB
2088 TCGv_i32 t0, t1;
2089 t0 = tcg_temp_new_i32();
2090 t1 = tcg_temp_new_i32();
15824571
AJ
2091 tcg_gen_shli_i32(t0, arg1, arg2);
2092 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
2093 tcg_gen_or_i32(ret, t0, t1);
a7812ae4
PB
2094 tcg_temp_free_i32(t0);
2095 tcg_temp_free_i32(t1);
15824571
AJ
2096 }
2097}
2098
a7812ae4 2099static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
15824571
AJ
2100{
2101 /* some cases can be optimized here */
2102 if (arg2 == 0) {
2103 tcg_gen_mov_i64(ret, arg1);
25c4d9cc 2104 } else if (TCG_TARGET_HAS_rot_i64) {
d42f183c
AJ
2105 TCGv_i64 t0 = tcg_const_i64(arg2);
2106 tcg_gen_rotl_i64(ret, arg1, t0);
2107 tcg_temp_free_i64(t0);
25c4d9cc 2108 } else {
a7812ae4
PB
2109 TCGv_i64 t0, t1;
2110 t0 = tcg_temp_new_i64();
2111 t1 = tcg_temp_new_i64();
15824571
AJ
2112 tcg_gen_shli_i64(t0, arg1, arg2);
2113 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
2114 tcg_gen_or_i64(ret, t0, t1);
a7812ae4
PB
2115 tcg_temp_free_i64(t0);
2116 tcg_temp_free_i64(t1);
15824571
AJ
2117 }
2118}
2119
a7812ae4 2120static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
15824571 2121{
25c4d9cc
RH
2122 if (TCG_TARGET_HAS_rot_i32) {
2123 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
2124 } else {
2125 TCGv_i32 t0, t1;
15824571 2126
25c4d9cc
RH
2127 t0 = tcg_temp_new_i32();
2128 t1 = tcg_temp_new_i32();
2129 tcg_gen_shr_i32(t0, arg1, arg2);
2130 tcg_gen_subfi_i32(t1, 32, arg2);
2131 tcg_gen_shl_i32(t1, arg1, t1);
2132 tcg_gen_or_i32(ret, t0, t1);
2133 tcg_temp_free_i32(t0);
2134 tcg_temp_free_i32(t1);
2135 }
15824571
AJ
2136}
2137
a7812ae4 2138static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
15824571 2139{
25c4d9cc
RH
2140 if (TCG_TARGET_HAS_rot_i64) {
2141 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
2142 } else {
2143 TCGv_i64 t0, t1;
2144 t0 = tcg_temp_new_i64();
2145 t1 = tcg_temp_new_i64();
2146 tcg_gen_shr_i64(t0, arg1, arg2);
2147 tcg_gen_subfi_i64(t1, 64, arg2);
2148 tcg_gen_shl_i64(t1, arg1, t1);
2149 tcg_gen_or_i64(ret, t0, t1);
2150 tcg_temp_free_i64(t0);
2151 tcg_temp_free_i64(t1);
2152 }
15824571
AJ
2153}
2154
a7812ae4 2155static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
15824571
AJ
2156{
2157 /* some cases can be optimized here */
2158 if (arg2 == 0) {
2159 tcg_gen_mov_i32(ret, arg1);
2160 } else {
2161 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
2162 }
2163}
2164
a7812ae4 2165static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
15824571
AJ
2166{
2167 /* some cases can be optimized here */
2168 if (arg2 == 0) {
de3526b2 2169 tcg_gen_mov_i64(ret, arg1);
15824571
AJ
2170 } else {
2171 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2172 }
2173}
2174
b7767f0f 2175static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
0756e71c
RH
2176 TCGv_i32 arg2, unsigned int ofs,
2177 unsigned int len)
b7767f0f 2178{
df072774
RH
2179 uint32_t mask;
2180 TCGv_i32 t1;
2181
717e7036
RH
2182 tcg_debug_assert(ofs < 32);
2183 tcg_debug_assert(len <= 32);
2184 tcg_debug_assert(ofs + len <= 32);
2185
df072774
RH
2186 if (ofs == 0 && len == 32) {
2187 tcg_gen_mov_i32(ret, arg2);
2188 return;
2189 }
a4773324 2190 if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
25c4d9cc 2191 tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
df072774
RH
2192 return;
2193 }
2194
2195 mask = (1u << len) - 1;
2196 t1 = tcg_temp_new_i32();
b7767f0f 2197
df072774 2198 if (ofs + len < 32) {
25c4d9cc
RH
2199 tcg_gen_andi_i32(t1, arg2, mask);
2200 tcg_gen_shli_i32(t1, t1, ofs);
df072774
RH
2201 } else {
2202 tcg_gen_shli_i32(t1, arg2, ofs);
25c4d9cc 2203 }
df072774
RH
2204 tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
2205 tcg_gen_or_i32(ret, ret, t1);
2206
2207 tcg_temp_free_i32(t1);
b7767f0f
RH
2208}
2209
2210static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
0756e71c
RH
2211 TCGv_i64 arg2, unsigned int ofs,
2212 unsigned int len)
b7767f0f 2213{
df072774
RH
2214 uint64_t mask;
2215 TCGv_i64 t1;
2216
717e7036
RH
2217 tcg_debug_assert(ofs < 64);
2218 tcg_debug_assert(len <= 64);
2219 tcg_debug_assert(ofs + len <= 64);
2220
df072774
RH
2221 if (ofs == 0 && len == 64) {
2222 tcg_gen_mov_i64(ret, arg2);
2223 return;
2224 }
a4773324 2225 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
25c4d9cc 2226 tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
df072774
RH
2227 return;
2228 }
b7767f0f 2229
df072774
RH
2230#if TCG_TARGET_REG_BITS == 32
2231 if (ofs >= 32) {
2232 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2233 TCGV_LOW(arg2), ofs - 32, len);
ed605126 2234 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
df072774
RH
2235 return;
2236 }
2237 if (ofs + len <= 32) {
2238 tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
2239 TCGV_LOW(arg2), ofs, len);
2f98c9db 2240 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
df072774
RH
2241 return;
2242 }
2243#endif
2244
2245 mask = (1ull << len) - 1;
2246 t1 = tcg_temp_new_i64();
2247
2248 if (ofs + len < 64) {
25c4d9cc
RH
2249 tcg_gen_andi_i64(t1, arg2, mask);
2250 tcg_gen_shli_i64(t1, t1, ofs);
df072774
RH
2251 } else {
2252 tcg_gen_shli_i64(t1, arg2, ofs);
25c4d9cc 2253 }
df072774
RH
2254 tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
2255 tcg_gen_or_i64(ret, ret, t1);
2256
2257 tcg_temp_free_i64(t1);
b7767f0f
RH
2258}
2259
77276f65
RH
2260static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
2261 TCGv_i32 high)
2262{
2263#if TCG_TARGET_REG_BITS == 32
2264 tcg_gen_mov_i32(TCGV_LOW(dest), low);
2265 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
2266#else
2267 TCGv_i64 tmp = tcg_temp_new_i64();
2268 /* These extensions are only needed for type correctness.
2269 We may be able to do better given target specific information. */
2270 tcg_gen_extu_i32_i64(tmp, high);
2271 tcg_gen_extu_i32_i64(dest, low);
2272 /* If deposit is available, use it. Otherwise use the extra
2273 knowledge that we have of the zero-extensions above. */
2274 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(32, 32)) {
2275 tcg_gen_deposit_i64(dest, dest, tmp, 32, 32);
2276 } else {
2277 tcg_gen_shli_i64(tmp, tmp, 32);
2278 tcg_gen_or_i64(dest, dest, tmp);
2279 }
2280 tcg_temp_free_i64(tmp);
2281#endif
2282}
2283
2284static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low,
2285 TCGv_i64 high)
2286{
2287 tcg_gen_deposit_i64(dest, low, high, 32, 32);
2288}
2289
4bb7a41e
RH
2290static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
2291{
2292 tcg_gen_trunc_shr_i64_i32(ret, arg, 0);
2293}
2294
3c51a985
RH
2295static inline void tcg_gen_extr_i64_i32(TCGv_i32 lo, TCGv_i32 hi, TCGv_i64 arg)
2296{
4bb7a41e
RH
2297 tcg_gen_trunc_shr_i64_i32(lo, arg, 0);
2298 tcg_gen_trunc_shr_i64_i32(hi, arg, 32);
3c51a985
RH
2299}
2300
2301static inline void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)
2302{
2303 tcg_gen_ext32u_i64(lo, arg);
2304 tcg_gen_shri_i64(hi, arg, 32);
2305}
2306
ffc5ea09
RH
2307static inline void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret,
2308 TCGv_i32 c1, TCGv_i32 c2,
2309 TCGv_i32 v1, TCGv_i32 v2)
2310{
2311 if (TCG_TARGET_HAS_movcond_i32) {
2312 tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond);
2313 } else {
2314 TCGv_i32 t0 = tcg_temp_new_i32();
2315 TCGv_i32 t1 = tcg_temp_new_i32();
2316 tcg_gen_setcond_i32(cond, t0, c1, c2);
2317 tcg_gen_neg_i32(t0, t0);
2318 tcg_gen_and_i32(t1, v1, t0);
2319 tcg_gen_andc_i32(ret, v2, t0);
2320 tcg_gen_or_i32(ret, ret, t1);
2321 tcg_temp_free_i32(t0);
2322 tcg_temp_free_i32(t1);
2323 }
2324}
2325
2326static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
2327 TCGv_i64 c1, TCGv_i64 c2,
2328 TCGv_i64 v1, TCGv_i64 v2)
2329{
a463133e
RH
2330#if TCG_TARGET_REG_BITS == 32
2331 TCGv_i32 t0 = tcg_temp_new_i32();
2332 TCGv_i32 t1 = tcg_temp_new_i32();
2333 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
2334 TCGV_LOW(c1), TCGV_HIGH(c1),
2335 TCGV_LOW(c2), TCGV_HIGH(c2), cond);
a463133e 2336
a80a6b63
RH
2337 if (TCG_TARGET_HAS_movcond_i32) {
2338 tcg_gen_movi_i32(t1, 0);
2339 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
2340 TCGV_LOW(v1), TCGV_LOW(v2));
2341 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
2342 TCGV_HIGH(v1), TCGV_HIGH(v2));
2343 } else {
2344 tcg_gen_neg_i32(t0, t0);
a463133e 2345
a80a6b63
RH
2346 tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
2347 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
2348 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
a463133e 2349
a80a6b63
RH
2350 tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
2351 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
2352 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
2353 }
a463133e
RH
2354 tcg_temp_free_i32(t0);
2355 tcg_temp_free_i32(t1);
2356#else
ffc5ea09
RH
2357 if (TCG_TARGET_HAS_movcond_i64) {
2358 tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond);
2359 } else {
2360 TCGv_i64 t0 = tcg_temp_new_i64();
2361 TCGv_i64 t1 = tcg_temp_new_i64();
2362 tcg_gen_setcond_i64(cond, t0, c1, c2);
2363 tcg_gen_neg_i64(t0, t0);
2364 tcg_gen_and_i64(t1, v1, t0);
2365 tcg_gen_andc_i64(ret, v2, t0);
2366 tcg_gen_or_i64(ret, ret, t1);
2367 tcg_temp_free_i64(t0);
2368 tcg_temp_free_i64(t1);
2369 }
a463133e 2370#endif
ffc5ea09
RH
2371}
2372
f6953a73
RH
2373static inline void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2374 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2375{
2376 if (TCG_TARGET_HAS_add2_i32) {
2377 tcg_gen_op6_i32(INDEX_op_add2_i32, rl, rh, al, ah, bl, bh);
2378 /* Allow the optimizer room to replace add2 with two moves. */
2379 tcg_gen_op0(INDEX_op_nop);
2380 } else {
2381 TCGv_i64 t0 = tcg_temp_new_i64();
2382 TCGv_i64 t1 = tcg_temp_new_i64();
2383 tcg_gen_concat_i32_i64(t0, al, ah);
2384 tcg_gen_concat_i32_i64(t1, bl, bh);
2385 tcg_gen_add_i64(t0, t0, t1);
2386 tcg_gen_extr_i64_i32(rl, rh, t0);
2387 tcg_temp_free_i64(t0);
2388 tcg_temp_free_i64(t1);
2389 }
2390}
2391
2392static inline void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2393 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2394{
2395 if (TCG_TARGET_HAS_sub2_i32) {
2396 tcg_gen_op6_i32(INDEX_op_sub2_i32, rl, rh, al, ah, bl, bh);
2397 /* Allow the optimizer room to replace sub2 with two moves. */
2398 tcg_gen_op0(INDEX_op_nop);
2399 } else {
2400 TCGv_i64 t0 = tcg_temp_new_i64();
2401 TCGv_i64 t1 = tcg_temp_new_i64();
2402 tcg_gen_concat_i32_i64(t0, al, ah);
2403 tcg_gen_concat_i32_i64(t1, bl, bh);
2404 tcg_gen_sub_i64(t0, t0, t1);
2405 tcg_gen_extr_i64_i32(rl, rh, t0);
2406 tcg_temp_free_i64(t0);
2407 tcg_temp_free_i64(t1);
2408 }
2409}
2410
696a8be6
RH
2411static inline void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh,
2412 TCGv_i32 arg1, TCGv_i32 arg2)
2413{
2414 if (TCG_TARGET_HAS_mulu2_i32) {
2415 tcg_gen_op4_i32(INDEX_op_mulu2_i32, rl, rh, arg1, arg2);
2416 /* Allow the optimizer room to replace mulu2 with two moves. */
2417 tcg_gen_op0(INDEX_op_nop);
03271524
RH
2418 } else if (TCG_TARGET_HAS_muluh_i32) {
2419 TCGv_i32 t = tcg_temp_new_i32();
2420 tcg_gen_op3_i32(INDEX_op_mul_i32, t, arg1, arg2);
2421 tcg_gen_op3_i32(INDEX_op_muluh_i32, rh, arg1, arg2);
2422 tcg_gen_mov_i32(rl, t);
2423 tcg_temp_free_i32(t);
696a8be6
RH
2424 } else {
2425 TCGv_i64 t0 = tcg_temp_new_i64();
2426 TCGv_i64 t1 = tcg_temp_new_i64();
2427 tcg_gen_extu_i32_i64(t0, arg1);
2428 tcg_gen_extu_i32_i64(t1, arg2);
2429 tcg_gen_mul_i64(t0, t0, t1);
2430 tcg_gen_extr_i64_i32(rl, rh, t0);
2431 tcg_temp_free_i64(t0);
2432 tcg_temp_free_i64(t1);
2433 }
2434}
2435
2436static inline void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh,
2437 TCGv_i32 arg1, TCGv_i32 arg2)
2438{
2439 if (TCG_TARGET_HAS_muls2_i32) {
2440 tcg_gen_op4_i32(INDEX_op_muls2_i32, rl, rh, arg1, arg2);
2441 /* Allow the optimizer room to replace muls2 with two moves. */
2442 tcg_gen_op0(INDEX_op_nop);
03271524
RH
2443 } else if (TCG_TARGET_HAS_mulsh_i32) {
2444 TCGv_i32 t = tcg_temp_new_i32();
2445 tcg_gen_op3_i32(INDEX_op_mul_i32, t, arg1, arg2);
2446 tcg_gen_op3_i32(INDEX_op_mulsh_i32, rh, arg1, arg2);
2447 tcg_gen_mov_i32(rl, t);
2448 tcg_temp_free_i32(t);
f46fc4e6 2449 } else if (TCG_TARGET_REG_BITS == 32) {
f402f38f
RH
2450 TCGv_i32 t0 = tcg_temp_new_i32();
2451 TCGv_i32 t1 = tcg_temp_new_i32();
2452 TCGv_i32 t2 = tcg_temp_new_i32();
2453 TCGv_i32 t3 = tcg_temp_new_i32();
f46fc4e6 2454 tcg_gen_mulu2_i32(t0, t1, arg1, arg2);
f402f38f
RH
2455 /* Adjust for negative inputs. */
2456 tcg_gen_sari_i32(t2, arg1, 31);
2457 tcg_gen_sari_i32(t3, arg2, 31);
2458 tcg_gen_and_i32(t2, t2, arg2);
2459 tcg_gen_and_i32(t3, t3, arg1);
2460 tcg_gen_sub_i32(rh, t1, t2);
2461 tcg_gen_sub_i32(rh, rh, t3);
2462 tcg_gen_mov_i32(rl, t0);
2463 tcg_temp_free_i32(t0);
2464 tcg_temp_free_i32(t1);
2465 tcg_temp_free_i32(t2);
2466 tcg_temp_free_i32(t3);
696a8be6
RH
2467 } else {
2468 TCGv_i64 t0 = tcg_temp_new_i64();
2469 TCGv_i64 t1 = tcg_temp_new_i64();
2470 tcg_gen_ext_i32_i64(t0, arg1);
2471 tcg_gen_ext_i32_i64(t1, arg2);
2472 tcg_gen_mul_i64(t0, t0, t1);
2473 tcg_gen_extr_i64_i32(rl, rh, t0);
2474 tcg_temp_free_i64(t0);
2475 tcg_temp_free_i64(t1);
2476 }
2477}
2478
f6953a73
RH
2479static inline void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2480 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2481{
2482 if (TCG_TARGET_HAS_add2_i64) {
2483 tcg_gen_op6_i64(INDEX_op_add2_i64, rl, rh, al, ah, bl, bh);
2484 /* Allow the optimizer room to replace add2 with two moves. */
2485 tcg_gen_op0(INDEX_op_nop);
2486 } else {
2487 TCGv_i64 t0 = tcg_temp_new_i64();
2488 TCGv_i64 t1 = tcg_temp_new_i64();
2489 tcg_gen_add_i64(t0, al, bl);
2490 tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, al);
2491 tcg_gen_add_i64(rh, ah, bh);
2492 tcg_gen_add_i64(rh, rh, t1);
2493 tcg_gen_mov_i64(rl, t0);
2494 tcg_temp_free_i64(t0);
2495 tcg_temp_free_i64(t1);
2496 }
2497}
2498
2499static inline void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2500 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2501{
2502 if (TCG_TARGET_HAS_sub2_i64) {
2503 tcg_gen_op6_i64(INDEX_op_sub2_i64, rl, rh, al, ah, bl, bh);
2504 /* Allow the optimizer room to replace sub2 with two moves. */
2505 tcg_gen_op0(INDEX_op_nop);
2506 } else {
2507 TCGv_i64 t0 = tcg_temp_new_i64();
2508 TCGv_i64 t1 = tcg_temp_new_i64();
2509 tcg_gen_sub_i64(t0, al, bl);
2510 tcg_gen_setcond_i64(TCG_COND_LTU, t1, al, bl);
2511 tcg_gen_sub_i64(rh, ah, bh);
2512 tcg_gen_sub_i64(rh, rh, t1);
2513 tcg_gen_mov_i64(rl, t0);
2514 tcg_temp_free_i64(t0);
2515 tcg_temp_free_i64(t1);
2516 }
2517}
2518
696a8be6
RH
2519static inline void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh,
2520 TCGv_i64 arg1, TCGv_i64 arg2)
2521{
2522 if (TCG_TARGET_HAS_mulu2_i64) {
2523 tcg_gen_op4_i64(INDEX_op_mulu2_i64, rl, rh, arg1, arg2);
2524 /* Allow the optimizer room to replace mulu2 with two moves. */
2525 tcg_gen_op0(INDEX_op_nop);
03271524
RH
2526 } else if (TCG_TARGET_HAS_muluh_i64) {
2527 TCGv_i64 t = tcg_temp_new_i64();
2528 tcg_gen_op3_i64(INDEX_op_mul_i64, t, arg1, arg2);
2529 tcg_gen_op3_i64(INDEX_op_muluh_i64, rh, arg1, arg2);
2530 tcg_gen_mov_i64(rl, t);
2531 tcg_temp_free_i64(t);
696a8be6
RH
2532 } else {
2533 TCGv_i64 t0 = tcg_temp_new_i64();
2534 int sizemask = 0;
2535 /* Return value and both arguments are 64-bit and unsigned. */
2536 sizemask |= tcg_gen_sizemask(0, 1, 0);
2537 sizemask |= tcg_gen_sizemask(1, 1, 0);
2538 sizemask |= tcg_gen_sizemask(2, 1, 0);
2539 tcg_gen_mul_i64(t0, arg1, arg2);
944eea96 2540 tcg_gen_helper64(helper_muluh_i64, sizemask, rh, arg1, arg2);
696a8be6
RH
2541 tcg_gen_mov_i64(rl, t0);
2542 tcg_temp_free_i64(t0);
2543 }
2544}
2545
2546static inline void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh,
2547 TCGv_i64 arg1, TCGv_i64 arg2)
2548{
2549 if (TCG_TARGET_HAS_muls2_i64) {
2550 tcg_gen_op4_i64(INDEX_op_muls2_i64, rl, rh, arg1, arg2);
2551 /* Allow the optimizer room to replace muls2 with two moves. */
2552 tcg_gen_op0(INDEX_op_nop);
03271524
RH
2553 } else if (TCG_TARGET_HAS_mulsh_i64) {
2554 TCGv_i64 t = tcg_temp_new_i64();
2555 tcg_gen_op3_i64(INDEX_op_mul_i64, t, arg1, arg2);
2556 tcg_gen_op3_i64(INDEX_op_mulsh_i64, rh, arg1, arg2);
2557 tcg_gen_mov_i64(rl, t);
2558 tcg_temp_free_i64(t);
662deb90
RH
2559 } else if (TCG_TARGET_HAS_mulu2_i64 || TCG_TARGET_HAS_muluh_i64) {
2560 TCGv_i64 t0 = tcg_temp_new_i64();
2561 TCGv_i64 t1 = tcg_temp_new_i64();
2562 TCGv_i64 t2 = tcg_temp_new_i64();
2563 TCGv_i64 t3 = tcg_temp_new_i64();
2564 tcg_gen_mulu2_i64(t0, t1, arg1, arg2);
2565 /* Adjust for negative inputs. */
2566 tcg_gen_sari_i64(t2, arg1, 63);
2567 tcg_gen_sari_i64(t3, arg2, 63);
2568 tcg_gen_and_i64(t2, t2, arg2);
2569 tcg_gen_and_i64(t3, t3, arg1);
2570 tcg_gen_sub_i64(rh, t1, t2);
2571 tcg_gen_sub_i64(rh, rh, t3);
2572 tcg_gen_mov_i64(rl, t0);
2573 tcg_temp_free_i64(t0);
2574 tcg_temp_free_i64(t1);
2575 tcg_temp_free_i64(t2);
2576 tcg_temp_free_i64(t3);
696a8be6
RH
2577 } else {
2578 TCGv_i64 t0 = tcg_temp_new_i64();
2579 int sizemask = 0;
2580 /* Return value and both arguments are 64-bit and signed. */
2581 sizemask |= tcg_gen_sizemask(0, 1, 1);
2582 sizemask |= tcg_gen_sizemask(1, 1, 1);
2583 sizemask |= tcg_gen_sizemask(2, 1, 1);
2584 tcg_gen_mul_i64(t0, arg1, arg2);
944eea96 2585 tcg_gen_helper64(helper_mulsh_i64, sizemask, rh, arg1, arg2);
696a8be6
RH
2586 tcg_gen_mov_i64(rl, t0);
2587 tcg_temp_free_i64(t0);
2588 }
2589}
2590
c896fe29
FB
2591/***************************************/
2592/* QEMU specific operations. Their type depend on the QEMU CPU
2593 type. */
2594#ifndef TARGET_LONG_BITS
2595#error must include QEMU headers
2596#endif
2597
a7812ae4
PB
2598#if TARGET_LONG_BITS == 32
2599#define TCGv TCGv_i32
2600#define tcg_temp_new() tcg_temp_new_i32()
2601#define tcg_global_reg_new tcg_global_reg_new_i32
2602#define tcg_global_mem_new tcg_global_mem_new_i32
df9247b2 2603#define tcg_temp_local_new() tcg_temp_local_new_i32()
a7812ae4 2604#define tcg_temp_free tcg_temp_free_i32
a7812ae4 2605#define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
afcb92be 2606#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I32(x)
fe75bcf7 2607#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
f713d6ad
RH
2608#define tcg_add_param_tl tcg_add_param_i32
2609#define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i32
2610#define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i32
a7812ae4
PB
2611#else
2612#define TCGv TCGv_i64
2613#define tcg_temp_new() tcg_temp_new_i64()
2614#define tcg_global_reg_new tcg_global_reg_new_i64
2615#define tcg_global_mem_new tcg_global_mem_new_i64
df9247b2 2616#define tcg_temp_local_new() tcg_temp_local_new_i64()
a7812ae4 2617#define tcg_temp_free tcg_temp_free_i64
a7812ae4 2618#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
afcb92be 2619#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I64(x)
fe75bcf7 2620#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
f713d6ad
RH
2621#define tcg_add_param_tl tcg_add_param_i64
2622#define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i64
2623#define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i64
a7812ae4
PB
2624#endif
2625
7e4597d7
FB
2626/* debug info: write the PC of the corresponding QEMU CPU instruction */
2627static inline void tcg_gen_debug_insn_start(uint64_t pc)
2628{
2629 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2630#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
bcb0126f
PB
2631 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2632 (uint32_t)(pc), (uint32_t)(pc >> 32));
7e4597d7
FB
2633#else
2634 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2635#endif
2636}
2637
8cfd0495 2638static inline void tcg_gen_exit_tb(uintptr_t val)
c896fe29 2639{
ac56dd48 2640 tcg_gen_op1i(INDEX_op_exit_tb, val);
c896fe29
FB
2641}
2642
0a209d4b
RH
2643static inline void tcg_gen_goto_tb(unsigned idx)
2644{
2645 /* We only support two chained exits. */
2646 tcg_debug_assert(idx <= 1);
2647#ifdef CONFIG_DEBUG_TCG
2648 /* Verify that we havn't seen this numbered exit before. */
2649 tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
2650 tcg_ctx.goto_tb_issue_mask |= 1 << idx;
2651#endif
ac56dd48 2652 tcg_gen_op1i(INDEX_op_goto_tb, idx);
c896fe29
FB
2653}
2654
c896fe29 2655
f713d6ad
RH
2656void tcg_gen_qemu_ld_i32(TCGv_i32, TCGv, TCGArg, TCGMemOp);
2657void tcg_gen_qemu_st_i32(TCGv_i32, TCGv, TCGArg, TCGMemOp);
2658void tcg_gen_qemu_ld_i64(TCGv_i64, TCGv, TCGArg, TCGMemOp);
2659void tcg_gen_qemu_st_i64(TCGv_i64, TCGv, TCGArg, TCGMemOp);
c896fe29 2660
ac56dd48 2661static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2662{
f713d6ad 2663 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_UB);
c896fe29
FB
2664}
2665
ac56dd48 2666static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2667{
f713d6ad 2668 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_SB);
c896fe29
FB
2669}
2670
ac56dd48 2671static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2672{
f713d6ad 2673 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TEUW);
c896fe29
FB
2674}
2675
ac56dd48 2676static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2677{
f713d6ad 2678 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TESW);
c896fe29
FB
2679}
2680
ac56dd48 2681static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
c896fe29 2682{
f713d6ad 2683 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TEUL);
c896fe29
FB
2684}
2685
ac56dd48 2686static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
c896fe29 2687{
f713d6ad 2688 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TESL);
c896fe29
FB
2689}
2690
a7812ae4 2691static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
c896fe29 2692{
f713d6ad 2693 tcg_gen_qemu_ld_i64(ret, addr, mem_index, MO_TEQ);
c896fe29
FB
2694}
2695
ac56dd48 2696static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
c896fe29 2697{
f713d6ad 2698 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_UB);
c896fe29
FB
2699}
2700
ac56dd48 2701static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
c896fe29 2702{
f713d6ad 2703 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_TEUW);
c896fe29
FB
2704}
2705
ac56dd48 2706static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
c896fe29 2707{
f713d6ad 2708 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_TEUL);
c896fe29
FB
2709}
2710
a7812ae4 2711static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
c896fe29 2712{
f713d6ad 2713 tcg_gen_qemu_st_i64(arg, addr, mem_index, MO_TEQ);
c896fe29
FB
2714}
2715
f8422f52 2716#if TARGET_LONG_BITS == 64
f8422f52
BS
2717#define tcg_gen_movi_tl tcg_gen_movi_i64
2718#define tcg_gen_mov_tl tcg_gen_mov_i64
2719#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2720#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2721#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2722#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2723#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2724#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2725#define tcg_gen_ld_tl tcg_gen_ld_i64
2726#define tcg_gen_st8_tl tcg_gen_st8_i64
2727#define tcg_gen_st16_tl tcg_gen_st16_i64
2728#define tcg_gen_st32_tl tcg_gen_st32_i64
2729#define tcg_gen_st_tl tcg_gen_st_i64
2730#define tcg_gen_add_tl tcg_gen_add_i64
2731#define tcg_gen_addi_tl tcg_gen_addi_i64
2732#define tcg_gen_sub_tl tcg_gen_sub_i64
390efc54 2733#define tcg_gen_neg_tl tcg_gen_neg_i64
10460c8a 2734#define tcg_gen_subfi_tl tcg_gen_subfi_i64
f8422f52
BS
2735#define tcg_gen_subi_tl tcg_gen_subi_i64
2736#define tcg_gen_and_tl tcg_gen_and_i64
2737#define tcg_gen_andi_tl tcg_gen_andi_i64
2738#define tcg_gen_or_tl tcg_gen_or_i64
2739#define tcg_gen_ori_tl tcg_gen_ori_i64
2740#define tcg_gen_xor_tl tcg_gen_xor_i64
2741#define tcg_gen_xori_tl tcg_gen_xori_i64
0b6ce4cf 2742#define tcg_gen_not_tl tcg_gen_not_i64
f8422f52
BS
2743#define tcg_gen_shl_tl tcg_gen_shl_i64
2744#define tcg_gen_shli_tl tcg_gen_shli_i64
2745#define tcg_gen_shr_tl tcg_gen_shr_i64
2746#define tcg_gen_shri_tl tcg_gen_shri_i64
2747#define tcg_gen_sar_tl tcg_gen_sar_i64
2748#define tcg_gen_sari_tl tcg_gen_sari_i64
0cf767d6 2749#define tcg_gen_brcond_tl tcg_gen_brcond_i64
cb63669a 2750#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
be210acb 2751#define tcg_gen_setcond_tl tcg_gen_setcond_i64
add1e7ea 2752#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
f730fd27
TS
2753#define tcg_gen_mul_tl tcg_gen_mul_i64
2754#define tcg_gen_muli_tl tcg_gen_muli_i64
ab36421e
AJ
2755#define tcg_gen_div_tl tcg_gen_div_i64
2756#define tcg_gen_rem_tl tcg_gen_rem_i64
864951af
AJ
2757#define tcg_gen_divu_tl tcg_gen_divu_i64
2758#define tcg_gen_remu_tl tcg_gen_remu_i64
a768e4b2 2759#define tcg_gen_discard_tl tcg_gen_discard_i64
e429073d
BS
2760#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2761#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2762#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2763#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2764#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2765#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
0b6ce4cf
FB
2766#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2767#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2768#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2769#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2770#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2771#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
911d79ba
AJ
2772#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2773#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2774#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
945ca823 2775#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
3c51a985 2776#define tcg_gen_extr_i64_tl tcg_gen_extr32_i64
f24cb33e
AJ
2777#define tcg_gen_andc_tl tcg_gen_andc_i64
2778#define tcg_gen_eqv_tl tcg_gen_eqv_i64
2779#define tcg_gen_nand_tl tcg_gen_nand_i64
2780#define tcg_gen_nor_tl tcg_gen_nor_i64
2781#define tcg_gen_orc_tl tcg_gen_orc_i64
15824571
AJ
2782#define tcg_gen_rotl_tl tcg_gen_rotl_i64
2783#define tcg_gen_rotli_tl tcg_gen_rotli_i64
2784#define tcg_gen_rotr_tl tcg_gen_rotr_i64
2785#define tcg_gen_rotri_tl tcg_gen_rotri_i64
b7767f0f 2786#define tcg_gen_deposit_tl tcg_gen_deposit_i64
a98824ac 2787#define tcg_const_tl tcg_const_i64
bdffd4a9 2788#define tcg_const_local_tl tcg_const_local_i64
ffc5ea09 2789#define tcg_gen_movcond_tl tcg_gen_movcond_i64
f6953a73
RH
2790#define tcg_gen_add2_tl tcg_gen_add2_i64
2791#define tcg_gen_sub2_tl tcg_gen_sub2_i64
696a8be6
RH
2792#define tcg_gen_mulu2_tl tcg_gen_mulu2_i64
2793#define tcg_gen_muls2_tl tcg_gen_muls2_i64
f8422f52 2794#else
f8422f52
BS
2795#define tcg_gen_movi_tl tcg_gen_movi_i32
2796#define tcg_gen_mov_tl tcg_gen_mov_i32
2797#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2798#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2799#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2800#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2801#define tcg_gen_ld32u_tl tcg_gen_ld_i32
2802#define tcg_gen_ld32s_tl tcg_gen_ld_i32
2803#define tcg_gen_ld_tl tcg_gen_ld_i32
2804#define tcg_gen_st8_tl tcg_gen_st8_i32
2805#define tcg_gen_st16_tl tcg_gen_st16_i32
2806#define tcg_gen_st32_tl tcg_gen_st_i32
2807#define tcg_gen_st_tl tcg_gen_st_i32
2808#define tcg_gen_add_tl tcg_gen_add_i32
2809#define tcg_gen_addi_tl tcg_gen_addi_i32
2810#define tcg_gen_sub_tl tcg_gen_sub_i32
390efc54 2811#define tcg_gen_neg_tl tcg_gen_neg_i32
0045734a 2812#define tcg_gen_subfi_tl tcg_gen_subfi_i32
f8422f52
BS
2813#define tcg_gen_subi_tl tcg_gen_subi_i32
2814#define tcg_gen_and_tl tcg_gen_and_i32
2815#define tcg_gen_andi_tl tcg_gen_andi_i32
2816#define tcg_gen_or_tl tcg_gen_or_i32
2817#define tcg_gen_ori_tl tcg_gen_ori_i32
2818#define tcg_gen_xor_tl tcg_gen_xor_i32
2819#define tcg_gen_xori_tl tcg_gen_xori_i32
0b6ce4cf 2820#define tcg_gen_not_tl tcg_gen_not_i32
f8422f52
BS
2821#define tcg_gen_shl_tl tcg_gen_shl_i32
2822#define tcg_gen_shli_tl tcg_gen_shli_i32
2823#define tcg_gen_shr_tl tcg_gen_shr_i32
2824#define tcg_gen_shri_tl tcg_gen_shri_i32
2825#define tcg_gen_sar_tl tcg_gen_sar_i32
2826#define tcg_gen_sari_tl tcg_gen_sari_i32
0cf767d6 2827#define tcg_gen_brcond_tl tcg_gen_brcond_i32
cb63669a 2828#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
be210acb 2829#define tcg_gen_setcond_tl tcg_gen_setcond_i32
add1e7ea 2830#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
f730fd27
TS
2831#define tcg_gen_mul_tl tcg_gen_mul_i32
2832#define tcg_gen_muli_tl tcg_gen_muli_i32
ab36421e
AJ
2833#define tcg_gen_div_tl tcg_gen_div_i32
2834#define tcg_gen_rem_tl tcg_gen_rem_i32
864951af
AJ
2835#define tcg_gen_divu_tl tcg_gen_divu_i32
2836#define tcg_gen_remu_tl tcg_gen_remu_i32
a768e4b2 2837#define tcg_gen_discard_tl tcg_gen_discard_i32
e429073d
BS
2838#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2839#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2840#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2841#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2842#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2843#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
0b6ce4cf
FB
2844#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2845#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2846#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2847#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2848#define tcg_gen_ext32u_tl tcg_gen_mov_i32
2849#define tcg_gen_ext32s_tl tcg_gen_mov_i32
911d79ba
AJ
2850#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2851#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
945ca823 2852#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
3c51a985 2853#define tcg_gen_extr_tl_i64 tcg_gen_extr_i32_i64
f24cb33e
AJ
2854#define tcg_gen_andc_tl tcg_gen_andc_i32
2855#define tcg_gen_eqv_tl tcg_gen_eqv_i32
2856#define tcg_gen_nand_tl tcg_gen_nand_i32
2857#define tcg_gen_nor_tl tcg_gen_nor_i32
2858#define tcg_gen_orc_tl tcg_gen_orc_i32
15824571
AJ
2859#define tcg_gen_rotl_tl tcg_gen_rotl_i32
2860#define tcg_gen_rotli_tl tcg_gen_rotli_i32
2861#define tcg_gen_rotr_tl tcg_gen_rotr_i32
2862#define tcg_gen_rotri_tl tcg_gen_rotri_i32
b7767f0f 2863#define tcg_gen_deposit_tl tcg_gen_deposit_i32
a98824ac 2864#define tcg_const_tl tcg_const_i32
bdffd4a9 2865#define tcg_const_local_tl tcg_const_local_i32
ffc5ea09 2866#define tcg_gen_movcond_tl tcg_gen_movcond_i32
f6953a73
RH
2867#define tcg_gen_add2_tl tcg_gen_add2_i32
2868#define tcg_gen_sub2_tl tcg_gen_sub2_i32
696a8be6
RH
2869#define tcg_gen_mulu2_tl tcg_gen_mulu2_i32
2870#define tcg_gen_muls2_tl tcg_gen_muls2_i32
f8422f52 2871#endif
6ddbc6e4 2872
71b92699 2873#if UINTPTR_MAX == UINT32_MAX
f713d6ad
RH
2874# define tcg_gen_ld_ptr(R, A, O) \
2875 tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2876# define tcg_gen_discard_ptr(A) \
2877 tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
2878# define tcg_gen_add_ptr(R, A, B) \
2879 tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), TCGV_PTR_TO_NAT(B))
2880# define tcg_gen_addi_ptr(R, A, B) \
2881 tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), (B))
2882# define tcg_gen_ext_i32_ptr(R, A) \
2883 tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
2884#else
2885# define tcg_gen_ld_ptr(R, A, O) \
2886 tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2887# define tcg_gen_discard_ptr(A) \
2888 tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
2889# define tcg_gen_add_ptr(R, A, B) \
2890 tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), TCGV_PTR_TO_NAT(B))
2891# define tcg_gen_addi_ptr(R, A, B) \
2892 tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), (B))
2893# define tcg_gen_ext_i32_ptr(R, A) \
2894 tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
71b92699 2895#endif /* UINTPTR_MAX == UINT32_MAX */
This page took 1.100809 seconds and 4 git commands to generate.