blob: f15c80351b47c653aaf7b34419af307749bb06ce [file] [log] [blame]
bellardc896fe22008-02-01 10:05:41 +00001/*
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
bellardc896fe22008-02-01 10:05:41 +000026int gen_new_label(void);
27
Richard Hendersona9751602010-03-19 11:12:29 -070028static inline void tcg_gen_op1_i32(TCGOpcode opc, TCGv_i32 arg1)
pbrookac56dd42008-02-03 19:56:33 +000029{
30 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +000031 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
32}
33
Richard Hendersona9751602010-03-19 11:12:29 -070034static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
pbrooka7812ae2008-11-17 14:43:54 +000035{
36 *gen_opc_ptr++ = opc;
37 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
pbrookac56dd42008-02-03 19:56:33 +000038}
39
Richard Hendersona9751602010-03-19 11:12:29 -070040static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg arg1)
bellardc896fe22008-02-01 10:05:41 +000041{
42 *gen_opc_ptr++ = opc;
43 *gen_opparam_ptr++ = arg1;
44}
45
Richard Hendersona9751602010-03-19 11:12:29 -070046static inline void tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +000047{
48 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +000049 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
50 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
pbrookac56dd42008-02-03 19:56:33 +000051}
52
Richard Hendersona9751602010-03-19 11:12:29 -070053static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
pbrookac56dd42008-02-03 19:56:33 +000054{
55 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +000056 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
57 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
58}
59
Richard Hendersona9751602010-03-19 11:12:29 -070060static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
pbrooka7812ae2008-11-17 14:43:54 +000061{
62 *gen_opc_ptr++ = opc;
63 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
64 *gen_opparam_ptr++ = arg2;
65}
66
Richard Hendersona9751602010-03-19 11:12:29 -070067static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
pbrooka7812ae2008-11-17 14:43:54 +000068{
69 *gen_opc_ptr++ = opc;
70 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
bellardc896fe22008-02-01 10:05:41 +000071 *gen_opparam_ptr++ = arg2;
72}
73
Richard Hendersona9751602010-03-19 11:12:29 -070074static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg arg1, TCGArg arg2)
pbrookbcb01262008-05-24 02:24:25 +000075{
76 *gen_opc_ptr++ = opc;
77 *gen_opparam_ptr++ = arg1;
78 *gen_opparam_ptr++ = arg2;
79}
80
Richard Hendersona9751602010-03-19 11:12:29 -070081static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +000082 TCGv_i32 arg3)
bellardc896fe22008-02-01 10:05:41 +000083{
84 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +000085 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
86 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
87 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
pbrookac56dd42008-02-03 19:56:33 +000088}
89
Richard Hendersona9751602010-03-19 11:12:29 -070090static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +000091 TCGv_i64 arg3)
pbrookac56dd42008-02-03 19:56:33 +000092{
93 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +000094 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
95 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
96 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
97}
98
Richard Hendersona9751602010-03-19 11:12:29 -070099static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
100 TCGv_i32 arg2, TCGArg arg3)
pbrooka7812ae2008-11-17 14:43:54 +0000101{
102 *gen_opc_ptr++ = opc;
103 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
104 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
bellardc896fe22008-02-01 10:05:41 +0000105 *gen_opparam_ptr++ = arg3;
106}
107
Richard Hendersona9751602010-03-19 11:12:29 -0700108static inline void tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 arg1,
109 TCGv_i64 arg2, TCGArg arg3)
bellardc896fe22008-02-01 10:05:41 +0000110{
111 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +0000112 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
113 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
114 *gen_opparam_ptr++ = arg3;
pbrookac56dd42008-02-03 19:56:33 +0000115}
116
Richard Hendersona9751602010-03-19 11:12:29 -0700117static inline void tcg_gen_ldst_op_i32(TCGOpcode opc, TCGv_i32 val,
118 TCGv_ptr base, TCGArg offset)
pbrookac56dd42008-02-03 19:56:33 +0000119{
120 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +0000121 *gen_opparam_ptr++ = GET_TCGV_I32(val);
122 *gen_opparam_ptr++ = GET_TCGV_PTR(base);
123 *gen_opparam_ptr++ = offset;
124}
125
Richard Hendersona9751602010-03-19 11:12:29 -0700126static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
127 TCGv_ptr base, TCGArg offset)
pbrooka7812ae2008-11-17 14:43:54 +0000128{
129 *gen_opc_ptr++ = opc;
blueswir1a810a2d2008-12-07 17:16:42 +0000130 *gen_opparam_ptr++ = GET_TCGV_I64(val);
pbrooka7812ae2008-11-17 14:43:54 +0000131 *gen_opparam_ptr++ = GET_TCGV_PTR(base);
132 *gen_opparam_ptr++ = offset;
133}
134
Richard Hendersona9751602010-03-19 11:12:29 -0700135static inline void tcg_gen_qemu_ldst_op_i64_i32(TCGOpcode opc, TCGv_i64 val,
136 TCGv_i32 addr, TCGArg mem_index)
pbrooka7812ae2008-11-17 14:43:54 +0000137{
138 *gen_opc_ptr++ = opc;
139 *gen_opparam_ptr++ = GET_TCGV_I64(val);
140 *gen_opparam_ptr++ = GET_TCGV_I32(addr);
141 *gen_opparam_ptr++ = mem_index;
142}
143
Richard Hendersona9751602010-03-19 11:12:29 -0700144static inline void tcg_gen_qemu_ldst_op_i64_i64(TCGOpcode opc, TCGv_i64 val,
145 TCGv_i64 addr, TCGArg mem_index)
pbrooka7812ae2008-11-17 14:43:54 +0000146{
147 *gen_opc_ptr++ = opc;
148 *gen_opparam_ptr++ = GET_TCGV_I64(val);
149 *gen_opparam_ptr++ = GET_TCGV_I64(addr);
150 *gen_opparam_ptr++ = mem_index;
151}
152
Richard Hendersona9751602010-03-19 11:12:29 -0700153static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000154 TCGv_i32 arg3, TCGv_i32 arg4)
155{
156 *gen_opc_ptr++ = opc;
157 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
158 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
159 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
160 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
161}
162
Richard Hendersona9751602010-03-19 11:12:29 -0700163static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
blueswir1a810a2d2008-12-07 17:16:42 +0000164 TCGv_i64 arg3, TCGv_i64 arg4)
pbrooka7812ae2008-11-17 14:43:54 +0000165{
166 *gen_opc_ptr++ = opc;
167 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
168 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
169 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
170 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
171}
172
Richard Hendersona9751602010-03-19 11:12:29 -0700173static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000174 TCGv_i32 arg3, TCGArg arg4)
175{
176 *gen_opc_ptr++ = opc;
177 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
178 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
179 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
pbrookac56dd42008-02-03 19:56:33 +0000180 *gen_opparam_ptr++ = arg4;
181}
182
Richard Hendersona9751602010-03-19 11:12:29 -0700183static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000184 TCGv_i64 arg3, TCGArg arg4)
pbrookac56dd42008-02-03 19:56:33 +0000185{
186 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +0000187 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
188 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
189 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
190 *gen_opparam_ptr++ = arg4;
191}
192
Richard Hendersona9751602010-03-19 11:12:29 -0700193static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000194 TCGArg arg3, TCGArg arg4)
195{
196 *gen_opc_ptr++ = opc;
197 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
198 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
bellardc896fe22008-02-01 10:05:41 +0000199 *gen_opparam_ptr++ = arg3;
200 *gen_opparam_ptr++ = arg4;
201}
202
Richard Hendersona9751602010-03-19 11:12:29 -0700203static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000204 TCGArg arg3, TCGArg arg4)
bellardc896fe22008-02-01 10:05:41 +0000205{
206 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +0000207 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
208 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
209 *gen_opparam_ptr++ = arg3;
210 *gen_opparam_ptr++ = arg4;
pbrookac56dd42008-02-03 19:56:33 +0000211}
212
Richard Hendersona9751602010-03-19 11:12:29 -0700213static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000214 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
pbrookac56dd42008-02-03 19:56:33 +0000215{
216 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +0000217 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
218 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
219 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
220 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
221 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
222}
223
Richard Hendersona9751602010-03-19 11:12:29 -0700224static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000225 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
226{
227 *gen_opc_ptr++ = opc;
228 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
229 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
230 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
231 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
232 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
233}
234
Richard Hendersona9751602010-03-19 11:12:29 -0700235static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000236 TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
237{
238 *gen_opc_ptr++ = opc;
239 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
240 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
241 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
242 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
bellardc896fe22008-02-01 10:05:41 +0000243 *gen_opparam_ptr++ = arg5;
244}
245
Richard Hendersona9751602010-03-19 11:12:29 -0700246static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000247 TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
bellardc896fe22008-02-01 10:05:41 +0000248{
249 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +0000250 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
251 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
252 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
253 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
254 *gen_opparam_ptr++ = arg5;
pbrookac56dd42008-02-03 19:56:33 +0000255}
256
Richard Hendersona9751602010-03-19 11:12:29 -0700257static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000258 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
259 TCGv_i32 arg6)
pbrookac56dd42008-02-03 19:56:33 +0000260{
261 *gen_opc_ptr++ = opc;
pbrooka7812ae2008-11-17 14:43:54 +0000262 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
263 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
264 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
265 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
266 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
267 *gen_opparam_ptr++ = GET_TCGV_I32(arg6);
268}
269
Richard Hendersona9751602010-03-19 11:12:29 -0700270static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000271 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
272 TCGv_i64 arg6)
273{
274 *gen_opc_ptr++ = opc;
275 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
276 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
277 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
278 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
279 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
280 *gen_opparam_ptr++ = GET_TCGV_I64(arg6);
281}
282
Richard Hendersona9751602010-03-19 11:12:29 -0700283static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800284 TCGv_i32 arg3, TCGv_i32 arg4,
285 TCGv_i32 arg5, TCGArg arg6)
286{
287 *gen_opc_ptr++ = opc;
288 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
289 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
290 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
291 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
292 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
293 *gen_opparam_ptr++ = arg6;
294}
295
Richard Hendersona9751602010-03-19 11:12:29 -0700296static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800297 TCGv_i64 arg3, TCGv_i64 arg4,
298 TCGv_i64 arg5, TCGArg arg6)
299{
300 *gen_opc_ptr++ = opc;
301 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
302 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
303 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
304 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
305 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
306 *gen_opparam_ptr++ = arg6;
307}
308
Richard Hendersona9751602010-03-19 11:12:29 -0700309static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 arg1,
310 TCGv_i32 arg2, TCGv_i32 arg3,
311 TCGv_i32 arg4, TCGArg arg5, TCGArg arg6)
pbrooka7812ae2008-11-17 14:43:54 +0000312{
313 *gen_opc_ptr++ = opc;
314 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
315 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
316 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
317 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
318 *gen_opparam_ptr++ = arg5;
319 *gen_opparam_ptr++ = arg6;
320}
321
Richard Hendersona9751602010-03-19 11:12:29 -0700322static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 arg1,
323 TCGv_i64 arg2, TCGv_i64 arg3,
324 TCGv_i64 arg4, TCGArg arg5, TCGArg arg6)
pbrooka7812ae2008-11-17 14:43:54 +0000325{
326 *gen_opc_ptr++ = opc;
327 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
328 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
329 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
330 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
bellardc896fe22008-02-01 10:05:41 +0000331 *gen_opparam_ptr++ = arg5;
332 *gen_opparam_ptr++ = arg6;
333}
334
335static inline void gen_set_label(int n)
336{
pbrookac56dd42008-02-03 19:56:33 +0000337 tcg_gen_op1i(INDEX_op_set_label, n);
bellardc896fe22008-02-01 10:05:41 +0000338}
339
blueswir1fb50d412008-03-21 17:58:45 +0000340static inline void tcg_gen_br(int label)
341{
342 tcg_gen_op1i(INDEX_op_br, label);
343}
344
pbrooka7812ae2008-11-17 14:43:54 +0000345static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +0000346{
aurel32fe75bcf2009-03-10 08:57:16 +0000347 if (!TCGV_EQUAL_I32(ret, arg))
pbrooka7812ae2008-11-17 14:43:54 +0000348 tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000349}
350
pbrooka7812ae2008-11-17 14:43:54 +0000351static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
bellardc896fe22008-02-01 10:05:41 +0000352{
pbrooka7812ae2008-11-17 14:43:54 +0000353 tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000354}
355
356/* helper calls */
pbrooka7812ae2008-11-17 14:43:54 +0000357static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
358 TCGArg ret, int nargs, TCGArg *args)
bellardc896fe22008-02-01 10:05:41 +0000359{
pbrooka7812ae2008-11-17 14:43:54 +0000360 TCGv_ptr fn;
361 fn = tcg_const_ptr((tcg_target_long)func);
362 tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
363 nargs, args);
364 tcg_temp_free_ptr(fn);
bellardc896fe22008-02-01 10:05:41 +0000365}
366
Aurelien Jarnodbfff4d2010-03-14 23:01:01 +0100367/* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
368 reserved for helpers in tcg-runtime.c. These helpers are all const
369 and pure, hence the call to tcg_gen_callN() with TCG_CALL_CONST |
370 TCG_CALL_PURE. This may need to be adjusted if these functions
371 start to be used with other helpers. */
Aurelien Jarno31d66552010-03-02 23:16:36 +0100372static inline void tcg_gen_helper32(void *func, TCGv_i32 ret,
373 TCGv_i32 a, TCGv_i32 b)
374{
375 TCGv_ptr fn;
376 TCGArg args[2];
377 fn = tcg_const_ptr((tcg_target_long)func);
378 args[0] = GET_TCGV_I32(a);
379 args[1] = GET_TCGV_I32(b);
Aurelien Jarnodbfff4d2010-03-14 23:01:01 +0100380 tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE,
381 0, GET_TCGV_I32(ret), 2, args);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100382 tcg_temp_free_ptr(fn);
383}
384
pbrooka7812ae2008-11-17 14:43:54 +0000385static inline void tcg_gen_helper64(void *func, TCGv_i64 ret,
386 TCGv_i64 a, TCGv_i64 b)
bellardc896fe22008-02-01 10:05:41 +0000387{
pbrooka7812ae2008-11-17 14:43:54 +0000388 TCGv_ptr fn;
389 TCGArg args[2];
390 fn = tcg_const_ptr((tcg_target_long)func);
391 args[0] = GET_TCGV_I64(a);
392 args[1] = GET_TCGV_I64(b);
Aurelien Jarnodbfff4d2010-03-14 23:01:01 +0100393 tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE,
394 7, GET_TCGV_I64(ret), 2, args);
pbrooka7812ae2008-11-17 14:43:54 +0000395 tcg_temp_free_ptr(fn);
blueswir1f8422f52008-02-24 07:45:43 +0000396}
397
bellardc896fe22008-02-01 10:05:41 +0000398/* 32 bit ops */
399
pbrooka7812ae2008-11-17 14:43:54 +0000400static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000401{
pbrooka7812ae2008-11-17 14:43:54 +0000402 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000403}
404
pbrooka7812ae2008-11-17 14:43:54 +0000405static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000406{
pbrooka7812ae2008-11-17 14:43:54 +0000407 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000408}
409
pbrooka7812ae2008-11-17 14:43:54 +0000410static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000411{
pbrooka7812ae2008-11-17 14:43:54 +0000412 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000413}
414
pbrooka7812ae2008-11-17 14:43:54 +0000415static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000416{
pbrooka7812ae2008-11-17 14:43:54 +0000417 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000418}
419
pbrooka7812ae2008-11-17 14:43:54 +0000420static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000421{
pbrooka7812ae2008-11-17 14:43:54 +0000422 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000423}
424
pbrooka7812ae2008-11-17 14:43:54 +0000425static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000426{
pbrooka7812ae2008-11-17 14:43:54 +0000427 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000428}
429
pbrooka7812ae2008-11-17 14:43:54 +0000430static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000431{
pbrooka7812ae2008-11-17 14:43:54 +0000432 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000433}
434
pbrooka7812ae2008-11-17 14:43:54 +0000435static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000436{
pbrooka7812ae2008-11-17 14:43:54 +0000437 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000438}
439
pbrooka7812ae2008-11-17 14:43:54 +0000440static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000441{
pbrooka7812ae2008-11-17 14:43:54 +0000442 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000443}
444
pbrooka7812ae2008-11-17 14:43:54 +0000445static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000446{
blueswir170894422008-02-20 18:01:23 +0000447 /* some cases can be optimized here */
448 if (arg2 == 0) {
449 tcg_gen_mov_i32(ret, arg1);
450 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000451 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000452 tcg_gen_add_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000453 tcg_temp_free_i32(t0);
blueswir170894422008-02-20 18:01:23 +0000454 }
bellardc896fe22008-02-01 10:05:41 +0000455}
456
pbrooka7812ae2008-11-17 14:43:54 +0000457static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000458{
pbrooka7812ae2008-11-17 14:43:54 +0000459 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000460}
461
pbrooka7812ae2008-11-17 14:43:54 +0000462static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
aurel3200457342008-11-02 08:23:04 +0000463{
pbrooka7812ae2008-11-17 14:43:54 +0000464 TCGv_i32 t0 = tcg_const_i32(arg1);
aurel3200457342008-11-02 08:23:04 +0000465 tcg_gen_sub_i32(ret, t0, arg2);
pbrooka7812ae2008-11-17 14:43:54 +0000466 tcg_temp_free_i32(t0);
aurel3200457342008-11-02 08:23:04 +0000467}
468
pbrooka7812ae2008-11-17 14:43:54 +0000469static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000470{
blueswir170894422008-02-20 18:01:23 +0000471 /* some cases can be optimized here */
472 if (arg2 == 0) {
473 tcg_gen_mov_i32(ret, arg1);
474 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000475 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000476 tcg_gen_sub_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000477 tcg_temp_free_i32(t0);
blueswir170894422008-02-20 18:01:23 +0000478 }
bellardc896fe22008-02-01 10:05:41 +0000479}
480
pbrooka7812ae2008-11-17 14:43:54 +0000481static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000482{
aurel327fc81052009-03-10 19:37:39 +0000483 if (TCGV_EQUAL_I32(arg1, arg2)) {
484 tcg_gen_mov_i32(ret, arg1);
485 } else {
486 tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
487 }
bellardc896fe22008-02-01 10:05:41 +0000488}
489
pbrooka7812ae2008-11-17 14:43:54 +0000490static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000491{
492 /* some cases can be optimized here */
493 if (arg2 == 0) {
494 tcg_gen_movi_i32(ret, 0);
495 } else if (arg2 == 0xffffffff) {
496 tcg_gen_mov_i32(ret, arg1);
497 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000498 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000499 tcg_gen_and_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000500 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000501 }
502}
503
pbrooka7812ae2008-11-17 14:43:54 +0000504static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000505{
aurel327fc81052009-03-10 19:37:39 +0000506 if (TCGV_EQUAL_I32(arg1, arg2)) {
507 tcg_gen_mov_i32(ret, arg1);
508 } else {
509 tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
510 }
bellardc896fe22008-02-01 10:05:41 +0000511}
512
pbrooka7812ae2008-11-17 14:43:54 +0000513static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000514{
515 /* some cases can be optimized here */
516 if (arg2 == 0xffffffff) {
blueswir170894422008-02-20 18:01:23 +0000517 tcg_gen_movi_i32(ret, 0xffffffff);
bellardc896fe22008-02-01 10:05:41 +0000518 } else if (arg2 == 0) {
519 tcg_gen_mov_i32(ret, arg1);
520 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000521 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000522 tcg_gen_or_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000523 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000524 }
525}
526
pbrooka7812ae2008-11-17 14:43:54 +0000527static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000528{
aurel327fc81052009-03-10 19:37:39 +0000529 if (TCGV_EQUAL_I32(arg1, arg2)) {
530 tcg_gen_movi_i32(ret, 0);
531 } else {
532 tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
533 }
bellardc896fe22008-02-01 10:05:41 +0000534}
535
pbrooka7812ae2008-11-17 14:43:54 +0000536static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000537{
538 /* some cases can be optimized here */
539 if (arg2 == 0) {
540 tcg_gen_mov_i32(ret, arg1);
541 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000542 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000543 tcg_gen_xor_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000544 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000545 }
546}
547
pbrooka7812ae2008-11-17 14:43:54 +0000548static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000549{
pbrooka7812ae2008-11-17 14:43:54 +0000550 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000551}
552
pbrooka7812ae2008-11-17 14:43:54 +0000553static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000554{
bellard34151a22008-05-22 13:25:14 +0000555 if (arg2 == 0) {
556 tcg_gen_mov_i32(ret, arg1);
557 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000558 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000559 tcg_gen_shl_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000560 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000561 }
bellardc896fe22008-02-01 10:05:41 +0000562}
563
pbrooka7812ae2008-11-17 14:43:54 +0000564static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000565{
pbrooka7812ae2008-11-17 14:43:54 +0000566 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000567}
568
pbrooka7812ae2008-11-17 14:43:54 +0000569static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000570{
bellard34151a22008-05-22 13:25:14 +0000571 if (arg2 == 0) {
572 tcg_gen_mov_i32(ret, arg1);
573 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000574 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000575 tcg_gen_shr_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000576 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000577 }
bellardc896fe22008-02-01 10:05:41 +0000578}
579
pbrooka7812ae2008-11-17 14:43:54 +0000580static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000581{
pbrooka7812ae2008-11-17 14:43:54 +0000582 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000583}
584
pbrooka7812ae2008-11-17 14:43:54 +0000585static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000586{
bellard34151a22008-05-22 13:25:14 +0000587 if (arg2 == 0) {
588 tcg_gen_mov_i32(ret, arg1);
589 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000590 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000591 tcg_gen_sar_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000592 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000593 }
bellardc896fe22008-02-01 10:05:41 +0000594}
595
Richard Henderson8a56e842010-03-19 11:26:05 -0700596static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
597 TCGv_i32 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +0000598{
pbrooka7812ae2008-11-17 14:43:54 +0000599 tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000600}
601
Richard Henderson8a56e842010-03-19 11:26:05 -0700602static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
603 int32_t arg2, int label_index)
pbrookcb636692008-05-24 02:22:00 +0000604{
pbrooka7812ae2008-11-17 14:43:54 +0000605 TCGv_i32 t0 = tcg_const_i32(arg2);
pbrookcb636692008-05-24 02:22:00 +0000606 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
pbrooka7812ae2008-11-17 14:43:54 +0000607 tcg_temp_free_i32(t0);
pbrookcb636692008-05-24 02:22:00 +0000608}
609
Richard Henderson8a56e842010-03-19 11:26:05 -0700610static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +0100611 TCGv_i32 arg1, TCGv_i32 arg2)
612{
613 tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
614}
615
Richard Henderson8a56e842010-03-19 11:26:05 -0700616static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
617 TCGv_i32 arg1, int32_t arg2)
Aurelien Jarno5105c552010-02-08 12:10:15 +0100618{
619 TCGv_i32 t0 = tcg_const_i32(arg2);
620 tcg_gen_setcond_i32(cond, ret, arg1, t0);
621 tcg_temp_free_i32(t0);
622}
623
pbrooka7812ae2008-11-17 14:43:54 +0000624static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000625{
pbrooka7812ae2008-11-17 14:43:54 +0000626 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000627}
628
pbrooka7812ae2008-11-17 14:43:54 +0000629static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
thsf730fd22008-05-04 08:14:08 +0000630{
pbrooka7812ae2008-11-17 14:43:54 +0000631 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000632 tcg_gen_mul_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000633 tcg_temp_free_i32(t0);
thsf730fd22008-05-04 08:14:08 +0000634}
635
bellardc896fe22008-02-01 10:05:41 +0000636#ifdef TCG_TARGET_HAS_div_i32
pbrooka7812ae2008-11-17 14:43:54 +0000637static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000638{
pbrooka7812ae2008-11-17 14:43:54 +0000639 tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000640}
641
pbrooka7812ae2008-11-17 14:43:54 +0000642static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000643{
pbrooka7812ae2008-11-17 14:43:54 +0000644 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000645}
646
pbrooka7812ae2008-11-17 14:43:54 +0000647static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000648{
pbrooka7812ae2008-11-17 14:43:54 +0000649 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000650}
651
pbrooka7812ae2008-11-17 14:43:54 +0000652static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000653{
pbrooka7812ae2008-11-17 14:43:54 +0000654 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000655}
Aurelien Jarno31d66552010-03-02 23:16:36 +0100656#elif defined(TCG_TARGET_HAS_div2_i32)
pbrooka7812ae2008-11-17 14:43:54 +0000657static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000658{
pbrooka7812ae2008-11-17 14:43:54 +0000659 TCGv_i32 t0;
660 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +0000661 tcg_gen_sari_i32(t0, arg1, 31);
pbrooka7812ae2008-11-17 14:43:54 +0000662 tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
663 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000664}
665
pbrooka7812ae2008-11-17 14:43:54 +0000666static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000667{
pbrooka7812ae2008-11-17 14:43:54 +0000668 TCGv_i32 t0;
669 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +0000670 tcg_gen_sari_i32(t0, arg1, 31);
pbrooka7812ae2008-11-17 14:43:54 +0000671 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
672 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000673}
674
pbrooka7812ae2008-11-17 14:43:54 +0000675static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000676{
pbrooka7812ae2008-11-17 14:43:54 +0000677 TCGv_i32 t0;
678 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +0000679 tcg_gen_movi_i32(t0, 0);
pbrooka7812ae2008-11-17 14:43:54 +0000680 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
681 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000682}
683
pbrooka7812ae2008-11-17 14:43:54 +0000684static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000685{
pbrooka7812ae2008-11-17 14:43:54 +0000686 TCGv_i32 t0;
687 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +0000688 tcg_gen_movi_i32(t0, 0);
pbrooka7812ae2008-11-17 14:43:54 +0000689 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
690 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000691}
Aurelien Jarno31d66552010-03-02 23:16:36 +0100692#else
693static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
694{
695 tcg_gen_helper32(tcg_helper_div_i32, ret, arg1, arg2);
696}
697
698static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
699{
700 tcg_gen_helper32(tcg_helper_rem_i32, ret, arg1, arg2);
701}
702
703static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
704{
705 tcg_gen_helper32(tcg_helper_divu_i32, ret, arg1, arg2);
706}
707
708static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
709{
710 tcg_gen_helper32(tcg_helper_remu_i32, ret, arg1, arg2);
711}
bellardc896fe22008-02-01 10:05:41 +0000712#endif
713
714#if TCG_TARGET_REG_BITS == 32
715
pbrooka7812ae2008-11-17 14:43:54 +0000716static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +0000717{
aurel32fe75bcf2009-03-10 08:57:16 +0000718 if (!TCGV_EQUAL_I64(ret, arg)) {
pbrooka7812ae2008-11-17 14:43:54 +0000719 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
blueswir14d072722008-05-03 20:52:26 +0000720 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
721 }
bellardc896fe22008-02-01 10:05:41 +0000722}
723
pbrooka7812ae2008-11-17 14:43:54 +0000724static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000725{
pbrooka7812ae2008-11-17 14:43:54 +0000726 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
pbrookac56dd42008-02-03 19:56:33 +0000727 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
bellardc896fe22008-02-01 10:05:41 +0000728}
729
pbrooka7812ae2008-11-17 14:43:54 +0000730static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
731 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000732{
pbrooka7812ae2008-11-17 14:43:54 +0000733 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000734 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000735}
736
pbrooka7812ae2008-11-17 14:43:54 +0000737static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
738 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000739{
pbrooka7812ae2008-11-17 14:43:54 +0000740 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
741 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000742}
743
pbrooka7812ae2008-11-17 14:43:54 +0000744static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
745 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000746{
aurel32a7477232009-02-09 20:43:53 +0000747 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000748 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000749}
750
pbrooka7812ae2008-11-17 14:43:54 +0000751static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
752 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000753{
pbrooka7812ae2008-11-17 14:43:54 +0000754 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
755 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000756}
757
pbrooka7812ae2008-11-17 14:43:54 +0000758static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
759 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000760{
pbrooka7812ae2008-11-17 14:43:54 +0000761 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000762 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000763}
764
pbrooka7812ae2008-11-17 14:43:54 +0000765static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
766 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000767{
pbrooka7812ae2008-11-17 14:43:54 +0000768 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
769 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000770}
771
pbrooka7812ae2008-11-17 14:43:54 +0000772static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
773 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000774{
775 /* since arg2 and ret have different types, they cannot be the
776 same temporary */
777#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000778 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
pbrooka7812ae2008-11-17 14:43:54 +0000779 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000780#else
pbrooka7812ae2008-11-17 14:43:54 +0000781 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000782 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000783#endif
784}
785
pbrooka7812ae2008-11-17 14:43:54 +0000786static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
787 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000788{
pbrooka7812ae2008-11-17 14:43:54 +0000789 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000790}
791
pbrooka7812ae2008-11-17 14:43:54 +0000792static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
793 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000794{
pbrooka7812ae2008-11-17 14:43:54 +0000795 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000796}
797
pbrooka7812ae2008-11-17 14:43:54 +0000798static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
799 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000800{
pbrooka7812ae2008-11-17 14:43:54 +0000801 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000802}
803
pbrooka7812ae2008-11-17 14:43:54 +0000804static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
805 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000806{
807#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000808 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
pbrooka7812ae2008-11-17 14:43:54 +0000809 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000810#else
pbrooka7812ae2008-11-17 14:43:54 +0000811 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000812 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000813#endif
814}
815
pbrooka7812ae2008-11-17 14:43:54 +0000816static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000817{
pbrooka7812ae2008-11-17 14:43:54 +0000818 tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
819 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
820 TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000821}
822
pbrooka7812ae2008-11-17 14:43:54 +0000823static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000824{
pbrooka7812ae2008-11-17 14:43:54 +0000825 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
826 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
827 TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000828}
829
pbrooka7812ae2008-11-17 14:43:54 +0000830static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000831{
pbrooka7812ae2008-11-17 14:43:54 +0000832 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
pbrookac56dd42008-02-03 19:56:33 +0000833 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000834}
835
pbrooka7812ae2008-11-17 14:43:54 +0000836static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000837{
aurel32e5105082009-03-11 02:57:30 +0000838 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
839 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000840}
841
pbrooka7812ae2008-11-17 14:43:54 +0000842static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000843{
aurel32e5105082009-03-11 02:57:30 +0000844 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
845 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000846}
847
pbrooka7812ae2008-11-17 14:43:54 +0000848static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000849{
pbrooka7812ae2008-11-17 14:43:54 +0000850 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
pbrookac56dd42008-02-03 19:56:33 +0000851 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000852}
853
pbrooka7812ae2008-11-17 14:43:54 +0000854static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000855{
aurel32e5105082009-03-11 02:57:30 +0000856 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
857 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000858}
859
pbrooka7812ae2008-11-17 14:43:54 +0000860static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000861{
pbrooka7812ae2008-11-17 14:43:54 +0000862 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
pbrookac56dd42008-02-03 19:56:33 +0000863 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000864}
865
866/* XXX: use generic code when basic block handling is OK or CPU
867 specific code (x86) */
pbrooka7812ae2008-11-17 14:43:54 +0000868static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000869{
pbrooka7812ae2008-11-17 14:43:54 +0000870 tcg_gen_helper64(tcg_helper_shl_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000871}
872
pbrooka7812ae2008-11-17 14:43:54 +0000873static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000874{
875 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
876}
877
pbrooka7812ae2008-11-17 14:43:54 +0000878static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000879{
pbrooka7812ae2008-11-17 14:43:54 +0000880 tcg_gen_helper64(tcg_helper_shr_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000881}
882
pbrooka7812ae2008-11-17 14:43:54 +0000883static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000884{
885 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
886}
887
pbrooka7812ae2008-11-17 14:43:54 +0000888static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000889{
pbrooka7812ae2008-11-17 14:43:54 +0000890 tcg_gen_helper64(tcg_helper_sar_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000891}
892
pbrooka7812ae2008-11-17 14:43:54 +0000893static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000894{
895 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
896}
897
Richard Henderson8a56e842010-03-19 11:26:05 -0700898static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
899 TCGv_i64 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +0000900{
pbrooka7812ae2008-11-17 14:43:54 +0000901 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
902 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
903 TCGV_HIGH(arg2), cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000904}
905
Richard Henderson8a56e842010-03-19 11:26:05 -0700906static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +0100907 TCGv_i64 arg1, TCGv_i64 arg2)
908{
909 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
910 TCGV_LOW(arg1), TCGV_HIGH(arg1),
911 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
912 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
913}
914
pbrooka7812ae2008-11-17 14:43:54 +0000915static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000916{
pbrooka7812ae2008-11-17 14:43:54 +0000917 TCGv_i64 t0;
918 TCGv_i32 t1;
bellardc896fe22008-02-01 10:05:41 +0000919
pbrooka7812ae2008-11-17 14:43:54 +0000920 t0 = tcg_temp_new_i64();
921 t1 = tcg_temp_new_i32();
922
923 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
924 TCGV_LOW(arg1), TCGV_LOW(arg2));
925
926 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
pbrookac56dd42008-02-03 19:56:33 +0000927 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
pbrooka7812ae2008-11-17 14:43:54 +0000928 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
pbrookac56dd42008-02-03 19:56:33 +0000929 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
pbrooka7812ae2008-11-17 14:43:54 +0000930
bellardc896fe22008-02-01 10:05:41 +0000931 tcg_gen_mov_i64(ret, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000932 tcg_temp_free_i64(t0);
933 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +0000934}
935
pbrooka7812ae2008-11-17 14:43:54 +0000936static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000937{
pbrooka7812ae2008-11-17 14:43:54 +0000938 tcg_gen_helper64(tcg_helper_div_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000939}
940
pbrooka7812ae2008-11-17 14:43:54 +0000941static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000942{
pbrooka7812ae2008-11-17 14:43:54 +0000943 tcg_gen_helper64(tcg_helper_rem_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000944}
945
pbrooka7812ae2008-11-17 14:43:54 +0000946static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000947{
pbrooka7812ae2008-11-17 14:43:54 +0000948 tcg_gen_helper64(tcg_helper_divu_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000949}
950
pbrooka7812ae2008-11-17 14:43:54 +0000951static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000952{
pbrooka7812ae2008-11-17 14:43:54 +0000953 tcg_gen_helper64(tcg_helper_remu_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000954}
955
956#else
957
pbrooka7812ae2008-11-17 14:43:54 +0000958static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +0000959{
aurel32fe75bcf2009-03-10 08:57:16 +0000960 if (!TCGV_EQUAL_I64(ret, arg))
pbrooka7812ae2008-11-17 14:43:54 +0000961 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000962}
963
pbrooka7812ae2008-11-17 14:43:54 +0000964static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000965{
pbrooka7812ae2008-11-17 14:43:54 +0000966 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000967}
968
pbrooka7812ae2008-11-17 14:43:54 +0000969static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +0000970 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000971{
pbrooka7812ae2008-11-17 14:43:54 +0000972 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000973}
974
pbrooka7812ae2008-11-17 14:43:54 +0000975static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +0000976 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000977{
pbrooka7812ae2008-11-17 14:43:54 +0000978 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000979}
980
pbrooka7812ae2008-11-17 14:43:54 +0000981static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +0000982 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000983{
pbrooka7812ae2008-11-17 14:43:54 +0000984 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000985}
986
pbrooka7812ae2008-11-17 14:43:54 +0000987static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +0000988 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000989{
pbrooka7812ae2008-11-17 14:43:54 +0000990 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000991}
992
pbrooka7812ae2008-11-17 14:43:54 +0000993static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +0000994 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000995{
pbrooka7812ae2008-11-17 14:43:54 +0000996 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000997}
998
pbrooka7812ae2008-11-17 14:43:54 +0000999static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001000 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001001{
pbrooka7812ae2008-11-17 14:43:54 +00001002 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001003}
1004
pbrooka7812ae2008-11-17 14:43:54 +00001005static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_i64 arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001006{
pbrooka7812ae2008-11-17 14:43:54 +00001007 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001008}
1009
pbrooka7812ae2008-11-17 14:43:54 +00001010static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001011 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001012{
pbrooka7812ae2008-11-17 14:43:54 +00001013 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001014}
1015
pbrooka7812ae2008-11-17 14:43:54 +00001016static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001017 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001018{
pbrooka7812ae2008-11-17 14:43:54 +00001019 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001020}
1021
pbrooka7812ae2008-11-17 14:43:54 +00001022static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001023 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001024{
pbrooka7812ae2008-11-17 14:43:54 +00001025 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001026}
1027
pbrooka7812ae2008-11-17 14:43:54 +00001028static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_i64 arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001029{
pbrooka7812ae2008-11-17 14:43:54 +00001030 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001031}
1032
pbrooka7812ae2008-11-17 14:43:54 +00001033static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001034{
pbrooka7812ae2008-11-17 14:43:54 +00001035 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001036}
1037
pbrooka7812ae2008-11-17 14:43:54 +00001038static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001039{
pbrooka7812ae2008-11-17 14:43:54 +00001040 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001041}
1042
pbrooka7812ae2008-11-17 14:43:54 +00001043static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001044{
aurel327fc81052009-03-10 19:37:39 +00001045 if (TCGV_EQUAL_I64(arg1, arg2)) {
1046 tcg_gen_mov_i64(ret, arg1);
1047 } else {
1048 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1049 }
bellardc896fe22008-02-01 10:05:41 +00001050}
1051
pbrooka7812ae2008-11-17 14:43:54 +00001052static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001053{
pbrooka7812ae2008-11-17 14:43:54 +00001054 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001055 tcg_gen_and_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001056 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001057}
1058
pbrooka7812ae2008-11-17 14:43:54 +00001059static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001060{
aurel327fc81052009-03-10 19:37:39 +00001061 if (TCGV_EQUAL_I64(arg1, arg2)) {
1062 tcg_gen_mov_i64(ret, arg1);
1063 } else {
1064 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1065 }
bellardc896fe22008-02-01 10:05:41 +00001066}
1067
pbrooka7812ae2008-11-17 14:43:54 +00001068static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001069{
pbrooka7812ae2008-11-17 14:43:54 +00001070 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001071 tcg_gen_or_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001072 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001073}
1074
pbrooka7812ae2008-11-17 14:43:54 +00001075static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001076{
aurel327fc81052009-03-10 19:37:39 +00001077 if (TCGV_EQUAL_I64(arg1, arg2)) {
1078 tcg_gen_movi_i64(ret, 0);
1079 } else {
1080 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1081 }
bellardc896fe22008-02-01 10:05:41 +00001082}
1083
pbrooka7812ae2008-11-17 14:43:54 +00001084static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001085{
pbrooka7812ae2008-11-17 14:43:54 +00001086 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001087 tcg_gen_xor_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001088 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001089}
1090
pbrooka7812ae2008-11-17 14:43:54 +00001091static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001092{
pbrooka7812ae2008-11-17 14:43:54 +00001093 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001094}
1095
pbrooka7812ae2008-11-17 14:43:54 +00001096static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001097{
bellard34151a22008-05-22 13:25:14 +00001098 if (arg2 == 0) {
1099 tcg_gen_mov_i64(ret, arg1);
1100 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001101 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001102 tcg_gen_shl_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001103 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001104 }
bellardc896fe22008-02-01 10:05:41 +00001105}
1106
pbrooka7812ae2008-11-17 14:43:54 +00001107static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001108{
pbrooka7812ae2008-11-17 14:43:54 +00001109 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001110}
1111
pbrooka7812ae2008-11-17 14:43:54 +00001112static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001113{
bellard34151a22008-05-22 13:25:14 +00001114 if (arg2 == 0) {
1115 tcg_gen_mov_i64(ret, arg1);
1116 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001117 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001118 tcg_gen_shr_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001119 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001120 }
bellardc896fe22008-02-01 10:05:41 +00001121}
1122
pbrooka7812ae2008-11-17 14:43:54 +00001123static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001124{
pbrooka7812ae2008-11-17 14:43:54 +00001125 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001126}
1127
pbrooka7812ae2008-11-17 14:43:54 +00001128static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001129{
bellard34151a22008-05-22 13:25:14 +00001130 if (arg2 == 0) {
1131 tcg_gen_mov_i64(ret, arg1);
1132 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001133 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001134 tcg_gen_sar_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001135 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001136 }
bellardc896fe22008-02-01 10:05:41 +00001137}
1138
Richard Henderson8a56e842010-03-19 11:26:05 -07001139static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1140 TCGv_i64 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +00001141{
pbrooka7812ae2008-11-17 14:43:54 +00001142 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
bellardc896fe22008-02-01 10:05:41 +00001143}
1144
Richard Henderson8a56e842010-03-19 11:26:05 -07001145static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +01001146 TCGv_i64 arg1, TCGv_i64 arg2)
1147{
1148 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1149}
1150
pbrooka7812ae2008-11-17 14:43:54 +00001151static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001152{
pbrooka7812ae2008-11-17 14:43:54 +00001153 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001154}
1155
1156#ifdef TCG_TARGET_HAS_div_i64
pbrooka7812ae2008-11-17 14:43:54 +00001157static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001158{
pbrooka7812ae2008-11-17 14:43:54 +00001159 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001160}
1161
pbrooka7812ae2008-11-17 14:43:54 +00001162static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001163{
pbrooka7812ae2008-11-17 14:43:54 +00001164 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001165}
1166
pbrooka7812ae2008-11-17 14:43:54 +00001167static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001168{
pbrooka7812ae2008-11-17 14:43:54 +00001169 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001170}
1171
pbrooka7812ae2008-11-17 14:43:54 +00001172static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001173{
pbrooka7812ae2008-11-17 14:43:54 +00001174 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001175}
Aurelien Jarno31d66552010-03-02 23:16:36 +01001176#elif defined(TCG_TARGET_HAS_div2_i64)
pbrooka7812ae2008-11-17 14:43:54 +00001177static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001178{
pbrooka7812ae2008-11-17 14:43:54 +00001179 TCGv_i64 t0;
1180 t0 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001181 tcg_gen_sari_i64(t0, arg1, 63);
pbrooka7812ae2008-11-17 14:43:54 +00001182 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1183 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001184}
1185
pbrooka7812ae2008-11-17 14:43:54 +00001186static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001187{
pbrooka7812ae2008-11-17 14:43:54 +00001188 TCGv_i64 t0;
1189 t0 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001190 tcg_gen_sari_i64(t0, arg1, 63);
pbrooka7812ae2008-11-17 14:43:54 +00001191 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1192 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001193}
1194
pbrooka7812ae2008-11-17 14:43:54 +00001195static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001196{
pbrooka7812ae2008-11-17 14:43:54 +00001197 TCGv_i64 t0;
1198 t0 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001199 tcg_gen_movi_i64(t0, 0);
pbrooka7812ae2008-11-17 14:43:54 +00001200 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1201 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001202}
1203
pbrooka7812ae2008-11-17 14:43:54 +00001204static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001205{
pbrooka7812ae2008-11-17 14:43:54 +00001206 TCGv_i64 t0;
1207 t0 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001208 tcg_gen_movi_i64(t0, 0);
pbrooka7812ae2008-11-17 14:43:54 +00001209 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1210 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001211}
Aurelien Jarno31d66552010-03-02 23:16:36 +01001212#else
1213static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1214{
1215 tcg_gen_helper64(tcg_helper_div_i64, ret, arg1, arg2);
1216}
1217
1218static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1219{
1220 tcg_gen_helper64(tcg_helper_rem_i64, ret, arg1, arg2);
1221}
1222
1223static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1224{
1225 tcg_gen_helper64(tcg_helper_divu_i64, ret, arg1, arg2);
1226}
1227
1228static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1229{
1230 tcg_gen_helper64(tcg_helper_remu_i64, ret, arg1, arg2);
1231}
bellardc896fe22008-02-01 10:05:41 +00001232#endif
1233
1234#endif
1235
pbrooka7812ae2008-11-17 14:43:54 +00001236static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3263597062008-11-02 08:22:54 +00001237{
1238 /* some cases can be optimized here */
1239 if (arg2 == 0) {
1240 tcg_gen_mov_i64(ret, arg1);
1241 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001242 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel3263597062008-11-02 08:22:54 +00001243 tcg_gen_add_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001244 tcg_temp_free_i64(t0);
aurel3263597062008-11-02 08:22:54 +00001245 }
1246}
1247
pbrooka7812ae2008-11-17 14:43:54 +00001248static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
aurel3200457342008-11-02 08:23:04 +00001249{
pbrooka7812ae2008-11-17 14:43:54 +00001250 TCGv_i64 t0 = tcg_const_i64(arg1);
aurel3200457342008-11-02 08:23:04 +00001251 tcg_gen_sub_i64(ret, t0, arg2);
pbrooka7812ae2008-11-17 14:43:54 +00001252 tcg_temp_free_i64(t0);
aurel3200457342008-11-02 08:23:04 +00001253}
1254
pbrooka7812ae2008-11-17 14:43:54 +00001255static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3263597062008-11-02 08:22:54 +00001256{
1257 /* some cases can be optimized here */
1258 if (arg2 == 0) {
1259 tcg_gen_mov_i64(ret, arg1);
1260 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001261 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel3263597062008-11-02 08:22:54 +00001262 tcg_gen_sub_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001263 tcg_temp_free_i64(t0);
aurel3263597062008-11-02 08:22:54 +00001264 }
1265}
Richard Henderson8a56e842010-03-19 11:26:05 -07001266static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1267 int64_t arg2, int label_index)
aurel32f02bb952008-11-03 07:08:26 +00001268{
pbrooka7812ae2008-11-17 14:43:54 +00001269 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel32f02bb952008-11-03 07:08:26 +00001270 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
pbrooka7812ae2008-11-17 14:43:54 +00001271 tcg_temp_free_i64(t0);
aurel32f02bb952008-11-03 07:08:26 +00001272}
1273
Richard Henderson8a56e842010-03-19 11:26:05 -07001274static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1275 TCGv_i64 arg1, int64_t arg2)
Aurelien Jarno5105c552010-02-08 12:10:15 +01001276{
1277 TCGv_i64 t0 = tcg_const_i64(arg2);
1278 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1279 tcg_temp_free_i64(t0);
1280}
1281
pbrooka7812ae2008-11-17 14:43:54 +00001282static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel32f02bb952008-11-03 07:08:26 +00001283{
pbrooka7812ae2008-11-17 14:43:54 +00001284 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel32f02bb952008-11-03 07:08:26 +00001285 tcg_gen_mul_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001286 tcg_temp_free_i64(t0);
aurel32f02bb952008-11-03 07:08:26 +00001287}
1288
aurel3263597062008-11-02 08:22:54 +00001289
bellardc896fe22008-02-01 10:05:41 +00001290/***************************************/
1291/* optional operations */
1292
pbrooka7812ae2008-11-17 14:43:54 +00001293static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001294{
1295#ifdef TCG_TARGET_HAS_ext8s_i32
pbrooka7812ae2008-11-17 14:43:54 +00001296 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001297#else
1298 tcg_gen_shli_i32(ret, arg, 24);
bellard5ff9d6a2008-02-04 00:37:54 +00001299 tcg_gen_sari_i32(ret, ret, 24);
bellardc896fe22008-02-01 10:05:41 +00001300#endif
1301}
1302
pbrooka7812ae2008-11-17 14:43:54 +00001303static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001304{
1305#ifdef TCG_TARGET_HAS_ext16s_i32
pbrooka7812ae2008-11-17 14:43:54 +00001306 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001307#else
1308 tcg_gen_shli_i32(ret, arg, 16);
bellard5ff9d6a2008-02-04 00:37:54 +00001309 tcg_gen_sari_i32(ret, ret, 16);
bellardc896fe22008-02-01 10:05:41 +00001310#endif
1311}
1312
pbrooka7812ae2008-11-17 14:43:54 +00001313static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook86831432008-05-11 12:22:01 +00001314{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001315#ifdef TCG_TARGET_HAS_ext8u_i32
1316 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1317#else
pbrook86831432008-05-11 12:22:01 +00001318 tcg_gen_andi_i32(ret, arg, 0xffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001319#endif
pbrook86831432008-05-11 12:22:01 +00001320}
1321
pbrooka7812ae2008-11-17 14:43:54 +00001322static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook86831432008-05-11 12:22:01 +00001323{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001324#ifdef TCG_TARGET_HAS_ext16u_i32
1325 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1326#else
pbrook86831432008-05-11 12:22:01 +00001327 tcg_gen_andi_i32(ret, arg, 0xffffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001328#endif
pbrook86831432008-05-11 12:22:01 +00001329}
1330
bellardc896fe22008-02-01 10:05:41 +00001331/* Note: we assume the two high bytes are set to zero */
pbrooka7812ae2008-11-17 14:43:54 +00001332static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001333{
1334#ifdef TCG_TARGET_HAS_bswap16_i32
pbrooka7812ae2008-11-17 14:43:54 +00001335 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001336#else
aurel32dfa1a3f2009-03-13 09:35:03 +00001337 TCGv_i32 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001338
aurel32dfa1a3f2009-03-13 09:35:03 +00001339 tcg_gen_ext8u_i32(t0, arg);
1340 tcg_gen_shli_i32(t0, t0, 8);
1341 tcg_gen_shri_i32(ret, arg, 8);
1342 tcg_gen_or_i32(ret, ret, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001343 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +00001344#endif
1345}
1346
aurel3266896cb2009-03-13 09:34:48 +00001347static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001348{
aurel3266896cb2009-03-13 09:34:48 +00001349#ifdef TCG_TARGET_HAS_bswap32_i32
1350 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001351#else
pbrooka7812ae2008-11-17 14:43:54 +00001352 TCGv_i32 t0, t1;
1353 t0 = tcg_temp_new_i32();
1354 t1 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001355
1356 tcg_gen_shli_i32(t0, arg, 24);
1357
1358 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1359 tcg_gen_shli_i32(t1, t1, 8);
1360 tcg_gen_or_i32(t0, t0, t1);
1361
1362 tcg_gen_shri_i32(t1, arg, 8);
1363 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1364 tcg_gen_or_i32(t0, t0, t1);
1365
1366 tcg_gen_shri_i32(t1, arg, 24);
1367 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001368 tcg_temp_free_i32(t0);
1369 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +00001370#endif
1371}
1372
1373#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001374static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001375{
pbrooka7812ae2008-11-17 14:43:54 +00001376 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1377 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001378}
1379
pbrooka7812ae2008-11-17 14:43:54 +00001380static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001381{
pbrooka7812ae2008-11-17 14:43:54 +00001382 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1383 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001384}
1385
pbrooka7812ae2008-11-17 14:43:54 +00001386static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001387{
pbrooka7812ae2008-11-17 14:43:54 +00001388 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1389 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001390}
1391
pbrooka7812ae2008-11-17 14:43:54 +00001392static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001393{
pbrooka7812ae2008-11-17 14:43:54 +00001394 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001395 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1396}
1397
pbrooka7812ae2008-11-17 14:43:54 +00001398static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001399{
pbrooka7812ae2008-11-17 14:43:54 +00001400 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001401 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1402}
1403
pbrooka7812ae2008-11-17 14:43:54 +00001404static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001405{
pbrooka7812ae2008-11-17 14:43:54 +00001406 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001407 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1408}
1409
pbrooka7812ae2008-11-17 14:43:54 +00001410static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001411{
pbrooka7812ae2008-11-17 14:43:54 +00001412 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
bellardc896fe22008-02-01 10:05:41 +00001413}
1414
pbrooka7812ae2008-11-17 14:43:54 +00001415static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001416{
pbrooka7812ae2008-11-17 14:43:54 +00001417 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
pbrookac56dd42008-02-03 19:56:33 +00001418 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001419}
1420
pbrooka7812ae2008-11-17 14:43:54 +00001421static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001422{
pbrooka7812ae2008-11-17 14:43:54 +00001423 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1424 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001425}
1426
aurel329a5c57f2009-03-13 09:35:12 +00001427/* Note: we assume the six high bytes are set to zero */
1428static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1429{
1430 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1431 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1432}
1433
1434/* Note: we assume the four high bytes are set to zero */
1435static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1436{
1437 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1438 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1439}
1440
aurel3266896cb2009-03-13 09:34:48 +00001441static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001442{
pbrooka7812ae2008-11-17 14:43:54 +00001443 TCGv_i32 t0, t1;
1444 t0 = tcg_temp_new_i32();
1445 t1 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001446
aurel3266896cb2009-03-13 09:34:48 +00001447 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1448 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
pbrooka7812ae2008-11-17 14:43:54 +00001449 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
pbrookac56dd42008-02-03 19:56:33 +00001450 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
pbrooka7812ae2008-11-17 14:43:54 +00001451 tcg_temp_free_i32(t0);
1452 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +00001453}
1454#else
1455
pbrooka7812ae2008-11-17 14:43:54 +00001456static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001457{
1458#ifdef TCG_TARGET_HAS_ext8s_i64
pbrooka7812ae2008-11-17 14:43:54 +00001459 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001460#else
1461 tcg_gen_shli_i64(ret, arg, 56);
bellard5ff9d6a2008-02-04 00:37:54 +00001462 tcg_gen_sari_i64(ret, ret, 56);
bellardc896fe22008-02-01 10:05:41 +00001463#endif
1464}
1465
pbrooka7812ae2008-11-17 14:43:54 +00001466static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001467{
1468#ifdef TCG_TARGET_HAS_ext16s_i64
pbrooka7812ae2008-11-17 14:43:54 +00001469 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001470#else
1471 tcg_gen_shli_i64(ret, arg, 48);
bellard5ff9d6a2008-02-04 00:37:54 +00001472 tcg_gen_sari_i64(ret, ret, 48);
bellardc896fe22008-02-01 10:05:41 +00001473#endif
1474}
1475
pbrooka7812ae2008-11-17 14:43:54 +00001476static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001477{
1478#ifdef TCG_TARGET_HAS_ext32s_i64
pbrooka7812ae2008-11-17 14:43:54 +00001479 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001480#else
1481 tcg_gen_shli_i64(ret, arg, 32);
bellard5ff9d6a2008-02-04 00:37:54 +00001482 tcg_gen_sari_i64(ret, ret, 32);
bellardc896fe22008-02-01 10:05:41 +00001483#endif
1484}
1485
pbrooka7812ae2008-11-17 14:43:54 +00001486static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001487{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001488#ifdef TCG_TARGET_HAS_ext8u_i64
1489 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1490#else
pbrook86831432008-05-11 12:22:01 +00001491 tcg_gen_andi_i64(ret, arg, 0xffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001492#endif
pbrook86831432008-05-11 12:22:01 +00001493}
1494
pbrooka7812ae2008-11-17 14:43:54 +00001495static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001496{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001497#ifdef TCG_TARGET_HAS_ext16u_i64
1498 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1499#else
pbrook86831432008-05-11 12:22:01 +00001500 tcg_gen_andi_i64(ret, arg, 0xffffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001501#endif
pbrook86831432008-05-11 12:22:01 +00001502}
1503
pbrooka7812ae2008-11-17 14:43:54 +00001504static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001505{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001506#ifdef TCG_TARGET_HAS_ext32u_i64
1507 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1508#else
pbrook86831432008-05-11 12:22:01 +00001509 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001510#endif
pbrook86831432008-05-11 12:22:01 +00001511}
1512
bellardc896fe22008-02-01 10:05:41 +00001513/* Note: we assume the target supports move between 32 and 64 bit
pbrookac56dd42008-02-03 19:56:33 +00001514 registers. This will probably break MIPS64 targets. */
pbrooka7812ae2008-11-17 14:43:54 +00001515static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001516{
pbrooka7812ae2008-11-17 14:43:54 +00001517 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
bellardc896fe22008-02-01 10:05:41 +00001518}
1519
1520/* Note: we assume the target supports move between 32 and 64 bit
1521 registers */
pbrooka7812ae2008-11-17 14:43:54 +00001522static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001523{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001524 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
bellardc896fe22008-02-01 10:05:41 +00001525}
1526
1527/* Note: we assume the target supports move between 32 and 64 bit
1528 registers */
pbrooka7812ae2008-11-17 14:43:54 +00001529static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001530{
pbrooka7812ae2008-11-17 14:43:54 +00001531 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
bellardc896fe22008-02-01 10:05:41 +00001532}
1533
aurel329a5c57f2009-03-13 09:35:12 +00001534/* Note: we assume the six high bytes are set to zero */
1535static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1536{
1537#ifdef TCG_TARGET_HAS_bswap16_i64
1538 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1539#else
1540 TCGv_i64 t0 = tcg_temp_new_i64();
1541
1542 tcg_gen_ext8u_i64(t0, arg);
1543 tcg_gen_shli_i64(t0, t0, 8);
1544 tcg_gen_shri_i64(ret, arg, 8);
1545 tcg_gen_or_i64(ret, ret, t0);
1546 tcg_temp_free_i64(t0);
1547#endif
1548}
1549
1550/* Note: we assume the four high bytes are set to zero */
1551static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1552{
1553#ifdef TCG_TARGET_HAS_bswap32_i64
1554 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1555#else
1556 TCGv_i64 t0, t1;
1557 t0 = tcg_temp_new_i64();
1558 t1 = tcg_temp_new_i64();
1559
1560 tcg_gen_shli_i64(t0, arg, 24);
1561 tcg_gen_ext32u_i64(t0, t0);
1562
1563 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1564 tcg_gen_shli_i64(t1, t1, 8);
1565 tcg_gen_or_i64(t0, t0, t1);
1566
1567 tcg_gen_shri_i64(t1, arg, 8);
1568 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1569 tcg_gen_or_i64(t0, t0, t1);
1570
1571 tcg_gen_shri_i64(t1, arg, 24);
1572 tcg_gen_or_i64(ret, t0, t1);
1573 tcg_temp_free_i64(t0);
1574 tcg_temp_free_i64(t1);
1575#endif
1576}
1577
aurel3266896cb2009-03-13 09:34:48 +00001578static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001579{
aurel3266896cb2009-03-13 09:34:48 +00001580#ifdef TCG_TARGET_HAS_bswap64_i64
1581 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001582#else
Stefan Weilb3481132009-09-05 18:54:10 +02001583 TCGv_i64 t0 = tcg_temp_new_i64();
1584 TCGv_i64 t1 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001585
1586 tcg_gen_shli_i64(t0, arg, 56);
1587
1588 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1589 tcg_gen_shli_i64(t1, t1, 40);
1590 tcg_gen_or_i64(t0, t0, t1);
1591
1592 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1593 tcg_gen_shli_i64(t1, t1, 24);
1594 tcg_gen_or_i64(t0, t0, t1);
1595
1596 tcg_gen_andi_i64(t1, arg, 0xff000000);
1597 tcg_gen_shli_i64(t1, t1, 8);
1598 tcg_gen_or_i64(t0, t0, t1);
1599
1600 tcg_gen_shri_i64(t1, arg, 8);
1601 tcg_gen_andi_i64(t1, t1, 0xff000000);
1602 tcg_gen_or_i64(t0, t0, t1);
1603
1604 tcg_gen_shri_i64(t1, arg, 24);
1605 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1606 tcg_gen_or_i64(t0, t0, t1);
1607
1608 tcg_gen_shri_i64(t1, arg, 40);
1609 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1610 tcg_gen_or_i64(t0, t0, t1);
1611
1612 tcg_gen_shri_i64(t1, arg, 56);
1613 tcg_gen_or_i64(ret, t0, t1);
Stefan Weilb3481132009-09-05 18:54:10 +02001614 tcg_temp_free_i64(t0);
1615 tcg_temp_free_i64(t1);
bellardc896fe22008-02-01 10:05:41 +00001616#endif
1617}
1618
1619#endif
1620
pbrooka7812ae2008-11-17 14:43:54 +00001621static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook390efc52008-05-11 14:35:37 +00001622{
1623#ifdef TCG_TARGET_HAS_neg_i32
pbrooka7812ae2008-11-17 14:43:54 +00001624 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
pbrook390efc52008-05-11 14:35:37 +00001625#else
pbrooka7812ae2008-11-17 14:43:54 +00001626 TCGv_i32 t0 = tcg_const_i32(0);
bellarde8996ee2008-05-23 17:33:39 +00001627 tcg_gen_sub_i32(ret, t0, arg);
pbrooka7812ae2008-11-17 14:43:54 +00001628 tcg_temp_free_i32(t0);
pbrook390efc52008-05-11 14:35:37 +00001629#endif
1630}
1631
pbrooka7812ae2008-11-17 14:43:54 +00001632static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook390efc52008-05-11 14:35:37 +00001633{
1634#ifdef TCG_TARGET_HAS_neg_i64
pbrooka7812ae2008-11-17 14:43:54 +00001635 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
pbrook390efc52008-05-11 14:35:37 +00001636#else
pbrooka7812ae2008-11-17 14:43:54 +00001637 TCGv_i64 t0 = tcg_const_i64(0);
bellarde8996ee2008-05-23 17:33:39 +00001638 tcg_gen_sub_i64(ret, t0, arg);
pbrooka7812ae2008-11-17 14:43:54 +00001639 tcg_temp_free_i64(t0);
pbrook390efc52008-05-11 14:35:37 +00001640#endif
1641}
1642
pbrooka7812ae2008-11-17 14:43:54 +00001643static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
bellard0b6ce4c2008-05-17 12:40:44 +00001644{
aurel32d2604282009-03-09 22:35:13 +00001645#ifdef TCG_TARGET_HAS_not_i32
1646 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1647#else
bellarde8996ee2008-05-23 17:33:39 +00001648 tcg_gen_xori_i32(ret, arg, -1);
aurel32d2604282009-03-09 22:35:13 +00001649#endif
bellard0b6ce4c2008-05-17 12:40:44 +00001650}
1651
pbrooka7812ae2008-11-17 14:43:54 +00001652static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
bellard0b6ce4c2008-05-17 12:40:44 +00001653{
aurel32d2604282009-03-09 22:35:13 +00001654#ifdef TCG_TARGET_HAS_not_i64
aurel3243e860e2009-03-10 10:29:45 +00001655 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
Richard Hendersona10f9f42010-03-19 12:44:47 -07001656#elif defined(TCG_TARGET_HAS_not_i32) && TCG_TARGET_REG_BITS == 32
1657 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1658 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
aurel32d2604282009-03-09 22:35:13 +00001659#else
bellarde8996ee2008-05-23 17:33:39 +00001660 tcg_gen_xori_i64(ret, arg, -1);
aurel32d2604282009-03-09 22:35:13 +00001661#endif
bellard0b6ce4c2008-05-17 12:40:44 +00001662}
bellard5ff9d6a2008-02-04 00:37:54 +00001663
pbrooka7812ae2008-11-17 14:43:54 +00001664static inline void tcg_gen_discard_i32(TCGv_i32 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001665{
pbrooka7812ae2008-11-17 14:43:54 +00001666 tcg_gen_op1_i32(INDEX_op_discard, arg);
bellard5ff9d6a2008-02-04 00:37:54 +00001667}
1668
1669#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001670static inline void tcg_gen_discard_i64(TCGv_i64 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001671{
pbrooka7812ae2008-11-17 14:43:54 +00001672 tcg_gen_discard_i32(TCGV_LOW(arg));
bellard5ff9d6a2008-02-04 00:37:54 +00001673 tcg_gen_discard_i32(TCGV_HIGH(arg));
1674}
1675#else
pbrooka7812ae2008-11-17 14:43:54 +00001676static inline void tcg_gen_discard_i64(TCGv_i64 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001677{
pbrooka7812ae2008-11-17 14:43:54 +00001678 tcg_gen_op1_i64(INDEX_op_discard, arg);
bellard5ff9d6a2008-02-04 00:37:54 +00001679}
1680#endif
1681
pbrooka7812ae2008-11-17 14:43:54 +00001682static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
pbrook36aa55d2008-09-21 13:48:32 +00001683{
1684#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001685 tcg_gen_mov_i32(TCGV_LOW(dest), low);
pbrook36aa55d2008-09-21 13:48:32 +00001686 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
1687#else
pbrooka7812ae2008-11-17 14:43:54 +00001688 TCGv_i64 tmp = tcg_temp_new_i64();
pbrook36aa55d2008-09-21 13:48:32 +00001689 /* This extension is only needed for type correctness.
1690 We may be able to do better given target specific information. */
1691 tcg_gen_extu_i32_i64(tmp, high);
1692 tcg_gen_shli_i64(tmp, tmp, 32);
1693 tcg_gen_extu_i32_i64(dest, low);
1694 tcg_gen_or_i64(dest, dest, tmp);
pbrooka7812ae2008-11-17 14:43:54 +00001695 tcg_temp_free_i64(tmp);
pbrook36aa55d2008-09-21 13:48:32 +00001696#endif
1697}
1698
pbrooka7812ae2008-11-17 14:43:54 +00001699static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low, TCGv_i64 high)
blueswir1945ca822008-09-21 18:32:28 +00001700{
1701#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001702 tcg_gen_concat_i32_i64(dest, TCGV_LOW(low), TCGV_LOW(high));
blueswir1945ca822008-09-21 18:32:28 +00001703#else
pbrooka7812ae2008-11-17 14:43:54 +00001704 TCGv_i64 tmp = tcg_temp_new_i64();
pbrook88422e22008-09-23 22:31:10 +00001705 tcg_gen_ext32u_i64(dest, low);
blueswir1945ca822008-09-21 18:32:28 +00001706 tcg_gen_shli_i64(tmp, high, 32);
pbrook88422e22008-09-23 22:31:10 +00001707 tcg_gen_or_i64(dest, dest, tmp);
pbrooka7812ae2008-11-17 14:43:54 +00001708 tcg_temp_free_i64(tmp);
blueswir1945ca822008-09-21 18:32:28 +00001709#endif
1710}
1711
pbrooka7812ae2008-11-17 14:43:54 +00001712static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001713{
Richard Henderson241cbed2010-02-16 14:10:13 -08001714#ifdef TCG_TARGET_HAS_andc_i32
1715 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1716#else
pbrooka7812ae2008-11-17 14:43:54 +00001717 TCGv_i32 t0;
1718 t0 = tcg_temp_new_i32();
aurel32f24cb332008-10-21 11:28:59 +00001719 tcg_gen_not_i32(t0, arg2);
1720 tcg_gen_and_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001721 tcg_temp_free_i32(t0);
Richard Henderson241cbed2010-02-16 14:10:13 -08001722#endif
aurel32f24cb332008-10-21 11:28:59 +00001723}
1724
pbrooka7812ae2008-11-17 14:43:54 +00001725static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001726{
Richard Henderson241cbed2010-02-16 14:10:13 -08001727#ifdef TCG_TARGET_HAS_andc_i64
1728 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1729#elif defined(TCG_TARGET_HAS_andc_i32) && TCG_TARGET_REG_BITS == 32
1730 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1731 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1732#else
pbrooka7812ae2008-11-17 14:43:54 +00001733 TCGv_i64 t0;
1734 t0 = tcg_temp_new_i64();
aurel32f24cb332008-10-21 11:28:59 +00001735 tcg_gen_not_i64(t0, arg2);
1736 tcg_gen_and_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001737 tcg_temp_free_i64(t0);
Richard Henderson241cbed2010-02-16 14:10:13 -08001738#endif
aurel32f24cb332008-10-21 11:28:59 +00001739}
1740
pbrooka7812ae2008-11-17 14:43:54 +00001741static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001742{
aurel327fc81052009-03-10 19:37:39 +00001743 tcg_gen_xor_i32(ret, arg1, arg2);
1744 tcg_gen_not_i32(ret, ret);
aurel32f24cb332008-10-21 11:28:59 +00001745}
1746
pbrooka7812ae2008-11-17 14:43:54 +00001747static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001748{
aurel327fc81052009-03-10 19:37:39 +00001749 tcg_gen_xor_i64(ret, arg1, arg2);
1750 tcg_gen_not_i64(ret, ret);
aurel32f24cb332008-10-21 11:28:59 +00001751}
1752
pbrooka7812ae2008-11-17 14:43:54 +00001753static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001754{
aurel327fc81052009-03-10 19:37:39 +00001755 tcg_gen_and_i32(ret, arg1, arg2);
1756 tcg_gen_not_i32(ret, ret);
aurel32f24cb332008-10-21 11:28:59 +00001757}
1758
pbrooka7812ae2008-11-17 14:43:54 +00001759static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001760{
aurel327fc81052009-03-10 19:37:39 +00001761 tcg_gen_and_i64(ret, arg1, arg2);
1762 tcg_gen_not_i64(ret, ret);
aurel32f24cb332008-10-21 11:28:59 +00001763}
1764
pbrooka7812ae2008-11-17 14:43:54 +00001765static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001766{
aurel327fc81052009-03-10 19:37:39 +00001767 tcg_gen_or_i32(ret, arg1, arg2);
1768 tcg_gen_not_i32(ret, ret);
aurel32f24cb332008-10-21 11:28:59 +00001769}
1770
pbrooka7812ae2008-11-17 14:43:54 +00001771static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001772{
aurel327fc81052009-03-10 19:37:39 +00001773 tcg_gen_or_i64(ret, arg1, arg2);
1774 tcg_gen_not_i64(ret, ret);
aurel32f24cb332008-10-21 11:28:59 +00001775}
1776
pbrooka7812ae2008-11-17 14:43:54 +00001777static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001778{
Richard Henderson791d1262010-02-16 14:15:28 -08001779#ifdef TCG_TARGET_HAS_orc_i32
1780 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
1781#else
pbrooka7812ae2008-11-17 14:43:54 +00001782 TCGv_i32 t0;
1783 t0 = tcg_temp_new_i32();
aurel32f24cb332008-10-21 11:28:59 +00001784 tcg_gen_not_i32(t0, arg2);
1785 tcg_gen_or_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001786 tcg_temp_free_i32(t0);
Richard Henderson791d1262010-02-16 14:15:28 -08001787#endif
aurel32f24cb332008-10-21 11:28:59 +00001788}
1789
pbrooka7812ae2008-11-17 14:43:54 +00001790static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001791{
Richard Henderson791d1262010-02-16 14:15:28 -08001792#ifdef TCG_TARGET_HAS_orc_i64
1793 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
1794#elif defined(TCG_TARGET_HAS_orc_i32) && TCG_TARGET_REG_BITS == 32
1795 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1796 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1797#else
pbrooka7812ae2008-11-17 14:43:54 +00001798 TCGv_i64 t0;
1799 t0 = tcg_temp_new_i64();
aurel32f24cb332008-10-21 11:28:59 +00001800 tcg_gen_not_i64(t0, arg2);
1801 tcg_gen_or_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001802 tcg_temp_free_i64(t0);
Richard Henderson791d1262010-02-16 14:15:28 -08001803#endif
aurel32f24cb332008-10-21 11:28:59 +00001804}
1805
pbrooka7812ae2008-11-17 14:43:54 +00001806static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3215824572008-11-03 07:08:36 +00001807{
aurel32d42f1832009-03-09 18:50:53 +00001808#ifdef TCG_TARGET_HAS_rot_i32
1809 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
1810#else
pbrooka7812ae2008-11-17 14:43:54 +00001811 TCGv_i32 t0, t1;
aurel3215824572008-11-03 07:08:36 +00001812
pbrooka7812ae2008-11-17 14:43:54 +00001813 t0 = tcg_temp_new_i32();
1814 t1 = tcg_temp_new_i32();
aurel3215824572008-11-03 07:08:36 +00001815 tcg_gen_shl_i32(t0, arg1, arg2);
1816 tcg_gen_subfi_i32(t1, 32, arg2);
1817 tcg_gen_shr_i32(t1, arg1, t1);
1818 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001819 tcg_temp_free_i32(t0);
1820 tcg_temp_free_i32(t1);
aurel32d42f1832009-03-09 18:50:53 +00001821#endif
aurel3215824572008-11-03 07:08:36 +00001822}
1823
pbrooka7812ae2008-11-17 14:43:54 +00001824static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel3215824572008-11-03 07:08:36 +00001825{
aurel32d42f1832009-03-09 18:50:53 +00001826#ifdef TCG_TARGET_HAS_rot_i64
1827 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
1828#else
pbrooka7812ae2008-11-17 14:43:54 +00001829 TCGv_i64 t0, t1;
aurel3215824572008-11-03 07:08:36 +00001830
pbrooka7812ae2008-11-17 14:43:54 +00001831 t0 = tcg_temp_new_i64();
1832 t1 = tcg_temp_new_i64();
aurel3215824572008-11-03 07:08:36 +00001833 tcg_gen_shl_i64(t0, arg1, arg2);
1834 tcg_gen_subfi_i64(t1, 64, arg2);
1835 tcg_gen_shr_i64(t1, arg1, t1);
1836 tcg_gen_or_i64(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001837 tcg_temp_free_i64(t0);
1838 tcg_temp_free_i64(t1);
aurel32d42f1832009-03-09 18:50:53 +00001839#endif
aurel3215824572008-11-03 07:08:36 +00001840}
1841
pbrooka7812ae2008-11-17 14:43:54 +00001842static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
aurel3215824572008-11-03 07:08:36 +00001843{
1844 /* some cases can be optimized here */
1845 if (arg2 == 0) {
1846 tcg_gen_mov_i32(ret, arg1);
1847 } else {
aurel32d42f1832009-03-09 18:50:53 +00001848#ifdef TCG_TARGET_HAS_rot_i32
1849 TCGv_i32 t0 = tcg_const_i32(arg2);
1850 tcg_gen_rotl_i32(ret, arg1, t0);
1851 tcg_temp_free_i32(t0);
1852#else
pbrooka7812ae2008-11-17 14:43:54 +00001853 TCGv_i32 t0, t1;
1854 t0 = tcg_temp_new_i32();
1855 t1 = tcg_temp_new_i32();
aurel3215824572008-11-03 07:08:36 +00001856 tcg_gen_shli_i32(t0, arg1, arg2);
1857 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
1858 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001859 tcg_temp_free_i32(t0);
1860 tcg_temp_free_i32(t1);
aurel32d42f1832009-03-09 18:50:53 +00001861#endif
aurel3215824572008-11-03 07:08:36 +00001862 }
1863}
1864
pbrooka7812ae2008-11-17 14:43:54 +00001865static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3215824572008-11-03 07:08:36 +00001866{
1867 /* some cases can be optimized here */
1868 if (arg2 == 0) {
1869 tcg_gen_mov_i64(ret, arg1);
1870 } else {
aurel32d42f1832009-03-09 18:50:53 +00001871#ifdef TCG_TARGET_HAS_rot_i64
1872 TCGv_i64 t0 = tcg_const_i64(arg2);
1873 tcg_gen_rotl_i64(ret, arg1, t0);
1874 tcg_temp_free_i64(t0);
1875#else
pbrooka7812ae2008-11-17 14:43:54 +00001876 TCGv_i64 t0, t1;
1877 t0 = tcg_temp_new_i64();
1878 t1 = tcg_temp_new_i64();
aurel3215824572008-11-03 07:08:36 +00001879 tcg_gen_shli_i64(t0, arg1, arg2);
1880 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
1881 tcg_gen_or_i64(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001882 tcg_temp_free_i64(t0);
1883 tcg_temp_free_i64(t1);
aurel32d42f1832009-03-09 18:50:53 +00001884#endif
aurel3215824572008-11-03 07:08:36 +00001885 }
1886}
1887
pbrooka7812ae2008-11-17 14:43:54 +00001888static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3215824572008-11-03 07:08:36 +00001889{
aurel32d42f1832009-03-09 18:50:53 +00001890#ifdef TCG_TARGET_HAS_rot_i32
1891 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
1892#else
pbrooka7812ae2008-11-17 14:43:54 +00001893 TCGv_i32 t0, t1;
aurel3215824572008-11-03 07:08:36 +00001894
pbrooka7812ae2008-11-17 14:43:54 +00001895 t0 = tcg_temp_new_i32();
1896 t1 = tcg_temp_new_i32();
aurel3215824572008-11-03 07:08:36 +00001897 tcg_gen_shr_i32(t0, arg1, arg2);
1898 tcg_gen_subfi_i32(t1, 32, arg2);
1899 tcg_gen_shl_i32(t1, arg1, t1);
1900 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001901 tcg_temp_free_i32(t0);
1902 tcg_temp_free_i32(t1);
aurel32d42f1832009-03-09 18:50:53 +00001903#endif
aurel3215824572008-11-03 07:08:36 +00001904}
1905
pbrooka7812ae2008-11-17 14:43:54 +00001906static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel3215824572008-11-03 07:08:36 +00001907{
aurel32d42f1832009-03-09 18:50:53 +00001908#ifdef TCG_TARGET_HAS_rot_i64
1909 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
1910#else
pbrooka7812ae2008-11-17 14:43:54 +00001911 TCGv_i64 t0, t1;
aurel3215824572008-11-03 07:08:36 +00001912
pbrooka7812ae2008-11-17 14:43:54 +00001913 t0 = tcg_temp_new_i64();
1914 t1 = tcg_temp_new_i64();
Aurelien Jarnod9885a02009-07-18 11:15:40 +02001915 tcg_gen_shr_i64(t0, arg1, arg2);
aurel3215824572008-11-03 07:08:36 +00001916 tcg_gen_subfi_i64(t1, 64, arg2);
1917 tcg_gen_shl_i64(t1, arg1, t1);
1918 tcg_gen_or_i64(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001919 tcg_temp_free_i64(t0);
1920 tcg_temp_free_i64(t1);
aurel32d42f1832009-03-09 18:50:53 +00001921#endif
aurel3215824572008-11-03 07:08:36 +00001922}
1923
pbrooka7812ae2008-11-17 14:43:54 +00001924static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
aurel3215824572008-11-03 07:08:36 +00001925{
1926 /* some cases can be optimized here */
1927 if (arg2 == 0) {
1928 tcg_gen_mov_i32(ret, arg1);
1929 } else {
1930 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
1931 }
1932}
1933
pbrooka7812ae2008-11-17 14:43:54 +00001934static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3215824572008-11-03 07:08:36 +00001935{
1936 /* some cases can be optimized here */
1937 if (arg2 == 0) {
pbrookde3526b2008-11-03 13:30:50 +00001938 tcg_gen_mov_i64(ret, arg1);
aurel3215824572008-11-03 07:08:36 +00001939 } else {
1940 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
1941 }
1942}
1943
bellardc896fe22008-02-01 10:05:41 +00001944/***************************************/
bellardc896fe22008-02-01 10:05:41 +00001945/* QEMU specific operations. Their type depend on the QEMU CPU
1946 type. */
1947#ifndef TARGET_LONG_BITS
1948#error must include QEMU headers
1949#endif
1950
pbrooka7812ae2008-11-17 14:43:54 +00001951#if TARGET_LONG_BITS == 32
1952#define TCGv TCGv_i32
1953#define tcg_temp_new() tcg_temp_new_i32()
1954#define tcg_global_reg_new tcg_global_reg_new_i32
1955#define tcg_global_mem_new tcg_global_mem_new_i32
aurel32df9247b2009-01-01 14:09:05 +00001956#define tcg_temp_local_new() tcg_temp_local_new_i32()
pbrooka7812ae2008-11-17 14:43:54 +00001957#define tcg_temp_free tcg_temp_free_i32
1958#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
1959#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
1960#define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
aurel32fe75bcf2009-03-10 08:57:16 +00001961#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
pbrooka7812ae2008-11-17 14:43:54 +00001962#else
1963#define TCGv TCGv_i64
1964#define tcg_temp_new() tcg_temp_new_i64()
1965#define tcg_global_reg_new tcg_global_reg_new_i64
1966#define tcg_global_mem_new tcg_global_mem_new_i64
aurel32df9247b2009-01-01 14:09:05 +00001967#define tcg_temp_local_new() tcg_temp_local_new_i64()
pbrooka7812ae2008-11-17 14:43:54 +00001968#define tcg_temp_free tcg_temp_free_i64
1969#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
1970#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
1971#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
aurel32fe75bcf2009-03-10 08:57:16 +00001972#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
pbrooka7812ae2008-11-17 14:43:54 +00001973#endif
1974
bellard7e4597d2008-05-22 16:56:05 +00001975/* debug info: write the PC of the corresponding QEMU CPU instruction */
1976static inline void tcg_gen_debug_insn_start(uint64_t pc)
1977{
1978 /* XXX: must really use a 32 bit size for TCGArg in all cases */
1979#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
pbrookbcb01262008-05-24 02:24:25 +00001980 tcg_gen_op2ii(INDEX_op_debug_insn_start,
1981 (uint32_t)(pc), (uint32_t)(pc >> 32));
bellard7e4597d2008-05-22 16:56:05 +00001982#else
1983 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
1984#endif
1985}
1986
bellardc896fe22008-02-01 10:05:41 +00001987static inline void tcg_gen_exit_tb(tcg_target_long val)
1988{
pbrookac56dd42008-02-03 19:56:33 +00001989 tcg_gen_op1i(INDEX_op_exit_tb, val);
bellardc896fe22008-02-01 10:05:41 +00001990}
1991
1992static inline void tcg_gen_goto_tb(int idx)
1993{
pbrookac56dd42008-02-03 19:56:33 +00001994 tcg_gen_op1i(INDEX_op_goto_tb, idx);
bellardc896fe22008-02-01 10:05:41 +00001995}
1996
1997#if TCG_TARGET_REG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001998static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001999{
2000#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002001 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002002#else
pbrooka7812ae2008-11-17 14:43:54 +00002003 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
2004 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002005 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002006#endif
2007}
2008
pbrookac56dd42008-02-03 19:56:33 +00002009static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002010{
2011#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002012 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002013#else
pbrooka7812ae2008-11-17 14:43:54 +00002014 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
2015 TCGV_HIGH(addr), mem_index);
2016 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002017#endif
2018}
2019
pbrookac56dd42008-02-03 19:56:33 +00002020static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002021{
2022#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002023 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002024#else
pbrooka7812ae2008-11-17 14:43:54 +00002025 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
2026 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002027 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002028#endif
2029}
2030
pbrookac56dd42008-02-03 19:56:33 +00002031static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002032{
2033#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002034 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002035#else
pbrooka7812ae2008-11-17 14:43:54 +00002036 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
2037 TCGV_HIGH(addr), mem_index);
2038 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002039#endif
2040}
2041
pbrookac56dd42008-02-03 19:56:33 +00002042static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002043{
2044#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002045 tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002046#else
pbrooka7812ae2008-11-17 14:43:54 +00002047 tcg_gen_op4i_i32(INDEX_op_qemu_ld32u, TCGV_LOW(ret), TCGV_LOW(addr),
2048 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002049 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002050#endif
2051}
2052
pbrookac56dd42008-02-03 19:56:33 +00002053static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002054{
2055#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002056 tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002057#else
pbrooka7812ae2008-11-17 14:43:54 +00002058 tcg_gen_op4i_i32(INDEX_op_qemu_ld32u, TCGV_LOW(ret), TCGV_LOW(addr),
2059 TCGV_HIGH(addr), mem_index);
2060 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002061#endif
2062}
2063
pbrooka7812ae2008-11-17 14:43:54 +00002064static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002065{
2066#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002067 tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002068#else
pbrooka7812ae2008-11-17 14:43:54 +00002069 tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
2070 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002071#endif
2072}
2073
pbrookac56dd42008-02-03 19:56:33 +00002074static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002075{
2076#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002077 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002078#else
pbrooka7812ae2008-11-17 14:43:54 +00002079 tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
2080 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002081#endif
2082}
2083
pbrookac56dd42008-02-03 19:56:33 +00002084static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002085{
2086#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002087 tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002088#else
pbrooka7812ae2008-11-17 14:43:54 +00002089 tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
2090 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002091#endif
2092}
2093
pbrookac56dd42008-02-03 19:56:33 +00002094static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002095{
2096#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002097 tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002098#else
pbrooka7812ae2008-11-17 14:43:54 +00002099 tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
2100 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002101#endif
2102}
2103
pbrooka7812ae2008-11-17 14:43:54 +00002104static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002105{
2106#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002107 tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
2108 mem_index);
bellardc896fe22008-02-01 10:05:41 +00002109#else
pbrooka7812ae2008-11-17 14:43:54 +00002110 tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
2111 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002112#endif
2113}
2114
blueswir156b8f562008-02-25 18:29:19 +00002115#define tcg_gen_ld_ptr tcg_gen_ld_i32
blueswir1a768e4b2008-03-16 19:16:37 +00002116#define tcg_gen_discard_ptr tcg_gen_discard_i32
blueswir1f8422f52008-02-24 07:45:43 +00002117
bellardc896fe22008-02-01 10:05:41 +00002118#else /* TCG_TARGET_REG_BITS == 32 */
2119
pbrookac56dd42008-02-03 19:56:33 +00002120static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002121{
pbrooka7812ae2008-11-17 14:43:54 +00002122 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002123}
2124
pbrookac56dd42008-02-03 19:56:33 +00002125static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002126{
pbrooka7812ae2008-11-17 14:43:54 +00002127 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002128}
2129
pbrookac56dd42008-02-03 19:56:33 +00002130static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002131{
pbrooka7812ae2008-11-17 14:43:54 +00002132 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002133}
2134
pbrookac56dd42008-02-03 19:56:33 +00002135static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002136{
pbrooka7812ae2008-11-17 14:43:54 +00002137 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002138}
2139
pbrookac56dd42008-02-03 19:56:33 +00002140static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002141{
pbrooka7812ae2008-11-17 14:43:54 +00002142 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002143}
2144
pbrookac56dd42008-02-03 19:56:33 +00002145static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002146{
pbrooka7812ae2008-11-17 14:43:54 +00002147 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002148}
2149
pbrooka7812ae2008-11-17 14:43:54 +00002150static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002151{
pbrooka7812ae2008-11-17 14:43:54 +00002152 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002153}
2154
pbrookac56dd42008-02-03 19:56:33 +00002155static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002156{
pbrooka7812ae2008-11-17 14:43:54 +00002157 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002158}
2159
pbrookac56dd42008-02-03 19:56:33 +00002160static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002161{
pbrooka7812ae2008-11-17 14:43:54 +00002162 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002163}
2164
pbrookac56dd42008-02-03 19:56:33 +00002165static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002166{
pbrooka7812ae2008-11-17 14:43:54 +00002167 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002168}
2169
pbrooka7812ae2008-11-17 14:43:54 +00002170static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002171{
pbrooka7812ae2008-11-17 14:43:54 +00002172 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002173}
2174
blueswir156b8f562008-02-25 18:29:19 +00002175#define tcg_gen_ld_ptr tcg_gen_ld_i64
blueswir1a768e4b2008-03-16 19:16:37 +00002176#define tcg_gen_discard_ptr tcg_gen_discard_i64
blueswir1f8422f52008-02-24 07:45:43 +00002177
bellardc896fe22008-02-01 10:05:41 +00002178#endif /* TCG_TARGET_REG_BITS != 32 */
blueswir1f8422f52008-02-24 07:45:43 +00002179
2180#if TARGET_LONG_BITS == 64
blueswir1f8422f52008-02-24 07:45:43 +00002181#define tcg_gen_movi_tl tcg_gen_movi_i64
2182#define tcg_gen_mov_tl tcg_gen_mov_i64
2183#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2184#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2185#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2186#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2187#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2188#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2189#define tcg_gen_ld_tl tcg_gen_ld_i64
2190#define tcg_gen_st8_tl tcg_gen_st8_i64
2191#define tcg_gen_st16_tl tcg_gen_st16_i64
2192#define tcg_gen_st32_tl tcg_gen_st32_i64
2193#define tcg_gen_st_tl tcg_gen_st_i64
2194#define tcg_gen_add_tl tcg_gen_add_i64
2195#define tcg_gen_addi_tl tcg_gen_addi_i64
2196#define tcg_gen_sub_tl tcg_gen_sub_i64
pbrook390efc52008-05-11 14:35:37 +00002197#define tcg_gen_neg_tl tcg_gen_neg_i64
pbrook10460c82008-11-02 13:26:16 +00002198#define tcg_gen_subfi_tl tcg_gen_subfi_i64
blueswir1f8422f52008-02-24 07:45:43 +00002199#define tcg_gen_subi_tl tcg_gen_subi_i64
2200#define tcg_gen_and_tl tcg_gen_and_i64
2201#define tcg_gen_andi_tl tcg_gen_andi_i64
2202#define tcg_gen_or_tl tcg_gen_or_i64
2203#define tcg_gen_ori_tl tcg_gen_ori_i64
2204#define tcg_gen_xor_tl tcg_gen_xor_i64
2205#define tcg_gen_xori_tl tcg_gen_xori_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002206#define tcg_gen_not_tl tcg_gen_not_i64
blueswir1f8422f52008-02-24 07:45:43 +00002207#define tcg_gen_shl_tl tcg_gen_shl_i64
2208#define tcg_gen_shli_tl tcg_gen_shli_i64
2209#define tcg_gen_shr_tl tcg_gen_shr_i64
2210#define tcg_gen_shri_tl tcg_gen_shri_i64
2211#define tcg_gen_sar_tl tcg_gen_sar_i64
2212#define tcg_gen_sari_tl tcg_gen_sari_i64
blueswir10cf767d2008-03-02 18:20:59 +00002213#define tcg_gen_brcond_tl tcg_gen_brcond_i64
pbrookcb636692008-05-24 02:22:00 +00002214#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
Richard Hendersonbe210ac2010-01-07 10:13:31 -08002215#define tcg_gen_setcond_tl tcg_gen_setcond_i64
Aurelien Jarnoadd1e7e2010-02-08 12:06:05 +01002216#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
thsf730fd22008-05-04 08:14:08 +00002217#define tcg_gen_mul_tl tcg_gen_mul_i64
2218#define tcg_gen_muli_tl tcg_gen_muli_i64
aurel32ab364212009-03-29 01:19:22 +00002219#define tcg_gen_div_tl tcg_gen_div_i64
2220#define tcg_gen_rem_tl tcg_gen_rem_i64
aurel32864951a2009-03-29 14:08:54 +00002221#define tcg_gen_divu_tl tcg_gen_divu_i64
2222#define tcg_gen_remu_tl tcg_gen_remu_i64
blueswir1a768e4b2008-03-16 19:16:37 +00002223#define tcg_gen_discard_tl tcg_gen_discard_i64
blueswir1e4290732008-03-22 08:39:04 +00002224#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2225#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2226#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2227#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2228#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2229#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002230#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2231#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2232#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2233#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2234#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2235#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
aurel32911d79b2009-03-13 09:35:19 +00002236#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2237#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2238#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
blueswir1945ca822008-09-21 18:32:28 +00002239#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
aurel32f24cb332008-10-21 11:28:59 +00002240#define tcg_gen_andc_tl tcg_gen_andc_i64
2241#define tcg_gen_eqv_tl tcg_gen_eqv_i64
2242#define tcg_gen_nand_tl tcg_gen_nand_i64
2243#define tcg_gen_nor_tl tcg_gen_nor_i64
2244#define tcg_gen_orc_tl tcg_gen_orc_i64
aurel3215824572008-11-03 07:08:36 +00002245#define tcg_gen_rotl_tl tcg_gen_rotl_i64
2246#define tcg_gen_rotli_tl tcg_gen_rotli_i64
2247#define tcg_gen_rotr_tl tcg_gen_rotr_i64
2248#define tcg_gen_rotri_tl tcg_gen_rotri_i64
blueswir1a98824a2008-03-13 20:46:42 +00002249#define tcg_const_tl tcg_const_i64
aurel32bdffd4a2008-10-21 11:30:45 +00002250#define tcg_const_local_tl tcg_const_local_i64
blueswir1f8422f52008-02-24 07:45:43 +00002251#else
blueswir1f8422f52008-02-24 07:45:43 +00002252#define tcg_gen_movi_tl tcg_gen_movi_i32
2253#define tcg_gen_mov_tl tcg_gen_mov_i32
2254#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2255#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2256#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2257#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2258#define tcg_gen_ld32u_tl tcg_gen_ld_i32
2259#define tcg_gen_ld32s_tl tcg_gen_ld_i32
2260#define tcg_gen_ld_tl tcg_gen_ld_i32
2261#define tcg_gen_st8_tl tcg_gen_st8_i32
2262#define tcg_gen_st16_tl tcg_gen_st16_i32
2263#define tcg_gen_st32_tl tcg_gen_st_i32
2264#define tcg_gen_st_tl tcg_gen_st_i32
2265#define tcg_gen_add_tl tcg_gen_add_i32
2266#define tcg_gen_addi_tl tcg_gen_addi_i32
2267#define tcg_gen_sub_tl tcg_gen_sub_i32
pbrook390efc52008-05-11 14:35:37 +00002268#define tcg_gen_neg_tl tcg_gen_neg_i32
aurel3200457342008-11-02 08:23:04 +00002269#define tcg_gen_subfi_tl tcg_gen_subfi_i32
blueswir1f8422f52008-02-24 07:45:43 +00002270#define tcg_gen_subi_tl tcg_gen_subi_i32
2271#define tcg_gen_and_tl tcg_gen_and_i32
2272#define tcg_gen_andi_tl tcg_gen_andi_i32
2273#define tcg_gen_or_tl tcg_gen_or_i32
2274#define tcg_gen_ori_tl tcg_gen_ori_i32
2275#define tcg_gen_xor_tl tcg_gen_xor_i32
2276#define tcg_gen_xori_tl tcg_gen_xori_i32
bellard0b6ce4c2008-05-17 12:40:44 +00002277#define tcg_gen_not_tl tcg_gen_not_i32
blueswir1f8422f52008-02-24 07:45:43 +00002278#define tcg_gen_shl_tl tcg_gen_shl_i32
2279#define tcg_gen_shli_tl tcg_gen_shli_i32
2280#define tcg_gen_shr_tl tcg_gen_shr_i32
2281#define tcg_gen_shri_tl tcg_gen_shri_i32
2282#define tcg_gen_sar_tl tcg_gen_sar_i32
2283#define tcg_gen_sari_tl tcg_gen_sari_i32
blueswir10cf767d2008-03-02 18:20:59 +00002284#define tcg_gen_brcond_tl tcg_gen_brcond_i32
pbrookcb636692008-05-24 02:22:00 +00002285#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
Richard Hendersonbe210ac2010-01-07 10:13:31 -08002286#define tcg_gen_setcond_tl tcg_gen_setcond_i32
Aurelien Jarnoadd1e7e2010-02-08 12:06:05 +01002287#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
thsf730fd22008-05-04 08:14:08 +00002288#define tcg_gen_mul_tl tcg_gen_mul_i32
2289#define tcg_gen_muli_tl tcg_gen_muli_i32
aurel32ab364212009-03-29 01:19:22 +00002290#define tcg_gen_div_tl tcg_gen_div_i32
2291#define tcg_gen_rem_tl tcg_gen_rem_i32
aurel32864951a2009-03-29 14:08:54 +00002292#define tcg_gen_divu_tl tcg_gen_divu_i32
2293#define tcg_gen_remu_tl tcg_gen_remu_i32
blueswir1a768e4b2008-03-16 19:16:37 +00002294#define tcg_gen_discard_tl tcg_gen_discard_i32
blueswir1e4290732008-03-22 08:39:04 +00002295#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2296#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2297#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2298#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2299#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2300#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002301#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2302#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2303#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2304#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2305#define tcg_gen_ext32u_tl tcg_gen_mov_i32
2306#define tcg_gen_ext32s_tl tcg_gen_mov_i32
aurel32911d79b2009-03-13 09:35:19 +00002307#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2308#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
blueswir1945ca822008-09-21 18:32:28 +00002309#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
aurel32f24cb332008-10-21 11:28:59 +00002310#define tcg_gen_andc_tl tcg_gen_andc_i32
2311#define tcg_gen_eqv_tl tcg_gen_eqv_i32
2312#define tcg_gen_nand_tl tcg_gen_nand_i32
2313#define tcg_gen_nor_tl tcg_gen_nor_i32
2314#define tcg_gen_orc_tl tcg_gen_orc_i32
aurel3215824572008-11-03 07:08:36 +00002315#define tcg_gen_rotl_tl tcg_gen_rotl_i32
2316#define tcg_gen_rotli_tl tcg_gen_rotli_i32
2317#define tcg_gen_rotr_tl tcg_gen_rotr_i32
2318#define tcg_gen_rotri_tl tcg_gen_rotri_i32
blueswir1a98824a2008-03-13 20:46:42 +00002319#define tcg_const_tl tcg_const_i32
aurel32bdffd4a2008-10-21 11:30:45 +00002320#define tcg_const_local_tl tcg_const_local_i32
blueswir1f8422f52008-02-24 07:45:43 +00002321#endif
pbrook6ddbc6e2008-03-31 03:46:33 +00002322
2323#if TCG_TARGET_REG_BITS == 32
ths48d38ca2008-05-18 22:50:49 +00002324#define tcg_gen_add_ptr tcg_gen_add_i32
pbrook6ddbc6e2008-03-31 03:46:33 +00002325#define tcg_gen_addi_ptr tcg_gen_addi_i32
ths48d38ca2008-05-18 22:50:49 +00002326#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
pbrook6ddbc6e2008-03-31 03:46:33 +00002327#else /* TCG_TARGET_REG_BITS == 32 */
ths48d38ca2008-05-18 22:50:49 +00002328#define tcg_gen_add_ptr tcg_gen_add_i64
pbrook6ddbc6e2008-03-31 03:46:33 +00002329#define tcg_gen_addi_ptr tcg_gen_addi_i64
ths48d38ca2008-05-18 22:50:49 +00002330#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
pbrook6ddbc6e2008-03-31 03:46:33 +00002331#endif /* TCG_TARGET_REG_BITS != 32 */