blob: bc6be8537eb32967b3091aae12b1e6ab40c73a74 [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
blueswir1bf6247f2008-05-10 12:27:33 +000026#ifdef CONFIG_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
pbrookbcb01262008-05-24 02:24:25 +000059static inline void tcg_gen_op2ii(int opc, TCGArg arg1, TCGArg arg2)
60{
61 *gen_opc_ptr++ = opc;
62 *gen_opparam_ptr++ = arg1;
63 *gen_opparam_ptr++ = arg2;
64}
65
pbrookac56dd42008-02-03 19:56:33 +000066static inline void tcg_gen_op3(int opc, TCGv arg1, TCGv arg2, TCGv arg3)
bellardc896fe22008-02-01 10:05:41 +000067{
68 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +000069 *gen_opparam_ptr++ = GET_TCGV(arg1);
70 *gen_opparam_ptr++ = GET_TCGV(arg2);
71 *gen_opparam_ptr++ = GET_TCGV(arg3);
72}
73
74static inline void tcg_gen_op3i(int opc, TCGv arg1, TCGv arg2, TCGArg arg3)
75{
76 *gen_opc_ptr++ = opc;
77 *gen_opparam_ptr++ = GET_TCGV(arg1);
78 *gen_opparam_ptr++ = GET_TCGV(arg2);
bellardc896fe22008-02-01 10:05:41 +000079 *gen_opparam_ptr++ = arg3;
80}
81
pbrookac56dd42008-02-03 19:56:33 +000082static inline void tcg_gen_op4(int opc, TCGv arg1, TCGv arg2, TCGv arg3,
83 TCGv arg4)
bellardc896fe22008-02-01 10:05:41 +000084{
85 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +000086 *gen_opparam_ptr++ = GET_TCGV(arg1);
87 *gen_opparam_ptr++ = GET_TCGV(arg2);
88 *gen_opparam_ptr++ = GET_TCGV(arg3);
89 *gen_opparam_ptr++ = GET_TCGV(arg4);
90}
91
92static inline void tcg_gen_op4i(int opc, TCGv arg1, TCGv arg2, TCGv arg3,
93 TCGArg arg4)
94{
95 *gen_opc_ptr++ = opc;
96 *gen_opparam_ptr++ = GET_TCGV(arg1);
97 *gen_opparam_ptr++ = GET_TCGV(arg2);
98 *gen_opparam_ptr++ = GET_TCGV(arg3);
99 *gen_opparam_ptr++ = arg4;
100}
101
102static inline void tcg_gen_op4ii(int opc, TCGv arg1, TCGv arg2, TCGArg arg3,
103 TCGArg arg4)
104{
105 *gen_opc_ptr++ = opc;
106 *gen_opparam_ptr++ = GET_TCGV(arg1);
107 *gen_opparam_ptr++ = GET_TCGV(arg2);
bellardc896fe22008-02-01 10:05:41 +0000108 *gen_opparam_ptr++ = arg3;
109 *gen_opparam_ptr++ = arg4;
110}
111
pbrookac56dd42008-02-03 19:56:33 +0000112static inline void tcg_gen_op5(int opc, TCGv arg1, TCGv arg2,
113 TCGv arg3, TCGv arg4,
114 TCGv arg5)
bellardc896fe22008-02-01 10:05:41 +0000115{
116 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +0000117 *gen_opparam_ptr++ = GET_TCGV(arg1);
118 *gen_opparam_ptr++ = GET_TCGV(arg2);
119 *gen_opparam_ptr++ = GET_TCGV(arg3);
120 *gen_opparam_ptr++ = GET_TCGV(arg4);
121 *gen_opparam_ptr++ = GET_TCGV(arg5);
122}
123
124static inline void tcg_gen_op5i(int opc, TCGv arg1, TCGv arg2,
125 TCGv arg3, TCGv arg4,
126 TCGArg arg5)
127{
128 *gen_opc_ptr++ = opc;
129 *gen_opparam_ptr++ = GET_TCGV(arg1);
130 *gen_opparam_ptr++ = GET_TCGV(arg2);
131 *gen_opparam_ptr++ = GET_TCGV(arg3);
132 *gen_opparam_ptr++ = GET_TCGV(arg4);
bellardc896fe22008-02-01 10:05:41 +0000133 *gen_opparam_ptr++ = arg5;
134}
135
pbrookac56dd42008-02-03 19:56:33 +0000136static inline void tcg_gen_op6(int opc, TCGv arg1, TCGv arg2,
137 TCGv arg3, TCGv arg4,
138 TCGv arg5, TCGv arg6)
bellardc896fe22008-02-01 10:05:41 +0000139{
140 *gen_opc_ptr++ = opc;
pbrookac56dd42008-02-03 19:56:33 +0000141 *gen_opparam_ptr++ = GET_TCGV(arg1);
142 *gen_opparam_ptr++ = GET_TCGV(arg2);
143 *gen_opparam_ptr++ = GET_TCGV(arg3);
144 *gen_opparam_ptr++ = GET_TCGV(arg4);
145 *gen_opparam_ptr++ = GET_TCGV(arg5);
146 *gen_opparam_ptr++ = GET_TCGV(arg6);
147}
148
149static inline void tcg_gen_op6ii(int opc, TCGv arg1, TCGv arg2,
150 TCGv arg3, TCGv arg4,
151 TCGArg arg5, TCGArg arg6)
152{
153 *gen_opc_ptr++ = opc;
154 *gen_opparam_ptr++ = GET_TCGV(arg1);
155 *gen_opparam_ptr++ = GET_TCGV(arg2);
156 *gen_opparam_ptr++ = GET_TCGV(arg3);
157 *gen_opparam_ptr++ = GET_TCGV(arg4);
bellardc896fe22008-02-01 10:05:41 +0000158 *gen_opparam_ptr++ = arg5;
159 *gen_opparam_ptr++ = arg6;
160}
161
162static inline void gen_set_label(int n)
163{
pbrookac56dd42008-02-03 19:56:33 +0000164 tcg_gen_op1i(INDEX_op_set_label, n);
bellardc896fe22008-02-01 10:05:41 +0000165}
166
blueswir1fb50d412008-03-21 17:58:45 +0000167static inline void tcg_gen_br(int label)
168{
169 tcg_gen_op1i(INDEX_op_br, label);
170}
171
pbrookac56dd42008-02-03 19:56:33 +0000172static inline void tcg_gen_mov_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000173{
pbrook98156422008-05-10 18:43:02 +0000174 if (GET_TCGV(ret) != GET_TCGV(arg))
blueswir14d072722008-05-03 20:52:26 +0000175 tcg_gen_op2(INDEX_op_mov_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000176}
177
pbrookac56dd42008-02-03 19:56:33 +0000178static inline void tcg_gen_movi_i32(TCGv ret, int32_t arg)
bellardc896fe22008-02-01 10:05:41 +0000179{
pbrookac56dd42008-02-03 19:56:33 +0000180 tcg_gen_op2i(INDEX_op_movi_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000181}
182
183/* helper calls */
184#define TCG_HELPER_CALL_FLAGS 0
185
186static inline void tcg_gen_helper_0_0(void *func)
187{
bellarde8996ee2008-05-23 17:33:39 +0000188 TCGv t0;
189 t0 = tcg_const_ptr((tcg_target_long)func);
bellardc896fe22008-02-01 10:05:41 +0000190 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000191 t0, TCG_HELPER_CALL_FLAGS,
bellardc896fe22008-02-01 10:05:41 +0000192 0, NULL, 0, NULL);
bellarde8996ee2008-05-23 17:33:39 +0000193 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000194}
195
pbrookac56dd42008-02-03 19:56:33 +0000196static inline void tcg_gen_helper_0_1(void *func, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000197{
bellarde8996ee2008-05-23 17:33:39 +0000198 TCGv t0;
199 t0 = tcg_const_ptr((tcg_target_long)func);
bellardc896fe22008-02-01 10:05:41 +0000200 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000201 t0, TCG_HELPER_CALL_FLAGS,
bellardc896fe22008-02-01 10:05:41 +0000202 0, NULL, 1, &arg);
bellarde8996ee2008-05-23 17:33:39 +0000203 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000204}
205
pbrookac56dd42008-02-03 19:56:33 +0000206static inline void tcg_gen_helper_0_2(void *func, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000207{
pbrookac56dd42008-02-03 19:56:33 +0000208 TCGv args[2];
bellarde8996ee2008-05-23 17:33:39 +0000209 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000210 args[0] = arg1;
211 args[1] = arg2;
bellarde8996ee2008-05-23 17:33:39 +0000212 t0 = tcg_const_ptr((tcg_target_long)func);
bellardc896fe22008-02-01 10:05:41 +0000213 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000214 t0, TCG_HELPER_CALL_FLAGS,
bellardc896fe22008-02-01 10:05:41 +0000215 0, NULL, 2, args);
bellarde8996ee2008-05-23 17:33:39 +0000216 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000217}
218
pbrookb0109802008-03-31 03:47:03 +0000219static inline void tcg_gen_helper_0_3(void *func,
220 TCGv arg1, TCGv arg2, TCGv arg3)
221{
222 TCGv args[3];
bellarde8996ee2008-05-23 17:33:39 +0000223 TCGv t0;
pbrookb0109802008-03-31 03:47:03 +0000224 args[0] = arg1;
225 args[1] = arg2;
226 args[2] = arg3;
bellarde8996ee2008-05-23 17:33:39 +0000227 t0 = tcg_const_ptr((tcg_target_long)func);
pbrookb0109802008-03-31 03:47:03 +0000228 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000229 t0, TCG_HELPER_CALL_FLAGS,
pbrookb0109802008-03-31 03:47:03 +0000230 0, NULL, 3, args);
bellarde8996ee2008-05-23 17:33:39 +0000231 tcg_temp_free(t0);
pbrookb0109802008-03-31 03:47:03 +0000232}
233
blueswir1f8422f52008-02-24 07:45:43 +0000234static inline void tcg_gen_helper_0_4(void *func, TCGv arg1, TCGv arg2,
235 TCGv arg3, TCGv arg4)
236{
237 TCGv args[4];
bellarde8996ee2008-05-23 17:33:39 +0000238 TCGv t0;
blueswir1f8422f52008-02-24 07:45:43 +0000239 args[0] = arg1;
240 args[1] = arg2;
241 args[2] = arg3;
242 args[3] = arg4;
bellarde8996ee2008-05-23 17:33:39 +0000243 t0 = tcg_const_ptr((tcg_target_long)func);
blueswir1f8422f52008-02-24 07:45:43 +0000244 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000245 t0, TCG_HELPER_CALL_FLAGS,
blueswir1f8422f52008-02-24 07:45:43 +0000246 0, NULL, 4, args);
bellarde8996ee2008-05-23 17:33:39 +0000247 tcg_temp_free(t0);
blueswir1f8422f52008-02-24 07:45:43 +0000248}
249
250static inline void tcg_gen_helper_1_0(void *func, TCGv ret)
251{
bellarde8996ee2008-05-23 17:33:39 +0000252 TCGv t0;
253 t0 = tcg_const_ptr((tcg_target_long)func);
blueswir1f8422f52008-02-24 07:45:43 +0000254 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000255 t0, TCG_HELPER_CALL_FLAGS,
blueswir1f8422f52008-02-24 07:45:43 +0000256 1, &ret, 0, NULL);
bellarde8996ee2008-05-23 17:33:39 +0000257 tcg_temp_free(t0);
blueswir1f8422f52008-02-24 07:45:43 +0000258}
259
260static inline void tcg_gen_helper_1_1(void *func, TCGv ret, TCGv arg1)
261{
bellarde8996ee2008-05-23 17:33:39 +0000262 TCGv t0;
263 t0 = tcg_const_ptr((tcg_target_long)func);
blueswir1f8422f52008-02-24 07:45:43 +0000264 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000265 t0, TCG_HELPER_CALL_FLAGS,
blueswir1f8422f52008-02-24 07:45:43 +0000266 1, &ret, 1, &arg1);
bellarde8996ee2008-05-23 17:33:39 +0000267 tcg_temp_free(t0);
blueswir1f8422f52008-02-24 07:45:43 +0000268}
269
pbrookac56dd42008-02-03 19:56:33 +0000270static inline void tcg_gen_helper_1_2(void *func, TCGv ret,
271 TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000272{
pbrookac56dd42008-02-03 19:56:33 +0000273 TCGv args[2];
bellarde8996ee2008-05-23 17:33:39 +0000274 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000275 args[0] = arg1;
276 args[1] = arg2;
bellarde8996ee2008-05-23 17:33:39 +0000277 t0 = tcg_const_ptr((tcg_target_long)func);
bellardc896fe22008-02-01 10:05:41 +0000278 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000279 t0, TCG_HELPER_CALL_FLAGS,
bellardc896fe22008-02-01 10:05:41 +0000280 1, &ret, 2, args);
bellarde8996ee2008-05-23 17:33:39 +0000281 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000282}
283
pbrook6ddbc6e2008-03-31 03:46:33 +0000284static inline void tcg_gen_helper_1_3(void *func, TCGv ret,
285 TCGv arg1, TCGv arg2, TCGv arg3)
286{
287 TCGv args[3];
bellarde8996ee2008-05-23 17:33:39 +0000288 TCGv t0;
pbrook6ddbc6e2008-03-31 03:46:33 +0000289 args[0] = arg1;
290 args[1] = arg2;
291 args[2] = arg3;
bellarde8996ee2008-05-23 17:33:39 +0000292 t0 = tcg_const_ptr((tcg_target_long)func);
pbrook6ddbc6e2008-03-31 03:46:33 +0000293 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000294 t0, TCG_HELPER_CALL_FLAGS,
pbrook6ddbc6e2008-03-31 03:46:33 +0000295 1, &ret, 3, args);
bellarde8996ee2008-05-23 17:33:39 +0000296 tcg_temp_free(t0);
pbrook6ddbc6e2008-03-31 03:46:33 +0000297}
298
blueswir1f8422f52008-02-24 07:45:43 +0000299static inline void tcg_gen_helper_1_4(void *func, TCGv ret,
300 TCGv arg1, TCGv arg2, TCGv arg3,
301 TCGv arg4)
302{
303 TCGv args[4];
bellarde8996ee2008-05-23 17:33:39 +0000304 TCGv t0;
blueswir1f8422f52008-02-24 07:45:43 +0000305 args[0] = arg1;
306 args[1] = arg2;
307 args[2] = arg3;
308 args[3] = arg4;
bellarde8996ee2008-05-23 17:33:39 +0000309 t0 = tcg_const_ptr((tcg_target_long)func);
blueswir1f8422f52008-02-24 07:45:43 +0000310 tcg_gen_call(&tcg_ctx,
bellarde8996ee2008-05-23 17:33:39 +0000311 t0, TCG_HELPER_CALL_FLAGS,
blueswir1f8422f52008-02-24 07:45:43 +0000312 1, &ret, 4, args);
bellarde8996ee2008-05-23 17:33:39 +0000313 tcg_temp_free(t0);
blueswir1f8422f52008-02-24 07:45:43 +0000314}
315
bellardc896fe22008-02-01 10:05:41 +0000316/* 32 bit ops */
317
pbrookac56dd42008-02-03 19:56:33 +0000318static inline void tcg_gen_ld8u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000319{
pbrookac56dd42008-02-03 19:56:33 +0000320 tcg_gen_op3i(INDEX_op_ld8u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000321}
322
pbrookac56dd42008-02-03 19:56:33 +0000323static inline void tcg_gen_ld8s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000324{
pbrookac56dd42008-02-03 19:56:33 +0000325 tcg_gen_op3i(INDEX_op_ld8s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000326}
327
pbrookac56dd42008-02-03 19:56:33 +0000328static inline void tcg_gen_ld16u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000329{
pbrookac56dd42008-02-03 19:56:33 +0000330 tcg_gen_op3i(INDEX_op_ld16u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000331}
332
pbrookac56dd42008-02-03 19:56:33 +0000333static inline void tcg_gen_ld16s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000334{
pbrookac56dd42008-02-03 19:56:33 +0000335 tcg_gen_op3i(INDEX_op_ld16s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000336}
337
pbrookac56dd42008-02-03 19:56:33 +0000338static inline void tcg_gen_ld_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000339{
pbrookac56dd42008-02-03 19:56:33 +0000340 tcg_gen_op3i(INDEX_op_ld_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000341}
342
pbrookac56dd42008-02-03 19:56:33 +0000343static inline void tcg_gen_st8_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000344{
pbrookac56dd42008-02-03 19:56:33 +0000345 tcg_gen_op3i(INDEX_op_st8_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000346}
347
pbrookac56dd42008-02-03 19:56:33 +0000348static inline void tcg_gen_st16_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000349{
pbrookac56dd42008-02-03 19:56:33 +0000350 tcg_gen_op3i(INDEX_op_st16_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000351}
352
pbrookac56dd42008-02-03 19:56:33 +0000353static inline void tcg_gen_st_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000354{
pbrookac56dd42008-02-03 19:56:33 +0000355 tcg_gen_op3i(INDEX_op_st_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000356}
357
pbrookac56dd42008-02-03 19:56:33 +0000358static inline void tcg_gen_add_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000359{
360 tcg_gen_op3(INDEX_op_add_i32, ret, arg1, arg2);
361}
362
pbrookac56dd42008-02-03 19:56:33 +0000363static inline void tcg_gen_addi_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000364{
blueswir170894422008-02-20 18:01:23 +0000365 /* some cases can be optimized here */
366 if (arg2 == 0) {
367 tcg_gen_mov_i32(ret, arg1);
368 } else {
bellarde8996ee2008-05-23 17:33:39 +0000369 TCGv t0 = tcg_const_i32(arg2);
370 tcg_gen_add_i32(ret, arg1, t0);
371 tcg_temp_free(t0);
blueswir170894422008-02-20 18:01:23 +0000372 }
bellardc896fe22008-02-01 10:05:41 +0000373}
374
pbrookac56dd42008-02-03 19:56:33 +0000375static inline void tcg_gen_sub_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000376{
377 tcg_gen_op3(INDEX_op_sub_i32, ret, arg1, arg2);
378}
379
pbrookac56dd42008-02-03 19:56:33 +0000380static inline void tcg_gen_subi_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000381{
blueswir170894422008-02-20 18:01:23 +0000382 /* some cases can be optimized here */
383 if (arg2 == 0) {
384 tcg_gen_mov_i32(ret, arg1);
385 } else {
bellarde8996ee2008-05-23 17:33:39 +0000386 TCGv t0 = tcg_const_i32(arg2);
387 tcg_gen_sub_i32(ret, arg1, t0);
388 tcg_temp_free(t0);
blueswir170894422008-02-20 18:01:23 +0000389 }
bellardc896fe22008-02-01 10:05:41 +0000390}
391
pbrookac56dd42008-02-03 19:56:33 +0000392static inline void tcg_gen_and_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000393{
394 tcg_gen_op3(INDEX_op_and_i32, ret, arg1, arg2);
395}
396
pbrookac56dd42008-02-03 19:56:33 +0000397static inline void tcg_gen_andi_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000398{
399 /* some cases can be optimized here */
400 if (arg2 == 0) {
401 tcg_gen_movi_i32(ret, 0);
402 } else if (arg2 == 0xffffffff) {
403 tcg_gen_mov_i32(ret, arg1);
404 } else {
bellarde8996ee2008-05-23 17:33:39 +0000405 TCGv t0 = tcg_const_i32(arg2);
406 tcg_gen_and_i32(ret, arg1, t0);
407 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000408 }
409}
410
pbrookac56dd42008-02-03 19:56:33 +0000411static inline void tcg_gen_or_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000412{
413 tcg_gen_op3(INDEX_op_or_i32, ret, arg1, arg2);
414}
415
pbrookac56dd42008-02-03 19:56:33 +0000416static inline void tcg_gen_ori_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000417{
418 /* some cases can be optimized here */
419 if (arg2 == 0xffffffff) {
blueswir170894422008-02-20 18:01:23 +0000420 tcg_gen_movi_i32(ret, 0xffffffff);
bellardc896fe22008-02-01 10:05:41 +0000421 } else if (arg2 == 0) {
422 tcg_gen_mov_i32(ret, arg1);
423 } else {
bellarde8996ee2008-05-23 17:33:39 +0000424 TCGv t0 = tcg_const_i32(arg2);
425 tcg_gen_or_i32(ret, arg1, t0);
426 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000427 }
428}
429
pbrookac56dd42008-02-03 19:56:33 +0000430static inline void tcg_gen_xor_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000431{
432 tcg_gen_op3(INDEX_op_xor_i32, ret, arg1, arg2);
433}
434
pbrookac56dd42008-02-03 19:56:33 +0000435static inline void tcg_gen_xori_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000436{
437 /* some cases can be optimized here */
438 if (arg2 == 0) {
439 tcg_gen_mov_i32(ret, arg1);
440 } else {
bellarde8996ee2008-05-23 17:33:39 +0000441 TCGv t0 = tcg_const_i32(arg2);
442 tcg_gen_xor_i32(ret, arg1, t0);
443 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000444 }
445}
446
pbrookac56dd42008-02-03 19:56:33 +0000447static inline void tcg_gen_shl_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000448{
449 tcg_gen_op3(INDEX_op_shl_i32, ret, arg1, arg2);
450}
451
pbrookac56dd42008-02-03 19:56:33 +0000452static inline void tcg_gen_shli_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000453{
bellard34151a22008-05-22 13:25:14 +0000454 if (arg2 == 0) {
455 tcg_gen_mov_i32(ret, arg1);
456 } else {
bellarde8996ee2008-05-23 17:33:39 +0000457 TCGv t0 = tcg_const_i32(arg2);
458 tcg_gen_shl_i32(ret, arg1, t0);
459 tcg_temp_free(t0);
bellard34151a22008-05-22 13:25:14 +0000460 }
bellardc896fe22008-02-01 10:05:41 +0000461}
462
pbrookac56dd42008-02-03 19:56:33 +0000463static inline void tcg_gen_shr_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000464{
465 tcg_gen_op3(INDEX_op_shr_i32, ret, arg1, arg2);
466}
467
pbrookac56dd42008-02-03 19:56:33 +0000468static inline void tcg_gen_shri_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000469{
bellard34151a22008-05-22 13:25:14 +0000470 if (arg2 == 0) {
471 tcg_gen_mov_i32(ret, arg1);
472 } else {
bellarde8996ee2008-05-23 17:33:39 +0000473 TCGv t0 = tcg_const_i32(arg2);
474 tcg_gen_shr_i32(ret, arg1, t0);
475 tcg_temp_free(t0);
bellard34151a22008-05-22 13:25:14 +0000476 }
bellardc896fe22008-02-01 10:05:41 +0000477}
478
pbrookac56dd42008-02-03 19:56:33 +0000479static inline void tcg_gen_sar_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000480{
481 tcg_gen_op3(INDEX_op_sar_i32, ret, arg1, arg2);
482}
483
pbrookac56dd42008-02-03 19:56:33 +0000484static inline void tcg_gen_sari_i32(TCGv ret, TCGv arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000485{
bellard34151a22008-05-22 13:25:14 +0000486 if (arg2 == 0) {
487 tcg_gen_mov_i32(ret, arg1);
488 } else {
bellarde8996ee2008-05-23 17:33:39 +0000489 TCGv t0 = tcg_const_i32(arg2);
490 tcg_gen_sar_i32(ret, arg1, t0);
491 tcg_temp_free(t0);
bellard34151a22008-05-22 13:25:14 +0000492 }
bellardc896fe22008-02-01 10:05:41 +0000493}
494
pbrookac56dd42008-02-03 19:56:33 +0000495static inline void tcg_gen_brcond_i32(int cond, TCGv arg1, TCGv arg2,
bellardc896fe22008-02-01 10:05:41 +0000496 int label_index)
497{
pbrookac56dd42008-02-03 19:56:33 +0000498 tcg_gen_op4ii(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000499}
500
pbrookcb636692008-05-24 02:22:00 +0000501static inline void tcg_gen_brcondi_i32(int cond, TCGv arg1, int32_t arg2,
502 int label_index)
503{
504 TCGv t0 = tcg_const_i32(arg2);
505 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
506 tcg_temp_free(t0);
507}
508
pbrookac56dd42008-02-03 19:56:33 +0000509static inline void tcg_gen_mul_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000510{
511 tcg_gen_op3(INDEX_op_mul_i32, ret, arg1, arg2);
512}
513
thsf730fd22008-05-04 08:14:08 +0000514static inline void tcg_gen_muli_i32(TCGv ret, TCGv arg1, int32_t arg2)
515{
bellarde8996ee2008-05-23 17:33:39 +0000516 TCGv t0 = tcg_const_i32(arg2);
517 tcg_gen_mul_i32(ret, arg1, t0);
518 tcg_temp_free(t0);
thsf730fd22008-05-04 08:14:08 +0000519}
520
bellardc896fe22008-02-01 10:05:41 +0000521#ifdef TCG_TARGET_HAS_div_i32
pbrookac56dd42008-02-03 19:56:33 +0000522static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000523{
524 tcg_gen_op3(INDEX_op_div_i32, ret, arg1, arg2);
525}
526
pbrookac56dd42008-02-03 19:56:33 +0000527static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000528{
529 tcg_gen_op3(INDEX_op_rem_i32, ret, arg1, arg2);
530}
531
pbrookac56dd42008-02-03 19:56:33 +0000532static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000533{
534 tcg_gen_op3(INDEX_op_divu_i32, ret, arg1, arg2);
535}
536
pbrookac56dd42008-02-03 19:56:33 +0000537static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000538{
539 tcg_gen_op3(INDEX_op_remu_i32, ret, arg1, arg2);
540}
541#else
pbrookac56dd42008-02-03 19:56:33 +0000542static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000543{
pbrookac56dd42008-02-03 19:56:33 +0000544 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000545 t0 = tcg_temp_new(TCG_TYPE_I32);
546 tcg_gen_sari_i32(t0, arg1, 31);
547 tcg_gen_op5(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
bellarde8996ee2008-05-23 17:33:39 +0000548 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000549}
550
pbrookac56dd42008-02-03 19:56:33 +0000551static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000552{
pbrookac56dd42008-02-03 19:56:33 +0000553 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000554 t0 = tcg_temp_new(TCG_TYPE_I32);
555 tcg_gen_sari_i32(t0, arg1, 31);
556 tcg_gen_op5(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
bellarde8996ee2008-05-23 17:33:39 +0000557 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000558}
559
pbrookac56dd42008-02-03 19:56:33 +0000560static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000561{
pbrookac56dd42008-02-03 19:56:33 +0000562 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000563 t0 = tcg_temp_new(TCG_TYPE_I32);
564 tcg_gen_movi_i32(t0, 0);
565 tcg_gen_op5(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
bellarde8996ee2008-05-23 17:33:39 +0000566 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000567}
568
pbrookac56dd42008-02-03 19:56:33 +0000569static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000570{
pbrookac56dd42008-02-03 19:56:33 +0000571 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +0000572 t0 = tcg_temp_new(TCG_TYPE_I32);
573 tcg_gen_movi_i32(t0, 0);
574 tcg_gen_op5(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
bellarde8996ee2008-05-23 17:33:39 +0000575 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000576}
577#endif
578
579#if TCG_TARGET_REG_BITS == 32
580
pbrookac56dd42008-02-03 19:56:33 +0000581static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000582{
pbrook98156422008-05-10 18:43:02 +0000583 if (GET_TCGV(ret) != GET_TCGV(arg)) {
blueswir14d072722008-05-03 20:52:26 +0000584 tcg_gen_mov_i32(ret, arg);
585 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
586 }
bellardc896fe22008-02-01 10:05:41 +0000587}
588
pbrookac56dd42008-02-03 19:56:33 +0000589static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000590{
591 tcg_gen_movi_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +0000592 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
bellardc896fe22008-02-01 10:05:41 +0000593}
594
pbrookac56dd42008-02-03 19:56:33 +0000595static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000596{
597 tcg_gen_ld8u_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000598 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000599}
600
pbrookac56dd42008-02-03 19:56:33 +0000601static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000602{
603 tcg_gen_ld8s_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000604 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +0000605}
606
pbrookac56dd42008-02-03 19:56:33 +0000607static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000608{
609 tcg_gen_ld16u_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000610 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000611}
612
pbrookac56dd42008-02-03 19:56:33 +0000613static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000614{
615 tcg_gen_ld16s_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000616 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +0000617}
618
pbrookac56dd42008-02-03 19:56:33 +0000619static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000620{
621 tcg_gen_ld_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000622 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000623}
624
pbrookac56dd42008-02-03 19:56:33 +0000625static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000626{
627 tcg_gen_ld_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000628 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +0000629}
630
pbrookac56dd42008-02-03 19:56:33 +0000631static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000632{
633 /* since arg2 and ret have different types, they cannot be the
634 same temporary */
635#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000636 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000637 tcg_gen_ld_i32(ret, arg2, offset + 4);
638#else
639 tcg_gen_ld_i32(ret, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000640 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000641#endif
642}
643
pbrookac56dd42008-02-03 19:56:33 +0000644static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000645{
646 tcg_gen_st8_i32(arg1, arg2, offset);
647}
648
pbrookac56dd42008-02-03 19:56:33 +0000649static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000650{
651 tcg_gen_st16_i32(arg1, arg2, offset);
652}
653
pbrookac56dd42008-02-03 19:56:33 +0000654static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000655{
656 tcg_gen_st_i32(arg1, arg2, offset);
657}
658
pbrookac56dd42008-02-03 19:56:33 +0000659static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000660{
661#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000662 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000663 tcg_gen_st_i32(arg1, arg2, offset + 4);
664#else
665 tcg_gen_st_i32(arg1, arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000666 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000667#endif
668}
669
pbrookac56dd42008-02-03 19:56:33 +0000670static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000671{
pbrookac56dd42008-02-03 19:56:33 +0000672 tcg_gen_op6(INDEX_op_add2_i32, ret, TCGV_HIGH(ret),
673 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000674}
675
pbrookac56dd42008-02-03 19:56:33 +0000676static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000677{
bellarde8996ee2008-05-23 17:33:39 +0000678 TCGv t0 = tcg_const_i64(arg2);
679 tcg_gen_add_i64(ret, arg1, t0);
680 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000681}
682
pbrookac56dd42008-02-03 19:56:33 +0000683static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000684{
pbrookac56dd42008-02-03 19:56:33 +0000685 tcg_gen_op6(INDEX_op_sub2_i32, ret, TCGV_HIGH(ret),
686 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000687}
688
pbrookac56dd42008-02-03 19:56:33 +0000689static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000690{
bellarde8996ee2008-05-23 17:33:39 +0000691 TCGv t0 = tcg_const_i64(arg2);
692 tcg_gen_sub_i64(ret, arg1, t0);
693 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000694}
695
pbrookac56dd42008-02-03 19:56:33 +0000696static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000697{
698 tcg_gen_and_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000699 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000700}
701
pbrookac56dd42008-02-03 19:56:33 +0000702static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000703{
704 tcg_gen_andi_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000705 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000706}
707
pbrookac56dd42008-02-03 19:56:33 +0000708static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000709{
710 tcg_gen_or_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000711 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000712}
713
pbrookac56dd42008-02-03 19:56:33 +0000714static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000715{
716 tcg_gen_ori_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000717 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000718}
719
pbrookac56dd42008-02-03 19:56:33 +0000720static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000721{
722 tcg_gen_xor_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000723 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000724}
725
pbrookac56dd42008-02-03 19:56:33 +0000726static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000727{
728 tcg_gen_xori_i32(ret, arg1, arg2);
pbrookac56dd42008-02-03 19:56:33 +0000729 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000730}
731
732/* XXX: use generic code when basic block handling is OK or CPU
733 specific code (x86) */
pbrookac56dd42008-02-03 19:56:33 +0000734static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000735{
736 tcg_gen_helper_1_2(tcg_helper_shl_i64, ret, arg1, arg2);
737}
738
pbrookac56dd42008-02-03 19:56:33 +0000739static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000740{
741 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
742}
743
pbrookac56dd42008-02-03 19:56:33 +0000744static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000745{
746 tcg_gen_helper_1_2(tcg_helper_shr_i64, ret, arg1, arg2);
747}
748
pbrookac56dd42008-02-03 19:56:33 +0000749static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000750{
751 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
752}
753
pbrookac56dd42008-02-03 19:56:33 +0000754static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000755{
756 tcg_gen_helper_1_2(tcg_helper_sar_i64, ret, arg1, arg2);
757}
758
pbrookac56dd42008-02-03 19:56:33 +0000759static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000760{
761 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
762}
763
pbrookac56dd42008-02-03 19:56:33 +0000764static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2,
bellardc896fe22008-02-01 10:05:41 +0000765 int label_index)
766{
pbrookac56dd42008-02-03 19:56:33 +0000767 tcg_gen_op6ii(INDEX_op_brcond2_i32,
768 arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2),
769 cond, label_index);
bellardc896fe22008-02-01 10:05:41 +0000770}
771
pbrookac56dd42008-02-03 19:56:33 +0000772static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000773{
pbrookac56dd42008-02-03 19:56:33 +0000774 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +0000775
776 t0 = tcg_temp_new(TCG_TYPE_I64);
777 t1 = tcg_temp_new(TCG_TYPE_I32);
778
pbrookac56dd42008-02-03 19:56:33 +0000779 tcg_gen_op4(INDEX_op_mulu2_i32, t0, TCGV_HIGH(t0), arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000780
pbrookac56dd42008-02-03 19:56:33 +0000781 tcg_gen_mul_i32(t1, arg1, TCGV_HIGH(arg2));
782 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
783 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), arg2);
784 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
bellardc896fe22008-02-01 10:05:41 +0000785
786 tcg_gen_mov_i64(ret, t0);
bellarde8996ee2008-05-23 17:33:39 +0000787 tcg_temp_free(t0);
788 tcg_temp_free(t1);
bellardc896fe22008-02-01 10:05:41 +0000789}
790
thsf730fd22008-05-04 08:14:08 +0000791static inline void tcg_gen_muli_i64(TCGv ret, TCGv arg1, int64_t arg2)
792{
bellarde8996ee2008-05-23 17:33:39 +0000793 TCGv t0 = tcg_const_i64(arg2);
794 tcg_gen_mul_i64(ret, arg1, t0);
795 tcg_temp_free(t0);
thsf730fd22008-05-04 08:14:08 +0000796}
797
pbrookac56dd42008-02-03 19:56:33 +0000798static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000799{
800 tcg_gen_helper_1_2(tcg_helper_div_i64, ret, arg1, arg2);
801}
802
pbrookac56dd42008-02-03 19:56:33 +0000803static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000804{
805 tcg_gen_helper_1_2(tcg_helper_rem_i64, ret, arg1, arg2);
806}
807
pbrookac56dd42008-02-03 19:56:33 +0000808static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000809{
810 tcg_gen_helper_1_2(tcg_helper_divu_i64, ret, arg1, arg2);
811}
812
pbrookac56dd42008-02-03 19:56:33 +0000813static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000814{
815 tcg_gen_helper_1_2(tcg_helper_remu_i64, ret, arg1, arg2);
816}
817
818#else
819
pbrookac56dd42008-02-03 19:56:33 +0000820static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +0000821{
pbrook98156422008-05-10 18:43:02 +0000822 if (GET_TCGV(ret) != GET_TCGV(arg))
blueswir14d072722008-05-03 20:52:26 +0000823 tcg_gen_op2(INDEX_op_mov_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000824}
825
pbrookac56dd42008-02-03 19:56:33 +0000826static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000827{
pbrookac56dd42008-02-03 19:56:33 +0000828 tcg_gen_op2i(INDEX_op_movi_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000829}
830
pbrookac56dd42008-02-03 19:56:33 +0000831static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2,
832 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000833{
pbrookac56dd42008-02-03 19:56:33 +0000834 tcg_gen_op3i(INDEX_op_ld8u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000835}
836
pbrookac56dd42008-02-03 19:56:33 +0000837static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2,
838 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000839{
pbrookac56dd42008-02-03 19:56:33 +0000840 tcg_gen_op3i(INDEX_op_ld8s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000841}
842
pbrookac56dd42008-02-03 19:56:33 +0000843static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2,
844 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000845{
pbrookac56dd42008-02-03 19:56:33 +0000846 tcg_gen_op3i(INDEX_op_ld16u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000847}
848
pbrookac56dd42008-02-03 19:56:33 +0000849static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2,
850 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000851{
pbrookac56dd42008-02-03 19:56:33 +0000852 tcg_gen_op3i(INDEX_op_ld16s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000853}
854
pbrookac56dd42008-02-03 19:56:33 +0000855static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2,
856 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000857{
pbrookac56dd42008-02-03 19:56:33 +0000858 tcg_gen_op3i(INDEX_op_ld32u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000859}
860
pbrookac56dd42008-02-03 19:56:33 +0000861static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2,
862 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000863{
pbrookac56dd42008-02-03 19:56:33 +0000864 tcg_gen_op3i(INDEX_op_ld32s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000865}
866
pbrookac56dd42008-02-03 19:56:33 +0000867static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000868{
pbrookac56dd42008-02-03 19:56:33 +0000869 tcg_gen_op3i(INDEX_op_ld_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000870}
871
pbrookac56dd42008-02-03 19:56:33 +0000872static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2,
873 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000874{
pbrookac56dd42008-02-03 19:56:33 +0000875 tcg_gen_op3i(INDEX_op_st8_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000876}
877
pbrookac56dd42008-02-03 19:56:33 +0000878static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2,
879 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000880{
pbrookac56dd42008-02-03 19:56:33 +0000881 tcg_gen_op3i(INDEX_op_st16_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000882}
883
pbrookac56dd42008-02-03 19:56:33 +0000884static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2,
885 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000886{
pbrookac56dd42008-02-03 19:56:33 +0000887 tcg_gen_op3i(INDEX_op_st32_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000888}
889
pbrookac56dd42008-02-03 19:56:33 +0000890static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000891{
pbrookac56dd42008-02-03 19:56:33 +0000892 tcg_gen_op3i(INDEX_op_st_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000893}
894
pbrookac56dd42008-02-03 19:56:33 +0000895static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000896{
897 tcg_gen_op3(INDEX_op_add_i64, ret, arg1, arg2);
898}
899
pbrookac56dd42008-02-03 19:56:33 +0000900static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000901{
bellarde8996ee2008-05-23 17:33:39 +0000902 TCGv t0 = tcg_const_i64(arg2);
903 tcg_gen_add_i64(ret, arg1, t0);
904 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000905}
906
pbrookac56dd42008-02-03 19:56:33 +0000907static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000908{
909 tcg_gen_op3(INDEX_op_sub_i64, ret, arg1, arg2);
910}
911
pbrookac56dd42008-02-03 19:56:33 +0000912static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000913{
bellarde8996ee2008-05-23 17:33:39 +0000914 TCGv t0 = tcg_const_i64(arg2);
915 tcg_gen_sub_i64(ret, arg1, t0);
916 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000917}
918
pbrookac56dd42008-02-03 19:56:33 +0000919static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000920{
921 tcg_gen_op3(INDEX_op_and_i64, ret, arg1, arg2);
922}
923
pbrookac56dd42008-02-03 19:56:33 +0000924static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000925{
bellarde8996ee2008-05-23 17:33:39 +0000926 TCGv t0 = tcg_const_i64(arg2);
927 tcg_gen_and_i64(ret, arg1, t0);
928 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000929}
930
pbrookac56dd42008-02-03 19:56:33 +0000931static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000932{
933 tcg_gen_op3(INDEX_op_or_i64, ret, arg1, arg2);
934}
935
pbrookac56dd42008-02-03 19:56:33 +0000936static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000937{
bellarde8996ee2008-05-23 17:33:39 +0000938 TCGv t0 = tcg_const_i64(arg2);
939 tcg_gen_or_i64(ret, arg1, t0);
940 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000941}
942
pbrookac56dd42008-02-03 19:56:33 +0000943static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000944{
945 tcg_gen_op3(INDEX_op_xor_i64, ret, arg1, arg2);
946}
947
pbrookac56dd42008-02-03 19:56:33 +0000948static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000949{
bellarde8996ee2008-05-23 17:33:39 +0000950 TCGv t0 = tcg_const_i64(arg2);
951 tcg_gen_xor_i64(ret, arg1, t0);
952 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +0000953}
954
pbrookac56dd42008-02-03 19:56:33 +0000955static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000956{
957 tcg_gen_op3(INDEX_op_shl_i64, ret, arg1, arg2);
958}
959
pbrookac56dd42008-02-03 19:56:33 +0000960static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000961{
bellard34151a22008-05-22 13:25:14 +0000962 if (arg2 == 0) {
963 tcg_gen_mov_i64(ret, arg1);
964 } else {
bellarde8996ee2008-05-23 17:33:39 +0000965 TCGv t0 = tcg_const_i64(arg2);
966 tcg_gen_shl_i64(ret, arg1, t0);
967 tcg_temp_free(t0);
bellard34151a22008-05-22 13:25:14 +0000968 }
bellardc896fe22008-02-01 10:05:41 +0000969}
970
pbrookac56dd42008-02-03 19:56:33 +0000971static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000972{
973 tcg_gen_op3(INDEX_op_shr_i64, ret, arg1, arg2);
974}
975
pbrookac56dd42008-02-03 19:56:33 +0000976static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000977{
bellard34151a22008-05-22 13:25:14 +0000978 if (arg2 == 0) {
979 tcg_gen_mov_i64(ret, arg1);
980 } else {
bellarde8996ee2008-05-23 17:33:39 +0000981 TCGv t0 = tcg_const_i64(arg2);
982 tcg_gen_shr_i64(ret, arg1, t0);
983 tcg_temp_free(t0);
bellard34151a22008-05-22 13:25:14 +0000984 }
bellardc896fe22008-02-01 10:05:41 +0000985}
986
pbrookac56dd42008-02-03 19:56:33 +0000987static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +0000988{
989 tcg_gen_op3(INDEX_op_sar_i64, ret, arg1, arg2);
990}
991
pbrookac56dd42008-02-03 19:56:33 +0000992static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000993{
bellard34151a22008-05-22 13:25:14 +0000994 if (arg2 == 0) {
995 tcg_gen_mov_i64(ret, arg1);
996 } else {
bellarde8996ee2008-05-23 17:33:39 +0000997 TCGv t0 = tcg_const_i64(arg2);
998 tcg_gen_sar_i64(ret, arg1, t0);
999 tcg_temp_free(t0);
bellard34151a22008-05-22 13:25:14 +00001000 }
bellardc896fe22008-02-01 10:05:41 +00001001}
1002
pbrookac56dd42008-02-03 19:56:33 +00001003static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2,
bellardc896fe22008-02-01 10:05:41 +00001004 int label_index)
1005{
pbrookac56dd42008-02-03 19:56:33 +00001006 tcg_gen_op4ii(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
bellardc896fe22008-02-01 10:05:41 +00001007}
1008
pbrookac56dd42008-02-03 19:56:33 +00001009static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001010{
1011 tcg_gen_op3(INDEX_op_mul_i64, ret, arg1, arg2);
1012}
1013
thsf730fd22008-05-04 08:14:08 +00001014static inline void tcg_gen_muli_i64(TCGv ret, TCGv arg1, int64_t arg2)
1015{
bellarde8996ee2008-05-23 17:33:39 +00001016 TCGv t0 = tcg_const_i64(arg2);
1017 tcg_gen_mul_i64(ret, arg1, t0);
1018 tcg_temp_free(t0);
thsf730fd22008-05-04 08:14:08 +00001019}
1020
bellardc896fe22008-02-01 10:05:41 +00001021#ifdef TCG_TARGET_HAS_div_i64
pbrookac56dd42008-02-03 19:56:33 +00001022static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001023{
1024 tcg_gen_op3(INDEX_op_div_i64, ret, arg1, arg2);
1025}
1026
pbrookac56dd42008-02-03 19:56:33 +00001027static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001028{
1029 tcg_gen_op3(INDEX_op_rem_i64, ret, arg1, arg2);
1030}
1031
pbrookac56dd42008-02-03 19:56:33 +00001032static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001033{
1034 tcg_gen_op3(INDEX_op_divu_i64, ret, arg1, arg2);
1035}
1036
pbrookac56dd42008-02-03 19:56:33 +00001037static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001038{
1039 tcg_gen_op3(INDEX_op_remu_i64, ret, arg1, arg2);
1040}
1041#else
pbrookac56dd42008-02-03 19:56:33 +00001042static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001043{
pbrookac56dd42008-02-03 19:56:33 +00001044 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +00001045 t0 = tcg_temp_new(TCG_TYPE_I64);
1046 tcg_gen_sari_i64(t0, arg1, 63);
1047 tcg_gen_op5(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
bellarde8996ee2008-05-23 17:33:39 +00001048 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +00001049}
1050
pbrookac56dd42008-02-03 19:56:33 +00001051static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001052{
pbrookac56dd42008-02-03 19:56:33 +00001053 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +00001054 t0 = tcg_temp_new(TCG_TYPE_I64);
1055 tcg_gen_sari_i64(t0, arg1, 63);
1056 tcg_gen_op5(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
bellarde8996ee2008-05-23 17:33:39 +00001057 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +00001058}
1059
pbrookac56dd42008-02-03 19:56:33 +00001060static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001061{
pbrookac56dd42008-02-03 19:56:33 +00001062 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +00001063 t0 = tcg_temp_new(TCG_TYPE_I64);
1064 tcg_gen_movi_i64(t0, 0);
1065 tcg_gen_op5(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
bellarde8996ee2008-05-23 17:33:39 +00001066 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +00001067}
1068
pbrookac56dd42008-02-03 19:56:33 +00001069static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
bellardc896fe22008-02-01 10:05:41 +00001070{
pbrookac56dd42008-02-03 19:56:33 +00001071 TCGv t0;
bellardc896fe22008-02-01 10:05:41 +00001072 t0 = tcg_temp_new(TCG_TYPE_I64);
1073 tcg_gen_movi_i64(t0, 0);
1074 tcg_gen_op5(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
bellarde8996ee2008-05-23 17:33:39 +00001075 tcg_temp_free(t0);
bellardc896fe22008-02-01 10:05:41 +00001076}
1077#endif
1078
1079#endif
1080
pbrookcb636692008-05-24 02:22:00 +00001081static inline void tcg_gen_brcondi_i64(int cond, TCGv arg1, int64_t arg2,
1082 int label_index)
1083{
1084 TCGv t0 = tcg_const_i64(arg2);
1085 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1086 tcg_temp_free(t0);
1087}
1088
bellardc896fe22008-02-01 10:05:41 +00001089/***************************************/
1090/* optional operations */
1091
pbrookac56dd42008-02-03 19:56:33 +00001092static inline void tcg_gen_ext8s_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001093{
1094#ifdef TCG_TARGET_HAS_ext8s_i32
1095 tcg_gen_op2(INDEX_op_ext8s_i32, ret, arg);
1096#else
1097 tcg_gen_shli_i32(ret, arg, 24);
bellard5ff9d6a2008-02-04 00:37:54 +00001098 tcg_gen_sari_i32(ret, ret, 24);
bellardc896fe22008-02-01 10:05:41 +00001099#endif
1100}
1101
pbrookac56dd42008-02-03 19:56:33 +00001102static inline void tcg_gen_ext16s_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001103{
1104#ifdef TCG_TARGET_HAS_ext16s_i32
1105 tcg_gen_op2(INDEX_op_ext16s_i32, ret, arg);
1106#else
1107 tcg_gen_shli_i32(ret, arg, 16);
bellard5ff9d6a2008-02-04 00:37:54 +00001108 tcg_gen_sari_i32(ret, ret, 16);
bellardc896fe22008-02-01 10:05:41 +00001109#endif
1110}
1111
pbrook86831432008-05-11 12:22:01 +00001112/* These are currently just for convenience.
1113 We assume a target will recognise these automatically . */
1114static inline void tcg_gen_ext8u_i32(TCGv ret, TCGv arg)
1115{
1116 tcg_gen_andi_i32(ret, arg, 0xffu);
1117}
1118
1119static inline void tcg_gen_ext16u_i32(TCGv ret, TCGv arg)
1120{
1121 tcg_gen_andi_i32(ret, arg, 0xffffu);
1122}
1123
bellardc896fe22008-02-01 10:05:41 +00001124/* Note: we assume the two high bytes are set to zero */
pbrookac56dd42008-02-03 19:56:33 +00001125static inline void tcg_gen_bswap16_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001126{
1127#ifdef TCG_TARGET_HAS_bswap16_i32
1128 tcg_gen_op2(INDEX_op_bswap16_i32, ret, arg);
1129#else
pbrookac56dd42008-02-03 19:56:33 +00001130 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +00001131 t0 = tcg_temp_new(TCG_TYPE_I32);
1132 t1 = tcg_temp_new(TCG_TYPE_I32);
1133
1134 tcg_gen_shri_i32(t0, arg, 8);
1135 tcg_gen_andi_i32(t1, arg, 0x000000ff);
1136 tcg_gen_shli_i32(t1, t1, 8);
1137 tcg_gen_or_i32(ret, t0, t1);
bellarde8996ee2008-05-23 17:33:39 +00001138 tcg_temp_free(t0);
1139 tcg_temp_free(t1);
bellardc896fe22008-02-01 10:05:41 +00001140#endif
1141}
1142
pbrookac56dd42008-02-03 19:56:33 +00001143static inline void tcg_gen_bswap_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001144{
1145#ifdef TCG_TARGET_HAS_bswap_i32
1146 tcg_gen_op2(INDEX_op_bswap_i32, ret, arg);
1147#else
pbrookac56dd42008-02-03 19:56:33 +00001148 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +00001149 t0 = tcg_temp_new(TCG_TYPE_I32);
1150 t1 = tcg_temp_new(TCG_TYPE_I32);
1151
1152 tcg_gen_shli_i32(t0, arg, 24);
1153
1154 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1155 tcg_gen_shli_i32(t1, t1, 8);
1156 tcg_gen_or_i32(t0, t0, t1);
1157
1158 tcg_gen_shri_i32(t1, arg, 8);
1159 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1160 tcg_gen_or_i32(t0, t0, t1);
1161
1162 tcg_gen_shri_i32(t1, arg, 24);
1163 tcg_gen_or_i32(ret, t0, t1);
bellarde8996ee2008-05-23 17:33:39 +00001164 tcg_temp_free(t0);
1165 tcg_temp_free(t1);
bellardc896fe22008-02-01 10:05:41 +00001166#endif
1167}
1168
1169#if TCG_TARGET_REG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001170static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001171{
1172 tcg_gen_ext8s_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001173 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001174}
1175
pbrookac56dd42008-02-03 19:56:33 +00001176static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001177{
1178 tcg_gen_ext16s_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001179 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001180}
1181
pbrookac56dd42008-02-03 19:56:33 +00001182static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001183{
1184 tcg_gen_mov_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001185 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001186}
1187
pbrook86831432008-05-11 12:22:01 +00001188static inline void tcg_gen_ext8u_i64(TCGv ret, TCGv arg)
1189{
1190 tcg_gen_ext8u_i32(ret, arg);
1191 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1192}
1193
1194static inline void tcg_gen_ext16u_i64(TCGv ret, TCGv arg)
1195{
1196 tcg_gen_ext16u_i32(ret, arg);
1197 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1198}
1199
1200static inline void tcg_gen_ext32u_i64(TCGv ret, TCGv arg)
1201{
1202 tcg_gen_mov_i32(ret, arg);
1203 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1204}
1205
pbrookac56dd42008-02-03 19:56:33 +00001206static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001207{
1208 tcg_gen_mov_i32(ret, arg);
1209}
1210
pbrookac56dd42008-02-03 19:56:33 +00001211static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001212{
1213 tcg_gen_mov_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001214 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001215}
1216
pbrookac56dd42008-02-03 19:56:33 +00001217static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001218{
1219 tcg_gen_mov_i32(ret, arg);
pbrookac56dd42008-02-03 19:56:33 +00001220 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001221}
1222
pbrookac56dd42008-02-03 19:56:33 +00001223static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001224{
pbrookac56dd42008-02-03 19:56:33 +00001225 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +00001226 t0 = tcg_temp_new(TCG_TYPE_I32);
1227 t1 = tcg_temp_new(TCG_TYPE_I32);
1228
1229 tcg_gen_bswap_i32(t0, arg);
pbrookac56dd42008-02-03 19:56:33 +00001230 tcg_gen_bswap_i32(t1, TCGV_HIGH(arg));
bellardc896fe22008-02-01 10:05:41 +00001231 tcg_gen_mov_i32(ret, t1);
pbrookac56dd42008-02-03 19:56:33 +00001232 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
bellarde8996ee2008-05-23 17:33:39 +00001233 tcg_temp_free(t0);
1234 tcg_temp_free(t1);
bellardc896fe22008-02-01 10:05:41 +00001235}
1236#else
1237
pbrookac56dd42008-02-03 19:56:33 +00001238static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001239{
1240#ifdef TCG_TARGET_HAS_ext8s_i64
1241 tcg_gen_op2(INDEX_op_ext8s_i64, ret, arg);
1242#else
1243 tcg_gen_shli_i64(ret, arg, 56);
bellard5ff9d6a2008-02-04 00:37:54 +00001244 tcg_gen_sari_i64(ret, ret, 56);
bellardc896fe22008-02-01 10:05:41 +00001245#endif
1246}
1247
pbrookac56dd42008-02-03 19:56:33 +00001248static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001249{
1250#ifdef TCG_TARGET_HAS_ext16s_i64
1251 tcg_gen_op2(INDEX_op_ext16s_i64, ret, arg);
1252#else
1253 tcg_gen_shli_i64(ret, arg, 48);
bellard5ff9d6a2008-02-04 00:37:54 +00001254 tcg_gen_sari_i64(ret, ret, 48);
bellardc896fe22008-02-01 10:05:41 +00001255#endif
1256}
1257
pbrookac56dd42008-02-03 19:56:33 +00001258static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001259{
1260#ifdef TCG_TARGET_HAS_ext32s_i64
1261 tcg_gen_op2(INDEX_op_ext32s_i64, ret, arg);
1262#else
1263 tcg_gen_shli_i64(ret, arg, 32);
bellard5ff9d6a2008-02-04 00:37:54 +00001264 tcg_gen_sari_i64(ret, ret, 32);
bellardc896fe22008-02-01 10:05:41 +00001265#endif
1266}
1267
pbrook86831432008-05-11 12:22:01 +00001268static inline void tcg_gen_ext8u_i64(TCGv ret, TCGv arg)
1269{
1270 tcg_gen_andi_i64(ret, arg, 0xffu);
1271}
1272
1273static inline void tcg_gen_ext16u_i64(TCGv ret, TCGv arg)
1274{
1275 tcg_gen_andi_i64(ret, arg, 0xffffu);
1276}
1277
1278static inline void tcg_gen_ext32u_i64(TCGv ret, TCGv arg)
1279{
1280 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1281}
1282
bellardc896fe22008-02-01 10:05:41 +00001283/* Note: we assume the target supports move between 32 and 64 bit
pbrookac56dd42008-02-03 19:56:33 +00001284 registers. This will probably break MIPS64 targets. */
1285static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001286{
1287 tcg_gen_mov_i32(ret, arg);
1288}
1289
1290/* Note: we assume the target supports move between 32 and 64 bit
1291 registers */
pbrookac56dd42008-02-03 19:56:33 +00001292static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001293{
pbrook86831432008-05-11 12:22:01 +00001294 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
bellardc896fe22008-02-01 10:05:41 +00001295}
1296
1297/* Note: we assume the target supports move between 32 and 64 bit
1298 registers */
pbrookac56dd42008-02-03 19:56:33 +00001299static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001300{
1301 tcg_gen_ext32s_i64(ret, arg);
1302}
1303
pbrookac56dd42008-02-03 19:56:33 +00001304static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
bellardc896fe22008-02-01 10:05:41 +00001305{
1306#ifdef TCG_TARGET_HAS_bswap_i64
1307 tcg_gen_op2(INDEX_op_bswap_i64, ret, arg);
1308#else
pbrookac56dd42008-02-03 19:56:33 +00001309 TCGv t0, t1;
bellardc896fe22008-02-01 10:05:41 +00001310 t0 = tcg_temp_new(TCG_TYPE_I32);
1311 t1 = tcg_temp_new(TCG_TYPE_I32);
1312
1313 tcg_gen_shli_i64(t0, arg, 56);
1314
1315 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1316 tcg_gen_shli_i64(t1, t1, 40);
1317 tcg_gen_or_i64(t0, t0, t1);
1318
1319 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1320 tcg_gen_shli_i64(t1, t1, 24);
1321 tcg_gen_or_i64(t0, t0, t1);
1322
1323 tcg_gen_andi_i64(t1, arg, 0xff000000);
1324 tcg_gen_shli_i64(t1, t1, 8);
1325 tcg_gen_or_i64(t0, t0, t1);
1326
1327 tcg_gen_shri_i64(t1, arg, 8);
1328 tcg_gen_andi_i64(t1, t1, 0xff000000);
1329 tcg_gen_or_i64(t0, t0, t1);
1330
1331 tcg_gen_shri_i64(t1, arg, 24);
1332 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1333 tcg_gen_or_i64(t0, t0, t1);
1334
1335 tcg_gen_shri_i64(t1, arg, 40);
1336 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1337 tcg_gen_or_i64(t0, t0, t1);
1338
1339 tcg_gen_shri_i64(t1, arg, 56);
1340 tcg_gen_or_i64(ret, t0, t1);
bellarde8996ee2008-05-23 17:33:39 +00001341 tcg_temp_free(t0);
1342 tcg_temp_free(t1);
bellardc896fe22008-02-01 10:05:41 +00001343#endif
1344}
1345
1346#endif
1347
pbrook390efc52008-05-11 14:35:37 +00001348static inline void tcg_gen_neg_i32(TCGv ret, TCGv arg)
1349{
1350#ifdef TCG_TARGET_HAS_neg_i32
1351 tcg_gen_op2(INDEX_op_neg_i32, ret, arg);
1352#else
bellarde8996ee2008-05-23 17:33:39 +00001353 TCGv t0 = tcg_const_i32(0);
1354 tcg_gen_sub_i32(ret, t0, arg);
1355 tcg_temp_free(t0);
pbrook390efc52008-05-11 14:35:37 +00001356#endif
1357}
1358
1359static inline void tcg_gen_neg_i64(TCGv ret, TCGv arg)
1360{
1361#ifdef TCG_TARGET_HAS_neg_i64
1362 tcg_gen_op2(INDEX_op_neg_i64, ret, arg);
1363#else
bellarde8996ee2008-05-23 17:33:39 +00001364 TCGv t0 = tcg_const_i64(0);
1365 tcg_gen_sub_i64(ret, t0, arg);
1366 tcg_temp_free(t0);
pbrook390efc52008-05-11 14:35:37 +00001367#endif
1368}
1369
bellard0b6ce4c2008-05-17 12:40:44 +00001370static inline void tcg_gen_not_i32(TCGv ret, TCGv arg)
1371{
bellarde8996ee2008-05-23 17:33:39 +00001372 tcg_gen_xori_i32(ret, arg, -1);
bellard0b6ce4c2008-05-17 12:40:44 +00001373}
1374
1375static inline void tcg_gen_not_i64(TCGv ret, TCGv arg)
1376{
bellarde8996ee2008-05-23 17:33:39 +00001377 tcg_gen_xori_i64(ret, arg, -1);
bellard0b6ce4c2008-05-17 12:40:44 +00001378}
bellard5ff9d6a2008-02-04 00:37:54 +00001379
1380static inline void tcg_gen_discard_i32(TCGv arg)
1381{
1382 tcg_gen_op1(INDEX_op_discard, arg);
1383}
1384
1385#if TCG_TARGET_REG_BITS == 32
1386static inline void tcg_gen_discard_i64(TCGv arg)
1387{
1388 tcg_gen_discard_i32(arg);
1389 tcg_gen_discard_i32(TCGV_HIGH(arg));
1390}
1391#else
1392static inline void tcg_gen_discard_i64(TCGv arg)
1393{
1394 tcg_gen_op1(INDEX_op_discard, arg);
1395}
1396#endif
1397
bellardc896fe22008-02-01 10:05:41 +00001398/***************************************/
bellardc896fe22008-02-01 10:05:41 +00001399/* QEMU specific operations. Their type depend on the QEMU CPU
1400 type. */
1401#ifndef TARGET_LONG_BITS
1402#error must include QEMU headers
1403#endif
1404
bellard7e4597d2008-05-22 16:56:05 +00001405/* debug info: write the PC of the corresponding QEMU CPU instruction */
1406static inline void tcg_gen_debug_insn_start(uint64_t pc)
1407{
1408 /* XXX: must really use a 32 bit size for TCGArg in all cases */
1409#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
pbrookbcb01262008-05-24 02:24:25 +00001410 tcg_gen_op2ii(INDEX_op_debug_insn_start,
1411 (uint32_t)(pc), (uint32_t)(pc >> 32));
bellard7e4597d2008-05-22 16:56:05 +00001412#else
1413 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
1414#endif
1415}
1416
bellardc896fe22008-02-01 10:05:41 +00001417static inline void tcg_gen_exit_tb(tcg_target_long val)
1418{
pbrookac56dd42008-02-03 19:56:33 +00001419 tcg_gen_op1i(INDEX_op_exit_tb, val);
bellardc896fe22008-02-01 10:05:41 +00001420}
1421
1422static inline void tcg_gen_goto_tb(int idx)
1423{
pbrookac56dd42008-02-03 19:56:33 +00001424 tcg_gen_op1i(INDEX_op_goto_tb, idx);
bellardc896fe22008-02-01 10:05:41 +00001425}
1426
1427#if TCG_TARGET_REG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001428static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001429{
1430#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001431 tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001432#else
pbrookac56dd42008-02-03 19:56:33 +00001433 tcg_gen_op4i(INDEX_op_qemu_ld8u, ret, addr, TCGV_HIGH(addr), mem_index);
1434 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001435#endif
1436}
1437
pbrookac56dd42008-02-03 19:56:33 +00001438static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001439{
1440#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001441 tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001442#else
pbrookac56dd42008-02-03 19:56:33 +00001443 tcg_gen_op4i(INDEX_op_qemu_ld8s, ret, addr, TCGV_HIGH(addr), mem_index);
pbrook21fc3cf2008-03-04 23:52:47 +00001444 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001445#endif
1446}
1447
pbrookac56dd42008-02-03 19:56:33 +00001448static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001449{
1450#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001451 tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001452#else
pbrookac56dd42008-02-03 19:56:33 +00001453 tcg_gen_op4i(INDEX_op_qemu_ld16u, ret, addr, TCGV_HIGH(addr), mem_index);
1454 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001455#endif
1456}
1457
pbrookac56dd42008-02-03 19:56:33 +00001458static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001459{
1460#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001461 tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001462#else
pbrookac56dd42008-02-03 19:56:33 +00001463 tcg_gen_op4i(INDEX_op_qemu_ld16s, ret, addr, TCGV_HIGH(addr), mem_index);
pbrook21fc3cf2008-03-04 23:52:47 +00001464 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001465#endif
1466}
1467
pbrookac56dd42008-02-03 19:56:33 +00001468static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001469{
1470#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001471 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001472#else
pbrookac56dd42008-02-03 19:56:33 +00001473 tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
1474 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001475#endif
1476}
1477
pbrookac56dd42008-02-03 19:56:33 +00001478static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001479{
1480#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001481 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001482#else
pbrookac56dd42008-02-03 19:56:33 +00001483 tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
1484 tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
bellardc896fe22008-02-01 10:05:41 +00001485#endif
1486}
1487
pbrookac56dd42008-02-03 19:56:33 +00001488static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001489{
1490#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001491 tcg_gen_op4i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret), addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001492#else
pbrookac56dd42008-02-03 19:56:33 +00001493 tcg_gen_op5i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret),
1494 addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001495#endif
1496}
1497
pbrookac56dd42008-02-03 19:56:33 +00001498static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001499{
1500#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001501 tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001502#else
pbrookac56dd42008-02-03 19:56:33 +00001503 tcg_gen_op4i(INDEX_op_qemu_st8, arg, addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001504#endif
1505}
1506
pbrookac56dd42008-02-03 19:56:33 +00001507static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001508{
1509#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001510 tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001511#else
pbrookac56dd42008-02-03 19:56:33 +00001512 tcg_gen_op4i(INDEX_op_qemu_st16, arg, addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001513#endif
1514}
1515
pbrookac56dd42008-02-03 19:56:33 +00001516static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001517{
1518#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001519 tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001520#else
pbrookac56dd42008-02-03 19:56:33 +00001521 tcg_gen_op4i(INDEX_op_qemu_st32, arg, addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001522#endif
1523}
1524
pbrookac56dd42008-02-03 19:56:33 +00001525static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001526{
1527#if TARGET_LONG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00001528 tcg_gen_op4i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg), addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001529#else
pbrookac56dd42008-02-03 19:56:33 +00001530 tcg_gen_op5i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg),
1531 addr, TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00001532#endif
1533}
1534
blueswir156b8f562008-02-25 18:29:19 +00001535#define tcg_gen_ld_ptr tcg_gen_ld_i32
blueswir1a768e4b2008-03-16 19:16:37 +00001536#define tcg_gen_discard_ptr tcg_gen_discard_i32
blueswir1f8422f52008-02-24 07:45:43 +00001537
bellardc896fe22008-02-01 10:05:41 +00001538#else /* TCG_TARGET_REG_BITS == 32 */
1539
pbrookac56dd42008-02-03 19:56:33 +00001540static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001541{
pbrookac56dd42008-02-03 19:56:33 +00001542 tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001543}
1544
pbrookac56dd42008-02-03 19:56:33 +00001545static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001546{
pbrookac56dd42008-02-03 19:56:33 +00001547 tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001548}
1549
pbrookac56dd42008-02-03 19:56:33 +00001550static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001551{
pbrookac56dd42008-02-03 19:56:33 +00001552 tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001553}
1554
pbrookac56dd42008-02-03 19:56:33 +00001555static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001556{
pbrookac56dd42008-02-03 19:56:33 +00001557 tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001558}
1559
pbrookac56dd42008-02-03 19:56:33 +00001560static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001561{
pbrookac56dd42008-02-03 19:56:33 +00001562 tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001563}
1564
pbrookac56dd42008-02-03 19:56:33 +00001565static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001566{
pbrookac56dd42008-02-03 19:56:33 +00001567 tcg_gen_op3i(INDEX_op_qemu_ld32s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001568}
1569
pbrookac56dd42008-02-03 19:56:33 +00001570static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001571{
pbrookac56dd42008-02-03 19:56:33 +00001572 tcg_gen_op3i(INDEX_op_qemu_ld64, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001573}
1574
pbrookac56dd42008-02-03 19:56:33 +00001575static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001576{
pbrookac56dd42008-02-03 19:56:33 +00001577 tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001578}
1579
pbrookac56dd42008-02-03 19:56:33 +00001580static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001581{
pbrookac56dd42008-02-03 19:56:33 +00001582 tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001583}
1584
pbrookac56dd42008-02-03 19:56:33 +00001585static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001586{
pbrookac56dd42008-02-03 19:56:33 +00001587 tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001588}
1589
pbrookac56dd42008-02-03 19:56:33 +00001590static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00001591{
pbrookac56dd42008-02-03 19:56:33 +00001592 tcg_gen_op3i(INDEX_op_qemu_st64, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00001593}
1594
blueswir156b8f562008-02-25 18:29:19 +00001595#define tcg_gen_ld_ptr tcg_gen_ld_i64
blueswir1a768e4b2008-03-16 19:16:37 +00001596#define tcg_gen_discard_ptr tcg_gen_discard_i64
blueswir1f8422f52008-02-24 07:45:43 +00001597
bellardc896fe22008-02-01 10:05:41 +00001598#endif /* TCG_TARGET_REG_BITS != 32 */
blueswir1f8422f52008-02-24 07:45:43 +00001599
1600#if TARGET_LONG_BITS == 64
1601#define TCG_TYPE_TL TCG_TYPE_I64
1602#define tcg_gen_movi_tl tcg_gen_movi_i64
1603#define tcg_gen_mov_tl tcg_gen_mov_i64
1604#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
1605#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
1606#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
1607#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
1608#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
1609#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
1610#define tcg_gen_ld_tl tcg_gen_ld_i64
1611#define tcg_gen_st8_tl tcg_gen_st8_i64
1612#define tcg_gen_st16_tl tcg_gen_st16_i64
1613#define tcg_gen_st32_tl tcg_gen_st32_i64
1614#define tcg_gen_st_tl tcg_gen_st_i64
1615#define tcg_gen_add_tl tcg_gen_add_i64
1616#define tcg_gen_addi_tl tcg_gen_addi_i64
1617#define tcg_gen_sub_tl tcg_gen_sub_i64
pbrook390efc52008-05-11 14:35:37 +00001618#define tcg_gen_neg_tl tcg_gen_neg_i64
blueswir1f8422f52008-02-24 07:45:43 +00001619#define tcg_gen_subi_tl tcg_gen_subi_i64
1620#define tcg_gen_and_tl tcg_gen_and_i64
1621#define tcg_gen_andi_tl tcg_gen_andi_i64
1622#define tcg_gen_or_tl tcg_gen_or_i64
1623#define tcg_gen_ori_tl tcg_gen_ori_i64
1624#define tcg_gen_xor_tl tcg_gen_xor_i64
1625#define tcg_gen_xori_tl tcg_gen_xori_i64
bellard0b6ce4c2008-05-17 12:40:44 +00001626#define tcg_gen_not_tl tcg_gen_not_i64
blueswir1f8422f52008-02-24 07:45:43 +00001627#define tcg_gen_shl_tl tcg_gen_shl_i64
1628#define tcg_gen_shli_tl tcg_gen_shli_i64
1629#define tcg_gen_shr_tl tcg_gen_shr_i64
1630#define tcg_gen_shri_tl tcg_gen_shri_i64
1631#define tcg_gen_sar_tl tcg_gen_sar_i64
1632#define tcg_gen_sari_tl tcg_gen_sari_i64
blueswir10cf767d2008-03-02 18:20:59 +00001633#define tcg_gen_brcond_tl tcg_gen_brcond_i64
pbrookcb636692008-05-24 02:22:00 +00001634#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
thsf730fd22008-05-04 08:14:08 +00001635#define tcg_gen_mul_tl tcg_gen_mul_i64
1636#define tcg_gen_muli_tl tcg_gen_muli_i64
blueswir1a768e4b2008-03-16 19:16:37 +00001637#define tcg_gen_discard_tl tcg_gen_discard_i64
blueswir1e4290732008-03-22 08:39:04 +00001638#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
1639#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
1640#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
1641#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
1642#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
1643#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
bellard0b6ce4c2008-05-17 12:40:44 +00001644#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
1645#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
1646#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
1647#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
1648#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
1649#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
blueswir1a98824a2008-03-13 20:46:42 +00001650#define tcg_const_tl tcg_const_i64
blueswir1f8422f52008-02-24 07:45:43 +00001651#else
1652#define TCG_TYPE_TL TCG_TYPE_I32
1653#define tcg_gen_movi_tl tcg_gen_movi_i32
1654#define tcg_gen_mov_tl tcg_gen_mov_i32
1655#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
1656#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
1657#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
1658#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
1659#define tcg_gen_ld32u_tl tcg_gen_ld_i32
1660#define tcg_gen_ld32s_tl tcg_gen_ld_i32
1661#define tcg_gen_ld_tl tcg_gen_ld_i32
1662#define tcg_gen_st8_tl tcg_gen_st8_i32
1663#define tcg_gen_st16_tl tcg_gen_st16_i32
1664#define tcg_gen_st32_tl tcg_gen_st_i32
1665#define tcg_gen_st_tl tcg_gen_st_i32
1666#define tcg_gen_add_tl tcg_gen_add_i32
1667#define tcg_gen_addi_tl tcg_gen_addi_i32
1668#define tcg_gen_sub_tl tcg_gen_sub_i32
pbrook390efc52008-05-11 14:35:37 +00001669#define tcg_gen_neg_tl tcg_gen_neg_i32
blueswir1f8422f52008-02-24 07:45:43 +00001670#define tcg_gen_subi_tl tcg_gen_subi_i32
1671#define tcg_gen_and_tl tcg_gen_and_i32
1672#define tcg_gen_andi_tl tcg_gen_andi_i32
1673#define tcg_gen_or_tl tcg_gen_or_i32
1674#define tcg_gen_ori_tl tcg_gen_ori_i32
1675#define tcg_gen_xor_tl tcg_gen_xor_i32
1676#define tcg_gen_xori_tl tcg_gen_xori_i32
bellard0b6ce4c2008-05-17 12:40:44 +00001677#define tcg_gen_not_tl tcg_gen_not_i32
blueswir1f8422f52008-02-24 07:45:43 +00001678#define tcg_gen_shl_tl tcg_gen_shl_i32
1679#define tcg_gen_shli_tl tcg_gen_shli_i32
1680#define tcg_gen_shr_tl tcg_gen_shr_i32
1681#define tcg_gen_shri_tl tcg_gen_shri_i32
1682#define tcg_gen_sar_tl tcg_gen_sar_i32
1683#define tcg_gen_sari_tl tcg_gen_sari_i32
blueswir10cf767d2008-03-02 18:20:59 +00001684#define tcg_gen_brcond_tl tcg_gen_brcond_i32
pbrookcb636692008-05-24 02:22:00 +00001685#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
thsf730fd22008-05-04 08:14:08 +00001686#define tcg_gen_mul_tl tcg_gen_mul_i32
1687#define tcg_gen_muli_tl tcg_gen_muli_i32
blueswir1a768e4b2008-03-16 19:16:37 +00001688#define tcg_gen_discard_tl tcg_gen_discard_i32
blueswir1e4290732008-03-22 08:39:04 +00001689#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
1690#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
1691#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
1692#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
1693#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
1694#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
bellard0b6ce4c2008-05-17 12:40:44 +00001695#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
1696#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
1697#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
1698#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
1699#define tcg_gen_ext32u_tl tcg_gen_mov_i32
1700#define tcg_gen_ext32s_tl tcg_gen_mov_i32
blueswir1a98824a2008-03-13 20:46:42 +00001701#define tcg_const_tl tcg_const_i32
blueswir1f8422f52008-02-24 07:45:43 +00001702#endif
pbrook6ddbc6e2008-03-31 03:46:33 +00001703
1704#if TCG_TARGET_REG_BITS == 32
ths48d38ca2008-05-18 22:50:49 +00001705#define tcg_gen_add_ptr tcg_gen_add_i32
pbrook6ddbc6e2008-03-31 03:46:33 +00001706#define tcg_gen_addi_ptr tcg_gen_addi_i32
ths48d38ca2008-05-18 22:50:49 +00001707#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
pbrook6ddbc6e2008-03-31 03:46:33 +00001708#else /* TCG_TARGET_REG_BITS == 32 */
ths48d38ca2008-05-18 22:50:49 +00001709#define tcg_gen_add_ptr tcg_gen_add_i64
pbrook6ddbc6e2008-03-31 03:46:33 +00001710#define tcg_gen_addi_ptr tcg_gen_addi_i64
ths48d38ca2008-05-18 22:50:49 +00001711#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
pbrook6ddbc6e2008-03-31 03:46:33 +00001712#endif /* TCG_TARGET_REG_BITS != 32 */
1713