tcg-op.h 33.4 KB
Newer Older
B
bellard 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * Tiny Code Generator for QEMU
 *
 * Copyright (c) 2008 Fabrice Bellard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include "tcg.h"

/* legacy dyngen operations */
#include "gen-op.h"

int gen_new_label(void);

P
pbrook 已提交
31
static inline void tcg_gen_op1(int opc, TCGv arg1)
B
bellard 已提交
32 33
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
34
    *gen_opparam_ptr++ = GET_TCGV(arg1);
B
bellard 已提交
35 36
}

P
pbrook 已提交
37
static inline void tcg_gen_op1i(int opc, TCGArg arg1)
B
bellard 已提交
38 39 40 41 42
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = arg1;
}

P
pbrook 已提交
43
static inline void tcg_gen_op2(int opc, TCGv arg1, TCGv arg2)
B
bellard 已提交
44 45
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
46 47
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
B
bellard 已提交
48 49
}

P
pbrook 已提交
50
static inline void tcg_gen_op2i(int opc, TCGv arg1, TCGArg arg2)
B
bellard 已提交
51 52
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
53
    *gen_opparam_ptr++ = GET_TCGV(arg1);
B
bellard 已提交
54
    *gen_opparam_ptr++ = arg2;
P
pbrook 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
}

static inline void tcg_gen_op3(int opc, TCGv arg1, TCGv arg2, TCGv arg3)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
    *gen_opparam_ptr++ = GET_TCGV(arg3);
}

static inline void tcg_gen_op3i(int opc, TCGv arg1, TCGv arg2, TCGArg arg3)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
B
bellard 已提交
70
    *gen_opparam_ptr++ = arg3;
P
pbrook 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
}

static inline void tcg_gen_op4(int opc, TCGv arg1, TCGv arg2, TCGv arg3, 
                               TCGv arg4)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
    *gen_opparam_ptr++ = GET_TCGV(arg3);
    *gen_opparam_ptr++ = GET_TCGV(arg4);
}

static inline void tcg_gen_op4i(int opc, TCGv arg1, TCGv arg2, TCGv arg3, 
                                TCGArg arg4)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
    *gen_opparam_ptr++ = GET_TCGV(arg3);
B
bellard 已提交
90 91 92
    *gen_opparam_ptr++ = arg4;
}

P
pbrook 已提交
93 94
static inline void tcg_gen_op4ii(int opc, TCGv arg1, TCGv arg2, TCGArg arg3, 
                                 TCGArg arg4)
B
bellard 已提交
95 96
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
97 98
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
B
bellard 已提交
99 100
    *gen_opparam_ptr++ = arg3;
    *gen_opparam_ptr++ = arg4;
P
pbrook 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
}

static inline void tcg_gen_op5(int opc, TCGv arg1, TCGv arg2, 
                               TCGv arg3, TCGv arg4,
                               TCGv arg5)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
    *gen_opparam_ptr++ = GET_TCGV(arg3);
    *gen_opparam_ptr++ = GET_TCGV(arg4);
    *gen_opparam_ptr++ = GET_TCGV(arg5);
}

static inline void tcg_gen_op5i(int opc, TCGv arg1, TCGv arg2, 
                                TCGv arg3, TCGv arg4,
                                TCGArg arg5)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
    *gen_opparam_ptr++ = GET_TCGV(arg3);
    *gen_opparam_ptr++ = GET_TCGV(arg4);
B
bellard 已提交
124 125 126
    *gen_opparam_ptr++ = arg5;
}

P
pbrook 已提交
127 128 129
static inline void tcg_gen_op6(int opc, TCGv arg1, TCGv arg2, 
                               TCGv arg3, TCGv arg4,
                               TCGv arg5, TCGv arg6)
B
bellard 已提交
130 131
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
    *gen_opparam_ptr++ = GET_TCGV(arg3);
    *gen_opparam_ptr++ = GET_TCGV(arg4);
    *gen_opparam_ptr++ = GET_TCGV(arg5);
    *gen_opparam_ptr++ = GET_TCGV(arg6);
}

static inline void tcg_gen_op6ii(int opc, TCGv arg1, TCGv arg2, 
                                 TCGv arg3, TCGv arg4,
                                 TCGArg arg5, TCGArg arg6)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV(arg1);
    *gen_opparam_ptr++ = GET_TCGV(arg2);
    *gen_opparam_ptr++ = GET_TCGV(arg3);
    *gen_opparam_ptr++ = GET_TCGV(arg4);
B
bellard 已提交
149 150 151 152 153 154
    *gen_opparam_ptr++ = arg5;
    *gen_opparam_ptr++ = arg6;
}

static inline void gen_set_label(int n)
{
P
pbrook 已提交
155
    tcg_gen_op1i(INDEX_op_set_label, n);
B
bellard 已提交
156 157
}

P
pbrook 已提交
158
static inline void tcg_gen_mov_i32(TCGv ret, TCGv arg)
B
bellard 已提交
159 160 161 162
{
    tcg_gen_op2(INDEX_op_mov_i32, ret, arg);
}

P
pbrook 已提交
163
static inline void tcg_gen_movi_i32(TCGv ret, int32_t arg)
B
bellard 已提交
164
{
P
pbrook 已提交
165
    tcg_gen_op2i(INDEX_op_movi_i32, ret, arg);
B
bellard 已提交
166 167 168 169 170 171 172 173 174 175 176 177
}

/* helper calls */
#define TCG_HELPER_CALL_FLAGS 0

static inline void tcg_gen_helper_0_0(void *func)
{
    tcg_gen_call(&tcg_ctx, 
                 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
                 0, NULL, 0, NULL);
}

P
pbrook 已提交
178
static inline void tcg_gen_helper_0_1(void *func, TCGv arg)
B
bellard 已提交
179 180 181 182 183 184
{
    tcg_gen_call(&tcg_ctx,
                 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
                 0, NULL, 1, &arg);
}

P
pbrook 已提交
185
static inline void tcg_gen_helper_0_2(void *func, TCGv arg1, TCGv arg2)
B
bellard 已提交
186
{
P
pbrook 已提交
187
    TCGv args[2];
B
bellard 已提交
188 189 190 191 192 193 194
    args[0] = arg1;
    args[1] = arg2;
    tcg_gen_call(&tcg_ctx, 
                 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
                 0, NULL, 2, args);
}

P
pbrook 已提交
195 196
static inline void tcg_gen_helper_1_2(void *func, TCGv ret, 
                                      TCGv arg1, TCGv arg2)
B
bellard 已提交
197
{
P
pbrook 已提交
198
    TCGv args[2];
B
bellard 已提交
199 200 201 202 203 204 205 206 207
    args[0] = arg1;
    args[1] = arg2;
    tcg_gen_call(&tcg_ctx, 
                 tcg_const_ptr((tcg_target_long)func), TCG_HELPER_CALL_FLAGS,
                 1, &ret, 2, args);
}

/* 32 bit ops */

P
pbrook 已提交
208
static inline void tcg_gen_ld8u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
209
{
P
pbrook 已提交
210
    tcg_gen_op3i(INDEX_op_ld8u_i32, ret, arg2, offset);
B
bellard 已提交
211 212
}

P
pbrook 已提交
213
static inline void tcg_gen_ld8s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
214
{
P
pbrook 已提交
215
    tcg_gen_op3i(INDEX_op_ld8s_i32, ret, arg2, offset);
B
bellard 已提交
216 217
}

P
pbrook 已提交
218
static inline void tcg_gen_ld16u_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
219
{
P
pbrook 已提交
220
    tcg_gen_op3i(INDEX_op_ld16u_i32, ret, arg2, offset);
B
bellard 已提交
221 222
}

P
pbrook 已提交
223
static inline void tcg_gen_ld16s_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
224
{
P
pbrook 已提交
225
    tcg_gen_op3i(INDEX_op_ld16s_i32, ret, arg2, offset);
B
bellard 已提交
226 227
}

P
pbrook 已提交
228
static inline void tcg_gen_ld_i32(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
229
{
P
pbrook 已提交
230
    tcg_gen_op3i(INDEX_op_ld_i32, ret, arg2, offset);
B
bellard 已提交
231 232
}

P
pbrook 已提交
233
static inline void tcg_gen_st8_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
234
{
P
pbrook 已提交
235
    tcg_gen_op3i(INDEX_op_st8_i32, arg1, arg2, offset);
B
bellard 已提交
236 237
}

P
pbrook 已提交
238
static inline void tcg_gen_st16_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
239
{
P
pbrook 已提交
240
    tcg_gen_op3i(INDEX_op_st16_i32, arg1, arg2, offset);
B
bellard 已提交
241 242
}

P
pbrook 已提交
243
static inline void tcg_gen_st_i32(TCGv arg1, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
244
{
P
pbrook 已提交
245
    tcg_gen_op3i(INDEX_op_st_i32, arg1, arg2, offset);
B
bellard 已提交
246 247
}

P
pbrook 已提交
248
static inline void tcg_gen_add_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
249 250 251 252
{
    tcg_gen_op3(INDEX_op_add_i32, ret, arg1, arg2);
}

P
pbrook 已提交
253
static inline void tcg_gen_addi_i32(TCGv ret, TCGv arg1, int32_t arg2)
B
bellard 已提交
254 255 256 257
{
    tcg_gen_add_i32(ret, arg1, tcg_const_i32(arg2));
}

P
pbrook 已提交
258
static inline void tcg_gen_sub_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
259 260 261 262
{
    tcg_gen_op3(INDEX_op_sub_i32, ret, arg1, arg2);
}

P
pbrook 已提交
263
static inline void tcg_gen_subi_i32(TCGv ret, TCGv arg1, int32_t arg2)
B
bellard 已提交
264 265 266 267
{
    tcg_gen_sub_i32(ret, arg1, tcg_const_i32(arg2));
}

P
pbrook 已提交
268
static inline void tcg_gen_and_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
269 270 271 272
{
    tcg_gen_op3(INDEX_op_and_i32, ret, arg1, arg2);
}

P
pbrook 已提交
273
static inline void tcg_gen_andi_i32(TCGv ret, TCGv arg1, int32_t arg2)
B
bellard 已提交
274 275 276 277 278 279 280 281 282 283 284
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_movi_i32(ret, 0);
    } else if (arg2 == 0xffffffff) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
        tcg_gen_and_i32(ret, arg1, tcg_const_i32(arg2));
    }
}

P
pbrook 已提交
285
static inline void tcg_gen_or_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
286 287 288 289
{
    tcg_gen_op3(INDEX_op_or_i32, ret, arg1, arg2);
}

P
pbrook 已提交
290
static inline void tcg_gen_ori_i32(TCGv ret, TCGv arg1, int32_t arg2)
B
bellard 已提交
291 292 293 294 295 296 297 298 299 300 301
{
    /* some cases can be optimized here */
    if (arg2 == 0xffffffff) {
        tcg_gen_movi_i32(ret, 0);
    } else if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
        tcg_gen_or_i32(ret, arg1, tcg_const_i32(arg2));
    }
}

P
pbrook 已提交
302
static inline void tcg_gen_xor_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
303 304 305 306
{
    tcg_gen_op3(INDEX_op_xor_i32, ret, arg1, arg2);
}

P
pbrook 已提交
307
static inline void tcg_gen_xori_i32(TCGv ret, TCGv arg1, int32_t arg2)
B
bellard 已提交
308 309 310 311 312 313 314 315 316
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
        tcg_gen_xor_i32(ret, arg1, tcg_const_i32(arg2));
    }
}

P
pbrook 已提交
317
static inline void tcg_gen_shl_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
318 319 320 321
{
    tcg_gen_op3(INDEX_op_shl_i32, ret, arg1, arg2);
}

P
pbrook 已提交
322
static inline void tcg_gen_shli_i32(TCGv ret, TCGv arg1, int32_t arg2)
B
bellard 已提交
323 324 325 326
{
    tcg_gen_shl_i32(ret, arg1, tcg_const_i32(arg2));
}

P
pbrook 已提交
327
static inline void tcg_gen_shr_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
328 329 330 331
{
    tcg_gen_op3(INDEX_op_shr_i32, ret, arg1, arg2);
}

P
pbrook 已提交
332
static inline void tcg_gen_shri_i32(TCGv ret, TCGv arg1, int32_t arg2)
B
bellard 已提交
333 334 335 336
{
    tcg_gen_shr_i32(ret, arg1, tcg_const_i32(arg2));
}

P
pbrook 已提交
337
static inline void tcg_gen_sar_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
338 339 340 341
{
    tcg_gen_op3(INDEX_op_sar_i32, ret, arg1, arg2);
}

P
pbrook 已提交
342
static inline void tcg_gen_sari_i32(TCGv ret, TCGv arg1, int32_t arg2)
B
bellard 已提交
343 344 345 346
{
    tcg_gen_sar_i32(ret, arg1, tcg_const_i32(arg2));
}

P
pbrook 已提交
347
static inline void tcg_gen_brcond_i32(int cond, TCGv arg1, TCGv arg2, 
B
bellard 已提交
348 349
                                      int label_index)
{
P
pbrook 已提交
350
    tcg_gen_op4ii(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
B
bellard 已提交
351 352
}

P
pbrook 已提交
353
static inline void tcg_gen_mul_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
354 355 356 357 358
{
    tcg_gen_op3(INDEX_op_mul_i32, ret, arg1, arg2);
}

#ifdef TCG_TARGET_HAS_div_i32
P
pbrook 已提交
359
static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
360 361 362 363
{
    tcg_gen_op3(INDEX_op_div_i32, ret, arg1, arg2);
}

P
pbrook 已提交
364
static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
365 366 367 368
{
    tcg_gen_op3(INDEX_op_rem_i32, ret, arg1, arg2);
}

P
pbrook 已提交
369
static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
370 371 372 373
{
    tcg_gen_op3(INDEX_op_divu_i32, ret, arg1, arg2);
}

P
pbrook 已提交
374
static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
375 376 377 378
{
    tcg_gen_op3(INDEX_op_remu_i32, ret, arg1, arg2);
}
#else
P
pbrook 已提交
379
static inline void tcg_gen_div_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
380
{
P
pbrook 已提交
381
    TCGv t0;
B
bellard 已提交
382 383 384 385 386
    t0 = tcg_temp_new(TCG_TYPE_I32);
    tcg_gen_sari_i32(t0, arg1, 31);
    tcg_gen_op5(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
}

P
pbrook 已提交
387
static inline void tcg_gen_rem_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
388
{
P
pbrook 已提交
389
    TCGv t0;
B
bellard 已提交
390 391 392 393 394
    t0 = tcg_temp_new(TCG_TYPE_I32);
    tcg_gen_sari_i32(t0, arg1, 31);
    tcg_gen_op5(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
}

P
pbrook 已提交
395
static inline void tcg_gen_divu_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
396
{
P
pbrook 已提交
397
    TCGv t0;
B
bellard 已提交
398 399 400 401 402
    t0 = tcg_temp_new(TCG_TYPE_I32);
    tcg_gen_movi_i32(t0, 0);
    tcg_gen_op5(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
}

P
pbrook 已提交
403
static inline void tcg_gen_remu_i32(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
404
{
P
pbrook 已提交
405
    TCGv t0;
B
bellard 已提交
406 407 408 409 410 411 412 413
    t0 = tcg_temp_new(TCG_TYPE_I32);
    tcg_gen_movi_i32(t0, 0);
    tcg_gen_op5(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
}
#endif

#if TCG_TARGET_REG_BITS == 32

P
pbrook 已提交
414
static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
B
bellard 已提交
415 416
{
    tcg_gen_mov_i32(ret, arg);
P
pbrook 已提交
417
    tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
B
bellard 已提交
418 419
}

P
pbrook 已提交
420
static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
B
bellard 已提交
421 422
{
    tcg_gen_movi_i32(ret, arg);
P
pbrook 已提交
423
    tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
B
bellard 已提交
424 425
}

P
pbrook 已提交
426
static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
427 428
{
    tcg_gen_ld8u_i32(ret, arg2, offset);
P
pbrook 已提交
429
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
430 431
}

P
pbrook 已提交
432
static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
433 434
{
    tcg_gen_ld8s_i32(ret, arg2, offset);
P
pbrook 已提交
435
    tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
B
bellard 已提交
436 437
}

P
pbrook 已提交
438
static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
439 440
{
    tcg_gen_ld16u_i32(ret, arg2, offset);
P
pbrook 已提交
441
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
442 443
}

P
pbrook 已提交
444
static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
445 446
{
    tcg_gen_ld16s_i32(ret, arg2, offset);
P
pbrook 已提交
447
    tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
B
bellard 已提交
448 449
}

P
pbrook 已提交
450
static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
451 452
{
    tcg_gen_ld_i32(ret, arg2, offset);
P
pbrook 已提交
453
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
454 455
}

P
pbrook 已提交
456
static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
457 458
{
    tcg_gen_ld_i32(ret, arg2, offset);
P
pbrook 已提交
459
    tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
B
bellard 已提交
460 461
}

P
pbrook 已提交
462
static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
463 464 465 466
{
    /* since arg2 and ret have different types, they cannot be the
       same temporary */
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
467
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
B
bellard 已提交
468 469 470
    tcg_gen_ld_i32(ret, arg2, offset + 4);
#else
    tcg_gen_ld_i32(ret, arg2, offset);
P
pbrook 已提交
471
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
B
bellard 已提交
472 473 474
#endif
}

P
pbrook 已提交
475
static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
476 477 478 479
{
    tcg_gen_st8_i32(arg1, arg2, offset);
}

P
pbrook 已提交
480
static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
481 482 483 484
{
    tcg_gen_st16_i32(arg1, arg2, offset);
}

P
pbrook 已提交
485
static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
486 487 488 489
{
    tcg_gen_st_i32(arg1, arg2, offset);
}

P
pbrook 已提交
490
static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
491 492
{
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
493
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
B
bellard 已提交
494 495 496
    tcg_gen_st_i32(arg1, arg2, offset + 4);
#else
    tcg_gen_st_i32(arg1, arg2, offset);
P
pbrook 已提交
497
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
B
bellard 已提交
498 499 500
#endif
}

P
pbrook 已提交
501
static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
502
{
P
pbrook 已提交
503 504
    tcg_gen_op6(INDEX_op_add2_i32, ret, TCGV_HIGH(ret), 
                arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
B
bellard 已提交
505 506
}

P
pbrook 已提交
507
static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
508 509 510 511
{
    tcg_gen_add_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
512
static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
513
{
P
pbrook 已提交
514 515
    tcg_gen_op6(INDEX_op_sub2_i32, ret, TCGV_HIGH(ret), 
                arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2));
B
bellard 已提交
516 517
}

P
pbrook 已提交
518
static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
519 520 521 522
{
    tcg_gen_sub_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
523
static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
524 525
{
    tcg_gen_and_i32(ret, arg1, arg2);
P
pbrook 已提交
526
    tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
527 528
}

P
pbrook 已提交
529
static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
530 531
{
    tcg_gen_andi_i32(ret, arg1, arg2);
P
pbrook 已提交
532
    tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
533 534
}

P
pbrook 已提交
535
static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
536 537
{
    tcg_gen_or_i32(ret, arg1, arg2);
P
pbrook 已提交
538
    tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
539 540
}

P
pbrook 已提交
541
static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
542 543
{
    tcg_gen_ori_i32(ret, arg1, arg2);
P
pbrook 已提交
544
    tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
545 546
}

P
pbrook 已提交
547
static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
548 549
{
    tcg_gen_xor_i32(ret, arg1, arg2);
P
pbrook 已提交
550
    tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
551 552
}

P
pbrook 已提交
553
static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
554 555
{
    tcg_gen_xori_i32(ret, arg1, arg2);
P
pbrook 已提交
556
    tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
557 558 559 560
}

/* XXX: use generic code when basic block handling is OK or CPU
   specific code (x86) */
P
pbrook 已提交
561
static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
562 563 564 565
{
    tcg_gen_helper_1_2(tcg_helper_shl_i64, ret, arg1, arg2);
}

P
pbrook 已提交
566
static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
567 568 569 570
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
}

P
pbrook 已提交
571
static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
572 573 574 575
{
    tcg_gen_helper_1_2(tcg_helper_shr_i64, ret, arg1, arg2);
}

P
pbrook 已提交
576
static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
577 578 579 580
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
}

P
pbrook 已提交
581
static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
582 583 584 585
{
    tcg_gen_helper_1_2(tcg_helper_sar_i64, ret, arg1, arg2);
}

P
pbrook 已提交
586
static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
587 588 589 590
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
}

P
pbrook 已提交
591
static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2, 
B
bellard 已提交
592 593
                                      int label_index)
{
P
pbrook 已提交
594 595 596
    tcg_gen_op6ii(INDEX_op_brcond2_i32, 
                  arg1, TCGV_HIGH(arg1), arg2, TCGV_HIGH(arg2),
                  cond, label_index);
B
bellard 已提交
597 598
}

P
pbrook 已提交
599
static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
600
{
P
pbrook 已提交
601
    TCGv t0, t1;
B
bellard 已提交
602 603 604 605
    
    t0 = tcg_temp_new(TCG_TYPE_I64);
    t1 = tcg_temp_new(TCG_TYPE_I32);

P
pbrook 已提交
606
    tcg_gen_op4(INDEX_op_mulu2_i32, t0, TCGV_HIGH(t0), arg1, arg2);
B
bellard 已提交
607
    
P
pbrook 已提交
608 609 610 611
    tcg_gen_mul_i32(t1, arg1, TCGV_HIGH(arg2));
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
    tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), arg2);
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
B
bellard 已提交
612 613 614 615
    
    tcg_gen_mov_i64(ret, t0);
}

P
pbrook 已提交
616
static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
617 618 619 620
{
    tcg_gen_helper_1_2(tcg_helper_div_i64, ret, arg1, arg2);
}

P
pbrook 已提交
621
static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
622 623 624 625
{
    tcg_gen_helper_1_2(tcg_helper_rem_i64, ret, arg1, arg2);
}

P
pbrook 已提交
626
static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
627 628 629 630
{
    tcg_gen_helper_1_2(tcg_helper_divu_i64, ret, arg1, arg2);
}

P
pbrook 已提交
631
static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
632 633 634 635 636 637
{
    tcg_gen_helper_1_2(tcg_helper_remu_i64, ret, arg1, arg2);
}

#else

P
pbrook 已提交
638
static inline void tcg_gen_mov_i64(TCGv ret, TCGv arg)
B
bellard 已提交
639 640 641 642
{
    tcg_gen_op2(INDEX_op_mov_i64, ret, arg);
}

P
pbrook 已提交
643
static inline void tcg_gen_movi_i64(TCGv ret, int64_t arg)
B
bellard 已提交
644
{
P
pbrook 已提交
645
    tcg_gen_op2i(INDEX_op_movi_i64, ret, arg);
B
bellard 已提交
646 647
}

P
pbrook 已提交
648 649
static inline void tcg_gen_ld8u_i64(TCGv ret, TCGv arg2,
                                    tcg_target_long offset)
B
bellard 已提交
650
{
P
pbrook 已提交
651
    tcg_gen_op3i(INDEX_op_ld8u_i64, ret, arg2, offset);
B
bellard 已提交
652 653
}

P
pbrook 已提交
654 655
static inline void tcg_gen_ld8s_i64(TCGv ret, TCGv arg2,
                                    tcg_target_long offset)
B
bellard 已提交
656
{
P
pbrook 已提交
657
    tcg_gen_op3i(INDEX_op_ld8s_i64, ret, arg2, offset);
B
bellard 已提交
658 659
}

P
pbrook 已提交
660 661
static inline void tcg_gen_ld16u_i64(TCGv ret, TCGv arg2,
                                     tcg_target_long offset)
B
bellard 已提交
662
{
P
pbrook 已提交
663
    tcg_gen_op3i(INDEX_op_ld16u_i64, ret, arg2, offset);
B
bellard 已提交
664 665
}

P
pbrook 已提交
666 667
static inline void tcg_gen_ld16s_i64(TCGv ret, TCGv arg2,
                                     tcg_target_long offset)
B
bellard 已提交
668
{
P
pbrook 已提交
669
    tcg_gen_op3i(INDEX_op_ld16s_i64, ret, arg2, offset);
B
bellard 已提交
670 671
}

P
pbrook 已提交
672 673
static inline void tcg_gen_ld32u_i64(TCGv ret, TCGv arg2,
                                     tcg_target_long offset)
B
bellard 已提交
674
{
P
pbrook 已提交
675
    tcg_gen_op3i(INDEX_op_ld32u_i64, ret, arg2, offset);
B
bellard 已提交
676 677
}

P
pbrook 已提交
678 679
static inline void tcg_gen_ld32s_i64(TCGv ret, TCGv arg2,
                                     tcg_target_long offset)
B
bellard 已提交
680
{
P
pbrook 已提交
681
    tcg_gen_op3i(INDEX_op_ld32s_i64, ret, arg2, offset);
B
bellard 已提交
682 683
}

P
pbrook 已提交
684
static inline void tcg_gen_ld_i64(TCGv ret, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
685
{
P
pbrook 已提交
686
    tcg_gen_op3i(INDEX_op_ld_i64, ret, arg2, offset);
B
bellard 已提交
687 688
}

P
pbrook 已提交
689 690
static inline void tcg_gen_st8_i64(TCGv arg1, TCGv arg2,
                                   tcg_target_long offset)
B
bellard 已提交
691
{
P
pbrook 已提交
692
    tcg_gen_op3i(INDEX_op_st8_i64, arg1, arg2, offset);
B
bellard 已提交
693 694
}

P
pbrook 已提交
695 696
static inline void tcg_gen_st16_i64(TCGv arg1, TCGv arg2,
                                    tcg_target_long offset)
B
bellard 已提交
697
{
P
pbrook 已提交
698
    tcg_gen_op3i(INDEX_op_st16_i64, arg1, arg2, offset);
B
bellard 已提交
699 700
}

P
pbrook 已提交
701 702
static inline void tcg_gen_st32_i64(TCGv arg1, TCGv arg2,
                                    tcg_target_long offset)
B
bellard 已提交
703
{
P
pbrook 已提交
704
    tcg_gen_op3i(INDEX_op_st32_i64, arg1, arg2, offset);
B
bellard 已提交
705 706
}

P
pbrook 已提交
707
static inline void tcg_gen_st_i64(TCGv arg1, TCGv arg2, tcg_target_long offset)
B
bellard 已提交
708
{
P
pbrook 已提交
709
    tcg_gen_op3i(INDEX_op_st_i64, arg1, arg2, offset);
B
bellard 已提交
710 711
}

P
pbrook 已提交
712
static inline void tcg_gen_add_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
713 714 715 716
{
    tcg_gen_op3(INDEX_op_add_i64, ret, arg1, arg2);
}

P
pbrook 已提交
717
static inline void tcg_gen_addi_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
718 719 720 721
{
    tcg_gen_add_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
722
static inline void tcg_gen_sub_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
723 724 725 726
{
    tcg_gen_op3(INDEX_op_sub_i64, ret, arg1, arg2);
}

P
pbrook 已提交
727
static inline void tcg_gen_subi_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
728 729 730 731
{
    tcg_gen_sub_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
732
static inline void tcg_gen_and_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
733 734 735 736
{
    tcg_gen_op3(INDEX_op_and_i64, ret, arg1, arg2);
}

P
pbrook 已提交
737
static inline void tcg_gen_andi_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
738 739 740 741
{
    tcg_gen_and_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
742
static inline void tcg_gen_or_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
743 744 745 746
{
    tcg_gen_op3(INDEX_op_or_i64, ret, arg1, arg2);
}

P
pbrook 已提交
747
static inline void tcg_gen_ori_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
748 749 750 751
{
    tcg_gen_or_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
752
static inline void tcg_gen_xor_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
753 754 755 756
{
    tcg_gen_op3(INDEX_op_xor_i64, ret, arg1, arg2);
}

P
pbrook 已提交
757
static inline void tcg_gen_xori_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
758 759 760 761
{
    tcg_gen_xor_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
762
static inline void tcg_gen_shl_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
763 764 765 766
{
    tcg_gen_op3(INDEX_op_shl_i64, ret, arg1, arg2);
}

P
pbrook 已提交
767
static inline void tcg_gen_shli_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
768 769 770 771
{
    tcg_gen_shl_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
772
static inline void tcg_gen_shr_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
773 774 775 776
{
    tcg_gen_op3(INDEX_op_shr_i64, ret, arg1, arg2);
}

P
pbrook 已提交
777
static inline void tcg_gen_shri_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
778 779 780 781
{
    tcg_gen_shr_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
782
static inline void tcg_gen_sar_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
783 784 785 786
{
    tcg_gen_op3(INDEX_op_sar_i64, ret, arg1, arg2);
}

P
pbrook 已提交
787
static inline void tcg_gen_sari_i64(TCGv ret, TCGv arg1, int64_t arg2)
B
bellard 已提交
788 789 790 791
{
    tcg_gen_sar_i64(ret, arg1, tcg_const_i64(arg2));
}

P
pbrook 已提交
792
static inline void tcg_gen_brcond_i64(int cond, TCGv arg1, TCGv arg2, 
B
bellard 已提交
793 794
                                      int label_index)
{
P
pbrook 已提交
795
    tcg_gen_op4ii(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
B
bellard 已提交
796 797
}

P
pbrook 已提交
798
static inline void tcg_gen_mul_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
799 800 801 802 803
{
    tcg_gen_op3(INDEX_op_mul_i64, ret, arg1, arg2);
}

#ifdef TCG_TARGET_HAS_div_i64
P
pbrook 已提交
804
static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
805 806 807 808
{
    tcg_gen_op3(INDEX_op_div_i64, ret, arg1, arg2);
}

P
pbrook 已提交
809
static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
810 811 812 813
{
    tcg_gen_op3(INDEX_op_rem_i64, ret, arg1, arg2);
}

P
pbrook 已提交
814
static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
815 816 817 818
{
    tcg_gen_op3(INDEX_op_divu_i64, ret, arg1, arg2);
}

P
pbrook 已提交
819
static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
820 821 822 823
{
    tcg_gen_op3(INDEX_op_remu_i64, ret, arg1, arg2);
}
#else
P
pbrook 已提交
824
static inline void tcg_gen_div_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
825
{
P
pbrook 已提交
826
    TCGv t0;
B
bellard 已提交
827 828 829 830 831
    t0 = tcg_temp_new(TCG_TYPE_I64);
    tcg_gen_sari_i64(t0, arg1, 63);
    tcg_gen_op5(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
}

P
pbrook 已提交
832
static inline void tcg_gen_rem_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
833
{
P
pbrook 已提交
834
    TCGv t0;
B
bellard 已提交
835 836 837 838 839
    t0 = tcg_temp_new(TCG_TYPE_I64);
    tcg_gen_sari_i64(t0, arg1, 63);
    tcg_gen_op5(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
}

P
pbrook 已提交
840
static inline void tcg_gen_divu_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
841
{
P
pbrook 已提交
842
    TCGv t0;
B
bellard 已提交
843 844 845 846 847
    t0 = tcg_temp_new(TCG_TYPE_I64);
    tcg_gen_movi_i64(t0, 0);
    tcg_gen_op5(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
}

P
pbrook 已提交
848
static inline void tcg_gen_remu_i64(TCGv ret, TCGv arg1, TCGv arg2)
B
bellard 已提交
849
{
P
pbrook 已提交
850
    TCGv t0;
B
bellard 已提交
851 852 853 854 855 856 857 858 859 860 861
    t0 = tcg_temp_new(TCG_TYPE_I64);
    tcg_gen_movi_i64(t0, 0);
    tcg_gen_op5(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
}
#endif

#endif

/***************************************/
/* optional operations */

P
pbrook 已提交
862
static inline void tcg_gen_ext8s_i32(TCGv ret, TCGv arg)
B
bellard 已提交
863 864 865 866 867 868 869 870 871
{
#ifdef TCG_TARGET_HAS_ext8s_i32
    tcg_gen_op2(INDEX_op_ext8s_i32, ret, arg);
#else
    tcg_gen_shli_i32(ret, arg, 24);
    tcg_gen_sari_i32(ret, arg, 24);
#endif
}

P
pbrook 已提交
872
static inline void tcg_gen_ext16s_i32(TCGv ret, TCGv arg)
B
bellard 已提交
873 874 875 876 877 878 879 880 881 882
{
#ifdef TCG_TARGET_HAS_ext16s_i32
    tcg_gen_op2(INDEX_op_ext16s_i32, ret, arg);
#else
    tcg_gen_shli_i32(ret, arg, 16);
    tcg_gen_sari_i32(ret, arg, 16);
#endif
}

/* Note: we assume the two high bytes are set to zero */
P
pbrook 已提交
883
static inline void tcg_gen_bswap16_i32(TCGv ret, TCGv arg)
B
bellard 已提交
884 885 886 887
{
#ifdef TCG_TARGET_HAS_bswap16_i32
    tcg_gen_op2(INDEX_op_bswap16_i32, ret, arg);
#else
P
pbrook 已提交
888
    TCGv t0, t1;
B
bellard 已提交
889 890 891 892 893 894 895 896 897 898
    t0 = tcg_temp_new(TCG_TYPE_I32);
    t1 = tcg_temp_new(TCG_TYPE_I32);
    
    tcg_gen_shri_i32(t0, arg, 8);
    tcg_gen_andi_i32(t1, arg, 0x000000ff);
    tcg_gen_shli_i32(t1, t1, 8);
    tcg_gen_or_i32(ret, t0, t1);
#endif
}

P
pbrook 已提交
899
static inline void tcg_gen_bswap_i32(TCGv ret, TCGv arg)
B
bellard 已提交
900 901 902 903
{
#ifdef TCG_TARGET_HAS_bswap_i32
    tcg_gen_op2(INDEX_op_bswap_i32, ret, arg);
#else
P
pbrook 已提交
904
    TCGv t0, t1;
B
bellard 已提交
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
    t0 = tcg_temp_new(TCG_TYPE_I32);
    t1 = tcg_temp_new(TCG_TYPE_I32);
    
    tcg_gen_shli_i32(t0, arg, 24);
    
    tcg_gen_andi_i32(t1, arg, 0x0000ff00);
    tcg_gen_shli_i32(t1, t1, 8);
    tcg_gen_or_i32(t0, t0, t1);
    
    tcg_gen_shri_i32(t1, arg, 8);
    tcg_gen_andi_i32(t1, t1, 0x0000ff00);
    tcg_gen_or_i32(t0, t0, t1);
    
    tcg_gen_shri_i32(t1, arg, 24);
    tcg_gen_or_i32(ret, t0, t1);
#endif
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
924
static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
B
bellard 已提交
925 926
{
    tcg_gen_ext8s_i32(ret, arg);
P
pbrook 已提交
927
    tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
B
bellard 已提交
928 929
}

P
pbrook 已提交
930
static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
B
bellard 已提交
931 932
{
    tcg_gen_ext16s_i32(ret, arg);
P
pbrook 已提交
933
    tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
B
bellard 已提交
934 935
}

P
pbrook 已提交
936
static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
B
bellard 已提交
937 938
{
    tcg_gen_mov_i32(ret, arg);
P
pbrook 已提交
939
    tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
B
bellard 已提交
940 941
}

P
pbrook 已提交
942
static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
B
bellard 已提交
943 944 945 946
{
    tcg_gen_mov_i32(ret, arg);
}

P
pbrook 已提交
947
static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
B
bellard 已提交
948 949
{
    tcg_gen_mov_i32(ret, arg);
P
pbrook 已提交
950
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
951 952
}

P
pbrook 已提交
953
static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
B
bellard 已提交
954 955
{
    tcg_gen_mov_i32(ret, arg);
P
pbrook 已提交
956
    tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
B
bellard 已提交
957 958
}

P
pbrook 已提交
959
static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
B
bellard 已提交
960
{
P
pbrook 已提交
961
    TCGv t0, t1;
B
bellard 已提交
962 963 964 965
    t0 = tcg_temp_new(TCG_TYPE_I32);
    t1 = tcg_temp_new(TCG_TYPE_I32);

    tcg_gen_bswap_i32(t0, arg);
P
pbrook 已提交
966
    tcg_gen_bswap_i32(t1, TCGV_HIGH(arg));
B
bellard 已提交
967
    tcg_gen_mov_i32(ret, t1);
P
pbrook 已提交
968
    tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
B
bellard 已提交
969 970 971
}
#else

P
pbrook 已提交
972
static inline void tcg_gen_ext8s_i64(TCGv ret, TCGv arg)
B
bellard 已提交
973 974 975 976 977 978 979 980 981
{
#ifdef TCG_TARGET_HAS_ext8s_i64
    tcg_gen_op2(INDEX_op_ext8s_i64, ret, arg);
#else
    tcg_gen_shli_i64(ret, arg, 56);
    tcg_gen_sari_i64(ret, arg, 56);
#endif
}

P
pbrook 已提交
982
static inline void tcg_gen_ext16s_i64(TCGv ret, TCGv arg)
B
bellard 已提交
983 984 985 986 987 988 989 990 991
{
#ifdef TCG_TARGET_HAS_ext16s_i64
    tcg_gen_op2(INDEX_op_ext16s_i64, ret, arg);
#else
    tcg_gen_shli_i64(ret, arg, 48);
    tcg_gen_sari_i64(ret, arg, 48);
#endif
}

P
pbrook 已提交
992
static inline void tcg_gen_ext32s_i64(TCGv ret, TCGv arg)
B
bellard 已提交
993 994 995 996 997 998 999 1000 1001 1002
{
#ifdef TCG_TARGET_HAS_ext32s_i64
    tcg_gen_op2(INDEX_op_ext32s_i64, ret, arg);
#else
    tcg_gen_shli_i64(ret, arg, 32);
    tcg_gen_sari_i64(ret, arg, 32);
#endif
}

/* Note: we assume the target supports move between 32 and 64 bit
P
pbrook 已提交
1003 1004
   registers.  This will probably break MIPS64 targets.  */
static inline void tcg_gen_trunc_i64_i32(TCGv ret, TCGv arg)
B
bellard 已提交
1005 1006 1007 1008 1009 1010
{
    tcg_gen_mov_i32(ret, arg);
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1011
static inline void tcg_gen_extu_i32_i64(TCGv ret, TCGv arg)
B
bellard 已提交
1012 1013 1014 1015 1016 1017
{
    tcg_gen_andi_i64(ret, arg, 0xffffffff);
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1018
static inline void tcg_gen_ext_i32_i64(TCGv ret, TCGv arg)
B
bellard 已提交
1019 1020 1021 1022
{
    tcg_gen_ext32s_i64(ret, arg);
}

P
pbrook 已提交
1023
static inline void tcg_gen_bswap_i64(TCGv ret, TCGv arg)
B
bellard 已提交
1024 1025 1026 1027
{
#ifdef TCG_TARGET_HAS_bswap_i64
    tcg_gen_op2(INDEX_op_bswap_i64, ret, arg);
#else
P
pbrook 已提交
1028
    TCGv t0, t1;
B
bellard 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
    t0 = tcg_temp_new(TCG_TYPE_I32);
    t1 = tcg_temp_new(TCG_TYPE_I32);
    
    tcg_gen_shli_i64(t0, arg, 56);
    
    tcg_gen_andi_i64(t1, arg, 0x0000ff00);
    tcg_gen_shli_i64(t1, t1, 40);
    tcg_gen_or_i64(t0, t0, t1);
    
    tcg_gen_andi_i64(t1, arg, 0x00ff0000);
    tcg_gen_shli_i64(t1, t1, 24);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_andi_i64(t1, arg, 0xff000000);
    tcg_gen_shli_i64(t1, t1, 8);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_shri_i64(t1, arg, 8);
    tcg_gen_andi_i64(t1, t1, 0xff000000);
    tcg_gen_or_i64(t0, t0, t1);
    
    tcg_gen_shri_i64(t1, arg, 24);
    tcg_gen_andi_i64(t1, t1, 0x00ff0000);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_shri_i64(t1, arg, 40);
    tcg_gen_andi_i64(t1, t1, 0x0000ff00);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_shri_i64(t1, arg, 56);
    tcg_gen_or_i64(ret, t0, t1);
#endif
}

#endif

/***************************************/
P
pbrook 已提交
1066
static inline void tcg_gen_macro_2(TCGv ret0, TCGv ret1, int macro_id)
B
bellard 已提交
1067
{
P
pbrook 已提交
1068
    tcg_gen_op3i(INDEX_op_macro_2, ret0, ret1, macro_id);
B
bellard 已提交
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
}

/***************************************/
/* QEMU specific operations. Their type depend on the QEMU CPU
   type. */
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
#endif

static inline void tcg_gen_exit_tb(tcg_target_long val)
{
P
pbrook 已提交
1080
    tcg_gen_op1i(INDEX_op_exit_tb, val);
B
bellard 已提交
1081 1082 1083 1084
}

static inline void tcg_gen_goto_tb(int idx)
{
P
pbrook 已提交
1085
    tcg_gen_op1i(INDEX_op_goto_tb, idx);
B
bellard 已提交
1086 1087 1088
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1089
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1090 1091
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1092
    tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
1093
#else
P
pbrook 已提交
1094 1095
    tcg_gen_op4i(INDEX_op_qemu_ld8u, ret, addr, TCGV_HIGH(addr), mem_index);
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1096 1097 1098
#endif
}

P
pbrook 已提交
1099
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1100 1101
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1102
    tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
1103
#else
P
pbrook 已提交
1104 1105
    tcg_gen_op4i(INDEX_op_qemu_ld8s, ret, addr, TCGV_HIGH(addr), mem_index);
    tcg_gen_ext8s_i32(TCGV_HIGH(ret), ret);
B
bellard 已提交
1106 1107 1108
#endif
}

P
pbrook 已提交
1109
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1110 1111
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1112
    tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
1113
#else
P
pbrook 已提交
1114 1115
    tcg_gen_op4i(INDEX_op_qemu_ld16u, ret, addr, TCGV_HIGH(addr), mem_index);
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1116 1117 1118
#endif
}

P
pbrook 已提交
1119
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1120 1121
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1122
    tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
1123
#else
P
pbrook 已提交
1124 1125
    tcg_gen_op4i(INDEX_op_qemu_ld16s, ret, addr, TCGV_HIGH(addr), mem_index);
    tcg_gen_ext16s_i32(TCGV_HIGH(ret), ret);
B
bellard 已提交
1126 1127 1128
#endif
}

P
pbrook 已提交
1129
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1130 1131
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1132
    tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1133
#else
P
pbrook 已提交
1134 1135
    tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1136 1137 1138
#endif
}

P
pbrook 已提交
1139
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1140 1141
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1142
    tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1143
#else
P
pbrook 已提交
1144 1145
    tcg_gen_op4i(INDEX_op_qemu_ld32u, ret, addr, TCGV_HIGH(addr), mem_index);
    tcg_gen_sari_i32(TCGV_HIGH(ret), ret, 31);
B
bellard 已提交
1146 1147 1148
#endif
}

P
pbrook 已提交
1149
static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1150 1151
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1152
    tcg_gen_op4i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret), addr, mem_index);
B
bellard 已提交
1153
#else
P
pbrook 已提交
1154 1155
    tcg_gen_op5i(INDEX_op_qemu_ld64, ret, TCGV_HIGH(ret),
                 addr, TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1156 1157 1158
#endif
}

P
pbrook 已提交
1159
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1160 1161
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1162
    tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
1163
#else
P
pbrook 已提交
1164
    tcg_gen_op4i(INDEX_op_qemu_st8, arg, addr, TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1165 1166 1167
#endif
}

P
pbrook 已提交
1168
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1169 1170
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1171
    tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
1172
#else
P
pbrook 已提交
1173
    tcg_gen_op4i(INDEX_op_qemu_st16, arg, addr, TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1174 1175 1176
#endif
}

P
pbrook 已提交
1177
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1178 1179
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1180
    tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
1181
#else
P
pbrook 已提交
1182
    tcg_gen_op4i(INDEX_op_qemu_st32, arg, addr, TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1183 1184 1185
#endif
}

P
pbrook 已提交
1186
static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1187 1188
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1189
    tcg_gen_op4i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg), addr, mem_index);
B
bellard 已提交
1190
#else
P
pbrook 已提交
1191 1192
    tcg_gen_op5i(INDEX_op_qemu_st64, arg, TCGV_HIGH(arg),
                 addr, TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1193 1194 1195 1196 1197
#endif
}

#else /* TCG_TARGET_REG_BITS == 32 */

P
pbrook 已提交
1198
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1199
{
P
pbrook 已提交
1200
    tcg_gen_op3i(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
1201 1202
}

P
pbrook 已提交
1203
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1204
{
P
pbrook 已提交
1205
    tcg_gen_op3i(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
1206 1207
}

P
pbrook 已提交
1208
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1209
{
P
pbrook 已提交
1210
    tcg_gen_op3i(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
1211 1212
}

P
pbrook 已提交
1213
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1214
{
P
pbrook 已提交
1215
    tcg_gen_op3i(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
1216 1217
}

P
pbrook 已提交
1218
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1219
{
P
pbrook 已提交
1220
    tcg_gen_op3i(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1221 1222
}

P
pbrook 已提交
1223
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1224
{
P
pbrook 已提交
1225
    tcg_gen_op3i(INDEX_op_qemu_ld32s, ret, addr, mem_index);
B
bellard 已提交
1226 1227
}

P
pbrook 已提交
1228
static inline void tcg_gen_qemu_ld64(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1229
{
P
pbrook 已提交
1230
    tcg_gen_op3i(INDEX_op_qemu_ld64, ret, addr, mem_index);
B
bellard 已提交
1231 1232
}

P
pbrook 已提交
1233
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1234
{
P
pbrook 已提交
1235
    tcg_gen_op3i(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
1236 1237
}

P
pbrook 已提交
1238
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1239
{
P
pbrook 已提交
1240
    tcg_gen_op3i(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
1241 1242
}

P
pbrook 已提交
1243
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1244
{
P
pbrook 已提交
1245
    tcg_gen_op3i(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
1246 1247
}

P
pbrook 已提交
1248
static inline void tcg_gen_qemu_st64(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1249
{
P
pbrook 已提交
1250
    tcg_gen_op3i(INDEX_op_qemu_st64, arg, addr, mem_index);
B
bellard 已提交
1251 1252 1253
}

#endif /* TCG_TARGET_REG_BITS != 32 */