tcg-op.h 65.3 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
}

283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
static inline void tcg_gen_op6i_i32(int opc, TCGv_i32 arg1, TCGv_i32 arg2,
                                    TCGv_i32 arg3, TCGv_i32 arg4,
                                    TCGv_i32 arg5, TCGArg 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++ = arg6;
}

static inline void tcg_gen_op6i_i64(int opc, TCGv_i64 arg1, TCGv_i64 arg2,
                                    TCGv_i64 arg3, TCGv_i64 arg4,
                                    TCGv_i64 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);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
    *gen_opparam_ptr++ = arg6;
}

P
pbrook 已提交
309 310 311
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 已提交
312 313
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    *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 已提交
331 332 333 334 335 336
    *gen_opparam_ptr++ = arg5;
    *gen_opparam_ptr++ = arg6;
}

static inline void gen_set_label(int n)
{
P
pbrook 已提交
337
    tcg_gen_op1i(INDEX_op_set_label, n);
B
bellard 已提交
338 339
}

B
blueswir1 已提交
340 341 342 343 344
static inline void tcg_gen_br(int label)
{
    tcg_gen_op1i(INDEX_op_br, label);
}

P
pbrook 已提交
345
static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
346
{
A
aurel32 已提交
347
    if (!TCGV_EQUAL_I32(ret, arg))
P
pbrook 已提交
348
        tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
B
bellard 已提交
349 350
}

P
pbrook 已提交
351
static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
B
bellard 已提交
352
{
P
pbrook 已提交
353
    tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
B
bellard 已提交
354 355 356
}

/* helper calls */
P
pbrook 已提交
357 358 359 360 361 362 363 364 365
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 已提交
366

P
pbrook 已提交
367 368 369
/* FIXME: Should this be pure?  */
static inline void tcg_gen_helper64(void *func, TCGv_i64 ret,
                                    TCGv_i64 a, TCGv_i64 b)
B
bellard 已提交
370
{
P
pbrook 已提交
371 372 373 374 375 376 377
    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);
378 379
}

B
bellard 已提交
380 381
/* 32 bit ops */

P
pbrook 已提交
382
static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
383
{
P
pbrook 已提交
384
    tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
B
bellard 已提交
385 386
}

P
pbrook 已提交
387
static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
388
{
P
pbrook 已提交
389
    tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
B
bellard 已提交
390 391
}

P
pbrook 已提交
392
static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
393
{
P
pbrook 已提交
394
    tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
B
bellard 已提交
395 396
}

P
pbrook 已提交
397
static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
398
{
P
pbrook 已提交
399
    tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
B
bellard 已提交
400 401
}

P
pbrook 已提交
402
static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
403
{
P
pbrook 已提交
404
    tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
B
bellard 已提交
405 406
}

P
pbrook 已提交
407
static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
408
{
P
pbrook 已提交
409
    tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
B
bellard 已提交
410 411
}

P
pbrook 已提交
412
static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
413
{
P
pbrook 已提交
414
    tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
B
bellard 已提交
415 416
}

P
pbrook 已提交
417
static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
418
{
P
pbrook 已提交
419
    tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
B
bellard 已提交
420 421
}

P
pbrook 已提交
422
static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
423
{
P
pbrook 已提交
424
    tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
B
bellard 已提交
425 426
}

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

P
pbrook 已提交
439
static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
440
{
P
pbrook 已提交
441
    tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
B
bellard 已提交
442 443
}

P
pbrook 已提交
444
static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
A
aurel32 已提交
445
{
P
pbrook 已提交
446
    TCGv_i32 t0 = tcg_const_i32(arg1);
A
aurel32 已提交
447
    tcg_gen_sub_i32(ret, t0, arg2);
P
pbrook 已提交
448
    tcg_temp_free_i32(t0);
A
aurel32 已提交
449 450
}

P
pbrook 已提交
451
static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
452
{
453 454 455 456
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
457
        TCGv_i32 t0 = tcg_const_i32(arg2);
458
        tcg_gen_sub_i32(ret, arg1, t0);
P
pbrook 已提交
459
        tcg_temp_free_i32(t0);
460
    }
B
bellard 已提交
461 462
}

P
pbrook 已提交
463
static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
464
{
A
aurel32 已提交
465 466 467 468 469
    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 已提交
470 471
}

P
pbrook 已提交
472
static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
473 474 475 476 477 478 479
{
    /* 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 已提交
480
        TCGv_i32 t0 = tcg_const_i32(arg2);
481
        tcg_gen_and_i32(ret, arg1, t0);
P
pbrook 已提交
482
        tcg_temp_free_i32(t0);
B
bellard 已提交
483 484 485
    }
}

P
pbrook 已提交
486
static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
487
{
A
aurel32 已提交
488 489 490 491 492
    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 已提交
493 494
}

P
pbrook 已提交
495
static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
496 497 498
{
    /* some cases can be optimized here */
    if (arg2 == 0xffffffff) {
499
        tcg_gen_movi_i32(ret, 0xffffffff);
B
bellard 已提交
500 501 502
    } else if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
503
        TCGv_i32 t0 = tcg_const_i32(arg2);
504
        tcg_gen_or_i32(ret, arg1, t0);
P
pbrook 已提交
505
        tcg_temp_free_i32(t0);
B
bellard 已提交
506 507 508
    }
}

P
pbrook 已提交
509
static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
510
{
A
aurel32 已提交
511 512 513 514 515
    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 已提交
516 517
}

P
pbrook 已提交
518
static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
519 520 521 522 523
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
524
        TCGv_i32 t0 = tcg_const_i32(arg2);
525
        tcg_gen_xor_i32(ret, arg1, t0);
P
pbrook 已提交
526
        tcg_temp_free_i32(t0);
B
bellard 已提交
527 528 529
    }
}

P
pbrook 已提交
530
static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
531
{
P
pbrook 已提交
532
    tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
B
bellard 已提交
533 534
}

P
pbrook 已提交
535
static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
536
{
B
bellard 已提交
537 538 539
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
540
        TCGv_i32 t0 = tcg_const_i32(arg2);
541
        tcg_gen_shl_i32(ret, arg1, t0);
P
pbrook 已提交
542
        tcg_temp_free_i32(t0);
B
bellard 已提交
543
    }
B
bellard 已提交
544 545
}

P
pbrook 已提交
546
static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
547
{
P
pbrook 已提交
548
    tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
B
bellard 已提交
549 550
}

P
pbrook 已提交
551
static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
552
{
B
bellard 已提交
553 554 555
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
556
        TCGv_i32 t0 = tcg_const_i32(arg2);
557
        tcg_gen_shr_i32(ret, arg1, t0);
P
pbrook 已提交
558
        tcg_temp_free_i32(t0);
B
bellard 已提交
559
    }
B
bellard 已提交
560 561
}

P
pbrook 已提交
562
static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
563
{
P
pbrook 已提交
564
    tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
B
bellard 已提交
565 566
}

P
pbrook 已提交
567
static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
568
{
B
bellard 已提交
569 570 571
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
572
        TCGv_i32 t0 = tcg_const_i32(arg2);
573
        tcg_gen_sar_i32(ret, arg1, t0);
P
pbrook 已提交
574
        tcg_temp_free_i32(t0);
B
bellard 已提交
575
    }
B
bellard 已提交
576 577
}

P
pbrook 已提交
578
static inline void tcg_gen_brcond_i32(int cond, TCGv_i32 arg1, TCGv_i32 arg2,
B
bellard 已提交
579 580
                                      int label_index)
{
P
pbrook 已提交
581
    tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
B
bellard 已提交
582 583
}

P
pbrook 已提交
584
static inline void tcg_gen_brcondi_i32(int cond, TCGv_i32 arg1, int32_t arg2,
P
pbrook 已提交
585 586
                                       int label_index)
{
P
pbrook 已提交
587
    TCGv_i32 t0 = tcg_const_i32(arg2);
P
pbrook 已提交
588
    tcg_gen_brcond_i32(cond, arg1, t0, label_index);
P
pbrook 已提交
589
    tcg_temp_free_i32(t0);
P
pbrook 已提交
590 591
}

P
pbrook 已提交
592
static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
593
{
P
pbrook 已提交
594
    tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
B
bellard 已提交
595 596
}

P
pbrook 已提交
597
static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
598
{
P
pbrook 已提交
599
    TCGv_i32 t0 = tcg_const_i32(arg2);
600
    tcg_gen_mul_i32(ret, arg1, t0);
P
pbrook 已提交
601
    tcg_temp_free_i32(t0);
602 603
}

B
bellard 已提交
604
#ifdef TCG_TARGET_HAS_div_i32
P
pbrook 已提交
605
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
606
{
P
pbrook 已提交
607
    tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
B
bellard 已提交
608 609
}

P
pbrook 已提交
610
static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
611
{
P
pbrook 已提交
612
    tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
B
bellard 已提交
613 614
}

P
pbrook 已提交
615
static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
616
{
P
pbrook 已提交
617
    tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
B
bellard 已提交
618 619
}

P
pbrook 已提交
620
static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
621
{
P
pbrook 已提交
622
    tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
B
bellard 已提交
623 624
}
#else
P
pbrook 已提交
625
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
626
{
P
pbrook 已提交
627 628
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
629
    tcg_gen_sari_i32(t0, arg1, 31);
P
pbrook 已提交
630 631
    tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
632 633
}

P
pbrook 已提交
634
static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
635
{
P
pbrook 已提交
636 637
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
638
    tcg_gen_sari_i32(t0, arg1, 31);
P
pbrook 已提交
639 640
    tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
641 642
}

P
pbrook 已提交
643
static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
644
{
P
pbrook 已提交
645 646
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
647
    tcg_gen_movi_i32(t0, 0);
P
pbrook 已提交
648 649
    tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
650 651
}

P
pbrook 已提交
652
static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
653
{
P
pbrook 已提交
654 655
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
656
    tcg_gen_movi_i32(t0, 0);
P
pbrook 已提交
657 658
    tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
659 660 661 662 663
}
#endif

#if TCG_TARGET_REG_BITS == 32

P
pbrook 已提交
664
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
665
{
A
aurel32 已提交
666
    if (!TCGV_EQUAL_I64(ret, arg)) {
P
pbrook 已提交
667
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
668 669
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
    }
B
bellard 已提交
670 671
}

P
pbrook 已提交
672
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
673
{
P
pbrook 已提交
674
    tcg_gen_movi_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
675
    tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
B
bellard 已提交
676 677
}

P
pbrook 已提交
678 679
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
680
{
P
pbrook 已提交
681
    tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
682
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
683 684
}

P
pbrook 已提交
685 686
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
687
{
P
pbrook 已提交
688 689
    tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
B
bellard 已提交
690 691
}

P
pbrook 已提交
692 693
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
694
{
A
aurel32 已提交
695
    tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
696
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
697 698
}

P
pbrook 已提交
699 700
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
701
{
P
pbrook 已提交
702 703
    tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
704 705
}

P
pbrook 已提交
706 707
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
708
{
P
pbrook 已提交
709
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
710
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
711 712
}

P
pbrook 已提交
713 714
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
715
{
P
pbrook 已提交
716 717
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
718 719
}

P
pbrook 已提交
720 721
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
722 723 724 725
{
    /* since arg2 and ret have different types, they cannot be the
       same temporary */
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
726
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
P
pbrook 已提交
727
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
B
bellard 已提交
728
#else
P
pbrook 已提交
729
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
730
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
B
bellard 已提交
731 732 733
#endif
}

P
pbrook 已提交
734 735
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                   tcg_target_long offset)
B
bellard 已提交
736
{
P
pbrook 已提交
737
    tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
738 739
}

P
pbrook 已提交
740 741
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
742
{
P
pbrook 已提交
743
    tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
744 745
}

P
pbrook 已提交
746 747
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
748
{
P
pbrook 已提交
749
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
750 751
}

P
pbrook 已提交
752 753
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
754 755
{
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
756
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
P
pbrook 已提交
757
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
B
bellard 已提交
758
#else
P
pbrook 已提交
759
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
P
pbrook 已提交
760
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
B
bellard 已提交
761 762 763
#endif
}

P
pbrook 已提交
764
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
765
{
P
pbrook 已提交
766 767 768
    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 已提交
769 770
}

P
pbrook 已提交
771
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
772
{
P
pbrook 已提交
773 774 775
    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 已提交
776 777
}

P
pbrook 已提交
778
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
779
{
P
pbrook 已提交
780
    tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
781
    tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
782 783
}

P
pbrook 已提交
784
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
785
{
A
aurel32 已提交
786 787
    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 已提交
788 789
}

P
pbrook 已提交
790
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
791
{
A
aurel32 已提交
792 793
    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 已提交
794 795
}

P
pbrook 已提交
796
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
797
{
P
pbrook 已提交
798
    tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
799
    tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
800 801
}

P
pbrook 已提交
802
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
803
{
A
aurel32 已提交
804 805
    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 已提交
806 807
}

P
pbrook 已提交
808
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
809
{
P
pbrook 已提交
810
    tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
811
    tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
812 813 814 815
}

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

P
pbrook 已提交
821
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
822 823 824 825
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
}

P
pbrook 已提交
826
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
827
{
P
pbrook 已提交
828
    tcg_gen_helper64(tcg_helper_shr_i64, ret, arg1, arg2);
B
bellard 已提交
829 830
}

P
pbrook 已提交
831
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
832 833 834 835
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
}

P
pbrook 已提交
836
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
837
{
P
pbrook 已提交
838
    tcg_gen_helper64(tcg_helper_sar_i64, ret, arg1, arg2);
B
bellard 已提交
839 840
}

P
pbrook 已提交
841
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
842 843 844 845
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
}

P
pbrook 已提交
846
static inline void tcg_gen_brcond_i64(int cond, TCGv_i64 arg1, TCGv_i64 arg2,
B
bellard 已提交
847 848
                                      int label_index)
{
P
pbrook 已提交
849 850 851
    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 已提交
852 853
}

P
pbrook 已提交
854
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
855
{
P
pbrook 已提交
856 857
    TCGv_i64 t0;
    TCGv_i32 t1;
B
bellard 已提交
858

P
pbrook 已提交
859 860 861 862 863 864 865
    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 已提交
866
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
867
    tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
868
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
869

B
bellard 已提交
870
    tcg_gen_mov_i64(ret, t0);
P
pbrook 已提交
871 872
    tcg_temp_free_i64(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
873 874
}

P
pbrook 已提交
875
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
876
{
P
pbrook 已提交
877
    tcg_gen_helper64(tcg_helper_div_i64, ret, arg1, arg2);
B
bellard 已提交
878 879
}

P
pbrook 已提交
880
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
881
{
P
pbrook 已提交
882
    tcg_gen_helper64(tcg_helper_rem_i64, ret, arg1, arg2);
B
bellard 已提交
883 884
}

P
pbrook 已提交
885
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
886
{
P
pbrook 已提交
887
    tcg_gen_helper64(tcg_helper_divu_i64, ret, arg1, arg2);
B
bellard 已提交
888 889
}

P
pbrook 已提交
890
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
891
{
P
pbrook 已提交
892
    tcg_gen_helper64(tcg_helper_remu_i64, ret, arg1, arg2);
B
bellard 已提交
893 894 895 896
}

#else

P
pbrook 已提交
897
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
898
{
A
aurel32 已提交
899
    if (!TCGV_EQUAL_I64(ret, arg))
P
pbrook 已提交
900
        tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
B
bellard 已提交
901 902
}

P
pbrook 已提交
903
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
904
{
P
pbrook 已提交
905
    tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
B
bellard 已提交
906 907
}

P
pbrook 已提交
908
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
909
                                    tcg_target_long offset)
B
bellard 已提交
910
{
P
pbrook 已提交
911
    tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
B
bellard 已提交
912 913
}

P
pbrook 已提交
914
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
915
                                    tcg_target_long offset)
B
bellard 已提交
916
{
P
pbrook 已提交
917
    tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
B
bellard 已提交
918 919
}

P
pbrook 已提交
920
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
921
                                     tcg_target_long offset)
B
bellard 已提交
922
{
P
pbrook 已提交
923
    tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
B
bellard 已提交
924 925
}

P
pbrook 已提交
926
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
927
                                     tcg_target_long offset)
B
bellard 已提交
928
{
P
pbrook 已提交
929
    tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
B
bellard 已提交
930 931
}

P
pbrook 已提交
932
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
933
                                     tcg_target_long offset)
B
bellard 已提交
934
{
P
pbrook 已提交
935
    tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
B
bellard 已提交
936 937
}

P
pbrook 已提交
938
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
939
                                     tcg_target_long offset)
B
bellard 已提交
940
{
P
pbrook 已提交
941
    tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
B
bellard 已提交
942 943
}

P
pbrook 已提交
944
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_i64 arg2, tcg_target_long offset)
B
bellard 已提交
945
{
P
pbrook 已提交
946
    tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
B
bellard 已提交
947 948
}

P
pbrook 已提交
949
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
950
                                   tcg_target_long offset)
B
bellard 已提交
951
{
P
pbrook 已提交
952
    tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
B
bellard 已提交
953 954
}

P
pbrook 已提交
955
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
956
                                    tcg_target_long offset)
B
bellard 已提交
957
{
P
pbrook 已提交
958
    tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
B
bellard 已提交
959 960
}

P
pbrook 已提交
961
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
962
                                    tcg_target_long offset)
B
bellard 已提交
963
{
P
pbrook 已提交
964
    tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
B
bellard 已提交
965 966
}

P
pbrook 已提交
967
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_i64 arg2, tcg_target_long offset)
B
bellard 已提交
968
{
P
pbrook 已提交
969
    tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
B
bellard 已提交
970 971
}

P
pbrook 已提交
972
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
973
{
P
pbrook 已提交
974
    tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
B
bellard 已提交
975 976
}

P
pbrook 已提交
977
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
978
{
P
pbrook 已提交
979
    tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
B
bellard 已提交
980 981
}

P
pbrook 已提交
982
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
983
{
A
aurel32 已提交
984 985 986 987 988
    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 已提交
989 990
}

P
pbrook 已提交
991
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
992
{
P
pbrook 已提交
993
    TCGv_i64 t0 = tcg_const_i64(arg2);
994
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
995
    tcg_temp_free_i64(t0);
B
bellard 已提交
996 997
}

P
pbrook 已提交
998
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
999
{
A
aurel32 已提交
1000 1001 1002 1003 1004
    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 已提交
1005 1006
}

P
pbrook 已提交
1007
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1008
{
P
pbrook 已提交
1009
    TCGv_i64 t0 = tcg_const_i64(arg2);
1010
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
1011
    tcg_temp_free_i64(t0);
B
bellard 已提交
1012 1013
}

P
pbrook 已提交
1014
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1015
{
A
aurel32 已提交
1016 1017 1018 1019 1020
    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 已提交
1021 1022
}

P
pbrook 已提交
1023
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1024
{
P
pbrook 已提交
1025
    TCGv_i64 t0 = tcg_const_i64(arg2);
1026
    tcg_gen_xor_i64(ret, arg1, t0);
P
pbrook 已提交
1027
    tcg_temp_free_i64(t0);
B
bellard 已提交
1028 1029
}

P
pbrook 已提交
1030
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1031
{
P
pbrook 已提交
1032
    tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
B
bellard 已提交
1033 1034
}

P
pbrook 已提交
1035
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1036
{
B
bellard 已提交
1037 1038 1039
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1040
        TCGv_i64 t0 = tcg_const_i64(arg2);
1041
        tcg_gen_shl_i64(ret, arg1, t0);
P
pbrook 已提交
1042
        tcg_temp_free_i64(t0);
B
bellard 已提交
1043
    }
B
bellard 已提交
1044 1045
}

P
pbrook 已提交
1046
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1047
{
P
pbrook 已提交
1048
    tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
B
bellard 已提交
1049 1050
}

P
pbrook 已提交
1051
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1052
{
B
bellard 已提交
1053 1054 1055
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1056
        TCGv_i64 t0 = tcg_const_i64(arg2);
1057
        tcg_gen_shr_i64(ret, arg1, t0);
P
pbrook 已提交
1058
        tcg_temp_free_i64(t0);
B
bellard 已提交
1059
    }
B
bellard 已提交
1060 1061
}

P
pbrook 已提交
1062
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1063
{
P
pbrook 已提交
1064
    tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
B
bellard 已提交
1065 1066
}

P
pbrook 已提交
1067
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1068
{
B
bellard 已提交
1069 1070 1071
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1072
        TCGv_i64 t0 = tcg_const_i64(arg2);
1073
        tcg_gen_sar_i64(ret, arg1, t0);
P
pbrook 已提交
1074
        tcg_temp_free_i64(t0);
B
bellard 已提交
1075
    }
B
bellard 已提交
1076 1077
}

P
pbrook 已提交
1078
static inline void tcg_gen_brcond_i64(int cond, TCGv_i64 arg1, TCGv_i64 arg2,
B
bellard 已提交
1079 1080
                                      int label_index)
{
P
pbrook 已提交
1081
    tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
B
bellard 已提交
1082 1083
}

P
pbrook 已提交
1084
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1085
{
P
pbrook 已提交
1086
    tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
B
bellard 已提交
1087 1088 1089
}

#ifdef TCG_TARGET_HAS_div_i64
P
pbrook 已提交
1090
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1091
{
P
pbrook 已提交
1092
    tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
B
bellard 已提交
1093 1094
}

P
pbrook 已提交
1095
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1096
{
P
pbrook 已提交
1097
    tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
B
bellard 已提交
1098 1099
}

P
pbrook 已提交
1100
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1101
{
P
pbrook 已提交
1102
    tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
B
bellard 已提交
1103 1104
}

P
pbrook 已提交
1105
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1106
{
P
pbrook 已提交
1107
    tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
B
bellard 已提交
1108 1109
}
#else
P
pbrook 已提交
1110
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1111
{
P
pbrook 已提交
1112 1113
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1114
    tcg_gen_sari_i64(t0, arg1, 63);
P
pbrook 已提交
1115 1116
    tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1117 1118
}

P
pbrook 已提交
1119
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1120
{
P
pbrook 已提交
1121 1122
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1123
    tcg_gen_sari_i64(t0, arg1, 63);
P
pbrook 已提交
1124 1125
    tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1126 1127
}

P
pbrook 已提交
1128
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1129
{
P
pbrook 已提交
1130 1131
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1132
    tcg_gen_movi_i64(t0, 0);
P
pbrook 已提交
1133 1134
    tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1135 1136
}

P
pbrook 已提交
1137
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1138
{
P
pbrook 已提交
1139 1140
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1141
    tcg_gen_movi_i64(t0, 0);
P
pbrook 已提交
1142 1143
    tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1144 1145 1146 1147 1148
}
#endif

#endif

P
pbrook 已提交
1149
static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1150 1151 1152 1153 1154
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1155
        TCGv_i64 t0 = tcg_const_i64(arg2);
1156
        tcg_gen_add_i64(ret, arg1, t0);
P
pbrook 已提交
1157
        tcg_temp_free_i64(t0);
1158 1159 1160
    }
}

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

P
pbrook 已提交
1168
static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1169 1170 1171 1172 1173
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1174
        TCGv_i64 t0 = tcg_const_i64(arg2);
1175
        tcg_gen_sub_i64(ret, arg1, t0);
P
pbrook 已提交
1176
        tcg_temp_free_i64(t0);
1177 1178
    }
}
P
pbrook 已提交
1179
static inline void tcg_gen_brcondi_i64(int cond, TCGv_i64 arg1, int64_t arg2,
1180 1181
                                       int label_index)
{
P
pbrook 已提交
1182
    TCGv_i64 t0 = tcg_const_i64(arg2);
1183
    tcg_gen_brcond_i64(cond, arg1, t0, label_index);
P
pbrook 已提交
1184
    tcg_temp_free_i64(t0);
1185 1186
}

P
pbrook 已提交
1187
static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1188
{
P
pbrook 已提交
1189
    TCGv_i64 t0 = tcg_const_i64(arg2);
1190
    tcg_gen_mul_i64(ret, arg1, t0);
P
pbrook 已提交
1191
    tcg_temp_free_i64(t0);
1192 1193
}

1194

B
bellard 已提交
1195 1196 1197
/***************************************/
/* optional operations */

P
pbrook 已提交
1198
static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1199 1200
{
#ifdef TCG_TARGET_HAS_ext8s_i32
P
pbrook 已提交
1201
    tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
B
bellard 已提交
1202 1203
#else
    tcg_gen_shli_i32(ret, arg, 24);
1204
    tcg_gen_sari_i32(ret, ret, 24);
B
bellard 已提交
1205 1206 1207
#endif
}

P
pbrook 已提交
1208
static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1209 1210
{
#ifdef TCG_TARGET_HAS_ext16s_i32
P
pbrook 已提交
1211
    tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
B
bellard 已提交
1212 1213
#else
    tcg_gen_shli_i32(ret, arg, 16);
1214
    tcg_gen_sari_i32(ret, ret, 16);
B
bellard 已提交
1215 1216 1217
#endif
}

P
pbrook 已提交
1218
static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1219
{
1220 1221 1222
#ifdef TCG_TARGET_HAS_ext8u_i32
    tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
#else
P
pbrook 已提交
1223
    tcg_gen_andi_i32(ret, arg, 0xffu);
1224
#endif
P
pbrook 已提交
1225 1226
}

P
pbrook 已提交
1227
static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1228
{
1229 1230 1231
#ifdef TCG_TARGET_HAS_ext16u_i32
    tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
#else
P
pbrook 已提交
1232
    tcg_gen_andi_i32(ret, arg, 0xffffu);
1233
#endif
P
pbrook 已提交
1234 1235
}

B
bellard 已提交
1236
/* Note: we assume the two high bytes are set to zero */
P
pbrook 已提交
1237
static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1238 1239
{
#ifdef TCG_TARGET_HAS_bswap16_i32
P
pbrook 已提交
1240
    tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
B
bellard 已提交
1241
#else
A
aurel32 已提交
1242
    TCGv_i32 t0 = tcg_temp_new_i32();
B
bellard 已提交
1243
    
A
aurel32 已提交
1244 1245 1246 1247
    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 已提交
1248
    tcg_temp_free_i32(t0);
B
bellard 已提交
1249 1250 1251
#endif
}

A
aurel32 已提交
1252
static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1253
{
A
aurel32 已提交
1254 1255
#ifdef TCG_TARGET_HAS_bswap32_i32
    tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
B
bellard 已提交
1256
#else
P
pbrook 已提交
1257 1258 1259
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
    
    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 已提交
1273 1274
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1275 1276 1277 1278
#endif
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1279
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1280
{
P
pbrook 已提交
1281 1282
    tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1283 1284
}

P
pbrook 已提交
1285
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1286
{
P
pbrook 已提交
1287 1288
    tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1289 1290
}

P
pbrook 已提交
1291
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1292
{
P
pbrook 已提交
1293 1294
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1295 1296
}

P
pbrook 已提交
1297
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1298
{
P
pbrook 已提交
1299
    tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1300 1301 1302
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1303
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1304
{
P
pbrook 已提交
1305
    tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1306 1307 1308
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1309
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1310
{
P
pbrook 已提交
1311
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1312 1313 1314
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1315
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1316
{
P
pbrook 已提交
1317
    tcg_gen_mov_i32(ret, TCGV_LOW(arg));
B
bellard 已提交
1318 1319
}

P
pbrook 已提交
1320
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1321
{
P
pbrook 已提交
1322
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
1323
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1324 1325
}

P
pbrook 已提交
1326
static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1327
{
P
pbrook 已提交
1328 1329
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1330 1331
}

1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
/* 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 已提交
1346
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1347
{
P
pbrook 已提交
1348 1349 1350
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1351

A
aurel32 已提交
1352 1353
    tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
    tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
P
pbrook 已提交
1354
    tcg_gen_mov_i32(TCGV_LOW(ret), t1);
P
pbrook 已提交
1355
    tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
P
pbrook 已提交
1356 1357
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1358 1359 1360
}
#else

P
pbrook 已提交
1361
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1362 1363
{
#ifdef TCG_TARGET_HAS_ext8s_i64
P
pbrook 已提交
1364
    tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
B
bellard 已提交
1365 1366
#else
    tcg_gen_shli_i64(ret, arg, 56);
1367
    tcg_gen_sari_i64(ret, ret, 56);
B
bellard 已提交
1368 1369 1370
#endif
}

P
pbrook 已提交
1371
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1372 1373
{
#ifdef TCG_TARGET_HAS_ext16s_i64
P
pbrook 已提交
1374
    tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
B
bellard 已提交
1375 1376
#else
    tcg_gen_shli_i64(ret, arg, 48);
1377
    tcg_gen_sari_i64(ret, ret, 48);
B
bellard 已提交
1378 1379 1380
#endif
}

P
pbrook 已提交
1381
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1382 1383
{
#ifdef TCG_TARGET_HAS_ext32s_i64
P
pbrook 已提交
1384
    tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
B
bellard 已提交
1385 1386
#else
    tcg_gen_shli_i64(ret, arg, 32);
1387
    tcg_gen_sari_i64(ret, ret, 32);
B
bellard 已提交
1388 1389 1390
#endif
}

P
pbrook 已提交
1391
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1392
{
1393 1394 1395
#ifdef TCG_TARGET_HAS_ext8u_i64
    tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
#else
P
pbrook 已提交
1396
    tcg_gen_andi_i64(ret, arg, 0xffu);
1397
#endif
P
pbrook 已提交
1398 1399
}

P
pbrook 已提交
1400
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1401
{
1402 1403 1404
#ifdef TCG_TARGET_HAS_ext16u_i64
    tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
#else
P
pbrook 已提交
1405
    tcg_gen_andi_i64(ret, arg, 0xffffu);
1406
#endif
P
pbrook 已提交
1407 1408
}

P
pbrook 已提交
1409
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1410
{
1411 1412 1413
#ifdef TCG_TARGET_HAS_ext32u_i64
    tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
#else
P
pbrook 已提交
1414
    tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1415
#endif
P
pbrook 已提交
1416 1417
}

B
bellard 已提交
1418
/* Note: we assume the target supports move between 32 and 64 bit
P
pbrook 已提交
1419
   registers.  This will probably break MIPS64 targets.  */
P
pbrook 已提交
1420
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1421
{
P
pbrook 已提交
1422
    tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
B
bellard 已提交
1423 1424 1425 1426
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1427
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1428
{
1429
    tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
B
bellard 已提交
1430 1431 1432 1433
}

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

1439 1440 1441 1442 1443 1444 1445 1446 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 1476 1477 1478 1479 1480 1481 1482
/* 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 已提交
1483
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1484
{
A
aurel32 已提交
1485 1486
#ifdef TCG_TARGET_HAS_bswap64_i64
    tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
B
bellard 已提交
1487
#else
1488 1489
    TCGv_i64 t0 = tcg_temp_new_i64();
    TCGv_i64 t1 = tcg_temp_new_i64();
B
bellard 已提交
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
    
    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);
1519 1520
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
B
bellard 已提交
1521 1522 1523 1524 1525
#endif
}

#endif

P
pbrook 已提交
1526
static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1527 1528
{
#ifdef TCG_TARGET_HAS_neg_i32
P
pbrook 已提交
1529
    tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
P
pbrook 已提交
1530
#else
P
pbrook 已提交
1531
    TCGv_i32 t0 = tcg_const_i32(0);
1532
    tcg_gen_sub_i32(ret, t0, arg);
P
pbrook 已提交
1533
    tcg_temp_free_i32(t0);
P
pbrook 已提交
1534 1535 1536
#endif
}

P
pbrook 已提交
1537
static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1538 1539
{
#ifdef TCG_TARGET_HAS_neg_i64
P
pbrook 已提交
1540
    tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
P
pbrook 已提交
1541
#else
P
pbrook 已提交
1542
    TCGv_i64 t0 = tcg_const_i64(0);
1543
    tcg_gen_sub_i64(ret, t0, arg);
P
pbrook 已提交
1544
    tcg_temp_free_i64(t0);
P
pbrook 已提交
1545 1546 1547
#endif
}

P
pbrook 已提交
1548
static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1549
{
A
aurel32 已提交
1550 1551 1552
#ifdef TCG_TARGET_HAS_not_i32
    tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
#else
1553
    tcg_gen_xori_i32(ret, arg, -1);
A
aurel32 已提交
1554
#endif
B
bellard 已提交
1555 1556
}

P
pbrook 已提交
1557
static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1558
{
A
aurel32 已提交
1559
#ifdef TCG_TARGET_HAS_not_i64
A
aurel32 已提交
1560
    tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
A
aurel32 已提交
1561
#else
1562
    tcg_gen_xori_i64(ret, arg, -1);
A
aurel32 已提交
1563
#endif
B
bellard 已提交
1564
}
1565

P
pbrook 已提交
1566
static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1567
{
P
pbrook 已提交
1568
    tcg_gen_op1_i32(INDEX_op_discard, arg);
1569 1570 1571
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1572
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1573
{
P
pbrook 已提交
1574
    tcg_gen_discard_i32(TCGV_LOW(arg));
1575 1576 1577
    tcg_gen_discard_i32(TCGV_HIGH(arg));
}
#else
P
pbrook 已提交
1578
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1579
{
P
pbrook 已提交
1580
    tcg_gen_op1_i64(INDEX_op_discard, arg);
1581 1582 1583
}
#endif

P
pbrook 已提交
1584
static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
P
pbrook 已提交
1585 1586
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1587
    tcg_gen_mov_i32(TCGV_LOW(dest), low);
P
pbrook 已提交
1588 1589
    tcg_gen_mov_i32(TCGV_HIGH(dest), high);
#else
P
pbrook 已提交
1590
    TCGv_i64 tmp = tcg_temp_new_i64();
P
pbrook 已提交
1591 1592 1593 1594 1595 1596
    /* 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 已提交
1597
    tcg_temp_free_i64(tmp);
P
pbrook 已提交
1598 1599 1600
#endif
}

P
pbrook 已提交
1601
static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low, TCGv_i64 high)
1602 1603
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1604
    tcg_gen_concat_i32_i64(dest, TCGV_LOW(low), TCGV_LOW(high));
1605
#else
P
pbrook 已提交
1606
    TCGv_i64 tmp = tcg_temp_new_i64();
1607
    tcg_gen_ext32u_i64(dest, low);
1608
    tcg_gen_shli_i64(tmp, high, 32);
1609
    tcg_gen_or_i64(dest, dest, tmp);
P
pbrook 已提交
1610
    tcg_temp_free_i64(tmp);
1611 1612 1613
#endif
}

P
pbrook 已提交
1614
static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1615
{
P
pbrook 已提交
1616 1617
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
1618 1619
    tcg_gen_not_i32(t0, arg2);
    tcg_gen_and_i32(ret, arg1, t0);
P
pbrook 已提交
1620
    tcg_temp_free_i32(t0);
1621 1622
}

P
pbrook 已提交
1623
static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1624
{
P
pbrook 已提交
1625 1626
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
1627 1628
    tcg_gen_not_i64(t0, arg2);
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1629
    tcg_temp_free_i64(t0);
1630 1631
}

P
pbrook 已提交
1632
static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1633
{
A
aurel32 已提交
1634 1635
    tcg_gen_xor_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1636 1637
}

P
pbrook 已提交
1638
static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1639
{
A
aurel32 已提交
1640 1641
    tcg_gen_xor_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1642 1643
}

P
pbrook 已提交
1644
static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1645
{
A
aurel32 已提交
1646 1647
    tcg_gen_and_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1648 1649
}

P
pbrook 已提交
1650
static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1651
{
A
aurel32 已提交
1652 1653
    tcg_gen_and_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1654 1655
}

P
pbrook 已提交
1656
static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1657
{
A
aurel32 已提交
1658 1659
    tcg_gen_or_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1660 1661
}

P
pbrook 已提交
1662
static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1663
{
A
aurel32 已提交
1664 1665
    tcg_gen_or_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1666 1667
}

P
pbrook 已提交
1668
static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1669
{
P
pbrook 已提交
1670 1671
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
1672 1673
    tcg_gen_not_i32(t0, arg2);
    tcg_gen_or_i32(ret, arg1, t0);
P
pbrook 已提交
1674
    tcg_temp_free_i32(t0);
1675 1676
}

P
pbrook 已提交
1677
static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1678
{
P
pbrook 已提交
1679 1680
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
1681 1682
    tcg_gen_not_i64(t0, arg2);
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
1683
    tcg_temp_free_i64(t0);
1684 1685
}

P
pbrook 已提交
1686
static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1687
{
A
aurel32 已提交
1688 1689 1690
#ifdef TCG_TARGET_HAS_rot_i32
    tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1691
    TCGv_i32 t0, t1;
1692

P
pbrook 已提交
1693 1694
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
1695 1696 1697 1698
    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 已提交
1699 1700
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
A
aurel32 已提交
1701
#endif
1702 1703
}

P
pbrook 已提交
1704
static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1705
{
A
aurel32 已提交
1706 1707 1708
#ifdef TCG_TARGET_HAS_rot_i64
    tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
#else
P
pbrook 已提交
1709
    TCGv_i64 t0, t1;
1710

P
pbrook 已提交
1711 1712
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();
1713 1714 1715 1716
    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 已提交
1717 1718
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
A
aurel32 已提交
1719
#endif
1720 1721
}

P
pbrook 已提交
1722
static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1723 1724 1725 1726 1727
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
A
aurel32 已提交
1728 1729 1730 1731 1732
#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 已提交
1733 1734 1735
        TCGv_i32 t0, t1;
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
1736 1737 1738
        tcg_gen_shli_i32(t0, arg1, arg2);
        tcg_gen_shri_i32(t1, arg1, 32 - arg2);
        tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1739 1740
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
A
aurel32 已提交
1741
#endif
1742 1743 1744
    }
}

P
pbrook 已提交
1745
static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1746 1747 1748 1749 1750
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
A
aurel32 已提交
1751 1752 1753 1754 1755
#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 已提交
1756 1757 1758
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
1759 1760 1761
        tcg_gen_shli_i64(t0, arg1, arg2);
        tcg_gen_shri_i64(t1, arg1, 64 - arg2);
        tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1762 1763
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
A
aurel32 已提交
1764
#endif
1765 1766 1767
    }
}

P
pbrook 已提交
1768
static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1769
{
A
aurel32 已提交
1770 1771 1772
#ifdef TCG_TARGET_HAS_rot_i32
    tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1773
    TCGv_i32 t0, t1;
1774

P
pbrook 已提交
1775 1776
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
1777 1778 1779 1780
    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 已提交
1781 1782
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
A
aurel32 已提交
1783
#endif
1784 1785
}

P
pbrook 已提交
1786
static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1787
{
A
aurel32 已提交
1788 1789 1790
#ifdef TCG_TARGET_HAS_rot_i64
    tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
#else
P
pbrook 已提交
1791
    TCGv_i64 t0, t1;
1792

P
pbrook 已提交
1793 1794
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();
A
Aurelien Jarno 已提交
1795
    tcg_gen_shr_i64(t0, arg1, arg2);
1796 1797 1798
    tcg_gen_subfi_i64(t1, 64, arg2);
    tcg_gen_shl_i64(t1, arg1, t1);
    tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1799 1800
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
A
aurel32 已提交
1801
#endif
1802 1803
}

P
pbrook 已提交
1804
static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1805 1806 1807 1808 1809 1810 1811 1812 1813
{
    /* 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 已提交
1814
static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1815 1816 1817
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
P
pbrook 已提交
1818
        tcg_gen_mov_i64(ret, arg1);
1819 1820 1821 1822 1823
    } else {
        tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
    }
}

1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842
static inline void tcg_gen_setcond_i32(int cond, TCGv_i32 ret,
                                       TCGv_i32 arg1, TCGv_i32 arg2)
{
    tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
}

static inline void tcg_gen_setcond_i64(int cond, TCGv_i64 ret,
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
#if TCG_TARGET_REG_BITS == 64
    tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
#else
    tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
                     TCGV_LOW(arg1), TCGV_HIGH(arg1),
                     TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
#endif
}

B
bellard 已提交
1843 1844 1845 1846 1847 1848 1849
/***************************************/
/* QEMU specific operations. Their type depend on the QEMU CPU
   type. */
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
#endif

P
pbrook 已提交
1850 1851 1852 1853 1854
#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
1855
#define tcg_temp_local_new() tcg_temp_local_new_i32()
P
pbrook 已提交
1856 1857 1858 1859
#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 已提交
1860
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
P
pbrook 已提交
1861 1862 1863 1864 1865
#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
1866
#define tcg_temp_local_new() tcg_temp_local_new_i64()
P
pbrook 已提交
1867 1868 1869 1870
#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 已提交
1871
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
P
pbrook 已提交
1872 1873
#endif

1874 1875 1876 1877 1878
/* 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 已提交
1879 1880
    tcg_gen_op2ii(INDEX_op_debug_insn_start, 
                  (uint32_t)(pc), (uint32_t)(pc >> 32));
1881 1882 1883 1884 1885
#else
    tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
#endif
}

B
bellard 已提交
1886 1887
static inline void tcg_gen_exit_tb(tcg_target_long val)
{
P
pbrook 已提交
1888
    tcg_gen_op1i(INDEX_op_exit_tb, val);
B
bellard 已提交
1889 1890 1891 1892
}

static inline void tcg_gen_goto_tb(int idx)
{
P
pbrook 已提交
1893
    tcg_gen_op1i(INDEX_op_goto_tb, idx);
B
bellard 已提交
1894 1895 1896
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1897
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1898 1899
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1900
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
1901
#else
P
pbrook 已提交
1902 1903
    tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1904
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1905 1906 1907
#endif
}

P
pbrook 已提交
1908
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1909 1910
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1911
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
1912
#else
P
pbrook 已提交
1913 1914 1915
    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 已提交
1916 1917 1918
#endif
}

P
pbrook 已提交
1919
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1920 1921
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1922
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
1923
#else
P
pbrook 已提交
1924 1925
    tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1926
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1927 1928 1929
#endif
}

P
pbrook 已提交
1930
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1931 1932
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1933
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
1934
#else
P
pbrook 已提交
1935 1936 1937
    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 已提交
1938 1939 1940
#endif
}

P
pbrook 已提交
1941
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1942 1943
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1944
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1945
#else
P
pbrook 已提交
1946 1947
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1948
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1949 1950 1951
#endif
}

P
pbrook 已提交
1952
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1953 1954
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1955
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1956
#else
P
pbrook 已提交
1957 1958 1959
    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 已提交
1960 1961 1962
#endif
}

P
pbrook 已提交
1963
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
1964 1965
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1966
    tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
B
bellard 已提交
1967
#else
P
pbrook 已提交
1968 1969
    tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1970 1971 1972
#endif
}

P
pbrook 已提交
1973
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1974 1975
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1976
    tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
1977
#else
P
pbrook 已提交
1978 1979
    tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1980 1981 1982
#endif
}

P
pbrook 已提交
1983
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1984 1985
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1986
    tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
1987
#else
P
pbrook 已提交
1988 1989
    tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1990 1991 1992
#endif
}

P
pbrook 已提交
1993
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
1994 1995
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1996
    tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
1997
#else
P
pbrook 已提交
1998 1999
    tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2000 2001 2002
#endif
}

P
pbrook 已提交
2003
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2004 2005
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2006 2007
    tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
                     mem_index);
B
bellard 已提交
2008
#else
P
pbrook 已提交
2009 2010
    tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2011 2012 2013
#endif
}

B
blueswir1 已提交
2014
#define tcg_gen_ld_ptr tcg_gen_ld_i32
B
blueswir1 已提交
2015
#define tcg_gen_discard_ptr tcg_gen_discard_i32
2016

B
bellard 已提交
2017 2018
#else /* TCG_TARGET_REG_BITS == 32 */

P
pbrook 已提交
2019
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2020
{
P
pbrook 已提交
2021
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
2022 2023
}

P
pbrook 已提交
2024
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2025
{
P
pbrook 已提交
2026
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2027 2028
}

P
pbrook 已提交
2029
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2030
{
P
pbrook 已提交
2031
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2032 2033
}

P
pbrook 已提交
2034
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2035
{
P
pbrook 已提交
2036
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2037 2038
}

P
pbrook 已提交
2039
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2040
{
P
pbrook 已提交
2041
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
2042 2043
}

P
pbrook 已提交
2044
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2045
{
P
pbrook 已提交
2046
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
B
bellard 已提交
2047 2048
}

P
pbrook 已提交
2049
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2050
{
P
pbrook 已提交
2051
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
B
bellard 已提交
2052 2053
}

P
pbrook 已提交
2054
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2055
{
P
pbrook 已提交
2056
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2057 2058
}

P
pbrook 已提交
2059
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2060
{
P
pbrook 已提交
2061
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2062 2063
}

P
pbrook 已提交
2064
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2065
{
P
pbrook 已提交
2066
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2067 2068
}

P
pbrook 已提交
2069
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2070
{
P
pbrook 已提交
2071
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
B
bellard 已提交
2072 2073
}

B
blueswir1 已提交
2074
#define tcg_gen_ld_ptr tcg_gen_ld_i64
B
blueswir1 已提交
2075
#define tcg_gen_discard_ptr tcg_gen_discard_i64
2076

B
bellard 已提交
2077
#endif /* TCG_TARGET_REG_BITS != 32 */
2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096

#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 已提交
2097
#define tcg_gen_neg_tl tcg_gen_neg_i64
P
pbrook 已提交
2098
#define tcg_gen_subfi_tl tcg_gen_subfi_i64
2099 2100 2101 2102 2103 2104 2105
#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 已提交
2106
#define tcg_gen_not_tl tcg_gen_not_i64
2107 2108 2109 2110 2111 2112
#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 已提交
2113
#define tcg_gen_brcond_tl tcg_gen_brcond_i64
P
pbrook 已提交
2114
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2115
#define tcg_gen_setcond_tl tcg_gen_setcond_i64
2116 2117
#define tcg_gen_mul_tl tcg_gen_mul_i64
#define tcg_gen_muli_tl tcg_gen_muli_i64
2118 2119
#define tcg_gen_div_tl tcg_gen_div_i64
#define tcg_gen_rem_tl tcg_gen_rem_i64
A
aurel32 已提交
2120 2121
#define tcg_gen_divu_tl tcg_gen_divu_i64
#define tcg_gen_remu_tl tcg_gen_remu_i64
B
blueswir1 已提交
2122
#define tcg_gen_discard_tl tcg_gen_discard_i64
2123 2124 2125 2126 2127 2128
#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 已提交
2129 2130 2131 2132 2133 2134
#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
2135 2136 2137
#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
2138
#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2139 2140 2141 2142 2143
#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
2144 2145 2146 2147
#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 已提交
2148
#define tcg_const_tl tcg_const_i64
A
aurel32 已提交
2149
#define tcg_const_local_tl tcg_const_local_i64
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
#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 已提交
2168
#define tcg_gen_neg_tl tcg_gen_neg_i32
A
aurel32 已提交
2169
#define tcg_gen_subfi_tl tcg_gen_subfi_i32
2170 2171 2172 2173 2174 2175 2176
#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 已提交
2177
#define tcg_gen_not_tl tcg_gen_not_i32
2178 2179 2180 2181 2182 2183
#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 已提交
2184
#define tcg_gen_brcond_tl tcg_gen_brcond_i32
P
pbrook 已提交
2185
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2186
#define tcg_gen_setcond_tl tcg_gen_setcond_i32
2187 2188
#define tcg_gen_mul_tl tcg_gen_mul_i32
#define tcg_gen_muli_tl tcg_gen_muli_i32
2189 2190
#define tcg_gen_div_tl tcg_gen_div_i32
#define tcg_gen_rem_tl tcg_gen_rem_i32
A
aurel32 已提交
2191 2192
#define tcg_gen_divu_tl tcg_gen_divu_i32
#define tcg_gen_remu_tl tcg_gen_remu_i32
B
blueswir1 已提交
2193
#define tcg_gen_discard_tl tcg_gen_discard_i32
2194 2195 2196 2197 2198 2199
#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 已提交
2200 2201 2202 2203 2204 2205
#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
2206 2207
#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2208
#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2209 2210 2211 2212 2213
#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
2214 2215 2216 2217
#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 已提交
2218
#define tcg_const_tl tcg_const_i32
A
aurel32 已提交
2219
#define tcg_const_local_tl tcg_const_local_i32
2220
#endif
P
pbrook 已提交
2221 2222

#if TCG_TARGET_REG_BITS == 32
2223
#define tcg_gen_add_ptr tcg_gen_add_i32
P
pbrook 已提交
2224
#define tcg_gen_addi_ptr tcg_gen_addi_i32
2225
#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
P
pbrook 已提交
2226
#else /* TCG_TARGET_REG_BITS == 32 */
2227
#define tcg_gen_add_ptr tcg_gen_add_i64
P
pbrook 已提交
2228
#define tcg_gen_addi_ptr tcg_gen_addi_i64
2229
#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
P
pbrook 已提交
2230
#endif /* TCG_TARGET_REG_BITS != 32 */