tcg-op.h 68.9 KB
Newer Older
B
bellard 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Tiny Code Generator for QEMU
 *
 * Copyright (c) 2008 Fabrice Bellard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include "tcg.h"

int gen_new_label(void);

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

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

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

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

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

60
static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
B
bellard 已提交
61 62
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
63 64
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = arg2;
B
bellard 已提交
65 66
}

67
static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
B
bellard 已提交
68 69
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
70
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
B
bellard 已提交
71
    *gen_opparam_ptr++ = arg2;
P
pbrook 已提交
72 73
}

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

81
static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
82 83 84 85 86 87 88 89
                                   TCGv_i32 arg3)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
}

90
static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
91 92 93 94 95 96 97 98
                                   TCGv_i64 arg3)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
}

99 100
static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
                                    TCGv_i32 arg2, TCGArg arg3)
P
pbrook 已提交
101 102
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
103 104 105
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = arg3;
P
pbrook 已提交
106 107
}

108 109
static inline void tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 arg1,
                                    TCGv_i64 arg2, TCGArg arg3)
P
pbrook 已提交
110 111
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
112 113
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
B
bellard 已提交
114
    *gen_opparam_ptr++ = arg3;
P
pbrook 已提交
115 116
}

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

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

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

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

153
static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
154 155 156 157 158 159 160 161 162
                                   TCGv_i32 arg3, TCGv_i32 arg4)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
}

163
static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
B
blueswir1 已提交
164
                                   TCGv_i64 arg3, TCGv_i64 arg4)
P
pbrook 已提交
165 166 167 168 169 170 171 172
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
}

173
static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
174 175 176 177 178 179 180 181 182
                                    TCGv_i32 arg3, TCGArg arg4)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = arg4;
}

183
static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
184
                                    TCGv_i64 arg3, TCGArg arg4)
P
pbrook 已提交
185 186
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
187 188 189 190
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = arg4;
P
pbrook 已提交
191 192
}

193
static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
194
                                     TCGArg arg3, TCGArg arg4)
P
pbrook 已提交
195 196
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
197 198 199
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = arg3;
B
bellard 已提交
200 201 202
    *gen_opparam_ptr++ = arg4;
}

203
static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
204
                                     TCGArg arg3, TCGArg arg4)
B
bellard 已提交
205 206
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
207 208
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
B
bellard 已提交
209 210
    *gen_opparam_ptr++ = arg3;
    *gen_opparam_ptr++ = arg4;
P
pbrook 已提交
211 212
}

213
static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
214 215 216 217 218 219 220 221 222 223
                                   TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
}

224
static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
225 226 227 228 229 230 231 232 233 234
                                   TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
}

235
static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
236
                                    TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
P
pbrook 已提交
237 238
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
239 240 241 242 243
    *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
    *gen_opparam_ptr++ = arg5;
P
pbrook 已提交
244 245
}

246
static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
247
                                    TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
P
pbrook 已提交
248 249
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
250 251 252 253
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
B
bellard 已提交
254 255 256
    *gen_opparam_ptr++ = arg5;
}

257
static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
P
pbrook 已提交
258 259 260 261 262 263 264 265 266 267 268 269
                                   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);
}

270
static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
271 272
                                   TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
                                   TCGv_i64 arg6)
B
bellard 已提交
273 274
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
275 276 277 278 279 280
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg6);
P
pbrook 已提交
281 282
}

283
static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
284 285 286 287 288 289 290 291 292 293 294 295
                                    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;
}

296
static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
297 298 299 300 301 302 303 304 305 306 307 308
                                    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;
}

309 310 311
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 已提交
312 313
{
    *gen_opc_ptr++ = opc;
P
pbrook 已提交
314 315 316 317 318 319 320 321
    *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;
}

322 323 324
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 已提交
325 326 327 328 329 330
{
    *gen_opc_ptr++ = opc;
    *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
    *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
B
bellard 已提交
331 332 333 334 335 336
    *gen_opparam_ptr++ = arg5;
    *gen_opparam_ptr++ = arg6;
}

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

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

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

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

/* helper calls */
P
pbrook 已提交
357 358 359 360 361 362 363 364 365
static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
                                   TCGArg ret, int nargs, TCGArg *args)
{
    TCGv_ptr fn;
    fn = tcg_const_ptr((tcg_target_long)func);
    tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
                  nargs, args);
    tcg_temp_free_ptr(fn);
}
B
bellard 已提交
366

367 368 369 370 371
/* 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. */
A
Aurelien Jarno 已提交
372 373 374 375 376 377 378 379
static inline void tcg_gen_helper32(void *func, TCGv_i32 ret,
                                    TCGv_i32 a, TCGv_i32 b)
{
    TCGv_ptr fn;
    TCGArg args[2];
    fn = tcg_const_ptr((tcg_target_long)func);
    args[0] = GET_TCGV_I32(a);
    args[1] = GET_TCGV_I32(b);
380 381
    tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE,
                  0, GET_TCGV_I32(ret), 2, args);
A
Aurelien Jarno 已提交
382 383 384
    tcg_temp_free_ptr(fn);
}

P
pbrook 已提交
385 386
static inline void tcg_gen_helper64(void *func, TCGv_i64 ret,
                                    TCGv_i64 a, TCGv_i64 b)
B
bellard 已提交
387
{
P
pbrook 已提交
388 389 390 391 392
    TCGv_ptr fn;
    TCGArg args[2];
    fn = tcg_const_ptr((tcg_target_long)func);
    args[0] = GET_TCGV_I64(a);
    args[1] = GET_TCGV_I64(b);
393 394
    tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE,
                  7, GET_TCGV_I64(ret), 2, args);
P
pbrook 已提交
395
    tcg_temp_free_ptr(fn);
396 397
}

B
bellard 已提交
398 399
/* 32 bit ops */

P
pbrook 已提交
400
static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
401
{
P
pbrook 已提交
402
    tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
B
bellard 已提交
403 404
}

P
pbrook 已提交
405
static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
406
{
P
pbrook 已提交
407
    tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
B
bellard 已提交
408 409
}

P
pbrook 已提交
410
static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
411
{
P
pbrook 已提交
412
    tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
B
bellard 已提交
413 414
}

P
pbrook 已提交
415
static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
416
{
P
pbrook 已提交
417
    tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
B
bellard 已提交
418 419
}

P
pbrook 已提交
420
static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
421
{
P
pbrook 已提交
422
    tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
B
bellard 已提交
423 424
}

P
pbrook 已提交
425
static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
426
{
P
pbrook 已提交
427
    tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
B
bellard 已提交
428 429
}

P
pbrook 已提交
430
static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
431
{
P
pbrook 已提交
432
    tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
B
bellard 已提交
433 434
}

P
pbrook 已提交
435
static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
B
bellard 已提交
436
{
P
pbrook 已提交
437
    tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
B
bellard 已提交
438 439
}

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

P
pbrook 已提交
445
static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
446
{
447 448 449 450
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
451
        TCGv_i32 t0 = tcg_const_i32(arg2);
452
        tcg_gen_add_i32(ret, arg1, t0);
P
pbrook 已提交
453
        tcg_temp_free_i32(t0);
454
    }
B
bellard 已提交
455 456
}

P
pbrook 已提交
457
static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
458
{
P
pbrook 已提交
459
    tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
B
bellard 已提交
460 461
}

P
pbrook 已提交
462
static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
A
aurel32 已提交
463
{
P
pbrook 已提交
464
    TCGv_i32 t0 = tcg_const_i32(arg1);
A
aurel32 已提交
465
    tcg_gen_sub_i32(ret, t0, arg2);
P
pbrook 已提交
466
    tcg_temp_free_i32(t0);
A
aurel32 已提交
467 468
}

P
pbrook 已提交
469
static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
470
{
471 472 473 474
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
475
        TCGv_i32 t0 = tcg_const_i32(arg2);
476
        tcg_gen_sub_i32(ret, arg1, t0);
P
pbrook 已提交
477
        tcg_temp_free_i32(t0);
478
    }
B
bellard 已提交
479 480
}

P
pbrook 已提交
481
static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
482
{
A
aurel32 已提交
483 484 485 486 487
    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 已提交
488 489
}

P
pbrook 已提交
490
static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
491 492 493 494 495 496 497
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_movi_i32(ret, 0);
    } else if (arg2 == 0xffffffff) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
498
        TCGv_i32 t0 = tcg_const_i32(arg2);
499
        tcg_gen_and_i32(ret, arg1, t0);
P
pbrook 已提交
500
        tcg_temp_free_i32(t0);
B
bellard 已提交
501 502 503
    }
}

P
pbrook 已提交
504
static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
505
{
A
aurel32 已提交
506 507 508 509 510
    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 已提交
511 512
}

P
pbrook 已提交
513
static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
514 515 516
{
    /* some cases can be optimized here */
    if (arg2 == 0xffffffff) {
517
        tcg_gen_movi_i32(ret, 0xffffffff);
B
bellard 已提交
518 519 520
    } else if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
521
        TCGv_i32 t0 = tcg_const_i32(arg2);
522
        tcg_gen_or_i32(ret, arg1, t0);
P
pbrook 已提交
523
        tcg_temp_free_i32(t0);
B
bellard 已提交
524 525 526
    }
}

P
pbrook 已提交
527
static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
528
{
A
aurel32 已提交
529 530 531 532 533
    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 已提交
534 535
}

P
pbrook 已提交
536
static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
537 538 539 540 541
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
542
        TCGv_i32 t0 = tcg_const_i32(arg2);
543
        tcg_gen_xor_i32(ret, arg1, t0);
P
pbrook 已提交
544
        tcg_temp_free_i32(t0);
B
bellard 已提交
545 546 547
    }
}

P
pbrook 已提交
548
static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
549
{
P
pbrook 已提交
550
    tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
B
bellard 已提交
551 552
}

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

P
pbrook 已提交
564
static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
565
{
P
pbrook 已提交
566
    tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
B
bellard 已提交
567 568
}

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

P
pbrook 已提交
580
static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
581
{
P
pbrook 已提交
582
    tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
B
bellard 已提交
583 584
}

P
pbrook 已提交
585
static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
B
bellard 已提交
586
{
B
bellard 已提交
587 588 589
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
P
pbrook 已提交
590
        TCGv_i32 t0 = tcg_const_i32(arg2);
591
        tcg_gen_sar_i32(ret, arg1, t0);
P
pbrook 已提交
592
        tcg_temp_free_i32(t0);
B
bellard 已提交
593
    }
B
bellard 已提交
594 595
}

P
pbrook 已提交
596
static inline void tcg_gen_brcond_i32(int cond, TCGv_i32 arg1, TCGv_i32 arg2,
B
bellard 已提交
597 598
                                      int label_index)
{
P
pbrook 已提交
599
    tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
B
bellard 已提交
600 601
}

P
pbrook 已提交
602
static inline void tcg_gen_brcondi_i32(int cond, TCGv_i32 arg1, int32_t arg2,
P
pbrook 已提交
603 604
                                       int label_index)
{
P
pbrook 已提交
605
    TCGv_i32 t0 = tcg_const_i32(arg2);
P
pbrook 已提交
606
    tcg_gen_brcond_i32(cond, arg1, t0, label_index);
P
pbrook 已提交
607
    tcg_temp_free_i32(t0);
P
pbrook 已提交
608 609
}

610 611 612 613 614 615 616 617 618 619 620 621 622 623
static inline void tcg_gen_setcond_i32(int cond, TCGv_i32 ret,
                                       TCGv_i32 arg1, TCGv_i32 arg2)
{
    tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
}

static inline void tcg_gen_setcondi_i32(int cond, TCGv_i32 ret, TCGv_i32 arg1,
                                        int32_t arg2)
{
    TCGv_i32 t0 = tcg_const_i32(arg2);
    tcg_gen_setcond_i32(cond, ret, arg1, t0);
    tcg_temp_free_i32(t0);
}

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

P
pbrook 已提交
629
static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
630
{
P
pbrook 已提交
631
    TCGv_i32 t0 = tcg_const_i32(arg2);
632
    tcg_gen_mul_i32(ret, arg1, t0);
P
pbrook 已提交
633
    tcg_temp_free_i32(t0);
634 635
}

B
bellard 已提交
636
#ifdef TCG_TARGET_HAS_div_i32
P
pbrook 已提交
637
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
638
{
P
pbrook 已提交
639
    tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
B
bellard 已提交
640 641
}

P
pbrook 已提交
642
static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
643
{
P
pbrook 已提交
644
    tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
B
bellard 已提交
645 646
}

P
pbrook 已提交
647
static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
648
{
P
pbrook 已提交
649
    tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
B
bellard 已提交
650 651
}

P
pbrook 已提交
652
static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
653
{
P
pbrook 已提交
654
    tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
B
bellard 已提交
655
}
A
Aurelien Jarno 已提交
656
#elif defined(TCG_TARGET_HAS_div2_i32)
P
pbrook 已提交
657
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
658
{
P
pbrook 已提交
659 660
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
661
    tcg_gen_sari_i32(t0, arg1, 31);
P
pbrook 已提交
662 663
    tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
664 665
}

P
pbrook 已提交
666
static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
667
{
P
pbrook 已提交
668 669
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
670
    tcg_gen_sari_i32(t0, arg1, 31);
P
pbrook 已提交
671 672
    tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
673 674
}

P
pbrook 已提交
675
static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
676
{
P
pbrook 已提交
677 678
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
679
    tcg_gen_movi_i32(t0, 0);
P
pbrook 已提交
680 681
    tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
682 683
}

P
pbrook 已提交
684
static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
B
bellard 已提交
685
{
P
pbrook 已提交
686 687
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
B
bellard 已提交
688
    tcg_gen_movi_i32(t0, 0);
P
pbrook 已提交
689 690
    tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i32(t0);
B
bellard 已提交
691
}
A
Aurelien Jarno 已提交
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
#else
static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
    tcg_gen_helper32(tcg_helper_div_i32, ret, arg1, arg2);
}

static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
    tcg_gen_helper32(tcg_helper_rem_i32, ret, arg1, arg2);
}

static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
    tcg_gen_helper32(tcg_helper_divu_i32, ret, arg1, arg2);
}

static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
    tcg_gen_helper32(tcg_helper_remu_i32, ret, arg1, arg2);
}
B
bellard 已提交
712 713 714 715
#endif

#if TCG_TARGET_REG_BITS == 32

P
pbrook 已提交
716
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
717
{
A
aurel32 已提交
718
    if (!TCGV_EQUAL_I64(ret, arg)) {
P
pbrook 已提交
719
        tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
720 721
        tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
    }
B
bellard 已提交
722 723
}

P
pbrook 已提交
724
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
725
{
P
pbrook 已提交
726
    tcg_gen_movi_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
727
    tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
B
bellard 已提交
728 729
}

P
pbrook 已提交
730 731
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
732
{
P
pbrook 已提交
733
    tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
734
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
735 736
}

P
pbrook 已提交
737 738
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
739
{
P
pbrook 已提交
740 741
    tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
B
bellard 已提交
742 743
}

P
pbrook 已提交
744 745
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
746
{
A
aurel32 已提交
747
    tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
748
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
749 750
}

P
pbrook 已提交
751 752
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
753
{
P
pbrook 已提交
754 755
    tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
756 757
}

P
pbrook 已提交
758 759
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
760
{
P
pbrook 已提交
761
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
762
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
763 764
}

P
pbrook 已提交
765 766
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                     tcg_target_long offset)
B
bellard 已提交
767
{
P
pbrook 已提交
768 769
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
770 771
}

P
pbrook 已提交
772 773
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
774 775 776 777
{
    /* since arg2 and ret have different types, they cannot be the
       same temporary */
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
778
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
P
pbrook 已提交
779
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
B
bellard 已提交
780
#else
P
pbrook 已提交
781
    tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
P
pbrook 已提交
782
    tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
B
bellard 已提交
783 784 785
#endif
}

P
pbrook 已提交
786 787
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                   tcg_target_long offset)
B
bellard 已提交
788
{
P
pbrook 已提交
789
    tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
790 791
}

P
pbrook 已提交
792 793
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
794
{
P
pbrook 已提交
795
    tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
796 797
}

P
pbrook 已提交
798 799
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                    tcg_target_long offset)
B
bellard 已提交
800
{
P
pbrook 已提交
801
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
B
bellard 已提交
802 803
}

P
pbrook 已提交
804 805
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
                                  tcg_target_long offset)
B
bellard 已提交
806 807
{
#ifdef TCG_TARGET_WORDS_BIGENDIAN
P
pbrook 已提交
808
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
P
pbrook 已提交
809
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
B
bellard 已提交
810
#else
P
pbrook 已提交
811
    tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
P
pbrook 已提交
812
    tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
B
bellard 已提交
813 814 815
#endif
}

P
pbrook 已提交
816
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
817
{
P
pbrook 已提交
818 819 820
    tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
                    TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
                    TCGV_HIGH(arg2));
B
bellard 已提交
821 822
}

P
pbrook 已提交
823
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
824
{
P
pbrook 已提交
825 826 827
    tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
                    TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
                    TCGV_HIGH(arg2));
B
bellard 已提交
828 829
}

P
pbrook 已提交
830
static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
831
{
P
pbrook 已提交
832
    tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
833
    tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
B
bellard 已提交
834 835
}

P
pbrook 已提交
836
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
837
{
A
aurel32 已提交
838 839
    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 已提交
840 841
}

P
pbrook 已提交
842
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
843
{
A
aurel32 已提交
844 845
    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 已提交
846 847
}

P
pbrook 已提交
848
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
849
{
P
pbrook 已提交
850
    tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
851
    tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
852 853
}

P
pbrook 已提交
854
static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
855
{
A
aurel32 已提交
856 857
    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 已提交
858 859
}

P
pbrook 已提交
860
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
861
{
P
pbrook 已提交
862
    tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
P
pbrook 已提交
863
    tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
B
bellard 已提交
864 865 866 867
}

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

P
pbrook 已提交
873
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
874 875 876 877
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
}

P
pbrook 已提交
878
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
879
{
P
pbrook 已提交
880
    tcg_gen_helper64(tcg_helper_shr_i64, ret, arg1, arg2);
B
bellard 已提交
881 882
}

P
pbrook 已提交
883
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
884 885 886 887
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
}

P
pbrook 已提交
888
static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
889
{
P
pbrook 已提交
890
    tcg_gen_helper64(tcg_helper_sar_i64, ret, arg1, arg2);
B
bellard 已提交
891 892
}

P
pbrook 已提交
893
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
894 895 896 897
{
    tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
}

P
pbrook 已提交
898
static inline void tcg_gen_brcond_i64(int cond, TCGv_i64 arg1, TCGv_i64 arg2,
B
bellard 已提交
899 900
                                      int label_index)
{
P
pbrook 已提交
901 902 903
    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 已提交
904 905
}

906 907 908 909 910 911 912 913 914
static inline void tcg_gen_setcond_i64(int cond, TCGv_i64 ret,
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
                     TCGV_LOW(arg1), TCGV_HIGH(arg1),
                     TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
915
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
916
{
P
pbrook 已提交
917 918
    TCGv_i64 t0;
    TCGv_i32 t1;
B
bellard 已提交
919

P
pbrook 已提交
920 921 922 923 924 925 926
    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 已提交
927
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
928
    tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
P
pbrook 已提交
929
    tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
P
pbrook 已提交
930

B
bellard 已提交
931
    tcg_gen_mov_i64(ret, t0);
P
pbrook 已提交
932 933
    tcg_temp_free_i64(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
934 935
}

P
pbrook 已提交
936
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
937
{
P
pbrook 已提交
938
    tcg_gen_helper64(tcg_helper_div_i64, ret, arg1, arg2);
B
bellard 已提交
939 940
}

P
pbrook 已提交
941
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
942
{
P
pbrook 已提交
943
    tcg_gen_helper64(tcg_helper_rem_i64, ret, arg1, arg2);
B
bellard 已提交
944 945
}

P
pbrook 已提交
946
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
947
{
P
pbrook 已提交
948
    tcg_gen_helper64(tcg_helper_divu_i64, ret, arg1, arg2);
B
bellard 已提交
949 950
}

P
pbrook 已提交
951
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
952
{
P
pbrook 已提交
953
    tcg_gen_helper64(tcg_helper_remu_i64, ret, arg1, arg2);
B
bellard 已提交
954 955 956 957
}

#else

P
pbrook 已提交
958
static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
959
{
A
aurel32 已提交
960
    if (!TCGV_EQUAL_I64(ret, arg))
P
pbrook 已提交
961
        tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
B
bellard 已提交
962 963
}

P
pbrook 已提交
964
static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
B
bellard 已提交
965
{
P
pbrook 已提交
966
    tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
B
bellard 已提交
967 968
}

P
pbrook 已提交
969
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
970
                                    tcg_target_long offset)
B
bellard 已提交
971
{
P
pbrook 已提交
972
    tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
B
bellard 已提交
973 974
}

P
pbrook 已提交
975
static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
976
                                    tcg_target_long offset)
B
bellard 已提交
977
{
P
pbrook 已提交
978
    tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
B
bellard 已提交
979 980
}

P
pbrook 已提交
981
static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
982
                                     tcg_target_long offset)
B
bellard 已提交
983
{
P
pbrook 已提交
984
    tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
B
bellard 已提交
985 986
}

P
pbrook 已提交
987
static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
988
                                     tcg_target_long offset)
B
bellard 已提交
989
{
P
pbrook 已提交
990
    tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
B
bellard 已提交
991 992
}

P
pbrook 已提交
993
static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
994
                                     tcg_target_long offset)
B
bellard 已提交
995
{
P
pbrook 已提交
996
    tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
B
bellard 已提交
997 998
}

P
pbrook 已提交
999
static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_i64 arg2,
P
pbrook 已提交
1000
                                     tcg_target_long offset)
B
bellard 已提交
1001
{
P
pbrook 已提交
1002
    tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
B
bellard 已提交
1003 1004
}

P
pbrook 已提交
1005
static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_i64 arg2, tcg_target_long offset)
B
bellard 已提交
1006
{
P
pbrook 已提交
1007
    tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
B
bellard 已提交
1008 1009
}

P
pbrook 已提交
1010
static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
1011
                                   tcg_target_long offset)
B
bellard 已提交
1012
{
P
pbrook 已提交
1013
    tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
B
bellard 已提交
1014 1015
}

P
pbrook 已提交
1016
static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
1017
                                    tcg_target_long offset)
B
bellard 已提交
1018
{
P
pbrook 已提交
1019
    tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
B
bellard 已提交
1020 1021
}

P
pbrook 已提交
1022
static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_i64 arg2,
P
pbrook 已提交
1023
                                    tcg_target_long offset)
B
bellard 已提交
1024
{
P
pbrook 已提交
1025
    tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
B
bellard 已提交
1026 1027
}

P
pbrook 已提交
1028
static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_i64 arg2, tcg_target_long offset)
B
bellard 已提交
1029
{
P
pbrook 已提交
1030
    tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
B
bellard 已提交
1031 1032
}

P
pbrook 已提交
1033
static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1034
{
P
pbrook 已提交
1035
    tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
B
bellard 已提交
1036 1037
}

P
pbrook 已提交
1038
static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1039
{
P
pbrook 已提交
1040
    tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
B
bellard 已提交
1041 1042
}

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

P
pbrook 已提交
1052
static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1053
{
P
pbrook 已提交
1054
    TCGv_i64 t0 = tcg_const_i64(arg2);
1055
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1056
    tcg_temp_free_i64(t0);
B
bellard 已提交
1057 1058
}

P
pbrook 已提交
1059
static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1060
{
A
aurel32 已提交
1061 1062 1063 1064 1065
    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 已提交
1066 1067
}

P
pbrook 已提交
1068
static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1069
{
P
pbrook 已提交
1070
    TCGv_i64 t0 = tcg_const_i64(arg2);
1071
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
1072
    tcg_temp_free_i64(t0);
B
bellard 已提交
1073 1074
}

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

P
pbrook 已提交
1084
static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1085
{
P
pbrook 已提交
1086
    TCGv_i64 t0 = tcg_const_i64(arg2);
1087
    tcg_gen_xor_i64(ret, arg1, t0);
P
pbrook 已提交
1088
    tcg_temp_free_i64(t0);
B
bellard 已提交
1089 1090
}

P
pbrook 已提交
1091
static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1092
{
P
pbrook 已提交
1093
    tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
B
bellard 已提交
1094 1095
}

P
pbrook 已提交
1096
static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1097
{
B
bellard 已提交
1098 1099 1100
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1101
        TCGv_i64 t0 = tcg_const_i64(arg2);
1102
        tcg_gen_shl_i64(ret, arg1, t0);
P
pbrook 已提交
1103
        tcg_temp_free_i64(t0);
B
bellard 已提交
1104
    }
B
bellard 已提交
1105 1106
}

P
pbrook 已提交
1107
static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1108
{
P
pbrook 已提交
1109
    tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
B
bellard 已提交
1110 1111
}

P
pbrook 已提交
1112
static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1113
{
B
bellard 已提交
1114 1115 1116
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1117
        TCGv_i64 t0 = tcg_const_i64(arg2);
1118
        tcg_gen_shr_i64(ret, arg1, t0);
P
pbrook 已提交
1119
        tcg_temp_free_i64(t0);
B
bellard 已提交
1120
    }
B
bellard 已提交
1121 1122
}

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

P
pbrook 已提交
1128
static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
B
bellard 已提交
1129
{
B
bellard 已提交
1130 1131 1132
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1133
        TCGv_i64 t0 = tcg_const_i64(arg2);
1134
        tcg_gen_sar_i64(ret, arg1, t0);
P
pbrook 已提交
1135
        tcg_temp_free_i64(t0);
B
bellard 已提交
1136
    }
B
bellard 已提交
1137 1138
}

P
pbrook 已提交
1139
static inline void tcg_gen_brcond_i64(int cond, TCGv_i64 arg1, TCGv_i64 arg2,
B
bellard 已提交
1140 1141
                                      int label_index)
{
P
pbrook 已提交
1142
    tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
B
bellard 已提交
1143 1144
}

1145 1146 1147 1148 1149 1150
static inline void tcg_gen_setcond_i64(int cond, TCGv_i64 ret,
                                       TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
}

P
pbrook 已提交
1151
static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1152
{
P
pbrook 已提交
1153
    tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
B
bellard 已提交
1154 1155 1156
}

#ifdef TCG_TARGET_HAS_div_i64
P
pbrook 已提交
1157
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1158
{
P
pbrook 已提交
1159
    tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
B
bellard 已提交
1160 1161
}

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

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

P
pbrook 已提交
1172
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1173
{
P
pbrook 已提交
1174
    tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
B
bellard 已提交
1175
}
A
Aurelien Jarno 已提交
1176
#elif defined(TCG_TARGET_HAS_div2_i64)
P
pbrook 已提交
1177
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1178
{
P
pbrook 已提交
1179 1180
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1181
    tcg_gen_sari_i64(t0, arg1, 63);
P
pbrook 已提交
1182 1183
    tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1184 1185
}

P
pbrook 已提交
1186
static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1187
{
P
pbrook 已提交
1188 1189
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1190
    tcg_gen_sari_i64(t0, arg1, 63);
P
pbrook 已提交
1191 1192
    tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1193 1194
}

P
pbrook 已提交
1195
static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1196
{
P
pbrook 已提交
1197 1198
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1199
    tcg_gen_movi_i64(t0, 0);
P
pbrook 已提交
1200 1201
    tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1202 1203
}

P
pbrook 已提交
1204
static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
B
bellard 已提交
1205
{
P
pbrook 已提交
1206 1207
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
B
bellard 已提交
1208
    tcg_gen_movi_i64(t0, 0);
P
pbrook 已提交
1209 1210
    tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
    tcg_temp_free_i64(t0);
B
bellard 已提交
1211
}
A
Aurelien Jarno 已提交
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
#else
static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_helper64(tcg_helper_div_i64, ret, arg1, arg2);
}

static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_helper64(tcg_helper_rem_i64, ret, arg1, arg2);
}

static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_helper64(tcg_helper_divu_i64, ret, arg1, arg2);
}

static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
    tcg_gen_helper64(tcg_helper_remu_i64, ret, arg1, arg2);
}
B
bellard 已提交
1232 1233 1234 1235
#endif

#endif

P
pbrook 已提交
1236
static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1237 1238 1239 1240 1241
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1242
        TCGv_i64 t0 = tcg_const_i64(arg2);
1243
        tcg_gen_add_i64(ret, arg1, t0);
P
pbrook 已提交
1244
        tcg_temp_free_i64(t0);
1245 1246 1247
    }
}

P
pbrook 已提交
1248
static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
A
aurel32 已提交
1249
{
P
pbrook 已提交
1250
    TCGv_i64 t0 = tcg_const_i64(arg1);
A
aurel32 已提交
1251
    tcg_gen_sub_i64(ret, t0, arg2);
P
pbrook 已提交
1252
    tcg_temp_free_i64(t0);
A
aurel32 已提交
1253 1254
}

P
pbrook 已提交
1255
static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1256 1257 1258 1259 1260
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
P
pbrook 已提交
1261
        TCGv_i64 t0 = tcg_const_i64(arg2);
1262
        tcg_gen_sub_i64(ret, arg1, t0);
P
pbrook 已提交
1263
        tcg_temp_free_i64(t0);
1264 1265
    }
}
P
pbrook 已提交
1266
static inline void tcg_gen_brcondi_i64(int cond, TCGv_i64 arg1, int64_t arg2,
1267 1268
                                       int label_index)
{
P
pbrook 已提交
1269
    TCGv_i64 t0 = tcg_const_i64(arg2);
1270
    tcg_gen_brcond_i64(cond, arg1, t0, label_index);
P
pbrook 已提交
1271
    tcg_temp_free_i64(t0);
1272 1273
}

1274 1275 1276 1277 1278 1279 1280 1281
static inline void tcg_gen_setcondi_i64(int cond, TCGv_i64 ret, TCGv_i64 arg1,
                                        int64_t arg2)
{
    TCGv_i64 t0 = tcg_const_i64(arg2);
    tcg_gen_setcond_i64(cond, ret, arg1, t0);
    tcg_temp_free_i64(t0);
}

P
pbrook 已提交
1282
static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1283
{
P
pbrook 已提交
1284
    TCGv_i64 t0 = tcg_const_i64(arg2);
1285
    tcg_gen_mul_i64(ret, arg1, t0);
P
pbrook 已提交
1286
    tcg_temp_free_i64(t0);
1287 1288
}

1289

B
bellard 已提交
1290 1291 1292
/***************************************/
/* optional operations */

P
pbrook 已提交
1293
static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1294 1295
{
#ifdef TCG_TARGET_HAS_ext8s_i32
P
pbrook 已提交
1296
    tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
B
bellard 已提交
1297 1298
#else
    tcg_gen_shli_i32(ret, arg, 24);
1299
    tcg_gen_sari_i32(ret, ret, 24);
B
bellard 已提交
1300 1301 1302
#endif
}

P
pbrook 已提交
1303
static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1304 1305
{
#ifdef TCG_TARGET_HAS_ext16s_i32
P
pbrook 已提交
1306
    tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
B
bellard 已提交
1307 1308
#else
    tcg_gen_shli_i32(ret, arg, 16);
1309
    tcg_gen_sari_i32(ret, ret, 16);
B
bellard 已提交
1310 1311 1312
#endif
}

P
pbrook 已提交
1313
static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1314
{
1315 1316 1317
#ifdef TCG_TARGET_HAS_ext8u_i32
    tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
#else
P
pbrook 已提交
1318
    tcg_gen_andi_i32(ret, arg, 0xffu);
1319
#endif
P
pbrook 已提交
1320 1321
}

P
pbrook 已提交
1322
static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1323
{
1324 1325 1326
#ifdef TCG_TARGET_HAS_ext16u_i32
    tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
#else
P
pbrook 已提交
1327
    tcg_gen_andi_i32(ret, arg, 0xffffu);
1328
#endif
P
pbrook 已提交
1329 1330
}

B
bellard 已提交
1331
/* Note: we assume the two high bytes are set to zero */
P
pbrook 已提交
1332
static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1333 1334
{
#ifdef TCG_TARGET_HAS_bswap16_i32
P
pbrook 已提交
1335
    tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
B
bellard 已提交
1336
#else
A
aurel32 已提交
1337
    TCGv_i32 t0 = tcg_temp_new_i32();
B
bellard 已提交
1338
    
A
aurel32 已提交
1339 1340 1341 1342
    tcg_gen_ext8u_i32(t0, arg);
    tcg_gen_shli_i32(t0, t0, 8);
    tcg_gen_shri_i32(ret, arg, 8);
    tcg_gen_or_i32(ret, ret, t0);
P
pbrook 已提交
1343
    tcg_temp_free_i32(t0);
B
bellard 已提交
1344 1345 1346
#endif
}

A
aurel32 已提交
1347
static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1348
{
A
aurel32 已提交
1349 1350
#ifdef TCG_TARGET_HAS_bswap32_i32
    tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
B
bellard 已提交
1351
#else
P
pbrook 已提交
1352 1353 1354
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
    
    tcg_gen_shli_i32(t0, arg, 24);
    
    tcg_gen_andi_i32(t1, arg, 0x0000ff00);
    tcg_gen_shli_i32(t1, t1, 8);
    tcg_gen_or_i32(t0, t0, t1);
    
    tcg_gen_shri_i32(t1, arg, 8);
    tcg_gen_andi_i32(t1, t1, 0x0000ff00);
    tcg_gen_or_i32(t0, t0, t1);
    
    tcg_gen_shri_i32(t1, arg, 24);
    tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1368 1369
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1370 1371 1372 1373
#endif
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1374
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1375
{
P
pbrook 已提交
1376 1377
    tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1378 1379
}

P
pbrook 已提交
1380
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1381
{
P
pbrook 已提交
1382 1383
    tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1384 1385
}

P
pbrook 已提交
1386
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1387
{
P
pbrook 已提交
1388 1389
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1390 1391
}

P
pbrook 已提交
1392
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1393
{
P
pbrook 已提交
1394
    tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1395 1396 1397
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1398
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1399
{
P
pbrook 已提交
1400
    tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1401 1402 1403
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1404
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1405
{
P
pbrook 已提交
1406
    tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
P
pbrook 已提交
1407 1408 1409
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
}

P
pbrook 已提交
1410
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1411
{
P
pbrook 已提交
1412
    tcg_gen_mov_i32(ret, TCGV_LOW(arg));
B
bellard 已提交
1413 1414
}

P
pbrook 已提交
1415
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1416
{
P
pbrook 已提交
1417
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
P
pbrook 已提交
1418
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
1419 1420
}

P
pbrook 已提交
1421
static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1422
{
P
pbrook 已提交
1423 1424
    tcg_gen_mov_i32(TCGV_LOW(ret), arg);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
1425 1426
}

1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
/* 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 已提交
1441
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1442
{
P
pbrook 已提交
1443 1444 1445
    TCGv_i32 t0, t1;
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
B
bellard 已提交
1446

A
aurel32 已提交
1447 1448
    tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
    tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
P
pbrook 已提交
1449
    tcg_gen_mov_i32(TCGV_LOW(ret), t1);
P
pbrook 已提交
1450
    tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
P
pbrook 已提交
1451 1452
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
B
bellard 已提交
1453 1454 1455
}
#else

P
pbrook 已提交
1456
static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1457 1458
{
#ifdef TCG_TARGET_HAS_ext8s_i64
P
pbrook 已提交
1459
    tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
B
bellard 已提交
1460 1461
#else
    tcg_gen_shli_i64(ret, arg, 56);
1462
    tcg_gen_sari_i64(ret, ret, 56);
B
bellard 已提交
1463 1464 1465
#endif
}

P
pbrook 已提交
1466
static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1467 1468
{
#ifdef TCG_TARGET_HAS_ext16s_i64
P
pbrook 已提交
1469
    tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
B
bellard 已提交
1470 1471
#else
    tcg_gen_shli_i64(ret, arg, 48);
1472
    tcg_gen_sari_i64(ret, ret, 48);
B
bellard 已提交
1473 1474 1475
#endif
}

P
pbrook 已提交
1476
static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1477 1478
{
#ifdef TCG_TARGET_HAS_ext32s_i64
P
pbrook 已提交
1479
    tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
B
bellard 已提交
1480 1481
#else
    tcg_gen_shli_i64(ret, arg, 32);
1482
    tcg_gen_sari_i64(ret, ret, 32);
B
bellard 已提交
1483 1484 1485
#endif
}

P
pbrook 已提交
1486
static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1487
{
1488 1489 1490
#ifdef TCG_TARGET_HAS_ext8u_i64
    tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
#else
P
pbrook 已提交
1491
    tcg_gen_andi_i64(ret, arg, 0xffu);
1492
#endif
P
pbrook 已提交
1493 1494
}

P
pbrook 已提交
1495
static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1496
{
1497 1498 1499
#ifdef TCG_TARGET_HAS_ext16u_i64
    tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
#else
P
pbrook 已提交
1500
    tcg_gen_andi_i64(ret, arg, 0xffffu);
1501
#endif
P
pbrook 已提交
1502 1503
}

P
pbrook 已提交
1504
static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1505
{
1506 1507 1508
#ifdef TCG_TARGET_HAS_ext32u_i64
    tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
#else
P
pbrook 已提交
1509
    tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1510
#endif
P
pbrook 已提交
1511 1512
}

B
bellard 已提交
1513
/* Note: we assume the target supports move between 32 and 64 bit
P
pbrook 已提交
1514
   registers.  This will probably break MIPS64 targets.  */
P
pbrook 已提交
1515
static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
B
bellard 已提交
1516
{
P
pbrook 已提交
1517
    tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
B
bellard 已提交
1518 1519 1520 1521
}

/* Note: we assume the target supports move between 32 and 64 bit
   registers */
P
pbrook 已提交
1522
static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
B
bellard 已提交
1523
{
1524
    tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
B
bellard 已提交
1525 1526 1527 1528
}

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

1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
/* Note: we assume the six high bytes are set to zero */
static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
{
#ifdef TCG_TARGET_HAS_bswap16_i64
    tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
#else
    TCGv_i64 t0 = tcg_temp_new_i64();

    tcg_gen_ext8u_i64(t0, arg);
    tcg_gen_shli_i64(t0, t0, 8);
    tcg_gen_shri_i64(ret, arg, 8);
    tcg_gen_or_i64(ret, ret, t0);
    tcg_temp_free_i64(t0);
#endif
}

/* Note: we assume the four high bytes are set to zero */
static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
{
#ifdef TCG_TARGET_HAS_bswap32_i64
    tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
#else
    TCGv_i64 t0, t1;
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();

    tcg_gen_shli_i64(t0, arg, 24);
    tcg_gen_ext32u_i64(t0, t0);

    tcg_gen_andi_i64(t1, arg, 0x0000ff00);
    tcg_gen_shli_i64(t1, t1, 8);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_shri_i64(t1, arg, 8);
    tcg_gen_andi_i64(t1, t1, 0x0000ff00);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_shri_i64(t1, arg, 24);
    tcg_gen_or_i64(ret, t0, t1);
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
#endif
}

A
aurel32 已提交
1578
static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1579
{
A
aurel32 已提交
1580 1581
#ifdef TCG_TARGET_HAS_bswap64_i64
    tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
B
bellard 已提交
1582
#else
1583 1584
    TCGv_i64 t0 = tcg_temp_new_i64();
    TCGv_i64 t1 = tcg_temp_new_i64();
B
bellard 已提交
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613
    
    tcg_gen_shli_i64(t0, arg, 56);
    
    tcg_gen_andi_i64(t1, arg, 0x0000ff00);
    tcg_gen_shli_i64(t1, t1, 40);
    tcg_gen_or_i64(t0, t0, t1);
    
    tcg_gen_andi_i64(t1, arg, 0x00ff0000);
    tcg_gen_shli_i64(t1, t1, 24);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_andi_i64(t1, arg, 0xff000000);
    tcg_gen_shli_i64(t1, t1, 8);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_shri_i64(t1, arg, 8);
    tcg_gen_andi_i64(t1, t1, 0xff000000);
    tcg_gen_or_i64(t0, t0, t1);
    
    tcg_gen_shri_i64(t1, arg, 24);
    tcg_gen_andi_i64(t1, t1, 0x00ff0000);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_shri_i64(t1, arg, 40);
    tcg_gen_andi_i64(t1, t1, 0x0000ff00);
    tcg_gen_or_i64(t0, t0, t1);

    tcg_gen_shri_i64(t1, arg, 56);
    tcg_gen_or_i64(ret, t0, t1);
1614 1615
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
B
bellard 已提交
1616 1617 1618 1619 1620
#endif
}

#endif

P
pbrook 已提交
1621
static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
P
pbrook 已提交
1622 1623
{
#ifdef TCG_TARGET_HAS_neg_i32
P
pbrook 已提交
1624
    tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
P
pbrook 已提交
1625
#else
P
pbrook 已提交
1626
    TCGv_i32 t0 = tcg_const_i32(0);
1627
    tcg_gen_sub_i32(ret, t0, arg);
P
pbrook 已提交
1628
    tcg_temp_free_i32(t0);
P
pbrook 已提交
1629 1630 1631
#endif
}

P
pbrook 已提交
1632
static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
P
pbrook 已提交
1633 1634
{
#ifdef TCG_TARGET_HAS_neg_i64
P
pbrook 已提交
1635
    tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
P
pbrook 已提交
1636
#else
P
pbrook 已提交
1637
    TCGv_i64 t0 = tcg_const_i64(0);
1638
    tcg_gen_sub_i64(ret, t0, arg);
P
pbrook 已提交
1639
    tcg_temp_free_i64(t0);
P
pbrook 已提交
1640 1641 1642
#endif
}

P
pbrook 已提交
1643
static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
B
bellard 已提交
1644
{
A
aurel32 已提交
1645 1646 1647
#ifdef TCG_TARGET_HAS_not_i32
    tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
#else
1648
    tcg_gen_xori_i32(ret, arg, -1);
A
aurel32 已提交
1649
#endif
B
bellard 已提交
1650 1651
}

P
pbrook 已提交
1652
static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
B
bellard 已提交
1653
{
A
aurel32 已提交
1654
#ifdef TCG_TARGET_HAS_not_i64
A
aurel32 已提交
1655
    tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
A
aurel32 已提交
1656
#else
1657
    tcg_gen_xori_i64(ret, arg, -1);
A
aurel32 已提交
1658
#endif
B
bellard 已提交
1659
}
1660

P
pbrook 已提交
1661
static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1662
{
P
pbrook 已提交
1663
    tcg_gen_op1_i32(INDEX_op_discard, arg);
1664 1665 1666
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1667
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1668
{
P
pbrook 已提交
1669
    tcg_gen_discard_i32(TCGV_LOW(arg));
1670 1671 1672
    tcg_gen_discard_i32(TCGV_HIGH(arg));
}
#else
P
pbrook 已提交
1673
static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1674
{
P
pbrook 已提交
1675
    tcg_gen_op1_i64(INDEX_op_discard, arg);
1676 1677 1678
}
#endif

P
pbrook 已提交
1679
static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
P
pbrook 已提交
1680 1681
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1682
    tcg_gen_mov_i32(TCGV_LOW(dest), low);
P
pbrook 已提交
1683 1684
    tcg_gen_mov_i32(TCGV_HIGH(dest), high);
#else
P
pbrook 已提交
1685
    TCGv_i64 tmp = tcg_temp_new_i64();
P
pbrook 已提交
1686 1687 1688 1689 1690 1691
    /* This extension is only needed for type correctness.
       We may be able to do better given target specific information.  */
    tcg_gen_extu_i32_i64(tmp, high);
    tcg_gen_shli_i64(tmp, tmp, 32);
    tcg_gen_extu_i32_i64(dest, low);
    tcg_gen_or_i64(dest, dest, tmp);
P
pbrook 已提交
1692
    tcg_temp_free_i64(tmp);
P
pbrook 已提交
1693 1694 1695
#endif
}

P
pbrook 已提交
1696
static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low, TCGv_i64 high)
1697 1698
{
#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1699
    tcg_gen_concat_i32_i64(dest, TCGV_LOW(low), TCGV_LOW(high));
1700
#else
P
pbrook 已提交
1701
    TCGv_i64 tmp = tcg_temp_new_i64();
1702
    tcg_gen_ext32u_i64(dest, low);
1703
    tcg_gen_shli_i64(tmp, high, 32);
1704
    tcg_gen_or_i64(dest, dest, tmp);
P
pbrook 已提交
1705
    tcg_temp_free_i64(tmp);
1706 1707 1708
#endif
}

P
pbrook 已提交
1709
static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1710
{
1711 1712 1713
#ifdef TCG_TARGET_HAS_andc_i32
    tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1714 1715
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
1716 1717
    tcg_gen_not_i32(t0, arg2);
    tcg_gen_and_i32(ret, arg1, t0);
P
pbrook 已提交
1718
    tcg_temp_free_i32(t0);
1719
#endif
1720 1721
}

P
pbrook 已提交
1722
static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1723
{
1724 1725 1726 1727 1728 1729
#ifdef TCG_TARGET_HAS_andc_i64
    tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
#elif defined(TCG_TARGET_HAS_andc_i32) && TCG_TARGET_REG_BITS == 32
    tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
    tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
#else
P
pbrook 已提交
1730 1731
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
1732 1733
    tcg_gen_not_i64(t0, arg2);
    tcg_gen_and_i64(ret, arg1, t0);
P
pbrook 已提交
1734
    tcg_temp_free_i64(t0);
1735
#endif
1736 1737
}

P
pbrook 已提交
1738
static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1739
{
A
aurel32 已提交
1740 1741
    tcg_gen_xor_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1742 1743
}

P
pbrook 已提交
1744
static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1745
{
A
aurel32 已提交
1746 1747
    tcg_gen_xor_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1748 1749
}

P
pbrook 已提交
1750
static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1751
{
A
aurel32 已提交
1752 1753
    tcg_gen_and_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1754 1755
}

P
pbrook 已提交
1756
static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1757
{
A
aurel32 已提交
1758 1759
    tcg_gen_and_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1760 1761
}

P
pbrook 已提交
1762
static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1763
{
A
aurel32 已提交
1764 1765
    tcg_gen_or_i32(ret, arg1, arg2);
    tcg_gen_not_i32(ret, ret);
1766 1767
}

P
pbrook 已提交
1768
static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1769
{
A
aurel32 已提交
1770 1771
    tcg_gen_or_i64(ret, arg1, arg2);
    tcg_gen_not_i64(ret, ret);
1772 1773
}

P
pbrook 已提交
1774
static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1775
{
1776 1777 1778
#ifdef TCG_TARGET_HAS_orc_i32
    tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1779 1780
    TCGv_i32 t0;
    t0 = tcg_temp_new_i32();
1781 1782
    tcg_gen_not_i32(t0, arg2);
    tcg_gen_or_i32(ret, arg1, t0);
P
pbrook 已提交
1783
    tcg_temp_free_i32(t0);
1784
#endif
1785 1786
}

P
pbrook 已提交
1787
static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1788
{
1789 1790 1791 1792 1793 1794
#ifdef TCG_TARGET_HAS_orc_i64
    tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
#elif defined(TCG_TARGET_HAS_orc_i32) && TCG_TARGET_REG_BITS == 32
    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));
#else
P
pbrook 已提交
1795 1796
    TCGv_i64 t0;
    t0 = tcg_temp_new_i64();
1797 1798
    tcg_gen_not_i64(t0, arg2);
    tcg_gen_or_i64(ret, arg1, t0);
P
pbrook 已提交
1799
    tcg_temp_free_i64(t0);
1800
#endif
1801 1802
}

P
pbrook 已提交
1803
static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1804
{
A
aurel32 已提交
1805 1806 1807
#ifdef TCG_TARGET_HAS_rot_i32
    tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1808
    TCGv_i32 t0, t1;
1809

P
pbrook 已提交
1810 1811
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
1812 1813 1814 1815
    tcg_gen_shl_i32(t0, arg1, arg2);
    tcg_gen_subfi_i32(t1, 32, arg2);
    tcg_gen_shr_i32(t1, arg1, t1);
    tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1816 1817
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
A
aurel32 已提交
1818
#endif
1819 1820
}

P
pbrook 已提交
1821
static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1822
{
A
aurel32 已提交
1823 1824 1825
#ifdef TCG_TARGET_HAS_rot_i64
    tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
#else
P
pbrook 已提交
1826
    TCGv_i64 t0, t1;
1827

P
pbrook 已提交
1828 1829
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();
1830 1831 1832 1833
    tcg_gen_shl_i64(t0, arg1, arg2);
    tcg_gen_subfi_i64(t1, 64, arg2);
    tcg_gen_shr_i64(t1, arg1, t1);
    tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1834 1835
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
A
aurel32 已提交
1836
#endif
1837 1838
}

P
pbrook 已提交
1839
static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1840 1841 1842 1843 1844
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i32(ret, arg1);
    } else {
A
aurel32 已提交
1845 1846 1847 1848 1849
#ifdef TCG_TARGET_HAS_rot_i32
        TCGv_i32 t0 = tcg_const_i32(arg2);
        tcg_gen_rotl_i32(ret, arg1, t0);
        tcg_temp_free_i32(t0);
#else
P
pbrook 已提交
1850 1851 1852
        TCGv_i32 t0, t1;
        t0 = tcg_temp_new_i32();
        t1 = tcg_temp_new_i32();
1853 1854 1855
        tcg_gen_shli_i32(t0, arg1, arg2);
        tcg_gen_shri_i32(t1, arg1, 32 - arg2);
        tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1856 1857
        tcg_temp_free_i32(t0);
        tcg_temp_free_i32(t1);
A
aurel32 已提交
1858
#endif
1859 1860 1861
    }
}

P
pbrook 已提交
1862
static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1863 1864 1865 1866 1867
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
        tcg_gen_mov_i64(ret, arg1);
    } else {
A
aurel32 已提交
1868 1869 1870 1871 1872
#ifdef TCG_TARGET_HAS_rot_i64
        TCGv_i64 t0 = tcg_const_i64(arg2);
        tcg_gen_rotl_i64(ret, arg1, t0);
        tcg_temp_free_i64(t0);
#else
P
pbrook 已提交
1873 1874 1875
        TCGv_i64 t0, t1;
        t0 = tcg_temp_new_i64();
        t1 = tcg_temp_new_i64();
1876 1877 1878
        tcg_gen_shli_i64(t0, arg1, arg2);
        tcg_gen_shri_i64(t1, arg1, 64 - arg2);
        tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1879 1880
        tcg_temp_free_i64(t0);
        tcg_temp_free_i64(t1);
A
aurel32 已提交
1881
#endif
1882 1883 1884
    }
}

P
pbrook 已提交
1885
static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1886
{
A
aurel32 已提交
1887 1888 1889
#ifdef TCG_TARGET_HAS_rot_i32
    tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
#else
P
pbrook 已提交
1890
    TCGv_i32 t0, t1;
1891

P
pbrook 已提交
1892 1893
    t0 = tcg_temp_new_i32();
    t1 = tcg_temp_new_i32();
1894 1895 1896 1897
    tcg_gen_shr_i32(t0, arg1, arg2);
    tcg_gen_subfi_i32(t1, 32, arg2);
    tcg_gen_shl_i32(t1, arg1, t1);
    tcg_gen_or_i32(ret, t0, t1);
P
pbrook 已提交
1898 1899
    tcg_temp_free_i32(t0);
    tcg_temp_free_i32(t1);
A
aurel32 已提交
1900
#endif
1901 1902
}

P
pbrook 已提交
1903
static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1904
{
A
aurel32 已提交
1905 1906 1907
#ifdef TCG_TARGET_HAS_rot_i64
    tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
#else
P
pbrook 已提交
1908
    TCGv_i64 t0, t1;
1909

P
pbrook 已提交
1910 1911
    t0 = tcg_temp_new_i64();
    t1 = tcg_temp_new_i64();
A
Aurelien Jarno 已提交
1912
    tcg_gen_shr_i64(t0, arg1, arg2);
1913 1914 1915
    tcg_gen_subfi_i64(t1, 64, arg2);
    tcg_gen_shl_i64(t1, arg1, t1);
    tcg_gen_or_i64(ret, t0, t1);
P
pbrook 已提交
1916 1917
    tcg_temp_free_i64(t0);
    tcg_temp_free_i64(t1);
A
aurel32 已提交
1918
#endif
1919 1920
}

P
pbrook 已提交
1921
static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1922 1923 1924 1925 1926 1927 1928 1929 1930
{
    /* 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 已提交
1931
static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1932 1933 1934
{
    /* some cases can be optimized here */
    if (arg2 == 0) {
P
pbrook 已提交
1935
        tcg_gen_mov_i64(ret, arg1);
1936 1937 1938 1939 1940
    } else {
        tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
    }
}

B
bellard 已提交
1941 1942 1943 1944 1945 1946 1947
/***************************************/
/* QEMU specific operations. Their type depend on the QEMU CPU
   type. */
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
#endif

P
pbrook 已提交
1948 1949 1950 1951 1952
#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
1953
#define tcg_temp_local_new() tcg_temp_local_new_i32()
P
pbrook 已提交
1954 1955 1956 1957
#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 已提交
1958
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
P
pbrook 已提交
1959 1960 1961 1962 1963
#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
1964
#define tcg_temp_local_new() tcg_temp_local_new_i64()
P
pbrook 已提交
1965 1966 1967 1968
#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 已提交
1969
#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
P
pbrook 已提交
1970 1971
#endif

1972 1973 1974 1975 1976
/* 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 已提交
1977 1978
    tcg_gen_op2ii(INDEX_op_debug_insn_start, 
                  (uint32_t)(pc), (uint32_t)(pc >> 32));
1979 1980 1981 1982 1983
#else
    tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
#endif
}

B
bellard 已提交
1984 1985
static inline void tcg_gen_exit_tb(tcg_target_long val)
{
P
pbrook 已提交
1986
    tcg_gen_op1i(INDEX_op_exit_tb, val);
B
bellard 已提交
1987 1988 1989 1990
}

static inline void tcg_gen_goto_tb(int idx)
{
P
pbrook 已提交
1991
    tcg_gen_op1i(INDEX_op_goto_tb, idx);
B
bellard 已提交
1992 1993 1994
}

#if TCG_TARGET_REG_BITS == 32
P
pbrook 已提交
1995
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
1996 1997
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
1998
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
1999
#else
P
pbrook 已提交
2000 2001
    tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2002
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2003 2004 2005
#endif
}

P
pbrook 已提交
2006
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2007 2008
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2009
    tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2010
#else
P
pbrook 已提交
2011 2012 2013
    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 已提交
2014 2015 2016
#endif
}

P
pbrook 已提交
2017
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2018 2019
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2020
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2021
#else
P
pbrook 已提交
2022 2023
    tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2024
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2025 2026 2027
#endif
}

P
pbrook 已提交
2028
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2029 2030
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2031
    tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2032
#else
P
pbrook 已提交
2033 2034 2035
    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 已提交
2036 2037 2038
#endif
}

P
pbrook 已提交
2039
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2040 2041
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2042
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
2043
#else
P
pbrook 已提交
2044 2045
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
P
pbrook 已提交
2046
    tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
B
bellard 已提交
2047 2048 2049
#endif
}

P
pbrook 已提交
2050
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2051 2052
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2053
    tcg_gen_op3i_i32(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
2054
#else
P
pbrook 已提交
2055 2056 2057
    tcg_gen_op4i_i32(INDEX_op_qemu_ld32u, TCGV_LOW(ret), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
    tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
B
bellard 已提交
2058 2059 2060
#endif
}

P
pbrook 已提交
2061
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2062 2063
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2064
    tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
B
bellard 已提交
2065
#else
P
pbrook 已提交
2066 2067
    tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2068 2069 2070
#endif
}

P
pbrook 已提交
2071
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2072 2073
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2074
    tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2075
#else
P
pbrook 已提交
2076 2077
    tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2078 2079 2080
#endif
}

P
pbrook 已提交
2081
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2082 2083
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2084
    tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2085
#else
P
pbrook 已提交
2086 2087
    tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2088 2089 2090
#endif
}

P
pbrook 已提交
2091
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2092 2093
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2094
    tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2095
#else
P
pbrook 已提交
2096 2097
    tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
                     TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2098 2099 2100
#endif
}

P
pbrook 已提交
2101
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2102 2103
{
#if TARGET_LONG_BITS == 32
P
pbrook 已提交
2104 2105
    tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
                     mem_index);
B
bellard 已提交
2106
#else
P
pbrook 已提交
2107 2108
    tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
                     TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
B
bellard 已提交
2109 2110 2111
#endif
}

B
blueswir1 已提交
2112
#define tcg_gen_ld_ptr tcg_gen_ld_i32
B
blueswir1 已提交
2113
#define tcg_gen_discard_ptr tcg_gen_discard_i32
2114

B
bellard 已提交
2115 2116
#else /* TCG_TARGET_REG_BITS == 32 */

P
pbrook 已提交
2117
static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2118
{
P
pbrook 已提交
2119
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
B
bellard 已提交
2120 2121
}

P
pbrook 已提交
2122
static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2123
{
P
pbrook 已提交
2124
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
B
bellard 已提交
2125 2126
}

P
pbrook 已提交
2127
static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2128
{
P
pbrook 已提交
2129
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
B
bellard 已提交
2130 2131
}

P
pbrook 已提交
2132
static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2133
{
P
pbrook 已提交
2134
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
B
bellard 已提交
2135 2136
}

P
pbrook 已提交
2137
static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2138
{
P
pbrook 已提交
2139
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
B
bellard 已提交
2140 2141
}

P
pbrook 已提交
2142
static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
B
bellard 已提交
2143
{
P
pbrook 已提交
2144
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
B
bellard 已提交
2145 2146
}

P
pbrook 已提交
2147
static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
B
bellard 已提交
2148
{
P
pbrook 已提交
2149
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
B
bellard 已提交
2150 2151
}

P
pbrook 已提交
2152
static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2153
{
P
pbrook 已提交
2154
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
B
bellard 已提交
2155 2156
}

P
pbrook 已提交
2157
static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2158
{
P
pbrook 已提交
2159
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
B
bellard 已提交
2160 2161
}

P
pbrook 已提交
2162
static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
B
bellard 已提交
2163
{
P
pbrook 已提交
2164
    tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
B
bellard 已提交
2165 2166
}

P
pbrook 已提交
2167
static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
B
bellard 已提交
2168
{
P
pbrook 已提交
2169
    tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
B
bellard 已提交
2170 2171
}

B
blueswir1 已提交
2172
#define tcg_gen_ld_ptr tcg_gen_ld_i64
B
blueswir1 已提交
2173
#define tcg_gen_discard_ptr tcg_gen_discard_i64
2174

B
bellard 已提交
2175
#endif /* TCG_TARGET_REG_BITS != 32 */
2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194

#if TARGET_LONG_BITS == 64
#define TCG_TYPE_TL TCG_TYPE_I64
#define tcg_gen_movi_tl tcg_gen_movi_i64
#define tcg_gen_mov_tl tcg_gen_mov_i64
#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
#define tcg_gen_ld_tl tcg_gen_ld_i64
#define tcg_gen_st8_tl tcg_gen_st8_i64
#define tcg_gen_st16_tl tcg_gen_st16_i64
#define tcg_gen_st32_tl tcg_gen_st32_i64
#define tcg_gen_st_tl tcg_gen_st_i64
#define tcg_gen_add_tl tcg_gen_add_i64
#define tcg_gen_addi_tl tcg_gen_addi_i64
#define tcg_gen_sub_tl tcg_gen_sub_i64
P
pbrook 已提交
2195
#define tcg_gen_neg_tl tcg_gen_neg_i64
P
pbrook 已提交
2196
#define tcg_gen_subfi_tl tcg_gen_subfi_i64
2197 2198 2199 2200 2201 2202 2203
#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 已提交
2204
#define tcg_gen_not_tl tcg_gen_not_i64
2205 2206 2207 2208 2209 2210
#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 已提交
2211
#define tcg_gen_brcond_tl tcg_gen_brcond_i64
P
pbrook 已提交
2212
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2213
#define tcg_gen_setcond_tl tcg_gen_setcond_i64
A
Aurelien Jarno 已提交
2214
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
2215 2216
#define tcg_gen_mul_tl tcg_gen_mul_i64
#define tcg_gen_muli_tl tcg_gen_muli_i64
2217 2218
#define tcg_gen_div_tl tcg_gen_div_i64
#define tcg_gen_rem_tl tcg_gen_rem_i64
A
aurel32 已提交
2219 2220
#define tcg_gen_divu_tl tcg_gen_divu_i64
#define tcg_gen_remu_tl tcg_gen_remu_i64
B
blueswir1 已提交
2221
#define tcg_gen_discard_tl tcg_gen_discard_i64
2222 2223 2224 2225 2226 2227
#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 已提交
2228 2229 2230 2231 2232 2233
#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
2234 2235 2236
#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
2237
#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2238 2239 2240 2241 2242
#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
2243 2244 2245 2246
#define tcg_gen_rotl_tl tcg_gen_rotl_i64
#define tcg_gen_rotli_tl tcg_gen_rotli_i64
#define tcg_gen_rotr_tl tcg_gen_rotr_i64
#define tcg_gen_rotri_tl tcg_gen_rotri_i64
B
blueswir1 已提交
2247
#define tcg_const_tl tcg_const_i64
A
aurel32 已提交
2248
#define tcg_const_local_tl tcg_const_local_i64
2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266
#else
#define TCG_TYPE_TL TCG_TYPE_I32
#define tcg_gen_movi_tl tcg_gen_movi_i32
#define tcg_gen_mov_tl tcg_gen_mov_i32
#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
#define tcg_gen_ld32u_tl tcg_gen_ld_i32
#define tcg_gen_ld32s_tl tcg_gen_ld_i32
#define tcg_gen_ld_tl tcg_gen_ld_i32
#define tcg_gen_st8_tl tcg_gen_st8_i32
#define tcg_gen_st16_tl tcg_gen_st16_i32
#define tcg_gen_st32_tl tcg_gen_st_i32
#define tcg_gen_st_tl tcg_gen_st_i32
#define tcg_gen_add_tl tcg_gen_add_i32
#define tcg_gen_addi_tl tcg_gen_addi_i32
#define tcg_gen_sub_tl tcg_gen_sub_i32
P
pbrook 已提交
2267
#define tcg_gen_neg_tl tcg_gen_neg_i32
A
aurel32 已提交
2268
#define tcg_gen_subfi_tl tcg_gen_subfi_i32
2269 2270 2271 2272 2273 2274 2275
#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 已提交
2276
#define tcg_gen_not_tl tcg_gen_not_i32
2277 2278 2279 2280 2281 2282
#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 已提交
2283
#define tcg_gen_brcond_tl tcg_gen_brcond_i32
P
pbrook 已提交
2284
#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2285
#define tcg_gen_setcond_tl tcg_gen_setcond_i32
A
Aurelien Jarno 已提交
2286
#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
2287 2288
#define tcg_gen_mul_tl tcg_gen_mul_i32
#define tcg_gen_muli_tl tcg_gen_muli_i32
2289 2290
#define tcg_gen_div_tl tcg_gen_div_i32
#define tcg_gen_rem_tl tcg_gen_rem_i32
A
aurel32 已提交
2291 2292
#define tcg_gen_divu_tl tcg_gen_divu_i32
#define tcg_gen_remu_tl tcg_gen_remu_i32
B
blueswir1 已提交
2293
#define tcg_gen_discard_tl tcg_gen_discard_i32
2294 2295 2296 2297 2298 2299
#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 已提交
2300 2301 2302 2303 2304 2305
#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
2306 2307
#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2308
#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2309 2310 2311 2312 2313
#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
2314 2315 2316 2317
#define tcg_gen_rotl_tl tcg_gen_rotl_i32
#define tcg_gen_rotli_tl tcg_gen_rotli_i32
#define tcg_gen_rotr_tl tcg_gen_rotr_i32
#define tcg_gen_rotri_tl tcg_gen_rotri_i32
B
blueswir1 已提交
2318
#define tcg_const_tl tcg_const_i32
A
aurel32 已提交
2319
#define tcg_const_local_tl tcg_const_local_i32
2320
#endif
P
pbrook 已提交
2321 2322

#if TCG_TARGET_REG_BITS == 32
2323
#define tcg_gen_add_ptr tcg_gen_add_i32
P
pbrook 已提交
2324
#define tcg_gen_addi_ptr tcg_gen_addi_i32
2325
#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
P
pbrook 已提交
2326
#else /* TCG_TARGET_REG_BITS == 32 */
2327
#define tcg_gen_add_ptr tcg_gen_add_i64
P
pbrook 已提交
2328
#define tcg_gen_addi_ptr tcg_gen_addi_i64
2329
#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
P
pbrook 已提交
2330
#endif /* TCG_TARGET_REG_BITS != 32 */