tcg-op.h 66.4 KB
Newer Older
B
bellard 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * 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
}

592 593 594 595 596 597 598 599 600 601 602 603 604 605
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_setcondi_i32(int cond, TCGv_i32 ret, TCGv_i32 arg1,
                                        int32_t arg2)
{
    TCGv_i32 t0 = tcg_const_i32(arg2);
    tcg_gen_setcond_i32(cond, ret, arg1, t0);
    tcg_temp_free_i32(t0);
}

P
pbrook 已提交
606
static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
607
{
P
pbrook 已提交
608
    tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
B
bellard 已提交
609 610
}

P
pbrook 已提交
611
static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
612
{
P
pbrook 已提交
613
    TCGv_i32 t0 = tcg_const_i32(arg2);
614
    tcg_gen_mul_i32(ret, arg1, t0);
P
pbrook 已提交
615
    tcg_temp_free_i32(t0);
616 617
}

B
bellard 已提交
618
#ifdef TCG_TARGET_HAS_div_i32
P
pbrook 已提交
619
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
620
{
P
pbrook 已提交
621
    tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
B
bellard 已提交
622 623
}

P
pbrook 已提交
624
static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
625
{
P
pbrook 已提交
626
    tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
B
bellard 已提交
627 628
}

P
pbrook 已提交
629
static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
630
{
P
pbrook 已提交
631
    tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
B
bellard 已提交
632 633
}

P
pbrook 已提交
634
static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
635
{
P
pbrook 已提交
636
    tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
B
bellard 已提交
637 638
}
#else
P
pbrook 已提交
639
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
640
{
P
pbrook 已提交
641 642
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
643
    tcg_gen_sari_i32(t0, arg1, 31);
P
pbrook 已提交
644 645
    tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
646 647
}

P
pbrook 已提交
648
static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
649
{
P
pbrook 已提交
650 651
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
652
    tcg_gen_sari_i32(t0, arg1, 31);
P
pbrook 已提交
653 654
    tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
655 656
}

P
pbrook 已提交
657
static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
658
{
P
pbrook 已提交
659 660
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
661
    tcg_gen_movi_i32(t0, 0);
P
pbrook 已提交
662 663
    tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
664 665
}

P
pbrook 已提交
666
static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
667
{
P
pbrook 已提交
668 669
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
670
    tcg_gen_movi_i32(t0, 0);
P
pbrook 已提交
671 672
    tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
673 674 675 676 677
}
#endif

#if TCG_TARGET_REG_BITS == 32

P
pbrook 已提交
678
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
679
{
A
aurel32 已提交
680
    if (!TCGV_EQUAL_I64(ret, arg)) {
P
pbrook 已提交
681
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
682 683
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
    }
B
bellard 已提交
684 685
}

P
pbrook 已提交
686
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
687
{
P
pbrook 已提交
688
    tcg_gen_movi_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
689
    tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
B
bellard 已提交
690 691
}

P
pbrook 已提交
692 693
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
694
{
P
pbrook 已提交
695
    tcg_gen_ld8u_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_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
701
{
P
pbrook 已提交
702 703
    tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
B
bellard 已提交
704 705
}

P
pbrook 已提交
706 707
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
708
{
A
aurel32 已提交
709
    tcg_gen_ld16u_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_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
715
{
P
pbrook 已提交
716 717
    tcg_gen_ld16s_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_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
722
{
P
pbrook 已提交
723
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
724
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
725 726
}

P
pbrook 已提交
727 728
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
729
{
P
pbrook 已提交
730 731
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
732 733
}

P
pbrook 已提交
734 735
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
736 737 738 739
{
    /* since arg2 and ret have different types, they cannot be the
       same temporary */
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
740
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
P
pbrook 已提交
741
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
B
bellard 已提交
742
#else
P
pbrook 已提交
743
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
744
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
B
bellard 已提交
745 746 747
#endif
}

P
pbrook 已提交
748 749
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                   tcg_target_long offset)
B
bellard 已提交
750
{
P
pbrook 已提交
751
    tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
752 753
}

P
pbrook 已提交
754 755
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
756
{
P
pbrook 已提交
757
    tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
758 759
}

P
pbrook 已提交
760 761
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
762
{
P
pbrook 已提交
763
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
764 765
}

P
pbrook 已提交
766 767
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
768 769
{
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
770
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
P
pbrook 已提交
771
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
B
bellard 已提交
772
#else
P
pbrook 已提交
773
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
P
pbrook 已提交
774
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
B
bellard 已提交
775 776 777
#endif
}

P
pbrook 已提交
778
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
779
{
P
pbrook 已提交
780 781 782
    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 已提交
783 784
}

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

P
pbrook 已提交
792
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
793
{
P
pbrook 已提交
794
    tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
795
    tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
796 797
}

P
pbrook 已提交
798
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
799
{
A
aurel32 已提交
800 801
    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 已提交
802 803
}

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

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

P
pbrook 已提交
816
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
817
{
A
aurel32 已提交
818 819
    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 已提交
820 821
}

P
pbrook 已提交
822
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
823
{
P
pbrook 已提交
824
    tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
825
    tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
826 827 828 829
}

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

P
pbrook 已提交
835
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
836 837 838 839
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
}

P
pbrook 已提交
840
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
841
{
P
pbrook 已提交
842
    tcg_gen_helper64(tcg_helper_shr_i64, ret, arg1, arg2);
B
bellard 已提交
843 844
}

P
pbrook 已提交
845
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
846 847 848 849
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
}

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

P
pbrook 已提交
855
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
856 857 858 859
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
}

P
pbrook 已提交
860
static inline void tcg_gen_brcond_i64(int cond, TCGv_i64 arg1, TCGv_i64 arg2,
B
bellard 已提交
861 862
                                      int label_index)
{
P
pbrook 已提交
863 864 865
    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 已提交
866 867
}

868 869 870 871 872 873 874 875 876
static inline void tcg_gen_setcond_i64(int cond, TCGv_i64 ret,
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
    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);
}

P
pbrook 已提交
877
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
878
{
P
pbrook 已提交
879 880
    TCGv_i64 t0;
    TCGv_i32 t1;
B
bellard 已提交
881

P
pbrook 已提交
882 883 884 885 886 887 888
    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 已提交
889
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
890
    tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
891
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
892

B
bellard 已提交
893
    tcg_gen_mov_i64(ret, t0);
P
pbrook 已提交
894 895
    tcg_temp_free_i64(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
896 897
}

P
pbrook 已提交
898
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
899
{
P
pbrook 已提交
900
    tcg_gen_helper64(tcg_helper_div_i64, ret, arg1, arg2);
B
bellard 已提交
901 902
}

P
pbrook 已提交
903
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
904
{
P
pbrook 已提交
905
    tcg_gen_helper64(tcg_helper_rem_i64, ret, arg1, arg2);
B
bellard 已提交
906 907
}

P
pbrook 已提交
908
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
909
{
P
pbrook 已提交
910
    tcg_gen_helper64(tcg_helper_divu_i64, ret, arg1, arg2);
B
bellard 已提交
911 912
}

P
pbrook 已提交
913
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
914
{
P
pbrook 已提交
915
    tcg_gen_helper64(tcg_helper_remu_i64, ret, arg1, arg2);
B
bellard 已提交
916 917 918 919
}

#else

P
pbrook 已提交
920
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
921
{
A
aurel32 已提交
922
    if (!TCGV_EQUAL_I64(ret, arg))
P
pbrook 已提交
923
        tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
B
bellard 已提交
924 925
}

P
pbrook 已提交
926
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
927
{
P
pbrook 已提交
928
    tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
B
bellard 已提交
929 930
}

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

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

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

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

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

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

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

P
pbrook 已提交
972
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
973
                                   tcg_target_long offset)
B
bellard 已提交
974
{
P
pbrook 已提交
975
    tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
B
bellard 已提交
976 977
}

P
pbrook 已提交
978
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
979
                                    tcg_target_long offset)
B
bellard 已提交
980
{
P
pbrook 已提交
981
    tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
B
bellard 已提交
982 983
}

P
pbrook 已提交
984
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
985
                                    tcg_target_long offset)
B
bellard 已提交
986
{
P
pbrook 已提交
987
    tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
B
bellard 已提交
988 989
}

P
pbrook 已提交
990
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_i64 arg2, tcg_target_long offset)
B
bellard 已提交
991
{
P
pbrook 已提交
992
    tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
B
bellard 已提交
993 994
}

P
pbrook 已提交
995
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
996
{
P
pbrook 已提交
997
    tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
B
bellard 已提交
998 999
}

P
pbrook 已提交
1000
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1001
{
P
pbrook 已提交
1002
    tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
B
bellard 已提交
1003 1004
}

P
pbrook 已提交
1005
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1006
{
A
aurel32 已提交
1007 1008 1009 1010 1011
    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 已提交
1012 1013
}

P
pbrook 已提交
1014
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1015
{
P
pbrook 已提交
1016
    TCGv_i64 t0 = tcg_const_i64(arg2);
1017
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1018
    tcg_temp_free_i64(t0);
B
bellard 已提交
1019 1020
}

P
pbrook 已提交
1021
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1022
{
A
aurel32 已提交
1023 1024 1025 1026 1027
    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 已提交
1028 1029
}

P
pbrook 已提交
1030
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1031
{
P
pbrook 已提交
1032
    TCGv_i64 t0 = tcg_const_i64(arg2);
1033
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
1034
    tcg_temp_free_i64(t0);
B
bellard 已提交
1035 1036
}

P
pbrook 已提交
1037
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1038
{
A
aurel32 已提交
1039 1040 1041 1042 1043
    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 已提交
1044 1045
}

P
pbrook 已提交
1046
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1047
{
P
pbrook 已提交
1048
    TCGv_i64 t0 = tcg_const_i64(arg2);
1049
    tcg_gen_xor_i64(ret, arg1, t0);
P
pbrook 已提交
1050
    tcg_temp_free_i64(t0);
B
bellard 已提交
1051 1052
}

P
pbrook 已提交
1053
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1054
{
P
pbrook 已提交
1055
    tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
B
bellard 已提交
1056 1057
}

P
pbrook 已提交
1058
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1059
{
B
bellard 已提交
1060 1061 1062
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1063
        TCGv_i64 t0 = tcg_const_i64(arg2);
1064
        tcg_gen_shl_i64(ret, arg1, t0);
P
pbrook 已提交
1065
        tcg_temp_free_i64(t0);
B
bellard 已提交
1066
    }
B
bellard 已提交
1067 1068
}

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

P
pbrook 已提交
1074
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1075
{
B
bellard 已提交
1076 1077 1078
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1079
        TCGv_i64 t0 = tcg_const_i64(arg2);
1080
        tcg_gen_shr_i64(ret, arg1, t0);
P
pbrook 已提交
1081
        tcg_temp_free_i64(t0);
B
bellard 已提交
1082
    }
B
bellard 已提交
1083 1084
}

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

P
pbrook 已提交
1090
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1091
{
B
bellard 已提交
1092 1093 1094
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1095
        TCGv_i64 t0 = tcg_const_i64(arg2);
1096
        tcg_gen_sar_i64(ret, arg1, t0);
P
pbrook 已提交
1097
        tcg_temp_free_i64(t0);
B
bellard 已提交
1098
    }
B
bellard 已提交
1099 1100
}

P
pbrook 已提交
1101
static inline void tcg_gen_brcond_i64(int cond, TCGv_i64 arg1, TCGv_i64 arg2,
B
bellard 已提交
1102 1103
                                      int label_index)
{
P
pbrook 已提交
1104
    tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
B
bellard 已提交
1105 1106
}

1107 1108 1109 1110 1111 1112
static inline void tcg_gen_setcond_i64(int cond, TCGv_i64 ret,
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
}

P
pbrook 已提交
1113
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1114
{
P
pbrook 已提交
1115
    tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
B
bellard 已提交
1116 1117 1118
}

#ifdef TCG_TARGET_HAS_div_i64
P
pbrook 已提交
1119
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1120
{
P
pbrook 已提交
1121
    tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
B
bellard 已提交
1122 1123
}

P
pbrook 已提交
1124
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1125
{
P
pbrook 已提交
1126
    tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
B
bellard 已提交
1127 1128
}

P
pbrook 已提交
1129
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1130
{
P
pbrook 已提交
1131
    tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
B
bellard 已提交
1132 1133
}

P
pbrook 已提交
1134
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1135
{
P
pbrook 已提交
1136
    tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
B
bellard 已提交
1137 1138
}
#else
P
pbrook 已提交
1139
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1140
{
P
pbrook 已提交
1141 1142
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1143
    tcg_gen_sari_i64(t0, arg1, 63);
P
pbrook 已提交
1144 1145
    tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1146 1147
}

P
pbrook 已提交
1148
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1149
{
P
pbrook 已提交
1150 1151
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1152
    tcg_gen_sari_i64(t0, arg1, 63);
P
pbrook 已提交
1153 1154
    tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1155 1156
}

P
pbrook 已提交
1157
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1158
{
P
pbrook 已提交
1159 1160
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1161
    tcg_gen_movi_i64(t0, 0);
P
pbrook 已提交
1162 1163
    tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1164 1165
}

P
pbrook 已提交
1166
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1167
{
P
pbrook 已提交
1168 1169
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1170
    tcg_gen_movi_i64(t0, 0);
P
pbrook 已提交
1171 1172
    tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1173 1174 1175 1176 1177
}
#endif

#endif

P
pbrook 已提交
1178
static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1179 1180 1181 1182 1183
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1184
        TCGv_i64 t0 = tcg_const_i64(arg2);
1185
        tcg_gen_add_i64(ret, arg1, t0);
P
pbrook 已提交
1186
        tcg_temp_free_i64(t0);
1187 1188 1189
    }
}

P
pbrook 已提交
1190
static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
A
aurel32 已提交
1191
{
P
pbrook 已提交
1192
    TCGv_i64 t0 = tcg_const_i64(arg1);
A
aurel32 已提交
1193
    tcg_gen_sub_i64(ret, t0, arg2);
P
pbrook 已提交
1194
    tcg_temp_free_i64(t0);
A
aurel32 已提交
1195 1196
}

P
pbrook 已提交
1197
static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1198 1199 1200 1201 1202
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1203
        TCGv_i64 t0 = tcg_const_i64(arg2);
1204
        tcg_gen_sub_i64(ret, arg1, t0);
P
pbrook 已提交
1205
        tcg_temp_free_i64(t0);
1206 1207
    }
}
P
pbrook 已提交
1208
static inline void tcg_gen_brcondi_i64(int cond, TCGv_i64 arg1, int64_t arg2,
1209 1210
                                       int label_index)
{
P
pbrook 已提交
1211
    TCGv_i64 t0 = tcg_const_i64(arg2);
1212
    tcg_gen_brcond_i64(cond, arg1, t0, label_index);
P
pbrook 已提交
1213
    tcg_temp_free_i64(t0);
1214 1215
}

1216 1217 1218 1219 1220 1221 1222 1223
static inline void tcg_gen_setcondi_i64(int cond, TCGv_i64 ret, TCGv_i64 arg1,
                                        int64_t arg2)
{
    TCGv_i64 t0 = tcg_const_i64(arg2);
    tcg_gen_setcond_i64(cond, ret, arg1, t0);
    tcg_temp_free_i64(t0);
}

P
pbrook 已提交
1224
static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1225
{
P
pbrook 已提交
1226
    TCGv_i64 t0 = tcg_const_i64(arg2);
1227
    tcg_gen_mul_i64(ret, arg1, t0);
P
pbrook 已提交
1228
    tcg_temp_free_i64(t0);
1229 1230
}

1231

B
bellard 已提交
1232 1233 1234
/***************************************/
/* optional operations */

P
pbrook 已提交
1235
static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1236 1237
{
#ifdef TCG_TARGET_HAS_ext8s_i32
P
pbrook 已提交
1238
    tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
B
bellard 已提交
1239 1240
#else
    tcg_gen_shli_i32(ret, arg, 24);
1241
    tcg_gen_sari_i32(ret, ret, 24);
B
bellard 已提交
1242 1243 1244
#endif
}

P
pbrook 已提交
1245
static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1246 1247
{
#ifdef TCG_TARGET_HAS_ext16s_i32
P
pbrook 已提交
1248
    tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
B
bellard 已提交
1249 1250
#else
    tcg_gen_shli_i32(ret, arg, 16);
1251
    tcg_gen_sari_i32(ret, ret, 16);
B
bellard 已提交
1252 1253 1254
#endif
}

P
pbrook 已提交
1255
static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1256
{
1257 1258 1259
#ifdef TCG_TARGET_HAS_ext8u_i32
    tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
#else
P
pbrook 已提交
1260
    tcg_gen_andi_i32(ret, arg, 0xffu);
1261
#endif
P
pbrook 已提交
1262 1263
}

P
pbrook 已提交
1264
static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1265
{
1266 1267 1268
#ifdef TCG_TARGET_HAS_ext16u_i32
    tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
#else
P
pbrook 已提交
1269
    tcg_gen_andi_i32(ret, arg, 0xffffu);
1270
#endif
P
pbrook 已提交
1271 1272
}

B
bellard 已提交
1273
/* Note: we assume the two high bytes are set to zero */
P
pbrook 已提交
1274
static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1275 1276
{
#ifdef TCG_TARGET_HAS_bswap16_i32
P
pbrook 已提交
1277
    tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
B
bellard 已提交
1278
#else
A
aurel32 已提交
1279
    TCGv_i32 t0 = tcg_temp_new_i32();
B
bellard 已提交
1280
    
A
aurel32 已提交
1281 1282 1283 1284
    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 已提交
1285
    tcg_temp_free_i32(t0);
B
bellard 已提交
1286 1287 1288
#endif
}

A
aurel32 已提交
1289
static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1290
{
A
aurel32 已提交
1291 1292
#ifdef TCG_TARGET_HAS_bswap32_i32
    tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
B
bellard 已提交
1293
#else
P
pbrook 已提交
1294 1295 1296
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
    
    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 已提交
1310 1311
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1312 1313 1314 1315
#endif
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1316
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1317
{
P
pbrook 已提交
1318 1319
    tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1320 1321
}

P
pbrook 已提交
1322
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1323
{
P
pbrook 已提交
1324 1325
    tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1326 1327
}

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

P
pbrook 已提交
1334
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1335
{
P
pbrook 已提交
1336
    tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1337 1338 1339
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1340
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1341
{
P
pbrook 已提交
1342
    tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1343 1344 1345
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1346
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1347
{
P
pbrook 已提交
1348
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1349 1350 1351
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1352
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1353
{
P
pbrook 已提交
1354
    tcg_gen_mov_i32(ret, TCGV_LOW(arg));
B
bellard 已提交
1355 1356
}

P
pbrook 已提交
1357
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1358
{
P
pbrook 已提交
1359
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
1360
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1361 1362
}

P
pbrook 已提交
1363
static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1364
{
P
pbrook 已提交
1365 1366
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1367 1368
}

1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382
/* 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 已提交
1383
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1384
{
P
pbrook 已提交
1385 1386 1387
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1388

A
aurel32 已提交
1389 1390
    tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
    tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
P
pbrook 已提交
1391
    tcg_gen_mov_i32(TCGV_LOW(ret), t1);
P
pbrook 已提交
1392
    tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
P
pbrook 已提交
1393 1394
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1395 1396 1397
}
#else

P
pbrook 已提交
1398
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1399 1400
{
#ifdef TCG_TARGET_HAS_ext8s_i64
P
pbrook 已提交
1401
    tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
B
bellard 已提交
1402 1403
#else
    tcg_gen_shli_i64(ret, arg, 56);
1404
    tcg_gen_sari_i64(ret, ret, 56);
B
bellard 已提交
1405 1406 1407
#endif
}

P
pbrook 已提交
1408
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1409 1410
{
#ifdef TCG_TARGET_HAS_ext16s_i64
P
pbrook 已提交
1411
    tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
B
bellard 已提交
1412 1413
#else
    tcg_gen_shli_i64(ret, arg, 48);
1414
    tcg_gen_sari_i64(ret, ret, 48);
B
bellard 已提交
1415 1416 1417
#endif
}

P
pbrook 已提交
1418
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1419 1420
{
#ifdef TCG_TARGET_HAS_ext32s_i64
P
pbrook 已提交
1421
    tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
B
bellard 已提交
1422 1423
#else
    tcg_gen_shli_i64(ret, arg, 32);
1424
    tcg_gen_sari_i64(ret, ret, 32);
B
bellard 已提交
1425 1426 1427
#endif
}

P
pbrook 已提交
1428
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1429
{
1430 1431 1432
#ifdef TCG_TARGET_HAS_ext8u_i64
    tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
#else
P
pbrook 已提交
1433
    tcg_gen_andi_i64(ret, arg, 0xffu);
1434
#endif
P
pbrook 已提交
1435 1436
}

P
pbrook 已提交
1437
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1438
{
1439 1440 1441
#ifdef TCG_TARGET_HAS_ext16u_i64
    tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
#else
P
pbrook 已提交
1442
    tcg_gen_andi_i64(ret, arg, 0xffffu);
1443
#endif
P
pbrook 已提交
1444 1445
}

P
pbrook 已提交
1446
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1447
{
1448 1449 1450
#ifdef TCG_TARGET_HAS_ext32u_i64
    tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
#else
P
pbrook 已提交
1451
    tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1452
#endif
P
pbrook 已提交
1453 1454
}

B
bellard 已提交
1455
/* Note: we assume the target supports move between 32 and 64 bit
P
pbrook 已提交
1456
   registers.  This will probably break MIPS64 targets.  */
P
pbrook 已提交
1457
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1458
{
P
pbrook 已提交
1459
    tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
B
bellard 已提交
1460 1461 1462 1463
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1464
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1465
{
1466
    tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
B
bellard 已提交
1467 1468 1469 1470
}

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

1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 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 1519
/* 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 已提交
1520
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1521
{
A
aurel32 已提交
1522 1523
#ifdef TCG_TARGET_HAS_bswap64_i64
    tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
B
bellard 已提交
1524
#else
1525 1526
    TCGv_i64 t0 = tcg_temp_new_i64();
    TCGv_i64 t1 = tcg_temp_new_i64();
B
bellard 已提交
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
    
    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);
1556 1557
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
B
bellard 已提交
1558 1559 1560 1561 1562
#endif
}

#endif

P
pbrook 已提交
1563
static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1564 1565
{
#ifdef TCG_TARGET_HAS_neg_i32
P
pbrook 已提交
1566
    tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
P
pbrook 已提交
1567
#else
P
pbrook 已提交
1568
    TCGv_i32 t0 = tcg_const_i32(0);
1569
    tcg_gen_sub_i32(ret, t0, arg);
P
pbrook 已提交
1570
    tcg_temp_free_i32(t0);
P
pbrook 已提交
1571 1572 1573
#endif
}

P
pbrook 已提交
1574
static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1575 1576
{
#ifdef TCG_TARGET_HAS_neg_i64
P
pbrook 已提交
1577
    tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
P
pbrook 已提交
1578
#else
P
pbrook 已提交
1579
    TCGv_i64 t0 = tcg_const_i64(0);
1580
    tcg_gen_sub_i64(ret, t0, arg);
P
pbrook 已提交
1581
    tcg_temp_free_i64(t0);
P
pbrook 已提交
1582 1583 1584
#endif
}

P
pbrook 已提交
1585
static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1586
{
A
aurel32 已提交
1587 1588 1589
#ifdef TCG_TARGET_HAS_not_i32
    tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
#else
1590
    tcg_gen_xori_i32(ret, arg, -1);
A
aurel32 已提交
1591
#endif
B
bellard 已提交
1592 1593
}

P
pbrook 已提交
1594
static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1595
{
A
aurel32 已提交
1596
#ifdef TCG_TARGET_HAS_not_i64
A
aurel32 已提交
1597
    tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
A
aurel32 已提交
1598
#else
1599
    tcg_gen_xori_i64(ret, arg, -1);
A
aurel32 已提交
1600
#endif
B
bellard 已提交
1601
}
1602

P
pbrook 已提交
1603
static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1604
{
P
pbrook 已提交
1605
    tcg_gen_op1_i32(INDEX_op_discard, arg);
1606 1607 1608
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1609
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1610
{
P
pbrook 已提交
1611
    tcg_gen_discard_i32(TCGV_LOW(arg));
1612 1613 1614
    tcg_gen_discard_i32(TCGV_HIGH(arg));
}
#else
P
pbrook 已提交
1615
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1616
{
P
pbrook 已提交
1617
    tcg_gen_op1_i64(INDEX_op_discard, arg);
1618 1619 1620
}
#endif

P
pbrook 已提交
1621
static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
P
pbrook 已提交
1622 1623
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1624
    tcg_gen_mov_i32(TCGV_LOW(dest), low);
P
pbrook 已提交
1625 1626
    tcg_gen_mov_i32(TCGV_HIGH(dest), high);
#else
P
pbrook 已提交
1627
    TCGv_i64 tmp = tcg_temp_new_i64();
P
pbrook 已提交
1628 1629 1630 1631 1632 1633
    /* 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 已提交
1634
    tcg_temp_free_i64(tmp);
P
pbrook 已提交
1635 1636 1637
#endif
}

P
pbrook 已提交
1638
static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low, TCGv_i64 high)
1639 1640
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1641
    tcg_gen_concat_i32_i64(dest, TCGV_LOW(low), TCGV_LOW(high));
1642
#else
P
pbrook 已提交
1643
    TCGv_i64 tmp = tcg_temp_new_i64();
1644
    tcg_gen_ext32u_i64(dest, low);
1645
    tcg_gen_shli_i64(tmp, high, 32);
1646
    tcg_gen_or_i64(dest, dest, tmp);
P
pbrook 已提交
1647
    tcg_temp_free_i64(tmp);
1648 1649 1650
#endif
}

P
pbrook 已提交
1651
static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1652
{
1653 1654 1655
#ifdef TCG_TARGET_HAS_andc_i32
    tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1656 1657
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
1658 1659
    tcg_gen_not_i32(t0, arg2);
    tcg_gen_and_i32(ret, arg1, t0);
P
pbrook 已提交
1660
    tcg_temp_free_i32(t0);
1661
#endif
1662 1663
}

P
pbrook 已提交
1664
static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1665
{
1666 1667 1668 1669 1670 1671
#ifdef TCG_TARGET_HAS_andc_i64
    tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
#elif defined(TCG_TARGET_HAS_andc_i32) && TCG_TARGET_REG_BITS == 32
    tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
    tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
#else
P
pbrook 已提交
1672 1673
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
1674 1675
    tcg_gen_not_i64(t0, arg2);
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1676
    tcg_temp_free_i64(t0);
1677
#endif
1678 1679
}

P
pbrook 已提交
1680
static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1681
{
A
aurel32 已提交
1682 1683
    tcg_gen_xor_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1684 1685
}

P
pbrook 已提交
1686
static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1687
{
A
aurel32 已提交
1688 1689
    tcg_gen_xor_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1690 1691
}

P
pbrook 已提交
1692
static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1693
{
A
aurel32 已提交
1694 1695
    tcg_gen_and_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1696 1697
}

P
pbrook 已提交
1698
static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1699
{
A
aurel32 已提交
1700 1701
    tcg_gen_and_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1702 1703
}

P
pbrook 已提交
1704
static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1705
{
A
aurel32 已提交
1706 1707
    tcg_gen_or_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1708 1709
}

P
pbrook 已提交
1710
static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1711
{
A
aurel32 已提交
1712 1713
    tcg_gen_or_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1714 1715
}

P
pbrook 已提交
1716
static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1717
{
P
pbrook 已提交
1718 1719
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
1720 1721
    tcg_gen_not_i32(t0, arg2);
    tcg_gen_or_i32(ret, arg1, t0);
P
pbrook 已提交
1722
    tcg_temp_free_i32(t0);
1723 1724
}

P
pbrook 已提交
1725
static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1726
{
P
pbrook 已提交
1727 1728
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
1729 1730
    tcg_gen_not_i64(t0, arg2);
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
1731
    tcg_temp_free_i64(t0);
1732 1733
}

P
pbrook 已提交
1734
static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1735
{
A
aurel32 已提交
1736 1737 1738
#ifdef TCG_TARGET_HAS_rot_i32
    tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1739
    TCGv_i32 t0, t1;
1740

P
pbrook 已提交
1741 1742
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
1743 1744 1745 1746
    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 已提交
1747 1748
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
A
aurel32 已提交
1749
#endif
1750 1751
}

P
pbrook 已提交
1752
static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1753
{
A
aurel32 已提交
1754 1755 1756
#ifdef TCG_TARGET_HAS_rot_i64
    tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
#else
P
pbrook 已提交
1757
    TCGv_i64 t0, t1;
1758

P
pbrook 已提交
1759 1760
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();
1761 1762 1763 1764
    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 已提交
1765 1766
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
A
aurel32 已提交
1767
#endif
1768 1769
}

P
pbrook 已提交
1770
static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1771 1772 1773 1774 1775
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
A
aurel32 已提交
1776 1777 1778 1779 1780
#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 已提交
1781 1782 1783
        TCGv_i32 t0, t1;
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
1784 1785 1786
        tcg_gen_shli_i32(t0, arg1, arg2);
        tcg_gen_shri_i32(t1, arg1, 32 - arg2);
        tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1787 1788
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
A
aurel32 已提交
1789
#endif
1790 1791 1792
    }
}

P
pbrook 已提交
1793
static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1794 1795 1796 1797 1798
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
A
aurel32 已提交
1799 1800 1801 1802 1803
#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 已提交
1804 1805 1806
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
1807 1808 1809
        tcg_gen_shli_i64(t0, arg1, arg2);
        tcg_gen_shri_i64(t1, arg1, 64 - arg2);
        tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1810 1811
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
A
aurel32 已提交
1812
#endif
1813 1814 1815
    }
}

P
pbrook 已提交
1816
static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1817
{
A
aurel32 已提交
1818 1819 1820
#ifdef TCG_TARGET_HAS_rot_i32
    tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1821
    TCGv_i32 t0, t1;
1822

P
pbrook 已提交
1823 1824
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
1825 1826 1827 1828
    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 已提交
1829 1830
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
A
aurel32 已提交
1831
#endif
1832 1833
}

P
pbrook 已提交
1834
static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1835
{
A
aurel32 已提交
1836 1837 1838
#ifdef TCG_TARGET_HAS_rot_i64
    tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
#else
P
pbrook 已提交
1839
    TCGv_i64 t0, t1;
1840

P
pbrook 已提交
1841 1842
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();
A
Aurelien Jarno 已提交
1843
    tcg_gen_shr_i64(t0, arg1, arg2);
1844 1845 1846
    tcg_gen_subfi_i64(t1, 64, arg2);
    tcg_gen_shl_i64(t1, arg1, t1);
    tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1847 1848
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
A
aurel32 已提交
1849
#endif
1850 1851
}

P
pbrook 已提交
1852
static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1853 1854 1855 1856 1857 1858 1859 1860 1861
{
    /* 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 已提交
1862
static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1863 1864 1865
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
P
pbrook 已提交
1866
        tcg_gen_mov_i64(ret, arg1);
1867 1868 1869 1870 1871
    } else {
        tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
    }
}

B
bellard 已提交
1872 1873 1874 1875 1876 1877 1878
/***************************************/
/* QEMU specific operations. Their type depend on the QEMU CPU
   type. */
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
#endif

P
pbrook 已提交
1879 1880 1881 1882 1883
#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
1884
#define tcg_temp_local_new() tcg_temp_local_new_i32()
P
pbrook 已提交
1885 1886 1887 1888
#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 已提交
1889
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
P
pbrook 已提交
1890 1891 1892 1893 1894
#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
1895
#define tcg_temp_local_new() tcg_temp_local_new_i64()
P
pbrook 已提交
1896 1897 1898 1899
#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 已提交
1900
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
P
pbrook 已提交
1901 1902
#endif

1903 1904 1905 1906 1907
/* 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 已提交
1908 1909
    tcg_gen_op2ii(INDEX_op_debug_insn_start, 
                  (uint32_t)(pc), (uint32_t)(pc >> 32));
1910 1911 1912 1913 1914
#else
    tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
#endif
}

B
bellard 已提交
1915 1916
static inline void tcg_gen_exit_tb(tcg_target_long val)
{
P
pbrook 已提交
1917
    tcg_gen_op1i(INDEX_op_exit_tb, val);
B
bellard 已提交
1918 1919 1920 1921
}

static inline void tcg_gen_goto_tb(int idx)
{
P
pbrook 已提交
1922
    tcg_gen_op1i(INDEX_op_goto_tb, idx);
B
bellard 已提交
1923 1924 1925
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1926
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1927 1928
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1929
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
1930
#else
P
pbrook 已提交
1931 1932
    tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1933
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1934 1935 1936
#endif
}

P
pbrook 已提交
1937
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1938 1939
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1940
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
1941
#else
P
pbrook 已提交
1942 1943 1944
    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 已提交
1945 1946 1947
#endif
}

P
pbrook 已提交
1948
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1949 1950
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1951
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
1952
#else
P
pbrook 已提交
1953 1954
    tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1955
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1956 1957 1958
#endif
}

P
pbrook 已提交
1959
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1960 1961
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1962
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
1963
#else
P
pbrook 已提交
1964 1965 1966
    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 已提交
1967 1968 1969
#endif
}

P
pbrook 已提交
1970
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1971 1972
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1973
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1974
#else
P
pbrook 已提交
1975 1976
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
1977
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1978 1979 1980
#endif
}

P
pbrook 已提交
1981
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1982 1983
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1984
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
1985
#else
P
pbrook 已提交
1986 1987 1988
    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 已提交
1989 1990 1991
#endif
}

P
pbrook 已提交
1992
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
1993 1994
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1995
    tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
B
bellard 已提交
1996
#else
P
pbrook 已提交
1997 1998
    tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
1999 2000 2001
#endif
}

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

P
pbrook 已提交
2012
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2013 2014
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2015
    tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2016
#else
P
pbrook 已提交
2017 2018
    tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2019 2020 2021
#endif
}

P
pbrook 已提交
2022
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2023 2024
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2025
    tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2026
#else
P
pbrook 已提交
2027 2028
    tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2029 2030 2031
#endif
}

P
pbrook 已提交
2032
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2033 2034
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2035 2036
    tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
                     mem_index);
B
bellard 已提交
2037
#else
P
pbrook 已提交
2038 2039
    tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2040 2041 2042
#endif
}

B
blueswir1 已提交
2043
#define tcg_gen_ld_ptr tcg_gen_ld_i32
B
blueswir1 已提交
2044
#define tcg_gen_discard_ptr tcg_gen_discard_i32
2045

B
bellard 已提交
2046 2047
#else /* TCG_TARGET_REG_BITS == 32 */

P
pbrook 已提交
2048
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2049
{
P
pbrook 已提交
2050
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
2051 2052
}

P
pbrook 已提交
2053
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2054
{
P
pbrook 已提交
2055
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2056 2057
}

P
pbrook 已提交
2058
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2059
{
P
pbrook 已提交
2060
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2061 2062
}

P
pbrook 已提交
2063
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2064
{
P
pbrook 已提交
2065
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2066 2067
}

P
pbrook 已提交
2068
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2069
{
P
pbrook 已提交
2070
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
2071 2072
}

P
pbrook 已提交
2073
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2074
{
P
pbrook 已提交
2075
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
B
bellard 已提交
2076 2077
}

P
pbrook 已提交
2078
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2079
{
P
pbrook 已提交
2080
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
B
bellard 已提交
2081 2082
}

P
pbrook 已提交
2083
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2084
{
P
pbrook 已提交
2085
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2086 2087
}

P
pbrook 已提交
2088
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2089
{
P
pbrook 已提交
2090
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2091 2092
}

P
pbrook 已提交
2093
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2094
{
P
pbrook 已提交
2095
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2096 2097
}

P
pbrook 已提交
2098
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2099
{
P
pbrook 已提交
2100
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
B
bellard 已提交
2101 2102
}

B
blueswir1 已提交
2103
#define tcg_gen_ld_ptr tcg_gen_ld_i64
B
blueswir1 已提交
2104
#define tcg_gen_discard_ptr tcg_gen_discard_i64
2105

B
bellard 已提交
2106
#endif /* TCG_TARGET_REG_BITS != 32 */
2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125

#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 已提交
2126
#define tcg_gen_neg_tl tcg_gen_neg_i64
P
pbrook 已提交
2127
#define tcg_gen_subfi_tl tcg_gen_subfi_i64
2128 2129 2130 2131 2132 2133 2134
#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 已提交
2135
#define tcg_gen_not_tl tcg_gen_not_i64
2136 2137 2138 2139 2140 2141
#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 已提交
2142
#define tcg_gen_brcond_tl tcg_gen_brcond_i64
P
pbrook 已提交
2143
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2144
#define tcg_gen_setcond_tl tcg_gen_setcond_i64
A
Aurelien Jarno 已提交
2145
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
2146 2147
#define tcg_gen_mul_tl tcg_gen_mul_i64
#define tcg_gen_muli_tl tcg_gen_muli_i64
2148 2149
#define tcg_gen_div_tl tcg_gen_div_i64
#define tcg_gen_rem_tl tcg_gen_rem_i64
A
aurel32 已提交
2150 2151
#define tcg_gen_divu_tl tcg_gen_divu_i64
#define tcg_gen_remu_tl tcg_gen_remu_i64
B
blueswir1 已提交
2152
#define tcg_gen_discard_tl tcg_gen_discard_i64
2153 2154 2155 2156 2157 2158
#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 已提交
2159 2160 2161 2162 2163 2164
#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
2165 2166 2167
#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
2168
#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2169 2170 2171 2172 2173
#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
2174 2175 2176 2177
#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 已提交
2178
#define tcg_const_tl tcg_const_i64
A
aurel32 已提交
2179
#define tcg_const_local_tl tcg_const_local_i64
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197
#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 已提交
2198
#define tcg_gen_neg_tl tcg_gen_neg_i32
A
aurel32 已提交
2199
#define tcg_gen_subfi_tl tcg_gen_subfi_i32
2200 2201 2202 2203 2204 2205 2206
#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 已提交
2207
#define tcg_gen_not_tl tcg_gen_not_i32
2208 2209 2210 2211 2212 2213
#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 已提交
2214
#define tcg_gen_brcond_tl tcg_gen_brcond_i32
P
pbrook 已提交
2215
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2216
#define tcg_gen_setcond_tl tcg_gen_setcond_i32
A
Aurelien Jarno 已提交
2217
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
2218 2219
#define tcg_gen_mul_tl tcg_gen_mul_i32
#define tcg_gen_muli_tl tcg_gen_muli_i32
2220 2221
#define tcg_gen_div_tl tcg_gen_div_i32
#define tcg_gen_rem_tl tcg_gen_rem_i32
A
aurel32 已提交
2222 2223
#define tcg_gen_divu_tl tcg_gen_divu_i32
#define tcg_gen_remu_tl tcg_gen_remu_i32
B
blueswir1 已提交
2224
#define tcg_gen_discard_tl tcg_gen_discard_i32
2225 2226 2227 2228 2229 2230
#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 已提交
2231 2232 2233 2234 2235 2236
#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
2237 2238
#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2239
#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2240 2241 2242 2243 2244
#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
2245 2246 2247 2248
#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 已提交
2249
#define tcg_const_tl tcg_const_i32
A
aurel32 已提交
2250
#define tcg_const_local_tl tcg_const_local_i32
2251
#endif
P
pbrook 已提交
2252 2253

#if TCG_TARGET_REG_BITS == 32
2254
#define tcg_gen_add_ptr tcg_gen_add_i32
P
pbrook 已提交
2255
#define tcg_gen_addi_ptr tcg_gen_addi_i32
2256
#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
P
pbrook 已提交
2257
#else /* TCG_TARGET_REG_BITS == 32 */
2258
#define tcg_gen_add_ptr tcg_gen_add_i64
P
pbrook 已提交
2259
#define tcg_gen_addi_ptr tcg_gen_addi_i64
2260
#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
P
pbrook 已提交
2261
#endif /* TCG_TARGET_REG_BITS != 32 */