]>
Commit | Line | Data |
---|---|---|
c896fe29 FB |
1 | /* |
2 | * Tiny Code Generator for QEMU | |
3 | * | |
4 | * Copyright (c) 2008 Fabrice Bellard | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | #include "tcg.h" | |
25 | ||
bf6247fb | 26 | #ifdef CONFIG_DYNGEN_OP |
c896fe29 FB |
27 | /* legacy dyngen operations */ |
28 | #include "gen-op.h" | |
cf2be984 | 29 | #endif |
c896fe29 FB |
30 | |
31 | int gen_new_label(void); | |
32 | ||
ac56dd48 | 33 | static inline void tcg_gen_op1(int opc, TCGv arg1) |
c896fe29 FB |
34 | { |
35 | *gen_opc_ptr++ = opc; | |
ac56dd48 | 36 | *gen_opparam_ptr++ = GET_TCGV(arg1); |
c896fe29 FB |
37 | } |
38 | ||
ac56dd48 | 39 | static inline void tcg_gen_op1i(int opc, TCGArg arg1) |
c896fe29 FB |
40 | { |
41 | *gen_opc_ptr++ = opc; | |
42 | *gen_opparam_ptr++ = arg1; | |
c896fe29 FB |
43 | } |
44 | ||
ac56dd48 | 45 | static inline void tcg_gen_op2(int opc, TCGv arg1, TCGv arg2) |
c896fe29 FB |
46 | { |
47 | *gen_opc_ptr++ = opc; | |
ac56dd48 PB |
48 | *gen_opparam_ptr++ = GET_TCGV(arg1); |
49 | *gen_opparam_ptr++ = GET_TCGV(arg2); | |
c896fe29 FB |
50 | } |
51 | ||
ac56dd48 | 52 | static inline void tcg_gen_op2i(int opc, TCGv arg1, TCGArg arg2) |
c896fe29 FB |
53 | { |
54 | *gen_opc_ptr++ = opc; | |
ac56dd48 | 55 | *gen_opparam_ptr++ = GET_TCGV(arg1); |
c896fe29 | 56 | *gen_opparam_ptr++ = arg2; |
ac56dd48 PB |
57 | } |
58 | ||
59 | static inline void tcg_gen_op3(int opc, TCGv arg1, TCGv arg2, TCGv arg3) | |
60 | { | |
61 | *gen_opc_ptr++ = opc; | |
62 | *gen_opparam_ptr++ = GET_TCGV(arg1); | |
63 | *gen_opparam_ptr++ = GET_TCGV(arg2); | |
64 | *gen_opparam_ptr++ = GET_TCGV(arg3); | |
65 | } | |
66 | ||
67 | static 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); | |
c896fe29 | 72 | *gen_opparam_ptr++ = arg3; |
ac56dd48 PB |
73 | } |
74 | ||
75 | static inline void tcg_gen_op4(int opc, TCGv arg1, TCGv arg2, TCGv arg3, | |
76 | TCGv arg4) | |
77 | { | |
78 | *gen_opc_ptr++ = opc; | |
79 | *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 | ||
85 | static 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); | |
c896fe29 FB |
92 | *gen_opparam_ptr++ = arg4; |
93 | } | |
94 | ||
ac56dd48 PB |
95 | static inline void tcg_gen_op4ii(int opc, TCGv arg1, TCGv arg2, TCGArg arg3, |
96 | TCGArg arg4) | |
c896fe29 FB |
97 | { |
98 | *gen_opc_ptr++ = opc; | |
ac56dd48 PB |
99 | *gen_opparam_ptr++ = GET_TCGV(arg1); |
100 | *gen_opparam_ptr++ = GET_TCGV(arg2); | |
c896fe29 FB |
101 | *gen_opparam_ptr++ = arg3; |
102 | *gen_opparam_ptr++ = arg4; | |
ac56dd48 PB |
103 | } |
104 | ||
105 | static inline void tcg_gen_op5(int opc, TCGv arg1, TCGv arg2, | |
106 | TCGv arg3, TCGv arg4, | |
107 | TCGv arg5) | |
108 | { | |
109 | *gen_opc_ptr++ = opc; | |
110 | *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 | ||
117 | static 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); | |
c896fe29 FB |
126 | *gen_opparam_ptr++ = arg5; |
127 | } | |
128 | ||
ac56dd48 PB |
129 | static inline void tcg_gen_op6(int opc, TCGv arg1, TCGv arg2, |
130 | TCGv arg3, TCGv arg4, | |
131 | TCGv arg5, TCGv arg6) | |
c896fe29 FB |
132 | { |
133 | *gen_opc_ptr++ = opc; | |
ac56dd48 PB |
134 | *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 | ||
142 | static 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); | |
c896fe29 FB |
151 | *gen_opparam_ptr++ = arg5; |
152 | *gen_opparam_ptr++ = arg6; | |
153 | } | |
154 | ||
155 | static inline void gen_set_label(int n) | |
156 | { | |
ac56dd48 | 157 | tcg_gen_op1i(INDEX_op_set_label, n); |
c896fe29 FB |
158 | } |
159 | ||
fb50d413 BS |
160 | static inline void tcg_gen_br(int label) |
161 | { | |
162 | tcg_gen_op1i(INDEX_op_br, label); | |
163 | } | |
164 | ||
ac56dd48 | 165 | static inline void tcg_gen_mov_i32(TCGv ret, TCGv arg) |
c896fe29 | 166 | { |
98156423 | 167 | if (GET_TCGV(ret) != GET_TCGV(arg)) |
4d07272d | 168 | tcg_gen_op2(INDEX_op_mov_i32, ret, arg); |
c896fe29 FB |
169 | } |
170 | ||
ac56dd48 | 171 | static inline void tcg_gen_movi_i32(TCGv ret, int32_t arg) |
c896fe29 | 172 | { |
ac56dd48 | 173 | tcg_gen_op2i(INDEX_op_movi_i32, ret, arg); |
c896fe29 FB |
174 | } |
175 | ||
176 | /* helper calls */ | |
177 | #define TCG_HELPER_CALL_FLAGS 0 | |
178 | ||
179 | static inline void tcg_gen_helper_0_0(void *func) | |
180 | { | |
181 | tcg_gen_call(&tcg_ctx, | |
182 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
183 | 0, NULL, 0, NULL); | |
184 | } | |
185 | ||
ac56dd48 | 186 | static inline void tcg_gen_helper_0_1(void *func, TCGv arg) |
c896fe29 FB |
187 | { |
188 | tcg_gen_call(&tcg_ctx, | |
189 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
190 | 0, NULL, 1, &arg); | |
191 | } | |
192 | ||
ac56dd48 | 193 | static inline void tcg_gen_helper_0_2(void *func, TCGv arg1, TCGv arg2) |
c896fe29 | 194 | { |
ac56dd48 | 195 | TCGv args[2]; |
c896fe29 FB |
196 | args[0] = arg1; |
197 | args[1] = arg2; | |
198 | tcg_gen_call(&tcg_ctx, | |
199 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
200 | 0, NULL, 2, args); | |
201 | } | |
202 | ||
b0109805 PB |
203 | static inline void tcg_gen_helper_0_3(void *func, |
204 | TCGv arg1, TCGv arg2, TCGv arg3) | |
205 | { | |
206 | TCGv args[3]; | |
207 | args[0] = arg1; | |
208 | args[1] = arg2; | |
209 | args[2] = arg3; | |
210 | tcg_gen_call(&tcg_ctx, | |
211 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
212 | 0, NULL, 3, args); | |
213 | } | |
214 | ||
f8422f52 BS |
215 | static inline void tcg_gen_helper_0_4(void *func, TCGv arg1, TCGv arg2, |
216 | TCGv arg3, TCGv arg4) | |
217 | { | |
218 | TCGv args[4]; | |
219 | args[0] = arg1; | |
220 | args[1] = arg2; | |
221 | args[2] = arg3; | |
222 | args[3] = arg4; | |
223 | tcg_gen_call(&tcg_ctx, | |
224 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
225 | 0, NULL, 4, args); | |
226 | } | |
227 | ||
228 | static inline void tcg_gen_helper_1_0(void *func, TCGv ret) | |
229 | { | |
230 | tcg_gen_call(&tcg_ctx, | |
231 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
232 | 1, &ret, 0, NULL); | |
233 | } | |
234 | ||
235 | static inline void tcg_gen_helper_1_1(void *func, TCGv ret, TCGv arg1) | |
236 | { | |
237 | tcg_gen_call(&tcg_ctx, | |
238 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
239 | 1, &ret, 1, &arg1); | |
240 | } | |
241 | ||
ac56dd48 PB |
242 | static inline void tcg_gen_helper_1_2(void *func, TCGv ret, |
243 | TCGv arg1, TCGv arg2) | |
c896fe29 | 244 | { |
ac56dd48 | 245 | TCGv args[2]; |
c896fe29 FB |
246 | args[0] = arg1; |
247 | args[1] = arg2; | |
248 | tcg_gen_call(&tcg_ctx, | |
249 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
250 | 1, &ret, 2, args); | |
251 | } | |
252 | ||
6ddbc6e4 PB |
253 | static inline void tcg_gen_helper_1_3(void *func, TCGv ret, |
254 | TCGv arg1, TCGv arg2, TCGv arg3) | |
255 | { | |
256 | TCGv args[3]; | |
257 | args[0] = arg1; | |
258 | args[1] = arg2; | |
259 | args[2] = arg3; | |
260 | tcg_gen_call(&tcg_ctx, | |
261 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
262 | 1, &ret, 3, args); | |
263 | } | |
264 | ||
f8422f52 BS |
265 | static inline void tcg_gen_helper_1_4(void *func, TCGv ret, |
266 | TCGv arg1, TCGv arg2, TCGv arg3, | |
267 | TCGv arg4) | |
268 | { | |
269 | TCGv args[4]; | |
270 | args[0] = arg1; | |
271 | args[1] = arg2; | |
272 | args[2] = arg3; | |
273 | args[3] = arg4; | |
274 | tcg_gen_call(&tcg_ctx, | |
275 | tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS, | |
276 | 1, &ret, 4, args); | |
277 | } | |
278 | ||
c896fe29 FB |
279 | /* 32 bit ops */ |
280 | ||
ac56dd48 | 281 | static inline void tcg_gen_ld8u_i32(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 | 282 | { |
ac56dd48 | 283 | tcg_gen_op3i(INDEX_op_ld8u_i32, ret, arg2, offset); |
c896fe29 FB |
284 | } |
285 | ||
ac56dd48 | 286 | static inline void tcg_gen_ld8s_i32(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 | 287 | { |
ac56dd48 | 288 | tcg_gen_op3i(INDEX_op_ld8s_i32, ret, arg2, offset); |
c896fe29 FB |
289 | } |
290 | ||
ac56dd48 | 291 | static inline void tcg_gen_ld16u_i32(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 | 292 | { |
ac56dd48 | 293 | tcg_gen_op3i(INDEX_op_ld16u_i32, ret, arg2, offset); |
c896fe29 FB |
294 | } |
295 | ||
ac56dd48 | 296 | static inline void tcg_gen_ld16s_i32(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 | 297 | { |
ac56dd48 | 298 | tcg_gen_op3i(INDEX_op_ld16s_i32, ret, arg2, offset); |
c896fe29 FB |
299 | } |
300 | ||
ac56dd48 | 301 | static inline void tcg_gen_ld_i32(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 | 302 | { |
ac56dd48 | 303 | tcg_gen_op3i(INDEX_op_ld_i32, ret, arg2, offset); |
c896fe29 FB |
304 | } |
305 | ||
ac56dd48 | 306 | static inline void tcg_gen_st8_i32(TCGv arg1, TCGv arg2, tcg_target_long offset) |
c896fe29 | 307 | { |
ac56dd48 | 308 | tcg_gen_op3i(INDEX_op_st8_i32, arg1, arg2, offset); |
c896fe29 FB |
309 | } |
310 | ||
ac56dd48 | 311 | static inline void tcg_gen_st16_i32(TCGv arg1, TCGv arg2, tcg_target_long offset) |
c896fe29 | 312 | { |
ac56dd48 | 313 | tcg_gen_op3i(INDEX_op_st16_i32, arg1, arg2, offset); |
c896fe29 FB |
314 | } |
315 | ||
ac56dd48 | 316 | static inline void tcg_gen_st_i32(TCGv arg1, TCGv arg2, tcg_target_long offset) |
c896fe29 | 317 | { |
ac56dd48 | 318 | tcg_gen_op3i(INDEX_op_st_i32, arg1, arg2, offset); |
c896fe29 FB |
319 | } |
320 | ||
ac56dd48 | 321 | static inline void tcg_gen_add_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
322 | { |
323 | tcg_gen_op3(INDEX_op_add_i32, ret, arg1, arg2); | |
324 | } | |
325 | ||
ac56dd48 | 326 | static inline void tcg_gen_addi_i32(TCGv ret, TCGv arg1, int32_t arg2) |
c896fe29 | 327 | { |
7089442c BS |
328 | /* some cases can be optimized here */ |
329 | if (arg2 == 0) { | |
330 | tcg_gen_mov_i32(ret, arg1); | |
331 | } else { | |
332 | tcg_gen_add_i32(ret, arg1, tcg_const_i32(arg2)); | |
333 | } | |
c896fe29 FB |
334 | } |
335 | ||
ac56dd48 | 336 | static inline void tcg_gen_sub_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
337 | { |
338 | tcg_gen_op3(INDEX_op_sub_i32, ret, arg1, arg2); | |
339 | } | |
340 | ||
ac56dd48 | 341 | static inline void tcg_gen_subi_i32(TCGv ret, TCGv arg1, int32_t arg2) |
c896fe29 | 342 | { |
7089442c BS |
343 | /* some cases can be optimized here */ |
344 | if (arg2 == 0) { | |
345 | tcg_gen_mov_i32(ret, arg1); | |
346 | } else { | |
347 | tcg_gen_sub_i32(ret, arg1, tcg_const_i32(arg2)); | |
348 | } | |
c896fe29 FB |
349 | } |
350 | ||
ac56dd48 | 351 | static inline void tcg_gen_and_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
352 | { |
353 | tcg_gen_op3(INDEX_op_and_i32, ret, arg1, arg2); | |
354 | } | |
355 | ||
ac56dd48 | 356 | static inline void tcg_gen_andi_i32(TCGv ret, TCGv arg1, int32_t arg2) |
c896fe29 FB |
357 | { |
358 | /* some cases can be optimized here */ | |
359 | if (arg2 == 0) { | |
360 | tcg_gen_movi_i32(ret, 0); | |
361 | } else if (arg2 == 0xffffffff) { | |
362 | tcg_gen_mov_i32(ret, arg1); | |
363 | } else { | |
364 | tcg_gen_and_i32(ret, arg1, tcg_const_i32(arg2)); | |
365 | } | |
366 | } | |
367 | ||
ac56dd48 | 368 | static inline void tcg_gen_or_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
369 | { |
370 | tcg_gen_op3(INDEX_op_or_i32, ret, arg1, arg2); | |
371 | } | |
372 | ||
ac56dd48 | 373 | static inline void tcg_gen_ori_i32(TCGv ret, TCGv arg1, int32_t arg2) |
c896fe29 FB |
374 | { |
375 | /* some cases can be optimized here */ | |
376 | if (arg2 == 0xffffffff) { | |
7089442c | 377 | tcg_gen_movi_i32(ret, 0xffffffff); |
c896fe29 FB |
378 | } else if (arg2 == 0) { |
379 | tcg_gen_mov_i32(ret, arg1); | |
380 | } else { | |
381 | tcg_gen_or_i32(ret, arg1, tcg_const_i32(arg2)); | |
382 | } | |
383 | } | |
384 | ||
ac56dd48 | 385 | static inline void tcg_gen_xor_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
386 | { |
387 | tcg_gen_op3(INDEX_op_xor_i32, ret, arg1, arg2); | |
388 | } | |
389 | ||
ac56dd48 | 390 | static inline void tcg_gen_xori_i32(TCGv ret, TCGv arg1, int32_t arg2) |
c896fe29 FB |
391 | { |
392 | /* some cases can be optimized here */ | |
393 | if (arg2 == 0) { | |
394 | tcg_gen_mov_i32(ret, arg1); | |
395 | } else { | |
396 | tcg_gen_xor_i32(ret, arg1, tcg_const_i32(arg2)); | |
397 | } | |
398 | } | |
399 | ||
ac56dd48 | 400 | static inline void tcg_gen_shl_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
401 | { |
402 | tcg_gen_op3(INDEX_op_shl_i32, ret, arg1, arg2); | |
403 | } | |
404 | ||
ac56dd48 | 405 | static inline void tcg_gen_shli_i32(TCGv ret, TCGv arg1, int32_t arg2) |
c896fe29 FB |
406 | { |
407 | tcg_gen_shl_i32(ret, arg1, tcg_const_i32(arg2)); | |
408 | } | |
409 | ||
ac56dd48 | 410 | static inline void tcg_gen_shr_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
411 | { |
412 | tcg_gen_op3(INDEX_op_shr_i32, ret, arg1, arg2); | |
413 | } | |
414 | ||
ac56dd48 | 415 | static inline void tcg_gen_shri_i32(TCGv ret, TCGv arg1, int32_t arg2) |
c896fe29 FB |
416 | { |
417 | tcg_gen_shr_i32(ret, arg1, tcg_const_i32(arg2)); | |
418 | } | |
419 | ||
ac56dd48 | 420 | static inline void tcg_gen_sar_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
421 | { |
422 | tcg_gen_op3(INDEX_op_sar_i32, ret, arg1, arg2); | |
423 | } | |
424 | ||
ac56dd48 | 425 | static inline void tcg_gen_sari_i32(TCGv ret, TCGv arg1, int32_t arg2) |
c896fe29 FB |
426 | { |
427 | tcg_gen_sar_i32(ret, arg1, tcg_const_i32(arg2)); | |
428 | } | |
429 | ||
ac56dd48 | 430 | static inline void tcg_gen_brcond_i32(int cond, TCGv arg1, TCGv arg2, |
c896fe29 FB |
431 | int label_index) |
432 | { | |
ac56dd48 | 433 | tcg_gen_op4ii(INDEX_op_brcond_i32, arg1, arg2, cond, label_index); |
c896fe29 FB |
434 | } |
435 | ||
ac56dd48 | 436 | static inline void tcg_gen_mul_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
437 | { |
438 | tcg_gen_op3(INDEX_op_mul_i32, ret, arg1, arg2); | |
439 | } | |
440 | ||
f730fd27 TS |
441 | static inline void tcg_gen_muli_i32(TCGv ret, TCGv arg1, int32_t arg2) |
442 | { | |
443 | tcg_gen_mul_i32(ret, arg1, tcg_const_i32(arg2)); | |
444 | } | |
445 | ||
c896fe29 | 446 | #ifdef TCG_TARGET_HAS_div_i32 |
ac56dd48 | 447 | static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
448 | { |
449 | tcg_gen_op3(INDEX_op_div_i32, ret, arg1, arg2); | |
450 | } | |
451 | ||
ac56dd48 | 452 | static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
453 | { |
454 | tcg_gen_op3(INDEX_op_rem_i32, ret, arg1, arg2); | |
455 | } | |
456 | ||
ac56dd48 | 457 | static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
458 | { |
459 | tcg_gen_op3(INDEX_op_divu_i32, ret, arg1, arg2); | |
460 | } | |
461 | ||
ac56dd48 | 462 | static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
463 | { |
464 | tcg_gen_op3(INDEX_op_remu_i32, ret, arg1, arg2); | |
465 | } | |
466 | #else | |
ac56dd48 | 467 | static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 468 | { |
ac56dd48 | 469 | TCGv t0; |
c896fe29 FB |
470 | t0 = tcg_temp_new(TCG_TYPE_I32); |
471 | tcg_gen_sari_i32(t0, arg1, 31); | |
472 | tcg_gen_op5(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2); | |
473 | } | |
474 | ||
ac56dd48 | 475 | static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 476 | { |
ac56dd48 | 477 | TCGv t0; |
c896fe29 FB |
478 | t0 = tcg_temp_new(TCG_TYPE_I32); |
479 | tcg_gen_sari_i32(t0, arg1, 31); | |
480 | tcg_gen_op5(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2); | |
481 | } | |
482 | ||
ac56dd48 | 483 | static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 484 | { |
ac56dd48 | 485 | TCGv t0; |
c896fe29 FB |
486 | t0 = tcg_temp_new(TCG_TYPE_I32); |
487 | tcg_gen_movi_i32(t0, 0); | |
488 | tcg_gen_op5(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2); | |
489 | } | |
490 | ||
ac56dd48 | 491 | static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 492 | { |
ac56dd48 | 493 | TCGv t0; |
c896fe29 FB |
494 | t0 = tcg_temp_new(TCG_TYPE_I32); |
495 | tcg_gen_movi_i32(t0, 0); | |
496 | tcg_gen_op5(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2); | |
497 | } | |
498 | #endif | |
499 | ||
500 | #if TCG_TARGET_REG_BITS == 32 | |
501 | ||
ac56dd48 | 502 | static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg) |
c896fe29 | 503 | { |
98156423 | 504 | if (GET_TCGV(ret) != GET_TCGV(arg)) { |
4d07272d BS |
505 | tcg_gen_mov_i32(ret, arg); |
506 | tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg)); | |
507 | } | |
c896fe29 FB |
508 | } |
509 | ||
ac56dd48 | 510 | static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg) |
c896fe29 FB |
511 | { |
512 | tcg_gen_movi_i32(ret, arg); | |
ac56dd48 | 513 | tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32); |
c896fe29 FB |
514 | } |
515 | ||
ac56dd48 | 516 | static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
517 | { |
518 | tcg_gen_ld8u_i32(ret, arg2, offset); | |
ac56dd48 | 519 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); |
c896fe29 FB |
520 | } |
521 | ||
ac56dd48 | 522 | static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
523 | { |
524 | tcg_gen_ld8s_i32(ret, arg2, offset); | |
ac56dd48 | 525 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
526 | } |
527 | ||
ac56dd48 | 528 | static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
529 | { |
530 | tcg_gen_ld16u_i32(ret, arg2, offset); | |
ac56dd48 | 531 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); |
c896fe29 FB |
532 | } |
533 | ||
ac56dd48 | 534 | static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
535 | { |
536 | tcg_gen_ld16s_i32(ret, arg2, offset); | |
ac56dd48 | 537 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
538 | } |
539 | ||
ac56dd48 | 540 | static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
541 | { |
542 | tcg_gen_ld_i32(ret, arg2, offset); | |
ac56dd48 | 543 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); |
c896fe29 FB |
544 | } |
545 | ||
ac56dd48 | 546 | static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
547 | { |
548 | tcg_gen_ld_i32(ret, arg2, offset); | |
ac56dd48 | 549 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
550 | } |
551 | ||
ac56dd48 | 552 | static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
553 | { |
554 | /* since arg2 and ret have different types, they cannot be the | |
555 | same temporary */ | |
556 | #ifdef TCG_TARGET_WORDS_BIGENDIAN | |
ac56dd48 | 557 | tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset); |
c896fe29 FB |
558 | tcg_gen_ld_i32(ret, arg2, offset + 4); |
559 | #else | |
560 | tcg_gen_ld_i32(ret, arg2, offset); | |
ac56dd48 | 561 | tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4); |
c896fe29 FB |
562 | #endif |
563 | } | |
564 | ||
ac56dd48 | 565 | static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
566 | { |
567 | tcg_gen_st8_i32(arg1, arg2, offset); | |
568 | } | |
569 | ||
ac56dd48 | 570 | static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
571 | { |
572 | tcg_gen_st16_i32(arg1, arg2, offset); | |
573 | } | |
574 | ||
ac56dd48 | 575 | static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
576 | { |
577 | tcg_gen_st_i32(arg1, arg2, offset); | |
578 | } | |
579 | ||
ac56dd48 | 580 | static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset) |
c896fe29 FB |
581 | { |
582 | #ifdef TCG_TARGET_WORDS_BIGENDIAN | |
ac56dd48 | 583 | tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset); |
c896fe29 FB |
584 | tcg_gen_st_i32(arg1, arg2, offset + 4); |
585 | #else | |
586 | tcg_gen_st_i32(arg1, arg2, offset); | |
ac56dd48 | 587 | tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4); |
c896fe29 FB |
588 | #endif |
589 | } | |
590 | ||
ac56dd48 | 591 | static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 592 | { |
ac56dd48 PB |
593 | tcg_gen_op6(INDEX_op_add2_i32, ret, TCGV_HIGH(ret), |
594 | arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2)); | |
c896fe29 FB |
595 | } |
596 | ||
ac56dd48 | 597 | static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
598 | { |
599 | tcg_gen_add_i64(ret, arg1, tcg_const_i64(arg2)); | |
600 | } | |
601 | ||
ac56dd48 | 602 | static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 603 | { |
ac56dd48 PB |
604 | tcg_gen_op6(INDEX_op_sub2_i32, ret, TCGV_HIGH(ret), |
605 | arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2)); | |
c896fe29 FB |
606 | } |
607 | ||
ac56dd48 | 608 | static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
609 | { |
610 | tcg_gen_sub_i64(ret, arg1, tcg_const_i64(arg2)); | |
611 | } | |
612 | ||
ac56dd48 | 613 | static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
614 | { |
615 | tcg_gen_and_i32(ret, arg1, arg2); | |
ac56dd48 | 616 | tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2)); |
c896fe29 FB |
617 | } |
618 | ||
ac56dd48 | 619 | static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
620 | { |
621 | tcg_gen_andi_i32(ret, arg1, arg2); | |
ac56dd48 | 622 | tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32); |
c896fe29 FB |
623 | } |
624 | ||
ac56dd48 | 625 | static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
626 | { |
627 | tcg_gen_or_i32(ret, arg1, arg2); | |
ac56dd48 | 628 | tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2)); |
c896fe29 FB |
629 | } |
630 | ||
ac56dd48 | 631 | static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
632 | { |
633 | tcg_gen_ori_i32(ret, arg1, arg2); | |
ac56dd48 | 634 | tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32); |
c896fe29 FB |
635 | } |
636 | ||
ac56dd48 | 637 | static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
638 | { |
639 | tcg_gen_xor_i32(ret, arg1, arg2); | |
ac56dd48 | 640 | tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2)); |
c896fe29 FB |
641 | } |
642 | ||
ac56dd48 | 643 | static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
644 | { |
645 | tcg_gen_xori_i32(ret, arg1, arg2); | |
ac56dd48 | 646 | tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32); |
c896fe29 FB |
647 | } |
648 | ||
649 | /* XXX: use generic code when basic block handling is OK or CPU | |
650 | specific code (x86) */ | |
ac56dd48 | 651 | static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
652 | { |
653 | tcg_gen_helper_1_2(tcg_helper_shl_i64, ret, arg1, arg2); | |
654 | } | |
655 | ||
ac56dd48 | 656 | static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
657 | { |
658 | tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0); | |
659 | } | |
660 | ||
ac56dd48 | 661 | static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
662 | { |
663 | tcg_gen_helper_1_2(tcg_helper_shr_i64, ret, arg1, arg2); | |
664 | } | |
665 | ||
ac56dd48 | 666 | static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
667 | { |
668 | tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0); | |
669 | } | |
670 | ||
ac56dd48 | 671 | static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
672 | { |
673 | tcg_gen_helper_1_2(tcg_helper_sar_i64, ret, arg1, arg2); | |
674 | } | |
675 | ||
ac56dd48 | 676 | static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
677 | { |
678 | tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1); | |
679 | } | |
680 | ||
ac56dd48 | 681 | static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2, |
c896fe29 FB |
682 | int label_index) |
683 | { | |
ac56dd48 PB |
684 | tcg_gen_op6ii(INDEX_op_brcond2_i32, |
685 | arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2), | |
686 | cond, label_index); | |
c896fe29 FB |
687 | } |
688 | ||
ac56dd48 | 689 | static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 690 | { |
ac56dd48 | 691 | TCGv t0, t1; |
c896fe29 FB |
692 | |
693 | t0 = tcg_temp_new(TCG_TYPE_I64); | |
694 | t1 = tcg_temp_new(TCG_TYPE_I32); | |
695 | ||
ac56dd48 | 696 | tcg_gen_op4(INDEX_op_mulu2_i32, t0, TCGV_HIGH(t0), arg1, arg2); |
c896fe29 | 697 | |
ac56dd48 PB |
698 | tcg_gen_mul_i32(t1, arg1, TCGV_HIGH(arg2)); |
699 | tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1); | |
700 | tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), arg2); | |
701 | tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1); | |
c896fe29 FB |
702 | |
703 | tcg_gen_mov_i64(ret, t0); | |
704 | } | |
705 | ||
f730fd27 TS |
706 | static inline void tcg_gen_muli_i64(TCGv ret, TCGv arg1, int64_t arg2) |
707 | { | |
708 | tcg_gen_mul_i64(ret, arg1, tcg_const_i64(arg2)); | |
709 | } | |
710 | ||
ac56dd48 | 711 | static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
712 | { |
713 | tcg_gen_helper_1_2(tcg_helper_div_i64, ret, arg1, arg2); | |
714 | } | |
715 | ||
ac56dd48 | 716 | static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
717 | { |
718 | tcg_gen_helper_1_2(tcg_helper_rem_i64, ret, arg1, arg2); | |
719 | } | |
720 | ||
ac56dd48 | 721 | static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
722 | { |
723 | tcg_gen_helper_1_2(tcg_helper_divu_i64, ret, arg1, arg2); | |
724 | } | |
725 | ||
ac56dd48 | 726 | static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
727 | { |
728 | tcg_gen_helper_1_2(tcg_helper_remu_i64, ret, arg1, arg2); | |
729 | } | |
730 | ||
731 | #else | |
732 | ||
ac56dd48 | 733 | static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg) |
c896fe29 | 734 | { |
98156423 | 735 | if (GET_TCGV(ret) != GET_TCGV(arg)) |
4d07272d | 736 | tcg_gen_op2(INDEX_op_mov_i64, ret, arg); |
c896fe29 FB |
737 | } |
738 | ||
ac56dd48 | 739 | static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg) |
c896fe29 | 740 | { |
ac56dd48 | 741 | tcg_gen_op2i(INDEX_op_movi_i64, ret, arg); |
c896fe29 FB |
742 | } |
743 | ||
ac56dd48 PB |
744 | static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2, |
745 | tcg_target_long offset) | |
c896fe29 | 746 | { |
ac56dd48 | 747 | tcg_gen_op3i(INDEX_op_ld8u_i64, ret, arg2, offset); |
c896fe29 FB |
748 | } |
749 | ||
ac56dd48 PB |
750 | static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2, |
751 | tcg_target_long offset) | |
c896fe29 | 752 | { |
ac56dd48 | 753 | tcg_gen_op3i(INDEX_op_ld8s_i64, ret, arg2, offset); |
c896fe29 FB |
754 | } |
755 | ||
ac56dd48 PB |
756 | static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2, |
757 | tcg_target_long offset) | |
c896fe29 | 758 | { |
ac56dd48 | 759 | tcg_gen_op3i(INDEX_op_ld16u_i64, ret, arg2, offset); |
c896fe29 FB |
760 | } |
761 | ||
ac56dd48 PB |
762 | static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2, |
763 | tcg_target_long offset) | |
c896fe29 | 764 | { |
ac56dd48 | 765 | tcg_gen_op3i(INDEX_op_ld16s_i64, ret, arg2, offset); |
c896fe29 FB |
766 | } |
767 | ||
ac56dd48 PB |
768 | static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2, |
769 | tcg_target_long offset) | |
c896fe29 | 770 | { |
ac56dd48 | 771 | tcg_gen_op3i(INDEX_op_ld32u_i64, ret, arg2, offset); |
c896fe29 FB |
772 | } |
773 | ||
ac56dd48 PB |
774 | static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2, |
775 | tcg_target_long offset) | |
c896fe29 | 776 | { |
ac56dd48 | 777 | tcg_gen_op3i(INDEX_op_ld32s_i64, ret, arg2, offset); |
c896fe29 FB |
778 | } |
779 | ||
ac56dd48 | 780 | static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset) |
c896fe29 | 781 | { |
ac56dd48 | 782 | tcg_gen_op3i(INDEX_op_ld_i64, ret, arg2, offset); |
c896fe29 FB |
783 | } |
784 | ||
ac56dd48 PB |
785 | static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2, |
786 | tcg_target_long offset) | |
c896fe29 | 787 | { |
ac56dd48 | 788 | tcg_gen_op3i(INDEX_op_st8_i64, arg1, arg2, offset); |
c896fe29 FB |
789 | } |
790 | ||
ac56dd48 PB |
791 | static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2, |
792 | tcg_target_long offset) | |
c896fe29 | 793 | { |
ac56dd48 | 794 | tcg_gen_op3i(INDEX_op_st16_i64, arg1, arg2, offset); |
c896fe29 FB |
795 | } |
796 | ||
ac56dd48 PB |
797 | static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2, |
798 | tcg_target_long offset) | |
c896fe29 | 799 | { |
ac56dd48 | 800 | tcg_gen_op3i(INDEX_op_st32_i64, arg1, arg2, offset); |
c896fe29 FB |
801 | } |
802 | ||
ac56dd48 | 803 | static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset) |
c896fe29 | 804 | { |
ac56dd48 | 805 | tcg_gen_op3i(INDEX_op_st_i64, arg1, arg2, offset); |
c896fe29 FB |
806 | } |
807 | ||
ac56dd48 | 808 | static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
809 | { |
810 | tcg_gen_op3(INDEX_op_add_i64, ret, arg1, arg2); | |
811 | } | |
812 | ||
ac56dd48 | 813 | static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
814 | { |
815 | tcg_gen_add_i64(ret, arg1, tcg_const_i64(arg2)); | |
816 | } | |
817 | ||
ac56dd48 | 818 | static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
819 | { |
820 | tcg_gen_op3(INDEX_op_sub_i64, ret, arg1, arg2); | |
821 | } | |
822 | ||
ac56dd48 | 823 | static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
824 | { |
825 | tcg_gen_sub_i64(ret, arg1, tcg_const_i64(arg2)); | |
826 | } | |
827 | ||
ac56dd48 | 828 | static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
829 | { |
830 | tcg_gen_op3(INDEX_op_and_i64, ret, arg1, arg2); | |
831 | } | |
832 | ||
ac56dd48 | 833 | static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
834 | { |
835 | tcg_gen_and_i64(ret, arg1, tcg_const_i64(arg2)); | |
836 | } | |
837 | ||
ac56dd48 | 838 | static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
839 | { |
840 | tcg_gen_op3(INDEX_op_or_i64, ret, arg1, arg2); | |
841 | } | |
842 | ||
ac56dd48 | 843 | static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
844 | { |
845 | tcg_gen_or_i64(ret, arg1, tcg_const_i64(arg2)); | |
846 | } | |
847 | ||
ac56dd48 | 848 | static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
849 | { |
850 | tcg_gen_op3(INDEX_op_xor_i64, ret, arg1, arg2); | |
851 | } | |
852 | ||
ac56dd48 | 853 | static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
854 | { |
855 | tcg_gen_xor_i64(ret, arg1, tcg_const_i64(arg2)); | |
856 | } | |
857 | ||
ac56dd48 | 858 | static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
859 | { |
860 | tcg_gen_op3(INDEX_op_shl_i64, ret, arg1, arg2); | |
861 | } | |
862 | ||
ac56dd48 | 863 | static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
864 | { |
865 | tcg_gen_shl_i64(ret, arg1, tcg_const_i64(arg2)); | |
866 | } | |
867 | ||
ac56dd48 | 868 | static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
869 | { |
870 | tcg_gen_op3(INDEX_op_shr_i64, ret, arg1, arg2); | |
871 | } | |
872 | ||
ac56dd48 | 873 | static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
874 | { |
875 | tcg_gen_shr_i64(ret, arg1, tcg_const_i64(arg2)); | |
876 | } | |
877 | ||
ac56dd48 | 878 | static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
879 | { |
880 | tcg_gen_op3(INDEX_op_sar_i64, ret, arg1, arg2); | |
881 | } | |
882 | ||
ac56dd48 | 883 | static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2) |
c896fe29 FB |
884 | { |
885 | tcg_gen_sar_i64(ret, arg1, tcg_const_i64(arg2)); | |
886 | } | |
887 | ||
ac56dd48 | 888 | static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2, |
c896fe29 FB |
889 | int label_index) |
890 | { | |
ac56dd48 | 891 | tcg_gen_op4ii(INDEX_op_brcond_i64, arg1, arg2, cond, label_index); |
c896fe29 FB |
892 | } |
893 | ||
ac56dd48 | 894 | static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
895 | { |
896 | tcg_gen_op3(INDEX_op_mul_i64, ret, arg1, arg2); | |
897 | } | |
898 | ||
f730fd27 TS |
899 | static inline void tcg_gen_muli_i64(TCGv ret, TCGv arg1, int64_t arg2) |
900 | { | |
901 | tcg_gen_mul_i64(ret, arg1, tcg_const_i64(arg2)); | |
902 | } | |
903 | ||
c896fe29 | 904 | #ifdef TCG_TARGET_HAS_div_i64 |
ac56dd48 | 905 | static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
906 | { |
907 | tcg_gen_op3(INDEX_op_div_i64, ret, arg1, arg2); | |
908 | } | |
909 | ||
ac56dd48 | 910 | static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
911 | { |
912 | tcg_gen_op3(INDEX_op_rem_i64, ret, arg1, arg2); | |
913 | } | |
914 | ||
ac56dd48 | 915 | static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
916 | { |
917 | tcg_gen_op3(INDEX_op_divu_i64, ret, arg1, arg2); | |
918 | } | |
919 | ||
ac56dd48 | 920 | static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 FB |
921 | { |
922 | tcg_gen_op3(INDEX_op_remu_i64, ret, arg1, arg2); | |
923 | } | |
924 | #else | |
ac56dd48 | 925 | static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 926 | { |
ac56dd48 | 927 | TCGv t0; |
c896fe29 FB |
928 | t0 = tcg_temp_new(TCG_TYPE_I64); |
929 | tcg_gen_sari_i64(t0, arg1, 63); | |
930 | tcg_gen_op5(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2); | |
931 | } | |
932 | ||
ac56dd48 | 933 | static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 934 | { |
ac56dd48 | 935 | TCGv t0; |
c896fe29 FB |
936 | t0 = tcg_temp_new(TCG_TYPE_I64); |
937 | tcg_gen_sari_i64(t0, arg1, 63); | |
938 | tcg_gen_op5(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2); | |
939 | } | |
940 | ||
ac56dd48 | 941 | static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 942 | { |
ac56dd48 | 943 | TCGv t0; |
c896fe29 FB |
944 | t0 = tcg_temp_new(TCG_TYPE_I64); |
945 | tcg_gen_movi_i64(t0, 0); | |
946 | tcg_gen_op5(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2); | |
947 | } | |
948 | ||
ac56dd48 | 949 | static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2) |
c896fe29 | 950 | { |
ac56dd48 | 951 | TCGv t0; |
c896fe29 FB |
952 | t0 = tcg_temp_new(TCG_TYPE_I64); |
953 | tcg_gen_movi_i64(t0, 0); | |
954 | tcg_gen_op5(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2); | |
955 | } | |
956 | #endif | |
957 | ||
958 | #endif | |
959 | ||
960 | /***************************************/ | |
961 | /* optional operations */ | |
962 | ||
ac56dd48 | 963 | static inline void tcg_gen_ext8s_i32(TCGv ret, TCGv arg) |
c896fe29 FB |
964 | { |
965 | #ifdef TCG_TARGET_HAS_ext8s_i32 | |
966 | tcg_gen_op2(INDEX_op_ext8s_i32, ret, arg); | |
967 | #else | |
968 | tcg_gen_shli_i32(ret, arg, 24); | |
5ff9d6a4 | 969 | tcg_gen_sari_i32(ret, ret, 24); |
c896fe29 FB |
970 | #endif |
971 | } | |
972 | ||
ac56dd48 | 973 | static inline void tcg_gen_ext16s_i32(TCGv ret, TCGv arg) |
c896fe29 FB |
974 | { |
975 | #ifdef TCG_TARGET_HAS_ext16s_i32 | |
976 | tcg_gen_op2(INDEX_op_ext16s_i32, ret, arg); | |
977 | #else | |
978 | tcg_gen_shli_i32(ret, arg, 16); | |
5ff9d6a4 | 979 | tcg_gen_sari_i32(ret, ret, 16); |
c896fe29 FB |
980 | #endif |
981 | } | |
982 | ||
86831435 PB |
983 | /* These are currently just for convenience. |
984 | We assume a target will recognise these automatically . */ | |
985 | static inline void tcg_gen_ext8u_i32(TCGv ret, TCGv arg) | |
986 | { | |
987 | tcg_gen_andi_i32(ret, arg, 0xffu); | |
988 | } | |
989 | ||
990 | static inline void tcg_gen_ext16u_i32(TCGv ret, TCGv arg) | |
991 | { | |
992 | tcg_gen_andi_i32(ret, arg, 0xffffu); | |
993 | } | |
994 | ||
c896fe29 | 995 | /* Note: we assume the two high bytes are set to zero */ |
ac56dd48 | 996 | static inline void tcg_gen_bswap16_i32(TCGv ret, TCGv arg) |
c896fe29 FB |
997 | { |
998 | #ifdef TCG_TARGET_HAS_bswap16_i32 | |
999 | tcg_gen_op2(INDEX_op_bswap16_i32, ret, arg); | |
1000 | #else | |
ac56dd48 | 1001 | TCGv t0, t1; |
c896fe29 FB |
1002 | t0 = tcg_temp_new(TCG_TYPE_I32); |
1003 | t1 = tcg_temp_new(TCG_TYPE_I32); | |
1004 | ||
1005 | tcg_gen_shri_i32(t0, arg, 8); | |
1006 | tcg_gen_andi_i32(t1, arg, 0x000000ff); | |
1007 | tcg_gen_shli_i32(t1, t1, 8); | |
1008 | tcg_gen_or_i32(ret, t0, t1); | |
1009 | #endif | |
1010 | } | |
1011 | ||
ac56dd48 | 1012 | static inline void tcg_gen_bswap_i32(TCGv ret, TCGv arg) |
c896fe29 FB |
1013 | { |
1014 | #ifdef TCG_TARGET_HAS_bswap_i32 | |
1015 | tcg_gen_op2(INDEX_op_bswap_i32, ret, arg); | |
1016 | #else | |
ac56dd48 | 1017 | TCGv t0, t1; |
c896fe29 FB |
1018 | t0 = tcg_temp_new(TCG_TYPE_I32); |
1019 | t1 = tcg_temp_new(TCG_TYPE_I32); | |
1020 | ||
1021 | tcg_gen_shli_i32(t0, arg, 24); | |
1022 | ||
1023 | tcg_gen_andi_i32(t1, arg, 0x0000ff00); | |
1024 | tcg_gen_shli_i32(t1, t1, 8); | |
1025 | tcg_gen_or_i32(t0, t0, t1); | |
1026 | ||
1027 | tcg_gen_shri_i32(t1, arg, 8); | |
1028 | tcg_gen_andi_i32(t1, t1, 0x0000ff00); | |
1029 | tcg_gen_or_i32(t0, t0, t1); | |
1030 | ||
1031 | tcg_gen_shri_i32(t1, arg, 24); | |
1032 | tcg_gen_or_i32(ret, t0, t1); | |
1033 | #endif | |
1034 | } | |
1035 | ||
1036 | #if TCG_TARGET_REG_BITS == 32 | |
ac56dd48 | 1037 | static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1038 | { |
1039 | tcg_gen_ext8s_i32(ret, arg); | |
ac56dd48 | 1040 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
1041 | } |
1042 | ||
ac56dd48 | 1043 | static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1044 | { |
1045 | tcg_gen_ext16s_i32(ret, arg); | |
ac56dd48 | 1046 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
1047 | } |
1048 | ||
ac56dd48 | 1049 | static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1050 | { |
1051 | tcg_gen_mov_i32(ret, arg); | |
ac56dd48 | 1052 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
1053 | } |
1054 | ||
86831435 PB |
1055 | static inline void tcg_gen_ext8u_i64(TCGv ret, TCGv arg) |
1056 | { | |
1057 | tcg_gen_ext8u_i32(ret, arg); | |
1058 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); | |
1059 | } | |
1060 | ||
1061 | static inline void tcg_gen_ext16u_i64(TCGv ret, TCGv arg) | |
1062 | { | |
1063 | tcg_gen_ext16u_i32(ret, arg); | |
1064 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); | |
1065 | } | |
1066 | ||
1067 | static inline void tcg_gen_ext32u_i64(TCGv ret, TCGv arg) | |
1068 | { | |
1069 | tcg_gen_mov_i32(ret, arg); | |
1070 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); | |
1071 | } | |
1072 | ||
ac56dd48 | 1073 | static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg) |
c896fe29 FB |
1074 | { |
1075 | tcg_gen_mov_i32(ret, arg); | |
1076 | } | |
1077 | ||
ac56dd48 | 1078 | static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1079 | { |
1080 | tcg_gen_mov_i32(ret, arg); | |
ac56dd48 | 1081 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); |
c896fe29 FB |
1082 | } |
1083 | ||
ac56dd48 | 1084 | static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1085 | { |
1086 | tcg_gen_mov_i32(ret, arg); | |
ac56dd48 | 1087 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
1088 | } |
1089 | ||
ac56dd48 | 1090 | static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg) |
c896fe29 | 1091 | { |
ac56dd48 | 1092 | TCGv t0, t1; |
c896fe29 FB |
1093 | t0 = tcg_temp_new(TCG_TYPE_I32); |
1094 | t1 = tcg_temp_new(TCG_TYPE_I32); | |
1095 | ||
1096 | tcg_gen_bswap_i32(t0, arg); | |
ac56dd48 | 1097 | tcg_gen_bswap_i32(t1, TCGV_HIGH(arg)); |
c896fe29 | 1098 | tcg_gen_mov_i32(ret, t1); |
ac56dd48 | 1099 | tcg_gen_mov_i32(TCGV_HIGH(ret), t0); |
c896fe29 FB |
1100 | } |
1101 | #else | |
1102 | ||
ac56dd48 | 1103 | static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1104 | { |
1105 | #ifdef TCG_TARGET_HAS_ext8s_i64 | |
1106 | tcg_gen_op2(INDEX_op_ext8s_i64, ret, arg); | |
1107 | #else | |
1108 | tcg_gen_shli_i64(ret, arg, 56); | |
5ff9d6a4 | 1109 | tcg_gen_sari_i64(ret, ret, 56); |
c896fe29 FB |
1110 | #endif |
1111 | } | |
1112 | ||
ac56dd48 | 1113 | static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1114 | { |
1115 | #ifdef TCG_TARGET_HAS_ext16s_i64 | |
1116 | tcg_gen_op2(INDEX_op_ext16s_i64, ret, arg); | |
1117 | #else | |
1118 | tcg_gen_shli_i64(ret, arg, 48); | |
5ff9d6a4 | 1119 | tcg_gen_sari_i64(ret, ret, 48); |
c896fe29 FB |
1120 | #endif |
1121 | } | |
1122 | ||
ac56dd48 | 1123 | static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1124 | { |
1125 | #ifdef TCG_TARGET_HAS_ext32s_i64 | |
1126 | tcg_gen_op2(INDEX_op_ext32s_i64, ret, arg); | |
1127 | #else | |
1128 | tcg_gen_shli_i64(ret, arg, 32); | |
5ff9d6a4 | 1129 | tcg_gen_sari_i64(ret, ret, 32); |
c896fe29 FB |
1130 | #endif |
1131 | } | |
1132 | ||
86831435 PB |
1133 | static inline void tcg_gen_ext8u_i64(TCGv ret, TCGv arg) |
1134 | { | |
1135 | tcg_gen_andi_i64(ret, arg, 0xffu); | |
1136 | } | |
1137 | ||
1138 | static inline void tcg_gen_ext16u_i64(TCGv ret, TCGv arg) | |
1139 | { | |
1140 | tcg_gen_andi_i64(ret, arg, 0xffffu); | |
1141 | } | |
1142 | ||
1143 | static inline void tcg_gen_ext32u_i64(TCGv ret, TCGv arg) | |
1144 | { | |
1145 | tcg_gen_andi_i64(ret, arg, 0xffffffffu); | |
1146 | } | |
1147 | ||
c896fe29 | 1148 | /* Note: we assume the target supports move between 32 and 64 bit |
ac56dd48 PB |
1149 | registers. This will probably break MIPS64 targets. */ |
1150 | static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg) | |
c896fe29 FB |
1151 | { |
1152 | tcg_gen_mov_i32(ret, arg); | |
1153 | } | |
1154 | ||
1155 | /* Note: we assume the target supports move between 32 and 64 bit | |
1156 | registers */ | |
ac56dd48 | 1157 | static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg) |
c896fe29 | 1158 | { |
86831435 | 1159 | tcg_gen_andi_i64(ret, arg, 0xffffffffu); |
c896fe29 FB |
1160 | } |
1161 | ||
1162 | /* Note: we assume the target supports move between 32 and 64 bit | |
1163 | registers */ | |
ac56dd48 | 1164 | static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1165 | { |
1166 | tcg_gen_ext32s_i64(ret, arg); | |
1167 | } | |
1168 | ||
ac56dd48 | 1169 | static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg) |
c896fe29 FB |
1170 | { |
1171 | #ifdef TCG_TARGET_HAS_bswap_i64 | |
1172 | tcg_gen_op2(INDEX_op_bswap_i64, ret, arg); | |
1173 | #else | |
ac56dd48 | 1174 | TCGv t0, t1; |
c896fe29 FB |
1175 | t0 = tcg_temp_new(TCG_TYPE_I32); |
1176 | t1 = tcg_temp_new(TCG_TYPE_I32); | |
1177 | ||
1178 | tcg_gen_shli_i64(t0, arg, 56); | |
1179 | ||
1180 | tcg_gen_andi_i64(t1, arg, 0x0000ff00); | |
1181 | tcg_gen_shli_i64(t1, t1, 40); | |
1182 | tcg_gen_or_i64(t0, t0, t1); | |
1183 | ||
1184 | tcg_gen_andi_i64(t1, arg, 0x00ff0000); | |
1185 | tcg_gen_shli_i64(t1, t1, 24); | |
1186 | tcg_gen_or_i64(t0, t0, t1); | |
1187 | ||
1188 | tcg_gen_andi_i64(t1, arg, 0xff000000); | |
1189 | tcg_gen_shli_i64(t1, t1, 8); | |
1190 | tcg_gen_or_i64(t0, t0, t1); | |
1191 | ||
1192 | tcg_gen_shri_i64(t1, arg, 8); | |
1193 | tcg_gen_andi_i64(t1, t1, 0xff000000); | |
1194 | tcg_gen_or_i64(t0, t0, t1); | |
1195 | ||
1196 | tcg_gen_shri_i64(t1, arg, 24); | |
1197 | tcg_gen_andi_i64(t1, t1, 0x00ff0000); | |
1198 | tcg_gen_or_i64(t0, t0, t1); | |
1199 | ||
1200 | tcg_gen_shri_i64(t1, arg, 40); | |
1201 | tcg_gen_andi_i64(t1, t1, 0x0000ff00); | |
1202 | tcg_gen_or_i64(t0, t0, t1); | |
1203 | ||
1204 | tcg_gen_shri_i64(t1, arg, 56); | |
1205 | tcg_gen_or_i64(ret, t0, t1); | |
1206 | #endif | |
1207 | } | |
1208 | ||
1209 | #endif | |
1210 | ||
390efc54 PB |
1211 | static inline void tcg_gen_neg_i32(TCGv ret, TCGv arg) |
1212 | { | |
1213 | #ifdef TCG_TARGET_HAS_neg_i32 | |
1214 | tcg_gen_op2(INDEX_op_neg_i32, ret, arg); | |
1215 | #else | |
1216 | tcg_gen_sub_i32(ret, tcg_const_i32(0), arg); | |
1217 | #endif | |
1218 | } | |
1219 | ||
1220 | static inline void tcg_gen_neg_i64(TCGv ret, TCGv arg) | |
1221 | { | |
1222 | #ifdef TCG_TARGET_HAS_neg_i64 | |
1223 | tcg_gen_op2(INDEX_op_neg_i64, ret, arg); | |
1224 | #else | |
1225 | tcg_gen_sub_i64(ret, tcg_const_i64(0), arg); | |
1226 | #endif | |
1227 | } | |
1228 | ||
0b6ce4cf FB |
1229 | static inline void tcg_gen_not_i32(TCGv ret, TCGv arg) |
1230 | { | |
1231 | tcg_gen_xor_i32(ret, arg, tcg_const_i32(-1)); | |
1232 | } | |
1233 | ||
1234 | static inline void tcg_gen_not_i64(TCGv ret, TCGv arg) | |
1235 | { | |
1236 | tcg_gen_xor_i64(ret, arg, tcg_const_i64(-1)); | |
1237 | } | |
5ff9d6a4 FB |
1238 | |
1239 | static inline void tcg_gen_discard_i32(TCGv arg) | |
1240 | { | |
1241 | tcg_gen_op1(INDEX_op_discard, arg); | |
1242 | } | |
1243 | ||
1244 | #if TCG_TARGET_REG_BITS == 32 | |
1245 | static inline void tcg_gen_discard_i64(TCGv arg) | |
1246 | { | |
1247 | tcg_gen_discard_i32(arg); | |
1248 | tcg_gen_discard_i32(TCGV_HIGH(arg)); | |
1249 | } | |
1250 | #else | |
1251 | static inline void tcg_gen_discard_i64(TCGv arg) | |
1252 | { | |
1253 | tcg_gen_op1(INDEX_op_discard, arg); | |
1254 | } | |
1255 | #endif | |
1256 | ||
c896fe29 | 1257 | /***************************************/ |
ac56dd48 | 1258 | static inline void tcg_gen_macro_2(TCGv ret0, TCGv ret1, int macro_id) |
c896fe29 | 1259 | { |
ac56dd48 | 1260 | tcg_gen_op3i(INDEX_op_macro_2, ret0, ret1, macro_id); |
c896fe29 FB |
1261 | } |
1262 | ||
1263 | /***************************************/ | |
1264 | /* QEMU specific operations. Their type depend on the QEMU CPU | |
1265 | type. */ | |
1266 | #ifndef TARGET_LONG_BITS | |
1267 | #error must include QEMU headers | |
1268 | #endif | |
1269 | ||
1270 | static inline void tcg_gen_exit_tb(tcg_target_long val) | |
1271 | { | |
ac56dd48 | 1272 | tcg_gen_op1i(INDEX_op_exit_tb, val); |
c896fe29 FB |
1273 | } |
1274 | ||
1275 | static inline void tcg_gen_goto_tb(int idx) | |
1276 | { | |
ac56dd48 | 1277 | tcg_gen_op1i(INDEX_op_goto_tb, idx); |
c896fe29 FB |
1278 | } |
1279 | ||
1280 | #if TCG_TARGET_REG_BITS == 32 | |
ac56dd48 | 1281 | static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index) |
c896fe29 FB |
1282 | { |
1283 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1284 | tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index); |
c896fe29 | 1285 | #else |
ac56dd48 PB |
1286 | tcg_gen_op4i(INDEX_op_qemu_ld8u, ret, addr, TCGV_HIGH(addr), mem_index); |
1287 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); | |
c896fe29 FB |
1288 | #endif |
1289 | } | |
1290 | ||
ac56dd48 | 1291 | static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index) |
c896fe29 FB |
1292 | { |
1293 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1294 | tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index); |
c896fe29 | 1295 | #else |
ac56dd48 | 1296 | tcg_gen_op4i(INDEX_op_qemu_ld8s, ret, addr, TCGV_HIGH(addr), mem_index); |
21fc3cfc | 1297 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
1298 | #endif |
1299 | } | |
1300 | ||
ac56dd48 | 1301 | static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index) |
c896fe29 FB |
1302 | { |
1303 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1304 | tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index); |
c896fe29 | 1305 | #else |
ac56dd48 PB |
1306 | tcg_gen_op4i(INDEX_op_qemu_ld16u, ret, addr, TCGV_HIGH(addr), mem_index); |
1307 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); | |
c896fe29 FB |
1308 | #endif |
1309 | } | |
1310 | ||
ac56dd48 | 1311 | static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index) |
c896fe29 FB |
1312 | { |
1313 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1314 | tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index); |
c896fe29 | 1315 | #else |
ac56dd48 | 1316 | tcg_gen_op4i(INDEX_op_qemu_ld16s, ret, addr, TCGV_HIGH(addr), mem_index); |
21fc3cfc | 1317 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); |
c896fe29 FB |
1318 | #endif |
1319 | } | |
1320 | ||
ac56dd48 | 1321 | static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index) |
c896fe29 FB |
1322 | { |
1323 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1324 | tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index); |
c896fe29 | 1325 | #else |
ac56dd48 PB |
1326 | tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index); |
1327 | tcg_gen_movi_i32(TCGV_HIGH(ret), 0); | |
c896fe29 FB |
1328 | #endif |
1329 | } | |
1330 | ||
ac56dd48 | 1331 | static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index) |
c896fe29 FB |
1332 | { |
1333 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1334 | tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index); |
c896fe29 | 1335 | #else |
ac56dd48 PB |
1336 | tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index); |
1337 | tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31); | |
c896fe29 FB |
1338 | #endif |
1339 | } | |
1340 | ||
ac56dd48 | 1341 | static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index) |
c896fe29 FB |
1342 | { |
1343 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1344 | tcg_gen_op4i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret), addr, mem_index); |
c896fe29 | 1345 | #else |
ac56dd48 PB |
1346 | tcg_gen_op5i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret), |
1347 | addr, TCGV_HIGH(addr), mem_index); | |
c896fe29 FB |
1348 | #endif |
1349 | } | |
1350 | ||
ac56dd48 | 1351 | static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index) |
c896fe29 FB |
1352 | { |
1353 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1354 | tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index); |
c896fe29 | 1355 | #else |
ac56dd48 | 1356 | tcg_gen_op4i(INDEX_op_qemu_st8, arg, addr, TCGV_HIGH(addr), mem_index); |
c896fe29 FB |
1357 | #endif |
1358 | } | |
1359 | ||
ac56dd48 | 1360 | static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index) |
c896fe29 FB |
1361 | { |
1362 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1363 | tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index); |
c896fe29 | 1364 | #else |
ac56dd48 | 1365 | tcg_gen_op4i(INDEX_op_qemu_st16, arg, addr, TCGV_HIGH(addr), mem_index); |
c896fe29 FB |
1366 | #endif |
1367 | } | |
1368 | ||
ac56dd48 | 1369 | static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index) |
c896fe29 FB |
1370 | { |
1371 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1372 | tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index); |
c896fe29 | 1373 | #else |
ac56dd48 | 1374 | tcg_gen_op4i(INDEX_op_qemu_st32, arg, addr, TCGV_HIGH(addr), mem_index); |
c896fe29 FB |
1375 | #endif |
1376 | } | |
1377 | ||
ac56dd48 | 1378 | static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index) |
c896fe29 FB |
1379 | { |
1380 | #if TARGET_LONG_BITS == 32 | |
ac56dd48 | 1381 | tcg_gen_op4i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg), addr, mem_index); |
c896fe29 | 1382 | #else |
ac56dd48 PB |
1383 | tcg_gen_op5i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg), |
1384 | addr, TCGV_HIGH(addr), mem_index); | |
c896fe29 FB |
1385 | #endif |
1386 | } | |
1387 | ||
56b8f567 | 1388 | #define tcg_gen_ld_ptr tcg_gen_ld_i32 |
a768e4b2 | 1389 | #define tcg_gen_discard_ptr tcg_gen_discard_i32 |
f8422f52 | 1390 | |
c896fe29 FB |
1391 | #else /* TCG_TARGET_REG_BITS == 32 */ |
1392 | ||
ac56dd48 | 1393 | static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index) |
c896fe29 | 1394 | { |
ac56dd48 | 1395 | tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index); |
c896fe29 FB |
1396 | } |
1397 | ||
ac56dd48 | 1398 | static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index) |
c896fe29 | 1399 | { |
ac56dd48 | 1400 | tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index); |
c896fe29 FB |
1401 | } |
1402 | ||
ac56dd48 | 1403 | static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index) |
c896fe29 | 1404 | { |
ac56dd48 | 1405 | tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index); |
c896fe29 FB |
1406 | } |
1407 | ||
ac56dd48 | 1408 | static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index) |
c896fe29 | 1409 | { |
ac56dd48 | 1410 | tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index); |
c896fe29 FB |
1411 | } |
1412 | ||
ac56dd48 | 1413 | static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index) |
c896fe29 | 1414 | { |
ac56dd48 | 1415 | tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index); |
c896fe29 FB |
1416 | } |
1417 | ||
ac56dd48 | 1418 | static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index) |
c896fe29 | 1419 | { |
ac56dd48 | 1420 | tcg_gen_op3i(INDEX_op_qemu_ld32s, ret, addr, mem_index); |
c896fe29 FB |
1421 | } |
1422 | ||
ac56dd48 | 1423 | static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index) |
c896fe29 | 1424 | { |
ac56dd48 | 1425 | tcg_gen_op3i(INDEX_op_qemu_ld64, ret, addr, mem_index); |
c896fe29 FB |
1426 | } |
1427 | ||
ac56dd48 | 1428 | static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index) |
c896fe29 | 1429 | { |
ac56dd48 | 1430 | tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index); |
c896fe29 FB |
1431 | } |
1432 | ||
ac56dd48 | 1433 | static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index) |
c896fe29 | 1434 | { |
ac56dd48 | 1435 | tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index); |
c896fe29 FB |
1436 | } |
1437 | ||
ac56dd48 | 1438 | static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index) |
c896fe29 | 1439 | { |
ac56dd48 | 1440 | tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index); |
c896fe29 FB |
1441 | } |
1442 | ||
ac56dd48 | 1443 | static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index) |
c896fe29 | 1444 | { |
ac56dd48 | 1445 | tcg_gen_op3i(INDEX_op_qemu_st64, arg, addr, mem_index); |
c896fe29 FB |
1446 | } |
1447 | ||
56b8f567 | 1448 | #define tcg_gen_ld_ptr tcg_gen_ld_i64 |
a768e4b2 | 1449 | #define tcg_gen_discard_ptr tcg_gen_discard_i64 |
f8422f52 | 1450 | |
c896fe29 | 1451 | #endif /* TCG_TARGET_REG_BITS != 32 */ |
f8422f52 BS |
1452 | |
1453 | #if TARGET_LONG_BITS == 64 | |
1454 | #define TCG_TYPE_TL TCG_TYPE_I64 | |
1455 | #define tcg_gen_movi_tl tcg_gen_movi_i64 | |
1456 | #define tcg_gen_mov_tl tcg_gen_mov_i64 | |
1457 | #define tcg_gen_ld8u_tl tcg_gen_ld8u_i64 | |
1458 | #define tcg_gen_ld8s_tl tcg_gen_ld8s_i64 | |
1459 | #define tcg_gen_ld16u_tl tcg_gen_ld16u_i64 | |
1460 | #define tcg_gen_ld16s_tl tcg_gen_ld16s_i64 | |
1461 | #define tcg_gen_ld32u_tl tcg_gen_ld32u_i64 | |
1462 | #define tcg_gen_ld32s_tl tcg_gen_ld32s_i64 | |
1463 | #define tcg_gen_ld_tl tcg_gen_ld_i64 | |
1464 | #define tcg_gen_st8_tl tcg_gen_st8_i64 | |
1465 | #define tcg_gen_st16_tl tcg_gen_st16_i64 | |
1466 | #define tcg_gen_st32_tl tcg_gen_st32_i64 | |
1467 | #define tcg_gen_st_tl tcg_gen_st_i64 | |
1468 | #define tcg_gen_add_tl tcg_gen_add_i64 | |
1469 | #define tcg_gen_addi_tl tcg_gen_addi_i64 | |
1470 | #define tcg_gen_sub_tl tcg_gen_sub_i64 | |
390efc54 | 1471 | #define tcg_gen_neg_tl tcg_gen_neg_i64 |
f8422f52 BS |
1472 | #define tcg_gen_subi_tl tcg_gen_subi_i64 |
1473 | #define tcg_gen_and_tl tcg_gen_and_i64 | |
1474 | #define tcg_gen_andi_tl tcg_gen_andi_i64 | |
1475 | #define tcg_gen_or_tl tcg_gen_or_i64 | |
1476 | #define tcg_gen_ori_tl tcg_gen_ori_i64 | |
1477 | #define tcg_gen_xor_tl tcg_gen_xor_i64 | |
1478 | #define tcg_gen_xori_tl tcg_gen_xori_i64 | |
0b6ce4cf | 1479 | #define tcg_gen_not_tl tcg_gen_not_i64 |
f8422f52 BS |
1480 | #define tcg_gen_shl_tl tcg_gen_shl_i64 |
1481 | #define tcg_gen_shli_tl tcg_gen_shli_i64 | |
1482 | #define tcg_gen_shr_tl tcg_gen_shr_i64 | |
1483 | #define tcg_gen_shri_tl tcg_gen_shri_i64 | |
1484 | #define tcg_gen_sar_tl tcg_gen_sar_i64 | |
1485 | #define tcg_gen_sari_tl tcg_gen_sari_i64 | |
0cf767d6 | 1486 | #define tcg_gen_brcond_tl tcg_gen_brcond_i64 |
f730fd27 TS |
1487 | #define tcg_gen_mul_tl tcg_gen_mul_i64 |
1488 | #define tcg_gen_muli_tl tcg_gen_muli_i64 | |
a768e4b2 | 1489 | #define tcg_gen_discard_tl tcg_gen_discard_i64 |
e429073d BS |
1490 | #define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32 |
1491 | #define tcg_gen_trunc_i64_tl tcg_gen_mov_i64 | |
1492 | #define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64 | |
1493 | #define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64 | |
1494 | #define tcg_gen_extu_tl_i64 tcg_gen_mov_i64 | |
1495 | #define tcg_gen_ext_tl_i64 tcg_gen_mov_i64 | |
0b6ce4cf FB |
1496 | #define tcg_gen_ext8u_tl tcg_gen_ext8u_i64 |
1497 | #define tcg_gen_ext8s_tl tcg_gen_ext8s_i64 | |
1498 | #define tcg_gen_ext16u_tl tcg_gen_ext16u_i64 | |
1499 | #define tcg_gen_ext16s_tl tcg_gen_ext16s_i64 | |
1500 | #define tcg_gen_ext32u_tl tcg_gen_ext32u_i64 | |
1501 | #define tcg_gen_ext32s_tl tcg_gen_ext32s_i64 | |
a98824ac | 1502 | #define tcg_const_tl tcg_const_i64 |
f8422f52 BS |
1503 | #else |
1504 | #define TCG_TYPE_TL TCG_TYPE_I32 | |
1505 | #define tcg_gen_movi_tl tcg_gen_movi_i32 | |
1506 | #define tcg_gen_mov_tl tcg_gen_mov_i32 | |
1507 | #define tcg_gen_ld8u_tl tcg_gen_ld8u_i32 | |
1508 | #define tcg_gen_ld8s_tl tcg_gen_ld8s_i32 | |
1509 | #define tcg_gen_ld16u_tl tcg_gen_ld16u_i32 | |
1510 | #define tcg_gen_ld16s_tl tcg_gen_ld16s_i32 | |
1511 | #define tcg_gen_ld32u_tl tcg_gen_ld_i32 | |
1512 | #define tcg_gen_ld32s_tl tcg_gen_ld_i32 | |
1513 | #define tcg_gen_ld_tl tcg_gen_ld_i32 | |
1514 | #define tcg_gen_st8_tl tcg_gen_st8_i32 | |
1515 | #define tcg_gen_st16_tl tcg_gen_st16_i32 | |
1516 | #define tcg_gen_st32_tl tcg_gen_st_i32 | |
1517 | #define tcg_gen_st_tl tcg_gen_st_i32 | |
1518 | #define tcg_gen_add_tl tcg_gen_add_i32 | |
1519 | #define tcg_gen_addi_tl tcg_gen_addi_i32 | |
1520 | #define tcg_gen_sub_tl tcg_gen_sub_i32 | |
390efc54 | 1521 | #define tcg_gen_neg_tl tcg_gen_neg_i32 |
f8422f52 BS |
1522 | #define tcg_gen_subi_tl tcg_gen_subi_i32 |
1523 | #define tcg_gen_and_tl tcg_gen_and_i32 | |
1524 | #define tcg_gen_andi_tl tcg_gen_andi_i32 | |
1525 | #define tcg_gen_or_tl tcg_gen_or_i32 | |
1526 | #define tcg_gen_ori_tl tcg_gen_ori_i32 | |
1527 | #define tcg_gen_xor_tl tcg_gen_xor_i32 | |
1528 | #define tcg_gen_xori_tl tcg_gen_xori_i32 | |
0b6ce4cf | 1529 | #define tcg_gen_not_tl tcg_gen_not_i32 |
f8422f52 BS |
1530 | #define tcg_gen_shl_tl tcg_gen_shl_i32 |
1531 | #define tcg_gen_shli_tl tcg_gen_shli_i32 | |
1532 | #define tcg_gen_shr_tl tcg_gen_shr_i32 | |
1533 | #define tcg_gen_shri_tl tcg_gen_shri_i32 | |
1534 | #define tcg_gen_sar_tl tcg_gen_sar_i32 | |
1535 | #define tcg_gen_sari_tl tcg_gen_sari_i32 | |
0cf767d6 | 1536 | #define tcg_gen_brcond_tl tcg_gen_brcond_i32 |
f730fd27 TS |
1537 | #define tcg_gen_mul_tl tcg_gen_mul_i32 |
1538 | #define tcg_gen_muli_tl tcg_gen_muli_i32 | |
a768e4b2 | 1539 | #define tcg_gen_discard_tl tcg_gen_discard_i32 |
e429073d BS |
1540 | #define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32 |
1541 | #define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32 | |
1542 | #define tcg_gen_extu_i32_tl tcg_gen_mov_i32 | |
1543 | #define tcg_gen_ext_i32_tl tcg_gen_mov_i32 | |
1544 | #define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64 | |
1545 | #define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64 | |
0b6ce4cf FB |
1546 | #define tcg_gen_ext8u_tl tcg_gen_ext8u_i32 |
1547 | #define tcg_gen_ext8s_tl tcg_gen_ext8s_i32 | |
1548 | #define tcg_gen_ext16u_tl tcg_gen_ext16u_i32 | |
1549 | #define tcg_gen_ext16s_tl tcg_gen_ext16s_i32 | |
1550 | #define tcg_gen_ext32u_tl tcg_gen_mov_i32 | |
1551 | #define tcg_gen_ext32s_tl tcg_gen_mov_i32 | |
a98824ac | 1552 | #define tcg_const_tl tcg_const_i32 |
f8422f52 | 1553 | #endif |
6ddbc6e4 PB |
1554 | |
1555 | #if TCG_TARGET_REG_BITS == 32 | |
48d38ca5 | 1556 | #define tcg_gen_add_ptr tcg_gen_add_i32 |
6ddbc6e4 | 1557 | #define tcg_gen_addi_ptr tcg_gen_addi_i32 |
48d38ca5 | 1558 | #define tcg_gen_ext_i32_ptr tcg_gen_mov_i32 |
6ddbc6e4 | 1559 | #else /* TCG_TARGET_REG_BITS == 32 */ |
48d38ca5 | 1560 | #define tcg_gen_add_ptr tcg_gen_add_i64 |
6ddbc6e4 | 1561 | #define tcg_gen_addi_ptr tcg_gen_addi_i64 |
48d38ca5 | 1562 | #define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64 |
6ddbc6e4 PB |
1563 | #endif /* TCG_TARGET_REG_BITS != 32 */ |
1564 |