tcg/i386: Perform comparison pass with qemu

Ensures code and formatting is consistent with qemu
This commit is contained in:
Lioncash 2018-03-15 21:14:58 -04:00
parent 3a5e6fb750
commit 35df572589
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 46 additions and 77 deletions

View file

@ -89,7 +89,7 @@ typedef enum {
/* used for function call generation */ /* used for function call generation */
#define TCG_REG_CALL_STACK TCG_REG_ESP #define TCG_REG_CALL_STACK TCG_REG_ESP
#define TCG_TARGET_STACK_ALIGN 16 #define TCG_TARGET_STACK_ALIGN 16
#if defined(_WIN64) || (defined(__CYGWIN__) && defined(__x86_64__)) #if defined(_WIN64)
#define TCG_TARGET_CALL_STACK_OFFSET 32 #define TCG_TARGET_CALL_STACK_OFFSET 32
#else #else
#define TCG_TARGET_CALL_STACK_OFFSET 0 #define TCG_TARGET_CALL_STACK_OFFSET 0
@ -100,39 +100,6 @@ extern bool have_popcnt;
extern bool have_avx1; extern bool have_avx1;
extern bool have_avx2; extern bool have_avx2;
// UNICORN FIXME:
// Taken from cpuid.h in mainline qemu.
// The cpuid mechanism should just be
// backported instead
/* Leaf 1, %ecx */
#ifndef bit_SSE4_1
#define bit_SSE4_1 (1 << 19)
#endif
#ifndef bit_MOVBE
#define bit_MOVBE (1 << 22)
#endif
#ifndef bit_OSXSAVE
#define bit_OSXSAVE (1 << 27)
#endif
#ifndef bit_AVX
#define bit_AVX (1 << 28)
#endif
/* Leaf 7, %ebx */
#ifndef bit_BMI
#define bit_BMI (1 << 3)
#endif
#ifndef bit_AVX2
#define bit_AVX2 (1 << 5)
#endif
#ifndef bit_BMI2
#define bit_BMI2 (1 << 8)
#endif
/* Leaf 0x80000001, %ecx */
#ifndef bit_LZCNT
#define bit_LZCNT (1 << 5)
#endif
/* optional instructions */ /* optional instructions */
#define TCG_TARGET_HAS_div2_i32 1 #define TCG_TARGET_HAS_div2_i32 1
#define TCG_TARGET_HAS_rot_i32 1 #define TCG_TARGET_HAS_rot_i32 1

View file

@ -1243,7 +1243,7 @@ static void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
} }
/* Use SMALL != 0 to force a short forward branch. */ /* Use SMALL != 0 to force a short forward branch. */
static void tcg_out_jxx(TCGContext *s, int opc, TCGLabel *l, int smallflag) static void tcg_out_jxx(TCGContext *s, int opc, TCGLabel *l, int small)
{ {
int32_t val, val1; int32_t val, val1;
@ -1258,7 +1258,7 @@ static void tcg_out_jxx(TCGContext *s, int opc, TCGLabel *l, int smallflag)
} }
tcg_out8(s, val1); tcg_out8(s, val1);
} else { } else {
if (smallflag) { if (small) {
tcg_abort(); tcg_abort();
} }
if (opc == -1) { if (opc == -1) {
@ -1269,7 +1269,7 @@ static void tcg_out_jxx(TCGContext *s, int opc, TCGLabel *l, int smallflag)
tcg_out32(s, val - 6); tcg_out32(s, val - 6);
} }
} }
} else if (smallflag) { } else if (small) {
if (opc == -1) { if (opc == -1) {
tcg_out8(s, OPC_JMP_short); tcg_out8(s, OPC_JMP_short);
} else { } else {
@ -1305,25 +1305,25 @@ static void tcg_out_cmp(TCGContext *s, TCGArg arg1, TCGArg arg2,
static void tcg_out_brcond32(TCGContext *s, TCGCond cond, static void tcg_out_brcond32(TCGContext *s, TCGCond cond,
TCGArg arg1, TCGArg arg2, int const_arg2, TCGArg arg1, TCGArg arg2, int const_arg2,
TCGLabel *label, int smallflag) TCGLabel *label, int small)
{ {
tcg_out_cmp(s, arg1, arg2, const_arg2, 0); tcg_out_cmp(s, arg1, arg2, const_arg2, 0);
tcg_out_jxx(s, tcg_cond_to_jcc[cond], label, smallflag); tcg_out_jxx(s, tcg_cond_to_jcc[cond], label, small);
} }
#if TCG_TARGET_REG_BITS == 64 #if TCG_TARGET_REG_BITS == 64
static void tcg_out_brcond64(TCGContext *s, TCGCond cond, static void tcg_out_brcond64(TCGContext *s, TCGCond cond,
TCGArg arg1, TCGArg arg2, int const_arg2, TCGArg arg1, TCGArg arg2, int const_arg2,
TCGLabel *label, int smallflag) TCGLabel *label, int small)
{ {
tcg_out_cmp(s, arg1, arg2, const_arg2, P_REXW); tcg_out_cmp(s, arg1, arg2, const_arg2, P_REXW);
tcg_out_jxx(s, tcg_cond_to_jcc[cond], label, smallflag); tcg_out_jxx(s, tcg_cond_to_jcc[cond], label, small);
} }
#else #else
/* XXX: we implement it at the target level to avoid having to /* XXX: we implement it at the target level to avoid having to
handle cross basic blocks temporaries */ handle cross basic blocks temporaries */
static void tcg_out_brcond2(TCGContext *s, const TCGArg *args, static void tcg_out_brcond2(TCGContext *s, const TCGArg *args,
const int *const_args, int smallflag) const int *const_args, int small)
{ {
TCGLabel *label_next = gen_new_label(s); TCGLabel *label_next = gen_new_label(s);
TCGLabel *label_this = arg_label(s, args[5]); TCGLabel *label_this = arg_label(s, args[5]);
@ -1333,69 +1333,69 @@ static void tcg_out_brcond2(TCGContext *s, const TCGArg *args,
tcg_out_brcond32(s, TCG_COND_NE, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_NE, args[0], args[2], const_args[2],
label_next, 1); label_next, 1);
tcg_out_brcond32(s, TCG_COND_EQ, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_EQ, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_NE: case TCG_COND_NE:
tcg_out_brcond32(s, TCG_COND_NE, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_NE, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
tcg_out_brcond32(s, TCG_COND_NE, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_NE, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_LT: case TCG_COND_LT:
tcg_out_brcond32(s, TCG_COND_LT, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_LT, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
tcg_out_jxx(s, JCC_JNE, label_next, 1); tcg_out_jxx(s, JCC_JNE, label_next, 1);
tcg_out_brcond32(s, TCG_COND_LTU, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_LTU, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_LE: case TCG_COND_LE:
tcg_out_brcond32(s, TCG_COND_LT, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_LT, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
tcg_out_jxx(s, JCC_JNE, label_next, 1); tcg_out_jxx(s, JCC_JNE, label_next, 1);
tcg_out_brcond32(s, TCG_COND_LEU, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_LEU, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_GT: case TCG_COND_GT:
tcg_out_brcond32(s, TCG_COND_GT, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_GT, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
tcg_out_jxx(s, JCC_JNE, label_next, 1); tcg_out_jxx(s, JCC_JNE, label_next, 1);
tcg_out_brcond32(s, TCG_COND_GTU, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_GTU, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_GE: case TCG_COND_GE:
tcg_out_brcond32(s, TCG_COND_GT, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_GT, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
tcg_out_jxx(s, JCC_JNE, label_next, 1); tcg_out_jxx(s, JCC_JNE, label_next, 1);
tcg_out_brcond32(s, TCG_COND_GEU, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_GEU, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_LTU: case TCG_COND_LTU:
tcg_out_brcond32(s, TCG_COND_LTU, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_LTU, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
tcg_out_jxx(s, JCC_JNE, label_next, 1); tcg_out_jxx(s, JCC_JNE, label_next, 1);
tcg_out_brcond32(s, TCG_COND_LTU, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_LTU, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_LEU: case TCG_COND_LEU:
tcg_out_brcond32(s, TCG_COND_LTU, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_LTU, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
tcg_out_jxx(s, JCC_JNE, label_next, 1); tcg_out_jxx(s, JCC_JNE, label_next, 1);
tcg_out_brcond32(s, TCG_COND_LEU, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_LEU, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_GTU: case TCG_COND_GTU:
tcg_out_brcond32(s, TCG_COND_GTU, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_GTU, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
tcg_out_jxx(s, JCC_JNE, label_next, 1); tcg_out_jxx(s, JCC_JNE, label_next, 1);
tcg_out_brcond32(s, TCG_COND_GTU, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_GTU, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
break; break;
case TCG_COND_GEU: case TCG_COND_GEU:
tcg_out_brcond32(s, TCG_COND_GTU, args[1], args[3], const_args[3], tcg_out_brcond32(s, TCG_COND_GTU, args[1], args[3], const_args[3],
label_this, smallflag); label_this, small);
tcg_out_jxx(s, JCC_JNE, label_next, 1); tcg_out_jxx(s, JCC_JNE, label_next, 1);
tcg_out_brcond32(s, TCG_COND_GEU, args[0], args[2], const_args[2], tcg_out_brcond32(s, TCG_COND_GEU, args[0], args[2], const_args[2],
label_this, smallflag); label_this, small);
break; break;
default: default:
tcg_abort(); tcg_abort();
@ -1716,8 +1716,8 @@ static inline void tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
const TCGReg r0 = TCG_REG_L0; const TCGReg r0 = TCG_REG_L0;
const TCGReg r1 = TCG_REG_L1; const TCGReg r1 = TCG_REG_L1;
TCGType ttype = TCG_TYPE_I32; TCGType ttype = TCG_TYPE_I32;
TCGType htype = TCG_TYPE_I32; TCGType tlbtype = TCG_TYPE_I32;
int trexw = 0, hrexw = 0; int trexw = 0, hrexw = 0, tlbrexw = 0;
unsigned a_bits = get_alignment_bits(opc); unsigned a_bits = get_alignment_bits(opc);
unsigned s_bits = opc & MO_SIZE; unsigned s_bits = opc & MO_SIZE;
unsigned a_mask = (1 << a_bits) - 1; unsigned a_mask = (1 << a_bits) - 1;
@ -1730,12 +1730,15 @@ static inline void tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
trexw = P_REXW; trexw = P_REXW;
} }
if (TCG_TYPE_PTR == TCG_TYPE_I64) { if (TCG_TYPE_PTR == TCG_TYPE_I64) {
htype = TCG_TYPE_I64;
hrexw = P_REXW; hrexw = P_REXW;
if (TARGET_PAGE_BITS + CPU_TLB_BITS > 32) {
tlbtype = TCG_TYPE_I64;
tlbrexw = P_REXW;
}
} }
} }
tcg_out_mov(s, htype, r0, addrlo); tcg_out_mov(s, tlbtype, r0, addrlo);
/* If the required alignment is at least as large as the access, simply /* If the required alignment is at least as large as the access, simply
copy the address and mask. For lesser alignments, check that we don't copy the address and mask. For lesser alignments, check that we don't
cross pages for the complete access. */ cross pages for the complete access. */
@ -1746,11 +1749,11 @@ static inline void tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
} }
tlb_mask = (target_ulong)TARGET_PAGE_MASK | a_mask; tlb_mask = (target_ulong)TARGET_PAGE_MASK | a_mask;
tcg_out_shifti(s, SHIFT_SHR + hrexw, r0, tcg_out_shifti(s, SHIFT_SHR + tlbrexw, r0,
TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS); TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS);
tgen_arithi(s, ARITH_AND + trexw, r1, tlb_mask, 0); tgen_arithi(s, ARITH_AND + trexw, r1, tlb_mask, 0);
tgen_arithi(s, ARITH_AND + hrexw, r0, tgen_arithi(s, ARITH_AND + tlbrexw, r0,
(CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS, 0); (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS, 0);
tcg_out_modrm_sib_offset(s, OPC_LEA + hrexw, r0, TCG_AREG0, r0, 0, tcg_out_modrm_sib_offset(s, OPC_LEA + hrexw, r0, TCG_AREG0, r0, 0,
@ -2139,8 +2142,8 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)
if (TARGET_LONG_BITS == 32) { if (TARGET_LONG_BITS == 32) {
tcg_out_ext32u(s, TCG_REG_L0, base); tcg_out_ext32u(s, TCG_REG_L0, base);
base = TCG_REG_L0; base = TCG_REG_L0;
} }
if (offset != GUEST_BASE) { if (offset != GUEST_BASE) {
tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_L1, GUEST_BASE); tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_L1, GUEST_BASE);
index = TCG_REG_L1; index = TCG_REG_L1;
offset = 0; offset = 0;
@ -2283,10 +2286,10 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)
tgen_arithr(s, ARITH_ADD + P_REXW, TCG_REG_L1, base); tgen_arithr(s, ARITH_ADD + P_REXW, TCG_REG_L1, base);
base = TCG_REG_L1; base = TCG_REG_L1;
offset = 0; offset = 0;
} else if (TARGET_LONG_BITS == 32) {
tcg_out_ext32u(s, TCG_REG_L1, base);
base = TCG_REG_L1;
} }
} else if (TARGET_LONG_BITS == 32) {
tcg_out_ext32u(s, TCG_REG_L1, base);
base = TCG_REG_L1;
} }
tcg_out_qemu_st_direct(s, datalo, datahi, base, offset, seg, opc); tcg_out_qemu_st_direct(s, datalo, datahi, base, offset, seg, opc);
@ -2316,7 +2319,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
a2 = args[2]; a2 = args[2];
const_a2 = const_args[2]; const_a2 = const_args[2];
switch(opc) { switch (opc) {
case INDEX_op_exit_tb: case INDEX_op_exit_tb:
/* Reuse the zeroing that exists for goto_ptr. */ /* Reuse the zeroing that exists for goto_ptr. */
if (a0 == 0) { if (a0 == 0) {
@ -3070,7 +3073,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op)
static const TCGTargetOpDef arith2 = { 0, { "r", "r", "0", "1", "re", "re" } }; static const TCGTargetOpDef arith2 = { 0, { "r", "r", "0", "1", "re", "re" } };
return &arith2; return &arith2;
} }
case INDEX_op_ctz_i32: case INDEX_op_ctz_i32:
case INDEX_op_ctz_i64: case INDEX_op_ctz_i64:
{ {
@ -3454,7 +3456,7 @@ static const int tcg_target_callee_save_regs[] = {
#if TCG_TARGET_REG_BITS == 64 #if TCG_TARGET_REG_BITS == 64
TCG_REG_RBP, TCG_REG_RBP,
TCG_REG_RBX, TCG_REG_RBX,
#if (defined(_WIN64) || defined(__CYGWIN__)) #if defined(_WIN64)
TCG_REG_RDI, TCG_REG_RDI,
TCG_REG_RSI, TCG_REG_RSI,
#endif #endif
@ -3507,8 +3509,8 @@ static void tcg_target_qemu_prologue(TCGContext *s)
tcg_out_addi(s, TCG_REG_ESP, -stack_addend); tcg_out_addi(s, TCG_REG_ESP, -stack_addend);
/* jmp *tb. */ /* jmp *tb. */
tcg_out_modrm_offset(s, OPC_GRP5, EXT5_JMPN_Ev, TCG_REG_ESP, tcg_out_modrm_offset(s, OPC_GRP5, EXT5_JMPN_Ev, TCG_REG_ESP,
(ARRAY_SIZE(tcg_target_callee_save_regs) + 2) * 4 (ARRAY_SIZE(tcg_target_callee_save_regs) + 2) * 4
+ stack_addend); + stack_addend);
#else #else
tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]); tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
tcg_out_addi(s, TCG_REG_ESP, -stack_addend); tcg_out_addi(s, TCG_REG_ESP, -stack_addend);