tcg-op.h 83.0 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);

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

34
static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
P
pbrook 已提交
35 36 37
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
B
bellard 已提交
38 39
}

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

46
static inline void tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2)
P
pbrook 已提交
47 48 49 50 51 52
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
}

53
static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
P
pbrook 已提交
54 55 56 57 58 59
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
}

60
static inline void tcg_gen_op2i_i32(TCGOpcode 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
}

67
static inline void tcg_gen_op2i_i64(TCGOpcode 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
}

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

81
static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
82 83 84 85 86 87 88 89
                                   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);
}

90
static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
91 92 93 94 95 96 97 98
                                   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);
}

99 100
static inline void tcg_gen_op3i_i32(TCGOpcode 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
}

108 109
static inline void tcg_gen_op3i_i64(TCGOpcode 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
}

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

126 127
static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
                                       TCGv_ptr base, TCGArg offset)
P
pbrook 已提交
128 129
{
    *gen_opc_ptr++ = opc;
B
blueswir1 已提交
130
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
P
pbrook 已提交
131 132 133 134
    *gen_opparam_ptr++ = GET_TCGV_PTR(base);
    *gen_opparam_ptr++ = offset;
}

135 136
static inline void tcg_gen_qemu_ldst_op_i64_i32(TCGOpcode opc, TCGv_i64 val,
                                                TCGv_i32 addr, TCGArg mem_index)
P
pbrook 已提交
137 138 139 140 141 142 143
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
    *gen_opparam_ptr++ = GET_TCGV_I32(addr);
    *gen_opparam_ptr++ = mem_index;
}

144 145
static inline void tcg_gen_qemu_ldst_op_i64_i64(TCGOpcode opc, TCGv_i64 val,
                                                TCGv_i64 addr, TCGArg mem_index)
P
pbrook 已提交
146 147 148 149 150 151 152
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
    *gen_opparam_ptr++ = GET_TCGV_I64(addr);
    *gen_opparam_ptr++ = mem_index;
}

153
static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
154 155 156 157 158 159 160 161 162
                                   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);
}

163
static inline void tcg_gen_op4_i64(TCGOpcode 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
{
    *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);
}

173
static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
174 175 176 177 178 179 180 181 182
                                    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;
}

183
static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
184
                                    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
}

193
static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
194
                                     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;
}

203
static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
204
                                     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
}

213
static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
214 215 216 217 218 219 220 221 222 223
                                   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);
}

224
static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
225 226 227 228 229 230 231 232 233 234
                                   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);
}

235
static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
236
                                    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
}

246
static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
247
                                    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;
}

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
static inline void tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 arg1,
                                     TCGv_i32 arg2, TCGv_i32 arg3,
                                     TCGArg arg4, TCGArg 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++ = arg4;
    *gen_opparam_ptr++ = arg5;
}

static inline void tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 arg1,
                                     TCGv_i64 arg2, TCGv_i64 arg3,
                                     TCGArg arg4, TCGArg 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++ = arg4;
    *gen_opparam_ptr++ = arg5;
}

281
static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
282 283 284 285 286 287 288 289 290 291 292 293
                                   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);
}

294
static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
295 296
                                   TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
                                   TCGv_i64 arg6)
B
bellard 已提交
297 298
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
299 300 301 302 303 304
    *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 已提交
305 306
}

307
static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
308 309 310 311 312 313 314 315 316 317 318 319
                                    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;
}

320
static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
321 322 323 324 325 326 327 328 329 330 331 332
                                    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;
}

333 334 335
static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 arg1,
                                     TCGv_i32 arg2, TCGv_i32 arg3,
                                     TCGv_i32 arg4, TCGArg arg5, TCGArg arg6)
P
pbrook 已提交
336 337
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
338 339 340 341 342 343 344 345
    *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;
}

346 347 348
static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 arg1,
                                     TCGv_i64 arg2, TCGv_i64 arg3,
                                     TCGv_i64 arg4, TCGArg arg5, TCGArg arg6)
P
pbrook 已提交
349 350 351 352 353 354
{
    *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 已提交
355 356 357 358 359 360
    *gen_opparam_ptr++ = arg5;
    *gen_opparam_ptr++ = arg6;
}

static inline void gen_set_label(int n)
{
P
pbrook 已提交
361
    tcg_gen_op1i(INDEX_op_set_label, n);
B
bellard 已提交
362 363
}

B
blueswir1 已提交
364 365 366 367 368
static inline void tcg_gen_br(int label)
{
    tcg_gen_op1i(INDEX_op_br, label);
}

P
pbrook 已提交
369
static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
370
{
A
aurel32 已提交
371
    if (!TCGV_EQUAL_I32(ret, arg))
P
pbrook 已提交
372
        tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
B
bellard 已提交
373 374
}

P
pbrook 已提交
375
static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
B
bellard 已提交
376
{
P
pbrook 已提交
377
    tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
B
bellard 已提交
378 379
}

380 381 382 383 384 385 386
/* A version of dh_sizemask from def-helper.h that doesn't rely on
   preprocessor magic.  */
static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
{
    return (is_64bit << n*2) | (is_signed << (n*2 + 1));
}

B
bellard 已提交
387
/* helper calls */
P
pbrook 已提交
388 389 390 391
static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
                                   TCGArg ret, int nargs, TCGArg *args)
{
    TCGv_ptr fn;
392
    fn = tcg_const_ptr(func);
P
pbrook 已提交
393 394 395 396
    tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
                  nargs, args);
    tcg_temp_free_ptr(fn);
}
B
bellard 已提交
397

398 399 400 401 402
/* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
   reserved for helpers in tcg-runtime.c. These helpers are all const
   and pure, hence the call to tcg_gen_callN() with TCG_CALL_CONST |
   TCG_CALL_PURE. This may need to be adjusted if these functions
   start to be used with other helpers. */
403
static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
A
Aurelien Jarno 已提交
404 405 406 407
                                    TCGv_i32 a, TCGv_i32 b)
{
    TCGv_ptr fn;
    TCGArg args[2];
408
    fn = tcg_const_ptr(func);
A
Aurelien Jarno 已提交
409 410
    args[0] = GET_TCGV_I32(a);
    args[1] = GET_TCGV_I32(b);
411 412
    tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
                  GET_TCGV_I32(ret), 2, args);
A
Aurelien Jarno 已提交
413 414 415
    tcg_temp_free_ptr(fn);
}

416
static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
P
pbrook 已提交
417
                                    TCGv_i64 a, TCGv_i64 b)
B
bellard 已提交
418
{
P
pbrook 已提交
419 420
    TCGv_ptr fn;
    TCGArg args[2];
421
    fn = tcg_const_ptr(func);
P
pbrook 已提交
422 423
    args[0] = GET_TCGV_I64(a);
    args[1] = GET_TCGV_I64(b);
424 425
    tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
                  GET_TCGV_I64(ret), 2, args);
P
pbrook 已提交
426
    tcg_temp_free_ptr(fn);
427 428
}

B
bellard 已提交
429 430
/* 32 bit ops */

P
pbrook 已提交
431
static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
432
{
P
pbrook 已提交
433
    tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
B
bellard 已提交
434 435
}

P
pbrook 已提交
436
static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
437
{
P
pbrook 已提交
438
    tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
B
bellard 已提交
439 440
}

P
pbrook 已提交
441
static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
442
{
P
pbrook 已提交
443
    tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
B
bellard 已提交
444 445
}

P
pbrook 已提交
446
static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
447
{
P
pbrook 已提交
448
    tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
B
bellard 已提交
449 450
}

P
pbrook 已提交
451
static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
452
{
P
pbrook 已提交
453
    tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
B
bellard 已提交
454 455
}

P
pbrook 已提交
456
static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
457
{
P
pbrook 已提交
458
    tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
B
bellard 已提交
459 460
}

P
pbrook 已提交
461
static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
462
{
P
pbrook 已提交
463
    tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
B
bellard 已提交
464 465
}

P
pbrook 已提交
466
static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
467
{
P
pbrook 已提交
468
    tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
B
bellard 已提交
469 470
}

P
pbrook 已提交
471
static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
472
{
P
pbrook 已提交
473
    tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
B
bellard 已提交
474 475
}

P
pbrook 已提交
476
static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
477
{
478 479 480 481
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
482
        TCGv_i32 t0 = tcg_const_i32(arg2);
483
        tcg_gen_add_i32(ret, arg1, t0);
P
pbrook 已提交
484
        tcg_temp_free_i32(t0);
485
    }
B
bellard 已提交
486 487
}

P
pbrook 已提交
488
static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
489
{
P
pbrook 已提交
490
    tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
B
bellard 已提交
491 492
}

P
pbrook 已提交
493
static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
A
aurel32 已提交
494
{
P
pbrook 已提交
495
    TCGv_i32 t0 = tcg_const_i32(arg1);
A
aurel32 已提交
496
    tcg_gen_sub_i32(ret, t0, arg2);
P
pbrook 已提交
497
    tcg_temp_free_i32(t0);
A
aurel32 已提交
498 499
}

P
pbrook 已提交
500
static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
501
{
502 503 504 505
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
506
        TCGv_i32 t0 = tcg_const_i32(arg2);
507
        tcg_gen_sub_i32(ret, arg1, t0);
P
pbrook 已提交
508
        tcg_temp_free_i32(t0);
509
    }
B
bellard 已提交
510 511
}

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

521
static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
B
bellard 已提交
522
{
523 524 525 526
    TCGv_i32 t0;
    /* Some cases can be optimized here.  */
    switch (arg2) {
    case 0:
B
bellard 已提交
527
        tcg_gen_movi_i32(ret, 0);
528 529
        return;
    case 0xffffffffu:
B
bellard 已提交
530
        tcg_gen_mov_i32(ret, arg1);
531 532 533 534 535 536 537 538 539 540 541 542 543 544
        return;
    case 0xffu:
        /* Don't recurse with tcg_gen_ext8u_i32.  */
        if (TCG_TARGET_HAS_ext8u_i32) {
            tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg1);
            return;
        }
        break;
    case 0xffffu:
        if (TCG_TARGET_HAS_ext16u_i32) {
            tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg1);
            return;
        }
        break;
B
bellard 已提交
545
    }
546 547 548
    t0 = tcg_const_i32(arg2);
    tcg_gen_and_i32(ret, arg1, t0);
    tcg_temp_free_i32(t0);
B
bellard 已提交
549 550
}

P
pbrook 已提交
551
static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
552
{
A
aurel32 已提交
553 554 555 556 557
    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 已提交
558 559
}

P
pbrook 已提交
560
static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
561
{
562 563 564
    /* Some cases can be optimized here.  */
    if (arg2 == -1) {
        tcg_gen_movi_i32(ret, -1);
B
bellard 已提交
565 566 567
    } else if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
568
        TCGv_i32 t0 = tcg_const_i32(arg2);
569
        tcg_gen_or_i32(ret, arg1, t0);
P
pbrook 已提交
570
        tcg_temp_free_i32(t0);
B
bellard 已提交
571 572 573
    }
}

P
pbrook 已提交
574
static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
575
{
A
aurel32 已提交
576 577 578 579 580
    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 已提交
581 582
}

P
pbrook 已提交
583
static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
584
{
585
    /* Some cases can be optimized here.  */
B
bellard 已提交
586 587
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
588 589 590
    } else if (arg2 == -1 && TCG_TARGET_HAS_not_i32) {
        /* Don't recurse with tcg_gen_not_i32.  */
        tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg1);
B
bellard 已提交
591
    } else {
P
pbrook 已提交
592
        TCGv_i32 t0 = tcg_const_i32(arg2);
593
        tcg_gen_xor_i32(ret, arg1, t0);
P
pbrook 已提交
594
        tcg_temp_free_i32(t0);
B
bellard 已提交
595 596 597
    }
}

P
pbrook 已提交
598
static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
599
{
P
pbrook 已提交
600
    tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
B
bellard 已提交
601 602
}

P
pbrook 已提交
603
static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
604
{
B
bellard 已提交
605 606 607
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
608
        TCGv_i32 t0 = tcg_const_i32(arg2);
609
        tcg_gen_shl_i32(ret, arg1, t0);
P
pbrook 已提交
610
        tcg_temp_free_i32(t0);
B
bellard 已提交
611
    }
B
bellard 已提交
612 613
}

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

P
pbrook 已提交
619
static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
620
{
B
bellard 已提交
621 622 623
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
624
        TCGv_i32 t0 = tcg_const_i32(arg2);
625
        tcg_gen_shr_i32(ret, arg1, t0);
P
pbrook 已提交
626
        tcg_temp_free_i32(t0);
B
bellard 已提交
627
    }
B
bellard 已提交
628 629
}

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

P
pbrook 已提交
635
static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
636
{
B
bellard 已提交
637 638 639
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
640
        TCGv_i32 t0 = tcg_const_i32(arg2);
641
        tcg_gen_sar_i32(ret, arg1, t0);
P
pbrook 已提交
642
        tcg_temp_free_i32(t0);
B
bellard 已提交
643
    }
B
bellard 已提交
644 645
}

646 647
static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
                                      TCGv_i32 arg2, int label_index)
B
bellard 已提交
648
{
P
pbrook 已提交
649
    tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
B
bellard 已提交
650 651
}

652 653
static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
                                       int32_t arg2, int label_index)
P
pbrook 已提交
654
{
P
pbrook 已提交
655
    TCGv_i32 t0 = tcg_const_i32(arg2);
P
pbrook 已提交
656
    tcg_gen_brcond_i32(cond, arg1, t0, label_index);
P
pbrook 已提交
657
    tcg_temp_free_i32(t0);
P
pbrook 已提交
658 659
}

660
static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
661 662 663 664 665
                                       TCGv_i32 arg1, TCGv_i32 arg2)
{
    tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
}

666 667
static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
                                        TCGv_i32 arg1, int32_t arg2)
668 669 670 671 672 673
{
    TCGv_i32 t0 = tcg_const_i32(arg2);
    tcg_gen_setcond_i32(cond, ret, arg1, t0);
    tcg_temp_free_i32(t0);
}

P
pbrook 已提交
674
static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
675
{
P
pbrook 已提交
676
    tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
B
bellard 已提交
677 678
}

P
pbrook 已提交
679
static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
680
{
P
pbrook 已提交
681
    TCGv_i32 t0 = tcg_const_i32(arg2);
682
    tcg_gen_mul_i32(ret, arg1, t0);
P
pbrook 已提交
683
    tcg_temp_free_i32(t0);
684 685
}

P
pbrook 已提交
686
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
687
{
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
    if (TCG_TARGET_HAS_div_i32) {
        tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
    } else if (TCG_TARGET_HAS_div2_i32) {
        TCGv_i32 t0 = tcg_temp_new_i32();
        tcg_gen_sari_i32(t0, arg1, 31);
        tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
        tcg_temp_free_i32(t0);
    } else {
        int sizemask = 0;
        /* Return value and both arguments are 32-bit and signed.  */
        sizemask |= tcg_gen_sizemask(0, 0, 1);
        sizemask |= tcg_gen_sizemask(1, 0, 1);
        sizemask |= tcg_gen_sizemask(2, 0, 1);
        tcg_gen_helper32(tcg_helper_div_i32, sizemask, ret, arg1, arg2);
    }
A
Aurelien Jarno 已提交
703 704 705 706
}

static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
    if (TCG_TARGET_HAS_div_i32) {
        tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
    } else if (TCG_TARGET_HAS_div2_i32) {
        TCGv_i32 t0 = tcg_temp_new_i32();
        tcg_gen_sari_i32(t0, arg1, 31);
        tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
        tcg_temp_free_i32(t0);
    } else {
        int sizemask = 0;
        /* Return value and both arguments are 32-bit and signed.  */
        sizemask |= tcg_gen_sizemask(0, 0, 1);
        sizemask |= tcg_gen_sizemask(1, 0, 1);
        sizemask |= tcg_gen_sizemask(2, 0, 1);
        tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2);
    }
A
Aurelien Jarno 已提交
722 723 724 725
}

static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
    if (TCG_TARGET_HAS_div_i32) {
        tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
    } else if (TCG_TARGET_HAS_div2_i32) {
        TCGv_i32 t0 = tcg_temp_new_i32();
        tcg_gen_movi_i32(t0, 0);
        tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
        tcg_temp_free_i32(t0);
    } else {
        int sizemask = 0;
        /* Return value and both arguments are 32-bit and unsigned.  */
        sizemask |= tcg_gen_sizemask(0, 0, 0);
        sizemask |= tcg_gen_sizemask(1, 0, 0);
        sizemask |= tcg_gen_sizemask(2, 0, 0);
        tcg_gen_helper32(tcg_helper_divu_i32, sizemask, ret, arg1, arg2);
    }
A
Aurelien Jarno 已提交
741 742 743 744
}

static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
    if (TCG_TARGET_HAS_div_i32) {
        tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
    } else if (TCG_TARGET_HAS_div2_i32) {
        TCGv_i32 t0 = tcg_temp_new_i32();
        tcg_gen_movi_i32(t0, 0);
        tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
        tcg_temp_free_i32(t0);
    } else {
        int sizemask = 0;
        /* Return value and both arguments are 32-bit and unsigned.  */
        sizemask |= tcg_gen_sizemask(0, 0, 0);
        sizemask |= tcg_gen_sizemask(1, 0, 0);
        sizemask |= tcg_gen_sizemask(2, 0, 0);
        tcg_gen_helper32(tcg_helper_remu_i32, sizemask, ret, arg1, arg2);
    }
A
Aurelien Jarno 已提交
760
}
B
bellard 已提交
761 762 763

#if TCG_TARGET_REG_BITS == 32

P
pbrook 已提交
764
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
765
{
A
aurel32 已提交
766
    if (!TCGV_EQUAL_I64(ret, arg)) {
P
pbrook 已提交
767
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
768 769
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
    }
B
bellard 已提交
770 771
}

P
pbrook 已提交
772
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
773
{
P
pbrook 已提交
774
    tcg_gen_movi_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
775
    tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
B
bellard 已提交
776 777
}

P
pbrook 已提交
778 779
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
780
{
P
pbrook 已提交
781
    tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
782
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
783 784
}

P
pbrook 已提交
785 786
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
787
{
P
pbrook 已提交
788 789
    tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
B
bellard 已提交
790 791
}

P
pbrook 已提交
792 793
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
794
{
A
aurel32 已提交
795
    tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
796
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
797 798
}

P
pbrook 已提交
799 800
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
801
{
P
pbrook 已提交
802 803
    tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
804 805
}

P
pbrook 已提交
806 807
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
808
{
P
pbrook 已提交
809
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
810
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
811 812
}

P
pbrook 已提交
813 814
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
815
{
P
pbrook 已提交
816 817
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
818 819
}

P
pbrook 已提交
820 821
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
822 823 824 825
{
    /* since arg2 and ret have different types, they cannot be the
       same temporary */
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
826
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
P
pbrook 已提交
827
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
B
bellard 已提交
828
#else
P
pbrook 已提交
829
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
830
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
B
bellard 已提交
831 832 833
#endif
}

P
pbrook 已提交
834 835
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                   tcg_target_long offset)
B
bellard 已提交
836
{
P
pbrook 已提交
837
    tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
838 839
}

P
pbrook 已提交
840 841
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
842
{
P
pbrook 已提交
843
    tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
844 845
}

P
pbrook 已提交
846 847
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
848
{
P
pbrook 已提交
849
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
850 851
}

P
pbrook 已提交
852 853
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
854 855
{
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
856
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
P
pbrook 已提交
857
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
B
bellard 已提交
858
#else
P
pbrook 已提交
859
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
P
pbrook 已提交
860
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
B
bellard 已提交
861 862 863
#endif
}

P
pbrook 已提交
864
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
865
{
P
pbrook 已提交
866 867 868
    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 已提交
869 870
}

P
pbrook 已提交
871
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
872
{
P
pbrook 已提交
873 874 875
    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 已提交
876 877
}

P
pbrook 已提交
878
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
879
{
P
pbrook 已提交
880
    tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
881
    tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
882 883
}

P
pbrook 已提交
884
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
885
{
A
aurel32 已提交
886 887
    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 已提交
888 889
}

P
pbrook 已提交
890
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
891
{
A
aurel32 已提交
892 893
    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 已提交
894 895
}

P
pbrook 已提交
896
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
897
{
P
pbrook 已提交
898
    tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
899
    tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
900 901
}

P
pbrook 已提交
902
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
903
{
A
aurel32 已提交
904 905
    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 已提交
906 907
}

P
pbrook 已提交
908
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
909
{
P
pbrook 已提交
910
    tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
911
    tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
912 913 914 915
}

/* XXX: use generic code when basic block handling is OK or CPU
   specific code (x86) */
P
pbrook 已提交
916
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
917
{
918 919 920 921 922 923 924
    int sizemask = 0;
    /* Return value and both arguments are 64-bit and signed.  */
    sizemask |= tcg_gen_sizemask(0, 1, 1);
    sizemask |= tcg_gen_sizemask(1, 1, 1);
    sizemask |= tcg_gen_sizemask(2, 1, 1);

    tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
B
bellard 已提交
925 926
}

P
pbrook 已提交
927
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
928 929 930 931
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
}

P
pbrook 已提交
932
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
933
{
934 935 936 937 938 939 940
    int sizemask = 0;
    /* Return value and both arguments are 64-bit and signed.  */
    sizemask |= tcg_gen_sizemask(0, 1, 1);
    sizemask |= tcg_gen_sizemask(1, 1, 1);
    sizemask |= tcg_gen_sizemask(2, 1, 1);

    tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
B
bellard 已提交
941 942
}

P
pbrook 已提交
943
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
944 945 946 947
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
}

P
pbrook 已提交
948
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
949
{
950 951 952 953 954 955 956
    int sizemask = 0;
    /* Return value and both arguments are 64-bit and signed.  */
    sizemask |= tcg_gen_sizemask(0, 1, 1);
    sizemask |= tcg_gen_sizemask(1, 1, 1);
    sizemask |= tcg_gen_sizemask(2, 1, 1);

    tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
B
bellard 已提交
957 958
}

P
pbrook 已提交
959
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
960 961 962 963
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
}

964 965
static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
                                      TCGv_i64 arg2, int label_index)
B
bellard 已提交
966
{
P
pbrook 已提交
967 968 969
    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 已提交
970 971
}

972
static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
973 974 975 976 977 978 979 980
                                       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 已提交
981
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
982
{
P
pbrook 已提交
983 984
    TCGv_i64 t0;
    TCGv_i32 t1;
B
bellard 已提交
985

P
pbrook 已提交
986 987 988 989 990 991 992
    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 已提交
993
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
994
    tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
995
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
996

B
bellard 已提交
997
    tcg_gen_mov_i64(ret, t0);
P
pbrook 已提交
998 999
    tcg_temp_free_i64(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1000 1001
}

P
pbrook 已提交
1002
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1003
{
1004 1005 1006 1007 1008 1009 1010
    int sizemask = 0;
    /* Return value and both arguments are 64-bit and signed.  */
    sizemask |= tcg_gen_sizemask(0, 1, 1);
    sizemask |= tcg_gen_sizemask(1, 1, 1);
    sizemask |= tcg_gen_sizemask(2, 1, 1);

    tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
B
bellard 已提交
1011 1012
}

P
pbrook 已提交
1013
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1014
{
1015 1016 1017 1018 1019 1020 1021
    int sizemask = 0;
    /* Return value and both arguments are 64-bit and signed.  */
    sizemask |= tcg_gen_sizemask(0, 1, 1);
    sizemask |= tcg_gen_sizemask(1, 1, 1);
    sizemask |= tcg_gen_sizemask(2, 1, 1);

    tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
B
bellard 已提交
1022 1023
}

P
pbrook 已提交
1024
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1025
{
1026 1027 1028 1029 1030 1031 1032
    int sizemask = 0;
    /* Return value and both arguments are 64-bit and unsigned.  */
    sizemask |= tcg_gen_sizemask(0, 1, 0);
    sizemask |= tcg_gen_sizemask(1, 1, 0);
    sizemask |= tcg_gen_sizemask(2, 1, 0);

    tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
B
bellard 已提交
1033 1034
}

P
pbrook 已提交
1035
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1036
{
1037 1038 1039 1040 1041 1042 1043
    int sizemask = 0;
    /* Return value and both arguments are 64-bit and unsigned.  */
    sizemask |= tcg_gen_sizemask(0, 1, 0);
    sizemask |= tcg_gen_sizemask(1, 1, 0);
    sizemask |= tcg_gen_sizemask(2, 1, 0);

    tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
B
bellard 已提交
1044 1045 1046 1047
}

#else

P
pbrook 已提交
1048
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1049
{
A
aurel32 已提交
1050
    if (!TCGV_EQUAL_I64(ret, arg))
P
pbrook 已提交
1051
        tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
B
bellard 已提交
1052 1053
}

P
pbrook 已提交
1054
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
1055
{
P
pbrook 已提交
1056
    tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
B
bellard 已提交
1057 1058
}

1059
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1060
                                    tcg_target_long offset)
B
bellard 已提交
1061
{
P
pbrook 已提交
1062
    tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
B
bellard 已提交
1063 1064
}

1065
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1066
                                    tcg_target_long offset)
B
bellard 已提交
1067
{
P
pbrook 已提交
1068
    tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
B
bellard 已提交
1069 1070
}

1071
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1072
                                     tcg_target_long offset)
B
bellard 已提交
1073
{
P
pbrook 已提交
1074
    tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
B
bellard 已提交
1075 1076
}

1077
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1078
                                     tcg_target_long offset)
B
bellard 已提交
1079
{
P
pbrook 已提交
1080
    tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
B
bellard 已提交
1081 1082
}

1083
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1084
                                     tcg_target_long offset)
B
bellard 已提交
1085
{
P
pbrook 已提交
1086
    tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
B
bellard 已提交
1087 1088
}

1089
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1090
                                     tcg_target_long offset)
B
bellard 已提交
1091
{
P
pbrook 已提交
1092
    tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
B
bellard 已提交
1093 1094
}

1095
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
1096
{
P
pbrook 已提交
1097
    tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
B
bellard 已提交
1098 1099
}

1100
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
P
pbrook 已提交
1101
                                   tcg_target_long offset)
B
bellard 已提交
1102
{
P
pbrook 已提交
1103
    tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
B
bellard 已提交
1104 1105
}

1106
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
P
pbrook 已提交
1107
                                    tcg_target_long offset)
B
bellard 已提交
1108
{
P
pbrook 已提交
1109
    tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
B
bellard 已提交
1110 1111
}

1112
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
P
pbrook 已提交
1113
                                    tcg_target_long offset)
B
bellard 已提交
1114
{
P
pbrook 已提交
1115
    tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
B
bellard 已提交
1116 1117
}

1118
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
1119
{
P
pbrook 已提交
1120
    tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
B
bellard 已提交
1121 1122
}

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

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

P
pbrook 已提交
1133
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1134
{
A
aurel32 已提交
1135 1136 1137 1138 1139
    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 已提交
1140 1141
}

1142
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
B
bellard 已提交
1143
{
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
    TCGv_i64 t0;
    /* Some cases can be optimized here.  */
    switch (arg2) {
    case 0:
        tcg_gen_movi_i64(ret, 0);
        return;
    case 0xffffffffffffffffull:
        tcg_gen_mov_i64(ret, arg1);
        return;
    case 0xffull:
        /* Don't recurse with tcg_gen_ext8u_i32.  */
        if (TCG_TARGET_HAS_ext8u_i64) {
            tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg1);
            return;
        }
        break;
    case 0xffffu:
        if (TCG_TARGET_HAS_ext16u_i64) {
            tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg1);
            return;
        }
        break;
    case 0xffffffffull:
        if (TCG_TARGET_HAS_ext32u_i64) {
            tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg1);
            return;
        }
        break;
    }
    t0 = tcg_const_i64(arg2);
1174
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1175
    tcg_temp_free_i64(t0);
B
bellard 已提交
1176 1177
}

P
pbrook 已提交
1178
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1179
{
A
aurel32 已提交
1180 1181 1182 1183 1184
    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 已提交
1185 1186
}

P
pbrook 已提交
1187
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1188
{
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
    /* Some cases can be optimized here.  */
    if (arg2 == -1) {
        tcg_gen_movi_i64(ret, -1);
    } else if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_or_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
    }
B
bellard 已提交
1199 1200
}

P
pbrook 已提交
1201
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1202
{
A
aurel32 已提交
1203 1204 1205 1206 1207
    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 已提交
1208 1209
}

P
pbrook 已提交
1210
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1211
{
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
    /* Some cases can be optimized here.  */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else if (arg2 == -1 && TCG_TARGET_HAS_not_i64) {
        /* Don't recurse with tcg_gen_not_i64.  */
        tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
    } else {
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_xor_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
    }
B
bellard 已提交
1223 1224
}

P
pbrook 已提交
1225
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1226
{
P
pbrook 已提交
1227
    tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
B
bellard 已提交
1228 1229
}

P
pbrook 已提交
1230
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1231
{
B
bellard 已提交
1232 1233 1234
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1235
        TCGv_i64 t0 = tcg_const_i64(arg2);
1236
        tcg_gen_shl_i64(ret, arg1, t0);
P
pbrook 已提交
1237
        tcg_temp_free_i64(t0);
B
bellard 已提交
1238
    }
B
bellard 已提交
1239 1240
}

P
pbrook 已提交
1241
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1242
{
P
pbrook 已提交
1243
    tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
B
bellard 已提交
1244 1245
}

P
pbrook 已提交
1246
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1247
{
B
bellard 已提交
1248 1249 1250
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1251
        TCGv_i64 t0 = tcg_const_i64(arg2);
1252
        tcg_gen_shr_i64(ret, arg1, t0);
P
pbrook 已提交
1253
        tcg_temp_free_i64(t0);
B
bellard 已提交
1254
    }
B
bellard 已提交
1255 1256
}

P
pbrook 已提交
1257
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1258
{
P
pbrook 已提交
1259
    tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
B
bellard 已提交
1260 1261
}

P
pbrook 已提交
1262
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1263
{
B
bellard 已提交
1264 1265 1266
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1267
        TCGv_i64 t0 = tcg_const_i64(arg2);
1268
        tcg_gen_sar_i64(ret, arg1, t0);
P
pbrook 已提交
1269
        tcg_temp_free_i64(t0);
B
bellard 已提交
1270
    }
B
bellard 已提交
1271 1272
}

1273 1274
static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
                                      TCGv_i64 arg2, int label_index)
B
bellard 已提交
1275
{
P
pbrook 已提交
1276
    tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
B
bellard 已提交
1277 1278
}

1279
static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1280 1281 1282 1283 1284
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
}

P
pbrook 已提交
1285
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1286
{
P
pbrook 已提交
1287
    tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
B
bellard 已提交
1288 1289
}

A
Aurelien Jarno 已提交
1290 1291
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
    if (TCG_TARGET_HAS_div_i64) {
        tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
    } else if (TCG_TARGET_HAS_div2_i64) {
        TCGv_i64 t0 = tcg_temp_new_i64();
        tcg_gen_sari_i64(t0, arg1, 63);
        tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
        tcg_temp_free_i64(t0);
    } else {
        int sizemask = 0;
        /* Return value and both arguments are 64-bit and signed.  */
        sizemask |= tcg_gen_sizemask(0, 1, 1);
        sizemask |= tcg_gen_sizemask(1, 1, 1);
        sizemask |= tcg_gen_sizemask(2, 1, 1);
        tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
    }
A
Aurelien Jarno 已提交
1307 1308 1309 1310
}

static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
    if (TCG_TARGET_HAS_div_i64) {
        tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
    } else if (TCG_TARGET_HAS_div2_i64) {
        TCGv_i64 t0 = tcg_temp_new_i64();
        tcg_gen_sari_i64(t0, arg1, 63);
        tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
        tcg_temp_free_i64(t0);
    } else {
        int sizemask = 0;
        /* Return value and both arguments are 64-bit and signed.  */
        sizemask |= tcg_gen_sizemask(0, 1, 1);
        sizemask |= tcg_gen_sizemask(1, 1, 1);
        sizemask |= tcg_gen_sizemask(2, 1, 1);
        tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
    }
A
Aurelien Jarno 已提交
1326 1327 1328 1329
}

static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
    if (TCG_TARGET_HAS_div_i64) {
        tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
    } else if (TCG_TARGET_HAS_div2_i64) {
        TCGv_i64 t0 = tcg_temp_new_i64();
        tcg_gen_movi_i64(t0, 0);
        tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
        tcg_temp_free_i64(t0);
    } else {
        int sizemask = 0;
        /* Return value and both arguments are 64-bit and unsigned.  */
        sizemask |= tcg_gen_sizemask(0, 1, 0);
        sizemask |= tcg_gen_sizemask(1, 1, 0);
        sizemask |= tcg_gen_sizemask(2, 1, 0);
        tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
    }
A
Aurelien Jarno 已提交
1345 1346 1347 1348
}

static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
    if (TCG_TARGET_HAS_div_i64) {
        tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
    } else if (TCG_TARGET_HAS_div2_i64) {
        TCGv_i64 t0 = tcg_temp_new_i64();
        tcg_gen_movi_i64(t0, 0);
        tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
        tcg_temp_free_i64(t0);
    } else {
        int sizemask = 0;
        /* Return value and both arguments are 64-bit and unsigned.  */
        sizemask |= tcg_gen_sizemask(0, 1, 0);
        sizemask |= tcg_gen_sizemask(1, 1, 0);
        sizemask |= tcg_gen_sizemask(2, 1, 0);
        tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
    }
A
Aurelien Jarno 已提交
1364
}
1365
#endif /* TCG_TARGET_REG_BITS == 32 */
B
bellard 已提交
1366

P
pbrook 已提交
1367
static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1368 1369 1370 1371 1372
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1373
        TCGv_i64 t0 = tcg_const_i64(arg2);
1374
        tcg_gen_add_i64(ret, arg1, t0);
P
pbrook 已提交
1375
        tcg_temp_free_i64(t0);
1376 1377 1378
    }
}

P
pbrook 已提交
1379
static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
A
aurel32 已提交
1380
{
P
pbrook 已提交
1381
    TCGv_i64 t0 = tcg_const_i64(arg1);
A
aurel32 已提交
1382
    tcg_gen_sub_i64(ret, t0, arg2);
P
pbrook 已提交
1383
    tcg_temp_free_i64(t0);
A
aurel32 已提交
1384 1385
}

P
pbrook 已提交
1386
static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1387 1388 1389 1390 1391
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1392
        TCGv_i64 t0 = tcg_const_i64(arg2);
1393
        tcg_gen_sub_i64(ret, arg1, t0);
P
pbrook 已提交
1394
        tcg_temp_free_i64(t0);
1395 1396
    }
}
1397 1398
static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
                                       int64_t arg2, int label_index)
1399
{
P
pbrook 已提交
1400
    TCGv_i64 t0 = tcg_const_i64(arg2);
1401
    tcg_gen_brcond_i64(cond, arg1, t0, label_index);
P
pbrook 已提交
1402
    tcg_temp_free_i64(t0);
1403 1404
}

1405 1406
static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
                                        TCGv_i64 arg1, int64_t arg2)
1407 1408 1409 1410 1411 1412
{
    TCGv_i64 t0 = tcg_const_i64(arg2);
    tcg_gen_setcond_i64(cond, ret, arg1, t0);
    tcg_temp_free_i64(t0);
}

P
pbrook 已提交
1413
static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1414
{
P
pbrook 已提交
1415
    TCGv_i64 t0 = tcg_const_i64(arg2);
1416
    tcg_gen_mul_i64(ret, arg1, t0);
P
pbrook 已提交
1417
    tcg_temp_free_i64(t0);
1418 1419
}

1420

B
bellard 已提交
1421 1422 1423
/***************************************/
/* optional operations */

P
pbrook 已提交
1424
static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1425
{
1426 1427 1428 1429 1430 1431
    if (TCG_TARGET_HAS_ext8s_i32) {
        tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
    } else {
        tcg_gen_shli_i32(ret, arg, 24);
        tcg_gen_sari_i32(ret, ret, 24);
    }
B
bellard 已提交
1432 1433
}

P
pbrook 已提交
1434
static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1435
{
1436 1437 1438 1439 1440 1441
    if (TCG_TARGET_HAS_ext16s_i32) {
        tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
    } else {
        tcg_gen_shli_i32(ret, arg, 16);
        tcg_gen_sari_i32(ret, ret, 16);
    }
B
bellard 已提交
1442 1443
}

P
pbrook 已提交
1444
static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1445
{
1446 1447 1448 1449 1450
    if (TCG_TARGET_HAS_ext8u_i32) {
        tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
    } else {
        tcg_gen_andi_i32(ret, arg, 0xffu);
    }
P
pbrook 已提交
1451 1452
}

P
pbrook 已提交
1453
static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1454
{
1455 1456 1457 1458 1459
    if (TCG_TARGET_HAS_ext16u_i32) {
        tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
    } else {
        tcg_gen_andi_i32(ret, arg, 0xffffu);
    }
P
pbrook 已提交
1460 1461
}

B
bellard 已提交
1462
/* Note: we assume the two high bytes are set to zero */
P
pbrook 已提交
1463
static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1464
{
1465 1466 1467 1468
    if (TCG_TARGET_HAS_bswap16_i32) {
        tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
    } else {
        TCGv_i32 t0 = tcg_temp_new_i32();
B
bellard 已提交
1469
    
1470 1471 1472 1473 1474 1475
        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);
        tcg_temp_free_i32(t0);
    }
B
bellard 已提交
1476 1477
}

A
aurel32 已提交
1478
static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1479
{
1480 1481 1482 1483 1484 1485
    if (TCG_TARGET_HAS_bswap32_i32) {
        tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
    } else {
        TCGv_i32 t0, t1;
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
B
bellard 已提交
1486
    
1487
        tcg_gen_shli_i32(t0, arg, 24);
B
bellard 已提交
1488
    
1489 1490 1491
        tcg_gen_andi_i32(t1, arg, 0x0000ff00);
        tcg_gen_shli_i32(t1, t1, 8);
        tcg_gen_or_i32(t0, t0, t1);
B
bellard 已提交
1492
    
1493 1494 1495
        tcg_gen_shri_i32(t1, arg, 8);
        tcg_gen_andi_i32(t1, t1, 0x0000ff00);
        tcg_gen_or_i32(t0, t0, t1);
B
bellard 已提交
1496
    
1497 1498 1499 1500 1501
        tcg_gen_shri_i32(t1, arg, 24);
        tcg_gen_or_i32(ret, t0, t1);
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
    }
B
bellard 已提交
1502 1503 1504
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1505
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1506
{
P
pbrook 已提交
1507 1508
    tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1509 1510
}

P
pbrook 已提交
1511
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1512
{
P
pbrook 已提交
1513 1514
    tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1515 1516
}

P
pbrook 已提交
1517
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1518
{
P
pbrook 已提交
1519 1520
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1521 1522
}

P
pbrook 已提交
1523
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1524
{
P
pbrook 已提交
1525
    tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1526 1527 1528
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1529
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1530
{
P
pbrook 已提交
1531
    tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1532 1533 1534
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1535
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1536
{
P
pbrook 已提交
1537
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1538 1539 1540
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1541
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1542
{
P
pbrook 已提交
1543
    tcg_gen_mov_i32(ret, TCGV_LOW(arg));
B
bellard 已提交
1544 1545
}

P
pbrook 已提交
1546
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1547
{
P
pbrook 已提交
1548
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
1549
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1550 1551
}

P
pbrook 已提交
1552
static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1553
{
P
pbrook 已提交
1554 1555
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1556 1557
}

1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571
/* 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 已提交
1572
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1573
{
P
pbrook 已提交
1574 1575 1576
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1577

A
aurel32 已提交
1578 1579
    tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
    tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
P
pbrook 已提交
1580
    tcg_gen_mov_i32(TCGV_LOW(ret), t1);
P
pbrook 已提交
1581
    tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
P
pbrook 已提交
1582 1583
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1584 1585 1586
}
#else

P
pbrook 已提交
1587
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1588
{
1589 1590 1591 1592 1593 1594
    if (TCG_TARGET_HAS_ext8s_i64) {
        tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
    } else {
        tcg_gen_shli_i64(ret, arg, 56);
        tcg_gen_sari_i64(ret, ret, 56);
    }
B
bellard 已提交
1595 1596
}

P
pbrook 已提交
1597
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1598
{
1599 1600 1601 1602 1603 1604
    if (TCG_TARGET_HAS_ext16s_i64) {
        tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
    } else {
        tcg_gen_shli_i64(ret, arg, 48);
        tcg_gen_sari_i64(ret, ret, 48);
    }
B
bellard 已提交
1605 1606
}

P
pbrook 已提交
1607
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1608
{
1609 1610 1611 1612 1613 1614
    if (TCG_TARGET_HAS_ext32s_i64) {
        tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
    } else {
        tcg_gen_shli_i64(ret, arg, 32);
        tcg_gen_sari_i64(ret, ret, 32);
    }
B
bellard 已提交
1615 1616
}

P
pbrook 已提交
1617
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1618
{
1619 1620 1621 1622 1623
    if (TCG_TARGET_HAS_ext8u_i64) {
        tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
    } else {
        tcg_gen_andi_i64(ret, arg, 0xffu);
    }
P
pbrook 已提交
1624 1625
}

P
pbrook 已提交
1626
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1627
{
1628 1629 1630 1631 1632
    if (TCG_TARGET_HAS_ext16u_i64) {
        tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
    } else {
        tcg_gen_andi_i64(ret, arg, 0xffffu);
    }
P
pbrook 已提交
1633 1634
}

P
pbrook 已提交
1635
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1636
{
1637 1638 1639 1640 1641
    if (TCG_TARGET_HAS_ext32u_i64) {
        tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
    } else {
        tcg_gen_andi_i64(ret, arg, 0xffffffffu);
    }
P
pbrook 已提交
1642 1643
}

B
bellard 已提交
1644
/* Note: we assume the target supports move between 32 and 64 bit
P
pbrook 已提交
1645
   registers.  This will probably break MIPS64 targets.  */
P
pbrook 已提交
1646
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1647
{
P
pbrook 已提交
1648
    tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
B
bellard 已提交
1649 1650 1651 1652
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1653
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1654
{
1655
    tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
B
bellard 已提交
1656 1657 1658 1659
}

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

1665 1666 1667
/* Note: we assume the six high bytes are set to zero */
static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
{
1668 1669 1670 1671
    if (TCG_TARGET_HAS_bswap16_i64) {
        tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
    } else {
        TCGv_i64 t0 = tcg_temp_new_i64();
1672

1673 1674 1675 1676 1677 1678
        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);
    }
1679 1680 1681 1682 1683
}

/* Note: we assume the four high bytes are set to zero */
static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
{
1684 1685 1686 1687 1688 1689
    if (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();
1690

1691 1692
        tcg_gen_shli_i64(t0, arg, 24);
        tcg_gen_ext32u_i64(t0, t0);
1693

1694 1695 1696
        tcg_gen_andi_i64(t1, arg, 0x0000ff00);
        tcg_gen_shli_i64(t1, t1, 8);
        tcg_gen_or_i64(t0, t0, t1);
1697

1698 1699 1700
        tcg_gen_shri_i64(t1, arg, 8);
        tcg_gen_andi_i64(t1, t1, 0x0000ff00);
        tcg_gen_or_i64(t0, t0, t1);
1701

1702 1703 1704 1705 1706
        tcg_gen_shri_i64(t1, arg, 24);
        tcg_gen_or_i64(ret, t0, t1);
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
    }
1707 1708
}

A
aurel32 已提交
1709
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1710
{
1711 1712 1713 1714 1715
    if (TCG_TARGET_HAS_bswap64_i64) {
        tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
    } else {
        TCGv_i64 t0 = tcg_temp_new_i64();
        TCGv_i64 t1 = tcg_temp_new_i64();
B
bellard 已提交
1716
    
1717
        tcg_gen_shli_i64(t0, arg, 56);
B
bellard 已提交
1718
    
1719 1720 1721
        tcg_gen_andi_i64(t1, arg, 0x0000ff00);
        tcg_gen_shli_i64(t1, t1, 40);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1722
    
1723 1724 1725
        tcg_gen_andi_i64(t1, arg, 0x00ff0000);
        tcg_gen_shli_i64(t1, t1, 24);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1726

1727 1728 1729
        tcg_gen_andi_i64(t1, arg, 0xff000000);
        tcg_gen_shli_i64(t1, t1, 8);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1730

1731 1732 1733
        tcg_gen_shri_i64(t1, arg, 8);
        tcg_gen_andi_i64(t1, t1, 0xff000000);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1734
    
1735 1736 1737
        tcg_gen_shri_i64(t1, arg, 24);
        tcg_gen_andi_i64(t1, t1, 0x00ff0000);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1738

1739 1740 1741
        tcg_gen_shri_i64(t1, arg, 40);
        tcg_gen_andi_i64(t1, t1, 0x0000ff00);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1742

1743 1744 1745 1746 1747
        tcg_gen_shri_i64(t1, arg, 56);
        tcg_gen_or_i64(ret, t0, t1);
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
    }
B
bellard 已提交
1748 1749 1750 1751
}

#endif

P
pbrook 已提交
1752
static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1753
{
1754 1755 1756 1757 1758 1759 1760
    if (TCG_TARGET_HAS_neg_i32) {
        tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
    } else {
        TCGv_i32 t0 = tcg_const_i32(0);
        tcg_gen_sub_i32(ret, t0, arg);
        tcg_temp_free_i32(t0);
    }
P
pbrook 已提交
1761 1762
}

P
pbrook 已提交
1763
static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1764
{
1765 1766 1767 1768 1769 1770 1771
    if (TCG_TARGET_HAS_neg_i64) {
        tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
    } else {
        TCGv_i64 t0 = tcg_const_i64(0);
        tcg_gen_sub_i64(ret, t0, arg);
        tcg_temp_free_i64(t0);
    }
P
pbrook 已提交
1772 1773
}

P
pbrook 已提交
1774
static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1775
{
1776 1777 1778 1779 1780
    if (TCG_TARGET_HAS_not_i32) {
        tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
    } else {
        tcg_gen_xori_i32(ret, arg, -1);
    }
B
bellard 已提交
1781 1782
}

P
pbrook 已提交
1783
static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1784
{
1785 1786 1787 1788 1789 1790 1791
#if TCG_TARGET_REG_BITS == 64
    if (TCG_TARGET_HAS_not_i64) {
        tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
    } else {
        tcg_gen_xori_i64(ret, arg, -1);
    }
#else
1792 1793
    tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
A
aurel32 已提交
1794
#endif
B
bellard 已提交
1795
}
1796

P
pbrook 已提交
1797
static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1798
{
P
pbrook 已提交
1799
    tcg_gen_op1_i32(INDEX_op_discard, arg);
1800 1801
}

P
pbrook 已提交
1802
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1803
{
1804
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1805
    tcg_gen_discard_i32(TCGV_LOW(arg));
1806 1807
    tcg_gen_discard_i32(TCGV_HIGH(arg));
#else
P
pbrook 已提交
1808
    tcg_gen_op1_i64(INDEX_op_discard, arg);
1809
#endif
1810
}
1811

P
pbrook 已提交
1812
static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1813
{
1814 1815 1816 1817 1818 1819 1820 1821
    if (TCG_TARGET_HAS_andc_i32) {
        tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
    } else {
        TCGv_i32 t0 = tcg_temp_new_i32();
        tcg_gen_not_i32(t0, arg2);
        tcg_gen_and_i32(ret, arg1, t0);
        tcg_temp_free_i32(t0);
    }
1822 1823
}

P
pbrook 已提交
1824
static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1825
{
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835
#if TCG_TARGET_REG_BITS == 64
    if (TCG_TARGET_HAS_andc_i64) {
        tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
    } else {
        TCGv_i64 t0 = tcg_temp_new_i64();
        tcg_gen_not_i64(t0, arg2);
        tcg_gen_and_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
    }
#else
1836 1837 1838
    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));
#endif
1839 1840
}

P
pbrook 已提交
1841
static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1842
{
1843 1844 1845 1846 1847 1848
    if (TCG_TARGET_HAS_eqv_i32) {
        tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
    } else {
        tcg_gen_xor_i32(ret, arg1, arg2);
        tcg_gen_not_i32(ret, ret);
    }
1849 1850
}

P
pbrook 已提交
1851
static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1852
{
1853 1854 1855 1856 1857 1858 1859 1860
#if TCG_TARGET_REG_BITS == 64
    if (TCG_TARGET_HAS_eqv_i64) {
        tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
    } else {
        tcg_gen_xor_i64(ret, arg1, arg2);
        tcg_gen_not_i64(ret, ret);
    }
#else
1861 1862 1863
    tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
    tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
#endif
1864 1865
}

P
pbrook 已提交
1866
static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1867
{
1868 1869 1870 1871 1872 1873
    if (TCG_TARGET_HAS_nand_i32) {
        tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
    } else {
        tcg_gen_and_i32(ret, arg1, arg2);
        tcg_gen_not_i32(ret, ret);
    }
1874 1875
}

P
pbrook 已提交
1876
static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1877
{
1878 1879 1880 1881 1882 1883 1884 1885
#if TCG_TARGET_REG_BITS == 64
    if (TCG_TARGET_HAS_nand_i64) {
        tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
    } else {
        tcg_gen_and_i64(ret, arg1, arg2);
        tcg_gen_not_i64(ret, ret);
    }
#else
1886 1887 1888
    tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
    tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
#endif
1889 1890
}

P
pbrook 已提交
1891
static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1892
{
1893 1894 1895 1896 1897 1898
    if (TCG_TARGET_HAS_nor_i32) {
        tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
    } else {
        tcg_gen_or_i32(ret, arg1, arg2);
        tcg_gen_not_i32(ret, ret);
    }
1899 1900
}

P
pbrook 已提交
1901
static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1902
{
1903 1904 1905 1906 1907 1908 1909 1910
#if TCG_TARGET_REG_BITS == 64
    if (TCG_TARGET_HAS_nor_i64) {
        tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
    } else {
        tcg_gen_or_i64(ret, arg1, arg2);
        tcg_gen_not_i64(ret, ret);
    }
#else
1911 1912 1913
    tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
    tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
#endif
1914 1915
}

P
pbrook 已提交
1916
static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1917
{
1918 1919 1920 1921 1922 1923 1924 1925
    if (TCG_TARGET_HAS_orc_i32) {
        tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
    } else {
        TCGv_i32 t0 = tcg_temp_new_i32();
        tcg_gen_not_i32(t0, arg2);
        tcg_gen_or_i32(ret, arg1, t0);
        tcg_temp_free_i32(t0);
    }
1926 1927
}

P
pbrook 已提交
1928
static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1929
{
1930 1931 1932 1933 1934 1935 1936 1937 1938 1939
#if TCG_TARGET_REG_BITS == 64
    if (TCG_TARGET_HAS_orc_i64) {
        tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
    } else {
        TCGv_i64 t0 = tcg_temp_new_i64();
        tcg_gen_not_i64(t0, arg2);
        tcg_gen_or_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
    }
#else
1940 1941 1942
    tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
    tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
#endif
1943 1944
}

P
pbrook 已提交
1945
static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1946
{
1947 1948 1949 1950
    if (TCG_TARGET_HAS_rot_i32) {
        tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
    } else {
        TCGv_i32 t0, t1;
1951

1952 1953 1954 1955 1956 1957 1958 1959 1960
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
        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);
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
    }
1961 1962
}

P
pbrook 已提交
1963
static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1964
{
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977
    if (TCG_TARGET_HAS_rot_i64) {
        tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
    } else {
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
        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);
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
    }
1978 1979
}

P
pbrook 已提交
1980
static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1981 1982 1983 1984
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
1985
    } else if (TCG_TARGET_HAS_rot_i32) {
A
aurel32 已提交
1986 1987 1988
        TCGv_i32 t0 = tcg_const_i32(arg2);
        tcg_gen_rotl_i32(ret, arg1, t0);
        tcg_temp_free_i32(t0);
1989
    } else {
P
pbrook 已提交
1990 1991 1992
        TCGv_i32 t0, t1;
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
1993 1994 1995
        tcg_gen_shli_i32(t0, arg1, arg2);
        tcg_gen_shri_i32(t1, arg1, 32 - arg2);
        tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1996 1997
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
1998 1999 2000
    }
}

P
pbrook 已提交
2001
static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2002 2003 2004 2005
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
2006
    } else if (TCG_TARGET_HAS_rot_i64) {
A
aurel32 已提交
2007 2008 2009
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_rotl_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
2010
    } else {
P
pbrook 已提交
2011 2012 2013
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
2014 2015 2016
        tcg_gen_shli_i64(t0, arg1, arg2);
        tcg_gen_shri_i64(t1, arg1, 64 - arg2);
        tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
2017 2018
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
2019 2020 2021
    }
}

P
pbrook 已提交
2022
static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2023
{
2024 2025 2026 2027
    if (TCG_TARGET_HAS_rot_i32) {
        tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
    } else {
        TCGv_i32 t0, t1;
2028

2029 2030 2031 2032 2033 2034 2035 2036 2037
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
        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);
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
    }
2038 2039
}

P
pbrook 已提交
2040
static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2041
{
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054
    if (TCG_TARGET_HAS_rot_i64) {
        tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
    } else {
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
        tcg_gen_shr_i64(t0, arg1, arg2);
        tcg_gen_subfi_i64(t1, 64, arg2);
        tcg_gen_shl_i64(t1, arg1, t1);
        tcg_gen_or_i64(ret, t0, t1);
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
    }
2055 2056
}

P
pbrook 已提交
2057
static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2058 2059 2060 2061 2062 2063 2064 2065 2066
{
    /* 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 已提交
2067
static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2068 2069 2070
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
P
pbrook 已提交
2071
        tcg_gen_mov_i64(ret, arg1);
2072 2073 2074 2075 2076
    } else {
        tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
    }
}

2077
static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
2078 2079
                                       TCGv_i32 arg2, unsigned int ofs,
                                       unsigned int len)
2080
{
2081 2082 2083
    uint32_t mask;
    TCGv_i32 t1;

2084 2085 2086 2087
    tcg_debug_assert(ofs < 32);
    tcg_debug_assert(len <= 32);
    tcg_debug_assert(ofs + len <= 32);

2088 2089 2090 2091
    if (ofs == 0 && len == 32) {
        tcg_gen_mov_i32(ret, arg2);
        return;
    }
2092
    if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
2093
        tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
2094 2095 2096 2097 2098
        return;
    }

    mask = (1u << len) - 1;
    t1 = tcg_temp_new_i32();
2099

2100
    if (ofs + len < 32) {
2101 2102
        tcg_gen_andi_i32(t1, arg2, mask);
        tcg_gen_shli_i32(t1, t1, ofs);
2103 2104
    } else {
        tcg_gen_shli_i32(t1, arg2, ofs);
2105
    }
2106 2107 2108 2109
    tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
    tcg_gen_or_i32(ret, ret, t1);

    tcg_temp_free_i32(t1);
2110 2111 2112
}

static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
2113 2114
                                       TCGv_i64 arg2, unsigned int ofs,
                                       unsigned int len)
2115
{
2116 2117 2118
    uint64_t mask;
    TCGv_i64 t1;

2119 2120 2121 2122
    tcg_debug_assert(ofs < 64);
    tcg_debug_assert(len <= 64);
    tcg_debug_assert(ofs + len <= 64);

2123 2124 2125 2126
    if (ofs == 0 && len == 64) {
        tcg_gen_mov_i64(ret, arg2);
        return;
    }
2127
    if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
2128
        tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
2129 2130
        return;
    }
2131

2132 2133
#if TCG_TARGET_REG_BITS == 32
    if (ofs >= 32) {
2134
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
2135 2136 2137 2138 2139 2140 2141
        tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
                            TCGV_LOW(arg2), ofs - 32, len);
        return;
    }
    if (ofs + len <= 32) {
        tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
                            TCGV_LOW(arg2), ofs, len);
2142
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
2143 2144 2145 2146 2147 2148 2149 2150
        return;
    }
#endif

    mask = (1ull << len) - 1;
    t1 = tcg_temp_new_i64();

    if (ofs + len < 64) {
2151 2152
        tcg_gen_andi_i64(t1, arg2, mask);
        tcg_gen_shli_i64(t1, t1, ofs);
2153 2154
    } else {
        tcg_gen_shli_i64(t1, arg2, ofs);
2155
    }
2156 2157 2158 2159
    tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
    tcg_gen_or_i64(ret, ret, t1);

    tcg_temp_free_i64(t1);
2160 2161
}

2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191
static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
                                          TCGv_i32 high)
{
#if TCG_TARGET_REG_BITS == 32
    tcg_gen_mov_i32(TCGV_LOW(dest), low);
    tcg_gen_mov_i32(TCGV_HIGH(dest), high);
#else
    TCGv_i64 tmp = tcg_temp_new_i64();
    /* These extensions are 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_extu_i32_i64(dest, low);
    /* If deposit is available, use it.  Otherwise use the extra
       knowledge that we have of the zero-extensions above.  */
    if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(32, 32)) {
        tcg_gen_deposit_i64(dest, dest, tmp, 32, 32);
    } else {
        tcg_gen_shli_i64(tmp, tmp, 32);
        tcg_gen_or_i64(dest, dest, tmp);
    }
    tcg_temp_free_i64(tmp);
#endif
}

static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low,
                                        TCGv_i64 high)
{
    tcg_gen_deposit_i64(dest, low, high, 32, 32);
}

R
Richard Henderson 已提交
2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214
static inline void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret,
                                       TCGv_i32 c1, TCGv_i32 c2,
                                       TCGv_i32 v1, TCGv_i32 v2)
{
    if (TCG_TARGET_HAS_movcond_i32) {
        tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond);
    } else {
        TCGv_i32 t0 = tcg_temp_new_i32();
        TCGv_i32 t1 = tcg_temp_new_i32();
        tcg_gen_setcond_i32(cond, t0, c1, c2);
        tcg_gen_neg_i32(t0, t0);
        tcg_gen_and_i32(t1, v1, t0);
        tcg_gen_andc_i32(ret, v2, t0);
        tcg_gen_or_i32(ret, ret, t1);
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
    }
}

static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
                                       TCGv_i64 c1, TCGv_i64 c2,
                                       TCGv_i64 v1, TCGv_i64 v2)
{
2215 2216 2217 2218 2219 2220 2221
#if TCG_TARGET_REG_BITS == 32
    TCGv_i32 t0 = tcg_temp_new_i32();
    TCGv_i32 t1 = tcg_temp_new_i32();
    tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
                     TCGV_LOW(c1), TCGV_HIGH(c1),
                     TCGV_LOW(c2), TCGV_HIGH(c2), cond);

2222 2223 2224 2225 2226 2227 2228 2229
    if (TCG_TARGET_HAS_movcond_i32) {
        tcg_gen_movi_i32(t1, 0);
        tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
                            TCGV_LOW(v1), TCGV_LOW(v2));
        tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
                            TCGV_HIGH(v1), TCGV_HIGH(v2));
    } else {
        tcg_gen_neg_i32(t0, t0);
2230

2231 2232 2233
        tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
        tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
        tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
2234

2235 2236 2237 2238
        tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
        tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
        tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
    }
2239 2240 2241
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
#else
R
Richard Henderson 已提交
2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254
    if (TCG_TARGET_HAS_movcond_i64) {
        tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond);
    } else {
        TCGv_i64 t0 = tcg_temp_new_i64();
        TCGv_i64 t1 = tcg_temp_new_i64();
        tcg_gen_setcond_i64(cond, t0, c1, c2);
        tcg_gen_neg_i64(t0, t0);
        tcg_gen_and_i64(t1, v1, t0);
        tcg_gen_andc_i64(ret, v2, t0);
        tcg_gen_or_i64(ret, ret, t1);
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
    }
2255
#endif
R
Richard Henderson 已提交
2256 2257
}

B
bellard 已提交
2258 2259 2260 2261 2262 2263 2264
/***************************************/
/* QEMU specific operations. Their type depend on the QEMU CPU
   type. */
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
#endif

P
pbrook 已提交
2265 2266 2267 2268 2269
#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
2270
#define tcg_temp_local_new() tcg_temp_local_new_i32()
P
pbrook 已提交
2271 2272 2273 2274
#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 已提交
2275
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
P
pbrook 已提交
2276 2277 2278 2279 2280
#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
2281
#define tcg_temp_local_new() tcg_temp_local_new_i64()
P
pbrook 已提交
2282 2283 2284 2285
#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 已提交
2286
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
P
pbrook 已提交
2287 2288
#endif

2289 2290 2291 2292 2293
/* 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 已提交
2294 2295
    tcg_gen_op2ii(INDEX_op_debug_insn_start, 
                  (uint32_t)(pc), (uint32_t)(pc >> 32));
2296 2297 2298 2299 2300
#else
    tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
#endif
}

B
bellard 已提交
2301 2302
static inline void tcg_gen_exit_tb(tcg_target_long val)
{
P
pbrook 已提交
2303
    tcg_gen_op1i(INDEX_op_exit_tb, val);
B
bellard 已提交
2304 2305
}

2306 2307 2308 2309 2310 2311 2312 2313 2314
static inline void tcg_gen_goto_tb(unsigned idx)
{
    /* We only support two chained exits.  */
    tcg_debug_assert(idx <= 1);
#ifdef CONFIG_DEBUG_TCG
    /* Verify that we havn't seen this numbered exit before.  */
    tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
    tcg_ctx.goto_tb_issue_mask |= 1 << idx;
#endif
P
pbrook 已提交
2315
    tcg_gen_op1i(INDEX_op_goto_tb, idx);
B
bellard 已提交
2316 2317 2318
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
2319
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2320 2321
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2322
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
2323
#else
P
pbrook 已提交
2324 2325
    tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2326
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2327 2328 2329
#endif
}

P
pbrook 已提交
2330
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2331 2332
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2333
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2334
#else
P
pbrook 已提交
2335 2336 2337
    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 已提交
2338 2339 2340
#endif
}

P
pbrook 已提交
2341
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2342 2343
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2344
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2345
#else
P
pbrook 已提交
2346 2347
    tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2348
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2349 2350 2351
#endif
}

P
pbrook 已提交
2352
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2353 2354
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2355
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2356
#else
P
pbrook 已提交
2357 2358 2359
    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 已提交
2360 2361 2362
#endif
}

P
pbrook 已提交
2363
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2364 2365
{
#if TARGET_LONG_BITS == 32
2366
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
B
bellard 已提交
2367
#else
2368
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
P
pbrook 已提交
2369
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2370
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2371 2372 2373
#endif
}

P
pbrook 已提交
2374
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2375 2376
{
#if TARGET_LONG_BITS == 32
2377
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
B
bellard 已提交
2378
#else
2379
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
P
pbrook 已提交
2380 2381
                     TCGV_HIGH(addr), mem_index);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
2382 2383 2384
#endif
}

P
pbrook 已提交
2385
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2386 2387
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2388
    tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
B
bellard 已提交
2389
#else
P
pbrook 已提交
2390 2391
    tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2392 2393 2394
#endif
}

P
pbrook 已提交
2395
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2396 2397
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2398
    tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2399
#else
P
pbrook 已提交
2400 2401
    tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2402 2403 2404
#endif
}

P
pbrook 已提交
2405
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2406 2407
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2408
    tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2409
#else
P
pbrook 已提交
2410 2411
    tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2412 2413 2414
#endif
}

P
pbrook 已提交
2415
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2416 2417
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2418
    tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2419
#else
P
pbrook 已提交
2420 2421
    tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2422 2423 2424
#endif
}

P
pbrook 已提交
2425
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2426 2427
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2428 2429
    tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
                     mem_index);
B
bellard 已提交
2430
#else
P
pbrook 已提交
2431 2432
    tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2433 2434 2435
#endif
}

2436 2437
#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
#define tcg_gen_discard_ptr(A) tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
2438

B
bellard 已提交
2439 2440
#else /* TCG_TARGET_REG_BITS == 32 */

P
pbrook 已提交
2441
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2442
{
P
pbrook 已提交
2443
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
2444 2445
}

P
pbrook 已提交
2446
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2447
{
P
pbrook 已提交
2448
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2449 2450
}

P
pbrook 已提交
2451
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2452
{
P
pbrook 已提交
2453
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2454 2455
}

P
pbrook 已提交
2456
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2457
{
P
pbrook 已提交
2458
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2459 2460
}

P
pbrook 已提交
2461
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2462
{
2463 2464 2465
#if TARGET_LONG_BITS == 32
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
#else
P
pbrook 已提交
2466
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
2467
#endif
B
bellard 已提交
2468 2469
}

P
pbrook 已提交
2470
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2471
{
2472 2473 2474
#if TARGET_LONG_BITS == 32
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
#else
P
pbrook 已提交
2475
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
2476
#endif
B
bellard 已提交
2477 2478
}

P
pbrook 已提交
2479
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2480
{
P
pbrook 已提交
2481
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
B
bellard 已提交
2482 2483
}

P
pbrook 已提交
2484
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2485
{
P
pbrook 已提交
2486
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2487 2488
}

P
pbrook 已提交
2489
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2490
{
P
pbrook 已提交
2491
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2492 2493
}

P
pbrook 已提交
2494
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2495
{
P
pbrook 已提交
2496
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2497 2498
}

P
pbrook 已提交
2499
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2500
{
P
pbrook 已提交
2501
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
B
bellard 已提交
2502 2503
}

2504 2505
#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
#define tcg_gen_discard_ptr(A) tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
2506

B
bellard 已提交
2507
#endif /* TCG_TARGET_REG_BITS != 32 */
2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525

#if TARGET_LONG_BITS == 64
#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 已提交
2526
#define tcg_gen_neg_tl tcg_gen_neg_i64
P
pbrook 已提交
2527
#define tcg_gen_subfi_tl tcg_gen_subfi_i64
2528 2529 2530 2531 2532 2533 2534
#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 已提交
2535
#define tcg_gen_not_tl tcg_gen_not_i64
2536 2537 2538 2539 2540 2541
#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 已提交
2542
#define tcg_gen_brcond_tl tcg_gen_brcond_i64
P
pbrook 已提交
2543
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2544
#define tcg_gen_setcond_tl tcg_gen_setcond_i64
A
Aurelien Jarno 已提交
2545
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
2546 2547
#define tcg_gen_mul_tl tcg_gen_mul_i64
#define tcg_gen_muli_tl tcg_gen_muli_i64
2548 2549
#define tcg_gen_div_tl tcg_gen_div_i64
#define tcg_gen_rem_tl tcg_gen_rem_i64
A
aurel32 已提交
2550 2551
#define tcg_gen_divu_tl tcg_gen_divu_i64
#define tcg_gen_remu_tl tcg_gen_remu_i64
B
blueswir1 已提交
2552
#define tcg_gen_discard_tl tcg_gen_discard_i64
2553 2554 2555 2556 2557 2558
#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 已提交
2559 2560 2561 2562 2563 2564
#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
2565 2566 2567
#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
2568
#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2569 2570 2571 2572 2573
#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
2574 2575 2576 2577
#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
2578
#define tcg_gen_deposit_tl tcg_gen_deposit_i64
B
blueswir1 已提交
2579
#define tcg_const_tl tcg_const_i64
A
aurel32 已提交
2580
#define tcg_const_local_tl tcg_const_local_i64
R
Richard Henderson 已提交
2581
#define tcg_gen_movcond_tl tcg_gen_movcond_i64
2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598
#else
#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 已提交
2599
#define tcg_gen_neg_tl tcg_gen_neg_i32
A
aurel32 已提交
2600
#define tcg_gen_subfi_tl tcg_gen_subfi_i32
2601 2602 2603 2604 2605 2606 2607
#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 已提交
2608
#define tcg_gen_not_tl tcg_gen_not_i32
2609 2610 2611 2612 2613 2614
#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 已提交
2615
#define tcg_gen_brcond_tl tcg_gen_brcond_i32
P
pbrook 已提交
2616
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2617
#define tcg_gen_setcond_tl tcg_gen_setcond_i32
A
Aurelien Jarno 已提交
2618
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
2619 2620
#define tcg_gen_mul_tl tcg_gen_mul_i32
#define tcg_gen_muli_tl tcg_gen_muli_i32
2621 2622
#define tcg_gen_div_tl tcg_gen_div_i32
#define tcg_gen_rem_tl tcg_gen_rem_i32
A
aurel32 已提交
2623 2624
#define tcg_gen_divu_tl tcg_gen_divu_i32
#define tcg_gen_remu_tl tcg_gen_remu_i32
B
blueswir1 已提交
2625
#define tcg_gen_discard_tl tcg_gen_discard_i32
2626 2627 2628 2629 2630 2631
#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 已提交
2632 2633 2634 2635 2636 2637
#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
2638 2639
#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2640
#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2641 2642 2643 2644 2645
#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
2646 2647 2648 2649
#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
2650
#define tcg_gen_deposit_tl tcg_gen_deposit_i32
B
blueswir1 已提交
2651
#define tcg_const_tl tcg_const_i32
A
aurel32 已提交
2652
#define tcg_const_local_tl tcg_const_local_i32
R
Richard Henderson 已提交
2653
#define tcg_gen_movcond_tl tcg_gen_movcond_i32
2654
#endif
P
pbrook 已提交
2655 2656

#if TCG_TARGET_REG_BITS == 32
2657 2658 2659 2660 2661 2662
#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), \
                                               TCGV_PTR_TO_NAT(A), \
                                               TCGV_PTR_TO_NAT(B))
#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), \
                                                 TCGV_PTR_TO_NAT(A), (B))
#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
P
pbrook 已提交
2663
#else /* TCG_TARGET_REG_BITS == 32 */
2664 2665 2666 2667 2668 2669
#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), \
                                               TCGV_PTR_TO_NAT(A), \
                                               TCGV_PTR_TO_NAT(B))
#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R),   \
                                                 TCGV_PTR_TO_NAT(A), (B))
#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
P
pbrook 已提交
2670
#endif /* TCG_TARGET_REG_BITS != 32 */