target/i386 tcg updates
v2 cover target/i386 tcg updates
Resurrecting some patches that were on the list in July. There are two bug fixes in here, so we should at least get those into 2.11.
Changes since v1:
* Rebased, adjusting for x86_ldub_code.
r~
Ricardo Ribalda Delgado (1):
target/i386: Fix ANDN (bmi)
Richard Henderson (3):
target/i386: Decode AMD XOP prefix
target/i386: Implement all TBM instructions
target/i386: Fix BLSR and BLSI
target/i386/cc_helper_template.h | 18 ++++ target/i386/cpu.h | 7 +- target/i386/cc_helper.c | 28 +++++- target/i386/cpu.c | 3 +- target/i386/translate.c | 191 ++++++++++++++++++++++++++++++++------- 5 files changed, 209 insertions(+), 38 deletions(-)
Signature · 1 line
2.13.6
PATCH v2 1/4 target/i386: Decode AMD XOP prefix
From: Richard Henderson <[email protected]>
--- target/i386/translate.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-)
target/i386/translate.c +32 -14
@@ -4536,8 +4536,9 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)#endif case 0xc5 :/* 2-byte VEX */ case 0xc4 :/* 3-byte VEX */ +case 0x8f :/* 3-byte XOP */ /* VEX prefixes cannot be used except in 32-bit mode. -Otherwise the instruction is LES or LDS. */ +Otherwise the instruction is LES, LDS, or POP. */ if (s->code32 && !s->vm86) {static const int pp_prefix[4 ] = {0 ,PREFIX_DATA ,PREFIX_REPZ ,PREFIX_REPNZ
@@ -4546,7 +4547,13 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)if (!CODE64 (s) && (vex2 &0xc0 ) !=0xc0 ) {/* 4.1.4.6: In 32-bit mode, bits [7:6] must be 11b, -otherwise the instruction is LES or LDS. */ +otherwise the instruction is LES, LDS, or POP. */ +break ; + } +if (b ==0x8f && (vex2 &0x1f ) <8 ) { +/* If the value of the XOP.map_select field is less than 8, +the first two bytes of the three-byte XOP are interpreted +as a form of the POP instruction. */ break ; } s->pc++;
@@ -4572,18 +4579,25 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)#endif vex3 =x86_ldub_code (env, s); rex_w = (vex3 >>7 ) &1 ; -switch (vex2 &0x1f ) { -case 0x01 :/* Implied 0f leading opcode bytes. */ - b =x86_ldub_code (env, s) |0x100 ; -break ; -case 0x02 :/* Implied 0f 38 leading opcode bytes. */ - b =0x138 ; -break ; -case 0x03 :/* Implied 0f 3a leading opcode bytes. */ - b =0x13a ; -break ; -default :/* Reserved for future use. */ - goto unknown_op; +if (b ==0xc4 ) { +switch (vex2 &0x1f ) { +case 0x01 :/* Implied 0f leading opcode bytes. */ + b =x86_ldub_code (env, s) |0x100 ; +break ; +case 0x02 :/* Implied 0f 38 leading opcode bytes. */ + b =0x138 ; +break ; +case 0x03 :/* Implied 0f 3a leading opcode bytes. */ + b =0x13a ; +break ; +default :/* Reserved for future use. */ + goto unknown_op; + } + }else { +/* Unlike VEX, XOP.map_select does not overlap the +base instruction set. Prepend the map_select to +the next opcode byte. */ + b =x86_ldub_code (env, s) + (vex2 &0x1f ) *0x100 ; } } s->vex_v = (~vex3 >>3 ) &0xf ;
@@ -8307,6 +8321,10 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x1d0 ... 0x1fe:gen_sse (env, s, b, pc_start, rex_r);break ; + + case 0x800 ... 0x8ff: /* XOP opcode map 8 */ + case 0x900 ... 0x9ff: /* XOP opcode map 9 */ + case 0xa00 ... 0xaff: /* XOP opcode map 10 */default : goto unknown_op; }
Signature · 1 line
2.13.6
PATCH v2 2/4 target/i386: Implement all TBM instructions
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
--- target/i386/cc_helper_template.h | 18 ++++++ target/i386/cpu.h | 7 ++- target/i386/cc_helper.c | 28 +++++++-- target/i386/cpu.c | 3 +- target/i386/translate.c | 123 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 170 insertions(+), 9 deletions(-)
target/i386/cc_helper_template.h +18 -0
@@ -235,6 +235,24 @@ static int glue(compute_c_bmilg, SUFFIX)(DATA_TYPE dst, DATA_TYPE src1)return src1 ==0 ; } +static int glue (compute_all_tbmadd ,SUFFIX )(DATA_TYPE dst,DATA_TYPE src1) +{ +int cf, pf, af, zf, sf, of; + + cf = (src1 == (DATA_TYPE )-1 ); + pf =0 ;/* undefined */ + af =0 ;/* undefined */ + zf = (dst ==0 ) *CC_Z ; + sf =lshift (dst,8 -DATA_BITS ) &CC_S ; + of =0 ; +return cf | pf | af | zf | sf | of; +} + +static int glue (compute_c_tbmadd ,SUFFIX )(DATA_TYPE dst,DATA_TYPE src1) +{ +return src1 == (DATA_TYPE )-1 ; +} +#undef DATA_BITS#undef SIGN_MASK#undef DATA_TYPE
target/i386/cpu.h +6 -1
@@ -774,11 +774,16 @@ typedef enum {CC_OP_SARL ,CC_OP_SARQ , -CC_OP_BMILGB ,/* Z,S via CC_DST, C = SRC==0; O=0; P,A undefined */ +CC_OP_BMILGB ,/* Z,S via DST, C = SRC==0; O=0; P,A undefined */ CC_OP_BMILGW ,CC_OP_BMILGL ,CC_OP_BMILGQ , +CC_OP_TBMADDB ,/* Z,S via DST; C = SRC==-1; O=0; P,A undefined */ +CC_OP_TBMADDW , +CC_OP_TBMADDL , +CC_OP_TBMADDQ , +CC_OP_ADCX ,/* CC_DST = C, CC_SRC = rest. */ CC_OP_ADOX ,/* CC_DST = O, CC_SRC = rest. */ CC_OP_ADCOX, /* CC_DST = C, CC_SRC2 = O, CC_SRC = rest. */
target/i386/cc_helper.c +24 -4
@@ -98,9 +98,6 @@ target_ulong helper_cc_compute_all(target_ulong dst, target_ulong src1, target_ulong src2, int op) {switch (op) { -default :/* should never happen */ -return 0 ; -case CC_OP_EFLAGS :return src1;case CC_OP_CLR :
@@ -185,6 +182,13 @@ target_ulong helper_cc_compute_all(target_ulong dst, target_ulong src1,case CC_OP_BMILGL :return compute_all_bmilgl (dst, src1); +case CC_OP_TBMADDB : +return compute_all_tbmaddb (dst, src1); +case CC_OP_TBMADDW : +return compute_all_tbmaddw (dst, src1); +case CC_OP_TBMADDL : +return compute_all_tbmaddl (dst, src1); +case CC_OP_ADCX :return compute_all_adcx (dst, src1, src2);case CC_OP_ADOX :
@@ -215,7 +219,12 @@ target_ulong helper_cc_compute_all(target_ulong dst, target_ulong src1,return compute_all_sarq (dst, src1);case CC_OP_BMILGQ :return compute_all_bmilgq (dst, src1); +case CC_OP_TBMADDQ : +return compute_all_tbmaddq (dst, src1);#endif + +default : +g_assert_not_reached (); } }
@@ -228,7 +237,6 @@ target_ulong helper_cc_compute_c(target_ulong dst, target_ulong src1, target_ulong src2, int op) {switch (op) { -default :/* should never happen */ case CC_OP_LOGICB :case CC_OP_LOGICW :case CC_OP_LOGICL :
@@ -307,6 +315,13 @@ target_ulong helper_cc_compute_c(target_ulong dst, target_ulong src1,case CC_OP_BMILGL :return compute_c_bmilgl (dst, src1); +case CC_OP_TBMADDB : +return compute_c_tbmaddb (dst, src1); +case CC_OP_TBMADDW : +return compute_c_tbmaddw (dst, src1); +case CC_OP_TBMADDL : +return compute_c_tbmaddl (dst, src1); +#ifdef TARGET_X86_64 case CC_OP_ADDQ :return compute_c_addq (dst, src1);
@@ -320,7 +335,12 @@ target_ulong helper_cc_compute_c(target_ulong dst, target_ulong src1,return compute_c_shlq (dst, src1);case CC_OP_BMILGQ :return compute_c_bmilgq (dst, src1); +case CC_OP_TBMADDQ : +return compute_c_tbmaddq (dst, src1);#endif + +default : +g_assert_not_reached (); } }
target/i386/cpu.c +2 -1
@@ -227,7 +227,8 @@ static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_PDPE1GB | \ TCG_EXT2_X86_64_FEATURES)#define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ - CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A) + CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A | \ + CPUID_EXT3_TBM)#define TCG_EXT4_FEATURES 0#define TCG_SVM_FEATURES 0#define TCG_KVM_FEATURES 0
target/i386/translate.c +120 -3
141 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH v2 3/4 target/i386: Fix BLSR and BLSI
In reply to Richard HendersonFrom: Richard Henderson <[email protected]>
The implementation of these two instructions was swapped. At the same time, unify the setup of eflags for the insn group.
--- target/i386/translate.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
target/i386/translate.c +9 -17
@@ -4067,34 +4067,26 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, ot =mo_64_32 (s->dflag);gen_ldst_modrm (env, s, modrm, ot,OR_TMP0 ,0 ); +tcg_gen_mov_tl (cpu_cc_src, cpu_T0);switch (reg &7 ) {case 1 :/* blsr By,Ey */ -tcg_gen_neg_tl (cpu_T1, cpu_T0); +tcg_gen_subi_tl (cpu_T1, cpu_T0,1 );tcg_gen_and_tl (cpu_T0, cpu_T0, cpu_T1); -gen_op_mov_reg_v (ot, s->vex_v, cpu_T0); -gen_op_update2_cc (); -set_cc_op (s,CC_OP_BMILGB + ot);break ; -case 2 :/* blsmsk By,Ey */ -tcg_gen_mov_tl (cpu_cc_src, cpu_T0); -tcg_gen_subi_tl (cpu_T0, cpu_T0,1 ); -tcg_gen_xor_tl (cpu_T0, cpu_T0, cpu_cc_src); -tcg_gen_mov_tl (cpu_cc_dst, cpu_T0); -set_cc_op (s,CC_OP_BMILGB + ot); +tcg_gen_subi_tl (cpu_T1, cpu_T0,1 ); +tcg_gen_xor_tl (cpu_T0, cpu_T0, cpu_T1);break ; -case 3 :/* blsi By, Ey */ -tcg_gen_mov_tl (cpu_cc_src, cpu_T0); -tcg_gen_subi_tl (cpu_T0, cpu_T0,1 ); -tcg_gen_and_tl (cpu_T0, cpu_T0, cpu_cc_src); -tcg_gen_mov_tl (cpu_cc_dst, cpu_T0); -set_cc_op (s,CC_OP_BMILGB + ot); +tcg_gen_neg_tl (cpu_T1, cpu_T0); +tcg_gen_and_tl (cpu_T0, cpu_T0, cpu_T1);break ; -default : goto unknown_op; } +tcg_gen_mov_tl (cpu_cc_dst, cpu_T0); +gen_op_mov_reg_v (ot, s->vex_v, cpu_T0); +set_cc_op (s,CC_OP_BMILGB + ot);break ;default :
Signature · 1 line
2.13.6
PATCH v2 4/4 target/i386: Fix ANDN (bmi)
In reply to Richard HendersonFrom: Ricardo Ribalda Delgado <[email protected]>
Operands on ANDN are swapped.
Tested with the following function:
long test_andn(long v1, long v2){
return (~v1 & v2);
}Compiled with:
gcc kk.c -mbmi -O3 -Wall
0000000000000910 <test_andn>:
910:c4 e2 c0 f2 c6 andn %rsi,%rdi,%rax
915:c3 retq
916:66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
91d:00 00 00
and
gcc kk.c -march=native -O3 -Wall
0000000000000930 <test_andn>:
930: 48 f7 d7 not %rdi 933: 48 89 f8 mov %rdi,%rax 936: 48 21 f0 and %rsi,%rax 939: c3 retq 93a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
The test showed than -mbmi version behaved differently than the -march native version.
Message-Id: <[email protected]>
--- target/i386/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/translate.c +1 -1
@@ -3810,7 +3810,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, } ot =mo_64_32 (s->dflag);gen_ldst_modrm (env, s, modrm, ot,OR_TMP0 ,0 ); -tcg_gen_andc_tl (cpu_T0, cpu_regs[s->vex_v], cpu_T0); +tcg_gen_andc_tl (cpu_T0, cpu_T0, cpu_regs[s->vex_v]);gen_op_mov_reg_v (ot, reg, cpu_T0);gen_op_update1_cc ();set_cc_op (s,CC_OP_LOGICB + ot);
Signature · 1 line
2.13.6