tcg/i386 haswell improvements
cover tcg/i386 haswell improvements
We can implement extract and deposit fairly efficiently with the bmi2 pext and pdep instructions.
I did wonder about using bextr and tcg_reg_alloc_new to allocate the register required to hold the parameters. But pdep allows the mask to be stored in the constant pool, and there's the chance that the mask could be re-used, either by another extract or by a deposit.
I have not yet done any profiling on this yet.
r~
Richard Henderson (6):
tcg: Add tcg_reg_alloc_new
disas/i386: Fix disassembly of two-byte vex prefixes disas/i386: Add disassembly of vex.0f38.f5 disas/i386: Add disassembly of rorx tcg/i386: Use pext for extract
tcg/i386: Use pdep for deposit
tcg/i386/tcg-target.h | 10 ++- tcg/tcg.h | 1 + disas/i386.c | 29 ++++-- tcg/i386/tcg-target.inc.c | 223 +++++++++++++++++++++++++++++++++++----------- tcg/tcg.c | 58 +++++++++--- 5 files changed, 246 insertions(+), 75 deletions(-)
Signature · 1 line
2.13.3
PATCH 1/6 tcg: Add tcg_reg_alloc_new
This allows the backend to allocate an otherwise unused register. This can allow the backend to avoid having to reserve a full-time temporary register.
--- tcg/tcg.h | 1 + tcg/tcg.c | 58 +++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 13 deletions(-)
tcg/tcg.h +1 -0
@@ -655,6 +655,7 @@ struct TCGContext {uintptr_t *tb_jmp_insn_offset;/* tb->jmp_target_arg if direct_jump */ uintptr_t *tb_jmp_target_addr;/* tb->jmp_target_arg if !direct_jump */ +TCGRegSet regs_in_use;TCGRegSet reserved_regs;intptr_t current_frame_offset;intptr_t frame_start;
tcg/tcg.c +45 -13
211 lines not on this page · raw message
Signature · 1 line
2.13.3
PATCH 2/6 disas/i386: Fix disassembly of two-byte vex prefixes
In reply to Richard Henderson--- disas/i386.c | 1 + 1 file changed, 1 insertion(+)
disas/i386.c +1 -0
@@ -3559,6 +3559,7 @@ ckvexprefix (void) }else {/* Two byte VEX prefix. */ newrex |= (vex2 &0x80 ?0 :REX_R ); + newpfx |=PREFIX_VEX_0F ; codep +=2 ; }
Signature · 1 line
2.13.3
PATCH 3/6 disas/i386: Add disassembly of vex.0f38.f5
In reply to Richard HendersonWhich includes pext, pdep and bzhi.
--- disas/i386.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
disas/i386.c +12 -3
@@ -683,6 +683,7 @@ fetch_data(struct disassemble_info *info, bfd_byte *addr)#define PREGRP105 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 105 } }#define PREGRP106 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 106 } }#define PREGRP107 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 107 } } +#define PREGRP108 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 108 } }#define X86_64_0 NULL, { { NULL, X86_64_SPECIAL }, { NULL, 0 } }#define X86_64_1 NULL, { { NULL, X86_64_SPECIAL }, { NULL, 1 } }
@@ -1484,7 +1485,7 @@ static const unsigned char threebyte_0x38_uses_REPNZ_prefix[256] = {/* c0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* cf */ /* d0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* df */ /* e0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* ef */ - /* f0 */ 1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0, /* ff */ + /* f0 */ 1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0, /* ff */ /* ------------------------------- */ /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ };
@@ -1508,7 +1509,7 @@ static const unsigned char threebyte_0x38_uses_REPZ_prefix[256] = {/* c0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* cf */ /* d0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* df */ /* e0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* ef */ - /* f0 */ 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0, /* ff */ + /* f0 */ 0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0, /* ff */ /* ------------------------------- */ /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ };
@@ -2808,6 +2809,14 @@ static const struct dis386 prefix_user_table[][4] = { { "bsfS", { Gv, Ev } }, { "(bad)", { XX } }, }, + +/* PREGRP108 */ + { + { "bzhi", { Gv, Ev, Bv } }, + { "pext", { Gv, Bv, Ev } }, + { "(bad)", { XX } }, + { "pdep", { Gv, Bv, Ev } }, + }, };static const struct dis386 x86_64_table[][2 ] = {
@@ -3108,7 +3117,7 @@ static const struct dis386 three_byte_table[][256] = { { PREGRP105 }, { "(bad)", { XX } }, { "(bad)", { XX } }, - { "(bad)", { XX } }, + { PREGRP108 }, { "(bad)", { XX } }, { PREGRP106 },/* f8 */
Signature · 1 line
2.13.3
PATCH 4/6 disas/i386: Add disassembly of rorx
In reply to Richard Henderson--- disas/i386.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
disas/i386.c +11 -2
@@ -684,6 +684,7 @@ fetch_data(struct disassemble_info *info, bfd_byte *addr)#define PREGRP106 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 106 } }#define PREGRP107 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 107 } }#define PREGRP108 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 108 } } +#define PREGRP109 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 109 } }#define X86_64_0 NULL, { { NULL, X86_64_SPECIAL }, { NULL, 0 } }#define X86_64_1 NULL, { { NULL, X86_64_SPECIAL }, { NULL, 1 } }
@@ -1557,7 +1558,7 @@ static const unsigned char threebyte_0x3a_uses_REPNZ_prefix[256] = {/* c0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* cf */ /* d0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* df */ /* e0 */ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* ef */ - /* f0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */ + /* f0 */ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */ /* ------------------------------- */ /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ };
@@ -2817,6 +2818,14 @@ static const struct dis386 prefix_user_table[][4] = { { "(bad)", { XX } }, { "pdep", { Gv, Bv, Ev } }, }, + +/* PREGRP109 */ + { + { "(bad)", { XX } }, + { "(bad)", { XX } }, + { "(bad)", { XX } }, + { "rorx", { Gv, Ev, Ib } }, + }, };static const struct dis386 x86_64_table[][2 ] = {
@@ -3403,7 +3412,7 @@ static const struct dis386 three_byte_table[][256] = { { "(bad)", { XX } }, { "(bad)", { XX } },/* f0 */ - { "(bad)", { XX } }, + { PREGRP109 }, { "(bad)", { XX } }, { "(bad)", { XX } }, { "(bad)", { XX } },
Signature · 1 line
2.13.3
PATCH 5/6 tcg/i386: Use pext for extract
In reply to Richard Henderson--- tcg/i386/tcg-target.h | 6 +- tcg/i386/tcg-target.inc.c | 147 +++++++++++++++++++++++++++++++++------------- 2 files changed, 109 insertions(+), 44 deletions(-)
tcg/i386/tcg-target.h +4 -2
@@ -76,6 +76,7 @@ typedef enum {#endif extern bool have_bmi1; +extern bool have_bmi2;extern bool have_popcnt;/* optional instructions */
@@ -153,9 +154,10 @@ extern bool have_popcnt;/* Check for the possibility of high-byte extraction and, for 64-bit, zero-extending 32-bit right-shift. */ -#define TCG_TARGET_extract_i32_valid (ofs, len) ((ofs) == 8 && (len) == 8) +#define TCG_TARGET_extract_i32_valid (ofs, len) \ + (have_bmi2 || ((ofs) == 8 && (len) == 8))#define TCG_TARGET_extract_i64_valid (ofs, len) \ - (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32) + (have_bmi2 || ((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32)#if TCG_TARGET_REG_BITS ==64 # define TCG_AREG0 TCG_REG_R14
tcg/i386/tcg-target.inc.c +105 -42
247 lines not on this page · raw message
Signature · 1 line
2.13.3
PATCH 6/6 tcg/i386: Use pdep for deposit
In reply to Richard Henderson--- tcg/i386/tcg-target.h | 4 ++- tcg/i386/tcg-target.inc.c | 82 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 70 insertions(+), 16 deletions(-)
tcg/i386/tcg-target.h +3 -1
@@ -148,7 +148,9 @@ extern bool have_popcnt;#endif #define TCG_TARGET_deposit_i32_valid (ofs, len) \ - (((ofs) == 0 && (len) == 8) || ((ofs) == 8 && (len) == 8) || \ + (have_bmi2 || \ + ((ofs) == 0 && (len) == 8) || \ + ((ofs) == 8 && (len) == 8) || \ ((ofs) == 0 && (len) == 16))#define TCG_TARGET_deposit_i64_valid TCG_TARGET_deposit_i32_valid
tcg/i386/tcg-target.inc.c +67 -15
118 lines not on this page · raw message
Signature · 1 line
2.13.3