tcg-op.h 80.7 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
{
    /* some cases can be optimized here */
    if (arg2 == 0xffffffff) {
564
        tcg_gen_movi_i32(ret, 0xffffffff);
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 586 587 588
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
589
        TCGv_i32 t0 = tcg_const_i32(arg2);
590
        tcg_gen_xor_i32(ret, arg1, t0);
P
pbrook 已提交
591
        tcg_temp_free_i32(t0);
B
bellard 已提交
592 593 594
    }
}

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

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

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

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

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

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

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

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

657
static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
658 659 660 661 662
                                       TCGv_i32 arg1, TCGv_i32 arg2)
{
    tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
}

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

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

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

P
pbrook 已提交
683
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
684
{
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
    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 已提交
700 701 702 703
}

static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
    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 已提交
719 720 721 722
}

static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
    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 已提交
738 739 740 741
}

static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
    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 已提交
757
}
B
bellard 已提交
758 759 760

#if TCG_TARGET_REG_BITS == 32

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* XXX: use generic code when basic block handling is OK or CPU
   specific code (x86) */
P
pbrook 已提交
913
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
914
{
915 916 917 918 919 920 921
    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 已提交
922 923
}

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

P
pbrook 已提交
929
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
930
{
931 932 933 934 935 936 937
    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 已提交
938 939
}

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

P
pbrook 已提交
945
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
946
{
947 948 949 950 951 952 953
    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 已提交
954 955
}

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

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

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

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

B
bellard 已提交
994
    tcg_gen_mov_i64(ret, t0);
P
pbrook 已提交
995 996
    tcg_temp_free_i64(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
997 998
}

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

P
pbrook 已提交
1010
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1011
{
1012 1013 1014 1015 1016 1017 1018
    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 已提交
1019 1020
}

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

P
pbrook 已提交
1032
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1033
{
1034 1035 1036 1037 1038 1039 1040
    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 已提交
1041 1042 1043 1044
}

#else

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1139
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
B
bellard 已提交
1140
{
1141 1142 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
    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);
1171
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1172
    tcg_temp_free_i64(t0);
B
bellard 已提交
1173 1174
}

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

P
pbrook 已提交
1184
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1185
{
P
pbrook 已提交
1186
    TCGv_i64 t0 = tcg_const_i64(arg2);
1187
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
1188
    tcg_temp_free_i64(t0);
B
bellard 已提交
1189 1190
}

P
pbrook 已提交
1191
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1192
{
A
aurel32 已提交
1193 1194 1195 1196 1197
    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 已提交
1198 1199
}

P
pbrook 已提交
1200
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1201
{
P
pbrook 已提交
1202
    TCGv_i64 t0 = tcg_const_i64(arg2);
1203
    tcg_gen_xor_i64(ret, arg1, t0);
P
pbrook 已提交
1204
    tcg_temp_free_i64(t0);
B
bellard 已提交
1205 1206
}

P
pbrook 已提交
1207
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1208
{
P
pbrook 已提交
1209
    tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
B
bellard 已提交
1210 1211
}

P
pbrook 已提交
1212
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1213
{
B
bellard 已提交
1214 1215 1216
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1217
        TCGv_i64 t0 = tcg_const_i64(arg2);
1218
        tcg_gen_shl_i64(ret, arg1, t0);
P
pbrook 已提交
1219
        tcg_temp_free_i64(t0);
B
bellard 已提交
1220
    }
B
bellard 已提交
1221 1222
}

P
pbrook 已提交
1223
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1224
{
P
pbrook 已提交
1225
    tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
B
bellard 已提交
1226 1227
}

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

P
pbrook 已提交
1239
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1240
{
P
pbrook 已提交
1241
    tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
B
bellard 已提交
1242 1243
}

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

1255 1256
static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
                                      TCGv_i64 arg2, int label_index)
B
bellard 已提交
1257
{
P
pbrook 已提交
1258
    tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
B
bellard 已提交
1259 1260
}

1261
static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1262 1263 1264 1265 1266
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
}

P
pbrook 已提交
1267
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1268
{
P
pbrook 已提交
1269
    tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
B
bellard 已提交
1270 1271
}

A
Aurelien Jarno 已提交
1272 1273
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
    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 已提交
1289 1290 1291 1292
}

static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
    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 已提交
1308 1309 1310 1311
}

static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
    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 已提交
1327 1328 1329 1330
}

static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
    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 已提交
1346
}
1347
#endif /* TCG_TARGET_REG_BITS == 32 */
B
bellard 已提交
1348

P
pbrook 已提交
1349
static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1350 1351 1352 1353 1354
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1355
        TCGv_i64 t0 = tcg_const_i64(arg2);
1356
        tcg_gen_add_i64(ret, arg1, t0);
P
pbrook 已提交
1357
        tcg_temp_free_i64(t0);
1358 1359 1360
    }
}

P
pbrook 已提交
1361
static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
A
aurel32 已提交
1362
{
P
pbrook 已提交
1363
    TCGv_i64 t0 = tcg_const_i64(arg1);
A
aurel32 已提交
1364
    tcg_gen_sub_i64(ret, t0, arg2);
P
pbrook 已提交
1365
    tcg_temp_free_i64(t0);
A
aurel32 已提交
1366 1367
}

P
pbrook 已提交
1368
static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1369 1370 1371 1372 1373
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1374
        TCGv_i64 t0 = tcg_const_i64(arg2);
1375
        tcg_gen_sub_i64(ret, arg1, t0);
P
pbrook 已提交
1376
        tcg_temp_free_i64(t0);
1377 1378
    }
}
1379 1380
static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
                                       int64_t arg2, int label_index)
1381
{
P
pbrook 已提交
1382
    TCGv_i64 t0 = tcg_const_i64(arg2);
1383
    tcg_gen_brcond_i64(cond, arg1, t0, label_index);
P
pbrook 已提交
1384
    tcg_temp_free_i64(t0);
1385 1386
}

1387 1388
static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
                                        TCGv_i64 arg1, int64_t arg2)
1389 1390 1391 1392 1393 1394
{
    TCGv_i64 t0 = tcg_const_i64(arg2);
    tcg_gen_setcond_i64(cond, ret, arg1, t0);
    tcg_temp_free_i64(t0);
}

P
pbrook 已提交
1395
static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1396
{
P
pbrook 已提交
1397
    TCGv_i64 t0 = tcg_const_i64(arg2);
1398
    tcg_gen_mul_i64(ret, arg1, t0);
P
pbrook 已提交
1399
    tcg_temp_free_i64(t0);
1400 1401
}

1402

B
bellard 已提交
1403 1404 1405
/***************************************/
/* optional operations */

P
pbrook 已提交
1406
static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1407
{
1408 1409 1410 1411 1412 1413
    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 已提交
1414 1415
}

P
pbrook 已提交
1416
static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1417
{
1418 1419 1420 1421 1422 1423
    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 已提交
1424 1425
}

P
pbrook 已提交
1426
static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1427
{
1428 1429 1430 1431 1432
    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 已提交
1433 1434
}

P
pbrook 已提交
1435
static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1436
{
1437 1438 1439 1440 1441
    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 已提交
1442 1443
}

B
bellard 已提交
1444
/* Note: we assume the two high bytes are set to zero */
P
pbrook 已提交
1445
static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1446
{
1447 1448 1449 1450
    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 已提交
1451
    
1452 1453 1454 1455 1456 1457
        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 已提交
1458 1459
}

A
aurel32 已提交
1460
static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1461
{
1462 1463 1464 1465 1466 1467
    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 已提交
1468
    
1469
        tcg_gen_shli_i32(t0, arg, 24);
B
bellard 已提交
1470
    
1471 1472 1473
        tcg_gen_andi_i32(t1, arg, 0x0000ff00);
        tcg_gen_shli_i32(t1, t1, 8);
        tcg_gen_or_i32(t0, t0, t1);
B
bellard 已提交
1474
    
1475 1476 1477
        tcg_gen_shri_i32(t1, arg, 8);
        tcg_gen_andi_i32(t1, t1, 0x0000ff00);
        tcg_gen_or_i32(t0, t0, t1);
B
bellard 已提交
1478
    
1479 1480 1481 1482 1483
        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 已提交
1484 1485 1486
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1487
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1488
{
P
pbrook 已提交
1489 1490
    tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1491 1492
}

P
pbrook 已提交
1493
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1494
{
P
pbrook 已提交
1495 1496
    tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1497 1498
}

P
pbrook 已提交
1499
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1500
{
P
pbrook 已提交
1501 1502
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1503 1504
}

P
pbrook 已提交
1505
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1506
{
P
pbrook 已提交
1507
    tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1508 1509 1510
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1511
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1512
{
P
pbrook 已提交
1513
    tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1514 1515 1516
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1517
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1518
{
P
pbrook 已提交
1519
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1520 1521 1522
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1523
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1524
{
P
pbrook 已提交
1525
    tcg_gen_mov_i32(ret, TCGV_LOW(arg));
B
bellard 已提交
1526 1527
}

P
pbrook 已提交
1528
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1529
{
P
pbrook 已提交
1530
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
1531
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1532 1533
}

P
pbrook 已提交
1534
static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1535
{
P
pbrook 已提交
1536 1537
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1538 1539
}

1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553
/* 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 已提交
1554
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1555
{
P
pbrook 已提交
1556 1557 1558
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1559

A
aurel32 已提交
1560 1561
    tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
    tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
P
pbrook 已提交
1562
    tcg_gen_mov_i32(TCGV_LOW(ret), t1);
P
pbrook 已提交
1563
    tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
P
pbrook 已提交
1564 1565
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1566 1567 1568
}
#else

P
pbrook 已提交
1569
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1570
{
1571 1572 1573 1574 1575 1576
    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 已提交
1577 1578
}

P
pbrook 已提交
1579
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1580
{
1581 1582 1583 1584 1585 1586
    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 已提交
1587 1588
}

P
pbrook 已提交
1589
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1590
{
1591 1592 1593 1594 1595 1596
    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 已提交
1597 1598
}

P
pbrook 已提交
1599
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1600
{
1601 1602 1603 1604 1605
    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 已提交
1606 1607
}

P
pbrook 已提交
1608
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1609
{
1610 1611 1612 1613 1614
    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 已提交
1615 1616
}

P
pbrook 已提交
1617
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1618
{
1619 1620 1621 1622 1623
    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 已提交
1624 1625
}

B
bellard 已提交
1626
/* Note: we assume the target supports move between 32 and 64 bit
P
pbrook 已提交
1627
   registers.  This will probably break MIPS64 targets.  */
P
pbrook 已提交
1628
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1629
{
P
pbrook 已提交
1630
    tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
B
bellard 已提交
1631 1632 1633 1634
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1635
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1636
{
1637
    tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
B
bellard 已提交
1638 1639 1640 1641
}

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

1647 1648 1649
/* Note: we assume the six high bytes are set to zero */
static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
{
1650 1651 1652 1653
    if (TCG_TARGET_HAS_bswap16_i64) {
        tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
    } else {
        TCGv_i64 t0 = tcg_temp_new_i64();
1654

1655 1656 1657 1658 1659 1660
        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);
    }
1661 1662 1663 1664 1665
}

/* Note: we assume the four high bytes are set to zero */
static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
{
1666 1667 1668 1669 1670 1671
    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();
1672

1673 1674
        tcg_gen_shli_i64(t0, arg, 24);
        tcg_gen_ext32u_i64(t0, t0);
1675

1676 1677 1678
        tcg_gen_andi_i64(t1, arg, 0x0000ff00);
        tcg_gen_shli_i64(t1, t1, 8);
        tcg_gen_or_i64(t0, t0, t1);
1679

1680 1681 1682
        tcg_gen_shri_i64(t1, arg, 8);
        tcg_gen_andi_i64(t1, t1, 0x0000ff00);
        tcg_gen_or_i64(t0, t0, t1);
1683

1684 1685 1686 1687 1688
        tcg_gen_shri_i64(t1, arg, 24);
        tcg_gen_or_i64(ret, t0, t1);
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
    }
1689 1690
}

A
aurel32 已提交
1691
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1692
{
1693 1694 1695 1696 1697
    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 已提交
1698
    
1699
        tcg_gen_shli_i64(t0, arg, 56);
B
bellard 已提交
1700
    
1701 1702 1703
        tcg_gen_andi_i64(t1, arg, 0x0000ff00);
        tcg_gen_shli_i64(t1, t1, 40);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1704
    
1705 1706 1707
        tcg_gen_andi_i64(t1, arg, 0x00ff0000);
        tcg_gen_shli_i64(t1, t1, 24);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1708

1709 1710 1711
        tcg_gen_andi_i64(t1, arg, 0xff000000);
        tcg_gen_shli_i64(t1, t1, 8);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1712

1713 1714 1715
        tcg_gen_shri_i64(t1, arg, 8);
        tcg_gen_andi_i64(t1, t1, 0xff000000);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1716
    
1717 1718 1719
        tcg_gen_shri_i64(t1, arg, 24);
        tcg_gen_andi_i64(t1, t1, 0x00ff0000);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1720

1721 1722 1723
        tcg_gen_shri_i64(t1, arg, 40);
        tcg_gen_andi_i64(t1, t1, 0x0000ff00);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1724

1725 1726 1727 1728 1729
        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 已提交
1730 1731 1732 1733
}

#endif

P
pbrook 已提交
1734
static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1735
{
1736 1737 1738 1739 1740 1741 1742
    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 已提交
1743 1744
}

P
pbrook 已提交
1745
static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1746
{
1747 1748 1749 1750 1751 1752 1753
    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 已提交
1754 1755
}

P
pbrook 已提交
1756
static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1757
{
1758 1759 1760 1761 1762
    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 已提交
1763 1764
}

P
pbrook 已提交
1765
static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1766
{
1767 1768 1769 1770 1771 1772 1773
#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
1774 1775
    tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
A
aurel32 已提交
1776
#endif
B
bellard 已提交
1777
}
1778

P
pbrook 已提交
1779
static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1780
{
P
pbrook 已提交
1781
    tcg_gen_op1_i32(INDEX_op_discard, arg);
1782 1783
}

P
pbrook 已提交
1784
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1785
{
1786
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1787
    tcg_gen_discard_i32(TCGV_LOW(arg));
1788 1789
    tcg_gen_discard_i32(TCGV_HIGH(arg));
#else
P
pbrook 已提交
1790
    tcg_gen_op1_i64(INDEX_op_discard, arg);
1791
#endif
1792
}
1793

P
pbrook 已提交
1794
static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
P
pbrook 已提交
1795 1796
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1797
    tcg_gen_mov_i32(TCGV_LOW(dest), low);
P
pbrook 已提交
1798 1799
    tcg_gen_mov_i32(TCGV_HIGH(dest), high);
#else
P
pbrook 已提交
1800
    TCGv_i64 tmp = tcg_temp_new_i64();
P
pbrook 已提交
1801 1802 1803 1804 1805 1806
    /* This extension is only needed for type correctness.
       We may be able to do better given target specific information.  */
    tcg_gen_extu_i32_i64(tmp, high);
    tcg_gen_shli_i64(tmp, tmp, 32);
    tcg_gen_extu_i32_i64(dest, low);
    tcg_gen_or_i64(dest, dest, tmp);
P
pbrook 已提交
1807
    tcg_temp_free_i64(tmp);
P
pbrook 已提交
1808 1809 1810
#endif
}

P
pbrook 已提交
1811
static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low, TCGv_i64 high)
1812 1813
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1814
    tcg_gen_concat_i32_i64(dest, TCGV_LOW(low), TCGV_LOW(high));
1815
#else
P
pbrook 已提交
1816
    TCGv_i64 tmp = tcg_temp_new_i64();
1817
    tcg_gen_ext32u_i64(dest, low);
1818
    tcg_gen_shli_i64(tmp, high, 32);
1819
    tcg_gen_or_i64(dest, dest, tmp);
P
pbrook 已提交
1820
    tcg_temp_free_i64(tmp);
1821 1822 1823
#endif
}

P
pbrook 已提交
1824
static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1825
{
1826 1827 1828 1829 1830 1831 1832 1833
    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);
    }
1834 1835
}

P
pbrook 已提交
1836
static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1837
{
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847
#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
1848 1849 1850
    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
1851 1852
}

P
pbrook 已提交
1853
static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1854
{
1855 1856 1857 1858 1859 1860
    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);
    }
1861 1862
}

P
pbrook 已提交
1863
static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1864
{
1865 1866 1867 1868 1869 1870 1871 1872
#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
1873 1874 1875
    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
1876 1877
}

P
pbrook 已提交
1878
static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1879
{
1880 1881 1882 1883 1884 1885
    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);
    }
1886 1887
}

P
pbrook 已提交
1888
static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1889
{
1890 1891 1892 1893 1894 1895 1896 1897
#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
1898 1899 1900
    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
1901 1902
}

P
pbrook 已提交
1903
static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1904
{
1905 1906 1907 1908 1909 1910
    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);
    }
1911 1912
}

P
pbrook 已提交
1913
static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1914
{
1915 1916 1917 1918 1919 1920 1921 1922
#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
1923 1924 1925
    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
1926 1927
}

P
pbrook 已提交
1928
static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1929
{
1930 1931 1932 1933 1934 1935 1936 1937
    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);
    }
1938 1939
}

P
pbrook 已提交
1940
static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1941
{
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951
#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
1952 1953 1954
    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
1955 1956
}

P
pbrook 已提交
1957
static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1958
{
1959 1960 1961 1962
    if (TCG_TARGET_HAS_rot_i32) {
        tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
    } else {
        TCGv_i32 t0, t1;
1963

1964 1965 1966 1967 1968 1969 1970 1971 1972
        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);
    }
1973 1974
}

P
pbrook 已提交
1975
static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1976
{
1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989
    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);
    }
1990 1991
}

P
pbrook 已提交
1992
static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1993 1994 1995 1996
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
1997
    } else if (TCG_TARGET_HAS_rot_i32) {
A
aurel32 已提交
1998 1999 2000
        TCGv_i32 t0 = tcg_const_i32(arg2);
        tcg_gen_rotl_i32(ret, arg1, t0);
        tcg_temp_free_i32(t0);
2001
    } else {
P
pbrook 已提交
2002 2003 2004
        TCGv_i32 t0, t1;
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
2005 2006 2007
        tcg_gen_shli_i32(t0, arg1, arg2);
        tcg_gen_shri_i32(t1, arg1, 32 - arg2);
        tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
2008 2009
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
2010 2011 2012
    }
}

P
pbrook 已提交
2013
static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2014 2015 2016 2017
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
2018
    } else if (TCG_TARGET_HAS_rot_i64) {
A
aurel32 已提交
2019 2020 2021
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_rotl_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
2022
    } else {
P
pbrook 已提交
2023 2024 2025
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
2026 2027 2028
        tcg_gen_shli_i64(t0, arg1, arg2);
        tcg_gen_shri_i64(t1, arg1, 64 - arg2);
        tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
2029 2030
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
2031 2032 2033
    }
}

P
pbrook 已提交
2034
static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2035
{
2036 2037 2038 2039
    if (TCG_TARGET_HAS_rot_i32) {
        tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
    } else {
        TCGv_i32 t0, t1;
2040

2041 2042 2043 2044 2045 2046 2047 2048 2049
        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);
    }
2050 2051
}

P
pbrook 已提交
2052
static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2053
{
2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066
    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);
    }
2067 2068
}

P
pbrook 已提交
2069
static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2070 2071 2072 2073 2074 2075 2076 2077 2078
{
    /* 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 已提交
2079
static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2080 2081 2082
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
P
pbrook 已提交
2083
        tcg_gen_mov_i64(ret, arg1);
2084 2085 2086 2087 2088
    } else {
        tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
    }
}

2089
static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
2090 2091
                                       TCGv_i32 arg2, unsigned int ofs,
                                       unsigned int len)
2092
{
2093 2094 2095 2096 2097 2098 2099
    uint32_t mask;
    TCGv_i32 t1;

    if (ofs == 0 && len == 32) {
        tcg_gen_mov_i32(ret, arg2);
        return;
    }
2100
    if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
2101
        tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
2102 2103 2104 2105 2106
        return;
    }

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

2108
    if (ofs + len < 32) {
2109 2110
        tcg_gen_andi_i32(t1, arg2, mask);
        tcg_gen_shli_i32(t1, t1, ofs);
2111 2112
    } else {
        tcg_gen_shli_i32(t1, arg2, ofs);
2113
    }
2114 2115 2116 2117
    tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
    tcg_gen_or_i32(ret, ret, t1);

    tcg_temp_free_i32(t1);
2118 2119 2120
}

static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
2121 2122
                                       TCGv_i64 arg2, unsigned int ofs,
                                       unsigned int len)
2123
{
2124 2125 2126 2127 2128 2129 2130
    uint64_t mask;
    TCGv_i64 t1;

    if (ofs == 0 && len == 64) {
        tcg_gen_mov_i64(ret, arg2);
        return;
    }
2131
    if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
2132
        tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
2133 2134
        return;
    }
2135

2136 2137
#if TCG_TARGET_REG_BITS == 32
    if (ofs >= 32) {
2138
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
2139 2140 2141 2142 2143 2144 2145
        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);
2146
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
2147 2148 2149 2150 2151 2152 2153 2154
        return;
    }
#endif

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

    if (ofs + len < 64) {
2155 2156
        tcg_gen_andi_i64(t1, arg2, mask);
        tcg_gen_shli_i64(t1, t1, ofs);
2157 2158
    } else {
        tcg_gen_shli_i64(t1, arg2, ofs);
2159
    }
2160 2161 2162 2163
    tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
    tcg_gen_or_i64(ret, ret, t1);

    tcg_temp_free_i64(t1);
2164 2165
}

R
Richard Henderson 已提交
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 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203
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)
{
    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);
    }
}

B
bellard 已提交
2204 2205 2206 2207 2208 2209 2210
/***************************************/
/* QEMU specific operations. Their type depend on the QEMU CPU
   type. */
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
#endif

P
pbrook 已提交
2211 2212 2213 2214 2215
#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
2216
#define tcg_temp_local_new() tcg_temp_local_new_i32()
P
pbrook 已提交
2217 2218 2219 2220
#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 已提交
2221
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
P
pbrook 已提交
2222 2223 2224 2225 2226
#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
2227
#define tcg_temp_local_new() tcg_temp_local_new_i64()
P
pbrook 已提交
2228 2229 2230 2231
#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 已提交
2232
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
P
pbrook 已提交
2233 2234
#endif

2235 2236 2237 2238 2239
/* 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 已提交
2240 2241
    tcg_gen_op2ii(INDEX_op_debug_insn_start, 
                  (uint32_t)(pc), (uint32_t)(pc >> 32));
2242 2243 2244 2245 2246
#else
    tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
#endif
}

B
bellard 已提交
2247 2248
static inline void tcg_gen_exit_tb(tcg_target_long val)
{
P
pbrook 已提交
2249
    tcg_gen_op1i(INDEX_op_exit_tb, val);
B
bellard 已提交
2250 2251 2252 2253
}

static inline void tcg_gen_goto_tb(int idx)
{
P
pbrook 已提交
2254
    tcg_gen_op1i(INDEX_op_goto_tb, idx);
B
bellard 已提交
2255 2256 2257
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
2258
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2259 2260
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2261
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
2262
#else
P
pbrook 已提交
2263 2264
    tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2265
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2266 2267 2268
#endif
}

P
pbrook 已提交
2269
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2270 2271
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2272
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2273
#else
P
pbrook 已提交
2274 2275 2276
    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 已提交
2277 2278 2279
#endif
}

P
pbrook 已提交
2280
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2281 2282
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2283
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2284
#else
P
pbrook 已提交
2285 2286
    tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2287
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2288 2289 2290
#endif
}

P
pbrook 已提交
2291
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2292 2293
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2294
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2295
#else
P
pbrook 已提交
2296 2297 2298
    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 已提交
2299 2300 2301
#endif
}

P
pbrook 已提交
2302
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2303 2304
{
#if TARGET_LONG_BITS == 32
2305
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
B
bellard 已提交
2306
#else
2307
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
P
pbrook 已提交
2308
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2309
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2310 2311 2312
#endif
}

P
pbrook 已提交
2313
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2314 2315
{
#if TARGET_LONG_BITS == 32
2316
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
B
bellard 已提交
2317
#else
2318
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
P
pbrook 已提交
2319 2320
                     TCGV_HIGH(addr), mem_index);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
2321 2322 2323
#endif
}

P
pbrook 已提交
2324
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2325 2326
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2327
    tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
B
bellard 已提交
2328
#else
P
pbrook 已提交
2329 2330
    tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2331 2332 2333
#endif
}

P
pbrook 已提交
2334
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2335 2336
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2337
    tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2338
#else
P
pbrook 已提交
2339 2340
    tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2341 2342 2343
#endif
}

P
pbrook 已提交
2344
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2345 2346
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2347
    tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2348
#else
P
pbrook 已提交
2349 2350
    tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2351 2352 2353
#endif
}

P
pbrook 已提交
2354
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2355 2356
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2357
    tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2358
#else
P
pbrook 已提交
2359 2360
    tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2361 2362 2363
#endif
}

P
pbrook 已提交
2364
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2365 2366
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2367 2368
    tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
                     mem_index);
B
bellard 已提交
2369
#else
P
pbrook 已提交
2370 2371
    tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2372 2373 2374
#endif
}

2375 2376
#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))
2377

B
bellard 已提交
2378 2379
#else /* TCG_TARGET_REG_BITS == 32 */

P
pbrook 已提交
2380
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2381
{
P
pbrook 已提交
2382
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
2383 2384
}

P
pbrook 已提交
2385
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2386
{
P
pbrook 已提交
2387
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2388 2389
}

P
pbrook 已提交
2390
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2391
{
P
pbrook 已提交
2392
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2393 2394
}

P
pbrook 已提交
2395
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2396
{
P
pbrook 已提交
2397
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2398 2399
}

P
pbrook 已提交
2400
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2401
{
2402 2403 2404
#if TARGET_LONG_BITS == 32
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
#else
P
pbrook 已提交
2405
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
2406
#endif
B
bellard 已提交
2407 2408
}

P
pbrook 已提交
2409
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2410
{
2411 2412 2413
#if TARGET_LONG_BITS == 32
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
#else
P
pbrook 已提交
2414
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
2415
#endif
B
bellard 已提交
2416 2417
}

P
pbrook 已提交
2418
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2419
{
P
pbrook 已提交
2420
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
B
bellard 已提交
2421 2422
}

P
pbrook 已提交
2423
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2424
{
P
pbrook 已提交
2425
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2426 2427
}

P
pbrook 已提交
2428
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2429
{
P
pbrook 已提交
2430
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2431 2432
}

P
pbrook 已提交
2433
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2434
{
P
pbrook 已提交
2435
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2436 2437
}

P
pbrook 已提交
2438
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2439
{
P
pbrook 已提交
2440
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
B
bellard 已提交
2441 2442
}

2443 2444
#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))
2445

B
bellard 已提交
2446
#endif /* TCG_TARGET_REG_BITS != 32 */
2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464

#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 已提交
2465
#define tcg_gen_neg_tl tcg_gen_neg_i64
P
pbrook 已提交
2466
#define tcg_gen_subfi_tl tcg_gen_subfi_i64
2467 2468 2469 2470 2471 2472 2473
#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 已提交
2474
#define tcg_gen_not_tl tcg_gen_not_i64
2475 2476 2477 2478 2479 2480
#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 已提交
2481
#define tcg_gen_brcond_tl tcg_gen_brcond_i64
P
pbrook 已提交
2482
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2483
#define tcg_gen_setcond_tl tcg_gen_setcond_i64
A
Aurelien Jarno 已提交
2484
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
2485 2486
#define tcg_gen_mul_tl tcg_gen_mul_i64
#define tcg_gen_muli_tl tcg_gen_muli_i64
2487 2488
#define tcg_gen_div_tl tcg_gen_div_i64
#define tcg_gen_rem_tl tcg_gen_rem_i64
A
aurel32 已提交
2489 2490
#define tcg_gen_divu_tl tcg_gen_divu_i64
#define tcg_gen_remu_tl tcg_gen_remu_i64
B
blueswir1 已提交
2491
#define tcg_gen_discard_tl tcg_gen_discard_i64
2492 2493 2494 2495 2496 2497
#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 已提交
2498 2499 2500 2501 2502 2503
#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
2504 2505 2506
#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
2507
#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2508 2509 2510 2511 2512
#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
2513 2514 2515 2516
#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
2517
#define tcg_gen_deposit_tl tcg_gen_deposit_i64
B
blueswir1 已提交
2518
#define tcg_const_tl tcg_const_i64
A
aurel32 已提交
2519
#define tcg_const_local_tl tcg_const_local_i64
R
Richard Henderson 已提交
2520
#define tcg_gen_movcond_tl tcg_gen_movcond_i64
2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537
#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 已提交
2538
#define tcg_gen_neg_tl tcg_gen_neg_i32
A
aurel32 已提交
2539
#define tcg_gen_subfi_tl tcg_gen_subfi_i32
2540 2541 2542 2543 2544 2545 2546
#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 已提交
2547
#define tcg_gen_not_tl tcg_gen_not_i32
2548 2549 2550 2551 2552 2553
#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 已提交
2554
#define tcg_gen_brcond_tl tcg_gen_brcond_i32
P
pbrook 已提交
2555
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2556
#define tcg_gen_setcond_tl tcg_gen_setcond_i32
A
Aurelien Jarno 已提交
2557
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
2558 2559
#define tcg_gen_mul_tl tcg_gen_mul_i32
#define tcg_gen_muli_tl tcg_gen_muli_i32
2560 2561
#define tcg_gen_div_tl tcg_gen_div_i32
#define tcg_gen_rem_tl tcg_gen_rem_i32
A
aurel32 已提交
2562 2563
#define tcg_gen_divu_tl tcg_gen_divu_i32
#define tcg_gen_remu_tl tcg_gen_remu_i32
B
blueswir1 已提交
2564
#define tcg_gen_discard_tl tcg_gen_discard_i32
2565 2566 2567 2568 2569 2570
#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 已提交
2571 2572 2573 2574 2575 2576
#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
2577 2578
#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2579
#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2580 2581 2582 2583 2584
#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
2585 2586 2587 2588
#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
2589
#define tcg_gen_deposit_tl tcg_gen_deposit_i32
B
blueswir1 已提交
2590
#define tcg_const_tl tcg_const_i32
A
aurel32 已提交
2591
#define tcg_const_local_tl tcg_const_local_i32
R
Richard Henderson 已提交
2592
#define tcg_gen_movcond_tl tcg_gen_movcond_i32
2593
#endif
P
pbrook 已提交
2594 2595

#if TCG_TARGET_REG_BITS == 32
2596 2597 2598 2599 2600 2601
#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 已提交
2602
#else /* TCG_TARGET_REG_BITS == 32 */
2603 2604 2605 2606 2607 2608
#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 已提交
2609
#endif /* TCG_TARGET_REG_BITS != 32 */