tcg-op.h 62.9 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
/*
 * 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"

int gen_new_label(void);

P
pbrook 已提交
28
static inline void tcg_gen_op1_i32(int opc, TCGv_i32 arg1)
B
bellard 已提交
29 30
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
31 32 33 34 35 36 37
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
}

static inline void tcg_gen_op1_i64(int opc, TCGv_i64 arg1)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
B
bellard 已提交
38 39
}

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

P
pbrook 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
static inline void tcg_gen_op2_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
}

static inline void tcg_gen_op2_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
}

static inline void tcg_gen_op2i_i32(int opc, TCGv_i32 arg1, TCGArg arg2)
B
bellard 已提交
61 62
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
63 64
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = arg2;
B
bellard 已提交
65 66
}

P
pbrook 已提交
67
static inline void tcg_gen_op2i_i64(int opc, TCGv_i64 arg1, TCGArg arg2)
B
bellard 已提交
68 69
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
70
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
B
bellard 已提交
71
    *gen_opparam_ptr++ = arg2;
P
pbrook 已提交
72 73
}

P
pbrook 已提交
74 75 76 77 78 79 80
static inline void tcg_gen_op2ii(int opc, TCGArg arg1, TCGArg arg2)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = arg1;
    *gen_opparam_ptr++ = arg2;
}

P
pbrook 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
static inline void tcg_gen_op3_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                   TCGv_i32 arg3)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
}

static inline void tcg_gen_op3_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                   TCGv_i64 arg3)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
}

static inline void tcg_gen_op3i_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                    TCGArg arg3)
P
pbrook 已提交
101 102
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
103 104 105
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = arg3;
P
pbrook 已提交
106 107
}

P
pbrook 已提交
108 109
static inline void tcg_gen_op3i_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                    TCGArg arg3)
P
pbrook 已提交
110 111
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
112 113
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
B
bellard 已提交
114
    *gen_opparam_ptr++ = arg3;
P
pbrook 已提交
115 116
}

P
pbrook 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129
static inline void tcg_gen_ldst_op_i32(int opc, TCGv_i32 val, TCGv_ptr base,
                                       TCGArg offset)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(val);
    *gen_opparam_ptr++ = GET_TCGV_PTR(base);
    *gen_opparam_ptr++ = offset;
}

static inline void tcg_gen_ldst_op_i64(int opc, TCGv_i64 val, TCGv_ptr base,
                                       TCGArg offset)
{
    *gen_opc_ptr++ = opc;
B
blueswir1 已提交
130
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
P
pbrook 已提交
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    *gen_opparam_ptr++ = GET_TCGV_PTR(base);
    *gen_opparam_ptr++ = offset;
}

static inline void tcg_gen_qemu_ldst_op_i64_i32(int opc, TCGv_i64 val, TCGv_i32 addr,
                                                TCGArg mem_index)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
    *gen_opparam_ptr++ = GET_TCGV_I32(addr);
    *gen_opparam_ptr++ = mem_index;
}

static inline void tcg_gen_qemu_ldst_op_i64_i64(int opc, TCGv_i64 val, TCGv_i64 addr,
                                                TCGArg mem_index)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
    *gen_opparam_ptr++ = GET_TCGV_I64(addr);
    *gen_opparam_ptr++ = mem_index;
}

static inline void tcg_gen_op4_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                   TCGv_i32 arg3, TCGv_i32 arg4)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
}

static inline void tcg_gen_op4_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
B
blueswir1 已提交
164
                                   TCGv_i64 arg3, TCGv_i64 arg4)
P
pbrook 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
}

static inline void tcg_gen_op4i_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                    TCGv_i32 arg3, TCGArg arg4)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = arg4;
}

static inline void tcg_gen_op4i_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                    TCGv_i64 arg3, TCGArg arg4)
P
pbrook 已提交
185 186
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
187 188 189 190
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = arg4;
P
pbrook 已提交
191 192
}

P
pbrook 已提交
193 194
static inline void tcg_gen_op4ii_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                     TCGArg arg3, TCGArg arg4)
P
pbrook 已提交
195 196
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
197 198 199
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = arg3;
B
bellard 已提交
200 201 202
    *gen_opparam_ptr++ = arg4;
}

P
pbrook 已提交
203 204
static inline void tcg_gen_op4ii_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                     TCGArg arg3, TCGArg arg4)
B
bellard 已提交
205 206
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
207 208
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
B
bellard 已提交
209 210
    *gen_opparam_ptr++ = arg3;
    *gen_opparam_ptr++ = arg4;
P
pbrook 已提交
211 212
}

P
pbrook 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
static inline void tcg_gen_op5_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                   TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
}

static inline void tcg_gen_op5_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                   TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
}

static inline void tcg_gen_op5i_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                    TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
P
pbrook 已提交
237 238
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
239 240 241 242 243
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
    *gen_opparam_ptr++ = arg5;
P
pbrook 已提交
244 245
}

P
pbrook 已提交
246 247
static inline void tcg_gen_op5i_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                    TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
P
pbrook 已提交
248 249
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
250 251 252 253
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
B
bellard 已提交
254 255 256
    *gen_opparam_ptr++ = arg5;
}

P
pbrook 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
static inline void tcg_gen_op6_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                   TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
                                   TCGv_i32 arg6)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg6);
}

static inline void tcg_gen_op6_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                   TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
                                   TCGv_i64 arg6)
B
bellard 已提交
273 274
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
275 276 277 278 279 280
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg6);
P
pbrook 已提交
281 282
}

P
pbrook 已提交
283 284 285
static inline void tcg_gen_op6ii_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                     TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5,
                                     TCGArg arg6)
P
pbrook 已提交
286 287
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
    *gen_opparam_ptr++ = arg5;
    *gen_opparam_ptr++ = arg6;
}

static inline void tcg_gen_op6ii_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                     TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5,
                                     TCGArg arg6)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
B
bellard 已提交
305 306 307 308 309 310
    *gen_opparam_ptr++ = arg5;
    *gen_opparam_ptr++ = arg6;
}

static inline void gen_set_label(int n)
{
P
pbrook 已提交
311
    tcg_gen_op1i(INDEX_op_set_label, n);
B
bellard 已提交
312 313
}

B
blueswir1 已提交
314 315 316 317 318
static inline void tcg_gen_br(int label)
{
    tcg_gen_op1i(INDEX_op_br, label);
}

P
pbrook 已提交
319
static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
320
{
A
aurel32 已提交
321
    if (!TCGV_EQUAL_I32(ret, arg))
P
pbrook 已提交
322
        tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
B
bellard 已提交
323 324
}

P
pbrook 已提交
325
static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
B
bellard 已提交
326
{
P
pbrook 已提交
327
    tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
B
bellard 已提交
328 329 330
}

/* helper calls */
P
pbrook 已提交
331 332 333 334 335 336 337 338 339
static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
                                   TCGArg ret, int nargs, TCGArg *args)
{
    TCGv_ptr fn;
    fn = tcg_const_ptr((tcg_target_long)func);
    tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
                  nargs, args);
    tcg_temp_free_ptr(fn);
}
B
bellard 已提交
340

P
pbrook 已提交
341 342 343
/* FIXME: Should this be pure?  */
static inline void tcg_gen_helper64(void *func, TCGv_i64 ret,
                                    TCGv_i64 a, TCGv_i64 b)
B
bellard 已提交
344
{
P
pbrook 已提交
345 346 347 348 349 350 351
    TCGv_ptr fn;
    TCGArg args[2];
    fn = tcg_const_ptr((tcg_target_long)func);
    args[0] = GET_TCGV_I64(a);
    args[1] = GET_TCGV_I64(b);
    tcg_gen_callN(&tcg_ctx, fn, 0, 7, GET_TCGV_I64(ret), 2, args);
    tcg_temp_free_ptr(fn);
352 353
}

B
bellard 已提交
354 355
/* 32 bit ops */

P
pbrook 已提交
356
static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
357
{
P
pbrook 已提交
358
    tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
B
bellard 已提交
359 360
}

P
pbrook 已提交
361
static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
362
{
P
pbrook 已提交
363
    tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
B
bellard 已提交
364 365
}

P
pbrook 已提交
366
static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
367
{
P
pbrook 已提交
368
    tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
B
bellard 已提交
369 370
}

P
pbrook 已提交
371
static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
372
{
P
pbrook 已提交
373
    tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
B
bellard 已提交
374 375
}

P
pbrook 已提交
376
static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
377
{
P
pbrook 已提交
378
    tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
B
bellard 已提交
379 380
}

P
pbrook 已提交
381
static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
382
{
P
pbrook 已提交
383
    tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
B
bellard 已提交
384 385
}

P
pbrook 已提交
386
static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
387
{
P
pbrook 已提交
388
    tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
B
bellard 已提交
389 390
}

P
pbrook 已提交
391
static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
392
{
P
pbrook 已提交
393
    tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
B
bellard 已提交
394 395
}

P
pbrook 已提交
396
static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
397
{
P
pbrook 已提交
398
    tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
B
bellard 已提交
399 400
}

P
pbrook 已提交
401
static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
402
{
403 404 405 406
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
407
        TCGv_i32 t0 = tcg_const_i32(arg2);
408
        tcg_gen_add_i32(ret, arg1, t0);
P
pbrook 已提交
409
        tcg_temp_free_i32(t0);
410
    }
B
bellard 已提交
411 412
}

P
pbrook 已提交
413
static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
414
{
P
pbrook 已提交
415
    tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
B
bellard 已提交
416 417
}

P
pbrook 已提交
418
static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
A
aurel32 已提交
419
{
P
pbrook 已提交
420
    TCGv_i32 t0 = tcg_const_i32(arg1);
A
aurel32 已提交
421
    tcg_gen_sub_i32(ret, t0, arg2);
P
pbrook 已提交
422
    tcg_temp_free_i32(t0);
A
aurel32 已提交
423 424
}

P
pbrook 已提交
425
static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
426
{
427 428 429 430
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
431
        TCGv_i32 t0 = tcg_const_i32(arg2);
432
        tcg_gen_sub_i32(ret, arg1, t0);
P
pbrook 已提交
433
        tcg_temp_free_i32(t0);
434
    }
B
bellard 已提交
435 436
}

P
pbrook 已提交
437
static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
438
{
A
aurel32 已提交
439 440 441 442 443
    if (TCGV_EQUAL_I32(arg1, arg2)) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
        tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
    }
B
bellard 已提交
444 445
}

P
pbrook 已提交
446
static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
447 448 449 450 451 452 453
{
    /* 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 {
P
pbrook 已提交
454
        TCGv_i32 t0 = tcg_const_i32(arg2);
455
        tcg_gen_and_i32(ret, arg1, t0);
P
pbrook 已提交
456
        tcg_temp_free_i32(t0);
B
bellard 已提交
457 458 459
    }
}

P
pbrook 已提交
460
static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
461
{
A
aurel32 已提交
462 463 464 465 466
    if (TCGV_EQUAL_I32(arg1, arg2)) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
        tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
    }
B
bellard 已提交
467 468
}

P
pbrook 已提交
469
static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
470 471 472
{
    /* some cases can be optimized here */
    if (arg2 == 0xffffffff) {
473
        tcg_gen_movi_i32(ret, 0xffffffff);
B
bellard 已提交
474 475 476
    } else if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
477
        TCGv_i32 t0 = tcg_const_i32(arg2);
478
        tcg_gen_or_i32(ret, arg1, t0);
P
pbrook 已提交
479
        tcg_temp_free_i32(t0);
B
bellard 已提交
480 481 482
    }
}

P
pbrook 已提交
483
static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
484
{
A
aurel32 已提交
485 486 487 488 489
    if (TCGV_EQUAL_I32(arg1, arg2)) {
        tcg_gen_movi_i32(ret, 0);
    } else {
        tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
    }
B
bellard 已提交
490 491
}

P
pbrook 已提交
492
static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
493 494 495 496 497
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
498
        TCGv_i32 t0 = tcg_const_i32(arg2);
499
        tcg_gen_xor_i32(ret, arg1, t0);
P
pbrook 已提交
500
        tcg_temp_free_i32(t0);
B
bellard 已提交
501 502 503
    }
}

P
pbrook 已提交
504
static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
505
{
P
pbrook 已提交
506
    tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
B
bellard 已提交
507 508
}

P
pbrook 已提交
509
static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
510
{
B
bellard 已提交
511 512 513
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
514
        TCGv_i32 t0 = tcg_const_i32(arg2);
515
        tcg_gen_shl_i32(ret, arg1, t0);
P
pbrook 已提交
516
        tcg_temp_free_i32(t0);
B
bellard 已提交
517
    }
B
bellard 已提交
518 519
}

P
pbrook 已提交
520
static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
521
{
P
pbrook 已提交
522
    tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
B
bellard 已提交
523 524
}

P
pbrook 已提交
525
static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
526
{
B
bellard 已提交
527 528 529
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
530
        TCGv_i32 t0 = tcg_const_i32(arg2);
531
        tcg_gen_shr_i32(ret, arg1, t0);
P
pbrook 已提交
532
        tcg_temp_free_i32(t0);
B
bellard 已提交
533
    }
B
bellard 已提交
534 535
}

P
pbrook 已提交
536
static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
537
{
P
pbrook 已提交
538
    tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
B
bellard 已提交
539 540
}

P
pbrook 已提交
541
static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
542
{
B
bellard 已提交
543 544 545
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
546
        TCGv_i32 t0 = tcg_const_i32(arg2);
547
        tcg_gen_sar_i32(ret, arg1, t0);
P
pbrook 已提交
548
        tcg_temp_free_i32(t0);
B
bellard 已提交
549
    }
B
bellard 已提交
550 551
}

P
pbrook 已提交
552
static inline void tcg_gen_brcond_i32(int cond, TCGv_i32 arg1, TCGv_i32 arg2,
B
bellard 已提交
553 554
                                      int label_index)
{
P
pbrook 已提交
555
    tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
B
bellard 已提交
556 557
}

P
pbrook 已提交
558
static inline void tcg_gen_brcondi_i32(int cond, TCGv_i32 arg1, int32_t arg2,
P
pbrook 已提交
559 560
                                       int label_index)
{
P
pbrook 已提交
561
    TCGv_i32 t0 = tcg_const_i32(arg2);
P
pbrook 已提交
562
    tcg_gen_brcond_i32(cond, arg1, t0, label_index);
P
pbrook 已提交
563
    tcg_temp_free_i32(t0);
P
pbrook 已提交
564 565
}

P
pbrook 已提交
566
static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
567
{
P
pbrook 已提交
568
    tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
B
bellard 已提交
569 570
}

P
pbrook 已提交
571
static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
572
{
P
pbrook 已提交
573
    TCGv_i32 t0 = tcg_const_i32(arg2);
574
    tcg_gen_mul_i32(ret, arg1, t0);
P
pbrook 已提交
575
    tcg_temp_free_i32(t0);
576 577
}

B
bellard 已提交
578
#ifdef TCG_TARGET_HAS_div_i32
P
pbrook 已提交
579
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
580
{
P
pbrook 已提交
581
    tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
B
bellard 已提交
582 583
}

P
pbrook 已提交
584
static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
585
{
P
pbrook 已提交
586
    tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
B
bellard 已提交
587 588
}

P
pbrook 已提交
589
static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
590
{
P
pbrook 已提交
591
    tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
B
bellard 已提交
592 593
}

P
pbrook 已提交
594
static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
595
{
P
pbrook 已提交
596
    tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
B
bellard 已提交
597 598
}
#else
P
pbrook 已提交
599
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
600
{
P
pbrook 已提交
601 602
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
603
    tcg_gen_sari_i32(t0, arg1, 31);
P
pbrook 已提交
604 605
    tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
606 607
}

P
pbrook 已提交
608
static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
609
{
P
pbrook 已提交
610 611
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
612
    tcg_gen_sari_i32(t0, arg1, 31);
P
pbrook 已提交
613 614
    tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
615 616
}

P
pbrook 已提交
617
static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
618
{
P
pbrook 已提交
619 620
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
621
    tcg_gen_movi_i32(t0, 0);
P
pbrook 已提交
622 623
    tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
624 625
}

P
pbrook 已提交
626
static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
627
{
P
pbrook 已提交
628 629
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
630
    tcg_gen_movi_i32(t0, 0);
P
pbrook 已提交
631 632
    tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
633 634 635 636 637
}
#endif

#if TCG_TARGET_REG_BITS == 32

P
pbrook 已提交
638
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
639
{
A
aurel32 已提交
640
    if (!TCGV_EQUAL_I64(ret, arg)) {
P
pbrook 已提交
641
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
642 643
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
    }
B
bellard 已提交
644 645
}

P
pbrook 已提交
646
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
647
{
P
pbrook 已提交
648
    tcg_gen_movi_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
649
    tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
B
bellard 已提交
650 651
}

P
pbrook 已提交
652 653
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
654
{
P
pbrook 已提交
655
    tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
656
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
657 658
}

P
pbrook 已提交
659 660
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
661
{
P
pbrook 已提交
662 663
    tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
B
bellard 已提交
664 665
}

P
pbrook 已提交
666 667
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
668
{
A
aurel32 已提交
669
    tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
670
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
671 672
}

P
pbrook 已提交
673 674
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
675
{
P
pbrook 已提交
676 677
    tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
678 679
}

P
pbrook 已提交
680 681
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
682
{
P
pbrook 已提交
683
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
684
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
685 686
}

P
pbrook 已提交
687 688
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
689
{
P
pbrook 已提交
690 691
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
692 693
}

P
pbrook 已提交
694 695
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
696 697 698 699
{
    /* since arg2 and ret have different types, they cannot be the
       same temporary */
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
700
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
P
pbrook 已提交
701
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
B
bellard 已提交
702
#else
P
pbrook 已提交
703
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
704
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
B
bellard 已提交
705 706 707
#endif
}

P
pbrook 已提交
708 709
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                   tcg_target_long offset)
B
bellard 已提交
710
{
P
pbrook 已提交
711
    tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
712 713
}

P
pbrook 已提交
714 715
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
716
{
P
pbrook 已提交
717
    tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
718 719
}

P
pbrook 已提交
720 721
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
722
{
P
pbrook 已提交
723
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
724 725
}

P
pbrook 已提交
726 727
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
728 729
{
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
730
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
P
pbrook 已提交
731
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
B
bellard 已提交
732
#else
P
pbrook 已提交
733
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
P
pbrook 已提交
734
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
B
bellard 已提交
735 736 737
#endif
}

P
pbrook 已提交
738
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
739
{
P
pbrook 已提交
740 741 742
    tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
                    TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
                    TCGV_HIGH(arg2));
B
bellard 已提交
743 744
}

P
pbrook 已提交
745
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
746
{
P
pbrook 已提交
747 748 749
    tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
                    TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
                    TCGV_HIGH(arg2));
B
bellard 已提交
750 751
}

P
pbrook 已提交
752
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
753
{
P
pbrook 已提交
754
    tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
755
    tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
756 757
}

P
pbrook 已提交
758
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
759
{
A
aurel32 已提交
760 761
    tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
    tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
762 763
}

P
pbrook 已提交
764
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
765
{
A
aurel32 已提交
766 767
    tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
    tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
768 769
}

P
pbrook 已提交
770
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
771
{
P
pbrook 已提交
772
    tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
773
    tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
774 775
}

P
pbrook 已提交
776
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
777
{
A
aurel32 已提交
778 779
    tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
    tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
780 781
}

P
pbrook 已提交
782
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
783
{
P
pbrook 已提交
784
    tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
785
    tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
786 787 788 789
}

/* XXX: use generic code when basic block handling is OK or CPU
   specific code (x86) */
P
pbrook 已提交
790
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
791
{
P
pbrook 已提交
792
    tcg_gen_helper64(tcg_helper_shl_i64, ret, arg1, arg2);
B
bellard 已提交
793 794
}

P
pbrook 已提交
795
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
796 797 798 799
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
}

P
pbrook 已提交
800
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
801
{
P
pbrook 已提交
802
    tcg_gen_helper64(tcg_helper_shr_i64, ret, arg1, arg2);
B
bellard 已提交
803 804
}

P
pbrook 已提交
805
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
806 807 808 809
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
}

P
pbrook 已提交
810
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
811
{
P
pbrook 已提交
812
    tcg_gen_helper64(tcg_helper_sar_i64, ret, arg1, arg2);
B
bellard 已提交
813 814
}

P
pbrook 已提交
815
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
816 817 818 819
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
}

P
pbrook 已提交
820
static inline void tcg_gen_brcond_i64(int cond, TCGv_i64 arg1, TCGv_i64 arg2,
B
bellard 已提交
821 822
                                      int label_index)
{
P
pbrook 已提交
823 824 825
    tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
                      TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
                      TCGV_HIGH(arg2), cond, label_index);
B
bellard 已提交
826 827
}

P
pbrook 已提交
828
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
829
{
P
pbrook 已提交
830 831
    TCGv_i64 t0;
    TCGv_i32 t1;
B
bellard 已提交
832

P
pbrook 已提交
833 834 835 836 837 838 839
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i32();

    tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
                    TCGV_LOW(arg1), TCGV_LOW(arg2));

    tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
P
pbrook 已提交
840
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
841
    tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
842
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
843

B
bellard 已提交
844
    tcg_gen_mov_i64(ret, t0);
P
pbrook 已提交
845 846
    tcg_temp_free_i64(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
847 848
}

P
pbrook 已提交
849
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
850
{
P
pbrook 已提交
851
    tcg_gen_helper64(tcg_helper_div_i64, ret, arg1, arg2);
B
bellard 已提交
852 853
}

P
pbrook 已提交
854
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
855
{
P
pbrook 已提交
856
    tcg_gen_helper64(tcg_helper_rem_i64, ret, arg1, arg2);
B
bellard 已提交
857 858
}

P
pbrook 已提交
859
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
860
{
P
pbrook 已提交
861
    tcg_gen_helper64(tcg_helper_divu_i64, ret, arg1, arg2);
B
bellard 已提交
862 863
}

P
pbrook 已提交
864
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
865
{
P
pbrook 已提交
866
    tcg_gen_helper64(tcg_helper_remu_i64, ret, arg1, arg2);
B
bellard 已提交
867 868 869 870
}

#else

P
pbrook 已提交
871
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
872
{
A
aurel32 已提交
873
    if (!TCGV_EQUAL_I64(ret, arg))
P
pbrook 已提交
874
        tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
B
bellard 已提交
875 876
}

P
pbrook 已提交
877
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
878
{
P
pbrook 已提交
879
    tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
B
bellard 已提交
880 881
}

P
pbrook 已提交
882
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
883
                                    tcg_target_long offset)
B
bellard 已提交
884
{
P
pbrook 已提交
885
    tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
B
bellard 已提交
886 887
}

P
pbrook 已提交
888
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
889
                                    tcg_target_long offset)
B
bellard 已提交
890
{
P
pbrook 已提交
891
    tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
B
bellard 已提交
892 893
}

P
pbrook 已提交
894
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
895
                                     tcg_target_long offset)
B
bellard 已提交
896
{
P
pbrook 已提交
897
    tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
B
bellard 已提交
898 899
}

P
pbrook 已提交
900
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
901
                                     tcg_target_long offset)
B
bellard 已提交
902
{
P
pbrook 已提交
903
    tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
B
bellard 已提交
904 905
}

P
pbrook 已提交
906
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
907
                                     tcg_target_long offset)
B
bellard 已提交
908
{
P
pbrook 已提交
909
    tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
B
bellard 已提交
910 911
}

P
pbrook 已提交
912
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
913
                                     tcg_target_long offset)
B
bellard 已提交
914
{
P
pbrook 已提交
915
    tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
B
bellard 已提交
916 917
}

P
pbrook 已提交
918
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_i64 arg2, tcg_target_long offset)
B
bellard 已提交
919
{
P
pbrook 已提交
920
    tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
B
bellard 已提交
921 922
}

P
pbrook 已提交
923
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
924
                                   tcg_target_long offset)
B
bellard 已提交
925
{
P
pbrook 已提交
926
    tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
B
bellard 已提交
927 928
}

P
pbrook 已提交
929
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
930
                                    tcg_target_long offset)
B
bellard 已提交
931
{
P
pbrook 已提交
932
    tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
B
bellard 已提交
933 934
}

P
pbrook 已提交
935
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
936
                                    tcg_target_long offset)
B
bellard 已提交
937
{
P
pbrook 已提交
938
    tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
B
bellard 已提交
939 940
}

P
pbrook 已提交
941
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_i64 arg2, tcg_target_long offset)
B
bellard 已提交
942
{
P
pbrook 已提交
943
    tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
B
bellard 已提交
944 945
}

P
pbrook 已提交
946
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
947
{
P
pbrook 已提交
948
    tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
B
bellard 已提交
949 950
}

P
pbrook 已提交
951
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
952
{
P
pbrook 已提交
953
    tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
B
bellard 已提交
954 955
}

P
pbrook 已提交
956
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
957
{
A
aurel32 已提交
958 959 960 961 962
    if (TCGV_EQUAL_I64(arg1, arg2)) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
        tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
    }
B
bellard 已提交
963 964
}

P
pbrook 已提交
965
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
966
{
P
pbrook 已提交
967
    TCGv_i64 t0 = tcg_const_i64(arg2);
968
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
969
    tcg_temp_free_i64(t0);
B
bellard 已提交
970 971
}

P
pbrook 已提交
972
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
973
{
A
aurel32 已提交
974 975 976 977 978
    if (TCGV_EQUAL_I64(arg1, arg2)) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
        tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
    }
B
bellard 已提交
979 980
}

P
pbrook 已提交
981
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
982
{
P
pbrook 已提交
983
    TCGv_i64 t0 = tcg_const_i64(arg2);
984
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
985
    tcg_temp_free_i64(t0);
B
bellard 已提交
986 987
}

P
pbrook 已提交
988
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
989
{
A
aurel32 已提交
990 991 992 993 994
    if (TCGV_EQUAL_I64(arg1, arg2)) {
        tcg_gen_movi_i64(ret, 0);
    } else {
        tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
    }
B
bellard 已提交
995 996
}

P
pbrook 已提交
997
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
998
{
P
pbrook 已提交
999
    TCGv_i64 t0 = tcg_const_i64(arg2);
1000
    tcg_gen_xor_i64(ret, arg1, t0);
P
pbrook 已提交
1001
    tcg_temp_free_i64(t0);
B
bellard 已提交
1002 1003
}

P
pbrook 已提交
1004
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1005
{
P
pbrook 已提交
1006
    tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
B
bellard 已提交
1007 1008
}

P
pbrook 已提交
1009
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1010
{
B
bellard 已提交
1011 1012 1013
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1014
        TCGv_i64 t0 = tcg_const_i64(arg2);
1015
        tcg_gen_shl_i64(ret, arg1, t0);
P
pbrook 已提交
1016
        tcg_temp_free_i64(t0);
B
bellard 已提交
1017
    }
B
bellard 已提交
1018 1019
}

P
pbrook 已提交
1020
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1021
{
P
pbrook 已提交
1022
    tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
B
bellard 已提交
1023 1024
}

P
pbrook 已提交
1025
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1026
{
B
bellard 已提交
1027 1028 1029
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1030
        TCGv_i64 t0 = tcg_const_i64(arg2);
1031
        tcg_gen_shr_i64(ret, arg1, t0);
P
pbrook 已提交
1032
        tcg_temp_free_i64(t0);
B
bellard 已提交
1033
    }
B
bellard 已提交
1034 1035
}

P
pbrook 已提交
1036
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1037
{
P
pbrook 已提交
1038
    tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
B
bellard 已提交
1039 1040
}

P
pbrook 已提交
1041
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1042
{
B
bellard 已提交
1043 1044 1045
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1046
        TCGv_i64 t0 = tcg_const_i64(arg2);
1047
        tcg_gen_sar_i64(ret, arg1, t0);
P
pbrook 已提交
1048
        tcg_temp_free_i64(t0);
B
bellard 已提交
1049
    }
B
bellard 已提交
1050 1051
}

P
pbrook 已提交
1052
static inline void tcg_gen_brcond_i64(int cond, TCGv_i64 arg1, TCGv_i64 arg2,
B
bellard 已提交
1053 1054
                                      int label_index)
{
P
pbrook 已提交
1055
    tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
B
bellard 已提交
1056 1057
}

P
pbrook 已提交
1058
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1059
{
P
pbrook 已提交
1060
    tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
B
bellard 已提交
1061 1062 1063
}

#ifdef TCG_TARGET_HAS_div_i64
P
pbrook 已提交
1064
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1065
{
P
pbrook 已提交
1066
    tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
B
bellard 已提交
1067 1068
}

P
pbrook 已提交
1069
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1070
{
P
pbrook 已提交
1071
    tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
B
bellard 已提交
1072 1073
}

P
pbrook 已提交
1074
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1075
{
P
pbrook 已提交
1076
    tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
B
bellard 已提交
1077 1078
}

P
pbrook 已提交
1079
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1080
{
P
pbrook 已提交
1081
    tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
B
bellard 已提交
1082 1083
}
#else
P
pbrook 已提交
1084
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1085
{
P
pbrook 已提交
1086 1087
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1088
    tcg_gen_sari_i64(t0, arg1, 63);
P
pbrook 已提交
1089 1090
    tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1091 1092
}

P
pbrook 已提交
1093
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1094
{
P
pbrook 已提交
1095 1096
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1097
    tcg_gen_sari_i64(t0, arg1, 63);
P
pbrook 已提交
1098 1099
    tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1100 1101
}

P
pbrook 已提交
1102
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1103
{
P
pbrook 已提交
1104 1105
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1106
    tcg_gen_movi_i64(t0, 0);
P
pbrook 已提交
1107 1108
    tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1109 1110
}

P
pbrook 已提交
1111
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1112
{
P
pbrook 已提交
1113 1114
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1115
    tcg_gen_movi_i64(t0, 0);
P
pbrook 已提交
1116 1117
    tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1118 1119 1120 1121 1122
}
#endif

#endif

P
pbrook 已提交
1123
static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1124 1125 1126 1127 1128
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1129
        TCGv_i64 t0 = tcg_const_i64(arg2);
1130
        tcg_gen_add_i64(ret, arg1, t0);
P
pbrook 已提交
1131
        tcg_temp_free_i64(t0);
1132 1133 1134
    }
}

P
pbrook 已提交
1135
static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
A
aurel32 已提交
1136
{
P
pbrook 已提交
1137
    TCGv_i64 t0 = tcg_const_i64(arg1);
A
aurel32 已提交
1138
    tcg_gen_sub_i64(ret, t0, arg2);
P
pbrook 已提交
1139
    tcg_temp_free_i64(t0);
A
aurel32 已提交
1140 1141
}

P
pbrook 已提交
1142
static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1143 1144 1145 1146 1147
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1148
        TCGv_i64 t0 = tcg_const_i64(arg2);
1149
        tcg_gen_sub_i64(ret, arg1, t0);
P
pbrook 已提交
1150
        tcg_temp_free_i64(t0);
1151 1152
    }
}
P
pbrook 已提交
1153
static inline void tcg_gen_brcondi_i64(int cond, TCGv_i64 arg1, int64_t arg2,
1154 1155
                                       int label_index)
{
P
pbrook 已提交
1156
    TCGv_i64 t0 = tcg_const_i64(arg2);
1157
    tcg_gen_brcond_i64(cond, arg1, t0, label_index);
P
pbrook 已提交
1158
    tcg_temp_free_i64(t0);
1159 1160
}

P
pbrook 已提交
1161
static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1162
{
P
pbrook 已提交
1163
    TCGv_i64 t0 = tcg_const_i64(arg2);
1164
    tcg_gen_mul_i64(ret, arg1, t0);
P
pbrook 已提交
1165
    tcg_temp_free_i64(t0);
1166 1167
}

1168

B
bellard 已提交
1169 1170 1171
/***************************************/
/* optional operations */

P
pbrook 已提交
1172
static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1173 1174
{
#ifdef TCG_TARGET_HAS_ext8s_i32
P
pbrook 已提交
1175
    tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
B
bellard 已提交
1176 1177
#else
    tcg_gen_shli_i32(ret, arg, 24);
1178
    tcg_gen_sari_i32(ret, ret, 24);
B
bellard 已提交
1179 1180 1181
#endif
}

P
pbrook 已提交
1182
static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1183 1184
{
#ifdef TCG_TARGET_HAS_ext16s_i32
P
pbrook 已提交
1185
    tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
B
bellard 已提交
1186 1187
#else
    tcg_gen_shli_i32(ret, arg, 16);
1188
    tcg_gen_sari_i32(ret, ret, 16);
B
bellard 已提交
1189 1190 1191
#endif
}

P
pbrook 已提交
1192 1193
/* These are currently just for convenience.
   We assume a target will recognise these automatically .  */
P
pbrook 已提交
1194
static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1195 1196 1197 1198
{
    tcg_gen_andi_i32(ret, arg, 0xffu);
}

P
pbrook 已提交
1199
static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1200 1201 1202 1203
{
    tcg_gen_andi_i32(ret, arg, 0xffffu);
}

B
bellard 已提交
1204
/* Note: we assume the two high bytes are set to zero */
P
pbrook 已提交
1205
static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1206 1207
{
#ifdef TCG_TARGET_HAS_bswap16_i32
P
pbrook 已提交
1208
    tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
B
bellard 已提交
1209
#else
A
aurel32 已提交
1210
    TCGv_i32 t0 = tcg_temp_new_i32();
B
bellard 已提交
1211
    
A
aurel32 已提交
1212 1213 1214 1215
    tcg_gen_ext8u_i32(t0, arg);
    tcg_gen_shli_i32(t0, t0, 8);
    tcg_gen_shri_i32(ret, arg, 8);
    tcg_gen_or_i32(ret, ret, t0);
P
pbrook 已提交
1216
    tcg_temp_free_i32(t0);
B
bellard 已提交
1217 1218 1219
#endif
}

A
aurel32 已提交
1220
static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1221
{
A
aurel32 已提交
1222 1223
#ifdef TCG_TARGET_HAS_bswap32_i32
    tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
B
bellard 已提交
1224
#else
P
pbrook 已提交
1225 1226 1227
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
    
    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);
P
pbrook 已提交
1241 1242
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1243 1244 1245 1246
#endif
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1247
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1248
{
P
pbrook 已提交
1249 1250
    tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1251 1252
}

P
pbrook 已提交
1253
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1254
{
P
pbrook 已提交
1255 1256
    tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1257 1258
}

P
pbrook 已提交
1259
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1260
{
P
pbrook 已提交
1261 1262
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1263 1264
}

P
pbrook 已提交
1265
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1266
{
P
pbrook 已提交
1267
    tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1268 1269 1270
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1271
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1272
{
P
pbrook 已提交
1273
    tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1274 1275 1276
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1277
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1278
{
P
pbrook 已提交
1279
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1280 1281 1282
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1283
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1284
{
P
pbrook 已提交
1285
    tcg_gen_mov_i32(ret, TCGV_LOW(arg));
B
bellard 已提交
1286 1287
}

P
pbrook 已提交
1288
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1289
{
P
pbrook 已提交
1290
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
1291
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1292 1293
}

P
pbrook 已提交
1294
static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1295
{
P
pbrook 已提交
1296 1297
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1298 1299
}

1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
/* Note: we assume the six high bytes are set to zero */
static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
{
    tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
    tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
}

/* Note: we assume the four high bytes are set to zero */
static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
{
    tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
    tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
}

A
aurel32 已提交
1314
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1315
{
P
pbrook 已提交
1316 1317 1318
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1319

A
aurel32 已提交
1320 1321
    tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
    tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
P
pbrook 已提交
1322
    tcg_gen_mov_i32(TCGV_LOW(ret), t1);
P
pbrook 已提交
1323
    tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
P
pbrook 已提交
1324 1325
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1326 1327 1328
}
#else

P
pbrook 已提交
1329
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1330 1331
{
#ifdef TCG_TARGET_HAS_ext8s_i64
P
pbrook 已提交
1332
    tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
B
bellard 已提交
1333 1334
#else
    tcg_gen_shli_i64(ret, arg, 56);
1335
    tcg_gen_sari_i64(ret, ret, 56);
B
bellard 已提交
1336 1337 1338
#endif
}

P
pbrook 已提交
1339
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1340 1341
{
#ifdef TCG_TARGET_HAS_ext16s_i64
P
pbrook 已提交
1342
    tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
B
bellard 已提交
1343 1344
#else
    tcg_gen_shli_i64(ret, arg, 48);
1345
    tcg_gen_sari_i64(ret, ret, 48);
B
bellard 已提交
1346 1347 1348
#endif
}

P
pbrook 已提交
1349
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1350 1351
{
#ifdef TCG_TARGET_HAS_ext32s_i64
P
pbrook 已提交
1352
    tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
B
bellard 已提交
1353 1354
#else
    tcg_gen_shli_i64(ret, arg, 32);
1355
    tcg_gen_sari_i64(ret, ret, 32);
B
bellard 已提交
1356 1357 1358
#endif
}

P
pbrook 已提交
1359
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1360 1361 1362 1363
{
    tcg_gen_andi_i64(ret, arg, 0xffu);
}

P
pbrook 已提交
1364
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1365 1366 1367 1368
{
    tcg_gen_andi_i64(ret, arg, 0xffffu);
}

P
pbrook 已提交
1369
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1370 1371 1372 1373
{
    tcg_gen_andi_i64(ret, arg, 0xffffffffu);
}

B
bellard 已提交
1374
/* Note: we assume the target supports move between 32 and 64 bit
P
pbrook 已提交
1375
   registers.  This will probably break MIPS64 targets.  */
P
pbrook 已提交
1376
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1377
{
P
pbrook 已提交
1378
    tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
B
bellard 已提交
1379 1380 1381 1382
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1383
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1384
{
P
pbrook 已提交
1385
    tcg_gen_andi_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)), 0xffffffffu);
B
bellard 已提交
1386 1387 1388 1389
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1390
static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1391
{
P
pbrook 已提交
1392
    tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
B
bellard 已提交
1393 1394
}

1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
/* Note: we assume the six high bytes are set to zero */
static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
{
#ifdef TCG_TARGET_HAS_bswap16_i64
    tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
#else
    TCGv_i64 t0 = tcg_temp_new_i64();

    tcg_gen_ext8u_i64(t0, arg);
    tcg_gen_shli_i64(t0, t0, 8);
    tcg_gen_shri_i64(ret, arg, 8);
    tcg_gen_or_i64(ret, ret, t0);
    tcg_temp_free_i64(t0);
#endif
}

/* Note: we assume the four high bytes are set to zero */
static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
{
#ifdef TCG_TARGET_HAS_bswap32_i64
    tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
#else
    TCGv_i64 t0, t1;
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();

    tcg_gen_shli_i64(t0, arg, 24);
    tcg_gen_ext32u_i64(t0, t0);

    tcg_gen_andi_i64(t1, arg, 0x0000ff00);
    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, 0x0000ff00);
    tcg_gen_or_i64(t0, t0, t1);

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

A
aurel32 已提交
1439
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1440
{
A
aurel32 已提交
1441 1442
#ifdef TCG_TARGET_HAS_bswap64_i64
    tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
B
bellard 已提交
1443
#else
P
pbrook 已提交
1444 1445 1446
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475
    
    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);
P
pbrook 已提交
1476 1477
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1478 1479 1480 1481 1482
#endif
}

#endif

P
pbrook 已提交
1483
static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1484 1485
{
#ifdef TCG_TARGET_HAS_neg_i32
P
pbrook 已提交
1486
    tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
P
pbrook 已提交
1487
#else
P
pbrook 已提交
1488
    TCGv_i32 t0 = tcg_const_i32(0);
1489
    tcg_gen_sub_i32(ret, t0, arg);
P
pbrook 已提交
1490
    tcg_temp_free_i32(t0);
P
pbrook 已提交
1491 1492 1493
#endif
}

P
pbrook 已提交
1494
static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1495 1496
{
#ifdef TCG_TARGET_HAS_neg_i64
P
pbrook 已提交
1497
    tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
P
pbrook 已提交
1498
#else
P
pbrook 已提交
1499
    TCGv_i64 t0 = tcg_const_i64(0);
1500
    tcg_gen_sub_i64(ret, t0, arg);
P
pbrook 已提交
1501
    tcg_temp_free_i64(t0);
P
pbrook 已提交
1502 1503 1504
#endif
}

P
pbrook 已提交
1505
static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1506
{
A
aurel32 已提交
1507 1508 1509
#ifdef TCG_TARGET_HAS_not_i32
    tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
#else
1510
    tcg_gen_xori_i32(ret, arg, -1);
A
aurel32 已提交
1511
#endif
B
bellard 已提交
1512 1513
}

P
pbrook 已提交
1514
static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1515
{
A
aurel32 已提交
1516
#ifdef TCG_TARGET_HAS_not_i64
A
aurel32 已提交
1517
    tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
A
aurel32 已提交
1518
#else
1519
    tcg_gen_xori_i64(ret, arg, -1);
A
aurel32 已提交
1520
#endif
B
bellard 已提交
1521
}
1522

P
pbrook 已提交
1523
static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1524
{
P
pbrook 已提交
1525
    tcg_gen_op1_i32(INDEX_op_discard, arg);
1526 1527 1528
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1529
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1530
{
P
pbrook 已提交
1531
    tcg_gen_discard_i32(TCGV_LOW(arg));
1532 1533 1534
    tcg_gen_discard_i32(TCGV_HIGH(arg));
}
#else
P
pbrook 已提交
1535
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1536
{
P
pbrook 已提交
1537
    tcg_gen_op1_i64(INDEX_op_discard, arg);
1538 1539 1540
}
#endif

P
pbrook 已提交
1541
static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
P
pbrook 已提交
1542 1543
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1544
    tcg_gen_mov_i32(TCGV_LOW(dest), low);
P
pbrook 已提交
1545 1546
    tcg_gen_mov_i32(TCGV_HIGH(dest), high);
#else
P
pbrook 已提交
1547
    TCGv_i64 tmp = tcg_temp_new_i64();
P
pbrook 已提交
1548 1549 1550 1551 1552 1553
    /* This extension is only needed for type correctness.
       We may be able to do better given target specific information.  */
    tcg_gen_extu_i32_i64(tmp, high);
    tcg_gen_shli_i64(tmp, tmp, 32);
    tcg_gen_extu_i32_i64(dest, low);
    tcg_gen_or_i64(dest, dest, tmp);
P
pbrook 已提交
1554
    tcg_temp_free_i64(tmp);
P
pbrook 已提交
1555 1556 1557
#endif
}

P
pbrook 已提交
1558
static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low, TCGv_i64 high)
1559 1560
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1561
    tcg_gen_concat_i32_i64(dest, TCGV_LOW(low), TCGV_LOW(high));
1562
#else
P
pbrook 已提交
1563
    TCGv_i64 tmp = tcg_temp_new_i64();
1564
    tcg_gen_ext32u_i64(dest, low);
1565
    tcg_gen_shli_i64(tmp, high, 32);
1566
    tcg_gen_or_i64(dest, dest, tmp);
P
pbrook 已提交
1567
    tcg_temp_free_i64(tmp);
1568 1569 1570
#endif
}

P
pbrook 已提交
1571
static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1572
{
P
pbrook 已提交
1573 1574
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
1575 1576
    tcg_gen_not_i32(t0, arg2);
    tcg_gen_and_i32(ret, arg1, t0);
P
pbrook 已提交
1577
    tcg_temp_free_i32(t0);
1578 1579
}

P
pbrook 已提交
1580
static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1581
{
P
pbrook 已提交
1582 1583
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
1584 1585
    tcg_gen_not_i64(t0, arg2);
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1586
    tcg_temp_free_i64(t0);
1587 1588
}

P
pbrook 已提交
1589
static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1590
{
A
aurel32 已提交
1591 1592
    tcg_gen_xor_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1593 1594
}

P
pbrook 已提交
1595
static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1596
{
A
aurel32 已提交
1597 1598
    tcg_gen_xor_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1599 1600
}

P
pbrook 已提交
1601
static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1602
{
A
aurel32 已提交
1603 1604
    tcg_gen_and_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1605 1606
}

P
pbrook 已提交
1607
static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1608
{
A
aurel32 已提交
1609 1610
    tcg_gen_and_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1611 1612
}

P
pbrook 已提交
1613
static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1614
{
A
aurel32 已提交
1615 1616
    tcg_gen_or_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1617 1618
}

P
pbrook 已提交
1619
static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1620
{
A
aurel32 已提交
1621 1622
    tcg_gen_or_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1623 1624
}

P
pbrook 已提交
1625
static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1626
{
P
pbrook 已提交
1627 1628
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
1629 1630
    tcg_gen_not_i32(t0, arg2);
    tcg_gen_or_i32(ret, arg1, t0);
P
pbrook 已提交
1631
    tcg_temp_free_i32(t0);
1632 1633
}

P
pbrook 已提交
1634
static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1635
{
P
pbrook 已提交
1636 1637
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
1638 1639
    tcg_gen_not_i64(t0, arg2);
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
1640
    tcg_temp_free_i64(t0);
1641 1642
}

P
pbrook 已提交
1643
static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1644
{
A
aurel32 已提交
1645 1646 1647
#ifdef TCG_TARGET_HAS_rot_i32
    tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1648
    TCGv_i32 t0, t1;
1649

P
pbrook 已提交
1650 1651
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
1652 1653 1654 1655
    tcg_gen_shl_i32(t0, arg1, arg2);
    tcg_gen_subfi_i32(t1, 32, arg2);
    tcg_gen_shr_i32(t1, arg1, t1);
    tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1656 1657
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
A
aurel32 已提交
1658
#endif
1659 1660
}

P
pbrook 已提交
1661
static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1662
{
A
aurel32 已提交
1663 1664 1665
#ifdef TCG_TARGET_HAS_rot_i64
    tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
#else
P
pbrook 已提交
1666
    TCGv_i64 t0, t1;
1667

P
pbrook 已提交
1668 1669
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();
1670 1671 1672 1673
    tcg_gen_shl_i64(t0, arg1, arg2);
    tcg_gen_subfi_i64(t1, 64, arg2);
    tcg_gen_shr_i64(t1, arg1, t1);
    tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1674 1675
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
A
aurel32 已提交
1676
#endif
1677 1678
}

P
pbrook 已提交
1679
static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1680 1681 1682 1683 1684
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
A
aurel32 已提交
1685 1686 1687 1688 1689
#ifdef TCG_TARGET_HAS_rot_i32
        TCGv_i32 t0 = tcg_const_i32(arg2);
        tcg_gen_rotl_i32(ret, arg1, t0);
        tcg_temp_free_i32(t0);
#else
P
pbrook 已提交
1690 1691 1692
        TCGv_i32 t0, t1;
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
1693 1694 1695
        tcg_gen_shli_i32(t0, arg1, arg2);
        tcg_gen_shri_i32(t1, arg1, 32 - arg2);
        tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1696 1697
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
A
aurel32 已提交
1698
#endif
1699 1700 1701
    }
}

P
pbrook 已提交
1702
static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1703 1704 1705 1706 1707
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
A
aurel32 已提交
1708 1709 1710 1711 1712
#ifdef TCG_TARGET_HAS_rot_i64
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_rotl_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
#else
P
pbrook 已提交
1713 1714 1715
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
1716 1717 1718
        tcg_gen_shli_i64(t0, arg1, arg2);
        tcg_gen_shri_i64(t1, arg1, 64 - arg2);
        tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1719 1720
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
A
aurel32 已提交
1721
#endif
1722 1723 1724
    }
}

P
pbrook 已提交
1725
static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1726
{
A
aurel32 已提交
1727 1728 1729
#ifdef TCG_TARGET_HAS_rot_i32
    tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1730
    TCGv_i32 t0, t1;
1731

P
pbrook 已提交
1732 1733
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
1734 1735 1736 1737
    tcg_gen_shr_i32(t0, arg1, arg2);
    tcg_gen_subfi_i32(t1, 32, arg2);
    tcg_gen_shl_i32(t1, arg1, t1);
    tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1738 1739
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
A
aurel32 已提交
1740
#endif
1741 1742
}

P
pbrook 已提交
1743
static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1744
{
A
aurel32 已提交
1745 1746 1747
#ifdef TCG_TARGET_HAS_rot_i64
    tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
#else
P
pbrook 已提交
1748
    TCGv_i64 t0, t1;
1749

P
pbrook 已提交
1750 1751
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();
1752 1753 1754 1755
    tcg_gen_shl_i64(t0, arg1, arg2);
    tcg_gen_subfi_i64(t1, 64, arg2);
    tcg_gen_shl_i64(t1, arg1, t1);
    tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1756 1757
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
A
aurel32 已提交
1758
#endif
1759 1760
}

P
pbrook 已提交
1761
static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1762 1763 1764 1765 1766 1767 1768 1769 1770
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
        tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
    }
}

P
pbrook 已提交
1771
static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1772 1773 1774
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
P
pbrook 已提交
1775
        tcg_gen_mov_i64(ret, arg1);
1776 1777 1778 1779 1780
    } else {
        tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
    }
}

B
bellard 已提交
1781 1782 1783 1784 1785 1786 1787
/***************************************/
/* QEMU specific operations. Their type depend on the QEMU CPU
   type. */
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
#endif

P
pbrook 已提交
1788 1789 1790 1791 1792
#if TARGET_LONG_BITS == 32
#define TCGv TCGv_i32
#define tcg_temp_new() tcg_temp_new_i32()
#define tcg_global_reg_new tcg_global_reg_new_i32
#define tcg_global_mem_new tcg_global_mem_new_i32
1793
#define tcg_temp_local_new() tcg_temp_local_new_i32()
P
pbrook 已提交
1794 1795 1796 1797
#define tcg_temp_free tcg_temp_free_i32
#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
#define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
A
aurel32 已提交
1798
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
P
pbrook 已提交
1799 1800 1801 1802 1803
#else
#define TCGv TCGv_i64
#define tcg_temp_new() tcg_temp_new_i64()
#define tcg_global_reg_new tcg_global_reg_new_i64
#define tcg_global_mem_new tcg_global_mem_new_i64
1804
#define tcg_temp_local_new() tcg_temp_local_new_i64()
P
pbrook 已提交
1805 1806 1807 1808
#define tcg_temp_free tcg_temp_free_i64
#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
A
aurel32 已提交
1809
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
P
pbrook 已提交
1810 1811
#endif

1812 1813 1814 1815 1816
/* debug info: write the PC of the corresponding QEMU CPU instruction */
static inline void tcg_gen_debug_insn_start(uint64_t pc)
{
    /* XXX: must really use a 32 bit size for TCGArg in all cases */
#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
P
pbrook 已提交
1817 1818
    tcg_gen_op2ii(INDEX_op_debug_insn_start, 
                  (uint32_t)(pc), (uint32_t)(pc >> 32));
1819 1820 1821 1822 1823
#else
    tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
#endif
}

B
bellard 已提交
1824 1825
static inline void tcg_gen_exit_tb(tcg_target_long val)
{
P
pbrook 已提交
1826
    tcg_gen_op1i(INDEX_op_exit_tb, val);
B
bellard 已提交
1827 1828 1829 1830
}

static inline void tcg_gen_goto_tb(int idx)
{
P
pbrook 已提交
1831
    tcg_gen_op1i(INDEX_op_goto_tb, idx);
B
bellard 已提交
1832 1833 1834
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1835
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1836 1837
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1838
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
1839
#else
P
pbrook 已提交
1840 1841
    tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1842
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1843 1844 1845
#endif
}

P
pbrook 已提交
1846
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1847 1848
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1849
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
1850
#else
P
pbrook 已提交
1851 1852 1853
    tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1854 1855 1856
#endif
}

P
pbrook 已提交
1857
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1858 1859
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1860
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
1861
#else
P
pbrook 已提交
1862 1863
    tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1864
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1865 1866 1867
#endif
}

P
pbrook 已提交
1868
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1869 1870
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1871
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
1872
#else
P
pbrook 已提交
1873 1874 1875
    tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1876 1877 1878
#endif
}

P
pbrook 已提交
1879
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1880 1881
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1882
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1883
#else
P
pbrook 已提交
1884 1885
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1886
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1887 1888 1889
#endif
}

P
pbrook 已提交
1890
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1891 1892
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1893
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1894
#else
P
pbrook 已提交
1895 1896 1897
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1898 1899 1900
#endif
}

P
pbrook 已提交
1901
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
1902 1903
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1904
    tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
B
bellard 已提交
1905
#else
P
pbrook 已提交
1906 1907
    tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1908 1909 1910
#endif
}

P
pbrook 已提交
1911
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1912 1913
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1914
    tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
1915
#else
P
pbrook 已提交
1916 1917
    tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1918 1919 1920
#endif
}

P
pbrook 已提交
1921
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1922 1923
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1924
    tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
1925
#else
P
pbrook 已提交
1926 1927
    tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1928 1929 1930
#endif
}

P
pbrook 已提交
1931
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1932 1933
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1934
    tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
1935
#else
P
pbrook 已提交
1936 1937
    tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1938 1939 1940
#endif
}

P
pbrook 已提交
1941
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
1942 1943
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1944 1945
    tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
                     mem_index);
B
bellard 已提交
1946
#else
P
pbrook 已提交
1947 1948
    tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1949 1950 1951
#endif
}

B
blueswir1 已提交
1952
#define tcg_gen_ld_ptr tcg_gen_ld_i32
B
blueswir1 已提交
1953
#define tcg_gen_discard_ptr tcg_gen_discard_i32
1954

B
bellard 已提交
1955 1956
#else /* TCG_TARGET_REG_BITS == 32 */

P
pbrook 已提交
1957
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1958
{
P
pbrook 已提交
1959
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
1960 1961
}

P
pbrook 已提交
1962
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1963
{
P
pbrook 已提交
1964
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
1965 1966
}

P
pbrook 已提交
1967
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1968
{
P
pbrook 已提交
1969
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
1970 1971
}

P
pbrook 已提交
1972
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1973
{
P
pbrook 已提交
1974
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
1975 1976
}

P
pbrook 已提交
1977
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1978
{
P
pbrook 已提交
1979
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1980 1981
}

P
pbrook 已提交
1982
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1983
{
P
pbrook 已提交
1984
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
B
bellard 已提交
1985 1986
}

P
pbrook 已提交
1987
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
1988
{
P
pbrook 已提交
1989
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
B
bellard 已提交
1990 1991
}

P
pbrook 已提交
1992
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1993
{
P
pbrook 已提交
1994
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
1995 1996
}

P
pbrook 已提交
1997
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1998
{
P
pbrook 已提交
1999
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2000 2001
}

P
pbrook 已提交
2002
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2003
{
P
pbrook 已提交
2004
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2005 2006
}

P
pbrook 已提交
2007
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2008
{
P
pbrook 已提交
2009
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
B
bellard 已提交
2010 2011
}

B
blueswir1 已提交
2012
#define tcg_gen_ld_ptr tcg_gen_ld_i64
B
blueswir1 已提交
2013
#define tcg_gen_discard_ptr tcg_gen_discard_i64
2014

B
bellard 已提交
2015
#endif /* TCG_TARGET_REG_BITS != 32 */
2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034

#if TARGET_LONG_BITS == 64
#define TCG_TYPE_TL TCG_TYPE_I64
#define tcg_gen_movi_tl tcg_gen_movi_i64
#define tcg_gen_mov_tl tcg_gen_mov_i64
#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
#define tcg_gen_ld_tl tcg_gen_ld_i64
#define tcg_gen_st8_tl tcg_gen_st8_i64
#define tcg_gen_st16_tl tcg_gen_st16_i64
#define tcg_gen_st32_tl tcg_gen_st32_i64
#define tcg_gen_st_tl tcg_gen_st_i64
#define tcg_gen_add_tl tcg_gen_add_i64
#define tcg_gen_addi_tl tcg_gen_addi_i64
#define tcg_gen_sub_tl tcg_gen_sub_i64
P
pbrook 已提交
2035
#define tcg_gen_neg_tl tcg_gen_neg_i64
P
pbrook 已提交
2036
#define tcg_gen_subfi_tl tcg_gen_subfi_i64
2037 2038 2039 2040 2041 2042 2043
#define tcg_gen_subi_tl tcg_gen_subi_i64
#define tcg_gen_and_tl tcg_gen_and_i64
#define tcg_gen_andi_tl tcg_gen_andi_i64
#define tcg_gen_or_tl tcg_gen_or_i64
#define tcg_gen_ori_tl tcg_gen_ori_i64
#define tcg_gen_xor_tl tcg_gen_xor_i64
#define tcg_gen_xori_tl tcg_gen_xori_i64
B
bellard 已提交
2044
#define tcg_gen_not_tl tcg_gen_not_i64
2045 2046 2047 2048 2049 2050
#define tcg_gen_shl_tl tcg_gen_shl_i64
#define tcg_gen_shli_tl tcg_gen_shli_i64
#define tcg_gen_shr_tl tcg_gen_shr_i64
#define tcg_gen_shri_tl tcg_gen_shri_i64
#define tcg_gen_sar_tl tcg_gen_sar_i64
#define tcg_gen_sari_tl tcg_gen_sari_i64
B
blueswir1 已提交
2051
#define tcg_gen_brcond_tl tcg_gen_brcond_i64
P
pbrook 已提交
2052
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2053 2054
#define tcg_gen_mul_tl tcg_gen_mul_i64
#define tcg_gen_muli_tl tcg_gen_muli_i64
B
blueswir1 已提交
2055
#define tcg_gen_discard_tl tcg_gen_discard_i64
2056 2057 2058 2059 2060 2061
#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
B
bellard 已提交
2062 2063 2064 2065 2066 2067
#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
2068 2069 2070
#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
2071
#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2072 2073 2074 2075 2076
#define tcg_gen_andc_tl tcg_gen_andc_i64
#define tcg_gen_eqv_tl tcg_gen_eqv_i64
#define tcg_gen_nand_tl tcg_gen_nand_i64
#define tcg_gen_nor_tl tcg_gen_nor_i64
#define tcg_gen_orc_tl tcg_gen_orc_i64
2077 2078 2079 2080
#define tcg_gen_rotl_tl tcg_gen_rotl_i64
#define tcg_gen_rotli_tl tcg_gen_rotli_i64
#define tcg_gen_rotr_tl tcg_gen_rotr_i64
#define tcg_gen_rotri_tl tcg_gen_rotri_i64
B
blueswir1 已提交
2081
#define tcg_const_tl tcg_const_i64
A
aurel32 已提交
2082
#define tcg_const_local_tl tcg_const_local_i64
2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100
#else
#define TCG_TYPE_TL TCG_TYPE_I32
#define tcg_gen_movi_tl tcg_gen_movi_i32
#define tcg_gen_mov_tl tcg_gen_mov_i32
#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
#define tcg_gen_ld32u_tl tcg_gen_ld_i32
#define tcg_gen_ld32s_tl tcg_gen_ld_i32
#define tcg_gen_ld_tl tcg_gen_ld_i32
#define tcg_gen_st8_tl tcg_gen_st8_i32
#define tcg_gen_st16_tl tcg_gen_st16_i32
#define tcg_gen_st32_tl tcg_gen_st_i32
#define tcg_gen_st_tl tcg_gen_st_i32
#define tcg_gen_add_tl tcg_gen_add_i32
#define tcg_gen_addi_tl tcg_gen_addi_i32
#define tcg_gen_sub_tl tcg_gen_sub_i32
P
pbrook 已提交
2101
#define tcg_gen_neg_tl tcg_gen_neg_i32
A
aurel32 已提交
2102
#define tcg_gen_subfi_tl tcg_gen_subfi_i32
2103 2104 2105 2106 2107 2108 2109
#define tcg_gen_subi_tl tcg_gen_subi_i32
#define tcg_gen_and_tl tcg_gen_and_i32
#define tcg_gen_andi_tl tcg_gen_andi_i32
#define tcg_gen_or_tl tcg_gen_or_i32
#define tcg_gen_ori_tl tcg_gen_ori_i32
#define tcg_gen_xor_tl tcg_gen_xor_i32
#define tcg_gen_xori_tl tcg_gen_xori_i32
B
bellard 已提交
2110
#define tcg_gen_not_tl tcg_gen_not_i32
2111 2112 2113 2114 2115 2116
#define tcg_gen_shl_tl tcg_gen_shl_i32
#define tcg_gen_shli_tl tcg_gen_shli_i32
#define tcg_gen_shr_tl tcg_gen_shr_i32
#define tcg_gen_shri_tl tcg_gen_shri_i32
#define tcg_gen_sar_tl tcg_gen_sar_i32
#define tcg_gen_sari_tl tcg_gen_sari_i32
B
blueswir1 已提交
2117
#define tcg_gen_brcond_tl tcg_gen_brcond_i32
P
pbrook 已提交
2118
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2119 2120
#define tcg_gen_mul_tl tcg_gen_mul_i32
#define tcg_gen_muli_tl tcg_gen_muli_i32
B
blueswir1 已提交
2121
#define tcg_gen_discard_tl tcg_gen_discard_i32
2122 2123 2124 2125 2126 2127
#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
B
bellard 已提交
2128 2129 2130 2131 2132 2133
#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
#define tcg_gen_ext32u_tl tcg_gen_mov_i32
#define tcg_gen_ext32s_tl tcg_gen_mov_i32
2134 2135
#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2136
#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2137 2138 2139 2140 2141
#define tcg_gen_andc_tl tcg_gen_andc_i32
#define tcg_gen_eqv_tl tcg_gen_eqv_i32
#define tcg_gen_nand_tl tcg_gen_nand_i32
#define tcg_gen_nor_tl tcg_gen_nor_i32
#define tcg_gen_orc_tl tcg_gen_orc_i32
2142 2143 2144 2145
#define tcg_gen_rotl_tl tcg_gen_rotl_i32
#define tcg_gen_rotli_tl tcg_gen_rotli_i32
#define tcg_gen_rotr_tl tcg_gen_rotr_i32
#define tcg_gen_rotri_tl tcg_gen_rotri_i32
B
blueswir1 已提交
2146
#define tcg_const_tl tcg_const_i32
A
aurel32 已提交
2147
#define tcg_const_local_tl tcg_const_local_i32
2148
#endif
P
pbrook 已提交
2149 2150

#if TCG_TARGET_REG_BITS == 32
2151
#define tcg_gen_add_ptr tcg_gen_add_i32
P
pbrook 已提交
2152
#define tcg_gen_addi_ptr tcg_gen_addi_i32
2153
#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
P
pbrook 已提交
2154
#else /* TCG_TARGET_REG_BITS == 32 */
2155
#define tcg_gen_add_ptr tcg_gen_add_i64
P
pbrook 已提交
2156
#define tcg_gen_addi_ptr tcg_gen_addi_i64
2157
#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
P
pbrook 已提交
2158
#endif /* TCG_TARGET_REG_BITS != 32 */