blob: 27f83b5b236d03bd75e6de1e1eaf185c228d181e [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
blueswir1cf2be982008-03-21 18:03:09 +000026#ifndef CONFIG_NO_DYNGEN_OP
bellardc896fe22008-02-01 10:05:41 +000027/* legacy dyngen operations */
28#include "gen-op.h"
blueswir1cf2be982008-03-21 18:03:09 +000029#endif
bellardc896fe22008-02-01 10:05:41 +000030
31int gen_new_label(void);
32
pbrookac56dd42008-02-03 19:56:33 +000033static inline void tcg_gen_op1(int opc, TCGv arg1)
34{
35 *gen_opc_ptr++ = opc;
36 *gen_opparam_ptr++ = GET_TCGV(arg1);
37}
38
39static inline void tcg_gen_op1i(int opc, TCGArg arg1)
bellardc896fe22008-02-01 10:05:41 +000040{
41 *gen_opc_ptr++ = opc;
42 *gen_opparam_ptr++ = arg1;
43}
44
pbrookac56dd42008-02-03 19:56:33 +000045static inline void tcg_gen_op2(int opc, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +000046{
47 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +000048 *gen_opparam_ptr++ = GET_TCGV(arg1);
49 *gen_opparam_ptr++ = GET_TCGV(arg2);
50}
51
52static inline void tcg_gen_op2i(int opc, TCGv arg1, TCGArg arg2)
53{
54 *gen_opc_ptr++ = opc;
55 *gen_opparam_ptr++ = GET_TCGV(arg1);
bellardc896fe22008-02-01 10:05:41 +000056 *gen_opparam_ptr++ = arg2;
57}
58
pbrookac56dd42008-02-03 19:56:33 +000059static inline void tcg_gen_op3(int opc, TCGv arg1, TCGv arg2, TCGv arg3)
bellardc896fe22008-02-01 10:05:41 +000060{
61 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +000062 *gen_opparam_ptr++ = GET_TCGV(arg1);
63 *gen_opparam_ptr++ = GET_TCGV(arg2);
64 *gen_opparam_ptr++ = GET_TCGV(arg3);
65}
66
67static inline void tcg_gen_op3i(int opc, TCGv arg1, TCGv arg2, TCGArg arg3)
68{
69 *gen_opc_ptr++ = opc;
70 *gen_opparam_ptr++ = GET_TCGV(arg1);
71 *gen_opparam_ptr++ = GET_TCGV(arg2);
bellardc896fe22008-02-01 10:05:41 +000072 *gen_opparam_ptr++ = arg3;
73}
74
pbrookac56dd42008-02-03 19:56:33 +000075static inline void tcg_gen_op4(int opc, TCGv arg1, TCGv arg2, TCGv arg3,
76 TCGv arg4)
bellardc896fe22008-02-01 10:05:41 +000077{
78 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +000079 *gen_opparam_ptr++ = GET_TCGV(arg1);
80 *gen_opparam_ptr++ = GET_TCGV(arg2);
81 *gen_opparam_ptr++ = GET_TCGV(arg3);
82 *gen_opparam_ptr++ = GET_TCGV(arg4);
83}
84
85static inline void tcg_gen_op4i(int opc, TCGv arg1, TCGv arg2, TCGv arg3,
86 TCGArg arg4)
87{
88 *gen_opc_ptr++ = opc;
89 *gen_opparam_ptr++ = GET_TCGV(arg1);
90 *gen_opparam_ptr++ = GET_TCGV(arg2);
91 *gen_opparam_ptr++ = GET_TCGV(arg3);
92 *gen_opparam_ptr++ = arg4;
93}
94
95static inline void tcg_gen_op4ii(int opc, TCGv arg1, TCGv arg2, TCGArg arg3,
96 TCGArg arg4)
97{
98 *gen_opc_ptr++ = opc;
99 *gen_opparam_ptr++ = GET_TCGV(arg1);
100 *gen_opparam_ptr++ = GET_TCGV(arg2);
bellardc896fe22008-02-01 10:05:41 +0000101 *gen_opparam_ptr++ = arg3;
102 *gen_opparam_ptr++ = arg4;
103}
104
pbrookac56dd42008-02-03 19:56:33 +0000105static inline void tcg_gen_op5(int opc, TCGv arg1, TCGv arg2,
106 TCGv arg3, TCGv arg4,
107 TCGv arg5)
bellardc896fe22008-02-01 10:05:41 +0000108{
109 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +0000110 *gen_opparam_ptr++ = GET_TCGV(arg1);
111 *gen_opparam_ptr++ = GET_TCGV(arg2);
112 *gen_opparam_ptr++ = GET_TCGV(arg3);
113 *gen_opparam_ptr++ = GET_TCGV(arg4);
114 *gen_opparam_ptr++ = GET_TCGV(arg5);
115}
116
117static inline void tcg_gen_op5i(int opc, TCGv arg1, TCGv arg2,
118 TCGv arg3, TCGv arg4,
119 TCGArg arg5)
120{
121 *gen_opc_ptr++ = opc;
122 *gen_opparam_ptr++ = GET_TCGV(arg1);
123 *gen_opparam_ptr++ = GET_TCGV(arg2);
124 *gen_opparam_ptr++ = GET_TCGV(arg3);
125 *gen_opparam_ptr++ = GET_TCGV(arg4);
bellardc896fe22008-02-01 10:05:41 +0000126 *gen_opparam_ptr++ = arg5;
127}
128
pbrookac56dd42008-02-03 19:56:33 +0000129static inline void tcg_gen_op6(int opc, TCGv arg1, TCGv arg2,
130 TCGv arg3, TCGv arg4,
131 TCGv arg5, TCGv arg6)
bellardc896fe22008-02-01 10:05:41 +0000132{
133 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +0000134 *gen_opparam_ptr++ = GET_TCGV(arg1);
135 *gen_opparam_ptr++ = GET_TCGV(arg2);
136 *gen_opparam_ptr++ = GET_TCGV(arg3);
137 *gen_opparam_ptr++ = GET_TCGV(arg4);
138 *gen_opparam_ptr++ = GET_TCGV(arg5);
139 *gen_opparam_ptr++ = GET_TCGV(arg6);
140}
141
142static inline void tcg_gen_op6ii(int opc, TCGv arg1, TCGv arg2,
143 TCGv arg3, TCGv arg4,
144 TCGArg arg5, TCGArg arg6)
145{
146 *gen_opc_ptr++ = opc;
147 *gen_opparam_ptr++ = GET_TCGV(arg1);
148 *gen_opparam_ptr++ = GET_TCGV(arg2);
149 *gen_opparam_ptr++ = GET_TCGV(arg3);
150 *gen_opparam_ptr++ = GET_TCGV(arg4);
bellardc896fe22008-02-01 10:05:41 +0000151 *gen_opparam_ptr++ = arg5;
152 *gen_opparam_ptr++ = arg6;
153}
154
155static inline void gen_set_label(int n)
156{
pbrookac56dd42008-02-03 19:56:33 +0000157 tcg_gen_op1i(INDEX_op_set_label, n);
bellardc896fe22008-02-01 10:05:41 +0000158}
159
blueswir1fb50d412008-03-21 17:58:45 +0000160static inline void tcg_gen_br(int label)
161{
162 tcg_gen_op1i(INDEX_op_br, label);
163}
164
pbrookac56dd42008-02-03 19:56:33 +0000165static inline void tcg_gen_mov_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000166{
167 tcg_gen_op2(INDEX_op_mov_i32, ret, arg);
168}
169
pbrookac56dd42008-02-03 19:56:33 +0000170static inline void tcg_gen_movi_i32(TCGv ret, int32_t arg)
bellardc896fe22008-02-01 10:05:41 +0000171{
pbrookac56dd42008-02-03 19:56:33 +0000172 tcg_gen_op2i(INDEX_op_movi_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000173}
174
175/* helper calls */
176#define TCG_HELPER_CALL_FLAGS 0
177
178static inline void tcg_gen_helper_0_0(void *func)
179{
180 tcg_gen_call(&tcg_ctx,
181 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
182 0, NULL, 0, NULL);
183}
184
pbrookac56dd42008-02-03 19:56:33 +0000185static inline void tcg_gen_helper_0_1(void *func, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000186{
187 tcg_gen_call(&tcg_ctx,
188 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
189 0, NULL, 1, &arg);
190}
191
pbrookac56dd42008-02-03 19:56:33 +0000192static inline void tcg_gen_helper_0_2(void *func, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000193{
pbrookac56dd42008-02-03 19:56:33 +0000194 TCGv args[2];
bellardc896fe22008-02-01 10:05:41 +0000195 args[0] = arg1;
196 args[1] = arg2;
197 tcg_gen_call(&tcg_ctx,
198 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
199 0, NULL, 2, args);
200}
201
blueswir1f8422f52008-02-24 07:45:43 +0000202static inline void tcg_gen_helper_0_4(void *func, TCGv arg1, TCGv arg2,
203 TCGv arg3, TCGv arg4)
204{
205 TCGv args[4];
206 args[0] = arg1;
207 args[1] = arg2;
208 args[2] = arg3;
209 args[3] = arg4;
210 tcg_gen_call(&tcg_ctx,
211 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
212 0, NULL, 4, args);
213}
214
215static inline void tcg_gen_helper_1_0(void *func, TCGv ret)
216{
217 tcg_gen_call(&tcg_ctx,
218 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
219 1, &ret, 0, NULL);
220}
221
222static inline void tcg_gen_helper_1_1(void *func, TCGv ret, TCGv arg1)
223{
224 tcg_gen_call(&tcg_ctx,
225 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
226 1, &ret, 1, &arg1);
227}
228
pbrookac56dd42008-02-03 19:56:33 +0000229static inline void tcg_gen_helper_1_2(void *func, TCGv ret,
230 TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000231{
pbrookac56dd42008-02-03 19:56:33 +0000232 TCGv args[2];
bellardc896fe22008-02-01 10:05:41 +0000233 args[0] = arg1;
234 args[1] = arg2;
235 tcg_gen_call(&tcg_ctx,
236 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
237 1, &ret, 2, args);
238}
239
pbrook6ddbc6e2008-03-31 03:46:33 +0000240static inline void tcg_gen_helper_1_3(void *func, TCGv ret,
241 TCGv arg1, TCGv arg2, TCGv arg3)
242{
243 TCGv args[3];
244 args[0] = arg1;
245 args[1] = arg2;
246 args[2] = arg3;
247 tcg_gen_call(&tcg_ctx,
248 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
249 1, &ret, 3, args);
250}
251
blueswir1f8422f52008-02-24 07:45:43 +0000252static inline void tcg_gen_helper_1_4(void *func, TCGv ret,
253 TCGv arg1, TCGv arg2, TCGv arg3,
254 TCGv arg4)
255{
256 TCGv args[4];
257 args[0] = arg1;
258 args[1] = arg2;
259 args[2] = arg3;
260 args[3] = arg4;
261 tcg_gen_call(&tcg_ctx,
262 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
263 1, &ret, 4, args);
264}
265
bellardc896fe22008-02-01 10:05:41 +0000266/* 32 bit ops */
267
pbrookac56dd42008-02-03 19:56:33 +0000268static inline void tcg_gen_ld8u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000269{
pbrookac56dd42008-02-03 19:56:33 +0000270 tcg_gen_op3i(INDEX_op_ld8u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000271}
272
pbrookac56dd42008-02-03 19:56:33 +0000273static inline void tcg_gen_ld8s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000274{
pbrookac56dd42008-02-03 19:56:33 +0000275 tcg_gen_op3i(INDEX_op_ld8s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000276}
277
pbrookac56dd42008-02-03 19:56:33 +0000278static inline void tcg_gen_ld16u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000279{
pbrookac56dd42008-02-03 19:56:33 +0000280 tcg_gen_op3i(INDEX_op_ld16u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000281}
282
pbrookac56dd42008-02-03 19:56:33 +0000283static inline void tcg_gen_ld16s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000284{
pbrookac56dd42008-02-03 19:56:33 +0000285 tcg_gen_op3i(INDEX_op_ld16s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000286}
287
pbrookac56dd42008-02-03 19:56:33 +0000288static inline void tcg_gen_ld_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000289{
pbrookac56dd42008-02-03 19:56:33 +0000290 tcg_gen_op3i(INDEX_op_ld_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000291}
292
pbrookac56dd42008-02-03 19:56:33 +0000293static inline void tcg_gen_st8_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000294{
pbrookac56dd42008-02-03 19:56:33 +0000295 tcg_gen_op3i(INDEX_op_st8_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000296}
297
pbrookac56dd42008-02-03 19:56:33 +0000298static inline void tcg_gen_st16_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000299{
pbrookac56dd42008-02-03 19:56:33 +0000300 tcg_gen_op3i(INDEX_op_st16_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000301}
302
pbrookac56dd42008-02-03 19:56:33 +0000303static inline void tcg_gen_st_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000304{
pbrookac56dd42008-02-03 19:56:33 +0000305 tcg_gen_op3i(INDEX_op_st_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000306}
307
pbrookac56dd42008-02-03 19:56:33 +0000308static inline void tcg_gen_add_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000309{
310 tcg_gen_op3(INDEX_op_add_i32, ret, arg1, arg2);
311}
312
pbrookac56dd42008-02-03 19:56:33 +0000313static inline void tcg_gen_addi_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000314{
blueswir170894422008-02-20 18:01:23 +0000315 /* some cases can be optimized here */
316 if (arg2 == 0) {
317 tcg_gen_mov_i32(ret, arg1);
318 } else {
319 tcg_gen_add_i32(ret, arg1, tcg_const_i32(arg2));
320 }
bellardc896fe22008-02-01 10:05:41 +0000321}
322
pbrookac56dd42008-02-03 19:56:33 +0000323static inline void tcg_gen_sub_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000324{
325 tcg_gen_op3(INDEX_op_sub_i32, ret, arg1, arg2);
326}
327
pbrookac56dd42008-02-03 19:56:33 +0000328static inline void tcg_gen_subi_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000329{
blueswir170894422008-02-20 18:01:23 +0000330 /* some cases can be optimized here */
331 if (arg2 == 0) {
332 tcg_gen_mov_i32(ret, arg1);
333 } else {
334 tcg_gen_sub_i32(ret, arg1, tcg_const_i32(arg2));
335 }
bellardc896fe22008-02-01 10:05:41 +0000336}
337
pbrookac56dd42008-02-03 19:56:33 +0000338static inline void tcg_gen_and_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000339{
340 tcg_gen_op3(INDEX_op_and_i32, ret, arg1, arg2);
341}
342
pbrookac56dd42008-02-03 19:56:33 +0000343static inline void tcg_gen_andi_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000344{
345 /* some cases can be optimized here */
346 if (arg2 == 0) {
347 tcg_gen_movi_i32(ret, 0);
348 } else if (arg2 == 0xffffffff) {
349 tcg_gen_mov_i32(ret, arg1);
350 } else {
351 tcg_gen_and_i32(ret, arg1, tcg_const_i32(arg2));
352 }
353}
354
pbrookac56dd42008-02-03 19:56:33 +0000355static inline void tcg_gen_or_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000356{
357 tcg_gen_op3(INDEX_op_or_i32, ret, arg1, arg2);
358}
359
pbrookac56dd42008-02-03 19:56:33 +0000360static inline void tcg_gen_ori_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000361{
362 /* some cases can be optimized here */
363 if (arg2 == 0xffffffff) {
blueswir170894422008-02-20 18:01:23 +0000364 tcg_gen_movi_i32(ret, 0xffffffff);
bellardc896fe22008-02-01 10:05:41 +0000365 } else if (arg2 == 0) {
366 tcg_gen_mov_i32(ret, arg1);
367 } else {
368 tcg_gen_or_i32(ret, arg1, tcg_const_i32(arg2));
369 }
370}
371
pbrookac56dd42008-02-03 19:56:33 +0000372static inline void tcg_gen_xor_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000373{
374 tcg_gen_op3(INDEX_op_xor_i32, ret, arg1, arg2);
375}
376
pbrookac56dd42008-02-03 19:56:33 +0000377static inline void tcg_gen_xori_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000378{
379 /* some cases can be optimized here */
380 if (arg2 == 0) {
381 tcg_gen_mov_i32(ret, arg1);
382 } else {
383 tcg_gen_xor_i32(ret, arg1, tcg_const_i32(arg2));
384 }
385}
386
pbrookac56dd42008-02-03 19:56:33 +0000387static inline void tcg_gen_shl_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000388{
389 tcg_gen_op3(INDEX_op_shl_i32, ret, arg1, arg2);
390}
391
pbrookac56dd42008-02-03 19:56:33 +0000392static inline void tcg_gen_shli_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000393{
394 tcg_gen_shl_i32(ret, arg1, tcg_const_i32(arg2));
395}
396
pbrookac56dd42008-02-03 19:56:33 +0000397static inline void tcg_gen_shr_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000398{
399 tcg_gen_op3(INDEX_op_shr_i32, ret, arg1, arg2);
400}
401
pbrookac56dd42008-02-03 19:56:33 +0000402static inline void tcg_gen_shri_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000403{
404 tcg_gen_shr_i32(ret, arg1, tcg_const_i32(arg2));
405}
406
pbrookac56dd42008-02-03 19:56:33 +0000407static inline void tcg_gen_sar_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000408{
409 tcg_gen_op3(INDEX_op_sar_i32, ret, arg1, arg2);
410}
411
pbrookac56dd42008-02-03 19:56:33 +0000412static inline void tcg_gen_sari_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000413{
414 tcg_gen_sar_i32(ret, arg1, tcg_const_i32(arg2));
415}
416
pbrookac56dd42008-02-03 19:56:33 +0000417static inline void tcg_gen_brcond_i32(int cond, TCGv arg1, TCGv arg2,
bellardc896fe22008-02-01 10:05:41 +0000418 int label_index)
419{
pbrookac56dd42008-02-03 19:56:33 +0000420 tcg_gen_op4ii(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000421}
422
pbrookac56dd42008-02-03 19:56:33 +0000423static inline void tcg_gen_mul_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000424{
425 tcg_gen_op3(INDEX_op_mul_i32, ret, arg1, arg2);
426}
427
428#ifdef TCG_TARGET_HAS_div_i32
pbrookac56dd42008-02-03 19:56:33 +0000429static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000430{
431 tcg_gen_op3(INDEX_op_div_i32, ret, arg1, arg2);
432}
433
pbrookac56dd42008-02-03 19:56:33 +0000434static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000435{
436 tcg_gen_op3(INDEX_op_rem_i32, ret, arg1, arg2);
437}
438
pbrookac56dd42008-02-03 19:56:33 +0000439static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000440{
441 tcg_gen_op3(INDEX_op_divu_i32, ret, arg1, arg2);
442}
443
pbrookac56dd42008-02-03 19:56:33 +0000444static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000445{
446 tcg_gen_op3(INDEX_op_remu_i32, ret, arg1, arg2);
447}
448#else
pbrookac56dd42008-02-03 19:56:33 +0000449static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000450{
pbrookac56dd42008-02-03 19:56:33 +0000451 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000452 t0 = tcg_temp_new(TCG_TYPE_I32);
453 tcg_gen_sari_i32(t0, arg1, 31);
454 tcg_gen_op5(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
455}
456
pbrookac56dd42008-02-03 19:56:33 +0000457static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000458{
pbrookac56dd42008-02-03 19:56:33 +0000459 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000460 t0 = tcg_temp_new(TCG_TYPE_I32);
461 tcg_gen_sari_i32(t0, arg1, 31);
462 tcg_gen_op5(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
463}
464
pbrookac56dd42008-02-03 19:56:33 +0000465static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000466{
pbrookac56dd42008-02-03 19:56:33 +0000467 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000468 t0 = tcg_temp_new(TCG_TYPE_I32);
469 tcg_gen_movi_i32(t0, 0);
470 tcg_gen_op5(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
471}
472
pbrookac56dd42008-02-03 19:56:33 +0000473static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000474{
pbrookac56dd42008-02-03 19:56:33 +0000475 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000476 t0 = tcg_temp_new(TCG_TYPE_I32);
477 tcg_gen_movi_i32(t0, 0);
478 tcg_gen_op5(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
479}
480#endif
481
482#if TCG_TARGET_REG_BITS == 32
483
pbrookac56dd42008-02-03 19:56:33 +0000484static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000485{
486 tcg_gen_mov_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +0000487 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
bellardc896fe22008-02-01 10:05:41 +0000488}
489
pbrookac56dd42008-02-03 19:56:33 +0000490static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000491{
492 tcg_gen_movi_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +0000493 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
bellardc896fe22008-02-01 10:05:41 +0000494}
495
pbrookac56dd42008-02-03 19:56:33 +0000496static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000497{
498 tcg_gen_ld8u_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000499 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000500}
501
pbrookac56dd42008-02-03 19:56:33 +0000502static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000503{
504 tcg_gen_ld8s_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000505 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +0000506}
507
pbrookac56dd42008-02-03 19:56:33 +0000508static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000509{
510 tcg_gen_ld16u_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000511 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000512}
513
pbrookac56dd42008-02-03 19:56:33 +0000514static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000515{
516 tcg_gen_ld16s_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000517 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +0000518}
519
pbrookac56dd42008-02-03 19:56:33 +0000520static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000521{
522 tcg_gen_ld_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000523 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000524}
525
pbrookac56dd42008-02-03 19:56:33 +0000526static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000527{
528 tcg_gen_ld_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000529 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +0000530}
531
pbrookac56dd42008-02-03 19:56:33 +0000532static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000533{
534 /* since arg2 and ret have different types, they cannot be the
535 same temporary */
536#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000537 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000538 tcg_gen_ld_i32(ret, arg2, offset + 4);
539#else
540 tcg_gen_ld_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000541 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000542#endif
543}
544
pbrookac56dd42008-02-03 19:56:33 +0000545static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000546{
547 tcg_gen_st8_i32(arg1, arg2, offset);
548}
549
pbrookac56dd42008-02-03 19:56:33 +0000550static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000551{
552 tcg_gen_st16_i32(arg1, arg2, offset);
553}
554
pbrookac56dd42008-02-03 19:56:33 +0000555static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000556{
557 tcg_gen_st_i32(arg1, arg2, offset);
558}
559
pbrookac56dd42008-02-03 19:56:33 +0000560static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000561{
562#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000563 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000564 tcg_gen_st_i32(arg1, arg2, offset + 4);
565#else
566 tcg_gen_st_i32(arg1, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000567 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000568#endif
569}
570
pbrookac56dd42008-02-03 19:56:33 +0000571static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000572{
pbrookac56dd42008-02-03 19:56:33 +0000573 tcg_gen_op6(INDEX_op_add2_i32, ret, TCGV_HIGH(ret),
574 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000575}
576
pbrookac56dd42008-02-03 19:56:33 +0000577static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000578{
579 tcg_gen_add_i64(ret, arg1, tcg_const_i64(arg2));
580}
581
pbrookac56dd42008-02-03 19:56:33 +0000582static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000583{
pbrookac56dd42008-02-03 19:56:33 +0000584 tcg_gen_op6(INDEX_op_sub2_i32, ret, TCGV_HIGH(ret),
585 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000586}
587
pbrookac56dd42008-02-03 19:56:33 +0000588static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000589{
590 tcg_gen_sub_i64(ret, arg1, tcg_const_i64(arg2));
591}
592
pbrookac56dd42008-02-03 19:56:33 +0000593static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000594{
595 tcg_gen_and_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000596 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000597}
598
pbrookac56dd42008-02-03 19:56:33 +0000599static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000600{
601 tcg_gen_andi_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000602 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000603}
604
pbrookac56dd42008-02-03 19:56:33 +0000605static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000606{
607 tcg_gen_or_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000608 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000609}
610
pbrookac56dd42008-02-03 19:56:33 +0000611static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000612{
613 tcg_gen_ori_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000614 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000615}
616
pbrookac56dd42008-02-03 19:56:33 +0000617static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000618{
619 tcg_gen_xor_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000620 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000621}
622
pbrookac56dd42008-02-03 19:56:33 +0000623static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000624{
625 tcg_gen_xori_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000626 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000627}
628
629/* XXX: use generic code when basic block handling is OK or CPU
630 specific code (x86) */
pbrookac56dd42008-02-03 19:56:33 +0000631static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000632{
633 tcg_gen_helper_1_2(tcg_helper_shl_i64, ret, arg1, arg2);
634}
635
pbrookac56dd42008-02-03 19:56:33 +0000636static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000637{
638 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
639}
640
pbrookac56dd42008-02-03 19:56:33 +0000641static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000642{
643 tcg_gen_helper_1_2(tcg_helper_shr_i64, ret, arg1, arg2);
644}
645
pbrookac56dd42008-02-03 19:56:33 +0000646static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000647{
648 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
649}
650
pbrookac56dd42008-02-03 19:56:33 +0000651static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000652{
653 tcg_gen_helper_1_2(tcg_helper_sar_i64, ret, arg1, arg2);
654}
655
pbrookac56dd42008-02-03 19:56:33 +0000656static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000657{
658 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
659}
660
pbrookac56dd42008-02-03 19:56:33 +0000661static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2,
bellardc896fe22008-02-01 10:05:41 +0000662 int label_index)
663{
pbrookac56dd42008-02-03 19:56:33 +0000664 tcg_gen_op6ii(INDEX_op_brcond2_i32,
665 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2),
666 cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000667}
668
pbrookac56dd42008-02-03 19:56:33 +0000669static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000670{
pbrookac56dd42008-02-03 19:56:33 +0000671 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +0000672
673 t0 = tcg_temp_new(TCG_TYPE_I64);
674 t1 = tcg_temp_new(TCG_TYPE_I32);
675
pbrookac56dd42008-02-03 19:56:33 +0000676 tcg_gen_op4(INDEX_op_mulu2_i32, t0, TCGV_HIGH(t0), arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000677
pbrookac56dd42008-02-03 19:56:33 +0000678 tcg_gen_mul_i32(t1, arg1, TCGV_HIGH(arg2));
679 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
680 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), arg2);
681 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
bellardc896fe22008-02-01 10:05:41 +0000682
683 tcg_gen_mov_i64(ret, t0);
684}
685
pbrookac56dd42008-02-03 19:56:33 +0000686static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000687{
688 tcg_gen_helper_1_2(tcg_helper_div_i64, ret, arg1, arg2);
689}
690
pbrookac56dd42008-02-03 19:56:33 +0000691static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000692{
693 tcg_gen_helper_1_2(tcg_helper_rem_i64, ret, arg1, arg2);
694}
695
pbrookac56dd42008-02-03 19:56:33 +0000696static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000697{
698 tcg_gen_helper_1_2(tcg_helper_divu_i64, ret, arg1, arg2);
699}
700
pbrookac56dd42008-02-03 19:56:33 +0000701static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000702{
703 tcg_gen_helper_1_2(tcg_helper_remu_i64, ret, arg1, arg2);
704}
705
706#else
707
pbrookac56dd42008-02-03 19:56:33 +0000708static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000709{
710 tcg_gen_op2(INDEX_op_mov_i64, ret, arg);
711}
712
pbrookac56dd42008-02-03 19:56:33 +0000713static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000714{
pbrookac56dd42008-02-03 19:56:33 +0000715 tcg_gen_op2i(INDEX_op_movi_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000716}
717
pbrookac56dd42008-02-03 19:56:33 +0000718static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2,
719 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000720{
pbrookac56dd42008-02-03 19:56:33 +0000721 tcg_gen_op3i(INDEX_op_ld8u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000722}
723
pbrookac56dd42008-02-03 19:56:33 +0000724static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2,
725 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000726{
pbrookac56dd42008-02-03 19:56:33 +0000727 tcg_gen_op3i(INDEX_op_ld8s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000728}
729
pbrookac56dd42008-02-03 19:56:33 +0000730static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2,
731 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000732{
pbrookac56dd42008-02-03 19:56:33 +0000733 tcg_gen_op3i(INDEX_op_ld16u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000734}
735
pbrookac56dd42008-02-03 19:56:33 +0000736static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2,
737 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000738{
pbrookac56dd42008-02-03 19:56:33 +0000739 tcg_gen_op3i(INDEX_op_ld16s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000740}
741
pbrookac56dd42008-02-03 19:56:33 +0000742static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2,
743 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000744{
pbrookac56dd42008-02-03 19:56:33 +0000745 tcg_gen_op3i(INDEX_op_ld32u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000746}
747
pbrookac56dd42008-02-03 19:56:33 +0000748static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2,
749 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000750{
pbrookac56dd42008-02-03 19:56:33 +0000751 tcg_gen_op3i(INDEX_op_ld32s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000752}
753
pbrookac56dd42008-02-03 19:56:33 +0000754static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000755{
pbrookac56dd42008-02-03 19:56:33 +0000756 tcg_gen_op3i(INDEX_op_ld_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000757}
758
pbrookac56dd42008-02-03 19:56:33 +0000759static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2,
760 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000761{
pbrookac56dd42008-02-03 19:56:33 +0000762 tcg_gen_op3i(INDEX_op_st8_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000763}
764
pbrookac56dd42008-02-03 19:56:33 +0000765static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2,
766 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000767{
pbrookac56dd42008-02-03 19:56:33 +0000768 tcg_gen_op3i(INDEX_op_st16_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000769}
770
pbrookac56dd42008-02-03 19:56:33 +0000771static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2,
772 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000773{
pbrookac56dd42008-02-03 19:56:33 +0000774 tcg_gen_op3i(INDEX_op_st32_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000775}
776
pbrookac56dd42008-02-03 19:56:33 +0000777static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000778{
pbrookac56dd42008-02-03 19:56:33 +0000779 tcg_gen_op3i(INDEX_op_st_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000780}
781
pbrookac56dd42008-02-03 19:56:33 +0000782static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000783{
784 tcg_gen_op3(INDEX_op_add_i64, ret, arg1, arg2);
785}
786
pbrookac56dd42008-02-03 19:56:33 +0000787static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000788{
789 tcg_gen_add_i64(ret, arg1, tcg_const_i64(arg2));
790}
791
pbrookac56dd42008-02-03 19:56:33 +0000792static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000793{
794 tcg_gen_op3(INDEX_op_sub_i64, ret, arg1, arg2);
795}
796
pbrookac56dd42008-02-03 19:56:33 +0000797static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000798{
799 tcg_gen_sub_i64(ret, arg1, tcg_const_i64(arg2));
800}
801
pbrookac56dd42008-02-03 19:56:33 +0000802static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000803{
804 tcg_gen_op3(INDEX_op_and_i64, ret, arg1, arg2);
805}
806
pbrookac56dd42008-02-03 19:56:33 +0000807static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000808{
809 tcg_gen_and_i64(ret, arg1, tcg_const_i64(arg2));
810}
811
pbrookac56dd42008-02-03 19:56:33 +0000812static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000813{
814 tcg_gen_op3(INDEX_op_or_i64, ret, arg1, arg2);
815}
816
pbrookac56dd42008-02-03 19:56:33 +0000817static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000818{
819 tcg_gen_or_i64(ret, arg1, tcg_const_i64(arg2));
820}
821
pbrookac56dd42008-02-03 19:56:33 +0000822static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000823{
824 tcg_gen_op3(INDEX_op_xor_i64, ret, arg1, arg2);
825}
826
pbrookac56dd42008-02-03 19:56:33 +0000827static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000828{
829 tcg_gen_xor_i64(ret, arg1, tcg_const_i64(arg2));
830}
831
pbrookac56dd42008-02-03 19:56:33 +0000832static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000833{
834 tcg_gen_op3(INDEX_op_shl_i64, ret, arg1, arg2);
835}
836
pbrookac56dd42008-02-03 19:56:33 +0000837static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000838{
839 tcg_gen_shl_i64(ret, arg1, tcg_const_i64(arg2));
840}
841
pbrookac56dd42008-02-03 19:56:33 +0000842static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000843{
844 tcg_gen_op3(INDEX_op_shr_i64, ret, arg1, arg2);
845}
846
pbrookac56dd42008-02-03 19:56:33 +0000847static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000848{
849 tcg_gen_shr_i64(ret, arg1, tcg_const_i64(arg2));
850}
851
pbrookac56dd42008-02-03 19:56:33 +0000852static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000853{
854 tcg_gen_op3(INDEX_op_sar_i64, ret, arg1, arg2);
855}
856
pbrookac56dd42008-02-03 19:56:33 +0000857static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000858{
859 tcg_gen_sar_i64(ret, arg1, tcg_const_i64(arg2));
860}
861
pbrookac56dd42008-02-03 19:56:33 +0000862static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2,
bellardc896fe22008-02-01 10:05:41 +0000863 int label_index)
864{
pbrookac56dd42008-02-03 19:56:33 +0000865 tcg_gen_op4ii(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000866}
867
pbrookac56dd42008-02-03 19:56:33 +0000868static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000869{
870 tcg_gen_op3(INDEX_op_mul_i64, ret, arg1, arg2);
871}
872
873#ifdef TCG_TARGET_HAS_div_i64
pbrookac56dd42008-02-03 19:56:33 +0000874static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000875{
876 tcg_gen_op3(INDEX_op_div_i64, ret, arg1, arg2);
877}
878
pbrookac56dd42008-02-03 19:56:33 +0000879static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000880{
881 tcg_gen_op3(INDEX_op_rem_i64, ret, arg1, arg2);
882}
883
pbrookac56dd42008-02-03 19:56:33 +0000884static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000885{
886 tcg_gen_op3(INDEX_op_divu_i64, ret, arg1, arg2);
887}
888
pbrookac56dd42008-02-03 19:56:33 +0000889static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000890{
891 tcg_gen_op3(INDEX_op_remu_i64, ret, arg1, arg2);
892}
893#else
pbrookac56dd42008-02-03 19:56:33 +0000894static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000895{
pbrookac56dd42008-02-03 19:56:33 +0000896 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000897 t0 = tcg_temp_new(TCG_TYPE_I64);
898 tcg_gen_sari_i64(t0, arg1, 63);
899 tcg_gen_op5(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
900}
901
pbrookac56dd42008-02-03 19:56:33 +0000902static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000903{
pbrookac56dd42008-02-03 19:56:33 +0000904 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000905 t0 = tcg_temp_new(TCG_TYPE_I64);
906 tcg_gen_sari_i64(t0, arg1, 63);
907 tcg_gen_op5(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
908}
909
pbrookac56dd42008-02-03 19:56:33 +0000910static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000911{
pbrookac56dd42008-02-03 19:56:33 +0000912 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000913 t0 = tcg_temp_new(TCG_TYPE_I64);
914 tcg_gen_movi_i64(t0, 0);
915 tcg_gen_op5(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
916}
917
pbrookac56dd42008-02-03 19:56:33 +0000918static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000919{
pbrookac56dd42008-02-03 19:56:33 +0000920 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000921 t0 = tcg_temp_new(TCG_TYPE_I64);
922 tcg_gen_movi_i64(t0, 0);
923 tcg_gen_op5(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
924}
925#endif
926
927#endif
928
929/***************************************/
930/* optional operations */
931
pbrookac56dd42008-02-03 19:56:33 +0000932static inline void tcg_gen_ext8s_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000933{
934#ifdef TCG_TARGET_HAS_ext8s_i32
935 tcg_gen_op2(INDEX_op_ext8s_i32, ret, arg);
936#else
937 tcg_gen_shli_i32(ret, arg, 24);
bellard5ff9d6a2008-02-04 00:37:54 +0000938 tcg_gen_sari_i32(ret, ret, 24);
bellardc896fe22008-02-01 10:05:41 +0000939#endif
940}
941
pbrookac56dd42008-02-03 19:56:33 +0000942static inline void tcg_gen_ext16s_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000943{
944#ifdef TCG_TARGET_HAS_ext16s_i32
945 tcg_gen_op2(INDEX_op_ext16s_i32, ret, arg);
946#else
947 tcg_gen_shli_i32(ret, arg, 16);
bellard5ff9d6a2008-02-04 00:37:54 +0000948 tcg_gen_sari_i32(ret, ret, 16);
bellardc896fe22008-02-01 10:05:41 +0000949#endif
950}
951
952/* Note: we assume the two high bytes are set to zero */
pbrookac56dd42008-02-03 19:56:33 +0000953static inline void tcg_gen_bswap16_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000954{
955#ifdef TCG_TARGET_HAS_bswap16_i32
956 tcg_gen_op2(INDEX_op_bswap16_i32, ret, arg);
957#else
pbrookac56dd42008-02-03 19:56:33 +0000958 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +0000959 t0 = tcg_temp_new(TCG_TYPE_I32);
960 t1 = tcg_temp_new(TCG_TYPE_I32);
961
962 tcg_gen_shri_i32(t0, arg, 8);
963 tcg_gen_andi_i32(t1, arg, 0x000000ff);
964 tcg_gen_shli_i32(t1, t1, 8);
965 tcg_gen_or_i32(ret, t0, t1);
966#endif
967}
968
pbrookac56dd42008-02-03 19:56:33 +0000969static inline void tcg_gen_bswap_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000970{
971#ifdef TCG_TARGET_HAS_bswap_i32
972 tcg_gen_op2(INDEX_op_bswap_i32, ret, arg);
973#else
pbrookac56dd42008-02-03 19:56:33 +0000974 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +0000975 t0 = tcg_temp_new(TCG_TYPE_I32);
976 t1 = tcg_temp_new(TCG_TYPE_I32);
977
978 tcg_gen_shli_i32(t0, arg, 24);
979
980 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
981 tcg_gen_shli_i32(t1, t1, 8);
982 tcg_gen_or_i32(t0, t0, t1);
983
984 tcg_gen_shri_i32(t1, arg, 8);
985 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
986 tcg_gen_or_i32(t0, t0, t1);
987
988 tcg_gen_shri_i32(t1, arg, 24);
989 tcg_gen_or_i32(ret, t0, t1);
990#endif
991}
992
993#if TCG_TARGET_REG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +0000994static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000995{
996 tcg_gen_ext8s_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +0000997 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +0000998}
999
pbrookac56dd42008-02-03 19:56:33 +00001000static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001001{
1002 tcg_gen_ext16s_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001003 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001004}
1005
pbrookac56dd42008-02-03 19:56:33 +00001006static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001007{
1008 tcg_gen_mov_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001009 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001010}
1011
pbrookac56dd42008-02-03 19:56:33 +00001012static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001013{
1014 tcg_gen_mov_i32(ret, arg);
1015}
1016
pbrookac56dd42008-02-03 19:56:33 +00001017static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001018{
1019 tcg_gen_mov_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001020 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001021}
1022
pbrookac56dd42008-02-03 19:56:33 +00001023static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001024{
1025 tcg_gen_mov_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001026 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001027}
1028
pbrookac56dd42008-02-03 19:56:33 +00001029static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001030{
pbrookac56dd42008-02-03 19:56:33 +00001031 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +00001032 t0 = tcg_temp_new(TCG_TYPE_I32);
1033 t1 = tcg_temp_new(TCG_TYPE_I32);
1034
1035 tcg_gen_bswap_i32(t0, arg);
pbrookac56dd42008-02-03 19:56:33 +00001036 tcg_gen_bswap_i32(t1, TCGV_HIGH(arg));
bellardc896fe22008-02-01 10:05:41 +00001037 tcg_gen_mov_i32(ret, t1);
pbrookac56dd42008-02-03 19:56:33 +00001038 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
bellardc896fe22008-02-01 10:05:41 +00001039}
1040#else
1041
pbrookac56dd42008-02-03 19:56:33 +00001042static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001043{
1044#ifdef TCG_TARGET_HAS_ext8s_i64
1045 tcg_gen_op2(INDEX_op_ext8s_i64, ret, arg);
1046#else
1047 tcg_gen_shli_i64(ret, arg, 56);
bellard5ff9d6a2008-02-04 00:37:54 +00001048 tcg_gen_sari_i64(ret, ret, 56);
bellardc896fe22008-02-01 10:05:41 +00001049#endif
1050}
1051
pbrookac56dd42008-02-03 19:56:33 +00001052static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001053{
1054#ifdef TCG_TARGET_HAS_ext16s_i64
1055 tcg_gen_op2(INDEX_op_ext16s_i64, ret, arg);
1056#else
1057 tcg_gen_shli_i64(ret, arg, 48);
bellard5ff9d6a2008-02-04 00:37:54 +00001058 tcg_gen_sari_i64(ret, ret, 48);
bellardc896fe22008-02-01 10:05:41 +00001059#endif
1060}
1061
pbrookac56dd42008-02-03 19:56:33 +00001062static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001063{
1064#ifdef TCG_TARGET_HAS_ext32s_i64
1065 tcg_gen_op2(INDEX_op_ext32s_i64, ret, arg);
1066#else
1067 tcg_gen_shli_i64(ret, arg, 32);
bellard5ff9d6a2008-02-04 00:37:54 +00001068 tcg_gen_sari_i64(ret, ret, 32);
bellardc896fe22008-02-01 10:05:41 +00001069#endif
1070}
1071
1072/* Note: we assume the target supports move between 32 and 64 bit
pbrookac56dd42008-02-03 19:56:33 +00001073 registers. This will probably break MIPS64 targets. */
1074static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001075{
1076 tcg_gen_mov_i32(ret, arg);
1077}
1078
1079/* Note: we assume the target supports move between 32 and 64 bit
1080 registers */
pbrookac56dd42008-02-03 19:56:33 +00001081static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001082{
1083 tcg_gen_andi_i64(ret, arg, 0xffffffff);
1084}
1085
1086/* Note: we assume the target supports move between 32 and 64 bit
1087 registers */
pbrookac56dd42008-02-03 19:56:33 +00001088static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001089{
1090 tcg_gen_ext32s_i64(ret, arg);
1091}
1092
pbrookac56dd42008-02-03 19:56:33 +00001093static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001094{
1095#ifdef TCG_TARGET_HAS_bswap_i64
1096 tcg_gen_op2(INDEX_op_bswap_i64, ret, arg);
1097#else
pbrookac56dd42008-02-03 19:56:33 +00001098 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +00001099 t0 = tcg_temp_new(TCG_TYPE_I32);
1100 t1 = tcg_temp_new(TCG_TYPE_I32);
1101
1102 tcg_gen_shli_i64(t0, arg, 56);
1103
1104 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1105 tcg_gen_shli_i64(t1, t1, 40);
1106 tcg_gen_or_i64(t0, t0, t1);
1107
1108 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1109 tcg_gen_shli_i64(t1, t1, 24);
1110 tcg_gen_or_i64(t0, t0, t1);
1111
1112 tcg_gen_andi_i64(t1, arg, 0xff000000);
1113 tcg_gen_shli_i64(t1, t1, 8);
1114 tcg_gen_or_i64(t0, t0, t1);
1115
1116 tcg_gen_shri_i64(t1, arg, 8);
1117 tcg_gen_andi_i64(t1, t1, 0xff000000);
1118 tcg_gen_or_i64(t0, t0, t1);
1119
1120 tcg_gen_shri_i64(t1, arg, 24);
1121 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1122 tcg_gen_or_i64(t0, t0, t1);
1123
1124 tcg_gen_shri_i64(t1, arg, 40);
1125 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1126 tcg_gen_or_i64(t0, t0, t1);
1127
1128 tcg_gen_shri_i64(t1, arg, 56);
1129 tcg_gen_or_i64(ret, t0, t1);
1130#endif
1131}
1132
1133#endif
1134
bellard5ff9d6a2008-02-04 00:37:54 +00001135
1136static inline void tcg_gen_discard_i32(TCGv arg)
1137{
1138 tcg_gen_op1(INDEX_op_discard, arg);
1139}
1140
1141#if TCG_TARGET_REG_BITS == 32
1142static inline void tcg_gen_discard_i64(TCGv arg)
1143{
1144 tcg_gen_discard_i32(arg);
1145 tcg_gen_discard_i32(TCGV_HIGH(arg));
1146}
1147#else
1148static inline void tcg_gen_discard_i64(TCGv arg)
1149{
1150 tcg_gen_op1(INDEX_op_discard, arg);
1151}
1152#endif
1153
bellardc896fe22008-02-01 10:05:41 +00001154/***************************************/
pbrookac56dd42008-02-03 19:56:33 +00001155static inline void tcg_gen_macro_2(TCGv ret0, TCGv ret1, int macro_id)
bellardc896fe22008-02-01 10:05:41 +00001156{
pbrookac56dd42008-02-03 19:56:33 +00001157 tcg_gen_op3i(INDEX_op_macro_2, ret0, ret1, macro_id);
bellardc896fe22008-02-01 10:05:41 +00001158}
1159
1160/***************************************/
1161/* QEMU specific operations. Their type depend on the QEMU CPU
1162 type. */
1163#ifndef TARGET_LONG_BITS
1164#error must include QEMU headers
1165#endif
1166
1167static inline void tcg_gen_exit_tb(tcg_target_long val)
1168{
pbrookac56dd42008-02-03 19:56:33 +00001169 tcg_gen_op1i(INDEX_op_exit_tb, val);
bellardc896fe22008-02-01 10:05:41 +00001170}
1171
1172static inline void tcg_gen_goto_tb(int idx)
1173{
pbrookac56dd42008-02-03 19:56:33 +00001174 tcg_gen_op1i(INDEX_op_goto_tb, idx);
bellardc896fe22008-02-01 10:05:41 +00001175}
1176
1177#if TCG_TARGET_REG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001178static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001179{
1180#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001181 tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001182#else
pbrookac56dd42008-02-03 19:56:33 +00001183 tcg_gen_op4i(INDEX_op_qemu_ld8u, ret, addr, TCGV_HIGH(addr), mem_index);
1184 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001185#endif
1186}
1187
pbrookac56dd42008-02-03 19:56:33 +00001188static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001189{
1190#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001191 tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001192#else
pbrookac56dd42008-02-03 19:56:33 +00001193 tcg_gen_op4i(INDEX_op_qemu_ld8s, ret, addr, TCGV_HIGH(addr), mem_index);
pbrook21fc3cf2008-03-04 23:52:47 +00001194 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001195#endif
1196}
1197
pbrookac56dd42008-02-03 19:56:33 +00001198static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001199{
1200#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001201 tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001202#else
pbrookac56dd42008-02-03 19:56:33 +00001203 tcg_gen_op4i(INDEX_op_qemu_ld16u, ret, addr, TCGV_HIGH(addr), mem_index);
1204 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001205#endif
1206}
1207
pbrookac56dd42008-02-03 19:56:33 +00001208static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001209{
1210#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001211 tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001212#else
pbrookac56dd42008-02-03 19:56:33 +00001213 tcg_gen_op4i(INDEX_op_qemu_ld16s, ret, addr, TCGV_HIGH(addr), mem_index);
pbrook21fc3cf2008-03-04 23:52:47 +00001214 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001215#endif
1216}
1217
pbrookac56dd42008-02-03 19:56:33 +00001218static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001219{
1220#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001221 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001222#else
pbrookac56dd42008-02-03 19:56:33 +00001223 tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
1224 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001225#endif
1226}
1227
pbrookac56dd42008-02-03 19:56:33 +00001228static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001229{
1230#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001231 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001232#else
pbrookac56dd42008-02-03 19:56:33 +00001233 tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
1234 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001235#endif
1236}
1237
pbrookac56dd42008-02-03 19:56:33 +00001238static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001239{
1240#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001241 tcg_gen_op4i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret), addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001242#else
pbrookac56dd42008-02-03 19:56:33 +00001243 tcg_gen_op5i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret),
1244 addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001245#endif
1246}
1247
pbrookac56dd42008-02-03 19:56:33 +00001248static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001249{
1250#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001251 tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001252#else
pbrookac56dd42008-02-03 19:56:33 +00001253 tcg_gen_op4i(INDEX_op_qemu_st8, arg, addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001254#endif
1255}
1256
pbrookac56dd42008-02-03 19:56:33 +00001257static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001258{
1259#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001260 tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001261#else
pbrookac56dd42008-02-03 19:56:33 +00001262 tcg_gen_op4i(INDEX_op_qemu_st16, arg, addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001263#endif
1264}
1265
pbrookac56dd42008-02-03 19:56:33 +00001266static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001267{
1268#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001269 tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001270#else
pbrookac56dd42008-02-03 19:56:33 +00001271 tcg_gen_op4i(INDEX_op_qemu_st32, arg, addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001272#endif
1273}
1274
pbrookac56dd42008-02-03 19:56:33 +00001275static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001276{
1277#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001278 tcg_gen_op4i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg), addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001279#else
pbrookac56dd42008-02-03 19:56:33 +00001280 tcg_gen_op5i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg),
1281 addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001282#endif
1283}
1284
blueswir156b8f562008-02-25 18:29:19 +00001285#define tcg_gen_ld_ptr tcg_gen_ld_i32
blueswir1a768e4b2008-03-16 19:16:37 +00001286#define tcg_gen_discard_ptr tcg_gen_discard_i32
blueswir1f8422f52008-02-24 07:45:43 +00001287
bellardc896fe22008-02-01 10:05:41 +00001288#else /* TCG_TARGET_REG_BITS == 32 */
1289
pbrookac56dd42008-02-03 19:56:33 +00001290static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001291{
pbrookac56dd42008-02-03 19:56:33 +00001292 tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001293}
1294
pbrookac56dd42008-02-03 19:56:33 +00001295static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001296{
pbrookac56dd42008-02-03 19:56:33 +00001297 tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001298}
1299
pbrookac56dd42008-02-03 19:56:33 +00001300static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001301{
pbrookac56dd42008-02-03 19:56:33 +00001302 tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001303}
1304
pbrookac56dd42008-02-03 19:56:33 +00001305static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001306{
pbrookac56dd42008-02-03 19:56:33 +00001307 tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001308}
1309
pbrookac56dd42008-02-03 19:56:33 +00001310static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001311{
pbrookac56dd42008-02-03 19:56:33 +00001312 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001313}
1314
pbrookac56dd42008-02-03 19:56:33 +00001315static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001316{
pbrookac56dd42008-02-03 19:56:33 +00001317 tcg_gen_op3i(INDEX_op_qemu_ld32s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001318}
1319
pbrookac56dd42008-02-03 19:56:33 +00001320static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001321{
pbrookac56dd42008-02-03 19:56:33 +00001322 tcg_gen_op3i(INDEX_op_qemu_ld64, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001323}
1324
pbrookac56dd42008-02-03 19:56:33 +00001325static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001326{
pbrookac56dd42008-02-03 19:56:33 +00001327 tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001328}
1329
pbrookac56dd42008-02-03 19:56:33 +00001330static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001331{
pbrookac56dd42008-02-03 19:56:33 +00001332 tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001333}
1334
pbrookac56dd42008-02-03 19:56:33 +00001335static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001336{
pbrookac56dd42008-02-03 19:56:33 +00001337 tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001338}
1339
pbrookac56dd42008-02-03 19:56:33 +00001340static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001341{
pbrookac56dd42008-02-03 19:56:33 +00001342 tcg_gen_op3i(INDEX_op_qemu_st64, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001343}
1344
blueswir156b8f562008-02-25 18:29:19 +00001345#define tcg_gen_ld_ptr tcg_gen_ld_i64
blueswir1a768e4b2008-03-16 19:16:37 +00001346#define tcg_gen_discard_ptr tcg_gen_discard_i64
blueswir1f8422f52008-02-24 07:45:43 +00001347
bellardc896fe22008-02-01 10:05:41 +00001348#endif /* TCG_TARGET_REG_BITS != 32 */
blueswir1f8422f52008-02-24 07:45:43 +00001349
1350#if TARGET_LONG_BITS == 64
1351#define TCG_TYPE_TL TCG_TYPE_I64
1352#define tcg_gen_movi_tl tcg_gen_movi_i64
1353#define tcg_gen_mov_tl tcg_gen_mov_i64
1354#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
1355#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
1356#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
1357#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
1358#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
1359#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
1360#define tcg_gen_ld_tl tcg_gen_ld_i64
1361#define tcg_gen_st8_tl tcg_gen_st8_i64
1362#define tcg_gen_st16_tl tcg_gen_st16_i64
1363#define tcg_gen_st32_tl tcg_gen_st32_i64
1364#define tcg_gen_st_tl tcg_gen_st_i64
1365#define tcg_gen_add_tl tcg_gen_add_i64
1366#define tcg_gen_addi_tl tcg_gen_addi_i64
1367#define tcg_gen_sub_tl tcg_gen_sub_i64
1368#define tcg_gen_subi_tl tcg_gen_subi_i64
1369#define tcg_gen_and_tl tcg_gen_and_i64
1370#define tcg_gen_andi_tl tcg_gen_andi_i64
1371#define tcg_gen_or_tl tcg_gen_or_i64
1372#define tcg_gen_ori_tl tcg_gen_ori_i64
1373#define tcg_gen_xor_tl tcg_gen_xor_i64
1374#define tcg_gen_xori_tl tcg_gen_xori_i64
1375#define tcg_gen_shl_tl tcg_gen_shl_i64
1376#define tcg_gen_shli_tl tcg_gen_shli_i64
1377#define tcg_gen_shr_tl tcg_gen_shr_i64
1378#define tcg_gen_shri_tl tcg_gen_shri_i64
1379#define tcg_gen_sar_tl tcg_gen_sar_i64
1380#define tcg_gen_sari_tl tcg_gen_sari_i64
blueswir10cf767d2008-03-02 18:20:59 +00001381#define tcg_gen_brcond_tl tcg_gen_brcond_i64
blueswir1a768e4b2008-03-16 19:16:37 +00001382#define tcg_gen_discard_tl tcg_gen_discard_i64
blueswir1e4290732008-03-22 08:39:04 +00001383#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
1384#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
1385#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
1386#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
1387#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
1388#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
blueswir1a98824a2008-03-13 20:46:42 +00001389#define tcg_const_tl tcg_const_i64
blueswir1f8422f52008-02-24 07:45:43 +00001390#else
1391#define TCG_TYPE_TL TCG_TYPE_I32
1392#define tcg_gen_movi_tl tcg_gen_movi_i32
1393#define tcg_gen_mov_tl tcg_gen_mov_i32
1394#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
1395#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
1396#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
1397#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
1398#define tcg_gen_ld32u_tl tcg_gen_ld_i32
1399#define tcg_gen_ld32s_tl tcg_gen_ld_i32
1400#define tcg_gen_ld_tl tcg_gen_ld_i32
1401#define tcg_gen_st8_tl tcg_gen_st8_i32
1402#define tcg_gen_st16_tl tcg_gen_st16_i32
1403#define tcg_gen_st32_tl tcg_gen_st_i32
1404#define tcg_gen_st_tl tcg_gen_st_i32
1405#define tcg_gen_add_tl tcg_gen_add_i32
1406#define tcg_gen_addi_tl tcg_gen_addi_i32
1407#define tcg_gen_sub_tl tcg_gen_sub_i32
1408#define tcg_gen_subi_tl tcg_gen_subi_i32
1409#define tcg_gen_and_tl tcg_gen_and_i32
1410#define tcg_gen_andi_tl tcg_gen_andi_i32
1411#define tcg_gen_or_tl tcg_gen_or_i32
1412#define tcg_gen_ori_tl tcg_gen_ori_i32
1413#define tcg_gen_xor_tl tcg_gen_xor_i32
1414#define tcg_gen_xori_tl tcg_gen_xori_i32
1415#define tcg_gen_shl_tl tcg_gen_shl_i32
1416#define tcg_gen_shli_tl tcg_gen_shli_i32
1417#define tcg_gen_shr_tl tcg_gen_shr_i32
1418#define tcg_gen_shri_tl tcg_gen_shri_i32
1419#define tcg_gen_sar_tl tcg_gen_sar_i32
1420#define tcg_gen_sari_tl tcg_gen_sari_i32
blueswir10cf767d2008-03-02 18:20:59 +00001421#define tcg_gen_brcond_tl tcg_gen_brcond_i32
blueswir1a768e4b2008-03-16 19:16:37 +00001422#define tcg_gen_discard_tl tcg_gen_discard_i32
blueswir1e4290732008-03-22 08:39:04 +00001423#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
1424#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
1425#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
1426#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
1427#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
1428#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
blueswir1a98824a2008-03-13 20:46:42 +00001429#define tcg_const_tl tcg_const_i32
blueswir1f8422f52008-02-24 07:45:43 +00001430#endif
pbrook6ddbc6e2008-03-31 03:46:33 +00001431
1432#if TCG_TARGET_REG_BITS == 32
1433#define tcg_gen_addi_ptr tcg_gen_addi_i32
1434#else /* TCG_TARGET_REG_BITS == 32 */
1435#define tcg_gen_addi_ptr tcg_gen_addi_i64
1436#endif /* TCG_TARGET_REG_BITS != 32 */
1437