tcg-op.h 84.5 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 29 30 31 32
static inline void tcg_gen_op0(TCGOpcode opc)
{
    *gen_opc_ptr++ = opc;
}

33
static inline void tcg_gen_op1_i32(TCGOpcode opc, TCGv_i32 arg1)
B
bellard 已提交
34 35
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
36 37 38
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
}

39
static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
P
pbrook 已提交
40 41 42
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
B
bellard 已提交
43 44
}

45
static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg arg1)
B
bellard 已提交
46 47 48 49 50
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = arg1;
}

51
static inline void tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2)
P
pbrook 已提交
52 53 54 55 56 57
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
}

58
static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
P
pbrook 已提交
59 60 61 62 63 64
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
}

65
static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
B
bellard 已提交
66 67
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
68 69
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = arg2;
B
bellard 已提交
70 71
}

72
static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
B
bellard 已提交
73 74
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
75
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
B
bellard 已提交
76
    *gen_opparam_ptr++ = arg2;
P
pbrook 已提交
77 78
}

79
static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg arg1, TCGArg arg2)
P
pbrook 已提交
80 81 82 83 84 85
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = arg1;
    *gen_opparam_ptr++ = arg2;
}

86
static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
87 88 89 90 91 92 93 94
                                   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);
}

95
static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
96 97 98 99 100 101 102 103
                                   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);
}

104 105
static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
                                    TCGv_i32 arg2, TCGArg arg3)
P
pbrook 已提交
106 107
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
108 109 110
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = arg3;
P
pbrook 已提交
111 112
}

113 114
static inline void tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 arg1,
                                    TCGv_i64 arg2, TCGArg arg3)
P
pbrook 已提交
115 116
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
117 118
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
B
bellard 已提交
119
    *gen_opparam_ptr++ = arg3;
P
pbrook 已提交
120 121
}

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

131 132
static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
                                       TCGv_ptr base, TCGArg offset)
P
pbrook 已提交
133 134
{
    *gen_opc_ptr++ = opc;
B
blueswir1 已提交
135
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
P
pbrook 已提交
136 137 138 139
    *gen_opparam_ptr++ = GET_TCGV_PTR(base);
    *gen_opparam_ptr++ = offset;
}

140 141
static inline void tcg_gen_qemu_ldst_op_i64_i32(TCGOpcode opc, TCGv_i64 val,
                                                TCGv_i32 addr, TCGArg mem_index)
P
pbrook 已提交
142 143 144 145 146 147 148
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
    *gen_opparam_ptr++ = GET_TCGV_I32(addr);
    *gen_opparam_ptr++ = mem_index;
}

149 150
static inline void tcg_gen_qemu_ldst_op_i64_i64(TCGOpcode opc, TCGv_i64 val,
                                                TCGv_i64 addr, TCGArg mem_index)
P
pbrook 已提交
151 152 153 154 155 156 157
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(val);
    *gen_opparam_ptr++ = GET_TCGV_I64(addr);
    *gen_opparam_ptr++ = mem_index;
}

158
static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
159 160 161 162 163 164 165 166 167
                                   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);
}

168
static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
B
blueswir1 已提交
169
                                   TCGv_i64 arg3, TCGv_i64 arg4)
P
pbrook 已提交
170 171 172 173 174 175 176 177
{
    *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);
}

178
static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
179 180 181 182 183 184 185 186 187
                                    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;
}

188
static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
189
                                    TCGv_i64 arg3, TCGArg arg4)
P
pbrook 已提交
190 191
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
192 193 194 195
    *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 已提交
196 197
}

198
static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
199
                                     TCGArg arg3, TCGArg arg4)
P
pbrook 已提交
200 201
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
202 203 204
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = arg3;
B
bellard 已提交
205 206 207
    *gen_opparam_ptr++ = arg4;
}

208
static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
209
                                     TCGArg arg3, TCGArg arg4)
B
bellard 已提交
210 211
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
212 213
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
B
bellard 已提交
214 215
    *gen_opparam_ptr++ = arg3;
    *gen_opparam_ptr++ = arg4;
P
pbrook 已提交
216 217
}

218
static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
219 220 221 222 223 224 225 226 227 228
                                   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);
}

229
static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
230 231 232 233 234 235 236 237 238 239
                                   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);
}

240
static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
241
                                    TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
P
pbrook 已提交
242 243
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
244 245 246 247 248
    *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 已提交
249 250
}

251
static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
252
                                    TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
P
pbrook 已提交
253 254
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
255 256 257 258
    *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 已提交
259 260 261
    *gen_opparam_ptr++ = arg5;
}

262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
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;
}

286
static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
287 288 289 290 291 292 293 294 295 296 297 298
                                   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);
}

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

312
static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
313 314 315 316 317 318 319 320 321 322 323 324
                                    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;
}

325
static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
326 327 328 329 330 331 332 333 334 335 336 337
                                    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;
}

338 339 340
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 已提交
341 342
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
343 344 345 346 347 348 349 350
    *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;
}

351 352 353
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 已提交
354 355 356 357 358 359
{
    *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 已提交
360 361 362 363 364 365
    *gen_opparam_ptr++ = arg5;
    *gen_opparam_ptr++ = arg6;
}

static inline void gen_set_label(int n)
{
P
pbrook 已提交
366
    tcg_gen_op1i(INDEX_op_set_label, n);
B
bellard 已提交
367 368
}

B
blueswir1 已提交
369 370 371 372 373
static inline void tcg_gen_br(int label)
{
    tcg_gen_op1i(INDEX_op_br, label);
}

P
pbrook 已提交
374
static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
375
{
A
aurel32 已提交
376
    if (!TCGV_EQUAL_I32(ret, arg))
P
pbrook 已提交
377
        tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
B
bellard 已提交
378 379
}

P
pbrook 已提交
380
static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
B
bellard 已提交
381
{
P
pbrook 已提交
382
    tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
B
bellard 已提交
383 384
}

385 386 387 388 389 390 391
/* 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 已提交
392
/* helper calls */
P
pbrook 已提交
393 394 395 396
static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
                                   TCGArg ret, int nargs, TCGArg *args)
{
    TCGv_ptr fn;
397
    fn = tcg_const_ptr(func);
P
pbrook 已提交
398 399 400 401
    tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
                  nargs, args);
    tcg_temp_free_ptr(fn);
}
B
bellard 已提交
402

403 404 405 406 407
/* 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. */
408
static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
A
Aurelien Jarno 已提交
409 410 411 412
                                    TCGv_i32 a, TCGv_i32 b)
{
    TCGv_ptr fn;
    TCGArg args[2];
413
    fn = tcg_const_ptr(func);
A
Aurelien Jarno 已提交
414 415
    args[0] = GET_TCGV_I32(a);
    args[1] = GET_TCGV_I32(b);
416 417
    tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
                  GET_TCGV_I32(ret), 2, args);
A
Aurelien Jarno 已提交
418 419 420
    tcg_temp_free_ptr(fn);
}

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

B
bellard 已提交
434 435
/* 32 bit ops */

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

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

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

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

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

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

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

P
pbrook 已提交
471
static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
472
{
P
pbrook 已提交
473
    tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
B
bellard 已提交
474 475
}

P
pbrook 已提交
476
static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
477
{
P
pbrook 已提交
478
    tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
B
bellard 已提交
479 480
}

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

P
pbrook 已提交
493
static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
494
{
P
pbrook 已提交
495
    tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
B
bellard 已提交
496 497
}

P
pbrook 已提交
498
static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
A
aurel32 已提交
499
{
P
pbrook 已提交
500
    TCGv_i32 t0 = tcg_const_i32(arg1);
A
aurel32 已提交
501
    tcg_gen_sub_i32(ret, t0, arg2);
P
pbrook 已提交
502
    tcg_temp_free_i32(t0);
A
aurel32 已提交
503 504
}

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

P
pbrook 已提交
517
static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
518
{
A
aurel32 已提交
519 520 521 522 523
    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 已提交
524 525
}

526
static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
B
bellard 已提交
527
{
528 529 530 531
    TCGv_i32 t0;
    /* Some cases can be optimized here.  */
    switch (arg2) {
    case 0:
B
bellard 已提交
532
        tcg_gen_movi_i32(ret, 0);
533 534
        return;
    case 0xffffffffu:
B
bellard 已提交
535
        tcg_gen_mov_i32(ret, arg1);
536 537 538 539 540 541 542 543 544 545 546 547 548 549
        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 已提交
550
    }
551 552 553
    t0 = tcg_const_i32(arg2);
    tcg_gen_and_i32(ret, arg1, t0);
    tcg_temp_free_i32(t0);
B
bellard 已提交
554 555
}

P
pbrook 已提交
556
static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
557
{
A
aurel32 已提交
558 559 560 561 562
    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 已提交
563 564
}

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

P
pbrook 已提交
579
static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
580
{
A
aurel32 已提交
581 582 583 584 585
    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 已提交
586 587
}

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

P
pbrook 已提交
603
static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
604
{
P
pbrook 已提交
605
    tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
B
bellard 已提交
606 607
}

P
pbrook 已提交
608
static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
609
{
B
bellard 已提交
610 611 612
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
613
        TCGv_i32 t0 = tcg_const_i32(arg2);
614
        tcg_gen_shl_i32(ret, arg1, t0);
P
pbrook 已提交
615
        tcg_temp_free_i32(t0);
B
bellard 已提交
616
    }
B
bellard 已提交
617 618
}

P
pbrook 已提交
619
static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
620
{
P
pbrook 已提交
621
    tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
B
bellard 已提交
622 623
}

P
pbrook 已提交
624
static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
625
{
B
bellard 已提交
626 627 628
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
629
        TCGv_i32 t0 = tcg_const_i32(arg2);
630
        tcg_gen_shr_i32(ret, arg1, t0);
P
pbrook 已提交
631
        tcg_temp_free_i32(t0);
B
bellard 已提交
632
    }
B
bellard 已提交
633 634
}

P
pbrook 已提交
635
static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
636
{
P
pbrook 已提交
637
    tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
B
bellard 已提交
638 639
}

P
pbrook 已提交
640
static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
641
{
B
bellard 已提交
642 643 644
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
645
        TCGv_i32 t0 = tcg_const_i32(arg2);
646
        tcg_gen_sar_i32(ret, arg1, t0);
P
pbrook 已提交
647
        tcg_temp_free_i32(t0);
B
bellard 已提交
648
    }
B
bellard 已提交
649 650
}

651 652
static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
                                      TCGv_i32 arg2, int label_index)
B
bellard 已提交
653
{
654 655 656 657 658
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_br(label_index);
    } else if (cond != TCG_COND_NEVER) {
        tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
    }
B
bellard 已提交
659 660
}

661 662
static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
                                       int32_t arg2, int label_index)
P
pbrook 已提交
663
{
664 665 666 667 668 669 670
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_br(label_index);
    } else if (cond != TCG_COND_NEVER) {
        TCGv_i32 t0 = tcg_const_i32(arg2);
        tcg_gen_brcond_i32(cond, arg1, t0, label_index);
        tcg_temp_free_i32(t0);
    }
P
pbrook 已提交
671 672
}

673
static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
674 675
                                       TCGv_i32 arg1, TCGv_i32 arg2)
{
676 677 678 679 680 681 682
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_movi_i32(ret, 1);
    } else if (cond == TCG_COND_NEVER) {
        tcg_gen_movi_i32(ret, 0);
    } else {
        tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
    }
683 684
}

685 686
static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
                                        TCGv_i32 arg1, int32_t arg2)
687
{
688 689 690 691 692 693 694 695 696
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_movi_i32(ret, 1);
    } else if (cond == TCG_COND_NEVER) {
        tcg_gen_movi_i32(ret, 0);
    } else {
        TCGv_i32 t0 = tcg_const_i32(arg2);
        tcg_gen_setcond_i32(cond, ret, arg1, t0);
        tcg_temp_free_i32(t0);
    }
697 698
}

P
pbrook 已提交
699
static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
700
{
P
pbrook 已提交
701
    tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
B
bellard 已提交
702 703
}

P
pbrook 已提交
704
static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
705
{
P
pbrook 已提交
706
    TCGv_i32 t0 = tcg_const_i32(arg2);
707
    tcg_gen_mul_i32(ret, arg1, t0);
P
pbrook 已提交
708
    tcg_temp_free_i32(t0);
709 710
}

P
pbrook 已提交
711
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
712
{
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
    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 已提交
728 729 730 731
}

static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
    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 已提交
747 748 749 750
}

static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
    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 已提交
766 767 768 769
}

static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
    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 已提交
785
}
B
bellard 已提交
786 787 788

#if TCG_TARGET_REG_BITS == 32

P
pbrook 已提交
789
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
790
{
A
aurel32 已提交
791
    if (!TCGV_EQUAL_I64(ret, arg)) {
P
pbrook 已提交
792
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
793 794
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
    }
B
bellard 已提交
795 796
}

P
pbrook 已提交
797
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
798
{
P
pbrook 已提交
799
    tcg_gen_movi_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
800
    tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
B
bellard 已提交
801 802
}

P
pbrook 已提交
803 804
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
805
{
P
pbrook 已提交
806
    tcg_gen_ld8u_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_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
812
{
P
pbrook 已提交
813 814
    tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
B
bellard 已提交
815 816
}

P
pbrook 已提交
817 818
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
819
{
A
aurel32 已提交
820
    tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
821
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
822 823
}

P
pbrook 已提交
824 825
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
826
{
P
pbrook 已提交
827 828
    tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
829 830
}

P
pbrook 已提交
831 832
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
833
{
P
pbrook 已提交
834
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
835
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
836 837
}

P
pbrook 已提交
838 839
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
840
{
P
pbrook 已提交
841 842
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
843 844
}

P
pbrook 已提交
845 846
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
847 848 849 850
{
    /* since arg2 and ret have different types, they cannot be the
       same temporary */
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
851
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
P
pbrook 已提交
852
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
B
bellard 已提交
853
#else
P
pbrook 已提交
854
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
855
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
B
bellard 已提交
856 857 858
#endif
}

P
pbrook 已提交
859 860
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                   tcg_target_long offset)
B
bellard 已提交
861
{
P
pbrook 已提交
862
    tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
863 864
}

P
pbrook 已提交
865 866
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
867
{
P
pbrook 已提交
868
    tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
869 870
}

P
pbrook 已提交
871 872
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
873
{
P
pbrook 已提交
874
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
875 876
}

P
pbrook 已提交
877 878
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
879 880
{
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
881
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
P
pbrook 已提交
882
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
B
bellard 已提交
883
#else
P
pbrook 已提交
884
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
P
pbrook 已提交
885
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
B
bellard 已提交
886 887 888
#endif
}

P
pbrook 已提交
889
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
890
{
P
pbrook 已提交
891 892 893
    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));
894 895
    /* Allow the optimizer room to replace add2 with two moves.  */
    tcg_gen_op0(INDEX_op_nop);
B
bellard 已提交
896 897
}

P
pbrook 已提交
898
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
899
{
P
pbrook 已提交
900 901 902
    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));
903 904
    /* Allow the optimizer room to replace sub2 with two moves.  */
    tcg_gen_op0(INDEX_op_nop);
B
bellard 已提交
905 906
}

P
pbrook 已提交
907
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
908
{
P
pbrook 已提交
909
    tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
910
    tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
911 912
}

P
pbrook 已提交
913
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
914
{
A
aurel32 已提交
915 916
    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 已提交
917 918
}

P
pbrook 已提交
919
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
920
{
A
aurel32 已提交
921 922
    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 已提交
923 924
}

P
pbrook 已提交
925
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
926
{
P
pbrook 已提交
927
    tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
928
    tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
929 930
}

P
pbrook 已提交
931
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
932
{
A
aurel32 已提交
933 934
    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 已提交
935 936
}

P
pbrook 已提交
937
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
938
{
P
pbrook 已提交
939
    tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
940
    tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
941 942 943 944
}

/* XXX: use generic code when basic block handling is OK or CPU
   specific code (x86) */
P
pbrook 已提交
945
static inline void tcg_gen_shl_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_shl_i64, sizemask, ret, arg1, arg2);
B
bellard 已提交
954 955
}

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

P
pbrook 已提交
961
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
962
{
963 964 965 966 967 968 969
    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 已提交
970 971
}

P
pbrook 已提交
972
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
973 974 975 976
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
}

P
pbrook 已提交
977
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
978
{
979 980 981 982 983 984 985
    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 已提交
986 987
}

P
pbrook 已提交
988
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
989 990 991 992
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
}

993 994
static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
                                      TCGv_i64 arg2, int label_index)
B
bellard 已提交
995
{
996 997 998 999 1000 1001 1002
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_br(label_index);
    } else if (cond != TCG_COND_NEVER) {
        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 已提交
1003 1004
}

1005
static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1006 1007
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
1008 1009 1010 1011 1012 1013 1014 1015 1016
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_movi_i32(TCGV_LOW(ret), 1);
    } else if (cond == TCG_COND_NEVER) {
        tcg_gen_movi_i32(TCGV_LOW(ret), 0);
    } else {
        tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
                         TCGV_LOW(arg1), TCGV_HIGH(arg1),
                         TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
    }
1017 1018 1019
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1020
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1021
{
P
pbrook 已提交
1022 1023
    TCGv_i64 t0;
    TCGv_i32 t1;
B
bellard 已提交
1024

P
pbrook 已提交
1025 1026 1027 1028 1029 1030 1031
    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 已提交
1032
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
1033
    tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
1034
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
1035

B
bellard 已提交
1036
    tcg_gen_mov_i64(ret, t0);
P
pbrook 已提交
1037 1038
    tcg_temp_free_i64(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1039 1040
}

P
pbrook 已提交
1041
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1042
{
1043 1044 1045 1046 1047 1048 1049
    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 已提交
1050 1051
}

P
pbrook 已提交
1052
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1053
{
1054 1055 1056 1057 1058 1059 1060
    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 已提交
1061 1062
}

P
pbrook 已提交
1063
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1064
{
1065 1066 1067 1068 1069 1070 1071
    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 已提交
1072 1073
}

P
pbrook 已提交
1074
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1075
{
1076 1077 1078 1079 1080 1081 1082
    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 已提交
1083 1084 1085 1086
}

#else

P
pbrook 已提交
1087
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1088
{
A
aurel32 已提交
1089
    if (!TCGV_EQUAL_I64(ret, arg))
P
pbrook 已提交
1090
        tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
B
bellard 已提交
1091 1092
}

P
pbrook 已提交
1093
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
1094
{
P
pbrook 已提交
1095
    tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
B
bellard 已提交
1096 1097
}

1098
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1099
                                    tcg_target_long offset)
B
bellard 已提交
1100
{
P
pbrook 已提交
1101
    tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
B
bellard 已提交
1102 1103
}

1104
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1105
                                    tcg_target_long offset)
B
bellard 已提交
1106
{
P
pbrook 已提交
1107
    tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
B
bellard 已提交
1108 1109
}

1110
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1111
                                     tcg_target_long offset)
B
bellard 已提交
1112
{
P
pbrook 已提交
1113
    tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
B
bellard 已提交
1114 1115
}

1116
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1117
                                     tcg_target_long offset)
B
bellard 已提交
1118
{
P
pbrook 已提交
1119
    tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
B
bellard 已提交
1120 1121
}

1122
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1123
                                     tcg_target_long offset)
B
bellard 已提交
1124
{
P
pbrook 已提交
1125
    tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
B
bellard 已提交
1126 1127
}

1128
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
P
pbrook 已提交
1129
                                     tcg_target_long offset)
B
bellard 已提交
1130
{
P
pbrook 已提交
1131
    tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
B
bellard 已提交
1132 1133
}

1134
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
1135
{
P
pbrook 已提交
1136
    tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
B
bellard 已提交
1137 1138
}

1139
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
P
pbrook 已提交
1140
                                   tcg_target_long offset)
B
bellard 已提交
1141
{
P
pbrook 已提交
1142
    tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
B
bellard 已提交
1143 1144
}

1145
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
P
pbrook 已提交
1146
                                    tcg_target_long offset)
B
bellard 已提交
1147
{
P
pbrook 已提交
1148
    tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
B
bellard 已提交
1149 1150
}

1151
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
P
pbrook 已提交
1152
                                    tcg_target_long offset)
B
bellard 已提交
1153
{
P
pbrook 已提交
1154
    tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
B
bellard 已提交
1155 1156
}

1157
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
1158
{
P
pbrook 已提交
1159
    tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
B
bellard 已提交
1160 1161
}

P
pbrook 已提交
1162
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1163
{
P
pbrook 已提交
1164
    tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
B
bellard 已提交
1165 1166
}

P
pbrook 已提交
1167
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1168
{
P
pbrook 已提交
1169
    tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
B
bellard 已提交
1170 1171
}

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

1181
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
B
bellard 已提交
1182
{
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
    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);
1213
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1214
    tcg_temp_free_i64(t0);
B
bellard 已提交
1215 1216
}

P
pbrook 已提交
1217
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1218
{
A
aurel32 已提交
1219 1220 1221 1222 1223
    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 已提交
1224 1225
}

P
pbrook 已提交
1226
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1227
{
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
    /* Some cases can be optimized here.  */
    if (arg2 == -1) {
        tcg_gen_movi_i64(ret, -1);
    } else if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_or_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
    }
B
bellard 已提交
1238 1239
}

P
pbrook 已提交
1240
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1241
{
A
aurel32 已提交
1242 1243 1244 1245 1246
    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 已提交
1247 1248
}

P
pbrook 已提交
1249
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1250
{
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
    /* Some cases can be optimized here.  */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else if (arg2 == -1 && TCG_TARGET_HAS_not_i64) {
        /* Don't recurse with tcg_gen_not_i64.  */
        tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
    } else {
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_xor_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
    }
B
bellard 已提交
1262 1263
}

P
pbrook 已提交
1264
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1265
{
P
pbrook 已提交
1266
    tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
B
bellard 已提交
1267 1268
}

P
pbrook 已提交
1269
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1270
{
B
bellard 已提交
1271 1272 1273
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1274
        TCGv_i64 t0 = tcg_const_i64(arg2);
1275
        tcg_gen_shl_i64(ret, arg1, t0);
P
pbrook 已提交
1276
        tcg_temp_free_i64(t0);
B
bellard 已提交
1277
    }
B
bellard 已提交
1278 1279
}

P
pbrook 已提交
1280
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1281
{
P
pbrook 已提交
1282
    tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
B
bellard 已提交
1283 1284
}

P
pbrook 已提交
1285
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1286
{
B
bellard 已提交
1287 1288 1289
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1290
        TCGv_i64 t0 = tcg_const_i64(arg2);
1291
        tcg_gen_shr_i64(ret, arg1, t0);
P
pbrook 已提交
1292
        tcg_temp_free_i64(t0);
B
bellard 已提交
1293
    }
B
bellard 已提交
1294 1295
}

P
pbrook 已提交
1296
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1297
{
P
pbrook 已提交
1298
    tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
B
bellard 已提交
1299 1300
}

P
pbrook 已提交
1301
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1302
{
B
bellard 已提交
1303 1304 1305
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1306
        TCGv_i64 t0 = tcg_const_i64(arg2);
1307
        tcg_gen_sar_i64(ret, arg1, t0);
P
pbrook 已提交
1308
        tcg_temp_free_i64(t0);
B
bellard 已提交
1309
    }
B
bellard 已提交
1310 1311
}

1312 1313
static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
                                      TCGv_i64 arg2, int label_index)
B
bellard 已提交
1314
{
1315 1316 1317 1318 1319
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_br(label_index);
    } else if (cond != TCG_COND_NEVER) {
        tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
    }
B
bellard 已提交
1320 1321
}

1322
static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1323 1324
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
1325 1326 1327 1328 1329 1330 1331
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_movi_i64(ret, 1);
    } else if (cond == TCG_COND_NEVER) {
        tcg_gen_movi_i64(ret, 0);
    } else {
        tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
    }
1332 1333
}

P
pbrook 已提交
1334
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1335
{
P
pbrook 已提交
1336
    tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
B
bellard 已提交
1337 1338
}

A
Aurelien Jarno 已提交
1339 1340
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
    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 已提交
1356 1357 1358 1359
}

static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
    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 已提交
1375 1376 1377 1378
}

static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
    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 已提交
1394 1395 1396 1397
}

static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
    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 已提交
1413
}
1414
#endif /* TCG_TARGET_REG_BITS == 32 */
B
bellard 已提交
1415

P
pbrook 已提交
1416
static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1417 1418 1419 1420 1421
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1422
        TCGv_i64 t0 = tcg_const_i64(arg2);
1423
        tcg_gen_add_i64(ret, arg1, t0);
P
pbrook 已提交
1424
        tcg_temp_free_i64(t0);
1425 1426 1427
    }
}

P
pbrook 已提交
1428
static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
A
aurel32 已提交
1429
{
P
pbrook 已提交
1430
    TCGv_i64 t0 = tcg_const_i64(arg1);
A
aurel32 已提交
1431
    tcg_gen_sub_i64(ret, t0, arg2);
P
pbrook 已提交
1432
    tcg_temp_free_i64(t0);
A
aurel32 已提交
1433 1434
}

P
pbrook 已提交
1435
static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1436 1437 1438 1439 1440
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1441
        TCGv_i64 t0 = tcg_const_i64(arg2);
1442
        tcg_gen_sub_i64(ret, arg1, t0);
P
pbrook 已提交
1443
        tcg_temp_free_i64(t0);
1444 1445
    }
}
1446 1447
static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
                                       int64_t arg2, int label_index)
1448
{
1449 1450 1451 1452 1453 1454 1455
    if (cond == TCG_COND_ALWAYS) {
        tcg_gen_br(label_index);
    } else if (cond != TCG_COND_NEVER) {
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_brcond_i64(cond, arg1, t0, label_index);
        tcg_temp_free_i64(t0);
    }
1456 1457
}

1458 1459
static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
                                        TCGv_i64 arg1, int64_t arg2)
1460 1461 1462 1463 1464 1465
{
    TCGv_i64 t0 = tcg_const_i64(arg2);
    tcg_gen_setcond_i64(cond, ret, arg1, t0);
    tcg_temp_free_i64(t0);
}

P
pbrook 已提交
1466
static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1467
{
P
pbrook 已提交
1468
    TCGv_i64 t0 = tcg_const_i64(arg2);
1469
    tcg_gen_mul_i64(ret, arg1, t0);
P
pbrook 已提交
1470
    tcg_temp_free_i64(t0);
1471 1472
}

1473

B
bellard 已提交
1474 1475 1476
/***************************************/
/* optional operations */

P
pbrook 已提交
1477
static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1478
{
1479 1480 1481 1482 1483 1484
    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 已提交
1485 1486
}

P
pbrook 已提交
1487
static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1488
{
1489 1490 1491 1492 1493 1494
    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 已提交
1495 1496
}

P
pbrook 已提交
1497
static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1498
{
1499 1500 1501 1502 1503
    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 已提交
1504 1505
}

P
pbrook 已提交
1506
static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1507
{
1508 1509 1510 1511 1512
    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 已提交
1513 1514
}

B
bellard 已提交
1515
/* Note: we assume the two high bytes are set to zero */
P
pbrook 已提交
1516
static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1517
{
1518 1519 1520 1521
    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 已提交
1522
    
1523 1524 1525 1526 1527 1528
        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 已提交
1529 1530
}

A
aurel32 已提交
1531
static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1532
{
1533 1534 1535 1536 1537 1538
    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 已提交
1539
    
1540
        tcg_gen_shli_i32(t0, arg, 24);
B
bellard 已提交
1541
    
1542 1543 1544
        tcg_gen_andi_i32(t1, arg, 0x0000ff00);
        tcg_gen_shli_i32(t1, t1, 8);
        tcg_gen_or_i32(t0, t0, t1);
B
bellard 已提交
1545
    
1546 1547 1548
        tcg_gen_shri_i32(t1, arg, 8);
        tcg_gen_andi_i32(t1, t1, 0x0000ff00);
        tcg_gen_or_i32(t0, t0, t1);
B
bellard 已提交
1549
    
1550 1551 1552 1553 1554
        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 已提交
1555 1556 1557
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1558
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1559
{
P
pbrook 已提交
1560 1561
    tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1562 1563
}

P
pbrook 已提交
1564
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1565
{
P
pbrook 已提交
1566 1567
    tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1568 1569
}

P
pbrook 已提交
1570
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1571
{
P
pbrook 已提交
1572 1573
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1574 1575
}

P
pbrook 已提交
1576
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1577
{
P
pbrook 已提交
1578
    tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1579 1580 1581
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1582
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1583
{
P
pbrook 已提交
1584
    tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1585 1586 1587
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1588
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1589
{
P
pbrook 已提交
1590
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1591 1592 1593
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1594
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1595
{
P
pbrook 已提交
1596
    tcg_gen_mov_i32(ret, TCGV_LOW(arg));
B
bellard 已提交
1597 1598
}

P
pbrook 已提交
1599
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1600
{
P
pbrook 已提交
1601
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
1602
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1603 1604
}

P
pbrook 已提交
1605
static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1606
{
P
pbrook 已提交
1607 1608
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1609 1610
}

1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
/* 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 已提交
1625
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1626
{
P
pbrook 已提交
1627 1628 1629
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1630

A
aurel32 已提交
1631 1632
    tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
    tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
P
pbrook 已提交
1633
    tcg_gen_mov_i32(TCGV_LOW(ret), t1);
P
pbrook 已提交
1634
    tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
P
pbrook 已提交
1635 1636
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1637 1638 1639
}
#else

P
pbrook 已提交
1640
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1641
{
1642 1643 1644 1645 1646 1647
    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 已提交
1648 1649
}

P
pbrook 已提交
1650
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1651
{
1652 1653 1654 1655 1656 1657
    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 已提交
1658 1659
}

P
pbrook 已提交
1660
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1661
{
1662 1663 1664 1665 1666 1667
    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 已提交
1668 1669
}

P
pbrook 已提交
1670
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1671
{
1672 1673 1674 1675 1676
    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 已提交
1677 1678
}

P
pbrook 已提交
1679
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1680
{
1681 1682 1683 1684 1685
    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 已提交
1686 1687
}

P
pbrook 已提交
1688
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1689
{
1690 1691 1692 1693 1694
    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 已提交
1695 1696
}

B
bellard 已提交
1697
/* Note: we assume the target supports move between 32 and 64 bit
P
pbrook 已提交
1698
   registers.  This will probably break MIPS64 targets.  */
P
pbrook 已提交
1699
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1700
{
P
pbrook 已提交
1701
    tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
B
bellard 已提交
1702 1703 1704 1705
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1706
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1707
{
1708
    tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
B
bellard 已提交
1709 1710 1711 1712
}

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

1718 1719 1720
/* Note: we assume the six high bytes are set to zero */
static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
{
1721 1722 1723 1724
    if (TCG_TARGET_HAS_bswap16_i64) {
        tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
    } else {
        TCGv_i64 t0 = tcg_temp_new_i64();
1725

1726 1727 1728 1729 1730 1731
        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);
    }
1732 1733 1734 1735 1736
}

/* Note: we assume the four high bytes are set to zero */
static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
{
1737 1738 1739 1740 1741 1742
    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();
1743

1744 1745
        tcg_gen_shli_i64(t0, arg, 24);
        tcg_gen_ext32u_i64(t0, t0);
1746

1747 1748 1749
        tcg_gen_andi_i64(t1, arg, 0x0000ff00);
        tcg_gen_shli_i64(t1, t1, 8);
        tcg_gen_or_i64(t0, t0, t1);
1750

1751 1752 1753
        tcg_gen_shri_i64(t1, arg, 8);
        tcg_gen_andi_i64(t1, t1, 0x0000ff00);
        tcg_gen_or_i64(t0, t0, t1);
1754

1755 1756 1757 1758 1759
        tcg_gen_shri_i64(t1, arg, 24);
        tcg_gen_or_i64(ret, t0, t1);
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
    }
1760 1761
}

A
aurel32 已提交
1762
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1763
{
1764 1765 1766 1767 1768
    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 已提交
1769
    
1770
        tcg_gen_shli_i64(t0, arg, 56);
B
bellard 已提交
1771
    
1772 1773 1774
        tcg_gen_andi_i64(t1, arg, 0x0000ff00);
        tcg_gen_shli_i64(t1, t1, 40);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1775
    
1776 1777 1778
        tcg_gen_andi_i64(t1, arg, 0x00ff0000);
        tcg_gen_shli_i64(t1, t1, 24);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1779

1780 1781 1782
        tcg_gen_andi_i64(t1, arg, 0xff000000);
        tcg_gen_shli_i64(t1, t1, 8);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1783

1784 1785 1786
        tcg_gen_shri_i64(t1, arg, 8);
        tcg_gen_andi_i64(t1, t1, 0xff000000);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1787
    
1788 1789 1790
        tcg_gen_shri_i64(t1, arg, 24);
        tcg_gen_andi_i64(t1, t1, 0x00ff0000);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1791

1792 1793 1794
        tcg_gen_shri_i64(t1, arg, 40);
        tcg_gen_andi_i64(t1, t1, 0x0000ff00);
        tcg_gen_or_i64(t0, t0, t1);
B
bellard 已提交
1795

1796 1797 1798 1799 1800
        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 已提交
1801 1802 1803 1804
}

#endif

P
pbrook 已提交
1805
static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1806
{
1807 1808 1809 1810 1811 1812 1813
    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 已提交
1814 1815
}

P
pbrook 已提交
1816
static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1817
{
1818 1819 1820 1821 1822 1823 1824
    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 已提交
1825 1826
}

P
pbrook 已提交
1827
static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1828
{
1829 1830 1831 1832 1833
    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 已提交
1834 1835
}

P
pbrook 已提交
1836
static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1837
{
1838 1839 1840 1841 1842 1843 1844
#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
1845 1846
    tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
A
aurel32 已提交
1847
#endif
B
bellard 已提交
1848
}
1849

P
pbrook 已提交
1850
static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1851
{
P
pbrook 已提交
1852
    tcg_gen_op1_i32(INDEX_op_discard, arg);
1853 1854
}

P
pbrook 已提交
1855
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1856
{
1857
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1858
    tcg_gen_discard_i32(TCGV_LOW(arg));
1859 1860
    tcg_gen_discard_i32(TCGV_HIGH(arg));
#else
P
pbrook 已提交
1861
    tcg_gen_op1_i64(INDEX_op_discard, arg);
1862
#endif
1863
}
1864

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

P
pbrook 已提交
1877
static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1878
{
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
#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
1889 1890 1891
    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
1892 1893
}

P
pbrook 已提交
1894
static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1895
{
1896 1897 1898 1899 1900 1901
    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);
    }
1902 1903
}

P
pbrook 已提交
1904
static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1905
{
1906 1907 1908 1909 1910 1911 1912 1913
#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
1914 1915 1916
    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
1917 1918
}

P
pbrook 已提交
1919
static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1920
{
1921 1922 1923 1924 1925 1926
    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);
    }
1927 1928
}

P
pbrook 已提交
1929
static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1930
{
1931 1932 1933 1934 1935 1936 1937 1938
#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
1939 1940 1941
    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
1942 1943
}

P
pbrook 已提交
1944
static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1945
{
1946 1947 1948 1949 1950 1951
    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);
    }
1952 1953
}

P
pbrook 已提交
1954
static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1955
{
1956 1957 1958 1959 1960 1961 1962 1963
#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
1964 1965 1966
    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
1967 1968
}

P
pbrook 已提交
1969
static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1970
{
1971 1972 1973 1974 1975 1976 1977 1978
    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);
    }
1979 1980
}

P
pbrook 已提交
1981
static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1982
{
1983 1984 1985 1986 1987 1988 1989 1990 1991 1992
#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
1993 1994 1995
    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
1996 1997
}

P
pbrook 已提交
1998
static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1999
{
2000 2001 2002 2003
    if (TCG_TARGET_HAS_rot_i32) {
        tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
    } else {
        TCGv_i32 t0, t1;
2004

2005 2006 2007 2008 2009 2010 2011 2012 2013
        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);
    }
2014 2015
}

P
pbrook 已提交
2016
static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2017
{
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
    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);
    }
2031 2032
}

P
pbrook 已提交
2033
static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2034 2035 2036 2037
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
2038
    } else if (TCG_TARGET_HAS_rot_i32) {
A
aurel32 已提交
2039 2040 2041
        TCGv_i32 t0 = tcg_const_i32(arg2);
        tcg_gen_rotl_i32(ret, arg1, t0);
        tcg_temp_free_i32(t0);
2042
    } else {
P
pbrook 已提交
2043 2044 2045
        TCGv_i32 t0, t1;
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
2046 2047 2048
        tcg_gen_shli_i32(t0, arg1, arg2);
        tcg_gen_shri_i32(t1, arg1, 32 - arg2);
        tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
2049 2050
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
2051 2052 2053
    }
}

P
pbrook 已提交
2054
static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2055 2056 2057 2058
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
2059
    } else if (TCG_TARGET_HAS_rot_i64) {
A
aurel32 已提交
2060 2061 2062
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_rotl_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
2063
    } else {
P
pbrook 已提交
2064 2065 2066
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
2067 2068 2069
        tcg_gen_shli_i64(t0, arg1, arg2);
        tcg_gen_shri_i64(t1, arg1, 64 - arg2);
        tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
2070 2071
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
2072 2073 2074
    }
}

P
pbrook 已提交
2075
static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
2076
{
2077 2078 2079 2080
    if (TCG_TARGET_HAS_rot_i32) {
        tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
    } else {
        TCGv_i32 t0, t1;
2081

2082 2083 2084 2085 2086 2087 2088 2089 2090
        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);
    }
2091 2092
}

P
pbrook 已提交
2093
static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2094
{
2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
    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);
    }
2108 2109
}

P
pbrook 已提交
2110
static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2111 2112 2113 2114 2115 2116 2117 2118 2119
{
    /* 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 已提交
2120
static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2121 2122 2123
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
P
pbrook 已提交
2124
        tcg_gen_mov_i64(ret, arg1);
2125 2126 2127 2128 2129
    } else {
        tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
    }
}

2130
static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
2131 2132
                                       TCGv_i32 arg2, unsigned int ofs,
                                       unsigned int len)
2133
{
2134 2135 2136
    uint32_t mask;
    TCGv_i32 t1;

2137 2138 2139 2140
    tcg_debug_assert(ofs < 32);
    tcg_debug_assert(len <= 32);
    tcg_debug_assert(ofs + len <= 32);

2141 2142 2143 2144
    if (ofs == 0 && len == 32) {
        tcg_gen_mov_i32(ret, arg2);
        return;
    }
2145
    if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
2146
        tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
2147 2148 2149 2150 2151
        return;
    }

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

2153
    if (ofs + len < 32) {
2154 2155
        tcg_gen_andi_i32(t1, arg2, mask);
        tcg_gen_shli_i32(t1, t1, ofs);
2156 2157
    } else {
        tcg_gen_shli_i32(t1, arg2, ofs);
2158
    }
2159 2160 2161 2162
    tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
    tcg_gen_or_i32(ret, ret, t1);

    tcg_temp_free_i32(t1);
2163 2164 2165
}

static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
2166 2167
                                       TCGv_i64 arg2, unsigned int ofs,
                                       unsigned int len)
2168
{
2169 2170 2171
    uint64_t mask;
    TCGv_i64 t1;

2172 2173 2174 2175
    tcg_debug_assert(ofs < 64);
    tcg_debug_assert(len <= 64);
    tcg_debug_assert(ofs + len <= 64);

2176 2177 2178 2179
    if (ofs == 0 && len == 64) {
        tcg_gen_mov_i64(ret, arg2);
        return;
    }
2180
    if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
2181
        tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
2182 2183
        return;
    }
2184

2185 2186
#if TCG_TARGET_REG_BITS == 32
    if (ofs >= 32) {
2187
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
2188 2189 2190 2191 2192 2193 2194
        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);
2195
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
2196 2197 2198 2199 2200 2201 2202 2203
        return;
    }
#endif

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

    if (ofs + len < 64) {
2204 2205
        tcg_gen_andi_i64(t1, arg2, mask);
        tcg_gen_shli_i64(t1, t1, ofs);
2206 2207
    } else {
        tcg_gen_shli_i64(t1, arg2, ofs);
2208
    }
2209 2210 2211 2212
    tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
    tcg_gen_or_i64(ret, ret, t1);

    tcg_temp_free_i64(t1);
2213 2214
}

2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244
static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
                                          TCGv_i32 high)
{
#if TCG_TARGET_REG_BITS == 32
    tcg_gen_mov_i32(TCGV_LOW(dest), low);
    tcg_gen_mov_i32(TCGV_HIGH(dest), high);
#else
    TCGv_i64 tmp = tcg_temp_new_i64();
    /* These extensions are only needed for type correctness.
       We may be able to do better given target specific information.  */
    tcg_gen_extu_i32_i64(tmp, high);
    tcg_gen_extu_i32_i64(dest, low);
    /* If deposit is available, use it.  Otherwise use the extra
       knowledge that we have of the zero-extensions above.  */
    if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(32, 32)) {
        tcg_gen_deposit_i64(dest, dest, tmp, 32, 32);
    } else {
        tcg_gen_shli_i64(tmp, tmp, 32);
        tcg_gen_or_i64(dest, dest, tmp);
    }
    tcg_temp_free_i64(tmp);
#endif
}

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

R
Richard Henderson 已提交
2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267
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)
{
2268 2269 2270 2271 2272 2273 2274
#if TCG_TARGET_REG_BITS == 32
    TCGv_i32 t0 = tcg_temp_new_i32();
    TCGv_i32 t1 = tcg_temp_new_i32();
    tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
                     TCGV_LOW(c1), TCGV_HIGH(c1),
                     TCGV_LOW(c2), TCGV_HIGH(c2), cond);

2275 2276 2277 2278 2279 2280 2281 2282
    if (TCG_TARGET_HAS_movcond_i32) {
        tcg_gen_movi_i32(t1, 0);
        tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
                            TCGV_LOW(v1), TCGV_LOW(v2));
        tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
                            TCGV_HIGH(v1), TCGV_HIGH(v2));
    } else {
        tcg_gen_neg_i32(t0, t0);
2283

2284 2285 2286
        tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
        tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
        tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
2287

2288 2289 2290 2291
        tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
        tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
        tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
    }
2292 2293 2294
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
#else
R
Richard Henderson 已提交
2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307
    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);
    }
2308
#endif
R
Richard Henderson 已提交
2309 2310
}

B
bellard 已提交
2311 2312 2313 2314 2315 2316 2317
/***************************************/
/* QEMU specific operations. Their type depend on the QEMU CPU
   type. */
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
#endif

P
pbrook 已提交
2318 2319 2320 2321 2322
#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
2323
#define tcg_temp_local_new() tcg_temp_local_new_i32()
P
pbrook 已提交
2324 2325 2326 2327
#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 已提交
2328
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
P
pbrook 已提交
2329 2330 2331 2332 2333
#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
2334
#define tcg_temp_local_new() tcg_temp_local_new_i64()
P
pbrook 已提交
2335 2336 2337 2338
#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 已提交
2339
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
P
pbrook 已提交
2340 2341
#endif

2342 2343 2344 2345 2346
/* 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 已提交
2347 2348
    tcg_gen_op2ii(INDEX_op_debug_insn_start, 
                  (uint32_t)(pc), (uint32_t)(pc >> 32));
2349 2350 2351 2352 2353
#else
    tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
#endif
}

B
bellard 已提交
2354 2355
static inline void tcg_gen_exit_tb(tcg_target_long val)
{
P
pbrook 已提交
2356
    tcg_gen_op1i(INDEX_op_exit_tb, val);
B
bellard 已提交
2357 2358
}

2359 2360 2361 2362 2363 2364 2365 2366 2367
static inline void tcg_gen_goto_tb(unsigned idx)
{
    /* We only support two chained exits.  */
    tcg_debug_assert(idx <= 1);
#ifdef CONFIG_DEBUG_TCG
    /* Verify that we havn't seen this numbered exit before.  */
    tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
    tcg_ctx.goto_tb_issue_mask |= 1 << idx;
#endif
P
pbrook 已提交
2368
    tcg_gen_op1i(INDEX_op_goto_tb, idx);
B
bellard 已提交
2369 2370 2371
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
2372
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2373 2374
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2375
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
2376
#else
P
pbrook 已提交
2377 2378
    tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2379
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2380 2381 2382
#endif
}

P
pbrook 已提交
2383
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2384 2385
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2386
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2387
#else
P
pbrook 已提交
2388 2389 2390
    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 已提交
2391 2392 2393
#endif
}

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

P
pbrook 已提交
2405
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2406 2407
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2408
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2409
#else
P
pbrook 已提交
2410 2411 2412
    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 已提交
2413 2414 2415
#endif
}

P
pbrook 已提交
2416
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2417 2418
{
#if TARGET_LONG_BITS == 32
2419
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
B
bellard 已提交
2420
#else
2421
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
P
pbrook 已提交
2422
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2423
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2424 2425 2426
#endif
}

P
pbrook 已提交
2427
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2428 2429
{
#if TARGET_LONG_BITS == 32
2430
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
B
bellard 已提交
2431
#else
2432
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
P
pbrook 已提交
2433 2434
                     TCGV_HIGH(addr), mem_index);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
2435 2436 2437
#endif
}

P
pbrook 已提交
2438
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2439 2440
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2441
    tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
B
bellard 已提交
2442
#else
P
pbrook 已提交
2443 2444
    tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2445 2446 2447
#endif
}

P
pbrook 已提交
2448
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2449 2450
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2451
    tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2452
#else
P
pbrook 已提交
2453 2454
    tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2455 2456 2457
#endif
}

P
pbrook 已提交
2458
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2459 2460
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2461
    tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2462
#else
P
pbrook 已提交
2463 2464
    tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2465 2466 2467
#endif
}

P
pbrook 已提交
2468
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2469 2470
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2471
    tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2472
#else
P
pbrook 已提交
2473 2474
    tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2475 2476 2477
#endif
}

P
pbrook 已提交
2478
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2479 2480
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2481 2482
    tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
                     mem_index);
B
bellard 已提交
2483
#else
P
pbrook 已提交
2484 2485
    tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2486 2487 2488
#endif
}

2489 2490
#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))
2491

B
bellard 已提交
2492 2493
#else /* TCG_TARGET_REG_BITS == 32 */

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

P
pbrook 已提交
2499
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2500
{
P
pbrook 已提交
2501
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2502 2503
}

P
pbrook 已提交
2504
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2505
{
P
pbrook 已提交
2506
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2507 2508
}

P
pbrook 已提交
2509
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2510
{
P
pbrook 已提交
2511
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2512 2513
}

P
pbrook 已提交
2514
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2515
{
2516 2517 2518
#if TARGET_LONG_BITS == 32
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
#else
P
pbrook 已提交
2519
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
2520
#endif
B
bellard 已提交
2521 2522
}

P
pbrook 已提交
2523
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2524
{
2525 2526 2527
#if TARGET_LONG_BITS == 32
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
#else
P
pbrook 已提交
2528
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
2529
#endif
B
bellard 已提交
2530 2531
}

P
pbrook 已提交
2532
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2533
{
P
pbrook 已提交
2534
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
B
bellard 已提交
2535 2536
}

P
pbrook 已提交
2537
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2538
{
P
pbrook 已提交
2539
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2540 2541
}

P
pbrook 已提交
2542
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2543
{
P
pbrook 已提交
2544
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2545 2546
}

P
pbrook 已提交
2547
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2548
{
P
pbrook 已提交
2549
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2550 2551
}

P
pbrook 已提交
2552
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2553
{
P
pbrook 已提交
2554
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
B
bellard 已提交
2555 2556
}

2557 2558
#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))
2559

B
bellard 已提交
2560
#endif /* TCG_TARGET_REG_BITS != 32 */
2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578

#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 已提交
2579
#define tcg_gen_neg_tl tcg_gen_neg_i64
P
pbrook 已提交
2580
#define tcg_gen_subfi_tl tcg_gen_subfi_i64
2581 2582 2583 2584 2585 2586 2587
#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 已提交
2588
#define tcg_gen_not_tl tcg_gen_not_i64
2589 2590 2591 2592 2593 2594
#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 已提交
2595
#define tcg_gen_brcond_tl tcg_gen_brcond_i64
P
pbrook 已提交
2596
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2597
#define tcg_gen_setcond_tl tcg_gen_setcond_i64
A
Aurelien Jarno 已提交
2598
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
2599 2600
#define tcg_gen_mul_tl tcg_gen_mul_i64
#define tcg_gen_muli_tl tcg_gen_muli_i64
2601 2602
#define tcg_gen_div_tl tcg_gen_div_i64
#define tcg_gen_rem_tl tcg_gen_rem_i64
A
aurel32 已提交
2603 2604
#define tcg_gen_divu_tl tcg_gen_divu_i64
#define tcg_gen_remu_tl tcg_gen_remu_i64
B
blueswir1 已提交
2605
#define tcg_gen_discard_tl tcg_gen_discard_i64
2606 2607 2608 2609 2610 2611
#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 已提交
2612 2613 2614 2615 2616 2617
#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
2618 2619 2620
#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
2621
#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2622 2623 2624 2625 2626
#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
2627 2628 2629 2630
#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
2631
#define tcg_gen_deposit_tl tcg_gen_deposit_i64
B
blueswir1 已提交
2632
#define tcg_const_tl tcg_const_i64
A
aurel32 已提交
2633
#define tcg_const_local_tl tcg_const_local_i64
R
Richard Henderson 已提交
2634
#define tcg_gen_movcond_tl tcg_gen_movcond_i64
2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651
#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 已提交
2652
#define tcg_gen_neg_tl tcg_gen_neg_i32
A
aurel32 已提交
2653
#define tcg_gen_subfi_tl tcg_gen_subfi_i32
2654 2655 2656 2657 2658 2659 2660
#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 已提交
2661
#define tcg_gen_not_tl tcg_gen_not_i32
2662 2663 2664 2665 2666 2667
#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 已提交
2668
#define tcg_gen_brcond_tl tcg_gen_brcond_i32
P
pbrook 已提交
2669
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2670
#define tcg_gen_setcond_tl tcg_gen_setcond_i32
A
Aurelien Jarno 已提交
2671
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
2672 2673
#define tcg_gen_mul_tl tcg_gen_mul_i32
#define tcg_gen_muli_tl tcg_gen_muli_i32
2674 2675
#define tcg_gen_div_tl tcg_gen_div_i32
#define tcg_gen_rem_tl tcg_gen_rem_i32
A
aurel32 已提交
2676 2677
#define tcg_gen_divu_tl tcg_gen_divu_i32
#define tcg_gen_remu_tl tcg_gen_remu_i32
B
blueswir1 已提交
2678
#define tcg_gen_discard_tl tcg_gen_discard_i32
2679 2680 2681 2682 2683 2684
#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 已提交
2685 2686 2687 2688 2689 2690
#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
2691 2692
#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2693
#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2694 2695 2696 2697 2698
#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
2699 2700 2701 2702
#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
2703
#define tcg_gen_deposit_tl tcg_gen_deposit_i32
B
blueswir1 已提交
2704
#define tcg_const_tl tcg_const_i32
A
aurel32 已提交
2705
#define tcg_const_local_tl tcg_const_local_i32
R
Richard Henderson 已提交
2706
#define tcg_gen_movcond_tl tcg_gen_movcond_i32
2707
#endif
P
pbrook 已提交
2708 2709

#if TCG_TARGET_REG_BITS == 32
2710 2711 2712 2713 2714 2715
#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 已提交
2716
#else /* TCG_TARGET_REG_BITS == 32 */
2717 2718 2719 2720 2721 2722
#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 已提交
2723
#endif /* TCG_TARGET_REG_BITS != 32 */