blob: c68927e6653d580d8bf84f135c8e463f0de611b6 [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
Richard Henderson2bece2c2010-06-14 17:35:27 -0700356/* A version of dh_sizemask from def-helper.h that doesn't rely on
357 preprocessor magic. */
358static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
359{
360 return (is_64bit << n*2) | (is_signed << (n*2 + 1));
361}
362
bellardc896fe22008-02-01 10:05:41 +0000363/* helper calls */
pbrooka7812ae2008-11-17 14:43:54 +0000364static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
365 TCGArg ret, int nargs, TCGArg *args)
bellardc896fe22008-02-01 10:05:41 +0000366{
pbrooka7812ae2008-11-17 14:43:54 +0000367 TCGv_ptr fn;
368 fn = tcg_const_ptr((tcg_target_long)func);
369 tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
370 nargs, args);
371 tcg_temp_free_ptr(fn);
bellardc896fe22008-02-01 10:05:41 +0000372}
373
Aurelien Jarnodbfff4d2010-03-14 23:01:01 +0100374/* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
375 reserved for helpers in tcg-runtime.c. These helpers are all const
376 and pure, hence the call to tcg_gen_callN() with TCG_CALL_CONST |
377 TCG_CALL_PURE. This may need to be adjusted if these functions
378 start to be used with other helpers. */
Richard Henderson2bece2c2010-06-14 17:35:27 -0700379static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
Aurelien Jarno31d66552010-03-02 23:16:36 +0100380 TCGv_i32 a, TCGv_i32 b)
381{
382 TCGv_ptr fn;
383 TCGArg args[2];
384 fn = tcg_const_ptr((tcg_target_long)func);
385 args[0] = GET_TCGV_I32(a);
386 args[1] = GET_TCGV_I32(b);
Richard Henderson2bece2c2010-06-14 17:35:27 -0700387 tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
388 GET_TCGV_I32(ret), 2, args);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100389 tcg_temp_free_ptr(fn);
390}
391
Richard Henderson2bece2c2010-06-14 17:35:27 -0700392static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
pbrooka7812ae2008-11-17 14:43:54 +0000393 TCGv_i64 a, TCGv_i64 b)
bellardc896fe22008-02-01 10:05:41 +0000394{
pbrooka7812ae2008-11-17 14:43:54 +0000395 TCGv_ptr fn;
396 TCGArg args[2];
397 fn = tcg_const_ptr((tcg_target_long)func);
398 args[0] = GET_TCGV_I64(a);
399 args[1] = GET_TCGV_I64(b);
Richard Henderson2bece2c2010-06-14 17:35:27 -0700400 tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
401 GET_TCGV_I64(ret), 2, args);
pbrooka7812ae2008-11-17 14:43:54 +0000402 tcg_temp_free_ptr(fn);
blueswir1f8422f52008-02-24 07:45:43 +0000403}
404
bellardc896fe22008-02-01 10:05:41 +0000405/* 32 bit ops */
406
pbrooka7812ae2008-11-17 14:43:54 +0000407static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000408{
pbrooka7812ae2008-11-17 14:43:54 +0000409 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000410}
411
pbrooka7812ae2008-11-17 14:43:54 +0000412static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000413{
pbrooka7812ae2008-11-17 14:43:54 +0000414 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000415}
416
pbrooka7812ae2008-11-17 14:43:54 +0000417static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000418{
pbrooka7812ae2008-11-17 14:43:54 +0000419 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000420}
421
pbrooka7812ae2008-11-17 14:43:54 +0000422static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000423{
pbrooka7812ae2008-11-17 14:43:54 +0000424 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000425}
426
pbrooka7812ae2008-11-17 14:43:54 +0000427static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000428{
pbrooka7812ae2008-11-17 14:43:54 +0000429 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000430}
431
pbrooka7812ae2008-11-17 14:43:54 +0000432static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000433{
pbrooka7812ae2008-11-17 14:43:54 +0000434 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000435}
436
pbrooka7812ae2008-11-17 14:43:54 +0000437static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000438{
pbrooka7812ae2008-11-17 14:43:54 +0000439 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000440}
441
pbrooka7812ae2008-11-17 14:43:54 +0000442static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000443{
pbrooka7812ae2008-11-17 14:43:54 +0000444 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000445}
446
pbrooka7812ae2008-11-17 14:43:54 +0000447static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000448{
pbrooka7812ae2008-11-17 14:43:54 +0000449 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000450}
451
pbrooka7812ae2008-11-17 14:43:54 +0000452static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000453{
blueswir170894422008-02-20 18:01:23 +0000454 /* some cases can be optimized here */
455 if (arg2 == 0) {
456 tcg_gen_mov_i32(ret, arg1);
457 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000458 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000459 tcg_gen_add_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000460 tcg_temp_free_i32(t0);
blueswir170894422008-02-20 18:01:23 +0000461 }
bellardc896fe22008-02-01 10:05:41 +0000462}
463
pbrooka7812ae2008-11-17 14:43:54 +0000464static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000465{
pbrooka7812ae2008-11-17 14:43:54 +0000466 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000467}
468
pbrooka7812ae2008-11-17 14:43:54 +0000469static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
aurel3200457342008-11-02 08:23:04 +0000470{
pbrooka7812ae2008-11-17 14:43:54 +0000471 TCGv_i32 t0 = tcg_const_i32(arg1);
aurel3200457342008-11-02 08:23:04 +0000472 tcg_gen_sub_i32(ret, t0, arg2);
pbrooka7812ae2008-11-17 14:43:54 +0000473 tcg_temp_free_i32(t0);
aurel3200457342008-11-02 08:23:04 +0000474}
475
pbrooka7812ae2008-11-17 14:43:54 +0000476static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000477{
blueswir170894422008-02-20 18:01:23 +0000478 /* some cases can be optimized here */
479 if (arg2 == 0) {
480 tcg_gen_mov_i32(ret, arg1);
481 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000482 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000483 tcg_gen_sub_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000484 tcg_temp_free_i32(t0);
blueswir170894422008-02-20 18:01:23 +0000485 }
bellardc896fe22008-02-01 10:05:41 +0000486}
487
pbrooka7812ae2008-11-17 14:43:54 +0000488static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000489{
aurel327fc81052009-03-10 19:37:39 +0000490 if (TCGV_EQUAL_I32(arg1, arg2)) {
491 tcg_gen_mov_i32(ret, arg1);
492 } else {
493 tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
494 }
bellardc896fe22008-02-01 10:05:41 +0000495}
496
pbrooka7812ae2008-11-17 14:43:54 +0000497static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000498{
499 /* some cases can be optimized here */
500 if (arg2 == 0) {
501 tcg_gen_movi_i32(ret, 0);
502 } else if (arg2 == 0xffffffff) {
503 tcg_gen_mov_i32(ret, arg1);
504 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000505 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000506 tcg_gen_and_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000507 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000508 }
509}
510
pbrooka7812ae2008-11-17 14:43:54 +0000511static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000512{
aurel327fc81052009-03-10 19:37:39 +0000513 if (TCGV_EQUAL_I32(arg1, arg2)) {
514 tcg_gen_mov_i32(ret, arg1);
515 } else {
516 tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
517 }
bellardc896fe22008-02-01 10:05:41 +0000518}
519
pbrooka7812ae2008-11-17 14:43:54 +0000520static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000521{
522 /* some cases can be optimized here */
523 if (arg2 == 0xffffffff) {
blueswir170894422008-02-20 18:01:23 +0000524 tcg_gen_movi_i32(ret, 0xffffffff);
bellardc896fe22008-02-01 10:05:41 +0000525 } else if (arg2 == 0) {
526 tcg_gen_mov_i32(ret, arg1);
527 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000528 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000529 tcg_gen_or_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000530 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000531 }
532}
533
pbrooka7812ae2008-11-17 14:43:54 +0000534static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000535{
aurel327fc81052009-03-10 19:37:39 +0000536 if (TCGV_EQUAL_I32(arg1, arg2)) {
537 tcg_gen_movi_i32(ret, 0);
538 } else {
539 tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
540 }
bellardc896fe22008-02-01 10:05:41 +0000541}
542
pbrooka7812ae2008-11-17 14:43:54 +0000543static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000544{
545 /* some cases can be optimized here */
546 if (arg2 == 0) {
547 tcg_gen_mov_i32(ret, arg1);
548 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000549 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000550 tcg_gen_xor_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000551 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000552 }
553}
554
pbrooka7812ae2008-11-17 14:43:54 +0000555static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000556{
pbrooka7812ae2008-11-17 14:43:54 +0000557 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000558}
559
pbrooka7812ae2008-11-17 14:43:54 +0000560static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000561{
bellard34151a22008-05-22 13:25:14 +0000562 if (arg2 == 0) {
563 tcg_gen_mov_i32(ret, arg1);
564 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000565 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000566 tcg_gen_shl_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000567 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000568 }
bellardc896fe22008-02-01 10:05:41 +0000569}
570
pbrooka7812ae2008-11-17 14:43:54 +0000571static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000572{
pbrooka7812ae2008-11-17 14:43:54 +0000573 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000574}
575
pbrooka7812ae2008-11-17 14:43:54 +0000576static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000577{
bellard34151a22008-05-22 13:25:14 +0000578 if (arg2 == 0) {
579 tcg_gen_mov_i32(ret, arg1);
580 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000581 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000582 tcg_gen_shr_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000583 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000584 }
bellardc896fe22008-02-01 10:05:41 +0000585}
586
pbrooka7812ae2008-11-17 14:43:54 +0000587static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000588{
pbrooka7812ae2008-11-17 14:43:54 +0000589 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000590}
591
pbrooka7812ae2008-11-17 14:43:54 +0000592static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000593{
bellard34151a22008-05-22 13:25:14 +0000594 if (arg2 == 0) {
595 tcg_gen_mov_i32(ret, arg1);
596 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000597 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000598 tcg_gen_sar_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000599 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000600 }
bellardc896fe22008-02-01 10:05:41 +0000601}
602
Richard Henderson8a56e842010-03-19 11:26:05 -0700603static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
604 TCGv_i32 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +0000605{
pbrooka7812ae2008-11-17 14:43:54 +0000606 tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000607}
608
Richard Henderson8a56e842010-03-19 11:26:05 -0700609static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
610 int32_t arg2, int label_index)
pbrookcb636692008-05-24 02:22:00 +0000611{
pbrooka7812ae2008-11-17 14:43:54 +0000612 TCGv_i32 t0 = tcg_const_i32(arg2);
pbrookcb636692008-05-24 02:22:00 +0000613 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
pbrooka7812ae2008-11-17 14:43:54 +0000614 tcg_temp_free_i32(t0);
pbrookcb636692008-05-24 02:22:00 +0000615}
616
Richard Henderson8a56e842010-03-19 11:26:05 -0700617static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +0100618 TCGv_i32 arg1, TCGv_i32 arg2)
619{
620 tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
621}
622
Richard Henderson8a56e842010-03-19 11:26:05 -0700623static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
624 TCGv_i32 arg1, int32_t arg2)
Aurelien Jarno5105c552010-02-08 12:10:15 +0100625{
626 TCGv_i32 t0 = tcg_const_i32(arg2);
627 tcg_gen_setcond_i32(cond, ret, arg1, t0);
628 tcg_temp_free_i32(t0);
629}
630
pbrooka7812ae2008-11-17 14:43:54 +0000631static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000632{
pbrooka7812ae2008-11-17 14:43:54 +0000633 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000634}
635
pbrooka7812ae2008-11-17 14:43:54 +0000636static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
thsf730fd22008-05-04 08:14:08 +0000637{
pbrooka7812ae2008-11-17 14:43:54 +0000638 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000639 tcg_gen_mul_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000640 tcg_temp_free_i32(t0);
thsf730fd22008-05-04 08:14:08 +0000641}
642
bellardc896fe22008-02-01 10:05:41 +0000643#ifdef TCG_TARGET_HAS_div_i32
pbrooka7812ae2008-11-17 14:43:54 +0000644static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000645{
pbrooka7812ae2008-11-17 14:43:54 +0000646 tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000647}
648
pbrooka7812ae2008-11-17 14:43:54 +0000649static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000650{
pbrooka7812ae2008-11-17 14:43:54 +0000651 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000652}
653
pbrooka7812ae2008-11-17 14:43:54 +0000654static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000655{
pbrooka7812ae2008-11-17 14:43:54 +0000656 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000657}
658
pbrooka7812ae2008-11-17 14:43:54 +0000659static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000660{
pbrooka7812ae2008-11-17 14:43:54 +0000661 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000662}
Aurelien Jarno31d66552010-03-02 23:16:36 +0100663#elif defined(TCG_TARGET_HAS_div2_i32)
pbrooka7812ae2008-11-17 14:43:54 +0000664static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000665{
pbrooka7812ae2008-11-17 14:43:54 +0000666 TCGv_i32 t0;
667 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +0000668 tcg_gen_sari_i32(t0, arg1, 31);
pbrooka7812ae2008-11-17 14:43:54 +0000669 tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
670 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000671}
672
pbrooka7812ae2008-11-17 14:43:54 +0000673static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000674{
pbrooka7812ae2008-11-17 14:43:54 +0000675 TCGv_i32 t0;
676 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +0000677 tcg_gen_sari_i32(t0, arg1, 31);
pbrooka7812ae2008-11-17 14:43:54 +0000678 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
679 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000680}
681
pbrooka7812ae2008-11-17 14:43:54 +0000682static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000683{
pbrooka7812ae2008-11-17 14:43:54 +0000684 TCGv_i32 t0;
685 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +0000686 tcg_gen_movi_i32(t0, 0);
pbrooka7812ae2008-11-17 14:43:54 +0000687 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
688 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000689}
690
pbrooka7812ae2008-11-17 14:43:54 +0000691static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000692{
pbrooka7812ae2008-11-17 14:43:54 +0000693 TCGv_i32 t0;
694 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +0000695 tcg_gen_movi_i32(t0, 0);
pbrooka7812ae2008-11-17 14:43:54 +0000696 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
697 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000698}
Aurelien Jarno31d66552010-03-02 23:16:36 +0100699#else
700static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
701{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700702 int sizemask = 0;
703 /* Return value and both arguments are 32-bit and signed. */
704 sizemask |= tcg_gen_sizemask(0, 0, 1);
705 sizemask |= tcg_gen_sizemask(1, 0, 1);
706 sizemask |= tcg_gen_sizemask(2, 0, 1);
707
708 tcg_gen_helper32(tcg_helper_div_i32, sizemask, ret, arg1, arg2);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100709}
710
711static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
712{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700713 int sizemask = 0;
714 /* Return value and both arguments are 32-bit and signed. */
715 sizemask |= tcg_gen_sizemask(0, 0, 1);
716 sizemask |= tcg_gen_sizemask(1, 0, 1);
717 sizemask |= tcg_gen_sizemask(2, 0, 1);
718
719 tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100720}
721
722static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
723{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700724 int sizemask = 0;
725 /* Return value and both arguments are 32-bit and unsigned. */
726 sizemask |= tcg_gen_sizemask(0, 0, 0);
727 sizemask |= tcg_gen_sizemask(1, 0, 0);
728 sizemask |= tcg_gen_sizemask(2, 0, 0);
729
730 tcg_gen_helper32(tcg_helper_divu_i32, ret, arg1, arg2, 0);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100731}
732
733static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
734{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700735 int sizemask = 0;
736 /* Return value and both arguments are 32-bit and unsigned. */
737 sizemask |= tcg_gen_sizemask(0, 0, 0);
738 sizemask |= tcg_gen_sizemask(1, 0, 0);
739 sizemask |= tcg_gen_sizemask(2, 0, 0);
740
741 tcg_gen_helper32(tcg_helper_remu_i32, ret, arg1, arg2, 0);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100742}
bellardc896fe22008-02-01 10:05:41 +0000743#endif
744
745#if TCG_TARGET_REG_BITS == 32
746
pbrooka7812ae2008-11-17 14:43:54 +0000747static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +0000748{
aurel32fe75bcf2009-03-10 08:57:16 +0000749 if (!TCGV_EQUAL_I64(ret, arg)) {
pbrooka7812ae2008-11-17 14:43:54 +0000750 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
blueswir14d072722008-05-03 20:52:26 +0000751 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
752 }
bellardc896fe22008-02-01 10:05:41 +0000753}
754
pbrooka7812ae2008-11-17 14:43:54 +0000755static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000756{
pbrooka7812ae2008-11-17 14:43:54 +0000757 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
pbrookac56dd42008-02-03 19:56:33 +0000758 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
bellardc896fe22008-02-01 10:05:41 +0000759}
760
pbrooka7812ae2008-11-17 14:43:54 +0000761static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
762 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000763{
pbrooka7812ae2008-11-17 14:43:54 +0000764 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000765 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000766}
767
pbrooka7812ae2008-11-17 14:43:54 +0000768static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
769 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000770{
pbrooka7812ae2008-11-17 14:43:54 +0000771 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
772 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000773}
774
pbrooka7812ae2008-11-17 14:43:54 +0000775static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
776 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000777{
aurel32a7477232009-02-09 20:43:53 +0000778 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000779 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000780}
781
pbrooka7812ae2008-11-17 14:43:54 +0000782static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
783 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000784{
pbrooka7812ae2008-11-17 14:43:54 +0000785 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
786 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000787}
788
pbrooka7812ae2008-11-17 14:43:54 +0000789static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
790 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000791{
pbrooka7812ae2008-11-17 14:43:54 +0000792 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000793 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000794}
795
pbrooka7812ae2008-11-17 14:43:54 +0000796static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
797 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000798{
pbrooka7812ae2008-11-17 14:43:54 +0000799 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
800 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000801}
802
pbrooka7812ae2008-11-17 14:43:54 +0000803static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
804 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000805{
806 /* since arg2 and ret have different types, they cannot be the
807 same temporary */
808#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000809 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
pbrooka7812ae2008-11-17 14:43:54 +0000810 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000811#else
pbrooka7812ae2008-11-17 14:43:54 +0000812 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000813 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000814#endif
815}
816
pbrooka7812ae2008-11-17 14:43:54 +0000817static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
818 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000819{
pbrooka7812ae2008-11-17 14:43:54 +0000820 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000821}
822
pbrooka7812ae2008-11-17 14:43:54 +0000823static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
824 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000825{
pbrooka7812ae2008-11-17 14:43:54 +0000826 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000827}
828
pbrooka7812ae2008-11-17 14:43:54 +0000829static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
830 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000831{
pbrooka7812ae2008-11-17 14:43:54 +0000832 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000833}
834
pbrooka7812ae2008-11-17 14:43:54 +0000835static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
836 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000837{
838#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000839 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
pbrooka7812ae2008-11-17 14:43:54 +0000840 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000841#else
pbrooka7812ae2008-11-17 14:43:54 +0000842 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000843 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000844#endif
845}
846
pbrooka7812ae2008-11-17 14:43:54 +0000847static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000848{
pbrooka7812ae2008-11-17 14:43:54 +0000849 tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
850 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
851 TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000852}
853
pbrooka7812ae2008-11-17 14:43:54 +0000854static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000855{
pbrooka7812ae2008-11-17 14:43:54 +0000856 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
857 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
858 TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000859}
860
pbrooka7812ae2008-11-17 14:43:54 +0000861static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000862{
pbrooka7812ae2008-11-17 14:43:54 +0000863 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
pbrookac56dd42008-02-03 19:56:33 +0000864 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000865}
866
pbrooka7812ae2008-11-17 14:43:54 +0000867static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000868{
aurel32e5105082009-03-11 02:57:30 +0000869 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
870 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000871}
872
pbrooka7812ae2008-11-17 14:43:54 +0000873static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000874{
aurel32e5105082009-03-11 02:57:30 +0000875 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
876 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000877}
878
pbrooka7812ae2008-11-17 14:43:54 +0000879static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000880{
pbrooka7812ae2008-11-17 14:43:54 +0000881 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
pbrookac56dd42008-02-03 19:56:33 +0000882 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000883}
884
pbrooka7812ae2008-11-17 14:43:54 +0000885static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000886{
aurel32e5105082009-03-11 02:57:30 +0000887 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
888 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000889}
890
pbrooka7812ae2008-11-17 14:43:54 +0000891static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000892{
pbrooka7812ae2008-11-17 14:43:54 +0000893 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
pbrookac56dd42008-02-03 19:56:33 +0000894 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000895}
896
897/* XXX: use generic code when basic block handling is OK or CPU
898 specific code (x86) */
pbrooka7812ae2008-11-17 14:43:54 +0000899static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000900{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700901 int sizemask = 0;
902 /* Return value and both arguments are 64-bit and signed. */
903 sizemask |= tcg_gen_sizemask(0, 1, 1);
904 sizemask |= tcg_gen_sizemask(1, 1, 1);
905 sizemask |= tcg_gen_sizemask(2, 1, 1);
906
907 tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000908}
909
pbrooka7812ae2008-11-17 14:43:54 +0000910static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000911{
912 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
913}
914
pbrooka7812ae2008-11-17 14:43:54 +0000915static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000916{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700917 int sizemask = 0;
918 /* Return value and both arguments are 64-bit and signed. */
919 sizemask |= tcg_gen_sizemask(0, 1, 1);
920 sizemask |= tcg_gen_sizemask(1, 1, 1);
921 sizemask |= tcg_gen_sizemask(2, 1, 1);
922
923 tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000924}
925
pbrooka7812ae2008-11-17 14:43:54 +0000926static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000927{
928 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
929}
930
pbrooka7812ae2008-11-17 14:43:54 +0000931static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000932{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700933 int sizemask = 0;
934 /* Return value and both arguments are 64-bit and signed. */
935 sizemask |= tcg_gen_sizemask(0, 1, 1);
936 sizemask |= tcg_gen_sizemask(1, 1, 1);
937 sizemask |= tcg_gen_sizemask(2, 1, 1);
938
939 tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000940}
941
pbrooka7812ae2008-11-17 14:43:54 +0000942static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000943{
944 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
945}
946
Richard Henderson8a56e842010-03-19 11:26:05 -0700947static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
948 TCGv_i64 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +0000949{
pbrooka7812ae2008-11-17 14:43:54 +0000950 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
951 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
952 TCGV_HIGH(arg2), cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000953}
954
Richard Henderson8a56e842010-03-19 11:26:05 -0700955static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +0100956 TCGv_i64 arg1, TCGv_i64 arg2)
957{
958 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
959 TCGV_LOW(arg1), TCGV_HIGH(arg1),
960 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
961 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
962}
963
pbrooka7812ae2008-11-17 14:43:54 +0000964static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000965{
pbrooka7812ae2008-11-17 14:43:54 +0000966 TCGv_i64 t0;
967 TCGv_i32 t1;
bellardc896fe22008-02-01 10:05:41 +0000968
pbrooka7812ae2008-11-17 14:43:54 +0000969 t0 = tcg_temp_new_i64();
970 t1 = tcg_temp_new_i32();
971
972 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
973 TCGV_LOW(arg1), TCGV_LOW(arg2));
974
975 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
pbrookac56dd42008-02-03 19:56:33 +0000976 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
pbrooka7812ae2008-11-17 14:43:54 +0000977 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
pbrookac56dd42008-02-03 19:56:33 +0000978 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
pbrooka7812ae2008-11-17 14:43:54 +0000979
bellardc896fe22008-02-01 10:05:41 +0000980 tcg_gen_mov_i64(ret, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000981 tcg_temp_free_i64(t0);
982 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +0000983}
984
pbrooka7812ae2008-11-17 14:43:54 +0000985static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000986{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700987 int sizemask = 0;
988 /* Return value and both arguments are 64-bit and signed. */
989 sizemask |= tcg_gen_sizemask(0, 1, 1);
990 sizemask |= tcg_gen_sizemask(1, 1, 1);
991 sizemask |= tcg_gen_sizemask(2, 1, 1);
992
993 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000994}
995
pbrooka7812ae2008-11-17 14:43:54 +0000996static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000997{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700998 int sizemask = 0;
999 /* Return value and both arguments are 64-bit and signed. */
1000 sizemask |= tcg_gen_sizemask(0, 1, 1);
1001 sizemask |= tcg_gen_sizemask(1, 1, 1);
1002 sizemask |= tcg_gen_sizemask(2, 1, 1);
1003
1004 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001005}
1006
pbrooka7812ae2008-11-17 14:43:54 +00001007static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001008{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001009 int sizemask = 0;
1010 /* Return value and both arguments are 64-bit and unsigned. */
1011 sizemask |= tcg_gen_sizemask(0, 1, 0);
1012 sizemask |= tcg_gen_sizemask(1, 1, 0);
1013 sizemask |= tcg_gen_sizemask(2, 1, 0);
1014
1015 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001016}
1017
pbrooka7812ae2008-11-17 14:43:54 +00001018static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001019{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001020 int sizemask = 0;
1021 /* Return value and both arguments are 64-bit and unsigned. */
1022 sizemask |= tcg_gen_sizemask(0, 1, 0);
1023 sizemask |= tcg_gen_sizemask(1, 1, 0);
1024 sizemask |= tcg_gen_sizemask(2, 1, 0);
1025
1026 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001027}
1028
1029#else
1030
pbrooka7812ae2008-11-17 14:43:54 +00001031static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001032{
aurel32fe75bcf2009-03-10 08:57:16 +00001033 if (!TCGV_EQUAL_I64(ret, arg))
pbrooka7812ae2008-11-17 14:43:54 +00001034 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001035}
1036
pbrooka7812ae2008-11-17 14:43:54 +00001037static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +00001038{
pbrooka7812ae2008-11-17 14:43:54 +00001039 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001040}
1041
pbrooka7812ae2008-11-17 14:43:54 +00001042static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001043 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001044{
pbrooka7812ae2008-11-17 14:43:54 +00001045 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001046}
1047
pbrooka7812ae2008-11-17 14:43:54 +00001048static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001049 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001050{
pbrooka7812ae2008-11-17 14:43:54 +00001051 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001052}
1053
pbrooka7812ae2008-11-17 14:43:54 +00001054static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001055 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001056{
pbrooka7812ae2008-11-17 14:43:54 +00001057 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001058}
1059
pbrooka7812ae2008-11-17 14:43:54 +00001060static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001061 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001062{
pbrooka7812ae2008-11-17 14:43:54 +00001063 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001064}
1065
pbrooka7812ae2008-11-17 14:43:54 +00001066static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001067 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001068{
pbrooka7812ae2008-11-17 14:43:54 +00001069 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001070}
1071
pbrooka7812ae2008-11-17 14:43:54 +00001072static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001073 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001074{
pbrooka7812ae2008-11-17 14:43:54 +00001075 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001076}
1077
pbrooka7812ae2008-11-17 14:43:54 +00001078static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_i64 arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001079{
pbrooka7812ae2008-11-17 14:43:54 +00001080 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001081}
1082
pbrooka7812ae2008-11-17 14:43:54 +00001083static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001084 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001085{
pbrooka7812ae2008-11-17 14:43:54 +00001086 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001087}
1088
pbrooka7812ae2008-11-17 14:43:54 +00001089static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001090 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001091{
pbrooka7812ae2008-11-17 14:43:54 +00001092 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001093}
1094
pbrooka7812ae2008-11-17 14:43:54 +00001095static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_i64 arg2,
pbrookac56dd42008-02-03 19:56:33 +00001096 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001097{
pbrooka7812ae2008-11-17 14:43:54 +00001098 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001099}
1100
pbrooka7812ae2008-11-17 14:43:54 +00001101static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_i64 arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001102{
pbrooka7812ae2008-11-17 14:43:54 +00001103 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001104}
1105
pbrooka7812ae2008-11-17 14:43:54 +00001106static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001107{
pbrooka7812ae2008-11-17 14:43:54 +00001108 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001109}
1110
pbrooka7812ae2008-11-17 14:43:54 +00001111static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001112{
pbrooka7812ae2008-11-17 14:43:54 +00001113 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001114}
1115
pbrooka7812ae2008-11-17 14:43:54 +00001116static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001117{
aurel327fc81052009-03-10 19:37:39 +00001118 if (TCGV_EQUAL_I64(arg1, arg2)) {
1119 tcg_gen_mov_i64(ret, arg1);
1120 } else {
1121 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1122 }
bellardc896fe22008-02-01 10:05:41 +00001123}
1124
pbrooka7812ae2008-11-17 14:43:54 +00001125static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001126{
pbrooka7812ae2008-11-17 14:43:54 +00001127 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001128 tcg_gen_and_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001129 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001130}
1131
pbrooka7812ae2008-11-17 14:43:54 +00001132static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001133{
aurel327fc81052009-03-10 19:37:39 +00001134 if (TCGV_EQUAL_I64(arg1, arg2)) {
1135 tcg_gen_mov_i64(ret, arg1);
1136 } else {
1137 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1138 }
bellardc896fe22008-02-01 10:05:41 +00001139}
1140
pbrooka7812ae2008-11-17 14:43:54 +00001141static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001142{
pbrooka7812ae2008-11-17 14:43:54 +00001143 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001144 tcg_gen_or_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001145 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001146}
1147
pbrooka7812ae2008-11-17 14:43:54 +00001148static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001149{
aurel327fc81052009-03-10 19:37:39 +00001150 if (TCGV_EQUAL_I64(arg1, arg2)) {
1151 tcg_gen_movi_i64(ret, 0);
1152 } else {
1153 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1154 }
bellardc896fe22008-02-01 10:05:41 +00001155}
1156
pbrooka7812ae2008-11-17 14:43:54 +00001157static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001158{
pbrooka7812ae2008-11-17 14:43:54 +00001159 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001160 tcg_gen_xor_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001161 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001162}
1163
pbrooka7812ae2008-11-17 14:43:54 +00001164static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001165{
pbrooka7812ae2008-11-17 14:43:54 +00001166 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001167}
1168
pbrooka7812ae2008-11-17 14:43:54 +00001169static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001170{
bellard34151a22008-05-22 13:25:14 +00001171 if (arg2 == 0) {
1172 tcg_gen_mov_i64(ret, arg1);
1173 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001174 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001175 tcg_gen_shl_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001176 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001177 }
bellardc896fe22008-02-01 10:05:41 +00001178}
1179
pbrooka7812ae2008-11-17 14:43:54 +00001180static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001181{
pbrooka7812ae2008-11-17 14:43:54 +00001182 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001183}
1184
pbrooka7812ae2008-11-17 14:43:54 +00001185static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001186{
bellard34151a22008-05-22 13:25:14 +00001187 if (arg2 == 0) {
1188 tcg_gen_mov_i64(ret, arg1);
1189 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001190 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001191 tcg_gen_shr_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001192 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001193 }
bellardc896fe22008-02-01 10:05:41 +00001194}
1195
pbrooka7812ae2008-11-17 14:43:54 +00001196static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001197{
pbrooka7812ae2008-11-17 14:43:54 +00001198 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001199}
1200
pbrooka7812ae2008-11-17 14:43:54 +00001201static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001202{
bellard34151a22008-05-22 13:25:14 +00001203 if (arg2 == 0) {
1204 tcg_gen_mov_i64(ret, arg1);
1205 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001206 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001207 tcg_gen_sar_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001208 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001209 }
bellardc896fe22008-02-01 10:05:41 +00001210}
1211
Richard Henderson8a56e842010-03-19 11:26:05 -07001212static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1213 TCGv_i64 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +00001214{
pbrooka7812ae2008-11-17 14:43:54 +00001215 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
bellardc896fe22008-02-01 10:05:41 +00001216}
1217
Richard Henderson8a56e842010-03-19 11:26:05 -07001218static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +01001219 TCGv_i64 arg1, TCGv_i64 arg2)
1220{
1221 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1222}
1223
pbrooka7812ae2008-11-17 14:43:54 +00001224static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001225{
pbrooka7812ae2008-11-17 14:43:54 +00001226 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001227}
1228
1229#ifdef TCG_TARGET_HAS_div_i64
pbrooka7812ae2008-11-17 14:43:54 +00001230static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001231{
pbrooka7812ae2008-11-17 14:43:54 +00001232 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001233}
1234
pbrooka7812ae2008-11-17 14:43:54 +00001235static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001236{
pbrooka7812ae2008-11-17 14:43:54 +00001237 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001238}
1239
pbrooka7812ae2008-11-17 14:43:54 +00001240static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001241{
pbrooka7812ae2008-11-17 14:43:54 +00001242 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001243}
1244
pbrooka7812ae2008-11-17 14:43:54 +00001245static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001246{
pbrooka7812ae2008-11-17 14:43:54 +00001247 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001248}
Aurelien Jarno31d66552010-03-02 23:16:36 +01001249#elif defined(TCG_TARGET_HAS_div2_i64)
pbrooka7812ae2008-11-17 14:43:54 +00001250static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001251{
pbrooka7812ae2008-11-17 14:43:54 +00001252 TCGv_i64 t0;
1253 t0 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001254 tcg_gen_sari_i64(t0, arg1, 63);
pbrooka7812ae2008-11-17 14:43:54 +00001255 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1256 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001257}
1258
pbrooka7812ae2008-11-17 14:43:54 +00001259static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001260{
pbrooka7812ae2008-11-17 14:43:54 +00001261 TCGv_i64 t0;
1262 t0 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001263 tcg_gen_sari_i64(t0, arg1, 63);
pbrooka7812ae2008-11-17 14:43:54 +00001264 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1265 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001266}
1267
pbrooka7812ae2008-11-17 14:43:54 +00001268static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001269{
pbrooka7812ae2008-11-17 14:43:54 +00001270 TCGv_i64 t0;
1271 t0 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001272 tcg_gen_movi_i64(t0, 0);
pbrooka7812ae2008-11-17 14:43:54 +00001273 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1274 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001275}
1276
pbrooka7812ae2008-11-17 14:43:54 +00001277static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001278{
pbrooka7812ae2008-11-17 14:43:54 +00001279 TCGv_i64 t0;
1280 t0 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001281 tcg_gen_movi_i64(t0, 0);
pbrooka7812ae2008-11-17 14:43:54 +00001282 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1283 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001284}
Aurelien Jarno31d66552010-03-02 23:16:36 +01001285#else
1286static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1287{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001288 int sizemask = 0;
1289 /* Return value and both arguments are 64-bit and signed. */
1290 sizemask |= tcg_gen_sizemask(0, 1, 1);
1291 sizemask |= tcg_gen_sizemask(1, 1, 1);
1292 sizemask |= tcg_gen_sizemask(2, 1, 1);
1293
1294 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
Aurelien Jarno31d66552010-03-02 23:16:36 +01001295}
1296
1297static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1298{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001299 int sizemask = 0;
1300 /* Return value and both arguments are 64-bit and signed. */
1301 sizemask |= tcg_gen_sizemask(0, 1, 1);
1302 sizemask |= tcg_gen_sizemask(1, 1, 1);
1303 sizemask |= tcg_gen_sizemask(2, 1, 1);
1304
1305 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
Aurelien Jarno31d66552010-03-02 23:16:36 +01001306}
1307
1308static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1309{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001310 int sizemask = 0;
1311 /* Return value and both arguments are 64-bit and unsigned. */
1312 sizemask |= tcg_gen_sizemask(0, 1, 0);
1313 sizemask |= tcg_gen_sizemask(1, 1, 0);
1314 sizemask |= tcg_gen_sizemask(2, 1, 0);
1315
1316 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
Aurelien Jarno31d66552010-03-02 23:16:36 +01001317}
1318
1319static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1320{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001321 int sizemask = 0;
1322 /* Return value and both arguments are 64-bit and unsigned. */
1323 sizemask |= tcg_gen_sizemask(0, 1, 0);
1324 sizemask |= tcg_gen_sizemask(1, 1, 0);
1325 sizemask |= tcg_gen_sizemask(2, 1, 0);
1326
1327 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
Aurelien Jarno31d66552010-03-02 23:16:36 +01001328}
bellardc896fe22008-02-01 10:05:41 +00001329#endif
1330
1331#endif
1332
pbrooka7812ae2008-11-17 14:43:54 +00001333static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3263597062008-11-02 08:22:54 +00001334{
1335 /* some cases can be optimized here */
1336 if (arg2 == 0) {
1337 tcg_gen_mov_i64(ret, arg1);
1338 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001339 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel3263597062008-11-02 08:22:54 +00001340 tcg_gen_add_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001341 tcg_temp_free_i64(t0);
aurel3263597062008-11-02 08:22:54 +00001342 }
1343}
1344
pbrooka7812ae2008-11-17 14:43:54 +00001345static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
aurel3200457342008-11-02 08:23:04 +00001346{
pbrooka7812ae2008-11-17 14:43:54 +00001347 TCGv_i64 t0 = tcg_const_i64(arg1);
aurel3200457342008-11-02 08:23:04 +00001348 tcg_gen_sub_i64(ret, t0, arg2);
pbrooka7812ae2008-11-17 14:43:54 +00001349 tcg_temp_free_i64(t0);
aurel3200457342008-11-02 08:23:04 +00001350}
1351
pbrooka7812ae2008-11-17 14:43:54 +00001352static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3263597062008-11-02 08:22:54 +00001353{
1354 /* some cases can be optimized here */
1355 if (arg2 == 0) {
1356 tcg_gen_mov_i64(ret, arg1);
1357 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001358 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel3263597062008-11-02 08:22:54 +00001359 tcg_gen_sub_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001360 tcg_temp_free_i64(t0);
aurel3263597062008-11-02 08:22:54 +00001361 }
1362}
Richard Henderson8a56e842010-03-19 11:26:05 -07001363static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1364 int64_t arg2, int label_index)
aurel32f02bb952008-11-03 07:08:26 +00001365{
pbrooka7812ae2008-11-17 14:43:54 +00001366 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel32f02bb952008-11-03 07:08:26 +00001367 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
pbrooka7812ae2008-11-17 14:43:54 +00001368 tcg_temp_free_i64(t0);
aurel32f02bb952008-11-03 07:08:26 +00001369}
1370
Richard Henderson8a56e842010-03-19 11:26:05 -07001371static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1372 TCGv_i64 arg1, int64_t arg2)
Aurelien Jarno5105c552010-02-08 12:10:15 +01001373{
1374 TCGv_i64 t0 = tcg_const_i64(arg2);
1375 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1376 tcg_temp_free_i64(t0);
1377}
1378
pbrooka7812ae2008-11-17 14:43:54 +00001379static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel32f02bb952008-11-03 07:08:26 +00001380{
pbrooka7812ae2008-11-17 14:43:54 +00001381 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel32f02bb952008-11-03 07:08:26 +00001382 tcg_gen_mul_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001383 tcg_temp_free_i64(t0);
aurel32f02bb952008-11-03 07:08:26 +00001384}
1385
aurel3263597062008-11-02 08:22:54 +00001386
bellardc896fe22008-02-01 10:05:41 +00001387/***************************************/
1388/* optional operations */
1389
pbrooka7812ae2008-11-17 14:43:54 +00001390static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001391{
1392#ifdef TCG_TARGET_HAS_ext8s_i32
pbrooka7812ae2008-11-17 14:43:54 +00001393 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001394#else
1395 tcg_gen_shli_i32(ret, arg, 24);
bellard5ff9d6a2008-02-04 00:37:54 +00001396 tcg_gen_sari_i32(ret, ret, 24);
bellardc896fe22008-02-01 10:05:41 +00001397#endif
1398}
1399
pbrooka7812ae2008-11-17 14:43:54 +00001400static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001401{
1402#ifdef TCG_TARGET_HAS_ext16s_i32
pbrooka7812ae2008-11-17 14:43:54 +00001403 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001404#else
1405 tcg_gen_shli_i32(ret, arg, 16);
bellard5ff9d6a2008-02-04 00:37:54 +00001406 tcg_gen_sari_i32(ret, ret, 16);
bellardc896fe22008-02-01 10:05:41 +00001407#endif
1408}
1409
pbrooka7812ae2008-11-17 14:43:54 +00001410static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook86831432008-05-11 12:22:01 +00001411{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001412#ifdef TCG_TARGET_HAS_ext8u_i32
1413 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1414#else
pbrook86831432008-05-11 12:22:01 +00001415 tcg_gen_andi_i32(ret, arg, 0xffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001416#endif
pbrook86831432008-05-11 12:22:01 +00001417}
1418
pbrooka7812ae2008-11-17 14:43:54 +00001419static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook86831432008-05-11 12:22:01 +00001420{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001421#ifdef TCG_TARGET_HAS_ext16u_i32
1422 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1423#else
pbrook86831432008-05-11 12:22:01 +00001424 tcg_gen_andi_i32(ret, arg, 0xffffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001425#endif
pbrook86831432008-05-11 12:22:01 +00001426}
1427
bellardc896fe22008-02-01 10:05:41 +00001428/* Note: we assume the two high bytes are set to zero */
pbrooka7812ae2008-11-17 14:43:54 +00001429static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001430{
1431#ifdef TCG_TARGET_HAS_bswap16_i32
pbrooka7812ae2008-11-17 14:43:54 +00001432 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001433#else
aurel32dfa1a3f2009-03-13 09:35:03 +00001434 TCGv_i32 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001435
aurel32dfa1a3f2009-03-13 09:35:03 +00001436 tcg_gen_ext8u_i32(t0, arg);
1437 tcg_gen_shli_i32(t0, t0, 8);
1438 tcg_gen_shri_i32(ret, arg, 8);
1439 tcg_gen_or_i32(ret, ret, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001440 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +00001441#endif
1442}
1443
aurel3266896cb2009-03-13 09:34:48 +00001444static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001445{
aurel3266896cb2009-03-13 09:34:48 +00001446#ifdef TCG_TARGET_HAS_bswap32_i32
1447 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001448#else
pbrooka7812ae2008-11-17 14:43:54 +00001449 TCGv_i32 t0, t1;
1450 t0 = tcg_temp_new_i32();
1451 t1 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001452
1453 tcg_gen_shli_i32(t0, arg, 24);
1454
1455 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1456 tcg_gen_shli_i32(t1, t1, 8);
1457 tcg_gen_or_i32(t0, t0, t1);
1458
1459 tcg_gen_shri_i32(t1, arg, 8);
1460 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1461 tcg_gen_or_i32(t0, t0, t1);
1462
1463 tcg_gen_shri_i32(t1, arg, 24);
1464 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001465 tcg_temp_free_i32(t0);
1466 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +00001467#endif
1468}
1469
1470#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001471static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001472{
pbrooka7812ae2008-11-17 14:43:54 +00001473 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1474 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001475}
1476
pbrooka7812ae2008-11-17 14:43:54 +00001477static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001478{
pbrooka7812ae2008-11-17 14:43:54 +00001479 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1480 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001481}
1482
pbrooka7812ae2008-11-17 14:43:54 +00001483static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001484{
pbrooka7812ae2008-11-17 14:43:54 +00001485 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1486 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001487}
1488
pbrooka7812ae2008-11-17 14:43:54 +00001489static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001490{
pbrooka7812ae2008-11-17 14:43:54 +00001491 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001492 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1493}
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{
pbrooka7812ae2008-11-17 14:43:54 +00001497 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001498 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1499}
1500
pbrooka7812ae2008-11-17 14:43:54 +00001501static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001502{
pbrooka7812ae2008-11-17 14:43:54 +00001503 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001504 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1505}
1506
pbrooka7812ae2008-11-17 14:43:54 +00001507static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001508{
pbrooka7812ae2008-11-17 14:43:54 +00001509 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
bellardc896fe22008-02-01 10:05:41 +00001510}
1511
pbrooka7812ae2008-11-17 14:43:54 +00001512static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001513{
pbrooka7812ae2008-11-17 14:43:54 +00001514 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
pbrookac56dd42008-02-03 19:56:33 +00001515 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001516}
1517
pbrooka7812ae2008-11-17 14:43:54 +00001518static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001519{
pbrooka7812ae2008-11-17 14:43:54 +00001520 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1521 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001522}
1523
aurel329a5c57f2009-03-13 09:35:12 +00001524/* Note: we assume the six high bytes are set to zero */
1525static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1526{
1527 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1528 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1529}
1530
1531/* Note: we assume the four high bytes are set to zero */
1532static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1533{
1534 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1535 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1536}
1537
aurel3266896cb2009-03-13 09:34:48 +00001538static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001539{
pbrooka7812ae2008-11-17 14:43:54 +00001540 TCGv_i32 t0, t1;
1541 t0 = tcg_temp_new_i32();
1542 t1 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001543
aurel3266896cb2009-03-13 09:34:48 +00001544 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1545 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
pbrooka7812ae2008-11-17 14:43:54 +00001546 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
pbrookac56dd42008-02-03 19:56:33 +00001547 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
pbrooka7812ae2008-11-17 14:43:54 +00001548 tcg_temp_free_i32(t0);
1549 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +00001550}
1551#else
1552
pbrooka7812ae2008-11-17 14:43:54 +00001553static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001554{
1555#ifdef TCG_TARGET_HAS_ext8s_i64
pbrooka7812ae2008-11-17 14:43:54 +00001556 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001557#else
1558 tcg_gen_shli_i64(ret, arg, 56);
bellard5ff9d6a2008-02-04 00:37:54 +00001559 tcg_gen_sari_i64(ret, ret, 56);
bellardc896fe22008-02-01 10:05:41 +00001560#endif
1561}
1562
pbrooka7812ae2008-11-17 14:43:54 +00001563static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001564{
1565#ifdef TCG_TARGET_HAS_ext16s_i64
pbrooka7812ae2008-11-17 14:43:54 +00001566 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001567#else
1568 tcg_gen_shli_i64(ret, arg, 48);
bellard5ff9d6a2008-02-04 00:37:54 +00001569 tcg_gen_sari_i64(ret, ret, 48);
bellardc896fe22008-02-01 10:05:41 +00001570#endif
1571}
1572
pbrooka7812ae2008-11-17 14:43:54 +00001573static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001574{
1575#ifdef TCG_TARGET_HAS_ext32s_i64
pbrooka7812ae2008-11-17 14:43:54 +00001576 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001577#else
1578 tcg_gen_shli_i64(ret, arg, 32);
bellard5ff9d6a2008-02-04 00:37:54 +00001579 tcg_gen_sari_i64(ret, ret, 32);
bellardc896fe22008-02-01 10:05:41 +00001580#endif
1581}
1582
pbrooka7812ae2008-11-17 14:43:54 +00001583static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001584{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001585#ifdef TCG_TARGET_HAS_ext8u_i64
1586 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1587#else
pbrook86831432008-05-11 12:22:01 +00001588 tcg_gen_andi_i64(ret, arg, 0xffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001589#endif
pbrook86831432008-05-11 12:22:01 +00001590}
1591
pbrooka7812ae2008-11-17 14:43:54 +00001592static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001593{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001594#ifdef TCG_TARGET_HAS_ext16u_i64
1595 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1596#else
pbrook86831432008-05-11 12:22:01 +00001597 tcg_gen_andi_i64(ret, arg, 0xffffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001598#endif
pbrook86831432008-05-11 12:22:01 +00001599}
1600
pbrooka7812ae2008-11-17 14:43:54 +00001601static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001602{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001603#ifdef TCG_TARGET_HAS_ext32u_i64
1604 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1605#else
pbrook86831432008-05-11 12:22:01 +00001606 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001607#endif
pbrook86831432008-05-11 12:22:01 +00001608}
1609
bellardc896fe22008-02-01 10:05:41 +00001610/* Note: we assume the target supports move between 32 and 64 bit
pbrookac56dd42008-02-03 19:56:33 +00001611 registers. This will probably break MIPS64 targets. */
pbrooka7812ae2008-11-17 14:43:54 +00001612static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001613{
pbrooka7812ae2008-11-17 14:43:54 +00001614 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
bellardc896fe22008-02-01 10:05:41 +00001615}
1616
1617/* Note: we assume the target supports move between 32 and 64 bit
1618 registers */
pbrooka7812ae2008-11-17 14:43:54 +00001619static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001620{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001621 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
bellardc896fe22008-02-01 10:05:41 +00001622}
1623
1624/* Note: we assume the target supports move between 32 and 64 bit
1625 registers */
pbrooka7812ae2008-11-17 14:43:54 +00001626static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001627{
pbrooka7812ae2008-11-17 14:43:54 +00001628 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
bellardc896fe22008-02-01 10:05:41 +00001629}
1630
aurel329a5c57f2009-03-13 09:35:12 +00001631/* Note: we assume the six high bytes are set to zero */
1632static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1633{
1634#ifdef TCG_TARGET_HAS_bswap16_i64
1635 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1636#else
1637 TCGv_i64 t0 = tcg_temp_new_i64();
1638
1639 tcg_gen_ext8u_i64(t0, arg);
1640 tcg_gen_shli_i64(t0, t0, 8);
1641 tcg_gen_shri_i64(ret, arg, 8);
1642 tcg_gen_or_i64(ret, ret, t0);
1643 tcg_temp_free_i64(t0);
1644#endif
1645}
1646
1647/* Note: we assume the four high bytes are set to zero */
1648static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1649{
1650#ifdef TCG_TARGET_HAS_bswap32_i64
1651 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1652#else
1653 TCGv_i64 t0, t1;
1654 t0 = tcg_temp_new_i64();
1655 t1 = tcg_temp_new_i64();
1656
1657 tcg_gen_shli_i64(t0, arg, 24);
1658 tcg_gen_ext32u_i64(t0, t0);
1659
1660 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1661 tcg_gen_shli_i64(t1, t1, 8);
1662 tcg_gen_or_i64(t0, t0, t1);
1663
1664 tcg_gen_shri_i64(t1, arg, 8);
1665 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1666 tcg_gen_or_i64(t0, t0, t1);
1667
1668 tcg_gen_shri_i64(t1, arg, 24);
1669 tcg_gen_or_i64(ret, t0, t1);
1670 tcg_temp_free_i64(t0);
1671 tcg_temp_free_i64(t1);
1672#endif
1673}
1674
aurel3266896cb2009-03-13 09:34:48 +00001675static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001676{
aurel3266896cb2009-03-13 09:34:48 +00001677#ifdef TCG_TARGET_HAS_bswap64_i64
1678 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001679#else
Stefan Weilb3481132009-09-05 18:54:10 +02001680 TCGv_i64 t0 = tcg_temp_new_i64();
1681 TCGv_i64 t1 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001682
1683 tcg_gen_shli_i64(t0, arg, 56);
1684
1685 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1686 tcg_gen_shli_i64(t1, t1, 40);
1687 tcg_gen_or_i64(t0, t0, t1);
1688
1689 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1690 tcg_gen_shli_i64(t1, t1, 24);
1691 tcg_gen_or_i64(t0, t0, t1);
1692
1693 tcg_gen_andi_i64(t1, arg, 0xff000000);
1694 tcg_gen_shli_i64(t1, t1, 8);
1695 tcg_gen_or_i64(t0, t0, t1);
1696
1697 tcg_gen_shri_i64(t1, arg, 8);
1698 tcg_gen_andi_i64(t1, t1, 0xff000000);
1699 tcg_gen_or_i64(t0, t0, t1);
1700
1701 tcg_gen_shri_i64(t1, arg, 24);
1702 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1703 tcg_gen_or_i64(t0, t0, t1);
1704
1705 tcg_gen_shri_i64(t1, arg, 40);
1706 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1707 tcg_gen_or_i64(t0, t0, t1);
1708
1709 tcg_gen_shri_i64(t1, arg, 56);
1710 tcg_gen_or_i64(ret, t0, t1);
Stefan Weilb3481132009-09-05 18:54:10 +02001711 tcg_temp_free_i64(t0);
1712 tcg_temp_free_i64(t1);
bellardc896fe22008-02-01 10:05:41 +00001713#endif
1714}
1715
1716#endif
1717
pbrooka7812ae2008-11-17 14:43:54 +00001718static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook390efc52008-05-11 14:35:37 +00001719{
1720#ifdef TCG_TARGET_HAS_neg_i32
pbrooka7812ae2008-11-17 14:43:54 +00001721 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
pbrook390efc52008-05-11 14:35:37 +00001722#else
pbrooka7812ae2008-11-17 14:43:54 +00001723 TCGv_i32 t0 = tcg_const_i32(0);
bellarde8996ee2008-05-23 17:33:39 +00001724 tcg_gen_sub_i32(ret, t0, arg);
pbrooka7812ae2008-11-17 14:43:54 +00001725 tcg_temp_free_i32(t0);
pbrook390efc52008-05-11 14:35:37 +00001726#endif
1727}
1728
pbrooka7812ae2008-11-17 14:43:54 +00001729static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook390efc52008-05-11 14:35:37 +00001730{
1731#ifdef TCG_TARGET_HAS_neg_i64
pbrooka7812ae2008-11-17 14:43:54 +00001732 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
pbrook390efc52008-05-11 14:35:37 +00001733#else
pbrooka7812ae2008-11-17 14:43:54 +00001734 TCGv_i64 t0 = tcg_const_i64(0);
bellarde8996ee2008-05-23 17:33:39 +00001735 tcg_gen_sub_i64(ret, t0, arg);
pbrooka7812ae2008-11-17 14:43:54 +00001736 tcg_temp_free_i64(t0);
pbrook390efc52008-05-11 14:35:37 +00001737#endif
1738}
1739
pbrooka7812ae2008-11-17 14:43:54 +00001740static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
bellard0b6ce4c2008-05-17 12:40:44 +00001741{
aurel32d2604282009-03-09 22:35:13 +00001742#ifdef TCG_TARGET_HAS_not_i32
1743 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1744#else
bellarde8996ee2008-05-23 17:33:39 +00001745 tcg_gen_xori_i32(ret, arg, -1);
aurel32d2604282009-03-09 22:35:13 +00001746#endif
bellard0b6ce4c2008-05-17 12:40:44 +00001747}
1748
pbrooka7812ae2008-11-17 14:43:54 +00001749static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
bellard0b6ce4c2008-05-17 12:40:44 +00001750{
aurel32d2604282009-03-09 22:35:13 +00001751#ifdef TCG_TARGET_HAS_not_i64
aurel3243e860e2009-03-10 10:29:45 +00001752 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
Richard Hendersona10f9f42010-03-19 12:44:47 -07001753#elif defined(TCG_TARGET_HAS_not_i32) && TCG_TARGET_REG_BITS == 32
1754 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1755 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
aurel32d2604282009-03-09 22:35:13 +00001756#else
bellarde8996ee2008-05-23 17:33:39 +00001757 tcg_gen_xori_i64(ret, arg, -1);
aurel32d2604282009-03-09 22:35:13 +00001758#endif
bellard0b6ce4c2008-05-17 12:40:44 +00001759}
bellard5ff9d6a2008-02-04 00:37:54 +00001760
pbrooka7812ae2008-11-17 14:43:54 +00001761static inline void tcg_gen_discard_i32(TCGv_i32 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001762{
pbrooka7812ae2008-11-17 14:43:54 +00001763 tcg_gen_op1_i32(INDEX_op_discard, arg);
bellard5ff9d6a2008-02-04 00:37:54 +00001764}
1765
1766#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001767static inline void tcg_gen_discard_i64(TCGv_i64 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001768{
pbrooka7812ae2008-11-17 14:43:54 +00001769 tcg_gen_discard_i32(TCGV_LOW(arg));
bellard5ff9d6a2008-02-04 00:37:54 +00001770 tcg_gen_discard_i32(TCGV_HIGH(arg));
1771}
1772#else
pbrooka7812ae2008-11-17 14:43:54 +00001773static inline void tcg_gen_discard_i64(TCGv_i64 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001774{
pbrooka7812ae2008-11-17 14:43:54 +00001775 tcg_gen_op1_i64(INDEX_op_discard, arg);
bellard5ff9d6a2008-02-04 00:37:54 +00001776}
1777#endif
1778
pbrooka7812ae2008-11-17 14:43:54 +00001779static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
pbrook36aa55d2008-09-21 13:48:32 +00001780{
1781#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001782 tcg_gen_mov_i32(TCGV_LOW(dest), low);
pbrook36aa55d2008-09-21 13:48:32 +00001783 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
1784#else
pbrooka7812ae2008-11-17 14:43:54 +00001785 TCGv_i64 tmp = tcg_temp_new_i64();
pbrook36aa55d2008-09-21 13:48:32 +00001786 /* This extension is only needed for type correctness.
1787 We may be able to do better given target specific information. */
1788 tcg_gen_extu_i32_i64(tmp, high);
1789 tcg_gen_shli_i64(tmp, tmp, 32);
1790 tcg_gen_extu_i32_i64(dest, low);
1791 tcg_gen_or_i64(dest, dest, tmp);
pbrooka7812ae2008-11-17 14:43:54 +00001792 tcg_temp_free_i64(tmp);
pbrook36aa55d2008-09-21 13:48:32 +00001793#endif
1794}
1795
pbrooka7812ae2008-11-17 14:43:54 +00001796static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low, TCGv_i64 high)
blueswir1945ca822008-09-21 18:32:28 +00001797{
1798#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001799 tcg_gen_concat_i32_i64(dest, TCGV_LOW(low), TCGV_LOW(high));
blueswir1945ca822008-09-21 18:32:28 +00001800#else
pbrooka7812ae2008-11-17 14:43:54 +00001801 TCGv_i64 tmp = tcg_temp_new_i64();
pbrook88422e22008-09-23 22:31:10 +00001802 tcg_gen_ext32u_i64(dest, low);
blueswir1945ca822008-09-21 18:32:28 +00001803 tcg_gen_shli_i64(tmp, high, 32);
pbrook88422e22008-09-23 22:31:10 +00001804 tcg_gen_or_i64(dest, dest, tmp);
pbrooka7812ae2008-11-17 14:43:54 +00001805 tcg_temp_free_i64(tmp);
blueswir1945ca822008-09-21 18:32:28 +00001806#endif
1807}
1808
pbrooka7812ae2008-11-17 14:43:54 +00001809static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001810{
Richard Henderson241cbed2010-02-16 14:10:13 -08001811#ifdef TCG_TARGET_HAS_andc_i32
1812 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1813#else
pbrooka7812ae2008-11-17 14:43:54 +00001814 TCGv_i32 t0;
1815 t0 = tcg_temp_new_i32();
aurel32f24cb332008-10-21 11:28:59 +00001816 tcg_gen_not_i32(t0, arg2);
1817 tcg_gen_and_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001818 tcg_temp_free_i32(t0);
Richard Henderson241cbed2010-02-16 14:10:13 -08001819#endif
aurel32f24cb332008-10-21 11:28:59 +00001820}
1821
pbrooka7812ae2008-11-17 14:43:54 +00001822static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001823{
Richard Henderson241cbed2010-02-16 14:10:13 -08001824#ifdef TCG_TARGET_HAS_andc_i64
1825 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1826#elif defined(TCG_TARGET_HAS_andc_i32) && TCG_TARGET_REG_BITS == 32
1827 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1828 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1829#else
pbrooka7812ae2008-11-17 14:43:54 +00001830 TCGv_i64 t0;
1831 t0 = tcg_temp_new_i64();
aurel32f24cb332008-10-21 11:28:59 +00001832 tcg_gen_not_i64(t0, arg2);
1833 tcg_gen_and_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001834 tcg_temp_free_i64(t0);
Richard Henderson241cbed2010-02-16 14:10:13 -08001835#endif
aurel32f24cb332008-10-21 11:28:59 +00001836}
1837
pbrooka7812ae2008-11-17 14:43:54 +00001838static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001839{
Richard Henderson8d625cf2010-03-19 13:02:02 -07001840#ifdef TCG_TARGET_HAS_eqv_i32
1841 tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
1842#else
aurel327fc81052009-03-10 19:37:39 +00001843 tcg_gen_xor_i32(ret, arg1, arg2);
1844 tcg_gen_not_i32(ret, ret);
Richard Henderson8d625cf2010-03-19 13:02:02 -07001845#endif
aurel32f24cb332008-10-21 11:28:59 +00001846}
1847
pbrooka7812ae2008-11-17 14:43:54 +00001848static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001849{
Richard Henderson8d625cf2010-03-19 13:02:02 -07001850#ifdef TCG_TARGET_HAS_eqv_i64
1851 tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
1852#elif defined(TCG_TARGET_HAS_eqv_i32) && TCG_TARGET_REG_BITS == 32
1853 tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1854 tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1855#else
aurel327fc81052009-03-10 19:37:39 +00001856 tcg_gen_xor_i64(ret, arg1, arg2);
1857 tcg_gen_not_i64(ret, ret);
Richard Henderson8d625cf2010-03-19 13:02:02 -07001858#endif
aurel32f24cb332008-10-21 11:28:59 +00001859}
1860
pbrooka7812ae2008-11-17 14:43:54 +00001861static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001862{
Richard Henderson9940a962010-03-19 13:03:58 -07001863#ifdef TCG_TARGET_HAS_nand_i32
1864 tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
1865#else
aurel327fc81052009-03-10 19:37:39 +00001866 tcg_gen_and_i32(ret, arg1, arg2);
1867 tcg_gen_not_i32(ret, ret);
Richard Henderson9940a962010-03-19 13:03:58 -07001868#endif
aurel32f24cb332008-10-21 11:28:59 +00001869}
1870
pbrooka7812ae2008-11-17 14:43:54 +00001871static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001872{
Richard Henderson9940a962010-03-19 13:03:58 -07001873#ifdef TCG_TARGET_HAS_nand_i64
1874 tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
1875#elif defined(TCG_TARGET_HAS_nand_i32) && TCG_TARGET_REG_BITS == 32
1876 tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1877 tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1878#else
aurel327fc81052009-03-10 19:37:39 +00001879 tcg_gen_and_i64(ret, arg1, arg2);
1880 tcg_gen_not_i64(ret, ret);
Richard Henderson9940a962010-03-19 13:03:58 -07001881#endif
aurel32f24cb332008-10-21 11:28:59 +00001882}
1883
pbrooka7812ae2008-11-17 14:43:54 +00001884static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001885{
Richard Henderson32d98fb2010-03-19 13:08:56 -07001886#ifdef TCG_TARGET_HAS_nor_i32
1887 tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
1888#else
aurel327fc81052009-03-10 19:37:39 +00001889 tcg_gen_or_i32(ret, arg1, arg2);
1890 tcg_gen_not_i32(ret, ret);
Richard Henderson32d98fb2010-03-19 13:08:56 -07001891#endif
aurel32f24cb332008-10-21 11:28:59 +00001892}
1893
pbrooka7812ae2008-11-17 14:43:54 +00001894static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001895{
Richard Henderson32d98fb2010-03-19 13:08:56 -07001896#ifdef TCG_TARGET_HAS_nor_i64
1897 tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
1898#elif defined(TCG_TARGET_HAS_nor_i32) && TCG_TARGET_REG_BITS == 32
1899 tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1900 tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1901#else
aurel327fc81052009-03-10 19:37:39 +00001902 tcg_gen_or_i64(ret, arg1, arg2);
1903 tcg_gen_not_i64(ret, ret);
Richard Henderson32d98fb2010-03-19 13:08:56 -07001904#endif
aurel32f24cb332008-10-21 11:28:59 +00001905}
1906
pbrooka7812ae2008-11-17 14:43:54 +00001907static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001908{
Richard Henderson791d1262010-02-16 14:15:28 -08001909#ifdef TCG_TARGET_HAS_orc_i32
1910 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
1911#else
pbrooka7812ae2008-11-17 14:43:54 +00001912 TCGv_i32 t0;
1913 t0 = tcg_temp_new_i32();
aurel32f24cb332008-10-21 11:28:59 +00001914 tcg_gen_not_i32(t0, arg2);
1915 tcg_gen_or_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001916 tcg_temp_free_i32(t0);
Richard Henderson791d1262010-02-16 14:15:28 -08001917#endif
aurel32f24cb332008-10-21 11:28:59 +00001918}
1919
pbrooka7812ae2008-11-17 14:43:54 +00001920static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001921{
Richard Henderson791d1262010-02-16 14:15:28 -08001922#ifdef TCG_TARGET_HAS_orc_i64
1923 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
1924#elif defined(TCG_TARGET_HAS_orc_i32) && TCG_TARGET_REG_BITS == 32
1925 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1926 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1927#else
pbrooka7812ae2008-11-17 14:43:54 +00001928 TCGv_i64 t0;
1929 t0 = tcg_temp_new_i64();
aurel32f24cb332008-10-21 11:28:59 +00001930 tcg_gen_not_i64(t0, arg2);
1931 tcg_gen_or_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001932 tcg_temp_free_i64(t0);
Richard Henderson791d1262010-02-16 14:15:28 -08001933#endif
aurel32f24cb332008-10-21 11:28:59 +00001934}
1935
pbrooka7812ae2008-11-17 14:43:54 +00001936static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3215824572008-11-03 07:08:36 +00001937{
aurel32d42f1832009-03-09 18:50:53 +00001938#ifdef TCG_TARGET_HAS_rot_i32
1939 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
1940#else
pbrooka7812ae2008-11-17 14:43:54 +00001941 TCGv_i32 t0, t1;
aurel3215824572008-11-03 07:08:36 +00001942
pbrooka7812ae2008-11-17 14:43:54 +00001943 t0 = tcg_temp_new_i32();
1944 t1 = tcg_temp_new_i32();
aurel3215824572008-11-03 07:08:36 +00001945 tcg_gen_shl_i32(t0, arg1, arg2);
1946 tcg_gen_subfi_i32(t1, 32, arg2);
1947 tcg_gen_shr_i32(t1, arg1, t1);
1948 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001949 tcg_temp_free_i32(t0);
1950 tcg_temp_free_i32(t1);
aurel32d42f1832009-03-09 18:50:53 +00001951#endif
aurel3215824572008-11-03 07:08:36 +00001952}
1953
pbrooka7812ae2008-11-17 14:43:54 +00001954static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel3215824572008-11-03 07:08:36 +00001955{
aurel32d42f1832009-03-09 18:50:53 +00001956#ifdef TCG_TARGET_HAS_rot_i64
1957 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
1958#else
pbrooka7812ae2008-11-17 14:43:54 +00001959 TCGv_i64 t0, t1;
aurel3215824572008-11-03 07:08:36 +00001960
pbrooka7812ae2008-11-17 14:43:54 +00001961 t0 = tcg_temp_new_i64();
1962 t1 = tcg_temp_new_i64();
aurel3215824572008-11-03 07:08:36 +00001963 tcg_gen_shl_i64(t0, arg1, arg2);
1964 tcg_gen_subfi_i64(t1, 64, arg2);
1965 tcg_gen_shr_i64(t1, arg1, t1);
1966 tcg_gen_or_i64(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001967 tcg_temp_free_i64(t0);
1968 tcg_temp_free_i64(t1);
aurel32d42f1832009-03-09 18:50:53 +00001969#endif
aurel3215824572008-11-03 07:08:36 +00001970}
1971
pbrooka7812ae2008-11-17 14:43:54 +00001972static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
aurel3215824572008-11-03 07:08:36 +00001973{
1974 /* some cases can be optimized here */
1975 if (arg2 == 0) {
1976 tcg_gen_mov_i32(ret, arg1);
1977 } else {
aurel32d42f1832009-03-09 18:50:53 +00001978#ifdef TCG_TARGET_HAS_rot_i32
1979 TCGv_i32 t0 = tcg_const_i32(arg2);
1980 tcg_gen_rotl_i32(ret, arg1, t0);
1981 tcg_temp_free_i32(t0);
1982#else
pbrooka7812ae2008-11-17 14:43:54 +00001983 TCGv_i32 t0, t1;
1984 t0 = tcg_temp_new_i32();
1985 t1 = tcg_temp_new_i32();
aurel3215824572008-11-03 07:08:36 +00001986 tcg_gen_shli_i32(t0, arg1, arg2);
1987 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
1988 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001989 tcg_temp_free_i32(t0);
1990 tcg_temp_free_i32(t1);
aurel32d42f1832009-03-09 18:50:53 +00001991#endif
aurel3215824572008-11-03 07:08:36 +00001992 }
1993}
1994
pbrooka7812ae2008-11-17 14:43:54 +00001995static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3215824572008-11-03 07:08:36 +00001996{
1997 /* some cases can be optimized here */
1998 if (arg2 == 0) {
1999 tcg_gen_mov_i64(ret, arg1);
2000 } else {
aurel32d42f1832009-03-09 18:50:53 +00002001#ifdef TCG_TARGET_HAS_rot_i64
2002 TCGv_i64 t0 = tcg_const_i64(arg2);
2003 tcg_gen_rotl_i64(ret, arg1, t0);
2004 tcg_temp_free_i64(t0);
2005#else
pbrooka7812ae2008-11-17 14:43:54 +00002006 TCGv_i64 t0, t1;
2007 t0 = tcg_temp_new_i64();
2008 t1 = tcg_temp_new_i64();
aurel3215824572008-11-03 07:08:36 +00002009 tcg_gen_shli_i64(t0, arg1, arg2);
2010 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
2011 tcg_gen_or_i64(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00002012 tcg_temp_free_i64(t0);
2013 tcg_temp_free_i64(t1);
aurel32d42f1832009-03-09 18:50:53 +00002014#endif
aurel3215824572008-11-03 07:08:36 +00002015 }
2016}
2017
pbrooka7812ae2008-11-17 14:43:54 +00002018static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3215824572008-11-03 07:08:36 +00002019{
aurel32d42f1832009-03-09 18:50:53 +00002020#ifdef TCG_TARGET_HAS_rot_i32
2021 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
2022#else
pbrooka7812ae2008-11-17 14:43:54 +00002023 TCGv_i32 t0, t1;
aurel3215824572008-11-03 07:08:36 +00002024
pbrooka7812ae2008-11-17 14:43:54 +00002025 t0 = tcg_temp_new_i32();
2026 t1 = tcg_temp_new_i32();
aurel3215824572008-11-03 07:08:36 +00002027 tcg_gen_shr_i32(t0, arg1, arg2);
2028 tcg_gen_subfi_i32(t1, 32, arg2);
2029 tcg_gen_shl_i32(t1, arg1, t1);
2030 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00002031 tcg_temp_free_i32(t0);
2032 tcg_temp_free_i32(t1);
aurel32d42f1832009-03-09 18:50:53 +00002033#endif
aurel3215824572008-11-03 07:08:36 +00002034}
2035
pbrooka7812ae2008-11-17 14:43:54 +00002036static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel3215824572008-11-03 07:08:36 +00002037{
aurel32d42f1832009-03-09 18:50:53 +00002038#ifdef TCG_TARGET_HAS_rot_i64
2039 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
2040#else
pbrooka7812ae2008-11-17 14:43:54 +00002041 TCGv_i64 t0, t1;
aurel3215824572008-11-03 07:08:36 +00002042
pbrooka7812ae2008-11-17 14:43:54 +00002043 t0 = tcg_temp_new_i64();
2044 t1 = tcg_temp_new_i64();
Aurelien Jarnod9885a02009-07-18 11:15:40 +02002045 tcg_gen_shr_i64(t0, arg1, arg2);
aurel3215824572008-11-03 07:08:36 +00002046 tcg_gen_subfi_i64(t1, 64, arg2);
2047 tcg_gen_shl_i64(t1, arg1, t1);
2048 tcg_gen_or_i64(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00002049 tcg_temp_free_i64(t0);
2050 tcg_temp_free_i64(t1);
aurel32d42f1832009-03-09 18:50:53 +00002051#endif
aurel3215824572008-11-03 07:08:36 +00002052}
2053
pbrooka7812ae2008-11-17 14:43:54 +00002054static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
aurel3215824572008-11-03 07:08:36 +00002055{
2056 /* some cases can be optimized here */
2057 if (arg2 == 0) {
2058 tcg_gen_mov_i32(ret, arg1);
2059 } else {
2060 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
2061 }
2062}
2063
pbrooka7812ae2008-11-17 14:43:54 +00002064static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3215824572008-11-03 07:08:36 +00002065{
2066 /* some cases can be optimized here */
2067 if (arg2 == 0) {
pbrookde3526b2008-11-03 13:30:50 +00002068 tcg_gen_mov_i64(ret, arg1);
aurel3215824572008-11-03 07:08:36 +00002069 } else {
2070 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2071 }
2072}
2073
bellardc896fe22008-02-01 10:05:41 +00002074/***************************************/
bellardc896fe22008-02-01 10:05:41 +00002075/* QEMU specific operations. Their type depend on the QEMU CPU
2076 type. */
2077#ifndef TARGET_LONG_BITS
2078#error must include QEMU headers
2079#endif
2080
pbrooka7812ae2008-11-17 14:43:54 +00002081#if TARGET_LONG_BITS == 32
2082#define TCGv TCGv_i32
2083#define tcg_temp_new() tcg_temp_new_i32()
2084#define tcg_global_reg_new tcg_global_reg_new_i32
2085#define tcg_global_mem_new tcg_global_mem_new_i32
aurel32df9247b2009-01-01 14:09:05 +00002086#define tcg_temp_local_new() tcg_temp_local_new_i32()
pbrooka7812ae2008-11-17 14:43:54 +00002087#define tcg_temp_free tcg_temp_free_i32
2088#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
2089#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
2090#define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
aurel32fe75bcf2009-03-10 08:57:16 +00002091#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
pbrooka7812ae2008-11-17 14:43:54 +00002092#else
2093#define TCGv TCGv_i64
2094#define tcg_temp_new() tcg_temp_new_i64()
2095#define tcg_global_reg_new tcg_global_reg_new_i64
2096#define tcg_global_mem_new tcg_global_mem_new_i64
aurel32df9247b2009-01-01 14:09:05 +00002097#define tcg_temp_local_new() tcg_temp_local_new_i64()
pbrooka7812ae2008-11-17 14:43:54 +00002098#define tcg_temp_free tcg_temp_free_i64
2099#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
2100#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
2101#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
aurel32fe75bcf2009-03-10 08:57:16 +00002102#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
pbrooka7812ae2008-11-17 14:43:54 +00002103#endif
2104
bellard7e4597d2008-05-22 16:56:05 +00002105/* debug info: write the PC of the corresponding QEMU CPU instruction */
2106static inline void tcg_gen_debug_insn_start(uint64_t pc)
2107{
2108 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2109#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
pbrookbcb01262008-05-24 02:24:25 +00002110 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2111 (uint32_t)(pc), (uint32_t)(pc >> 32));
bellard7e4597d2008-05-22 16:56:05 +00002112#else
2113 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2114#endif
2115}
2116
bellardc896fe22008-02-01 10:05:41 +00002117static inline void tcg_gen_exit_tb(tcg_target_long val)
2118{
pbrookac56dd42008-02-03 19:56:33 +00002119 tcg_gen_op1i(INDEX_op_exit_tb, val);
bellardc896fe22008-02-01 10:05:41 +00002120}
2121
2122static inline void tcg_gen_goto_tb(int idx)
2123{
pbrookac56dd42008-02-03 19:56:33 +00002124 tcg_gen_op1i(INDEX_op_goto_tb, idx);
bellardc896fe22008-02-01 10:05:41 +00002125}
2126
2127#if TCG_TARGET_REG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00002128static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002129{
2130#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002131 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002132#else
pbrooka7812ae2008-11-17 14:43:54 +00002133 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
2134 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002135 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002136#endif
2137}
2138
pbrookac56dd42008-02-03 19:56:33 +00002139static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002140{
2141#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002142 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002143#else
pbrooka7812ae2008-11-17 14:43:54 +00002144 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
2145 TCGV_HIGH(addr), mem_index);
2146 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002147#endif
2148}
2149
pbrookac56dd42008-02-03 19:56:33 +00002150static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002151{
2152#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002153 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002154#else
pbrooka7812ae2008-11-17 14:43:54 +00002155 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
2156 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002157 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002158#endif
2159}
2160
pbrookac56dd42008-02-03 19:56:33 +00002161static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002162{
2163#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002164 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002165#else
pbrooka7812ae2008-11-17 14:43:54 +00002166 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
2167 TCGV_HIGH(addr), mem_index);
2168 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002169#endif
2170}
2171
pbrookac56dd42008-02-03 19:56:33 +00002172static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002173{
2174#if TARGET_LONG_BITS == 32
Richard Henderson86feb1c2010-03-19 12:00:26 -07002175 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002176#else
Richard Henderson86feb1c2010-03-19 12:00:26 -07002177 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
pbrooka7812ae2008-11-17 14:43:54 +00002178 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002179 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002180#endif
2181}
2182
pbrookac56dd42008-02-03 19:56:33 +00002183static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002184{
2185#if TARGET_LONG_BITS == 32
Richard Henderson86feb1c2010-03-19 12:00:26 -07002186 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002187#else
Richard Henderson86feb1c2010-03-19 12:00:26 -07002188 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
pbrooka7812ae2008-11-17 14:43:54 +00002189 TCGV_HIGH(addr), mem_index);
2190 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002191#endif
2192}
2193
pbrooka7812ae2008-11-17 14:43:54 +00002194static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002195{
2196#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002197 tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002198#else
pbrooka7812ae2008-11-17 14:43:54 +00002199 tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
2200 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002201#endif
2202}
2203
pbrookac56dd42008-02-03 19:56:33 +00002204static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002205{
2206#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002207 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002208#else
pbrooka7812ae2008-11-17 14:43:54 +00002209 tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
2210 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002211#endif
2212}
2213
pbrookac56dd42008-02-03 19:56:33 +00002214static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002215{
2216#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002217 tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002218#else
pbrooka7812ae2008-11-17 14:43:54 +00002219 tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
2220 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002221#endif
2222}
2223
pbrookac56dd42008-02-03 19:56:33 +00002224static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002225{
2226#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002227 tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002228#else
pbrooka7812ae2008-11-17 14:43:54 +00002229 tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
2230 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002231#endif
2232}
2233
pbrooka7812ae2008-11-17 14:43:54 +00002234static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002235{
2236#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002237 tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
2238 mem_index);
bellardc896fe22008-02-01 10:05:41 +00002239#else
pbrooka7812ae2008-11-17 14:43:54 +00002240 tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
2241 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002242#endif
2243}
2244
blueswir156b8f562008-02-25 18:29:19 +00002245#define tcg_gen_ld_ptr tcg_gen_ld_i32
blueswir1a768e4b2008-03-16 19:16:37 +00002246#define tcg_gen_discard_ptr tcg_gen_discard_i32
blueswir1f8422f52008-02-24 07:45:43 +00002247
bellardc896fe22008-02-01 10:05:41 +00002248#else /* TCG_TARGET_REG_BITS == 32 */
2249
pbrookac56dd42008-02-03 19:56:33 +00002250static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002251{
pbrooka7812ae2008-11-17 14:43:54 +00002252 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002253}
2254
pbrookac56dd42008-02-03 19:56:33 +00002255static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002256{
pbrooka7812ae2008-11-17 14:43:54 +00002257 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002258}
2259
pbrookac56dd42008-02-03 19:56:33 +00002260static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002261{
pbrooka7812ae2008-11-17 14:43:54 +00002262 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002263}
2264
pbrookac56dd42008-02-03 19:56:33 +00002265static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002266{
pbrooka7812ae2008-11-17 14:43:54 +00002267 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002268}
2269
pbrookac56dd42008-02-03 19:56:33 +00002270static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002271{
Richard Henderson3e1dbad2010-05-03 16:30:48 -07002272#if TARGET_LONG_BITS == 32
2273 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2274#else
pbrooka7812ae2008-11-17 14:43:54 +00002275 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
Richard Henderson3e1dbad2010-05-03 16:30:48 -07002276#endif
bellardc896fe22008-02-01 10:05:41 +00002277}
2278
pbrookac56dd42008-02-03 19:56:33 +00002279static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002280{
Richard Henderson3e1dbad2010-05-03 16:30:48 -07002281#if TARGET_LONG_BITS == 32
2282 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2283#else
pbrooka7812ae2008-11-17 14:43:54 +00002284 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
Richard Henderson3e1dbad2010-05-03 16:30:48 -07002285#endif
bellardc896fe22008-02-01 10:05:41 +00002286}
2287
pbrooka7812ae2008-11-17 14:43:54 +00002288static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002289{
pbrooka7812ae2008-11-17 14:43:54 +00002290 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002291}
2292
pbrookac56dd42008-02-03 19:56:33 +00002293static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002294{
pbrooka7812ae2008-11-17 14:43:54 +00002295 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002296}
2297
pbrookac56dd42008-02-03 19:56:33 +00002298static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002299{
pbrooka7812ae2008-11-17 14:43:54 +00002300 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002301}
2302
pbrookac56dd42008-02-03 19:56:33 +00002303static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002304{
pbrooka7812ae2008-11-17 14:43:54 +00002305 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002306}
2307
pbrooka7812ae2008-11-17 14:43:54 +00002308static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002309{
pbrooka7812ae2008-11-17 14:43:54 +00002310 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002311}
2312
blueswir156b8f562008-02-25 18:29:19 +00002313#define tcg_gen_ld_ptr tcg_gen_ld_i64
blueswir1a768e4b2008-03-16 19:16:37 +00002314#define tcg_gen_discard_ptr tcg_gen_discard_i64
blueswir1f8422f52008-02-24 07:45:43 +00002315
bellardc896fe22008-02-01 10:05:41 +00002316#endif /* TCG_TARGET_REG_BITS != 32 */
blueswir1f8422f52008-02-24 07:45:43 +00002317
2318#if TARGET_LONG_BITS == 64
blueswir1f8422f52008-02-24 07:45:43 +00002319#define tcg_gen_movi_tl tcg_gen_movi_i64
2320#define tcg_gen_mov_tl tcg_gen_mov_i64
2321#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2322#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2323#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2324#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2325#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2326#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2327#define tcg_gen_ld_tl tcg_gen_ld_i64
2328#define tcg_gen_st8_tl tcg_gen_st8_i64
2329#define tcg_gen_st16_tl tcg_gen_st16_i64
2330#define tcg_gen_st32_tl tcg_gen_st32_i64
2331#define tcg_gen_st_tl tcg_gen_st_i64
2332#define tcg_gen_add_tl tcg_gen_add_i64
2333#define tcg_gen_addi_tl tcg_gen_addi_i64
2334#define tcg_gen_sub_tl tcg_gen_sub_i64
pbrook390efc52008-05-11 14:35:37 +00002335#define tcg_gen_neg_tl tcg_gen_neg_i64
pbrook10460c82008-11-02 13:26:16 +00002336#define tcg_gen_subfi_tl tcg_gen_subfi_i64
blueswir1f8422f52008-02-24 07:45:43 +00002337#define tcg_gen_subi_tl tcg_gen_subi_i64
2338#define tcg_gen_and_tl tcg_gen_and_i64
2339#define tcg_gen_andi_tl tcg_gen_andi_i64
2340#define tcg_gen_or_tl tcg_gen_or_i64
2341#define tcg_gen_ori_tl tcg_gen_ori_i64
2342#define tcg_gen_xor_tl tcg_gen_xor_i64
2343#define tcg_gen_xori_tl tcg_gen_xori_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002344#define tcg_gen_not_tl tcg_gen_not_i64
blueswir1f8422f52008-02-24 07:45:43 +00002345#define tcg_gen_shl_tl tcg_gen_shl_i64
2346#define tcg_gen_shli_tl tcg_gen_shli_i64
2347#define tcg_gen_shr_tl tcg_gen_shr_i64
2348#define tcg_gen_shri_tl tcg_gen_shri_i64
2349#define tcg_gen_sar_tl tcg_gen_sar_i64
2350#define tcg_gen_sari_tl tcg_gen_sari_i64
blueswir10cf767d2008-03-02 18:20:59 +00002351#define tcg_gen_brcond_tl tcg_gen_brcond_i64
pbrookcb636692008-05-24 02:22:00 +00002352#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
Richard Hendersonbe210ac2010-01-07 10:13:31 -08002353#define tcg_gen_setcond_tl tcg_gen_setcond_i64
Aurelien Jarnoadd1e7e2010-02-08 12:06:05 +01002354#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
thsf730fd22008-05-04 08:14:08 +00002355#define tcg_gen_mul_tl tcg_gen_mul_i64
2356#define tcg_gen_muli_tl tcg_gen_muli_i64
aurel32ab364212009-03-29 01:19:22 +00002357#define tcg_gen_div_tl tcg_gen_div_i64
2358#define tcg_gen_rem_tl tcg_gen_rem_i64
aurel32864951a2009-03-29 14:08:54 +00002359#define tcg_gen_divu_tl tcg_gen_divu_i64
2360#define tcg_gen_remu_tl tcg_gen_remu_i64
blueswir1a768e4b2008-03-16 19:16:37 +00002361#define tcg_gen_discard_tl tcg_gen_discard_i64
blueswir1e4290732008-03-22 08:39:04 +00002362#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2363#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2364#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2365#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2366#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2367#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002368#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2369#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2370#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2371#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2372#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2373#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
aurel32911d79b2009-03-13 09:35:19 +00002374#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2375#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2376#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
blueswir1945ca822008-09-21 18:32:28 +00002377#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
aurel32f24cb332008-10-21 11:28:59 +00002378#define tcg_gen_andc_tl tcg_gen_andc_i64
2379#define tcg_gen_eqv_tl tcg_gen_eqv_i64
2380#define tcg_gen_nand_tl tcg_gen_nand_i64
2381#define tcg_gen_nor_tl tcg_gen_nor_i64
2382#define tcg_gen_orc_tl tcg_gen_orc_i64
aurel3215824572008-11-03 07:08:36 +00002383#define tcg_gen_rotl_tl tcg_gen_rotl_i64
2384#define tcg_gen_rotli_tl tcg_gen_rotli_i64
2385#define tcg_gen_rotr_tl tcg_gen_rotr_i64
2386#define tcg_gen_rotri_tl tcg_gen_rotri_i64
blueswir1a98824a2008-03-13 20:46:42 +00002387#define tcg_const_tl tcg_const_i64
aurel32bdffd4a2008-10-21 11:30:45 +00002388#define tcg_const_local_tl tcg_const_local_i64
blueswir1f8422f52008-02-24 07:45:43 +00002389#else
blueswir1f8422f52008-02-24 07:45:43 +00002390#define tcg_gen_movi_tl tcg_gen_movi_i32
2391#define tcg_gen_mov_tl tcg_gen_mov_i32
2392#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2393#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2394#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2395#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2396#define tcg_gen_ld32u_tl tcg_gen_ld_i32
2397#define tcg_gen_ld32s_tl tcg_gen_ld_i32
2398#define tcg_gen_ld_tl tcg_gen_ld_i32
2399#define tcg_gen_st8_tl tcg_gen_st8_i32
2400#define tcg_gen_st16_tl tcg_gen_st16_i32
2401#define tcg_gen_st32_tl tcg_gen_st_i32
2402#define tcg_gen_st_tl tcg_gen_st_i32
2403#define tcg_gen_add_tl tcg_gen_add_i32
2404#define tcg_gen_addi_tl tcg_gen_addi_i32
2405#define tcg_gen_sub_tl tcg_gen_sub_i32
pbrook390efc52008-05-11 14:35:37 +00002406#define tcg_gen_neg_tl tcg_gen_neg_i32
aurel3200457342008-11-02 08:23:04 +00002407#define tcg_gen_subfi_tl tcg_gen_subfi_i32
blueswir1f8422f52008-02-24 07:45:43 +00002408#define tcg_gen_subi_tl tcg_gen_subi_i32
2409#define tcg_gen_and_tl tcg_gen_and_i32
2410#define tcg_gen_andi_tl tcg_gen_andi_i32
2411#define tcg_gen_or_tl tcg_gen_or_i32
2412#define tcg_gen_ori_tl tcg_gen_ori_i32
2413#define tcg_gen_xor_tl tcg_gen_xor_i32
2414#define tcg_gen_xori_tl tcg_gen_xori_i32
bellard0b6ce4c2008-05-17 12:40:44 +00002415#define tcg_gen_not_tl tcg_gen_not_i32
blueswir1f8422f52008-02-24 07:45:43 +00002416#define tcg_gen_shl_tl tcg_gen_shl_i32
2417#define tcg_gen_shli_tl tcg_gen_shli_i32
2418#define tcg_gen_shr_tl tcg_gen_shr_i32
2419#define tcg_gen_shri_tl tcg_gen_shri_i32
2420#define tcg_gen_sar_tl tcg_gen_sar_i32
2421#define tcg_gen_sari_tl tcg_gen_sari_i32
blueswir10cf767d2008-03-02 18:20:59 +00002422#define tcg_gen_brcond_tl tcg_gen_brcond_i32
pbrookcb636692008-05-24 02:22:00 +00002423#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
Richard Hendersonbe210ac2010-01-07 10:13:31 -08002424#define tcg_gen_setcond_tl tcg_gen_setcond_i32
Aurelien Jarnoadd1e7e2010-02-08 12:06:05 +01002425#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
thsf730fd22008-05-04 08:14:08 +00002426#define tcg_gen_mul_tl tcg_gen_mul_i32
2427#define tcg_gen_muli_tl tcg_gen_muli_i32
aurel32ab364212009-03-29 01:19:22 +00002428#define tcg_gen_div_tl tcg_gen_div_i32
2429#define tcg_gen_rem_tl tcg_gen_rem_i32
aurel32864951a2009-03-29 14:08:54 +00002430#define tcg_gen_divu_tl tcg_gen_divu_i32
2431#define tcg_gen_remu_tl tcg_gen_remu_i32
blueswir1a768e4b2008-03-16 19:16:37 +00002432#define tcg_gen_discard_tl tcg_gen_discard_i32
blueswir1e4290732008-03-22 08:39:04 +00002433#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2434#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2435#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2436#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2437#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2438#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002439#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2440#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2441#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2442#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2443#define tcg_gen_ext32u_tl tcg_gen_mov_i32
2444#define tcg_gen_ext32s_tl tcg_gen_mov_i32
aurel32911d79b2009-03-13 09:35:19 +00002445#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2446#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
blueswir1945ca822008-09-21 18:32:28 +00002447#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
aurel32f24cb332008-10-21 11:28:59 +00002448#define tcg_gen_andc_tl tcg_gen_andc_i32
2449#define tcg_gen_eqv_tl tcg_gen_eqv_i32
2450#define tcg_gen_nand_tl tcg_gen_nand_i32
2451#define tcg_gen_nor_tl tcg_gen_nor_i32
2452#define tcg_gen_orc_tl tcg_gen_orc_i32
aurel3215824572008-11-03 07:08:36 +00002453#define tcg_gen_rotl_tl tcg_gen_rotl_i32
2454#define tcg_gen_rotli_tl tcg_gen_rotli_i32
2455#define tcg_gen_rotr_tl tcg_gen_rotr_i32
2456#define tcg_gen_rotri_tl tcg_gen_rotri_i32
blueswir1a98824a2008-03-13 20:46:42 +00002457#define tcg_const_tl tcg_const_i32
aurel32bdffd4a2008-10-21 11:30:45 +00002458#define tcg_const_local_tl tcg_const_local_i32
blueswir1f8422f52008-02-24 07:45:43 +00002459#endif
pbrook6ddbc6e2008-03-31 03:46:33 +00002460
2461#if TCG_TARGET_REG_BITS == 32
ths48d38ca2008-05-18 22:50:49 +00002462#define tcg_gen_add_ptr tcg_gen_add_i32
pbrook6ddbc6e2008-03-31 03:46:33 +00002463#define tcg_gen_addi_ptr tcg_gen_addi_i32
ths48d38ca2008-05-18 22:50:49 +00002464#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
pbrook6ddbc6e2008-03-31 03:46:33 +00002465#else /* TCG_TARGET_REG_BITS == 32 */
ths48d38ca2008-05-18 22:50:49 +00002466#define tcg_gen_add_ptr tcg_gen_add_i64
pbrook6ddbc6e2008-03-31 03:46:33 +00002467#define tcg_gen_addi_ptr tcg_gen_addi_i64
ths48d38ca2008-05-18 22:50:49 +00002468#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
pbrook6ddbc6e2008-03-31 03:46:33 +00002469#endif /* TCG_TARGET_REG_BITS != 32 */