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