tcg: Assorted cleanups
v2 cover tcg: Assorted cleanups
This includes everything queued so far -- softmmu out-of-line patches, bswap cleanups, and (new) eliminating all scratch registers from x86 user-only memops.
This tree is now at
https://github.com/rth7680/qemu.git tcg-next-for-4.0
for future tcg/riscv/ rebasing.
r~
Richard Henderson (37):
tcg/i386: Always use %ebp for TCG_AREG0
tcg/i386: Move TCG_REG_CALL_STACK from define to enum
tcg: Return success from patch_reloc
tcg: Add TCG_TARGET_NEED_LDST_OOL_LABELS
tcg/i386: Add constraints for r8 and r9
tcg/i386: Return a base register from tcg_out_tlb_load tcg/i386: Change TCG_REG_L[01] to not overlap function arguments tcg/i386: Force qemu_ld/st arguments into fixed registers tcg/i386: Use TCG_TARGET_NEED_LDST_OOL_LABELS tcg/aarch64: Add constraints for x0, x1, x2 tcg/aarch64: Parameterize the temps for tcg_out_tlb_read tcg/aarch64: Parameterize the temp for tcg_out_goto_long tcg/aarch64: Use B not BL for tcg_out_goto_long tcg/aarch64: Use TCG_TARGET_NEED_LDST_OOL_LABELS tcg/arm: Parameterize the temps for tcg_out_tlb_read tcg/arm: Add constraints for R0-R5
tcg/arm: Reduce the number of temps for tcg_out_tlb_read tcg/arm: Force qemu_ld/st arguments into fixed registers tcg/arm: Use TCG_TARGET_NEED_LDST_OOL_LABELS
tcg/ppc: Parameterize the temps for tcg_out_tlb_read tcg/ppc: Split out tcg_out_call_int
tcg/ppc: Add constraints for R7-R8
tcg/ppc: Change TCG_TARGET_CALL_ALIGN_ARGS to bool tcg/ppc: Force qemu_ld/st arguments into fixed registers tcg/ppc: Use TCG_TARGET_NEED_LDST_OOL_LABELS
tcg: Clean up generic bswap32
tcg: Clean up generic bswap64
tcg/optimize: Optimize bswap
tcg: Add TCG_TARGET_HAS_MEMORY_BSWAP
tcg/i386: Adjust TCG_TARGET_HAS_MEMORY_BSWAP tcg/aarch64: Set TCG_TARGET_HAS_MEMORY_BSWAP to false tcg/arm: Set TCG_TARGET_HAS_MEMORY_BSWAP to false for user-only tcg/i386: Propagate is64 to tcg_out_qemu_ld_direct tcg/i386: Restrict user-only qemu_st_i32 values to q-regs tcg/i386: Add setup_guest_base_seg for FreeBSD tcg/i386: Require segment syscalls to succeed tcg/i386: Remove L constraint
tcg/aarch64/tcg-target.h | 3 +- tcg/arm/tcg-target.h | 7 +- tcg/i386/tcg-target.h | 19 +- tcg/mips/tcg-target.h | 1 + tcg/ppc/tcg-target.h | 3 +- tcg/s390/tcg-target.h | 1 + tcg/sparc/tcg-target.h | 1 + tcg/tcg.h | 5 + tcg/tci/tcg-target.h | 2 + accel/tcg/translate-all.c | 15 +- tcg/aarch64/tcg-target.inc.c | 369 ++++++++-------- tcg/arm/tcg-target.inc.c | 643 +++++++++++++-------------- tcg/i386/tcg-target.inc.c | 821 ++++++++++++++++++++--------------- tcg/mips/tcg-target.inc.c | 29 +- tcg/optimize.c | 12 + tcg/ppc/tcg-target.inc.c | 562 +++++++++++++----------- tcg/s390/tcg-target.inc.c | 37 +- tcg/sparc/tcg-target.inc.c | 13 +- tcg/tcg-ldst-ool.inc.c | 95 ++++ tcg/tcg-op.c | 215 ++++++--- tcg/tcg-pool.inc.c | 5 +- tcg/tcg.c | 36 +- tcg/tci/tcg-target.inc.c | 3 +- 23 files changed, 1628 insertions(+), 1269 deletions(-) create mode 100644 tcg/tcg-ldst-ool.inc.c
Signature · 1 line
2.17.2
PATCH v2 1/37 tcg/i386: Always use %ebp for TCG_AREG0
For x86_64, this can result in smaller code when manipulating TCG_TYPE_I32, as we can omit a REX prefix.
--- tcg/i386/tcg-target.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
tcg/i386/tcg-target.h +2 -6
@@ -84,6 +84,8 @@ typedef enum {TCG_REG_RBP =TCG_REG_EBP ,TCG_REG_RSI =TCG_REG_ESI ,TCG_REG_RDI =TCG_REG_EDI , + +TCG_AREG0 =TCG_REG_EBP , } TCGReg;/* used for function call generation */
@@ -194,12 +196,6 @@ extern bool have_avx2;#define TCG_TARGET_extract_i64_valid (ofs, len) \ (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32) -#if TCG_TARGET_REG_BITS ==64 -# define TCG_AREG0 TCG_REG_R14 -#else -# define TCG_AREG0 TCG_REG_EBP -#endif -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) { }
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 01/37] tcg/i386: Always use %ebp for TCG_AREG0
Quoted 2 lines · Richard Henderson
For
x86_64, this can result in smaller code when manipulatingTCG_TYPE_I32, as we can omit a REX prefix.
I take it you mean passing TCG_TYPE_I32 back and forth from the register backing store in CPUEnv which TCG_AREG0 points at?
Anyway:
Quoted 22 lines
Signed-off-by Richard Henderson <[email protected]>--- tcg/i386/tcg-target.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tcg/i386/tcg-target.h +2
-0@@ -84,6 +84,8 @@ typedef enum {TCG_REG_RBP =TCG_REG_EBP ,TCG_REG_RSI =TCG_REG_ESI ,TCG_REG_RDI =TCG_REG_EDI , + +TCG_AREG0 =TCG_REG_EBP , } TCGReg;/* used for function call generation */ @@ -194,12 +196,6 @@ extern bool have_avx2;#define TCG_TARGET_extract_i64_valid (ofs, len) \ (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32)
tcg/i386/tcg-target.h extern bool have_avx2; · line 201
Quoted 10 lines
tcg/i386/tcg-target.h +0
-6-#if TCG_TARGET_REG_BITS ==64 -# define TCG_AREG0 TCG_REG_R14 -#else -# define TCG_AREG0 TCG_REG_EBP -#endif -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) { }
--
Alex Bennée
Re: [Qemu-devel] [PATCH for-4.0 v2 01/37] tcg/i386: Always use %ebp for TCG_AREG0
Quoted 8 lines · Alex Bennée
Quoted 2 lines · Richard Henderson
For
x86_64, this can result in smaller code when manipulatingTCG_TYPE_I32, as we can omit a REX prefix.I take it you mean passing
TCG_TYPE_I32back and forth from the register backing store in CPUEnv whichTCG_AREG0points at?
Yes, exactly. Perhaps I should expand my comment...
r~
PATCH v2 2/37 tcg/i386: Move TCG_REG_CALL_STACK from define to enum
In reply to Richard Henderson--- tcg/i386/tcg-target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/i386/tcg-target.h +1 -1
@@ -86,10 +86,10 @@ typedef enum {TCG_REG_RDI =TCG_REG_EDI ,TCG_AREG0 =TCG_REG_EBP , + TCG_REG_CALL_STACK = TCG_REG_ESP } TCGReg;/* used for function call generation */ -#define TCG_REG_CALL_STACK TCG_REG_ESP#define TCG_TARGET_STACK_ALIGN 16#if defined(_WIN64)#define TCG_TARGET_CALL_STACK_OFFSET 32
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 02/37] tcg/i386: Move TCG_REG_CALL_STACK from define to enum
Quoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Quoted 10 lines
--- tcg/i386/tcg-target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tcg/i386/tcg-target.h +0
-0@@ -86,10 +86,10 @@ typedef enum { TCG_REG_RDI = TCG_REG_EDI,
tcg/i386/tcg-target.h typedef enum { · line 95
Quoted 10 lines
tcg/i386/tcg-target.h +1
-1TCG_AREG0 =TCG_REG_EBP , + TCG_REG_CALL_STACK = TCG_REG_ESP } TCGReg;/* used for function call generation */ -#define TCG_REG_CALL_STACK TCG_REG_ESP#define TCG_TARGET_STACK_ALIGN 16#if defined(_WIN64)#define TCG_TARGET_CALL_STACK_OFFSET 32
--
Alex Bennée
PATCH v2 3/37 tcg: Return success from patch_reloc
In reply to Richard HendersonThis moves the assert for success from inside patch_reloc to outside patch_reloc. This touches all tcg backends.
--- tcg/aarch64/tcg-target.inc.c | 44 ++++++++++++++------------------- tcg/arm/tcg-target.inc.c | 26 +++++++++----------- tcg/i386/tcg-target.inc.c | 17 +++++++------ tcg/mips/tcg-target.inc.c | 29 +++++++++------------- tcg/ppc/tcg-target.inc.c | 47 ++++++++++++++++++++++-------------- tcg/s390/tcg-target.inc.c | 37 +++++++++++++++++++--------- tcg/sparc/tcg-target.inc.c | 13 ++++++---- tcg/tcg-pool.inc.c | 5 +++- tcg/tcg.c | 8 +++--- tcg/tci/tcg-target.inc.c | 3 ++- 10 files changed, 125 insertions(+), 104 deletions(-)
tcg/aarch64/tcg-target.inc.c +18 -26
@@ -78,48 +78,40 @@ static const int tcg_target_call_oarg_regs[1] = {#define TCG_REG_GUEST_BASE TCG_REG_X28#endif -static inline void reloc_pc26 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) +static inline bool reloc_pc26 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) {ptrdiff_t offset = target - code_ptr; -tcg_debug_assert (offset ==sextract64 (offset,0 ,26 )); -/* read instruction, mask away previous PC_REL26 parameter contents, -set the proper offset, then write back the instruction. */ - *code_ptr =deposit32 (*code_ptr,0 ,26 , offset); +if (offset ==sextract64 (offset,0 ,26 )) { +/* read instruction, mask away previous PC_REL26 parameter contents, +set the proper offset, then write back the instruction. */ + *code_ptr =deposit32 (*code_ptr,0 ,26 , offset); +return true; + } +return false; } -static inline void reloc_pc26_atomic (tcg_insn_unit *code_ptr, -tcg_insn_unit *target) +static inline bool reloc_pc19 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) {ptrdiff_t offset = target - code_ptr; -tcg_insn_unit insn; -tcg_debug_assert (offset ==sextract64 (offset,0 ,26 )); -/* read instruction, mask away previous PC_REL26 parameter contents, -set the proper offset, then write back the instruction. */ - insn =atomic_read (code_ptr); -atomic_set (code_ptr,deposit32 (insn,0 ,26 , offset)); +if (offset ==sextract64 (offset,0 ,19 )) { + *code_ptr =deposit32 (*code_ptr,5 ,19 , offset); +return true; + } +return false; } -static inline void reloc_pc19 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) -{ -ptrdiff_t offset = target - code_ptr; -tcg_debug_assert (offset ==sextract64 (offset,0 ,19 )); - *code_ptr =deposit32 (*code_ptr,5 ,19 , offset); -} - -static inline void patch_reloc (tcg_insn_unit *code_ptr,int type, +static inline bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {tcg_debug_assert (addend ==0 );switch (type) {case R_AARCH64_JUMP26 :case R_AARCH64_CALL26 : -reloc_pc26 (code_ptr, (tcg_insn_unit *)value); -break ; +return reloc_pc26 (code_ptr, (tcg_insn_unit *)value);case R_AARCH64_CONDBR19 : -reloc_pc19 (code_ptr, (tcg_insn_unit *)value); -break ; +return reloc_pc19 (code_ptr, (tcg_insn_unit *)value);default : -tcg_abort (); +g_assert_not_reached (); } }
tcg/arm/tcg-target.inc.c +12 -14
@@ -187,27 +187,23 @@ static const uint8_t tcg_cond_to_arm_cond[] = { [TCG_COND_GTU] = COND_HI, }; -static inline void reloc_pc24 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) +static inline bool reloc_pc24 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) {ptrdiff_t offset = (tcg_ptr_byte_diff (target, code_ptr) -8 ) >>2 ; - *code_ptr = (*code_ptr & ~0xffffff ) | (offset &0xffffff ); +if (offset ==sextract32 (offset,0 ,24 )) { + *code_ptr = (*code_ptr & ~0xffffff ) | (offset &0xffffff ); +return true; + } +return false; } -static inline void reloc_pc24_atomic (tcg_insn_unit *code_ptr,tcg_insn_unit *target) -{ -ptrdiff_t offset = (tcg_ptr_byte_diff (target, code_ptr) -8 ) >>2 ; -tcg_insn_unit insn =atomic_read (code_ptr); -tcg_debug_assert (offset ==sextract32 (offset,0 ,24 )); -atomic_set (code_ptr,deposit32 (insn,0 ,24 , offset)); -} - -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {tcg_debug_assert (addend ==0 );if (type ==R_ARM_PC24 ) { -reloc_pc24 (code_ptr, (tcg_insn_unit *)value); +return reloc_pc24 (code_ptr, (tcg_insn_unit *)value); }else if (type ==R_ARM_PC13 ) {intptr_t diff = value - (uintptr_t )(code_ptr +2 );tcg_insn_unit insn = *code_ptr;
@@ -218,10 +214,9 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,if (!u) { diff = -diff; } - }else { + }else if (diff >=0x1000 && diff <0x100000 ) {int rd =extract32 (insn,12 ,4 );int rt = rd ==TCG_REG_PC ?TCG_REG_TMP : rd; -assert (diff >=0x1000 && diff <0x100000 );/* add rt, pc, #high */ *code_ptr++ = ((insn &0xf0000000 ) | (1 <<25 ) |ARITH_ADD | (TCG_REG_PC << 16) | (rt << 12)
@@ -230,10 +225,13 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, insn =deposit32 (insn,12 ,4 , rt); diff &=0xfff ; u =1 ; + }else { +return false; } insn =deposit32 (insn,23 ,1 , u); insn =deposit32 (insn,0 ,12 , diff); *code_ptr = insn; +return true; }else {g_assert_not_reached (); }
tcg/i386/tcg-target.inc.c +10 -7
@@ -167,29 +167,32 @@ static bool have_lzcnt;static tcg_insn_unit *tb_ret_addr; -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) { value += addend; -switch (type) { + +switch (type) {case R_386_PC32 : value -= (uintptr_t )code_ptr;if (value != (int32_t )value) { -tcg_abort (); +return false; }/* FALLTHRU */ case R_386_32 :tcg_patch32 (code_ptr, value); -break ; +return true; +case R_386_PC8 : value -= (uintptr_t )code_ptr;if (value != (int8_t )value) { -tcg_abort (); +return false; }tcg_patch8 (code_ptr, value); -break ; +return true; +default : -tcg_abort (); +g_assert_not_reached (); } }
tcg/mips/tcg-target.inc.c +11 -18
@@ -144,36 +144,29 @@ static tcg_insn_unit *bswap32_addr;static tcg_insn_unit *bswap32u_addr;static tcg_insn_unit *bswap64_addr; -static inline uint32_t reloc_pc16_val (tcg_insn_unit *pc,tcg_insn_unit *target) +static bool reloc_pc16_cond (tcg_insn_unit *pc,tcg_insn_unit *target) {/* Let the compiler perform the right-shift as part of the arithmetic. */ ptrdiff_t disp = target - (pc +1 ); -tcg_debug_assert (disp == (int16_t )disp); -return disp &0xffff ; +if (disp == (int16_t )disp) { + *pc =deposit32 (*pc,0 ,16 , disp); +return true; + }else { +return false; + } } -static inline void reloc_pc16 (tcg_insn_unit *pc,tcg_insn_unit *target) +static bool reloc_pc16 (tcg_insn_unit *pc,tcg_insn_unit *target) { - *pc =deposit32 (*pc,0 ,16 ,reloc_pc16_val (pc, target)); +tcg_debug_assert (reloc_pc16_cond (pc, target)); } -static inline uint32_t reloc_26_val (tcg_insn_unit *pc,tcg_insn_unit *target) -{ -tcg_debug_assert ((((uintptr_t )pc ^ (uintptr_t )target) &0xf0000000 ) ==0 ); -return ((uintptr_t )target >>2 ) &0x3ffffff ; -} - -static inline void reloc_26 (tcg_insn_unit *pc,tcg_insn_unit *target) -{ - *pc =deposit32 (*pc,0 ,26 ,reloc_26_val (pc, target)); -} - -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {tcg_debug_assert (type ==R_MIPS_PC16 );tcg_debug_assert (addend ==0 ); -reloc_pc16 (code_ptr, (tcg_insn_unit *)value); +return reloc_pc16_cond (code_ptr, (tcg_insn_unit *)value); }#define TCG_CT_CONST_ZERO 0x100
tcg/ppc/tcg-target.inc.c +29 -18
84 lines not on this page · raw message
tcg/s390/tcg-target.inc.c +26 -11
@@ -366,7 +366,7 @@ static void * const qemu_st_helpers[16] = {static tcg_insn_unit *tb_ret_addr;uint64_t s390_facilities; -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {intptr_t pcrel2;
@@ -377,22 +377,35 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,switch (type) {case R_390_PC16DBL : -assert (pcrel2 == (int16_t )pcrel2); -tcg_patch16 (code_ptr, pcrel2); +if (pcrel2 == (int16_t )pcrel2) { +tcg_patch16 (code_ptr, pcrel2); +return true; + }break ;case R_390_PC32DBL : -assert (pcrel2 == (int32_t )pcrel2); -tcg_patch32 (code_ptr, pcrel2); +if (pcrel2 == (int32_t )pcrel2) { +tcg_patch32 (code_ptr, pcrel2); +return true; + }break ;case R_390_20 : -assert (value ==sextract64 (value,0 ,20 )); - old = *(uint32_t *)code_ptr &0xf00000ff ; - old |= ((value &0xfff ) <<16 ) | ((value &0xff000 ) >>4 ); -tcg_patch32 (code_ptr, old); +if (value ==sextract64 (value,0 ,20 )) { + old = *(uint32_t *)code_ptr &0xf00000ff ; + old |= ((value &0xfff ) <<16 ) | ((value &0xff000 ) >>4 ); +tcg_patch32 (code_ptr, old); +return true; + }break ;default :g_assert_not_reached (); } +return false; +} + +static void patch_reloc_force (tcg_insn_unit *code_ptr,int type, +intptr_t value,intptr_t addend) +{ +tcg_debug_assert (patch_reloc (code_ptr, type, value, addend)); }/* parse target specific constraints */
@@ -1618,7 +1631,8 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)TCGMemOpIdx oi = lb->oi;TCGMemOp opc =get_memop (oi); -patch_reloc (lb->label_ptr[0 ],R_390_PC16DBL , (intptr_t )s->code_ptr,2 ); +patch_reloc_force (lb->label_ptr[0 ],R_390_PC16DBL , + (intptr_t )s->code_ptr,2 );tcg_out_mov (s,TCG_TYPE_PTR ,TCG_REG_R2 ,TCG_AREG0 );if (TARGET_LONG_BITS ==64 ) {
@@ -1639,7 +1653,8 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)TCGMemOpIdx oi = lb->oi;TCGMemOp opc =get_memop (oi); -patch_reloc (lb->label_ptr[0 ],R_390_PC16DBL , (intptr_t )s->code_ptr,2 ); +patch_reloc_force (lb->label_ptr[0 ],R_390_PC16DBL , + (intptr_t )s->code_ptr,2 );tcg_out_mov (s,TCG_TYPE_PTR ,TCG_REG_R2 ,TCG_AREG0 );if (TARGET_LONG_BITS ==64 ) {
tcg/sparc/tcg-target.inc.c +8 -5
@@ -291,32 +291,34 @@ static inline int check_fit_i32(int32_t val, unsigned int bits)# define check_fit_ptr check_fit_i32#endif -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {uint32_t insn = *code_ptr;intptr_t pcrel; +bool ret; value += addend; pcrel =tcg_ptr_byte_diff ((tcg_insn_unit *)value, code_ptr);switch (type) {case R_SPARC_WDISP16 : -assert (check_fit_ptr (pcrel >>2 ,16 )); + ret =check_fit_ptr (pcrel >>2 ,16 ); insn &= ~INSN_OFF16 (-1 ); insn |=INSN_OFF16 (pcrel);break ;case R_SPARC_WDISP19 : -assert (check_fit_ptr (pcrel >>2 ,19 )); + ret =check_fit_ptr (pcrel >>2 ,19 ); insn &= ~INSN_OFF19 (-1 ); insn |=INSN_OFF19 (pcrel);break ;case R_SPARC_13 :/* Note that we're abusing this reloc type for our own needs. */ + ret = true;if (!check_fit_ptr (value,13 )) {int adj = (value >0 ?0xff8 :-0x1000 ); value -= adj; -assert (check_fit_ptr (value,13 )); + ret =check_fit_ptr (value,13 ); *code_ptr++ = (ARITH_ADD |INSN_RD (TCG_REG_T2 ) |INSN_RS1 (TCG_REG_TB ) |INSN_IMM13 (adj)); insn ^=INSN_RS1 (TCG_REG_TB ) ^INSN_RS1 (TCG_REG_T2 );
@@ -328,12 +330,13 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,/* Note that we're abusing this reloc type for our own needs. */ code_ptr[0 ] =deposit32 (code_ptr[0 ],0 ,22 , value >>10 ); code_ptr[1 ] =deposit32 (code_ptr[1 ],0 ,10 , value); -return ; +return value == (intptr_t )(uint32_t )value;default :g_assert_not_reached (); } *code_ptr = insn; +return ret; }/* parse target specific constraints */
tcg/tcg-pool.inc.c +4 -1
@@ -140,6 +140,8 @@ static bool tcg_out_pool_finalize(TCGContext *s)for (; p !=NULL ; p = p->next) {size_t size =sizeof (tcg_target_ulong) * p->nlong; +bool ok; +if (!l || l->nlong != p->nlong ||memcmp (l->data, p->data, size)) {if (unlikely (a > s->code_gen_highwater)) {return false;
@@ -148,7 +150,8 @@ static bool tcg_out_pool_finalize(TCGContext *s) a += size; l = p; } -patch_reloc (p->label, p->rtype, (intptr_t )a - size, p->addend); + ok =patch_reloc (p->label, p->rtype, (intptr_t )a - size, p->addend); +tcg_debug_assert (ok); } s->code_ptr = a;
tcg/tcg.c +5 -3
@@ -66,7 +66,7 @@static void tcg_target_init (TCGContext *s);static const TCGTargetOpDef *tcg_target_op_def (TCGOpcode );static void tcg_target_qemu_prologue (TCGContext *s); -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend);/* The CIE and FDE header definitions will be common to all hosts. */
@@ -268,7 +268,8 @@ static void tcg_out_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,/* FIXME: This may break relocations on RISC targets that modify instruction fields in place. The caller may not have written the initial value. */ -patch_reloc (code_ptr, type, l->u.value, addend); +bool ok =patch_reloc (code_ptr, type, l->u.value, addend); +tcg_debug_assert (ok); }else {/* add a new relocation entry */ r =tcg_malloc (sizeof (TCGRelocation));
@@ -288,7 +289,8 @@ static void tcg_out_label(TCGContext *s, TCGLabel *l, tcg_insn_unit *ptr)tcg_debug_assert (!l->has_value);for (r = l->u.first_reloc; r !=NULL ; r = r->next) { -patch_reloc (r->ptr, r->type, value, r->addend); +bool ok =patch_reloc (r->ptr, r->type, value, r->addend); +tcg_debug_assert (ok); } l->has_value =1 ;
tcg/tci/tcg-target.inc.c +2 -1
@@ -369,7 +369,7 @@ static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { };#endif -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {/* tcg_out_reloc always uses the same type, addend. */
@@ -381,6 +381,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, }else {tcg_patch64 (code_ptr, value); } +return true; }/* Parse target specific constraints. */
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 03/37] tcg: Return success from patch_reloc
Quoted 2 lines · Richard Henderson
This moves the assert for success from inside
patch_relocto outsidepatch_reloc. This touches all tcg backends.
s/outside/above/?
We also seem to be dropping a bunch of reloc_atomic functions (which are no longer used?). Perhaps that should be a separate patch to make the series cleaner?
Quoted 201 lines
Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target.inc.c | 44 ++++++++++++++------------------- tcg/arm/tcg-target.inc.c | 26 +++++++++----------- tcg/i386/tcg-target.inc.c | 17 +++++++------ tcg/mips/tcg-target.inc.c | 29 +++++++++------------- tcg/ppc/tcg-target.inc.c | 47 ++++++++++++++++++++++-------------- tcg/s390/tcg-target.inc.c | 37 +++++++++++++++++++--------- tcg/sparc/tcg-target.inc.c | 13 ++++++---- tcg/tcg-pool.inc.c | 5 +++- tcg/tcg.c | 8 +++--- tcg/tci/tcg-target.inc.c | 3 ++- 10 files changed, 125 insertions(+), 104 deletions(-)tcg/aarch64/tcg-target.inc.c +18
-26@@ -78,48 +78,40 @@ static const int tcg_target_call_oarg_regs[1] = {#define TCG_REG_GUEST_BASE TCG_REG_X28#endif -static inline void reloc_pc26 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) +static inline bool reloc_pc26 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) {ptrdiff_t offset = target - code_ptr; -tcg_debug_assert (offset ==sextract64 (offset,0 ,26 )); -/* read instruction, mask away previous PC_REL26 parameter contents, -set the proper offset, then write back the instruction. */ - *code_ptr =deposit32 (*code_ptr,0 ,26 , offset); +if (offset ==sextract64 (offset,0 ,26 )) { +/* read instruction, mask away previous PC_REL26 parameter contents, +set the proper offset, then write back the instruction. */ + *code_ptr =deposit32 (*code_ptr,0 ,26 , offset); +return true; + } +return false; } -static inline void reloc_pc26_atomic (tcg_insn_unit *code_ptr, -tcg_insn_unit *target) +static inline bool reloc_pc19 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) {ptrdiff_t offset = target - code_ptr; -tcg_insn_unit insn; -tcg_debug_assert (offset ==sextract64 (offset,0 ,26 )); -/* read instruction, mask away previous PC_REL26 parameter contents, -set the proper offset, then write back the instruction. */ - insn =atomic_read (code_ptr); -atomic_set (code_ptr,deposit32 (insn,0 ,26 , offset)); +if (offset ==sextract64 (offset,0 ,19 )) { + *code_ptr =deposit32 (*code_ptr,5 ,19 , offset); +return true; + } +return false; } -static inline void reloc_pc19 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) -{ -ptrdiff_t offset = target - code_ptr; -tcg_debug_assert (offset ==sextract64 (offset,0 ,19 )); - *code_ptr =deposit32 (*code_ptr,5 ,19 , offset); -} - -static inline void patch_reloc (tcg_insn_unit *code_ptr,int type, +static inline bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {tcg_debug_assert (addend ==0 );switch (type) {case R_AARCH64_JUMP26 :case R_AARCH64_CALL26 : -reloc_pc26 (code_ptr, (tcg_insn_unit *)value); -break ; +return reloc_pc26 (code_ptr, (tcg_insn_unit *)value);case R_AARCH64_CONDBR19 : -reloc_pc19 (code_ptr, (tcg_insn_unit *)value); -break ; +return reloc_pc19 (code_ptr, (tcg_insn_unit *)value);default : -tcg_abort (); +g_assert_not_reached (); } }tcg/arm/tcg-target.inc.c +12
-14@@ -187,27 +187,23 @@ static const uint8_t tcg_cond_to_arm_cond[] = { [TCG_COND_GTU] = COND_HI, }; -static inline void reloc_pc24 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) +static inline bool reloc_pc24 (tcg_insn_unit *code_ptr,tcg_insn_unit *target) {ptrdiff_t offset = (tcg_ptr_byte_diff (target, code_ptr) -8 ) >>2 ; - *code_ptr = (*code_ptr & ~0xffffff ) | (offset &0xffffff ); +if (offset ==sextract32 (offset,0 ,24 )) { + *code_ptr = (*code_ptr & ~0xffffff ) | (offset &0xffffff ); +return true; + } +return false; } -static inline void reloc_pc24_atomic (tcg_insn_unit *code_ptr,tcg_insn_unit *target) -{ -ptrdiff_t offset = (tcg_ptr_byte_diff (target, code_ptr) -8 ) >>2 ; -tcg_insn_unit insn =atomic_read (code_ptr); -tcg_debug_assert (offset ==sextract32 (offset,0 ,24 )); -atomic_set (code_ptr,deposit32 (insn,0 ,24 , offset)); -} - -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {tcg_debug_assert (addend ==0 );if (type ==R_ARM_PC24 ) { -reloc_pc24 (code_ptr, (tcg_insn_unit *)value); +return reloc_pc24 (code_ptr, (tcg_insn_unit *)value); }else if (type ==R_ARM_PC13 ) {intptr_t diff = value - (uintptr_t )(code_ptr +2 );tcg_insn_unit insn = *code_ptr;@@ -218,10 +214,9 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,if (!u) { diff = -diff; } - }else { + }else if (diff >=0x1000 && diff <0x100000 ) {int rd =extract32 (insn,12 ,4 );int rt = rd ==TCG_REG_PC ?TCG_REG_TMP : rd; -assert (diff >=0x1000 && diff <0x100000 );/* add rt, pc, #high */ *code_ptr++ = ((insn &0xf0000000 ) | (1 <<25 ) |ARITH_ADD | (TCG_REG_PC << 16) | (rt << 12)@@ -230,10 +225,13 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, insn =deposit32 (insn,12 ,4 , rt); diff &=0xfff ; u =1 ; + }else { +return false; } insn =deposit32 (insn,23 ,1 , u); insn =deposit32 (insn,0 ,12 , diff); *code_ptr = insn; +return true; }else {g_assert_not_reached (); }tcg/i386/tcg-target.inc.c +10
-7@@ -167,29 +167,32 @@ static bool have_lzcnt;static tcg_insn_unit *tb_ret_addr; -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) { value += addend; -switch (type) { + +switch (type) {case R_386_PC32 : value -= (uintptr_t )code_ptr;if (value != (int32_t )value) { -tcg_abort (); +return false; }/* FALLTHRU */ case R_386_32 :tcg_patch32 (code_ptr, value); -break ; +return true; +case R_386_PC8 : value -= (uintptr_t )code_ptr;if (value != (int8_t )value) { -tcg_abort (); +return false; }tcg_patch8 (code_ptr, value); -break ; +return true; +default : -tcg_abort (); +g_assert_not_reached (); } }tcg/mips/tcg-target.inc.c +0
-0
tcg/mips/tcg-target.inc.c static tcg_insn_unit *bswap32_addr; · line 147
Quoted 5 lines
tcg/mips/tcg-target.inc.c +1
-1@@ -144,36 +144,29 @@ static tcg_insn_unit *bswap32_addr;static tcg_insn_unit *bswap32u_addr;static tcg_insn_unit *bswap64_addr; -static inline uint32_t reloc_pc16_val (tcg_insn_unit *pc,tcg_insn_unit *target) +static bool reloc_pc16_cond (tcg_insn_unit *pc,tcg_insn_unit *target)
What is the cond here anyway? Given we pass through bellow with a function with the same signature it makes me wonder if there shouldn't just be one reloc_pc16 function.
Quoted 8 lines
tcg/mips/tcg-target.inc.c +3
-2{/* Let the compiler perform the right-shift as part of the arithmetic. */ ptrdiff_t disp = target - (pc +1 ); -tcg_debug_assert (disp == (int16_t )disp); -return disp &0xffff ; +if (disp == (int16_t )disp) { + *pc =deposit32 (*pc,0 ,16 , disp); +return true;
tcg/mips/tcg-target.inc.c static tcg_insn_unit *bswap32_addr; · line 161
Quoted 10 lines
tcg/mips/tcg-target.inc.c +5
-2+ }else { +return false; + } } -static inline void reloc_pc16 (tcg_insn_unit *pc,tcg_insn_unit *target) +static bool reloc_pc16 (tcg_insn_unit *pc,tcg_insn_unit *target) { - *pc =deposit32 (*pc,0 ,16 ,reloc_pc16_val (pc, target)); +tcg_debug_assert (reloc_pc16_cond (pc, target));
Having side effects in tcg_debug_assert seems like bad style, besides should we not be passing the result up to the caller?
In fact I think this breaks the shippable build anyway:
In file included from /root/src/github.com/stsquad/qemu/tcg/tcg.c:320:0:/root/src/github.com/stsquad/qemu/tcg/mips/tcg-target.inc.c: In function 'reloc_pc16':/root/src/github.com/stsquad/qemu/tcg/mips/tcg-target.inc.c:162:1: error: control reaches end of non-void function [-Werror=return-type]
}
Quoted 11 lines
tcg/mips/tcg-target.inc.c +0
-9} -static inline uint32_t reloc_26_val (tcg_insn_unit *pc,tcg_insn_unit *target) -{ -tcg_debug_assert ((((uintptr_t )pc ^ (uintptr_t )target) &0xf0000000 ) ==0 ); -return ((uintptr_t )target >>2 ) &0x3ffffff ; -} - -static inline void reloc_26 (tcg_insn_unit *pc,tcg_insn_unit *target) -{ - *pc =deposit32 (*pc,0 ,26 ,reloc_26_val (pc, target));
tcg/mips/tcg-target.inc.c static tcg_insn_unit *bswap32_addr; · line 169
Quoted 10 lines
tcg/mips/tcg-target.inc.c +2
-4-} - -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {tcg_debug_assert (type ==R_MIPS_PC16 );tcg_debug_assert (addend ==0 ); -reloc_pc16 (code_ptr, (tcg_insn_unit *)value); +return reloc_pc16_cond (code_ptr, (tcg_insn_unit *)value);
See above.
Quoted 39 lines
tcg/mips/tcg-target.inc.c +0
-0}#define TCG_CT_CONST_ZERO 0x100tcg/ppc/tcg-target.inc.c +11
-8@@ -186,16 +186,14 @@ static inline bool in_range_b(tcg_target_long target)return target ==sextract64 (target,0 ,26 ); } -static uint32_t reloc_pc24_val (tcg_insn_unit *pc,tcg_insn_unit *target) +static bool reloc_pc24_cond (tcg_insn_unit *pc,tcg_insn_unit *target) {ptrdiff_t disp =tcg_ptr_byte_diff (target, pc); -tcg_debug_assert (in_range_b (disp)); -return disp &0x3fffffc ; -} - -static void reloc_pc24 (tcg_insn_unit *pc,tcg_insn_unit *target) -{ - *pc = (*pc & ~0x3fffffc ) |reloc_pc24_val (pc, target); +if (in_range_b (disp)) { + *pc = (*pc & ~0x3fffffc ) | (disp &0x3fffffc ); +return true; + } +return false; }static uint16_t reloc_pc14_val (tcg_insn_unit *pc,tcg_insn_unit *target)@@ -205,10 +203,22 @@ static uint16_t reloc_pc14_val(tcg_insn_unit *pc, tcg_insn_unit *target)return disp &0xfffc ; } +static bool reloc_pc14_cond (tcg_insn_unit *pc,tcg_insn_unit *target) +{ +ptrdiff_t disp =tcg_ptr_byte_diff (target, pc); +if (disp == (int16_t ) disp) { + *pc = (*pc & ~0xfffc ) | (disp &0xfffc );
tcg/ppc/tcg-target.inc.c static uint16_t reloc_pc14_val(tcg_insn_unit *pc, tcg_insn_unit *target) · line 219
Quoted 10 lines
tcg/ppc/tcg-target.inc.c +7
-1+return true; + } +return false; +} + +#ifdef CONFIG_SOFTMMU static void reloc_pc14 (tcg_insn_unit *pc,tcg_insn_unit *target) { - *pc = (*pc & ~0xfffc ) |reloc_pc14_val (pc, target); +tcg_debug_assert (reloc_pc14_cond (pc, target));
Again side effects in assert.
Quoted 91 lines
tcg/ppc/tcg-target.inc.c +11
-9} +#endif static inline void tcg_out_b_noaddr (TCGContext *s,int insn) {@@ -525,7 +535,7 @@ static const uint32_t tcg_to_isel[] = { [TCG_COND_GTU] = ISEL | BC_(7, CR_GT), }; -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {tcg_insn_unit *target;@@ -536,11 +546,9 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,switch (type) {case R_PPC_REL14 : -reloc_pc14 (code_ptr, target); -break ; +return reloc_pc14_cond (code_ptr, target);case R_PPC_REL24 : -reloc_pc24 (code_ptr, target); -break ; +return reloc_pc24_cond (code_ptr, target);case R_PPC_ADDR16 :/* We are abusing this relocation type. This points to a pair of insns, addis + load. If the displacement is small, we @@ -552,11 +560,14 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, }else {int16_t lo = value;int hi = value - lo; -assert (hi + lo == value); - code_ptr[0 ] =deposit32 (code_ptr[0 ],0 ,16 , hi >>16 ); - code_ptr[1 ] =deposit32 (code_ptr[1 ],0 ,16 , lo); +if (hi + lo == value) { + code_ptr[0 ] =deposit32 (code_ptr[0 ],0 ,16 , hi >>16 ); + code_ptr[1 ] =deposit32 (code_ptr[1 ],0 ,16 , lo); + }else { +return false; + } } -break ; +return true;default :g_assert_not_reached (); }tcg/s390/tcg-target.inc.c +15
-9@@ -366,7 +366,7 @@ static void * const qemu_st_helpers[16] = {static tcg_insn_unit *tb_ret_addr;uint64_t s390_facilities; -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {intptr_t pcrel2;@@ -377,22 +377,35 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,switch (type) {case R_390_PC16DBL : -assert (pcrel2 == (int16_t )pcrel2); -tcg_patch16 (code_ptr, pcrel2); +if (pcrel2 == (int16_t )pcrel2) { +tcg_patch16 (code_ptr, pcrel2); +return true; + }break ;case R_390_PC32DBL : -assert (pcrel2 == (int32_t )pcrel2); -tcg_patch32 (code_ptr, pcrel2); +if (pcrel2 == (int32_t )pcrel2) { +tcg_patch32 (code_ptr, pcrel2); +return true; + }break ;case R_390_20 : -assert (value ==sextract64 (value,0 ,20 )); - old = *(uint32_t *)code_ptr &0xf00000ff ; - old |= ((value &0xfff ) <<16 ) | ((value &0xff000 ) >>4 ); -tcg_patch32 (code_ptr, old); +if (value ==sextract64 (value,0 ,20 )) { + old = *(uint32_t *)code_ptr &0xf00000ff ; + old |= ((value &0xfff ) <<16 ) | ((value &0xff000 ) >>4 ); +tcg_patch32 (code_ptr, old); +return true; + }break ;
tcg/s390/tcg-target.inc.c static void patch_reloc(tcg_insn_unit *code_ptr, int type, · line 408
Quoted 10 lines
tcg/s390/tcg-target.inc.c +7
-0default :g_assert_not_reached (); } +return false; +} + +static void patch_reloc_force (tcg_insn_unit *code_ptr,int type, +intptr_t value,intptr_t addend) +{ +tcg_debug_assert (patch_reloc (code_ptr, type, value, addend));
Side effect in assert.
Also as patch_reloc_force is only called for softmmu it needs a guard to stop the compiler complaining for a linux-user build:
In file included from /root/src/github.com/stsquad/qemu/tcg/tcg.c:320:0:/root/src/github.com/stsquad/qemu/tcg/s390/tcg-target.inc.c:405:13: error: 'patch_reloc_force' defined but not used [-Werror=unused-function]
static void patch_reloc_force(tcg_insn_unit *code_ptr, int type,
^~~~~~~~~~~~~~~~~
Quoted 151 lines
tcg/s390/tcg-target.inc.c +4
-2}/* parse target specific constraints */ @@ -1618,7 +1631,8 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)TCGMemOpIdx oi = lb->oi;TCGMemOp opc =get_memop (oi); -patch_reloc (lb->label_ptr[0 ],R_390_PC16DBL , (intptr_t )s->code_ptr,2 ); +patch_reloc_force (lb->label_ptr[0 ],R_390_PC16DBL , + (intptr_t )s->code_ptr,2 );tcg_out_mov (s,TCG_TYPE_PTR ,TCG_REG_R2 ,TCG_AREG0 );if (TARGET_LONG_BITS ==64 ) {@@ -1639,7 +1653,8 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)TCGMemOpIdx oi = lb->oi;TCGMemOp opc =get_memop (oi); -patch_reloc (lb->label_ptr[0 ],R_390_PC16DBL , (intptr_t )s->code_ptr,2 ); +patch_reloc_force (lb->label_ptr[0 ],R_390_PC16DBL , + (intptr_t )s->code_ptr,2 );tcg_out_mov (s,TCG_TYPE_PTR ,TCG_REG_R2 ,TCG_AREG0 );if (TARGET_LONG_BITS ==64 ) {tcg/sparc/tcg-target.inc.c +8
-5@@ -291,32 +291,34 @@ static inline int check_fit_i32(int32_t val, unsigned int bits)# define check_fit_ptr check_fit_i32#endif -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {uint32_t insn = *code_ptr;intptr_t pcrel; +bool ret; value += addend; pcrel =tcg_ptr_byte_diff ((tcg_insn_unit *)value, code_ptr);switch (type) {case R_SPARC_WDISP16 : -assert (check_fit_ptr (pcrel >>2 ,16 )); + ret =check_fit_ptr (pcrel >>2 ,16 ); insn &= ~INSN_OFF16 (-1 ); insn |=INSN_OFF16 (pcrel);break ;case R_SPARC_WDISP19 : -assert (check_fit_ptr (pcrel >>2 ,19 )); + ret =check_fit_ptr (pcrel >>2 ,19 ); insn &= ~INSN_OFF19 (-1 ); insn |=INSN_OFF19 (pcrel);break ;case R_SPARC_13 :/* Note that we're abusing this reloc type for our own needs. */ + ret = true;if (!check_fit_ptr (value,13 )) {int adj = (value >0 ?0xff8 :-0x1000 ); value -= adj; -assert (check_fit_ptr (value,13 )); + ret =check_fit_ptr (value,13 ); *code_ptr++ = (ARITH_ADD |INSN_RD (TCG_REG_T2 ) |INSN_RS1 (TCG_REG_TB ) |INSN_IMM13 (adj)); insn ^=INSN_RS1 (TCG_REG_TB ) ^INSN_RS1 (TCG_REG_T2 );@@ -328,12 +330,13 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,/* Note that we're abusing this reloc type for our own needs. */ code_ptr[0 ] =deposit32 (code_ptr[0 ],0 ,22 , value >>10 ); code_ptr[1 ] =deposit32 (code_ptr[1 ],0 ,10 , value); -return ; +return value == (intptr_t )(uint32_t )value;default :g_assert_not_reached (); } *code_ptr = insn; +return ret; }/* parse target specific constraints */ tcg/tcg-pool.inc.c +4
-1@@ -140,6 +140,8 @@ static bool tcg_out_pool_finalize(TCGContext *s)for (; p !=NULL ; p = p->next) {size_t size =sizeof (tcg_target_ulong) * p->nlong; +bool ok; +if (!l || l->nlong != p->nlong ||memcmp (l->data, p->data, size)) {if (unlikely (a > s->code_gen_highwater)) {return false;@@ -148,7 +150,8 @@ static bool tcg_out_pool_finalize(TCGContext *s) a += size; l = p; } -patch_reloc (p->label, p->rtype, (intptr_t )a - size, p->addend); + ok =patch_reloc (p->label, p->rtype, (intptr_t )a - size, p->addend); +tcg_debug_assert (ok); } s->code_ptr = a;tcg/tcg.c +5
-3@@ -66,7 +66,7 @@static void tcg_target_init (TCGContext *s);static const TCGTargetOpDef *tcg_target_op_def (TCGOpcode );static void tcg_target_qemu_prologue (TCGContext *s); -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend);/* The CIE and FDE header definitions will be common to all hosts. */ @@ -268,7 +268,8 @@ static void tcg_out_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,/* FIXME: This may break relocations on RISC targets that modify instruction fields in place. The caller may not have written the initial value. */ -patch_reloc (code_ptr, type, l->u.value, addend); +bool ok =patch_reloc (code_ptr, type, l->u.value, addend); +tcg_debug_assert (ok); }else {/* add a new relocation entry */ r =tcg_malloc (sizeof (TCGRelocation));@@ -288,7 +289,8 @@ static void tcg_out_label(TCGContext *s, TCGLabel *l, tcg_insn_unit *ptr)tcg_debug_assert (!l->has_value);for (r = l->u.first_reloc; r !=NULL ; r = r->next) { -patch_reloc (r->ptr, r->type, value, r->addend); +bool ok =patch_reloc (r->ptr, r->type, value, r->addend); +tcg_debug_assert (ok); } l->has_value =1 ;tcg/tci/tcg-target.inc.c +1
-1@@ -369,7 +369,7 @@ static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { };#endif -static void patch_reloc (tcg_insn_unit *code_ptr,int type, +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {/* tcg_out_reloc always uses the same type, addend. */
tcg/tci/tcg-target.inc.c static void patch_reloc(tcg_insn_unit *code_ptr, int type, · line 387
Quoted 7 lines
tcg/tci/tcg-target.inc.c +1
-0@@ -381,6 +381,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, }else {tcg_patch64 (code_ptr, value); } +return true; }/* Parse target specific constraints. */
--
Alex Bennée
Re: [Qemu-devel] [PATCH for-4.0 v2 03/37] tcg: Return success from patch_reloc
Quoted 3 lines · Alex Bennée
We also seem to be dropping a bunch of
reloc_atomicfunctions (which are no longer used?). Perhaps that should be a separate patch to make the series cleaner?
Yes, they're no longer used.
I should do a full cleanup of "atomic" stuff that's no longer required due to the fact that we no longer re-translate for unwinding.
r~
PATCH v2 4/37 tcg: Add TCG_TARGET_NEED_LDST_OOL_LABELS
In reply to Richard HendersonThis variant of tcg-ldst.inc.c allows the entire thunk to be moved out-of-line, with caching across TBs within a region.
--- tcg/tcg.h | 5 +++ accel/tcg/translate-all.c | 15 +++++-- tcg/tcg-ldst-ool.inc.c | 95 +++++++++++++++++++++++++++++++++++++++ tcg/tcg.c | 28 ++++++++++++ 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 tcg/tcg-ldst-ool.inc.c
tcg/tcg.h +5 -0
@@ -706,6 +706,11 @@ struct TCGContext {#ifdef TCG_TARGET_NEED_LDST_LABELS QSIMPLEQ_HEAD(ldst_labels, TCGLabelQemuLdst) ldst_labels;#endif +#ifdef TCG_TARGET_NEED_LDST_OOL_LABELS + QSIMPLEQ_HEAD(ldst_labels, TCGLabelQemuLdstOol) ldst_ool_labels; +GHashTable *ldst_ool_thunks; +size_t ldst_ool_generation; +#endif #ifdef TCG_TARGET_NEED_POOL_LABELS struct TCGLabelPoolData *pool_labels;#endif
accel/tcg/translate-all.c +12 -3
@@ -1678,6 +1678,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu,target_ulong virt_page2;tcg_insn_unit *gen_code_buf;int gen_code_size, search_size; +#ifdef TCG_TARGET_NEED_LDST_OOL_LABELS +size_t ldst_ool_generation = tcg_ctx->ldst_ool_generation; +#endif #ifdef CONFIG_PROFILER TCGProfile *prof = &tcg_ctx->prof;int64_t ti;
@@ -1831,10 +1834,16 @@ TranslationBlock *tb_gen_code(CPUState *cpu, existing_tb =tb_link_page (tb, phys_pc, phys_page2);/* if the TB already exists, discard what we just translated */ if (unlikely (existing_tb != tb)) { -uintptr_t orig_aligned = (uintptr_t )gen_code_buf; +bool discard = true; - orig_aligned -=ROUND_UP (sizeof (*tb), qemu_icache_linesize); -atomic_set (&tcg_ctx->code_gen_ptr, (void *)orig_aligned); +#ifdef TCG_TARGET_NEED_LDST_OOL_LABELS + discard = ldst_ool_generation == tcg_ctx->ldst_ool_generation; +#endif +if (discard) { +uintptr_t orig_aligned = (uintptr_t )gen_code_buf; + orig_aligned -=ROUND_UP (sizeof (*tb), qemu_icache_linesize); +atomic_set (&tcg_ctx->code_gen_ptr, (void *)orig_aligned); + }return existing_tb; }tcg_tb_insert (tb);
tcg/tcg-ldst-ool.inc.c new file +95 -0
95 lines not on this page · raw message
tcg/tcg.c +28 -0
@@ -521,6 +521,13 @@ static void tcg_region_assign(TCGContext *s, size_t curr_region) s->code_gen_ptr = start; s->code_gen_buffer_size = end - start; s->code_gen_highwater = end -TCG_HIGHWATER ; + +#ifdef TCG_TARGET_NEED_LDST_OOL_LABELS +/* No thunks yet generated this region. Even if they were in range, +this is also the most convenient place to clear the table after a +full tb_flush. */ +g_hash_table_remove_all (s->ldst_ool_thunks); +#endif }static bool tcg_region_alloc__locked (TCGContext *s)
@@ -756,6 +763,14 @@ void tcg_register_thread(void) err =tcg_region_initial_alloc__locked (tcg_ctx);g_assert (!err);qemu_mutex_unlock (®ion.lock); + +#ifdef TCG_TARGET_NEED_LDST_OOL_LABELS +/* If n == 0, keep the hash table we allocated in tcg_context_init. */ +if (n) { +/* Both key and value are raw pointers. */ + s->ldst_ool_thunks =g_hash_table_new (NULL ,NULL ); + } +#endif }#endif /* !CONFIG_USER_ONLY */
@@ -964,6 +979,11 @@ void tcg_context_init(TCGContext *s)tcg_debug_assert (!tcg_regset_test_reg (s->reserved_regs,TCG_AREG0 )); ts =tcg_global_reg_new_internal (s,TCG_TYPE_PTR ,TCG_AREG0 ,"env" ); cpu_env =temp_tcgv_ptr (ts); + +#ifdef TCG_TARGET_NEED_LDST_OOL_LABELS +/* Both key and value are raw pointers. */ + s->ldst_ool_thunks =g_hash_table_new (NULL ,NULL ); +#endif }/*
@@ -3540,6 +3560,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)#ifdef TCG_TARGET_NEED_LDST_LABELS QSIMPLEQ_INIT (&s->ldst_labels);#endif +#ifdef TCG_TARGET_NEED_LDST_OOL_LABELS +QSIMPLEQ_INIT (&s->ldst_ool_labels); +#endif #ifdef TCG_TARGET_NEED_POOL_LABELS s->pool_labels =NULL ;#endif
@@ -3620,6 +3643,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)return -1 ; }#endif +#ifdef TCG_TARGET_NEED_LDST_OOL_LABELS +if (!tcg_out_ldst_ool_finalize (s)) { +return -1 ; + } +#endif #ifdef TCG_TARGET_NEED_POOL_LABELS if (!tcg_out_pool_finalize (s)) {return -1 ;
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 04/37] tcg: Add TCG_TARGET_NEED_LDST_OOL_LABELS
Quoted 5 lines · Richard Henderson
This variant of
tcg-ldst.inc.callows the entire thunk to be moved out-of-line, with caching across TBs within a region.Signed-off-by Richard Henderson <[email protected]>---
(snip)
Quoted 1 line
+++
b/tcg/tcg-ldst-ool.inc.c
(snip)
tcg/tcg-ldst-ool.inc.c line 29
Quoted 7 lines
tcg/tcg-ldst-ool.inc.c new file +7
-0+typedef struct TCGLabelQemuLdstOol { +QSIMPLEQ_ENTRY (TCGLabelQemuLdstOol) next; +tcg_insn_unit *label;/* label pointer to be updated */ +int reloc;/* relocation type from label_ptr */ +intptr_t addend;/* relocation addend from label_ptr */ +uint32_t key;/* oi : is_64 : is_ld */ +}TCGLabelQemuLdstOol ;
Just a tiny nit, here we can move reloc down to plug a hole.
Emilio
PATCH v2 5/37 tcg/i386: Add constraints for r8 and r9
In reply to Richard HendersonThese are function call arguments for x86_64 we will need soon.
--- tcg/i386/tcg-target.inc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tcg/i386/tcg-target.inc.c +8 -0
@@ -233,6 +233,14 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, ct->ct |=TCG_CT_REG ;tcg_regset_set_reg (ct->u.regs,TCG_REG_EDI );break ; +case 'E' :/* "Eight", r8 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_R8 ); +break ; +case 'N' :/* "Nine", r9 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_R9 ); +break ;case 'q' :/* A register that can be used as a byte operand. */ ct->ct |=TCG_CT_REG ;
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 05/37] tcg/i386: Add constraints for r8 and r9
Quoted 13 lines · Richard Henderson
These are function call arguments for
x86_64we will need soon.Signed-off-by Richard Henderson <[email protected]>--- tcg/i386/tcg-target.inc.c | 8 ++++++++ 1 file changed, 8 insertions(+)tcg/i386/tcg-target.inc.c +0
-0@@ -233,6 +233,14 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, ct->ct |=TCG_CT_REG ;
tcg/i386/tcg-target.inc.c static const char *target_parse_constraint(TCGArgConstraint *ct, · line 243
Quoted 10 lines
tcg/i386/tcg-target.inc.c +8
-0tcg_regset_set_reg (ct->u.regs,TCG_REG_EDI );break ; +case 'E' :/* "Eight", r8 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_R8 ); +break ; +case 'N' :/* "Nine", r9 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_R9 ); +break ;
I would be nice to flesh out the missing comments in tcg.h:
#define TCG_CT_ALIAS 0x80
#define TCG_CT_IALIAS 0x40
#define TCG_CT_NEWREG 0x20 /* output requires a new register */
#define TCG_CT_REG 0x01
#define TCG_CT_CONST 0x02 /* any constant of register size */
Anyway:
tcg/i386/tcg-target.inc.c static const char *target_parse_constraint(TCGArgConstraint *ct, · line 246
Quoted 3 lines
tcg/i386/tcg-target.inc.c +0
-0case 'q' :/* A register that can be used as a byte operand. */ ct->ct |=TCG_CT_REG ;
--
Alex Bennée
PATCH v2 6/37 tcg/i386: Return a base register from tcg_out_tlb_load
In reply to Richard HendersonWe will shortly be asking the hot path not to assume TCG_REG_L1 for the host base address.
--- tcg/i386/tcg-target.inc.c | 56 ++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-)
tcg/i386/tcg-target.inc.c +29 -27
@@ -1614,9 +1614,9 @@ static void * const qemu_st_helpers[16] = {First argument register is clobbered. */ -static inline void tcg_out_tlb_load (TCGContext *s,TCGReg addrlo,TCGReg addrhi, -int mem_index,TCGMemOp opc, -tcg_insn_unit **label_ptr,int which) +static TCGReg tcg_out_tlb_load (TCGContext *s,TCGReg addrlo,TCGReg addrhi, +int mem_index,TCGMemOp opc, +tcg_insn_unit **label_ptr,int which) {const TCGReg r0 =TCG_REG_L0 ;const TCGReg r1 =TCG_REG_L1 ;
@@ -1696,6 +1696,8 @@ static inline void tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,/* add addend(r0), r1 */ tcg_out_modrm_offset (s, OPC_ADD_GvEv + hrexw, r1, r0, offsetof(CPUTLBEntry , addend) - which); + +return r1; }/*
@@ -2001,10 +2003,6 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) TCGReg addrhi __attribute__((unused));TCGMemOpIdx oi;TCGMemOp opc; -#if defined(CONFIG_SOFTMMU ) -int mem_index; -tcg_insn_unit *label_ptr[2 ]; -#endif datalo = *args++; datahi = (TCG_TARGET_REG_BITS ==32 && is64 ? *args++ :0 );
@@ -2014,17 +2012,21 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) opc =get_memop (oi);#if defined(CONFIG_SOFTMMU ) - mem_index =get_mmuidx (oi); + { +int mem_index =get_mmuidx (oi); +tcg_insn_unit *label_ptr[2 ]; +TCGReg base; -tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, - label_ptr, offsetof(CPUTLBEntry , addr_read)); + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, + label_ptr, offsetof(CPUTLBEntry , addr_read)); -/* TLB Hit. */ -tcg_out_qemu_ld_direct (s, datalo, datahi,TCG_REG_L1 ,-1 ,0 ,0 , opc); +/* TLB Hit. */ +tcg_out_qemu_ld_direct (s, datalo, datahi, base,-1 ,0 ,0 , opc); -/* Record the current context of a load into ldst label */ -add_qemu_ldst_label (s, true, oi, datalo, datahi, addrlo, addrhi, - s->code_ptr, label_ptr); +/* Record the current context of a load into ldst label */ +add_qemu_ldst_label (s, true, oi, datalo, datahi, addrlo, addrhi, + s->code_ptr, label_ptr); + }#else {int32_t offset = guest_base;
@@ -2141,10 +2143,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) TCGReg addrhi __attribute__((unused));TCGMemOpIdx oi;TCGMemOp opc; -#if defined(CONFIG_SOFTMMU ) -int mem_index; -tcg_insn_unit *label_ptr[2 ]; -#endif datalo = *args++; datahi = (TCG_TARGET_REG_BITS ==32 && is64 ? *args++ :0 );
@@ -2154,17 +2152,21 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) opc =get_memop (oi);#if defined(CONFIG_SOFTMMU ) - mem_index =get_mmuidx (oi); + { +int mem_index =get_mmuidx (oi); +tcg_insn_unit *label_ptr[2 ]; +TCGReg base; -tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, - label_ptr, offsetof(CPUTLBEntry , addr_write)); + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, + label_ptr, offsetof(CPUTLBEntry , addr_write)); -/* TLB Hit. */ -tcg_out_qemu_st_direct (s, datalo, datahi,TCG_REG_L1 ,0 ,0 , opc); +/* TLB Hit. */ +tcg_out_qemu_st_direct (s, datalo, datahi, base,0 ,0 , opc); -/* Record the current context of a store into ldst label */ -add_qemu_ldst_label (s, false, oi, datalo, datahi, addrlo, addrhi, - s->code_ptr, label_ptr); +/* Record the current context of a store into ldst label */ +add_qemu_ldst_label (s, false, oi, datalo, datahi, addrlo, addrhi, + s->code_ptr, label_ptr); + }#else {int32_t offset = guest_base;
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 06/37] tcg/i386: Return a base register from tcg_out_tlb_load
Quoted 4 lines · Richard Henderson
We will shortly be asking the hot path not to assume
TCG_REG_L1for the host base address.Signed-off-by Richard Henderson <[email protected]>
Quoted 102 lines
--- tcg/i386/tcg-target.inc.c | 56 ++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-)tcg/i386/tcg-target.inc.c +25
-24@@ -1614,9 +1614,9 @@ static void * const qemu_st_helpers[16] = {First argument register is clobbered. */ -static inline void tcg_out_tlb_load (TCGContext *s,TCGReg addrlo,TCGReg addrhi, -int mem_index,TCGMemOp opc, -tcg_insn_unit **label_ptr,int which) +static TCGReg tcg_out_tlb_load (TCGContext *s,TCGReg addrlo,TCGReg addrhi, +int mem_index,TCGMemOp opc, +tcg_insn_unit **label_ptr,int which) {const TCGReg r0 =TCG_REG_L0 ;const TCGReg r1 =TCG_REG_L1 ;@@ -1696,6 +1696,8 @@ static inline void tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,/* add addend(r0), r1 */ tcg_out_modrm_offset (s, OPC_ADD_GvEv + hrexw, r1, r0, offsetof(CPUTLBEntry , addend) - which); + +return r1; }/* @@ -2001,10 +2003,6 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) TCGReg addrhi __attribute__((unused));TCGMemOpIdx oi;TCGMemOp opc; -#if defined(CONFIG_SOFTMMU ) -int mem_index; -tcg_insn_unit *label_ptr[2 ]; -#endif datalo = *args++; datahi = (TCG_TARGET_REG_BITS ==32 && is64 ? *args++ :0 );@@ -2014,17 +2012,21 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) opc =get_memop (oi);#if defined(CONFIG_SOFTMMU ) - mem_index =get_mmuidx (oi); + { +int mem_index =get_mmuidx (oi); +tcg_insn_unit *label_ptr[2 ]; +TCGReg base; -tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, - label_ptr, offsetof(CPUTLBEntry , addr_read)); + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, + label_ptr, offsetof(CPUTLBEntry , addr_read)); -/* TLB Hit. */ -tcg_out_qemu_ld_direct (s, datalo, datahi,TCG_REG_L1 ,-1 ,0 ,0 , opc); +/* TLB Hit. */ +tcg_out_qemu_ld_direct (s, datalo, datahi, base,-1 ,0 ,0 , opc); -/* Record the current context of a load into ldst label */ -add_qemu_ldst_label (s, true, oi, datalo, datahi, addrlo, addrhi, - s->code_ptr, label_ptr); +/* Record the current context of a load into ldst label */ +add_qemu_ldst_label (s, true, oi, datalo, datahi, addrlo, addrhi, + s->code_ptr, label_ptr); + }#else {int32_t offset = guest_base;@@ -2141,10 +2143,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) TCGReg addrhi __attribute__((unused));TCGMemOpIdx oi;TCGMemOp opc; -#if defined(CONFIG_SOFTMMU ) -int mem_index; -tcg_insn_unit *label_ptr[2 ]; -#endif datalo = *args++; datahi = (TCG_TARGET_REG_BITS ==32 && is64 ? *args++ :0 );@@ -2154,17 +2152,21 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) opc =get_memop (oi);#if defined(CONFIG_SOFTMMU ) - mem_index =get_mmuidx (oi); + { +int mem_index =get_mmuidx (oi); +tcg_insn_unit *label_ptr[2 ]; +TCGReg base; -tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, - label_ptr, offsetof(CPUTLBEntry , addr_write)); + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, + label_ptr, offsetof(CPUTLBEntry , addr_write)); -/* TLB Hit. */ -tcg_out_qemu_st_direct (s, datalo, datahi,TCG_REG_L1 ,0 ,0 , opc); +/* TLB Hit. */ +tcg_out_qemu_st_direct (s, datalo, datahi, base,0 ,0 , opc);
tcg/i386/tcg-target.inc.c static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) · line 2172
Quoted 10 lines
tcg/i386/tcg-target.inc.c +4
-3-/* Record the current context of a store into ldst label */ -add_qemu_ldst_label (s, false, oi, datalo, datahi, addrlo, addrhi, - s->code_ptr, label_ptr); +/* Record the current context of a store into ldst label */ +add_qemu_ldst_label (s, false, oi, datalo, datahi, addrlo, addrhi, + s->code_ptr, label_ptr); + }#else {int32_t offset = guest_base;
--
Alex Bennée
PATCH v2 7/37 tcg/i386: Change TCG_REG_L[01] to not overlap function arguments
In reply to Richard HendersonWe will shortly be forcing qemu_ld/st arguments into registers that match the function call abi of the host, which means that the temps must be elsewhere.
--- tcg/i386/tcg-target.inc.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
tcg/i386/tcg-target.inc.c +19 -9
@@ -121,12 +121,16 @@ static const int tcg_target_call_oarg_regs[] = {#define TCG_CT_CONST_I32 0x400#define TCG_CT_CONST_WSZ 0x800 -/* Registers used with L constraint, which are the first argument -registers on x86_64, and two random call clobbered registers on -i386. */ +/* Registers used with L constraint, which are two random +* call clobbered registers. These should be free. +*/ #if TCG_TARGET_REG_BITS ==64 -# define TCG_REG_L0 tcg_target_call_iarg_regs[0] -# define TCG_REG_L1 tcg_target_call_iarg_regs[1] +# define TCG_REG_L0 TCG_REG_RAX +# ifdef _WIN64 +# define TCG_REG_L1 TCG_REG_R10 +# else +# define TCG_REG_L1 TCG_REG_RDI +# endif #else # define TCG_REG_L0 TCG_REG_EAX# define TCG_REG_L1 TCG_REG_EDX
@@ -1628,6 +1632,7 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,unsigned a_mask = (1 << a_bits) -1 ;unsigned s_mask = (1 << s_bits) -1 ;target_ulong tlb_mask; +TCGReg base;if (TCG_TARGET_REG_BITS ==64 ) {if (TARGET_LONG_BITS ==64 ) {
@@ -1674,7 +1679,12 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,before the fastpath ADDQ below. For 64-bit guest and x32 host, MOVQ copies the entire guest address for the slow path, while truncation for the 32-bit host happens with the fastpath ADDL below. */ -tcg_out_mov (s, ttype, r1, addrlo); +if (TCG_TARGET_REG_BITS ==64 ) { + base = tcg_target_call_iarg_regs[1 ]; + }else { + base = r1; + } +tcg_out_mov (s, ttype, base, addrlo);/* jne slow_path */ tcg_out_opc (s, OPC_JCC_long +JCC_JNE ,0 ,0 ,0 );
@@ -1693,11 +1703,11 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,/* TLB Hit. */ -/* add addend(r0), r1 */ -tcg_out_modrm_offset (s, OPC_ADD_GvEv + hrexw, r1, r0, +/* add addend(r0), base */ +tcg_out_modrm_offset (s, OPC_ADD_GvEv + hrexw, base, r0, offsetof(CPUTLBEntry , addend) - which); -return r1; +return base; }/*
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 07/37] tcg/i386: Change TCG_REG_L[01] to not overlap function arguments
Quoted 14 lines · Richard Henderson
We will shortly be forcing qemu_ld/st arguments into registers that match the function call abi of the host, which means that the temps must be elsewhere.
Signed-off-by Richard Henderson <[email protected]>--- tcg/i386/tcg-target.inc.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)tcg/i386/tcg-target.inc.c +0
-0
tcg/i386/tcg-target.inc.c static const int tcg_target_call_oarg_regs[] = { · line 126
Quoted 9 lines
tcg/i386/tcg-target.inc.c +3
-3@@ -121,12 +121,16 @@ static const int tcg_target_call_oarg_regs[] = {#define TCG_CT_CONST_I32 0x400#define TCG_CT_CONST_WSZ 0x800 -/* Registers used with L constraint, which are the first argument -registers on x86_64, and two random call clobbered registers on -i386. */ +/* Registers used with L constraint, which are two random +* call clobbered registers. These should be free. +*/
"These should be free by the time we have committed to making a procedure call and won't be needed afterwards."?
tcg/i386/tcg-target.inc.c static const int tcg_target_call_oarg_regs[] = { · line 129
Quoted 3 lines
tcg/i386/tcg-target.inc.c +0
-2#if TCG_TARGET_REG_BITS ==64 -# define TCG_REG_L0 tcg_target_call_iarg_regs[0] -# define TCG_REG_L1 tcg_target_call_iarg_regs[1]
I guess we don't need this type of assignment enough to have a tcg_target_call_clobber_regs array we can fill from?
/me digs deeper
ahh I see we have tcg_target_call_clobber_regs but that's a bitmap for use by the register allocator... never mind.
Quoted 36 lines
tcg/i386/tcg-target.inc.c +13
-2+# define TCG_REG_L0 TCG_REG_RAX +# ifdef _WIN64 +# define TCG_REG_L1 TCG_REG_R10 +# else +# define TCG_REG_L1 TCG_REG_RDI +# endif #else # define TCG_REG_L0 TCG_REG_EAX# define TCG_REG_L1 TCG_REG_EDX@@ -1628,6 +1632,7 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,unsigned a_mask = (1 << a_bits) -1 ;unsigned s_mask = (1 << s_bits) -1 ;target_ulong tlb_mask; +TCGReg base;if (TCG_TARGET_REG_BITS ==64 ) {if (TARGET_LONG_BITS ==64 ) {@@ -1674,7 +1679,12 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,before the fastpath ADDQ below. For 64-bit guest and x32 host, MOVQ copies the entire guest address for the slow path, while truncation for the 32-bit host happens with the fastpath ADDL below. */ -tcg_out_mov (s, ttype, r1, addrlo); +if (TCG_TARGET_REG_BITS ==64 ) { + base = tcg_target_call_iarg_regs[1 ]; + }else { + base = r1; + } +tcg_out_mov (s, ttype, base, addrlo);/* jne slow_path */ tcg_out_opc (s, OPC_JCC_long +JCC_JNE ,0 ,0 ,0 );@@ -1693,11 +1703,11 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,/* TLB Hit. */ -/* add addend(r0), r1 */
tcg/i386/tcg-target.inc.c static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi, · line 1713
Quoted 10 lines
tcg/i386/tcg-target.inc.c +3
-2-tcg_out_modrm_offset (s, OPC_ADD_GvEv + hrexw, r1, r0, +/* add addend(r0), base */ +tcg_out_modrm_offset (s, OPC_ADD_GvEv + hrexw, base, r0, offsetof(CPUTLBEntry , addend) - which); -return r1; +return base; }/*
Anyway:
--
Alex Bennée
PATCH v2 8/37 tcg/i386: Force qemu_ld/st arguments into fixed registers
In reply to Richard HendersonThis is an incremental step toward moving the qemu_ld/st code sequence out of line.
--- tcg/i386/tcg-target.inc.c | 203 +++++++++++++++++++++++++++++++------- 1 file changed, 169 insertions(+), 34 deletions(-)
tcg/i386/tcg-target.inc.c +169 -34
@@ -171,6 +171,80 @@ static bool have_lzcnt;static tcg_insn_unit *tb_ret_addr; +typedef enum { +ARG_ADDR , +ARG_STVAL , +ARG_LDVAL , +}QemuMemArgType ; + +#ifdef CONFIG_SOFTMMU +/* +* Constraint to choose a particular register. This is used for softmmu +* loads and stores. Registers with no assignment get an empty string. +*/ +static const char *const one_reg_constraint[TCG_TARGET_NB_REGS ] = { + [TCG_REG_EAX ] ="a" , + [TCG_REG_EBX ] ="b" , + [TCG_REG_ECX ] ="c" , + [TCG_REG_EDX ] ="d" , + [TCG_REG_ESI ] ="S" , + [TCG_REG_EDI ] ="D" , +#if TCG_TARGET_REG_BITS == 64 + [TCG_REG_R8 ] ="E" , + [TCG_REG_R9 ] ="N" , +#endif +}; + +/* +* Calling convention for the softmmu load and store thunks. +* +* For 64-bit, we mostly use the host calling convention, therefore the +* real first argument is reserved for the ENV parameter that is passed +* on to the slow path helpers. +* +* For 32-bit, the host calling convention is stack based; we invent a +* private convention that uses 4 of the 6 available host registers. +* We reserve EAX and EDX as temporaries for use by the thunk, we require +* INDEX_op_qemu_st_i32 to have a 'q' register from which to store, and +* further complicate this last by wanting a call-clobbered for that store. +* The 'q' requirement allows MO_8 stores at all; the call-clobbered part +* allows bswap to operate in-place, clobbering the input. +*/ +static TCGReg softmmu_arg (QemuMemArgType type,bool is_64,int hi) +{ +switch (type) { +case ARG_ADDR : +tcg_debug_assert (!hi ||TARGET_LONG_BITS >TCG_TARGET_REG_BITS ); +if (TCG_TARGET_REG_BITS ==64 ) { +return tcg_target_call_iarg_regs[1 ]; + }else { +return hi ?TCG_REG_EDI :TCG_REG_ESI ; + } +case ARG_STVAL : +tcg_debug_assert (!hi || (TCG_TARGET_REG_BITS ==32 && is_64)); +if (TCG_TARGET_REG_BITS ==64 ) { +return tcg_target_call_iarg_regs[2 ]; + }else { +return hi ?TCG_REG_EBX :TCG_REG_ECX ; + } +case ARG_LDVAL : +tcg_debug_assert (!hi || (TCG_TARGET_REG_BITS ==32 && is_64)); +return tcg_target_call_oarg_regs[hi]; + } +g_assert_not_reached (); +} + +static const char *constrain_memop_arg (QemuMemArgType type,bool is_64,int hi) +{ +return one_reg_constraint[softmmu_arg (type, is_64, hi)]; +} +#else +static const char *constrain_memop_arg (QemuMemArgType type,bool is_64,int hi) +{ +return "L" ; +} +#endif /* CONFIG_SOFTMMU */ +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {
@@ -1680,11 +1754,15 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,copies the entire guest address for the slow path, while truncation for the 32-bit host happens with the fastpath ADDL below. */ if (TCG_TARGET_REG_BITS ==64 ) { - base = tcg_target_call_iarg_regs[1 ]; +tcg_debug_assert (addrlo == tcg_target_call_iarg_regs[1 ]); +if (TARGET_LONG_BITS ==32 ) { +tcg_out_ext32u (s, addrlo, addrlo); + } + base = addrlo; }else { base = r1; +tcg_out_mov (s, ttype, base, addrlo); } -tcg_out_mov (s, ttype, base, addrlo);/* jne slow_path */ tcg_out_opc (s, OPC_JCC_long +JCC_JNE ,0 ,0 ,0 );
@@ -2009,16 +2087,22 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi,common. */ static void tcg_out_qemu_ld (TCGContext *s,const TCGArg *args,bool is64) { -TCGReg datalo, datahi, addrlo; - TCGReg addrhi __attribute__((unused)); +TCGReg datalo, addrlo; + TCGReg datahi __attribute__((unused)) = -1; + TCGReg addrhi __attribute__((unused)) = -1;TCGMemOpIdx oi;TCGMemOp opc; +int i =-1 ; - datalo = *args++; - datahi = (TCG_TARGET_REG_BITS ==32 && is64 ? *args++ :0 ); - addrlo = *args++; - addrhi = (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ? *args++ :0 ); - oi = *args++; + datalo = args[++i]; +if (TCG_TARGET_REG_BITS ==32 && is64) { + datahi = args[++i]; + } + addrlo = args[++i]; +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { + addrhi = args[++i]; + } + oi = args[++i]; opc =get_memop (oi);#if defined(CONFIG_SOFTMMU )
@@ -2027,6 +2111,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)tcg_insn_unit *label_ptr[2 ];TCGReg base; +tcg_debug_assert (datalo ==softmmu_arg (ARG_LDVAL , is64,0 )); +if (TCG_TARGET_REG_BITS ==32 && is64) { +tcg_debug_assert (datahi ==softmmu_arg (ARG_LDVAL , is64,1 )); + } +tcg_debug_assert (addrlo ==softmmu_arg (ARG_ADDR ,0 ,0 )); +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { +tcg_debug_assert (addrhi ==softmmu_arg (ARG_ADDR ,0 ,1 )); + } + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, label_ptr, offsetof(CPUTLBEntry , addr_read));
@@ -2149,16 +2242,22 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg datalo, TCGReg datahi,static void tcg_out_qemu_st (TCGContext *s,const TCGArg *args,bool is64) { -TCGReg datalo, datahi, addrlo; - TCGReg addrhi __attribute__((unused)); +TCGReg datalo, addrlo; + TCGReg datahi __attribute__((unused)) = -1; + TCGReg addrhi __attribute__((unused)) = -1;TCGMemOpIdx oi;TCGMemOp opc; +int i =-1 ; - datalo = *args++; - datahi = (TCG_TARGET_REG_BITS ==32 && is64 ? *args++ :0 ); - addrlo = *args++; - addrhi = (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ? *args++ :0 ); - oi = *args++; + datalo = args[++i]; +if (TCG_TARGET_REG_BITS ==32 && is64) { + datahi = args[++i]; + } + addrlo = args[++i]; +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { + addrhi = args[++i]; + } + oi = args[++i]; opc =get_memop (oi);#if defined(CONFIG_SOFTMMU )
@@ -2167,6 +2266,15 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)tcg_insn_unit *label_ptr[2 ];TCGReg base; +tcg_debug_assert (datalo ==softmmu_arg (ARG_STVAL , is64,0 )); +if (TCG_TARGET_REG_BITS ==32 && is64) { +tcg_debug_assert (datahi ==softmmu_arg (ARG_STVAL , is64,1 )); + } +tcg_debug_assert (addrlo ==softmmu_arg (ARG_ADDR ,0 ,0 )); +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { +tcg_debug_assert (addrhi ==softmmu_arg (ARG_ADDR ,0 ,1 )); + } + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, label_ptr, offsetof(CPUTLBEntry , addr_write));
@@ -2836,15 +2944,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op)static const TCGTargetOpDef r_r_re = { .args_ct_str = {"r" ,"r" ,"re" } };static const TCGTargetOpDef r_0_re = { .args_ct_str = {"r" ,"0" ,"re" } };static const TCGTargetOpDef r_0_ci = { .args_ct_str = {"r" ,"0" ,"ci" } }; -static const TCGTargetOpDef r_L = { .args_ct_str = {"r" ,"L" } }; -static const TCGTargetOpDef L_L = { .args_ct_str = {"L" ,"L" } }; -static const TCGTargetOpDef r_L_L = { .args_ct_str = {"r" ,"L" ,"L" } }; -static const TCGTargetOpDef r_r_L = { .args_ct_str = {"r" ,"r" ,"L" } }; -static const TCGTargetOpDef L_L_L = { .args_ct_str = {"L" ,"L" ,"L" } }; -static const TCGTargetOpDef r_r_L_L - = { .args_ct_str = {"r" ,"r" ,"L" ,"L" } }; -static const TCGTargetOpDef L_L_L_L - = { .args_ct_str = {"L" ,"L" ,"L" ,"L" } };static const TCGTargetOpDef x_x = { .args_ct_str = {"x" ,"x" } };static const TCGTargetOpDef x_x_x = { .args_ct_str = {"x" ,"x" ,"x" } };static const TCGTargetOpDef x_x_x_x
@@ -3026,17 +3125,53 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) }case INDEX_op_qemu_ld_i32: -return TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &r_L : &r_L_L; -case INDEX_op_qemu_st_i32: -return TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &L_L : &L_L_L ; + { +static TCGTargetOpDef ld32; +int i; + + ld32.args_ct_str[0 ] =constrain_memop_arg (ARG_LDVAL ,0 ,0 ); +for (i =0 ; i *TCG_TARGET_REG_BITS <TARGET_LONG_BITS ; ++i) { + ld32.args_ct_str[i +1 ] =constrain_memop_arg (ARG_ADDR ,0 , i); + } +return &ld32; + }case INDEX_op_qemu_ld_i64: -return (TCG_TARGET_REG_BITS ==64 ? &r_L - :TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &r_r_L - : &r_r_L_L); + { +static TCGTargetOpDef ld64; +int i, j =0 ; + +for (i =0 ; i *TCG_TARGET_REG_BITS <64 ; ++i) { + ld64.args_ct_str[j++] =constrain_memop_arg (ARG_LDVAL ,1 , i); + } +for (i =0 ; i *TCG_TARGET_REG_BITS <TARGET_LONG_BITS ; ++i) { + ld64.args_ct_str[j++] =constrain_memop_arg (ARG_ADDR ,0 , i); + } +return &ld64; + } +case INDEX_op_qemu_st_i32: + { +static TCGTargetOpDef st32; +int i; + + st32.args_ct_str[0 ] =constrain_memop_arg (ARG_STVAL ,0 ,0 ); +for (i =0 ; i *TCG_TARGET_REG_BITS <TARGET_LONG_BITS ; ++i) { + st32.args_ct_str[i +1 ] =constrain_memop_arg (ARG_ADDR ,0 , i); + } +return &st32; + }case INDEX_op_qemu_st_i64: -return (TCG_TARGET_REG_BITS ==64 ? &L_L - :TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &L_L_L - : &L_L_L_L ); + { +static TCGTargetOpDef st64; +int i, j =0 ; + +for (i =0 ; i *TCG_TARGET_REG_BITS <64 ; ++i) { + st64.args_ct_str[j++] =constrain_memop_arg (ARG_STVAL ,1 , i); + } +for (i =0 ; i *TCG_TARGET_REG_BITS <TARGET_LONG_BITS ; ++i) { + st64.args_ct_str[j++] =constrain_memop_arg (ARG_ADDR ,0 , i); + } +return &st64; + }case INDEX_op_brcond2_i32: {
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 08/37] tcg/i386: Force qemu_ld/st arguments into fixed registers
Quoted 120 lines · Richard Henderson
This is an incremental step toward moving the qemu_ld/st code sequence out of line.
Signed-off-by Richard Henderson <[email protected]>--- tcg/i386/tcg-target.inc.c | 203 +++++++++++++++++++++++++++++++------- 1 file changed, 169 insertions(+), 34 deletions(-)tcg/i386/tcg-target.inc.c +83
-4@@ -171,6 +171,80 @@ static bool have_lzcnt;static tcg_insn_unit *tb_ret_addr; +typedef enum { +ARG_ADDR , +ARG_STVAL , +ARG_LDVAL , +}QemuMemArgType ; + +#ifdef CONFIG_SOFTMMU +/* +* Constraint to choose a particular register. This is used for softmmu +* loads and stores. Registers with no assignment get an empty string. +*/ +static const char *const one_reg_constraint[TCG_TARGET_NB_REGS ] = { + [TCG_REG_EAX ] ="a" , + [TCG_REG_EBX ] ="b" , + [TCG_REG_ECX ] ="c" , + [TCG_REG_EDX ] ="d" , + [TCG_REG_ESI ] ="S" , + [TCG_REG_EDI ] ="D" , +#if TCG_TARGET_REG_BITS == 64 + [TCG_REG_R8 ] ="E" , + [TCG_REG_R9 ] ="N" , +#endif +}; + +/* +* Calling convention for the softmmu load and store thunks. +* +* For 64-bit, we mostly use the host calling convention, therefore the +* real first argument is reserved for the ENV parameter that is passed +* on to the slow path helpers. +* +* For 32-bit, the host calling convention is stack based; we invent a +* private convention that uses 4 of the 6 available host registers. +* We reserve EAX and EDX as temporaries for use by the thunk, we require +* INDEX_op_qemu_st_i32 to have a 'q' register from which to store, and +* further complicate this last by wanting a call-clobbered for that store. +* The 'q' requirement allows MO_8 stores at all; the call-clobbered part +* allows bswap to operate in-place, clobbering the input. +*/ +static TCGReg softmmu_arg (QemuMemArgType type,bool is_64,int hi) +{ +switch (type) { +case ARG_ADDR : +tcg_debug_assert (!hi ||TARGET_LONG_BITS >TCG_TARGET_REG_BITS ); +if (TCG_TARGET_REG_BITS ==64 ) { +return tcg_target_call_iarg_regs[1 ]; + }else { +return hi ?TCG_REG_EDI :TCG_REG_ESI ; + } +case ARG_STVAL : +tcg_debug_assert (!hi || (TCG_TARGET_REG_BITS ==32 && is_64)); +if (TCG_TARGET_REG_BITS ==64 ) { +return tcg_target_call_iarg_regs[2 ]; + }else { +return hi ?TCG_REG_EBX :TCG_REG_ECX ; + } +case ARG_LDVAL : +tcg_debug_assert (!hi || (TCG_TARGET_REG_BITS ==32 && is_64)); +return tcg_target_call_oarg_regs[hi]; + } +g_assert_not_reached (); +} + +static const char *constrain_memop_arg (QemuMemArgType type,bool is_64,int hi) +{ +return one_reg_constraint[softmmu_arg (type, is_64, hi)]; +} +#else +static const char *constrain_memop_arg (QemuMemArgType type,bool is_64,int hi) +{ +return "L" ; +} +#endif /* CONFIG_SOFTMMU */ +static bool patch_reloc (tcg_insn_unit *code_ptr,int type,intptr_t value,intptr_t addend) {@@ -1680,11 +1754,15 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi,copies the entire guest address for the slow path, while truncation for the 32-bit host happens with the fastpath ADDL below. */ if (TCG_TARGET_REG_BITS ==64 ) { - base = tcg_target_call_iarg_regs[1 ]; +tcg_debug_assert (addrlo == tcg_target_call_iarg_regs[1 ]); +if (TARGET_LONG_BITS ==32 ) { +tcg_out_ext32u (s, addrlo, addrlo); + } + base = addrlo; }else { base = r1; +tcg_out_mov (s, ttype, base, addrlo); } -tcg_out_mov (s, ttype, base, addrlo);/* jne slow_path */ tcg_out_opc (s, OPC_JCC_long +JCC_JNE ,0 ,0 ,0 );@@ -2009,16 +2087,22 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi,common. */ static void tcg_out_qemu_ld (TCGContext *s,const TCGArg *args,bool is64) { -TCGReg datalo, datahi, addrlo; - TCGReg addrhi __attribute__((unused)); +TCGReg datalo, addrlo; + TCGReg datahi __attribute__((unused)) = -1; + TCGReg addrhi __attribute__((unused)) = -1;
tcg/i386/tcg-target.inc.c static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi, · line 2097
Quoted 10 lines
tcg/i386/tcg-target.inc.c +2
-5TCGMemOpIdx oi;TCGMemOp opc; +int i =-1 ; - datalo = *args++; - datahi = (TCG_TARGET_REG_BITS ==32 && is64 ? *args++ :0 ); - addrlo = *args++; - addrhi = (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ? *args++ :0 ); - oi = *args++; + datalo = args[++i];
Swapping to i = -1 and pre-indexes seems a little unnatural here compared to a more normal 0 and i++ unless there was a specific reason to have i in the range of 2-4?
Quoted 29 lines
tcg/i386/tcg-target.inc.c +17
-0+if (TCG_TARGET_REG_BITS ==32 && is64) { + datahi = args[++i]; + } + addrlo = args[++i]; +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { + addrhi = args[++i]; + } + oi = args[++i]; opc =get_memop (oi);#if defined(CONFIG_SOFTMMU )@@ -2027,6 +2111,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)tcg_insn_unit *label_ptr[2 ];TCGReg base; +tcg_debug_assert (datalo ==softmmu_arg (ARG_LDVAL , is64,0 )); +if (TCG_TARGET_REG_BITS ==32 && is64) { +tcg_debug_assert (datahi ==softmmu_arg (ARG_LDVAL , is64,1 )); + } +tcg_debug_assert (addrlo ==softmmu_arg (ARG_ADDR ,0 ,0 )); +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { +tcg_debug_assert (addrhi ==softmmu_arg (ARG_ADDR ,0 ,1 )); + } + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, label_ptr, offsetof(CPUTLBEntry , addr_read));@@ -2149,16 +2242,22 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg datalo, TCGReg datahi,
tcg/i386/tcg-target.inc.c static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg datalo, TCGReg datahi, · line 2250
Quoted 10 lines
tcg/i386/tcg-target.inc.c +4
-2static void tcg_out_qemu_st (TCGContext *s,const TCGArg *args,bool is64) { -TCGReg datalo, datahi, addrlo; - TCGReg addrhi __attribute__((unused)); +TCGReg datalo, addrlo; + TCGReg datahi __attribute__((unused)) = -1; + TCGReg addrhi __attribute__((unused)) = -1;TCGMemOpIdx oi;TCGMemOp opc; +int i =-1 ;
And again here
Quoted 54 lines
tcg/i386/tcg-target.inc.c +18
-14- datalo = *args++; - datahi = (TCG_TARGET_REG_BITS ==32 && is64 ? *args++ :0 ); - addrlo = *args++; - addrhi = (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ? *args++ :0 ); - oi = *args++; + datalo = args[++i]; +if (TCG_TARGET_REG_BITS ==32 && is64) { + datahi = args[++i]; + } + addrlo = args[++i]; +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { + addrhi = args[++i]; + } + oi = args[++i]; opc =get_memop (oi);#if defined(CONFIG_SOFTMMU )@@ -2167,6 +2266,15 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)tcg_insn_unit *label_ptr[2 ];TCGReg base; +tcg_debug_assert (datalo ==softmmu_arg (ARG_STVAL , is64,0 )); +if (TCG_TARGET_REG_BITS ==32 && is64) { +tcg_debug_assert (datahi ==softmmu_arg (ARG_STVAL , is64,1 )); + } +tcg_debug_assert (addrlo ==softmmu_arg (ARG_ADDR ,0 ,0 )); +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { +tcg_debug_assert (addrhi ==softmmu_arg (ARG_ADDR ,0 ,1 )); + } + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, label_ptr, offsetof(CPUTLBEntry , addr_write));@@ -2836,15 +2944,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op)static const TCGTargetOpDef r_r_re = { .args_ct_str = {"r" ,"r" ,"re" } };static const TCGTargetOpDef r_0_re = { .args_ct_str = {"r" ,"0" ,"re" } };static const TCGTargetOpDef r_0_ci = { .args_ct_str = {"r" ,"0" ,"ci" } }; -static const TCGTargetOpDef r_L = { .args_ct_str = {"r" ,"L" } }; -static const TCGTargetOpDef L_L = { .args_ct_str = {"L" ,"L" } }; -static const TCGTargetOpDef r_L_L = { .args_ct_str = {"r" ,"L" ,"L" } }; -static const TCGTargetOpDef r_r_L = { .args_ct_str = {"r" ,"r" ,"L" } }; -static const TCGTargetOpDef L_L_L = { .args_ct_str = {"L" ,"L" ,"L" } }; -static const TCGTargetOpDef r_r_L_L - = { .args_ct_str = {"r" ,"r" ,"L" ,"L" } }; -static const TCGTargetOpDef L_L_L_L - = { .args_ct_str = {"L" ,"L" ,"L" ,"L" } };static const TCGTargetOpDef x_x = { .args_ct_str = {"x" ,"x" } };static const TCGTargetOpDef x_x_x = { .args_ct_str = {"x" ,"x" ,"x" } };static const TCGTargetOpDef x_x_x_x@@ -3026,17 +3125,53 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) }case INDEX_op_qemu_ld_i32:
tcg/i386/tcg-target.inc.c static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) · line 3134
Quoted 10 lines
tcg/i386/tcg-target.inc.c +6
-3-return TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &r_L : &r_L_L; -case INDEX_op_qemu_st_i32: -return TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &L_L : &L_L_L ; + { +static TCGTargetOpDef ld32; +int i; + + ld32.args_ct_str[0 ] =constrain_memop_arg (ARG_LDVAL ,0 ,0 ); +for (i =0 ; i *TCG_TARGET_REG_BITS <TARGET_LONG_BITS ; ++i) {
This formulation is a bit weird to follow, at first I thought it was going to overflow TCG_MAX_OP_ARGS until I realised what it was doing. Maybe a helper function would be a little clearer:
for (src_reg = 0; src_reg < tcg_target_regs_for(TARGET_LONG_BITS), ++i)
Same comment applies bellow.
Quoted 49 lines
tcg/i386/tcg-target.inc.c +39
-6+ ld32.args_ct_str[i +1 ] =constrain_memop_arg (ARG_ADDR ,0 , i); + } +return &ld32; + }case INDEX_op_qemu_ld_i64: -return (TCG_TARGET_REG_BITS ==64 ? &r_L - :TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &r_r_L - : &r_r_L_L); + { +static TCGTargetOpDef ld64; +int i, j =0 ; + +for (i =0 ; i *TCG_TARGET_REG_BITS <64 ; ++i) { + ld64.args_ct_str[j++] =constrain_memop_arg (ARG_LDVAL ,1 , i); + } +for (i =0 ; i *TCG_TARGET_REG_BITS <TARGET_LONG_BITS ; ++i) { + ld64.args_ct_str[j++] =constrain_memop_arg (ARG_ADDR ,0 , i); + } +return &ld64; + } +case INDEX_op_qemu_st_i32: + { +static TCGTargetOpDef st32; +int i; + + st32.args_ct_str[0 ] =constrain_memop_arg (ARG_STVAL ,0 ,0 ); +for (i =0 ; i *TCG_TARGET_REG_BITS <TARGET_LONG_BITS ; ++i) { + st32.args_ct_str[i +1 ] =constrain_memop_arg (ARG_ADDR ,0 , i); + } +return &st32; + }case INDEX_op_qemu_st_i64: -return (TCG_TARGET_REG_BITS ==64 ? &L_L - :TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &L_L_L - : &L_L_L_L ); + { +static TCGTargetOpDef st64; +int i, j =0 ; + +for (i =0 ; i *TCG_TARGET_REG_BITS <64 ; ++i) { + st64.args_ct_str[j++] =constrain_memop_arg (ARG_STVAL ,1 , i); + } +for (i =0 ; i *TCG_TARGET_REG_BITS <TARGET_LONG_BITS ; ++i) { + st64.args_ct_str[j++] =constrain_memop_arg (ARG_ADDR ,0 , i); + } +return &st64; + }case INDEX_op_brcond2_i32:
Quoted 1 line
{--
Alex Bennée
PATCH v2 9/37 tcg/i386: Use TCG_TARGET_NEED_LDST_OOL_LABELS
In reply to Richard HendersonMove the entire memory operation out of line.
--- tcg/i386/tcg-target.h | 2 +- tcg/i386/tcg-target.inc.c | 391 ++++++++++++++++---------------------- 2 files changed, 162 insertions(+), 231 deletions(-)
tcg/i386/tcg-target.h +1 -1
@@ -220,7 +220,7 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,#define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD)#ifdef CONFIG_SOFTMMU -#define TCG_TARGET_NEED_LDST_LABELS +#define TCG_TARGET_NEED_LDST_OOL_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS
tcg/i386/tcg-target.inc.c +161 -230
463 lines not on this page · raw message
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 09/37] tcg/i386: Use TCG_TARGET_NEED_LDST_OOL_LABELS
Quoted 1 line · Richard Henderson
Move the entire memory operation out of line.
Given Emilio's numbers is it likely we will want to support both options given the variability on x86?
Quoted 35 lines
Signed-off-by Richard Henderson <[email protected]>--- tcg/i386/tcg-target.h | 2 +- tcg/i386/tcg-target.inc.c | 391 ++++++++++++++++---------------------- 2 files changed, 162 insertions(+), 231 deletions(-)tcg/i386/tcg-target.h +1
-1@@ -220,7 +220,7 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,#define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD)#ifdef CONFIG_SOFTMMU -#define TCG_TARGET_NEED_LDST_LABELS +#define TCG_TARGET_NEED_LDST_OOL_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS tcg/i386/tcg-target.inc.c +1
-1@@ -1643,7 +1643,7 @@ static void tcg_out_nopn(TCGContext *s, int n) }#if defined(CONFIG_SOFTMMU ) -#include "tcg-ldst.inc.c" +#include "tcg-ldst-ool.inc.c" /* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr, * int mmu_idx, uintptr_t ra) @@ -1656,6 +1656,14 @@ static void * const qemu_ld_helpers[16] = { [MO_BEUW] = helper_be_lduw_mmu,
tcg/i386/tcg-target.inc.c static void * const qemu_ld_helpers[16] = { · line 1666
Quoted 10 lines
tcg/i386/tcg-target.inc.c +8
-0[MO_BEUL] = helper_be_ldul_mmu, [MO_BEQ] = helper_be_ldq_mmu, + + [MO_SB] = helper_ret_ldsb_mmu, + [MO_LESW] = helper_le_ldsw_mmu, + [MO_BESW ] = helper_be_ldsw_mmu, +#if TCG_TARGET_REG_BITS == 64 + [MO_LESL] = helper_le_ldsl_mmu, + [MO_BESL] = helper_be_ldsl_mmu, +#endif
Can we mention why these are added in the commit message please?
rth: why has qemu_ld_helpers been filled out? Did those loads not
happen before?
<rth> stsquad, previously we performed sign-extensions inline after
returning from the helper; with the change to a tail call we can't do that anymore.
rth: maybe that could go in the commit message then...
Quoted 441 lines
tcg/i386/tcg-target.inc.c +145
-229};/* helper signature: helper_ret_st_mmu(CPUState *env, target_ulong addr, @@ -1765,18 +1773,18 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi, }/* jne slow_path */ -tcg_out_opc (s, OPC_JCC_long +JCC_JNE ,0 ,0 ,0 ); +tcg_out_opc (s, OPC_JCC_short +JCC_JNE ,0 ,0 ,0 ); label_ptr[0 ] = s->code_ptr; - s->code_ptr +=4 ; + s->code_ptr +=1 ;if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) {/* cmp 4(r0), addrhi */ tcg_out_modrm_offset (s, OPC_CMP_GvEv, addrhi, r0,4 );/* jne slow_path */ -tcg_out_opc (s, OPC_JCC_long +JCC_JNE ,0 ,0 ,0 ); +tcg_out_opc (s, OPC_JCC_short +JCC_JNE ,0 ,0 ,0 ); label_ptr[1 ] = s->code_ptr; - s->code_ptr +=4 ; + s->code_ptr +=1 ; }/* TLB Hit. */ @@ -1788,181 +1796,6 @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi, return base; } -/* -* Record the context of a call to the out of line helper code for the slow path -* for a load or store, so that we can later generate the correct helper code -*/ -static void add_qemu_ldst_label (TCGContext *s,bool is_ld,TCGMemOpIdx oi, -TCGReg datalo,TCGReg datahi, -TCGReg addrlo,TCGReg addrhi, -tcg_insn_unit *raddr, -tcg_insn_unit **label_ptr) -{ -TCGLabelQemuLdst *label =new_ldst_label (s); - - label->is_ld = is_ld; - label->oi = oi; - label->datalo_reg = datalo; - label->datahi_reg = datahi; - label->addrlo_reg = addrlo; - label->addrhi_reg = addrhi; - label->raddr = raddr; - label->label_ptr[0 ] = label_ptr[0 ]; -if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { - label->label_ptr[1 ] = label_ptr[1 ]; - } -} - -/* -* Generate code for the slow path for a load at the end of block -*/ -static void tcg_out_qemu_ld_slow_path (TCGContext *s,TCGLabelQemuLdst *l) -{ -TCGMemOpIdx oi = l->oi; -TCGMemOp opc =get_memop (oi); -TCGReg data_reg; -tcg_insn_unit **label_ptr = &l->label_ptr[0 ]; - -/* resolve label address */ -tcg_patch32 (label_ptr[0 ], s->code_ptr - label_ptr[0 ] -4 ); -if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { -tcg_patch32 (label_ptr[1 ], s->code_ptr - label_ptr[1 ] -4 ); - } - -if (TCG_TARGET_REG_BITS ==32 ) { -int ofs =0 ; - -tcg_out_st (s,TCG_TYPE_PTR ,TCG_AREG0 ,TCG_REG_ESP , ofs); - ofs +=4 ; - -tcg_out_st (s,TCG_TYPE_I32 , l->addrlo_reg,TCG_REG_ESP , ofs); - ofs +=4 ; - -if (TARGET_LONG_BITS ==64 ) { -tcg_out_st (s,TCG_TYPE_I32 , l->addrhi_reg,TCG_REG_ESP , ofs); - ofs +=4 ; - } - -tcg_out_sti (s,TCG_TYPE_I32 , oi,TCG_REG_ESP , ofs); - ofs +=4 ; - -tcg_out_sti (s,TCG_TYPE_PTR , (uintptr_t )l->raddr,TCG_REG_ESP , ofs); - }else { -tcg_out_mov (s,TCG_TYPE_PTR , tcg_target_call_iarg_regs[0 ],TCG_AREG0 ); -/* The second argument is already loaded with addrlo. */ -tcg_out_movi (s,TCG_TYPE_I32 , tcg_target_call_iarg_regs[2 ], oi); -tcg_out_movi (s,TCG_TYPE_PTR , tcg_target_call_iarg_regs[3 ], - (uintptr_t )l->raddr); - } - -tcg_out_call (s, qemu_ld_helpers[opc & (MO_BSWAP |MO_SIZE )]); - - data_reg = l->datalo_reg; -switch (opc &MO_SSIZE ) { -case MO_SB : -tcg_out_ext8s (s, data_reg,TCG_REG_EAX ,P_REXW ); -break ; -case MO_SW : -tcg_out_ext16s (s, data_reg,TCG_REG_EAX ,P_REXW ); -break ; -#if TCG_TARGET_REG_BITS ==64 -case MO_SL : -tcg_out_ext32s (s, data_reg,TCG_REG_EAX ); -break ; -#endif -case MO_UB : -case MO_UW : -/* Note that the helpers have zero-extended to tcg_target_long. */ -case MO_UL : -tcg_out_mov (s,TCG_TYPE_I32 , data_reg,TCG_REG_EAX ); -break ; -case MO_Q : -if (TCG_TARGET_REG_BITS ==64 ) { -tcg_out_mov (s,TCG_TYPE_I64 , data_reg,TCG_REG_RAX ); - }else if (data_reg ==TCG_REG_EDX ) { -/* xchg %edx, %eax */ -tcg_out_opc (s, OPC_XCHG_ax_r32 +TCG_REG_EDX ,0 ,0 ,0 ); -tcg_out_mov (s,TCG_TYPE_I32 , l->datahi_reg,TCG_REG_EAX ); - }else { -tcg_out_mov (s,TCG_TYPE_I32 , data_reg,TCG_REG_EAX ); -tcg_out_mov (s,TCG_TYPE_I32 , l->datahi_reg,TCG_REG_EDX ); - } -break ; -default : -tcg_abort (); - } - -/* Jump to the code corresponding to next IR of qemu_st */ -tcg_out_jmp (s, l->raddr); -} - -/* -* Generate code for the slow path for a store at the end of block -*/ -static void tcg_out_qemu_st_slow_path (TCGContext *s,TCGLabelQemuLdst *l) -{ -TCGMemOpIdx oi = l->oi; -TCGMemOp opc =get_memop (oi); -TCGMemOp s_bits = opc &MO_SIZE ; -tcg_insn_unit **label_ptr = &l->label_ptr[0 ]; -TCGReg retaddr; - -/* resolve label address */ -tcg_patch32 (label_ptr[0 ], s->code_ptr - label_ptr[0 ] -4 ); -if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { -tcg_patch32 (label_ptr[1 ], s->code_ptr - label_ptr[1 ] -4 ); - } - -if (TCG_TARGET_REG_BITS ==32 ) { -int ofs =0 ; - -tcg_out_st (s,TCG_TYPE_PTR ,TCG_AREG0 ,TCG_REG_ESP , ofs); - ofs +=4 ; - -tcg_out_st (s,TCG_TYPE_I32 , l->addrlo_reg,TCG_REG_ESP , ofs); - ofs +=4 ; - -if (TARGET_LONG_BITS ==64 ) { -tcg_out_st (s,TCG_TYPE_I32 , l->addrhi_reg,TCG_REG_ESP , ofs); - ofs +=4 ; - } - -tcg_out_st (s,TCG_TYPE_I32 , l->datalo_reg,TCG_REG_ESP , ofs); - ofs +=4 ; - -if (s_bits ==MO_64 ) { -tcg_out_st (s,TCG_TYPE_I32 , l->datahi_reg,TCG_REG_ESP , ofs); - ofs +=4 ; - } - -tcg_out_sti (s,TCG_TYPE_I32 , oi,TCG_REG_ESP , ofs); - ofs +=4 ; - - retaddr =TCG_REG_EAX ; -tcg_out_movi (s,TCG_TYPE_PTR , retaddr, (uintptr_t )l->raddr); -tcg_out_st (s,TCG_TYPE_PTR , retaddr,TCG_REG_ESP , ofs); - }else { -tcg_out_mov (s,TCG_TYPE_PTR , tcg_target_call_iarg_regs[0 ],TCG_AREG0 ); -/* The second argument is already loaded with addrlo. */ -tcg_out_mov (s, (s_bits ==MO_64 ?TCG_TYPE_I64 :TCG_TYPE_I32 ), - tcg_target_call_iarg_regs[2 ], l->datalo_reg); -tcg_out_movi (s,TCG_TYPE_I32 , tcg_target_call_iarg_regs[3 ], oi); - -if (ARRAY_SIZE (tcg_target_call_iarg_regs) >4 ) { - retaddr = tcg_target_call_iarg_regs[4 ]; -tcg_out_movi (s,TCG_TYPE_PTR , retaddr, (uintptr_t )l->raddr); - }else { - retaddr =TCG_REG_RAX ; -tcg_out_movi (s,TCG_TYPE_PTR , retaddr, (uintptr_t )l->raddr); -tcg_out_st (s,TCG_TYPE_PTR , retaddr,TCG_REG_ESP , -TCG_TARGET_CALL_STACK_OFFSET ); - } - } - -/* "Tail call" to the helper, with the return address back inline. */ -tcg_out_push (s, retaddr); -tcg_out_jmp (s, qemu_st_helpers[opc & (MO_BSWAP |MO_SIZE )]); -}#elif defined(__x86_64__) && defined(__linux__)# include <asm/prctl.h> # include <sys/prctl.h> @@ -2091,7 +1924,6 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) TCGReg datahi __attribute__((unused)) = -1; TCGReg addrhi __attribute__((unused)) = -1;TCGMemOpIdx oi; -TCGMemOp opc;int i =-1 ; datalo = args[++i];@@ -2103,35 +1935,25 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) addrhi = args[++i]; } oi = args[++i]; - opc =get_memop (oi);#if defined(CONFIG_SOFTMMU ) - { -int mem_index =get_mmuidx (oi); -tcg_insn_unit *label_ptr[2 ]; -TCGReg base; - -tcg_debug_assert (datalo ==softmmu_arg (ARG_LDVAL , is64,0 )); -if (TCG_TARGET_REG_BITS ==32 && is64) { -tcg_debug_assert (datahi ==softmmu_arg (ARG_LDVAL , is64,1 )); - } -tcg_debug_assert (addrlo ==softmmu_arg (ARG_ADDR ,0 ,0 )); -if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { -tcg_debug_assert (addrhi ==softmmu_arg (ARG_ADDR ,0 ,1 )); - } - - base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, - label_ptr, offsetof(CPUTLBEntry , addr_read)); - -/* TLB Hit. */ -tcg_out_qemu_ld_direct (s, datalo, datahi, base,-1 ,0 ,0 , opc); - -/* Record the current context of a load into ldst label */ -add_qemu_ldst_label (s, true, oi, datalo, datahi, addrlo, addrhi, - s->code_ptr, label_ptr); +/* Assert that we've set up the constraints properly. */ +tcg_debug_assert (datalo ==softmmu_arg (ARG_LDVAL , is64,0 )); +if (TCG_TARGET_REG_BITS ==32 && is64) { +tcg_debug_assert (datahi ==softmmu_arg (ARG_LDVAL , is64,1 )); } +tcg_debug_assert (addrlo ==softmmu_arg (ARG_ADDR ,0 ,0 )); +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { +tcg_debug_assert (addrhi ==softmmu_arg (ARG_ADDR ,0 ,1 )); + } + +/* Call to thunk. */ +tcg_out8 (s, OPC_CALL_Jz); +add_ldst_ool_label (s, true, is64, oi,R_386_PC32 ,-4 ); + s->code_ptr +=4 ;#else { +TCGMemOp opc =get_memop (oi);int32_t offset = guest_base;TCGReg base = addrlo;int index =-1 ;@@ -2246,7 +2068,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) TCGReg datahi __attribute__((unused)) = -1; TCGReg addrhi __attribute__((unused)) = -1;TCGMemOpIdx oi; -TCGMemOp opc;int i =-1 ; datalo = args[++i];@@ -2258,35 +2079,25 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) addrhi = args[++i]; } oi = args[++i]; - opc =get_memop (oi);#if defined(CONFIG_SOFTMMU ) - { -int mem_index =get_mmuidx (oi); -tcg_insn_unit *label_ptr[2 ]; -TCGReg base; - -tcg_debug_assert (datalo ==softmmu_arg (ARG_STVAL , is64,0 )); -if (TCG_TARGET_REG_BITS ==32 && is64) { -tcg_debug_assert (datahi ==softmmu_arg (ARG_STVAL , is64,1 )); - } -tcg_debug_assert (addrlo ==softmmu_arg (ARG_ADDR ,0 ,0 )); -if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { -tcg_debug_assert (addrhi ==softmmu_arg (ARG_ADDR ,0 ,1 )); - } - - base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, - label_ptr, offsetof(CPUTLBEntry , addr_write)); - -/* TLB Hit. */ -tcg_out_qemu_st_direct (s, datalo, datahi, base,0 ,0 , opc); - -/* Record the current context of a store into ldst label */ -add_qemu_ldst_label (s, false, oi, datalo, datahi, addrlo, addrhi, - s->code_ptr, label_ptr); +/* Assert that we've set up the constraints properly. */ +tcg_debug_assert (datalo ==softmmu_arg (ARG_STVAL , is64,0 )); +if (TCG_TARGET_REG_BITS ==32 && is64) { +tcg_debug_assert (datahi ==softmmu_arg (ARG_STVAL , is64,1 )); } +tcg_debug_assert (addrlo ==softmmu_arg (ARG_ADDR ,0 ,0 )); +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { +tcg_debug_assert (addrhi ==softmmu_arg (ARG_ADDR ,0 ,1 )); + } + +/* Call to thunk. */ +tcg_out8 (s, OPC_CALL_Jz); +add_ldst_ool_label (s, false, is64, oi,R_386_PC32 ,-4 ); + s->code_ptr +=4 ;#else { +TCGMemOp opc =get_memop (oi);int32_t offset = guest_base;TCGReg base = addrlo;int seg =0 ;@@ -2321,6 +2132,126 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)#endif } +#if defined(CONFIG_SOFTMMU ) +/* +* Generate code for an out-of-line thunk performing a load. +*/ +static tcg_insn_unit *tcg_out_qemu_ldst_ool (TCGContext *s,bool is_ld, +bool is_64,TCGMemOpIdx oi) +{ +TCGMemOp opc =get_memop (oi); +int mem_index =get_mmuidx (oi); +tcg_insn_unit *label_ptr[2 ], *thunk; +TCGReg datalo, addrlo, base; + TCGReg datahi __attribute__((unused)) = -1; + TCGReg addrhi __attribute__((unused)) = -1; +int i; + +/* Since we're amortizing the cost, align the thunk. */ + thunk =QEMU_ALIGN_PTR_UP (s->code_ptr,16 ); +if (thunk != s->code_ptr) { +memset (s->code_ptr,0x90 , thunk - s->code_ptr); + s->code_ptr = thunk; + } + +/* Discover where the inputs are held. */ + addrlo =softmmu_arg (ARG_ADDR ,0 ,0 ); +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { + addrhi =softmmu_arg (ARG_ADDR ,0 ,1 ); + } + datalo =softmmu_arg (is_ld ?ARG_LDVAL :ARG_STVAL , is_64,0 ); +if (TCG_TARGET_REG_BITS ==32 && is_64) { + datahi =softmmu_arg (is_ld ?ARG_LDVAL :ARG_STVAL , is_64,1 ); + } + + base =tcg_out_tlb_load (s, addrlo, addrhi, mem_index, opc, label_ptr, + is_ld ? offsetof(CPUTLBEntry , addr_read) + : offsetof(CPUTLBEntry , addr_write)); + +/* TLB Hit. */ +if (is_ld) { +tcg_out_qemu_ld_direct (s, datalo, datahi, base,-1 ,0 ,0 , opc); + }else { +tcg_out_qemu_st_direct (s, datalo, datahi, base,0 ,0 , opc); + } +tcg_out_opc (s,OPC_RET ,0 ,0 ,0 ); + +/* TLB Miss. */ + +/* resolve label address */ +tcg_patch8 (label_ptr[0 ], s->code_ptr - label_ptr[0 ] -1 ); +if (TARGET_LONG_BITS >TCG_TARGET_REG_BITS ) { +tcg_patch8 (label_ptr[1 ], s->code_ptr - label_ptr[1 ] -1 ); + } + +if (TCG_TARGET_REG_BITS ==32 ) { +/* Copy the return address into a temporary. */ +tcg_out_ld (s,TCG_TYPE_PTR ,TCG_REG_L0 ,TCG_REG_ESP ,0 ); + i =4 ; + +tcg_out_st (s,TCG_TYPE_PTR ,TCG_AREG0 ,TCG_REG_ESP , i); + i +=4 ; + +tcg_out_st (s,TCG_TYPE_I32 , addrlo,TCG_REG_ESP , i); + i +=4 ; + +if (TARGET_LONG_BITS ==64 ) { +tcg_out_st (s,TCG_TYPE_I32 , addrhi,TCG_REG_ESP , i); + i +=4 ; + } + +if (!is_ld) { +tcg_out_st (s,TCG_TYPE_I32 , datalo,TCG_REG_ESP , i); + i +=4 ; + +if (is_64) { +tcg_out_st (s,TCG_TYPE_I32 , datahi,TCG_REG_ESP , i); + i +=4 ; + } + } + +tcg_out_sti (s,TCG_TYPE_I32 , oi,TCG_REG_ESP , i); + i +=4 ; + +tcg_out_st (s,TCG_TYPE_PTR ,TCG_REG_L0 ,TCG_REG_ESP , i); + }else { +tcg_out_mov (s,TCG_TYPE_PTR , tcg_target_call_iarg_regs[0 ],TCG_AREG0 ); + +/* The address and data values have been placed by constraints. */ +tcg_debug_assert (addrlo == tcg_target_call_iarg_regs[1 ]); +if (is_ld) { + i =2 ; + }else { +tcg_debug_assert (datalo == tcg_target_call_iarg_regs[2 ]); + i =3 ; + } + +tcg_out_movi (s,TCG_TYPE_I32 , tcg_target_call_iarg_regs[i++], oi); + +/* Copy the return address from the stack to the rvalue argument. +* WIN64 runs out of argument registers for stores. +*/ +if (i < (int )ARRAY_SIZE (tcg_target_call_iarg_regs)) { +tcg_out_ld (s,TCG_TYPE_PTR , tcg_target_call_iarg_regs[i], +TCG_REG_ESP ,0 ); + }else { +tcg_out_ld (s,TCG_TYPE_PTR ,TCG_REG_RAX ,TCG_REG_ESP ,0 ); +tcg_out_st (s,TCG_TYPE_PTR ,TCG_REG_RAX ,TCG_REG_ESP , +TCG_TARGET_CALL_STACK_OFFSET +8 ); + } + } + +/* Tail call to the helper. */ +if (is_ld) { +tcg_out_jmp (s, qemu_ld_helpers[opc & (MO_BSWAP |MO_SSIZE )]); + }else {
tcg/i386/tcg-target.inc.c static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) · line 2257
Quoted 10 lines
tcg/i386/tcg-target.inc.c +7
-0+ tcg_out_jmp(s, qemu_st_helpers[opc & (MO_BSWAP | MO_SIZE)]); + } + +return thunk; +} +#endif +static inline void tcg_out_op (TCGContext *s,TCGOpcode opc,const TCGArg *args,const int *const_args) {
Otherwise:
--
Alex Bennée
Re: [Qemu-devel] [PATCH for-4.0 v2 09/37] tcg/i386: Use TCG_TARGET_NEED_LDST_OOL_LABELS
Quoted 7 lines · Alex Bennée
Quoted 1 line · Richard Henderson
Move the entire memory operation out of line.
Given Emilio's numbers is it likely we will want to support both options given the variability on x86?
No, I don't want to support two methods in any one tcg backend. Which is why I'm not really sure what to do about Emilio's results.
r~
Re: [Qemu-devel] [PATCH for-4.0 v2 09/37] tcg/i386: Use TCG_TARGET_NEED_LDST_OOL_LABELS
Quoted 11 lines · Richard Henderson
Quoted 7 lines · Alex Bennée
Quoted 1 line · Richard Henderson
Move the entire memory operation out of line.
Given Emilio's numbers is it likely we will want to support both options given the variability on x86?
No, I don't want to support two methods in any one tcg backend. Which is why I'm not really sure what to do about Emilio's results.
They at least seem pretty positive on aarch64 backends....
--
Alex Bennée
PATCH v2 10/37 tcg/aarch64: Add constraints for x0, x1, x2
In reply to Richard HendersonThese are function call arguments that we will need soon.
--- tcg/aarch64/tcg-target.inc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tcg/aarch64/tcg-target.inc.c +12 -0
@@ -125,6 +125,18 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, const char *ct_str, TCGType type) {switch (*ct_str++) { +case 'a' :/* x0 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_X0 ); +break ; +case 'b' :/* x1 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_X1 ); +break ; +case 'c' :/* x2 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_X2 ); +break ;case 'r' :/* general registers */ ct->ct |=TCG_CT_REG ; ct->u.regs |=0xffffffffu ;
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 10/37] tcg/aarch64: Add constraints for x0, x1, x2
Quoted 3 lines · Richard Henderson
These are function call arguments that we will need soon.
Signed-off-by Richard Henderson <[email protected]>
Quoted 17 lines
--- tcg/aarch64/tcg-target.inc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)tcg/aarch64/tcg-target.inc.c +5
-0@@ -125,6 +125,18 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, const char *ct_str, TCGType type) {switch (*ct_str++) { +case 'a' :/* x0 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_X0 ); +break ; +case 'b' :/* x1 */
tcg/aarch64/tcg-target.inc.c static const char *target_parse_constraint(TCGArgConstraint *ct, · line 142
Quoted 10 lines
tcg/aarch64/tcg-target.inc.c +7
-0+ ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_X1 ); +break ; +case 'c' :/* x2 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_X2 ); +break ;case 'r' :/* general registers */ ct->ct |=TCG_CT_REG ; ct->u.regs |=0xffffffffu ;
--
Alex Bennée
PATCH v2 11/37 tcg/aarch64: Parameterize the temps for tcg_out_tlb_read
In reply to Richard HendersonWhen moving the qemu_ld/st arguments to the right place for a function call, we'll need to move the temps out of the way.
--- tcg/aarch64/tcg-target.inc.c | 74 +++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 34 deletions(-)
tcg/aarch64/tcg-target.inc.c +40 -34
@@ -1467,13 +1467,15 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi, label->label_ptr[0 ] = label_ptr; } -/* Load and compare a TLB entry, emitting the conditional jump to the -slow path for the failure case, which will be patched later when finalizing -the slow path. Generated code returns the host addend in X1, -clobbers X0,X2,X3,TMP. */ -static void tcg_out_tlb_read (TCGContext *s,TCGReg addr_reg,TCGMemOp opc, -tcg_insn_unit **label_ptr,int mem_index, -bool is_read) +/* +* Load and compare a TLB entry, emitting the conditional jump to the +* slow path on failure. Returns the register for the host addend. +* Clobbers t0, t1, t2, t3. +*/ +static TCGReg tcg_out_tlb_read (TCGContext *s,TCGReg addr_reg,TCGMemOp opc, +tcg_insn_unit **label_ptr,int mem_index, +bool is_read,TCGReg t0,TCGReg t1, +TCGReg t2,TCGReg t3) { int tlb_offset = is_read ? offsetof(CPUArchState, tlb_table[mem_index][0].addr_read)
@@ -1491,55 +1493,56 @@ static void tcg_out_tlb_read(TCGContext *s, TCGReg addr_reg, TCGMemOp opc,if (a_bits >= s_bits) { x3 = addr_reg; }else { + x3 = t3;tcg_out_insn (s,3401 ,ADDI ,TARGET_LONG_BITS ==64 , -TCG_REG_X3 , addr_reg, s_mask - a_mask); - x3 =TCG_REG_X3 ; + x3, addr_reg, s_mask - a_mask); } tlb_mask = (uint64_t )TARGET_PAGE_MASK | a_mask; -/* Extract the TLB index from the address into X0. -X0<CPU_TLB_BITS:0> = +/* Extract the TLB index from the address into T0. +T0<CPU_TLB_BITS:0> = addr_reg<TARGET_PAGE_BITS+CPU_TLB_BITS:TARGET_PAGE_BITS> */ -tcg_out_ubfm (s,TARGET_LONG_BITS ==64 ,TCG_REG_X0 , addr_reg, +tcg_out_ubfm (s,TARGET_LONG_BITS ==64 , t0, addr_reg,TARGET_PAGE_BITS ,TARGET_PAGE_BITS +CPU_TLB_BITS ); -/* Store the page mask part of the address into X3. */ +/* Store the page mask part of the address into T3. */ tcg_out_logicali (s,I3404_ANDI ,TARGET_LONG_BITS ==64 , -TCG_REG_X3 , x3, tlb_mask); + t3, x3, tlb_mask); -/* Add any "high bits" from the tlb offset to the env address into X2, +/* Add any "high bits" from the tlb offset to the env address into T2, to take advantage of the LSL12 form of the ADDI instruction. -X2 = env + (tlb_offset & 0xfff000) */ +T2 = env + (tlb_offset & 0xfff000) */ if (tlb_offset &0xfff000 ) { -tcg_out_insn (s,3401 ,ADDI ,TCG_TYPE_I64 ,TCG_REG_X2 , base, +tcg_out_insn (s,3401 ,ADDI ,TCG_TYPE_I64 , t2, base, tlb_offset &0xfff000 ); - base =TCG_REG_X2 ; + base = t2; } -/* Merge the tlb index contribution into X2. -X2 = X2 + (X0 << CPU_TLB_ENTRY_BITS) */ - tcg_out_insn(s, 3502S, ADD_LSL, TCG_TYPE_I64, TCG_REG_X2, base, -TCG_REG_X0 ,CPU_TLB_ENTRY_BITS ); +/* Merge the tlb index contribution into T2. +T2 = T2 + (T0 << CPU_TLB_ENTRY_BITS) */ + tcg_out_insn(s, 3502S, ADD_LSL, TCG_TYPE_I64, + t2, base, t0,CPU_TLB_ENTRY_BITS ); -/* Merge "low bits" from tlb offset, load the tlb comparator into X0. -X0 = load [X2 + (tlb_offset & 0x000fff)] */ +/* Merge "low bits" from tlb offset, load the tlb comparator into T0. +T0 = load [T2 + (tlb_offset & 0x000fff)] */ tcg_out_ldst (s,TARGET_LONG_BITS ==32 ?I3312_LDRW :I3312_LDRX , -TCG_REG_X0 ,TCG_REG_X2 , tlb_offset &0xfff , -TARGET_LONG_BITS ==32 ?2 :3 ); + t0, t2, tlb_offset &0xfff ,TARGET_LONG_BITS ==32 ?2 :3 );/* Load the tlb addend. Do that early to avoid stalling. -X1 = load [X2 + (tlb_offset & 0xfff) + offsetof(addend)] */ -tcg_out_ldst (s,I3312_LDRX ,TCG_REG_X1 ,TCG_REG_X2 , +T1 = load [T2 + (tlb_offset & 0xfff) + offsetof(addend)] */ +tcg_out_ldst (s,I3312_LDRX , t1, t2, (tlb_offset &0xfff ) + (offsetof(CPUTLBEntry , addend)) - (is_read ? offsetof(CPUTLBEntry , addr_read) : offsetof(CPUTLBEntry , addr_write)),3 );/* Perform the address comparison. */ -tcg_out_cmp (s, (TARGET_LONG_BITS ==64 ),TCG_REG_X0 ,TCG_REG_X3 ,0 ); +tcg_out_cmp (s, (TARGET_LONG_BITS ==64 ), t0, t3,0 );/* If not equal, we jump to the slow path. */ *label_ptr = s->code_ptr;tcg_out_goto_cond_noaddr (s,TCG_COND_NE ); + + return t1; }#endif /* CONFIG_SOFTMMU */
@@ -1644,10 +1647,12 @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,#ifdef CONFIG_SOFTMMU unsigned mem_index =get_mmuidx (oi);tcg_insn_unit *label_ptr; +TCGReg base; -tcg_out_tlb_read (s, addr_reg, memop, &label_ptr, mem_index,1 ); + base =tcg_out_tlb_read (s, addr_reg, memop, &label_ptr, mem_index,1 , +TCG_REG_X0 ,TCG_REG_X1 ,TCG_REG_X2 ,TCG_REG_X3 );tcg_out_qemu_ld_direct (s, memop, ext, data_reg, -TCG_REG_X1 , otype, addr_reg); + base, otype, addr_reg);add_qemu_ldst_label (s, true, oi, ext, data_reg, addr_reg, s->code_ptr, label_ptr);#else /* !CONFIG_SOFTMMU */
@@ -1669,10 +1674,11 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,#ifdef CONFIG_SOFTMMU unsigned mem_index =get_mmuidx (oi);tcg_insn_unit *label_ptr; +TCGReg base; -tcg_out_tlb_read (s, addr_reg, memop, &label_ptr, mem_index,0 ); -tcg_out_qemu_st_direct (s, memop, data_reg, -TCG_REG_X1 , otype, addr_reg); + base =tcg_out_tlb_read (s, addr_reg, memop, &label_ptr, mem_index,0 , +TCG_REG_X0 ,TCG_REG_X1 ,TCG_REG_X2 ,TCG_REG_X3 ); +tcg_out_qemu_st_direct (s, memop, data_reg, base, otype, addr_reg);add_qemu_ldst_label (s, false, oi, (memop &MO_SIZE )==MO_64 , data_reg, addr_reg, s->code_ptr, label_ptr);#else /* !CONFIG_SOFTMMU */
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH for-4.0 v2 11/37] tcg/aarch64: Parameterize the temps for tcg_out_tlb_read
Quoted 4 lines · Richard Henderson
When moving the qemu_ld/st arguments to the right place for a function call, we'll need to move the temps out of the way.
Signed-off-by Richard Henderson <[email protected]>
Quoted 130 lines
--- tcg/aarch64/tcg-target.inc.c | 74 +++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 34 deletions(-)tcg/aarch64/tcg-target.inc.c +37
-31@@ -1467,13 +1467,15 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi, label->label_ptr[0 ] = label_ptr; } -/* Load and compare a TLB entry, emitting the conditional jump to the -slow path for the failure case, which will be patched later when finalizing -the slow path. Generated code returns the host addend in X1, -clobbers X0,X2,X3,TMP. */ -static void tcg_out_tlb_read (TCGContext *s,TCGReg addr_reg,TCGMemOp opc, -tcg_insn_unit **label_ptr,int mem_index, -bool is_read) +/* +* Load and compare a TLB entry, emitting the conditional jump to the +* slow path on failure. Returns the register for the host addend. +* Clobbers t0, t1, t2, t3. +*/ +static TCGReg tcg_out_tlb_read (TCGContext *s,TCGReg addr_reg,TCGMemOp opc, +tcg_insn_unit **label_ptr,int mem_index, +bool is_read,TCGReg t0,TCGReg t1, +TCGReg t2,TCGReg t3) { int tlb_offset = is_read ? offsetof(CPUArchState, tlb_table[mem_index][0].addr_read)@@ -1491,55 +1493,56 @@ static void tcg_out_tlb_read(TCGContext *s, TCGReg addr_reg, TCGMemOp opc,if (a_bits >= s_bits) { x3 = addr_reg; }else { + x3 = t3;tcg_out_insn (s,3401 ,ADDI ,TARGET_LONG_BITS ==64 , -TCG_REG_X3 , addr_reg, s_mask - a_mask); - x3 =TCG_REG_X3 ; + x3, addr_reg, s_mask - a_mask); } tlb_mask = (uint64_t )TARGET_PAGE_MASK | a_mask; -/* Extract the TLB index from the address into X0. -X0<CPU_TLB_BITS:0> = +/* Extract the TLB index from the address into T0. +T0<CPU_TLB_BITS:0> = addr_reg<TARGET_PAGE_BITS+CPU_TLB_BITS:TARGET_PAGE_BITS> */ -tcg_out_ubfm (s,TARGET_LONG_BITS ==64 ,TCG_REG_X0 , addr_reg, +tcg_out_ubfm (s,TARGET_LONG_BITS ==64 , t0, addr_reg,TARGET_PAGE_BITS ,TARGET_PAGE_BITS +CPU_TLB_BITS ); -/* Store the page mask part of the address into X3. */ +/* Store the page mask part of the address into T3. */ tcg_out_logicali (s,I3404_ANDI ,TARGET_LONG_BITS ==64 , -TCG_REG_X3 , x3, tlb_mask); + t3, x3, tlb_mask); -/* Add any "high bits" from the tlb offset to the env address into X2, +/* Add any "high bits" from the tlb offset to the env address into T2, to take advantage of the LSL12 form of the ADDI instruction. -X2 = env + (tlb_offset & 0xfff000) */ +T2 = env + (tlb_offset & 0xfff000) */ if (tlb_offset &0xfff000 ) { -tcg_out_insn (s,3401 ,ADDI ,TCG_TYPE_I64 ,TCG_REG_X2 , base, +tcg_out_insn (s,3401 ,ADDI ,TCG_TYPE_I64 , t2, base, tlb_offset &0xfff000 ); - base =TCG_REG_X2 ; + base = t2; } -/* Merge the tlb index contribution into X2. -X2 = X2 + (X0 << CPU_TLB_ENTRY_BITS) */ - tcg_out_insn(s, 3502S, ADD_LSL, TCG_TYPE_I64, TCG_REG_X2, base, -TCG_REG_X0 ,CPU_TLB_ENTRY_BITS ); +/* Merge the tlb index contribution into T2. +T2 = T2 + (T0 << CPU_TLB_ENTRY_BITS) */ + tcg_out_insn(s, 3502S, ADD_LSL, TCG_TYPE_I64, + t2, base, t0,CPU_TLB_ENTRY_BITS ); -/* Merge "low bits" from tlb offset, load the tlb comparator into X0. -X0 = load [X2 + (tlb_offset & 0x000fff)] */ +/* Merge "low bits" from tlb offset, load the tlb comparator into T0. +T0 = load [T2 + (tlb_offset & 0x000fff)] */ tcg_out_ldst (s,TARGET_LONG_BITS ==32 ?I3312_LDRW :I3312_LDRX , -TCG_REG_X0 ,TCG_REG_X2 , tlb_offset &0xfff , -TARGET_LONG_BITS ==32 ?2 :3 ); + t0, t2, tlb_offset &0xfff ,TARGET_LONG_BITS ==32 ?2 :3 );/* Load the tlb addend. Do that early to avoid stalling. -X1 = load [X2 + (tlb_offset & 0xfff) + offsetof(addend)] */ -tcg_out_ldst (s,I3312_LDRX ,TCG_REG_X1 ,TCG_REG_X2 , +T1 = load [T2 + (tlb_offset & 0xfff) + offsetof(addend)] */ +tcg_out_ldst (s,I3312_LDRX , t1, t2, (tlb_offset &0xfff ) + (offsetof(CPUTLBEntry , addend)) - (is_read ? offsetof(CPUTLBEntry , addr_read) : offsetof(CPUTLBEntry , addr_write)),3 );/* Perform the address comparison. */ -tcg_out_cmp (s, (TARGET_LONG_BITS ==64 ),TCG_REG_X0 ,TCG_REG_X3 ,0 ); +tcg_out_cmp (s, (TARGET_LONG_BITS ==64 ), t0, t3,0 );/* If not equal, we jump to the slow path. */ *label_ptr = s->code_ptr;tcg_out_goto_cond_noaddr (s,TCG_COND_NE ); + + return t1; }#endif /* CONFIG_SOFTMMU */ @@ -1644,10 +1647,12 @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,#ifdef CONFIG_SOFTMMU unsigned mem_index =get_mmuidx (oi);tcg_insn_unit *label_ptr; +TCGReg base; -tcg_out_tlb_read (s, addr_reg, memop, &label_ptr, mem_index,1 ); + base =tcg_out_tlb_read (s, addr_reg, memop, &label_ptr, mem_index,1 , +TCG_REG_X0 ,TCG_REG_X1 ,TCG_REG_X2 ,TCG_REG_X3 );tcg_out_qemu_ld_direct (s, memop, ext, data_reg, -TCG_REG_X1 , otype, addr_reg); + base, otype, addr_reg);add_qemu_ldst_label (s, true, oi, ext, data_reg, addr_reg, s->code_ptr, label_ptr);#else /* !CONFIG_SOFTMMU */ @@ -1669,10 +1674,11 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,#ifdef CONFIG_SOFTMMU unsigned mem_index =get_mmuidx (oi);tcg_insn_unit *label_ptr; +TCGReg base;
tcg/aarch64/tcg-target.inc.c static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg, · line 1684
Quoted 10 lines
tcg/aarch64/tcg-target.inc.c +3
-3-tcg_out_tlb_read (s, addr_reg, memop, &label_ptr, mem_index,0 ); -tcg_out_qemu_st_direct (s, memop, data_reg, -TCG_REG_X1 , otype, addr_reg); + base =tcg_out_tlb_read (s, addr_reg, memop, &label_ptr, mem_index,0 , +TCG_REG_X0 ,TCG_REG_X1 ,TCG_REG_X2 ,TCG_REG_X3 ); +tcg_out_qemu_st_direct (s, memop, data_reg, base, otype, addr_reg);add_qemu_ldst_label (s, false, oi, (memop &MO_SIZE )==MO_64 , data_reg, addr_reg, s->code_ptr, label_ptr);#else /* !CONFIG_SOFTMMU */
--
Alex Bennée
PATCH v2 12/37 tcg/aarch64: Parameterize the temp for tcg_out_goto_long
In reply to Richard HendersonWe cannot use TCG_REG_LR (aka TCG_REG_TMP) for tail calls.
--- tcg/aarch64/tcg-target.inc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
tcg/aarch64/tcg-target.inc.c +6 -5
@@ -1134,14 +1134,15 @@ static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target)tcg_out_insn (s,3206 ,B , offset); } -static inline void tcg_out_goto_long (TCGContext *s,tcg_insn_unit *target) +static inline void tcg_out_goto_long (TCGContext *s,tcg_insn_unit *target, +TCGReg scratch) {ptrdiff_t offset = target - s->code_ptr;if (offset ==sextract64 (offset,0 ,26 )) {tcg_out_insn (s,3206 ,BL , offset); }else { -tcg_out_movi (s,TCG_TYPE_I64 ,TCG_REG_TMP , (intptr_t )target); -tcg_out_insn (s,3207 ,BR ,TCG_REG_TMP ); +tcg_out_movi (s,TCG_TYPE_I64 , scratch, (intptr_t )target); +tcg_out_insn (s,3207 ,BR , scratch); } }
@@ -1716,10 +1717,10 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,case INDEX_op_exit_tb:/* Reuse the zeroing that exists for goto_ptr. */ if (a0 ==0 ) { -tcg_out_goto_long (s, s->code_gen_epilogue); +tcg_out_goto_long (s, s->code_gen_epilogue,TCG_REG_TMP ); }else {tcg_out_movi (s,TCG_TYPE_I64 ,TCG_REG_X0 , a0); -tcg_out_goto_long (s, tb_ret_addr); +tcg_out_goto_long (s, tb_ret_addr,TCG_REG_TMP ); }break ;
Signature · 1 line
2.17.2
PATCH v2 13/37 tcg/aarch64: Use B not BL for tcg_out_goto_long
In reply to Richard HendersonThis was a typo copying from tcg_out_call, apparently.
--- tcg/aarch64/tcg-target.inc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/aarch64/tcg-target.inc.c +1 -1
@@ -1139,7 +1139,7 @@ static inline void tcg_out_goto_long(TCGContext *s, tcg_insn_unit *target, {ptrdiff_t offset = target - s->code_ptr;if (offset ==sextract64 (offset,0 ,26 )) { -tcg_out_insn (s,3206 ,BL , offset); +tcg_out_insn (s,3206 ,B , offset); }else {tcg_out_movi (s,TCG_TYPE_I64 , scratch, (intptr_t )target);tcg_out_insn (s,3207 ,BR , scratch);
Signature · 1 line
2.17.2
PATCH v2 14/37 tcg/aarch64: Use TCG_TARGET_NEED_LDST_OOL_LABELS
In reply to Richard Henderson--- tcg/aarch64/tcg-target.h | 2 +- tcg/aarch64/tcg-target.inc.c | 191 +++++++++++++++++------------------ 2 files changed, 93 insertions(+), 100 deletions(-)
tcg/aarch64/tcg-target.h +1 -1
@@ -146,7 +146,7 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU -#define TCG_TARGET_NEED_LDST_LABELS +#define TCG_TARGET_NEED_LDST_OOL_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS
tcg/aarch64/tcg-target.inc.c +92 -99
253 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 15/37 tcg/arm: Parameterize the temps for tcg_out_tlb_read
In reply to Richard HendersonWhen moving the qemu_ld/st arguments to the right place for a function call, we'll need to move the temps out of the way.
--- tcg/arm/tcg-target.inc.c | 89 +++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 43 deletions(-)
tcg/arm/tcg-target.inc.c +46 -43
@@ -1245,11 +1245,14 @@ static TCGReg tcg_out_arg_reg64(TCGContext *s, TCGReg argreg,/* We're expecting to use an 8-bit immediate and to mask. */ QEMU_BUILD_BUG_ON (CPU_TLB_BITS >8 ); -/* Load and compare a TLB entry, leaving the flags set. Returns the register -containing the addend of the tlb entry. Clobbers R0, R1, R2, TMP. */ - +/* +*Load and compare a TLB entry, leaving the flags set. Returns the register +* containing the addend of the tlb entry. Clobbers t0, t1, t2, t3. +* T0 and T1 must be consecutive for LDRD. +*/ static TCGReg tcg_out_tlb_read (TCGContext *s,TCGReg addrlo,TCGReg addrhi, -TCGMemOp opc,int mem_index,bool is_load) +TCGMemOp opc,int mem_index,bool is_load, +TCGReg t0,TCGReg t1,TCGReg t2,TCGReg t3) {TCGReg base =TCG_AREG0 ; int cmp_off =
@@ -1262,36 +1265,37 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,unsigned a_bits =get_alignment_bits (opc);/* V7 generates the following: -* ubfx r0, addrlo, #TARGET_PAGE_BITS, #CPU_TLB_BITS -* add r2, env, #high -* add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS -* ldr r0, [r2, #cmp] -* ldr r2, [r2, #add] -* movw tmp, #page_align_mask -* bic tmp, addrlo, tmp -* cmp r0, tmp +* ubfx t0, addrlo, #TARGET_PAGE_BITS, #CPU_TLB_BITS +* add t2, env, #high +* add t2, t2, r0, lsl #CPU_TLB_ENTRY_BITS +* ldr t0, [t2, #cmp] (and t1 w/ldrd) +* ldr t2, [t2, #add] +* movw t3, #page_align_mask +* bic t3, addrlo, t3 +* cmp t0, t3 * * Otherwise we generate: -* shr tmp, addrlo, #TARGET_PAGE_BITS -* add r2, env, #high -* and r0, tmp, #(CPU_TLB_SIZE - 1) -* add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS -* ldr r0, [r2, #cmp] -* ldr r2, [r2, #add] +* shr t3, addrlo, #TARGET_PAGE_BITS +* add t2, env, #high +* and t0, t3, #(CPU_TLB_SIZE - 1) +* add t2, t2, t0, lsl #CPU_TLB_ENTRY_BITS +* ldr t0, [t2, #cmp] (and t1 w/ldrd) +* ldr t2, [t2, #add] * tst addrlo, #s_mask -* cmpeq r0, tmp, lsl #TARGET_PAGE_BITS +* cmpeq t0, t3, lsl #TARGET_PAGE_BITS */ if (use_armv7_instructions) { -tcg_out_extract (s,COND_AL ,TCG_REG_R0 , addrlo, +tcg_out_extract (s,COND_AL , t0, addrlo,TARGET_PAGE_BITS ,CPU_TLB_BITS ); }else { -tcg_out_dat_reg (s,COND_AL ,ARITH_MOV ,TCG_REG_TMP , +tcg_out_dat_reg (s,COND_AL ,ARITH_MOV , t3,0 , addrlo,SHIFT_IMM_LSR (TARGET_PAGE_BITS )); }/* Add portions of the offset until the memory access is in range. * If we plan on using ldrd, reduce to an 8-bit offset; otherwise -* we can use a 12-bit offset. */ +* we can use a 12-bit offset. +*/ if (use_armv6_instructions &&TARGET_LONG_BITS ==64 ) { mask_off =0xff ; }else {
@@ -1301,34 +1305,33 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,int shift =ctz32 (cmp_off & ~mask_off) & ~1 ;int rot = ((32 - shift) <<7 ) &0xf00 ;int addend = cmp_off & (0xff << shift); -tcg_out_dat_imm (s,COND_AL ,ARITH_ADD ,TCG_REG_R2 , base, +tcg_out_dat_imm (s,COND_AL ,ARITH_ADD , t2, base, rot | ((cmp_off >> shift) &0xff )); - base =TCG_REG_R2 ; + base = t2; add_off -= addend; cmp_off -= addend; }if (!use_armv7_instructions) { -tcg_out_dat_imm (s,COND_AL ,ARITH_AND , -TCG_REG_R0 ,TCG_REG_TMP ,CPU_TLB_SIZE -1 ); +tcg_out_dat_imm (s,COND_AL ,ARITH_AND , t0, t3,CPU_TLB_SIZE -1 ); } -tcg_out_dat_reg (s,COND_AL ,ARITH_ADD ,TCG_REG_R2 , base, -TCG_REG_R0 ,SHIFT_IMM_LSL (CPU_TLB_ENTRY_BITS )); +tcg_out_dat_reg (s,COND_AL ,ARITH_ADD , t2, base, t0, +SHIFT_IMM_LSL (CPU_TLB_ENTRY_BITS ));/* Load the tlb comparator. Use ldrd if needed and available, but due to how the pointer needs setting up, ldm isn't useful. Base arm5 doesn't have ldrd, but armv5te does. */ if (use_armv6_instructions &&TARGET_LONG_BITS ==64 ) { -tcg_out_ldrd_8 (s,COND_AL ,TCG_REG_R0 ,TCG_REG_R2 , cmp_off); +tcg_out_ldrd_8 (s,COND_AL , t0, t2, cmp_off); }else { -tcg_out_ld32_12 (s,COND_AL ,TCG_REG_R0 ,TCG_REG_R2 , cmp_off); +tcg_out_ld32_12 (s,COND_AL , t0, t2, cmp_off);if (TARGET_LONG_BITS ==64 ) { -tcg_out_ld32_12 (s,COND_AL ,TCG_REG_R1 ,TCG_REG_R2 , cmp_off +4 ); +tcg_out_ld32_12 (s,COND_AL , t1, t2, cmp_off +4 ); } }/* Load the tlb addend. */ -tcg_out_ld32_12 (s,COND_AL ,TCG_REG_R2 ,TCG_REG_R2 , add_off); +tcg_out_ld32_12 (s,COND_AL , t2, t2, add_off);/* Check alignment. We don't support inline unaligned acceses, but we can easily support overalignment checks. */
@@ -1341,29 +1344,27 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,int rot =encode_imm (mask);if (rot >=0 ) { -tcg_out_dat_imm (s,COND_AL ,ARITH_BIC ,TCG_REG_TMP , addrlo, +tcg_out_dat_imm (s,COND_AL ,ARITH_BIC , t3, addrlo,rotl (mask, rot) | (rot <<7 )); }else { -tcg_out_movi32 (s,COND_AL ,TCG_REG_TMP , mask); -tcg_out_dat_reg (s,COND_AL ,ARITH_BIC ,TCG_REG_TMP , - addrlo,TCG_REG_TMP ,0 ); +tcg_out_movi32 (s,COND_AL , t3, mask); +tcg_out_dat_reg (s,COND_AL ,ARITH_BIC , t3, addrlo, t3,0 ); } -tcg_out_dat_reg (s,COND_AL ,ARITH_CMP ,0 ,TCG_REG_R0 ,TCG_REG_TMP ,0 ); +tcg_out_dat_reg (s,COND_AL ,ARITH_CMP ,0 , t0, t3,0 ); }else {if (a_bits) {tcg_out_dat_imm (s,COND_AL ,ARITH_TST ,0 , addrlo, (1 << a_bits) -1 ); }tcg_out_dat_reg (s, (a_bits ?COND_EQ :COND_AL ),ARITH_CMP , -0 ,TCG_REG_R0 ,TCG_REG_TMP , -SHIFT_IMM_LSL (TARGET_PAGE_BITS )); +0 , t0, t3,SHIFT_IMM_LSL (TARGET_PAGE_BITS )); }if (TARGET_LONG_BITS ==64 ) { -tcg_out_dat_reg (s,COND_EQ ,ARITH_CMP ,0 ,TCG_REG_R1 , addrhi,0 ); +tcg_out_dat_reg (s,COND_EQ ,ARITH_CMP ,0 , t1, addrhi,0 ); } -return TCG_REG_R2 ; +return t2; }/* Record the context of a call to the out of line helper code for the slow
@@ -1629,7 +1630,8 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); - addend =tcg_out_tlb_read (s, addrlo, addrhi, opc, mem_index,1 ); + addend =tcg_out_tlb_read (s, addrlo, addrhi, opc, mem_index,1 , +TCG_REG_R0 ,TCG_REG_R1 ,TCG_REG_R2 ,TCG_REG_R14 );/* This a conditional BL only to load a pointer within this opcode into LR for the slow path. We will not be using the value for a tail call. */
@@ -1760,7 +1762,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); - addend =tcg_out_tlb_read (s, addrlo, addrhi, opc, mem_index,0 ); + addend =tcg_out_tlb_read (s, addrlo, addrhi, opc, mem_index,0 , +TCG_REG_R0 ,TCG_REG_R1 ,TCG_REG_R2 ,TCG_REG_R14 );tcg_out_qemu_st_index (s,COND_EQ , opc, datalo, datahi, addrlo, addend);
Signature · 1 line
2.17.2
PATCH v2 16/37 tcg/arm: Add constraints for R0-R5
In reply to Richard HendersonThese are function call arguments that we will need soon.
--- tcg/arm/tcg-target.inc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tcg/arm/tcg-target.inc.c +6 -1
@@ -246,7 +246,12 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,static const char *target_parse_constraint (TCGArgConstraint *ct,const char *ct_str,TCGType type) { -switch (*ct_str++) { +char c = *ct_str++; +switch (c) { + case 'a' ... 'f': /* r0 - r5 */ + ct->ct |=TCG_CT_REG ; +tcg_regset_set_reg (ct->u.regs,TCG_REG_R0 + (c -'a' )); +break ;case 'I' : ct->ct |=TCG_CT_CONST_ARM ;break ;
Signature · 1 line
2.17.2
PATCH v2 17/37 tcg/arm: Reduce the number of temps for tcg_out_tlb_read
In reply to Richard HendersonWhen moving the qemu_ld/st thunk out of line, we no longer have LR for use as a temporary. In the worst case we must make do with 3 temps, when dealing with a 64-bit guest address. This in turn imples that we cannot use LDRD anymore, as there are not enough temps.
--- tcg/arm/tcg-target.inc.c | 97 ++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 44 deletions(-)
tcg/arm/tcg-target.inc.c +53 -44
@@ -1251,13 +1251,12 @@ static TCGReg tcg_out_arg_reg64(TCGContext *s, TCGReg argreg,QEMU_BUILD_BUG_ON (CPU_TLB_BITS >8 );/* -*Load and compare a TLB entry, leaving the flags set. Returns the register -* containing the addend of the tlb entry. Clobbers t0, t1, t2, t3. -* T0 and T1 must be consecutive for LDRD. +* Load and compare a TLB entry, leaving the flags set. Returns the register +* containing the addend of the tlb entry. Clobbers t0, t1, t2. */ static TCGReg tcg_out_tlb_read (TCGContext *s,TCGReg addrlo,TCGReg addrhi,TCGMemOp opc,int mem_index,bool is_load, -TCGReg t0,TCGReg t1,TCGReg t2,TCGReg t3) +TCGReg t0,TCGReg t1,TCGReg t2) {TCGReg base =TCG_AREG0 ; int cmp_off =
@@ -1265,49 +1264,64 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, ? offsetof(CPUArchState, tlb_table[mem_index][0].addr_read) : offsetof(CPUArchState, tlb_table[mem_index][0].addr_write)); int add_off = offsetof(CPUArchState, tlb_table[mem_index][0].addend); -int mask_off;unsigned s_bits = opc &MO_SIZE ;unsigned a_bits =get_alignment_bits (opc);/* V7 generates the following: * ubfx t0, addrlo, #TARGET_PAGE_BITS, #CPU_TLB_BITS * add t2, env, #high -* add t2, t2, r0, lsl #CPU_TLB_ENTRY_BITS -* ldr t0, [t2, #cmp] (and t1 w/ldrd) +* add t2, t2, t0, lsl #CPU_TLB_ENTRY_BITS +* ldr t0, [t2, #cmp] * ldr t2, [t2, #add] -* movw t3, #page_align_mask -* bic t3, addrlo, t3 -* cmp t0, t3 +* movw t1, #page_align_mask +* bic t1, addrlo, t1 +* cmp t0, t1 +* +* ubfx t0, addrlo, #TPB, #CTB -- 64-bit address +* add t2, env, #high +* add t2, t2, t0, lsl #CTEB +* ldr t0, [t2, #cmplo] +* movw t1, #page_align_mask +* bic t1, addrlo, t1 +* cmp t0, t1 +* ldr t0, [t2, #cmphi] +* ldr t2, [t2, #add] +* cmpeq t0, addrhi * * Otherwise we generate: * shr t3, addrlo, #TARGET_PAGE_BITS * add t2, env, #high * and t0, t3, #(CPU_TLB_SIZE - 1) * add t2, t2, t0, lsl #CPU_TLB_ENTRY_BITS -* ldr t0, [t2, #cmp] (and t1 w/ldrd) +* ldr t0, [t2, #cmp] * ldr t2, [t2, #add] * tst addrlo, #s_mask * cmpeq t0, t3, lsl #TARGET_PAGE_BITS +* +* shr t1, addrlo, #TPB -- 64-bit address +* add t2, env, #high +* and t0, t1, #CTS-1 +* add t2, t2, t0, lsl #CTEB +* ldr t0, [t2, #cmplo] +* tst addrlo, #s_mask +* cmpeq t0, t1, lsl #TBP +* ldr t0, [t2, #cmphi] +* ldr t2, [t2, #add] +* cmpeq t0, addrhi */ if (use_armv7_instructions) {tcg_out_extract (s,COND_AL , t0, addrlo,TARGET_PAGE_BITS ,CPU_TLB_BITS ); }else { -tcg_out_dat_reg (s,COND_AL ,ARITH_MOV , t3, +tcg_out_dat_reg (s,COND_AL ,ARITH_MOV , t1,0 , addrlo,SHIFT_IMM_LSR (TARGET_PAGE_BITS )); }/* Add portions of the offset until the memory access is in range. -* If we plan on using ldrd, reduce to an 8-bit offset; otherwise -* we can use a 12-bit offset. +* We are not using ldrd, so we can use a 12-bit offset. */ -if (use_armv6_instructions &&TARGET_LONG_BITS ==64 ) { - mask_off =0xff ; - }else { - mask_off =0xfff ; - } -while (cmp_off > mask_off) { -int shift =ctz32 (cmp_off & ~mask_off) & ~1 ; +while (cmp_off >0xfff ) { +int shift =ctz32 (cmp_off & ~0xfff ) & ~1 ;int rot = ((32 - shift) <<7 ) &0xf00 ;int addend = cmp_off & (0xff << shift); tcg_out_dat_imm(s, COND_AL, ARITH_ADD, t2, base,
@@ -1318,25 +1332,13 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, }if (!use_armv7_instructions) { -tcg_out_dat_imm (s,COND_AL ,ARITH_AND , t0, t3,CPU_TLB_SIZE -1 ); +tcg_out_dat_imm (s,COND_AL ,ARITH_AND , t0, t1,CPU_TLB_SIZE -1 ); }tcg_out_dat_reg (s,COND_AL ,ARITH_ADD , t2, base, t0,SHIFT_IMM_LSL (CPU_TLB_ENTRY_BITS )); -/* Load the tlb comparator. Use ldrd if needed and available, -but due to how the pointer needs setting up, ldm isn't useful. -Base arm5 doesn't have ldrd, but armv5te does. */ -if (use_armv6_instructions &&TARGET_LONG_BITS ==64 ) { -tcg_out_ldrd_8 (s,COND_AL , t0, t2, cmp_off); - }else { -tcg_out_ld32_12 (s,COND_AL , t0, t2, cmp_off); -if (TARGET_LONG_BITS ==64 ) { -tcg_out_ld32_12 (s,COND_AL , t1, t2, cmp_off +4 ); - } - } - -/* Load the tlb addend. */ -tcg_out_ld32_12 (s,COND_AL , t2, t2, add_off); +/* Load the tlb comparator (low part). */ +tcg_out_ld32_12 (s,COND_AL , t0, t2, cmp_off);/* Check alignment. We don't support inline unaligned acceses, but we can easily support overalignment checks. */
@@ -1349,24 +1351,31 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,int rot =encode_imm (mask);if (rot >=0 ) { -tcg_out_dat_imm (s,COND_AL ,ARITH_BIC , t3, addrlo, +tcg_out_dat_imm (s,COND_AL ,ARITH_BIC , t1, addrlo,rotl (mask, rot) | (rot <<7 )); }else { -tcg_out_movi32 (s,COND_AL , t3, mask); -tcg_out_dat_reg (s,COND_AL ,ARITH_BIC , t3, addrlo, t3,0 ); +tcg_out_movi32 (s,COND_AL , t1, mask); +tcg_out_dat_reg (s,COND_AL ,ARITH_BIC , t1, addrlo, t1,0 ); } -tcg_out_dat_reg (s,COND_AL ,ARITH_CMP ,0 , t0, t3,0 ); +tcg_out_dat_reg (s,COND_AL ,ARITH_CMP ,0 , t0, t1,0 ); }else {if (a_bits) {tcg_out_dat_imm (s,COND_AL ,ARITH_TST ,0 , addrlo, (1 << a_bits) -1 ); }tcg_out_dat_reg (s, (a_bits ?COND_EQ :COND_AL ),ARITH_CMP , -0 , t0, t3,SHIFT_IMM_LSL (TARGET_PAGE_BITS )); +0 , t0, t1,SHIFT_IMM_LSL (TARGET_PAGE_BITS )); } +/* Load the tlb comparator (high part). */ if (TARGET_LONG_BITS ==64 ) { -tcg_out_dat_reg (s,COND_EQ ,ARITH_CMP ,0 , t1, addrhi,0 ); +tcg_out_ld32_12 (s,COND_AL , t0, t2, cmp_off +4 ); + } +/* Load the tlb addend. */ +tcg_out_ld32_12 (s,COND_AL , t2, t2, add_off); + +if (TARGET_LONG_BITS ==64 ) { +tcg_out_dat_reg (s,COND_EQ ,ARITH_CMP ,0 , t0, addrhi,0 ); }return t2;
@@ -1636,7 +1645,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); addend =tcg_out_tlb_read (s, addrlo, addrhi, opc, mem_index,1 , -TCG_REG_R0 ,TCG_REG_R1 ,TCG_REG_R2 ,TCG_REG_R14 ); +TCG_REG_R0 ,TCG_REG_R1 ,TCG_REG_TMP );/* This a conditional BL only to load a pointer within this opcode into LR for the slow path. We will not be using the value for a tail call. */
@@ -1768,7 +1777,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); addend =tcg_out_tlb_read (s, addrlo, addrhi, opc, mem_index,0 , -TCG_REG_R0 ,TCG_REG_R1 ,TCG_REG_R2 ,TCG_REG_R14 ); +TCG_REG_R0 ,TCG_REG_R1 ,TCG_REG_TMP );tcg_out_qemu_st_index (s,COND_EQ , opc, datalo, datahi, addrlo, addend);
Signature · 1 line
2.17.2
PATCH v2 18/37 tcg/arm: Force qemu_ld/st arguments into fixed registers
In reply to Richard HendersonThis is an incremental step toward moving the qemu_ld/st code sequence out of line.
--- tcg/arm/tcg-target.inc.c | 113 +++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 40 deletions(-)
tcg/arm/tcg-target.inc.c +73 -40
@@ -270,37 +270,13 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, ct->u.regs =0xffff ;break ; -/* qemu_ld address */ -case 'l' : - ct->ct |=TCG_CT_REG ; - ct->u.regs =0xffff ; -#ifdef CONFIG_SOFTMMU -/* r0-r2,lr will be overwritten when reading the tlb entry, -so don't use these. */ -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R0 ); -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R1 ); -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R2 ); -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R14 ); -#endif -break ; -/* qemu_st address & data */ case 's' : ct->ct |=TCG_CT_REG ; ct->u.regs =0xffff ; -/* r0-r2 will be overwritten when reading the tlb entry (softmmu only) -and r0-r1 doing the byte swapping, so don't use these. */ +/* r0-r1 doing the byte swapping, so don't use these */ tcg_regset_reset_reg (ct->u.regs,TCG_REG_R0 );tcg_regset_reset_reg (ct->u.regs,TCG_REG_R1 ); -#if defined(CONFIG_SOFTMMU ) -/* Avoid clashes with registers being used for helper args */ -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R2 ); -#if TARGET_LONG_BITS ==64 -/* Avoid clashes with registers being used for helper args */ -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R3 ); -#endif -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R14 ); -#endif break ;default :
@@ -1630,8 +1606,8 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)TCGMemOpIdx oi;TCGMemOp opc;#ifdef CONFIG_SOFTMMU -int mem_index; -TCGReg addend; +int mem_index, avail; +TCGReg addend, t0, t1;tcg_insn_unit *label_ptr;#endif
@@ -1644,8 +1620,20 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); + + avail =0xf ; + avail &= ~(1 << addrlo); +if (TARGET_LONG_BITS ==64 ) { + avail &= ~(1 << addrhi); + } +tcg_debug_assert (avail &1 ); + t0 =TCG_REG_R0 ; + avail &= ~1 ; +tcg_debug_assert (avail !=0 ); + t1 =ctz32 (avail); + addend =tcg_out_tlb_read (s, addrlo, addrhi, opc, mem_index,1 , -TCG_REG_R0 ,TCG_REG_R1 ,TCG_REG_TMP ); + t0, t1,TCG_REG_TMP );/* This a conditional BL only to load a pointer within this opcode into LR for the slow path. We will not be using the value for a tail call. */
@@ -1762,8 +1750,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)TCGMemOpIdx oi;TCGMemOp opc;#ifdef CONFIG_SOFTMMU -int mem_index; -TCGReg addend; +int mem_index, avail; +TCGReg addend, t0, t1;tcg_insn_unit *label_ptr;#endif
@@ -1776,8 +1764,24 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); + + avail =0xf ; + avail &= ~(1 << addrlo); + avail &= ~(1 << datalo); +if (TARGET_LONG_BITS ==64 ) { + avail &= ~(1 << addrhi); + } +if (is64) { + avail &= ~(1 << datahi); + } +tcg_debug_assert (avail &1 ); + t0 =TCG_REG_R0 ; + avail &= ~1 ; +tcg_debug_assert (avail !=0 ); + t1 =ctz32 (avail); + addend =tcg_out_tlb_read (s, addrlo, addrhi, opc, mem_index,0 , -TCG_REG_R0 ,TCG_REG_R1 ,TCG_REG_TMP ); + t0, t1,TCG_REG_TMP );tcg_out_qemu_st_index (s,COND_EQ , opc, datalo, datahi, addrlo, addend);
@@ -2118,11 +2122,14 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op)static const TCGTargetOpDef r = { .args_ct_str = {"r" } };static const TCGTargetOpDef r_r = { .args_ct_str = {"r" ,"r" } };static const TCGTargetOpDef s_s = { .args_ct_str = {"s" ,"s" } }; -static const TCGTargetOpDef r_l = { .args_ct_str = {"r" ,"l" } }; +static const TCGTargetOpDef a_b = { .args_ct_str = {"a" ,"b" } }; +static const TCGTargetOpDef c_b = { .args_ct_str = {"c" ,"b" } };static const TCGTargetOpDef r_r_r = { .args_ct_str = {"r" ,"r" ,"r" } }; -static const TCGTargetOpDef r_r_l = { .args_ct_str = {"r" ,"r" ,"l" } }; -static const TCGTargetOpDef r_l_l = { .args_ct_str = {"r" ,"l" ,"l" } };static const TCGTargetOpDef s_s_s = { .args_ct_str = {"s" ,"s" ,"s" } }; +static const TCGTargetOpDef a_c_d = { .args_ct_str = {"a" ,"c" ,"d" } }; +static const TCGTargetOpDef a_b_b = { .args_ct_str = {"a" ,"b" ,"b" } }; +static const TCGTargetOpDef e_c_d = { .args_ct_str = {"e" ,"c" ,"d" } }; +static const TCGTargetOpDef e_f_b = { .args_ct_str = {"e" ,"f" ,"b" } };static const TCGTargetOpDef r_r_ri = { .args_ct_str = {"r" ,"r" ,"ri" } };static const TCGTargetOpDef r_r_rI = { .args_ct_str = {"r" ,"r" ,"rI" } };static const TCGTargetOpDef r_r_rIN
@@ -2131,10 +2138,12 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) = { .args_ct_str = {"r" ,"r" ,"rIK" } };static const TCGTargetOpDef r_r_r_r = { .args_ct_str = {"r" ,"r" ,"r" ,"r" } }; -static const TCGTargetOpDef r_r_l_l - = { .args_ct_str = {"r" ,"r" ,"l" ,"l" } };static const TCGTargetOpDef s_s_s_s = { .args_ct_str = {"s" ,"s" ,"s" ,"s" } }; +static const TCGTargetOpDef a_b_c_d + = { .args_ct_str = {"a" ,"b" ,"c" ,"d" } }; +static const TCGTargetOpDef e_f_c_d + = { .args_ct_str = {"e" ,"f" ,"c" ,"d" } };static const TCGTargetOpDef br = { .args_ct_str = {"r" ,"rIN" } };static const TCGTargetOpDef dep
@@ -2215,13 +2224,37 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op)return &setc2;case INDEX_op_qemu_ld_i32: -return TARGET_LONG_BITS ==32 ? &r_l : &r_l_l; +if (!USING_SOFTMMU ) { +return TARGET_LONG_BITS ==32 ? &r_r : &r_r_r; + }else if (TARGET_LONG_BITS ==32 ) { +return &a_b;/* temps available r0, r2, r3, r12 */ + }else { +return &a_c_d;/* temps available r0, r1, r12 */ + }case INDEX_op_qemu_ld_i64: -return TARGET_LONG_BITS ==32 ? &r_r_l : &r_r_l_l; +if (!USING_SOFTMMU ) { +return TARGET_LONG_BITS ==32 ? &r_r_r : &r_r_r_r; + }else if (TARGET_LONG_BITS ==32 ) { +return &a_b_b;/* temps available r0, r2, r3, r12 */ + }else { +return &a_b_c_d;/* temps available r0, r1, r12 */ + }case INDEX_op_qemu_st_i32: -return TARGET_LONG_BITS ==32 ? &s_s : &s_s_s; +if (!USING_SOFTMMU ) { +return TARGET_LONG_BITS ==32 ? &s_s : &s_s_s; + }else if (TARGET_LONG_BITS ==32 ) { +return &c_b;/* temps available r0, r3, r12 */ + }else { +return &e_c_d;/* temps available r0, r1, r12 */ + }case INDEX_op_qemu_st_i64: -return TARGET_LONG_BITS ==32 ? &s_s_s : &s_s_s_s; +if (!USING_SOFTMMU ) { +return TARGET_LONG_BITS ==32 ? &s_s_s : &s_s_s_s; + }else if (TARGET_LONG_BITS ==32 ) { +return &e_f_b;/* temps available r0, r2, r3, r12 */ + }else { +return &e_f_c_d;/* temps available r0, r1, r12 */ + }default :return NULL ;
Signature · 1 line
2.17.2
PATCH v2 19/37 tcg/arm: Use TCG_TARGET_NEED_LDST_OOL_LABELS
In reply to Richard Henderson--- tcg/arm/tcg-target.h | 2 +- tcg/arm/tcg-target.inc.c | 314 ++++++++++++++++----------------------- 2 files changed, 125 insertions(+), 191 deletions(-)
tcg/arm/tcg-target.h +1 -1
@@ -141,7 +141,7 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU -#define TCG_TARGET_NEED_LDST_LABELS +#define TCG_TARGET_NEED_LDST_OOL_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS
tcg/arm/tcg-target.inc.c +124 -190
360 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 20/37 tcg/ppc: Parameterize the temps for tcg_out_tlb_read
In reply to Richard HendersonWhen moving the qemu_ld/st arguments to the right place for a function call, we'll need to move the temps out of the way.
--- tcg/ppc/tcg-target.inc.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-)
tcg/ppc/tcg-target.inc.c +22 -18
@@ -1516,12 +1516,14 @@ static void * const qemu_st_helpers[16] = { };/* Perform the TLB load and compare. Places the result of the comparison -in CR7, loads the addend of the TLB into R3, and returns the register -containing the guest address (zero-extended into R4). Clobbers R0 and R2. */ +in CR7, loads the addend of the TLB, and returns the register containing +the guest address, places the addend into T0. +Clobbers t0, t1, TCG_REG_R0, TCG_REG_TMP1. */ static TCGReg tcg_out_tlb_read (TCGContext *s,TCGMemOp opc,TCGReg addrlo,TCGReg addrhi, -int mem_index,bool is_read) +int mem_index,bool is_read, +TCGReg t0,TCGReg t1) {int cmp_off = (is_read
@@ -1536,10 +1538,10 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGMemOp opc,if (TCG_TARGET_REG_BITS ==64 ) {if (TARGET_LONG_BITS ==32 ) {/* Zero-extend the address into a place helpful for further use. */ -tcg_out_ext32u (s,TCG_REG_R4 , addrlo); - addrlo =TCG_REG_R4 ; +tcg_out_ext32u (s, t1, addrlo); + addrlo = t1; }else { -tcg_out_rld (s,RLDICL ,TCG_REG_R3 , addrlo, +tcg_out_rld (s,RLDICL , t0, addrlo,64 -TARGET_PAGE_BITS ,64 -CPU_TLB_BITS ); } }
@@ -1559,27 +1561,27 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGMemOp opc,/* Extraction and shifting, part 2. */ if (TCG_TARGET_REG_BITS ==32 ||TARGET_LONG_BITS ==32 ) { -tcg_out_rlw (s,RLWINM ,TCG_REG_R3 , addrlo, +tcg_out_rlw (s,RLWINM , t0, addrlo,32 - (TARGET_PAGE_BITS -CPU_TLB_ENTRY_BITS ),32 - (CPU_TLB_BITS +CPU_TLB_ENTRY_BITS ),31 -CPU_TLB_ENTRY_BITS ); }else { -tcg_out_shli64 (s,TCG_REG_R3 ,TCG_REG_R3 ,CPU_TLB_ENTRY_BITS ); +tcg_out_shli64 (s, t0, t0,CPU_TLB_ENTRY_BITS ); } -tcg_out32 (s,ADD |TAB (TCG_REG_R3 ,TCG_REG_R3 , base)); +tcg_out32 (s,ADD |TAB (t0, t0, base));/* Load the tlb comparator. */ if (TCG_TARGET_REG_BITS <TARGET_LONG_BITS ) { -tcg_out_ld (s,TCG_TYPE_I32 ,TCG_REG_R4 ,TCG_REG_R3 , cmp_off); -tcg_out_ld (s,TCG_TYPE_I32 ,TCG_REG_TMP1 ,TCG_REG_R3 , cmp_off +4 ); +tcg_out_ld (s,TCG_TYPE_I32 , t1, t0, cmp_off); +tcg_out_ld (s,TCG_TYPE_I32 ,TCG_REG_TMP1 , t0, cmp_off +4 ); }else { -tcg_out_ld (s,TCG_TYPE_TL ,TCG_REG_TMP1 ,TCG_REG_R3 , cmp_off); +tcg_out_ld (s,TCG_TYPE_TL ,TCG_REG_TMP1 , t0, cmp_off); }/* Load the TLB addend for use on the fast path. Do this asap to minimize any load use delay. */ -tcg_out_ld (s,TCG_TYPE_PTR ,TCG_REG_R3 ,TCG_REG_R3 , add_off); +tcg_out_ld (s,TCG_TYPE_PTR , t0, t0, add_off);/* Clear the non-page, non-alignment bits from the address */ if (TCG_TARGET_REG_BITS ==32 ) {
@@ -1624,7 +1626,7 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGMemOp opc,if (TCG_TARGET_REG_BITS <TARGET_LONG_BITS ) {tcg_out_cmp (s,TCG_COND_EQ ,TCG_REG_R0 ,TCG_REG_TMP1 ,0 ,7 ,TCG_TYPE_I32 ); -tcg_out_cmp (s,TCG_COND_EQ , addrhi,TCG_REG_R4 ,0 ,6 ,TCG_TYPE_I32 ); +tcg_out_cmp (s,TCG_COND_EQ , addrhi, t1,0 ,6 ,TCG_TYPE_I32 );tcg_out32 (s,CRAND |BT (7 ,CR_EQ ) |BA (6 ,CR_EQ ) |BB (7 ,CR_EQ )); }else { tcg_out_cmp(s, TCG_COND_EQ, TCG_REG_R0, TCG_REG_TMP1,
@@ -1778,13 +1780,14 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); - addrlo =tcg_out_tlb_read (s, opc, addrlo, addrhi, mem_index, true); + rbase =TCG_REG_R3 ; + addrlo =tcg_out_tlb_read (s, opc, addrlo, addrhi, mem_index, true, + rbase,TCG_REG_R4 );/* Load a pointer into the current opcode w/conditional branch-link. */ label_ptr = s->code_ptr;tcg_out_bc_noaddr (s,BC |BI (7 ,CR_EQ ) |BO_COND_FALSE |LK ); - rbase =TCG_REG_R3 ;#else /* !CONFIG_SOFTMMU */ rbase = guest_base ?TCG_GUEST_BASE_REG :0 ;if (TCG_TARGET_REG_BITS >TARGET_LONG_BITS ) {
@@ -1853,13 +1856,14 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); - addrlo =tcg_out_tlb_read (s, opc, addrlo, addrhi, mem_index, false); + rbase =TCG_REG_R3 ; + addrlo =tcg_out_tlb_read (s, opc, addrlo, addrhi, mem_index, false, + rbase,TCG_REG_R4 );/* Load a pointer into the current opcode w/conditional branch-link. */ label_ptr = s->code_ptr;tcg_out_bc_noaddr (s,BC |BI (7 ,CR_EQ ) |BO_COND_FALSE |LK ); - rbase =TCG_REG_R3 ;#else /* !CONFIG_SOFTMMU */ rbase = guest_base ?TCG_GUEST_BASE_REG :0 ;if (TCG_TARGET_REG_BITS >TARGET_LONG_BITS ) {
Signature · 1 line
2.17.2
PATCH v2 21/37 tcg/ppc: Split out tcg_out_call_int
In reply to Richard HendersonPass in a LK parameter, allowing us to create tail calls.
--- tcg/ppc/tcg-target.inc.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
tcg/ppc/tcg-target.inc.c +11 -6
@@ -1408,7 +1408,7 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, } } -static void tcg_out_call (TCGContext *s,tcg_insn_unit *target) +static void tcg_out_call_int (TCGContext *s,tcg_insn_unit *target,int lk) {#ifdef _CALL_AIX/* Look through the descriptor. If the branch is in range, and we
@@ -1419,7 +1419,7 @@ static void tcg_out_call(TCGContext *s, tcg_insn_unit *target)if (in_range_b (diff) && toc == (uint32_t )toc) {tcg_out_movi (s,TCG_TYPE_PTR ,TCG_REG_TMP1 , toc); -tcg_out_b (s,LK , tgt); +tcg_out_b (s, lk, tgt); }else {/* Fold the low bits of the constant into the addresses below. */ intptr_t arg = (intptr_t )target;
@@ -1434,7 +1434,7 @@ static void tcg_out_call(TCGContext *s, tcg_insn_unit *target)tcg_out_ld (s,TCG_TYPE_PTR ,TCG_REG_R0 ,TCG_REG_TMP1 , ofs);tcg_out32 (s,MTSPR |RA (TCG_REG_R0 ) |CTR );tcg_out_ld (s,TCG_TYPE_PTR ,TCG_REG_R2 ,TCG_REG_TMP1 , ofs +SZP ); - tcg_out32(s, BCCTR | BO_ALWAYS | LK); + tcg_out32(s, BCCTR | BO_ALWAYS | lk); }#elif defined(_CALL_ELF) && _CALL_ELF == 2intptr_t diff;
@@ -1448,16 +1448,21 @@ static void tcg_out_call(TCGContext *s, tcg_insn_unit *target) diff =tcg_pcrel_diff (s, target);if (in_range_b (diff)) { -tcg_out_b (s,LK , target); +tcg_out_b (s, lk, target); }else {tcg_out32 (s,MTSPR |RS (TCG_REG_R12 ) |CTR ); -tcg_out32 (s,BCCTR |BO_ALWAYS |LK ); +tcg_out32 (s,BCCTR |BO_ALWAYS | lk); }#else -tcg_out_b (s,LK , target); +tcg_out_b (s, lk, target);#endif } +static void tcg_out_call (TCGContext *s,tcg_insn_unit *target) +{ +tcg_out_call_int (s, target,LK ); +} +static const uint32_t qemu_ldx_opc[16 ] = { [MO_UB ] =LBZX , [MO_UW ] =LHZX ,
Signature · 1 line
2.17.2
PATCH v2 22/37 tcg/ppc: Add constraints for R7-R8
In reply to Richard HendersonThese are function call arguments that we will need soon.
--- tcg/ppc/tcg-target.inc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tcg/ppc/tcg-target.inc.c +4 -3
@@ -236,10 +236,11 @@ static inline void tcg_out_bc_noaddr(TCGContext *s, int insn)static const char *target_parse_constraint (TCGArgConstraint *ct,const char *ct_str,TCGType type) { -switch (*ct_str++) { -case 'A' :case 'B' :case 'C' :case 'D' : +char c = *ct_str++; +switch (c) { +case 'A' :case 'B' :case 'C' :case 'D' :case 'E' :case 'F' : ct->ct |=TCG_CT_REG ; -tcg_regset_set_reg (ct->u.regs,3 + ct_str[0 ] -'A' ); +tcg_regset_set_reg (ct->u.regs,3 + c -'A' );break ;case 'r' : ct->ct |=TCG_CT_REG ;
Signature · 1 line
2.17.2
PATCH v2 23/37 tcg/ppc: Change TCG_TARGET_CALL_ALIGN_ARGS to bool
In reply to Richard HendersonCleaner not to treat this as #ifdef.
--- tcg/ppc/tcg-target.inc.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
tcg/ppc/tcg-target.inc.c +5 -9
@@ -30,6 +30,8 @@#endif #ifdef _CALL_SYSV# define TCG_TARGET_CALL_ALIGN_ARGS 1 +#else +# define TCG_TARGET_CALL_ALIGN_ARGS 0#endif /* For some memory operations, we need a scratch that isn't R0. For the AIX
@@ -1675,9 +1677,7 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) lo = lb->addrlo_reg; hi = lb->addrhi_reg;if (TCG_TARGET_REG_BITS <TARGET_LONG_BITS ) { -#ifdef TCG_TARGET_CALL_ALIGN_ARGS - arg |=1 ; -#endif + arg |=TCG_TARGET_CALL_ALIGN_ARGS ;tcg_out_mov (s,TCG_TYPE_I32 , arg++, hi);tcg_out_mov (s,TCG_TYPE_I32 , arg++, lo); }else {
@@ -1720,9 +1720,7 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) lo = lb->addrlo_reg; hi = lb->addrhi_reg;if (TCG_TARGET_REG_BITS <TARGET_LONG_BITS ) { -#ifdef TCG_TARGET_CALL_ALIGN_ARGS - arg |=1 ; -#endif + arg |=TCG_TARGET_CALL_ALIGN_ARGS ;tcg_out_mov (s,TCG_TYPE_I32 , arg++, hi);tcg_out_mov (s,TCG_TYPE_I32 , arg++, lo); }else {
@@ -1736,9 +1734,7 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)if (TCG_TARGET_REG_BITS ==32 ) {switch (s_bits) {case MO_64 : -#ifdef TCG_TARGET_CALL_ALIGN_ARGS - arg |=1 ; -#endif + arg |=TCG_TARGET_CALL_ALIGN_ARGS ;tcg_out_mov (s,TCG_TYPE_I32 , arg++, hi);/* FALLTHRU */ case MO_32 :
Signature · 1 line
2.17.2
PATCH v2 24/37 tcg/ppc: Force qemu_ld/st arguments into fixed registers
In reply to Richard HendersonThis is an incremental step toward moving the qemu_ld/st code sequence out of line.
--- tcg/ppc/tcg-target.inc.c | 151 ++++++++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 40 deletions(-)
tcg/ppc/tcg-target.inc.c +111 -40
@@ -248,25 +248,6 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, ct->ct |=TCG_CT_REG ; ct->u.regs =0xffffffff ;break ; -case 'L' :/* qemu_ld constraint */ - ct->ct |=TCG_CT_REG ; - ct->u.regs =0xffffffff ; -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R3 ); -#ifdef CONFIG_SOFTMMU -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R4 ); -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R5 ); -#endif -break ; -case 'S' :/* qemu_st constraint */ - ct->ct |=TCG_CT_REG ; - ct->u.regs =0xffffffff ; -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R3 ); -#ifdef CONFIG_SOFTMMU -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R4 ); -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R5 ); -tcg_regset_reset_reg (ct->u.regs,TCG_REG_R6 ); -#endif -break ;case 'I' : ct->ct |=TCG_CT_CONST_S16 ;break ;
@@ -1759,6 +1740,21 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) tcg_out_b(s, 0, lb->raddr); } + +static TCGReg softmmu_args_2 (TCGReg reg,TCGReg *lo,TCGReg *hi) +{ +#ifdef HOST_WORDS_BIGENDIAN +static bool is_be = true; +#else +static bool is_be = false; +#endif + +assert (TCG_TARGET_REG_BITS ==32 ); + reg |=TCG_TARGET_CALL_ALIGN_ARGS ; + *(is_be ? hi : lo) = reg; + *(is_be ? lo : hi) = reg +1 ; +return reg +2 ; +}#endif /* SOFTMMU */ static void tcg_out_qemu_ld (TCGContext *s,const TCGArg *args,bool is_64)
@@ -1782,9 +1778,9 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); - rbase =TCG_REG_R3 ; + rbase =TCG_REG_R9 ; addrlo =tcg_out_tlb_read (s, opc, addrlo, addrhi, mem_index, true, - rbase,TCG_REG_R4 ); + rbase,TCG_REG_R10 );/* Load a pointer into the current opcode w/conditional branch-link. */ label_ptr = s->code_ptr;
@@ -1858,9 +1854,9 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)#ifdef CONFIG_SOFTMMU mem_index =get_mmuidx (oi); - rbase =TCG_REG_R3 ; + rbase =TCG_REG_R9 ; addrlo =tcg_out_tlb_read (s, opc, addrlo, addrhi, mem_index, false, - rbase,TCG_REG_R4 ); + rbase,TCG_REG_R10 );/* Load a pointer into the current opcode w/conditional branch-link. */ label_ptr = s->code_ptr;
@@ -2627,13 +2623,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) {static const TCGTargetOpDef r = { .args_ct_str = {"r" } };static const TCGTargetOpDef r_r = { .args_ct_str = {"r" ,"r" } }; -static const TCGTargetOpDef r_L = { .args_ct_str = {"r" ,"L" } }; -static const TCGTargetOpDef S_S = { .args_ct_str = {"S" ,"S" } };static const TCGTargetOpDef r_ri = { .args_ct_str = {"r" ,"ri" } };static const TCGTargetOpDef r_r_r = { .args_ct_str = {"r" ,"r" ,"r" } }; -static const TCGTargetOpDef r_L_L = { .args_ct_str = {"r" ,"L" ,"L" } }; -static const TCGTargetOpDef L_L_L = { .args_ct_str = {"L" ,"L" ,"L" } }; -static const TCGTargetOpDef S_S_S = { .args_ct_str = {"S" ,"S" ,"S" } };static const TCGTargetOpDef r_r_ri = { .args_ct_str = {"r" ,"r" ,"ri" } };static const TCGTargetOpDef r_r_rI = { .args_ct_str = {"r" ,"r" ,"rI" } };static const TCGTargetOpDef r_r_rT = { .args_ct_str = {"r" ,"r" ,"rT" } };
@@ -2644,10 +2635,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) = { .args_ct_str = {"r" ,"rI" ,"rT" } };static const TCGTargetOpDef r_r_rZW = { .args_ct_str = {"r" ,"r" ,"rZW" } }; -static const TCGTargetOpDef L_L_L_L - = { .args_ct_str = {"L" ,"L" ,"L" ,"L" } }; -static const TCGTargetOpDef S_S_S_S - = { .args_ct_str = {"S" ,"S" ,"S" ,"S" } };static const TCGTargetOpDef movc = { .args_ct_str = {"r" ,"r" ,"ri" ,"rZ" ,"rZ" } };static const TCGTargetOpDef dep
@@ -2660,6 +2647,15 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) = { .args_ct_str = {"r" ,"r" ,"r" ,"r" ,"rI" ,"rZM" } };static const TCGTargetOpDef sub2 = { .args_ct_str = {"r" ,"r" ,"rI" ,"rZM" ,"r" ,"r" } }; +#ifdef CONFIG_SOFTMMU +static const char *const arg_letter[] = { +NULL ,NULL ,NULL ,"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,NULL ,NULL + }; +TCGReg hi, lo, arg; +#else +static const TCGTargetOpDef r_r_r_r + = { .args_ct_str = {"r" ,"r" ,"r" ,"r" } }; +#endif switch (op) {case INDEX_op_goto_ptr:
@@ -2782,18 +2778,93 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op)case INDEX_op_sub2_i32:return &sub2; +#ifdef CONFIG_SOFTMMU case INDEX_op_qemu_ld_i32: -return (TCG_TARGET_REG_BITS ==64 ||TARGET_LONG_BITS ==32 - ? &r_L : &r_L_L); + { +static TCGTargetOpDef ld32; + ld32.args_ct_str[0 ] = arg_letter[tcg_target_call_oarg_regs[0 ]]; +if (TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ) { + ld32.args_ct_str[1 ] = arg_letter[tcg_target_call_iarg_regs[1 ]]; + }else { + arg = tcg_target_call_iarg_regs[1 ]; + arg =softmmu_args_2 (arg, &lo, &hi); + ld32.args_ct_str[1 ] = arg_letter[lo]; + ld32.args_ct_str[2 ] = arg_letter[hi]; + } +return &ld32; + }case INDEX_op_qemu_st_i32: -return (TCG_TARGET_REG_BITS ==64 ||TARGET_LONG_BITS ==32 - ? &S_S : &S_S_S ); + { +static TCGTargetOpDef st32; + arg = tcg_target_call_iarg_regs[1 ]; +if (TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ) { + st32.args_ct_str[0 ] = arg_letter[arg +1 ]; + st32.args_ct_str[1 ] = arg_letter[arg]; + }else { + arg =softmmu_args_2 (arg, &lo, &hi); + st32.args_ct_str[0 ] = arg_letter[arg]; + st32.args_ct_str[1 ] = arg_letter[lo]; + st32.args_ct_str[2 ] = arg_letter[hi]; + } +return &st32; + }case INDEX_op_qemu_ld_i64: -return (TCG_TARGET_REG_BITS ==64 ? &r_L - :TARGET_LONG_BITS ==32 ? &L_L_L : &L_L_L_L ); + { +static TCGTargetOpDef ld64; +if (TCG_TARGET_REG_BITS ==64 ) { + ld64.args_ct_str[0 ] = arg_letter[tcg_target_call_oarg_regs[0 ]]; + ld64.args_ct_str[1 ] = arg_letter[tcg_target_call_iarg_regs[1 ]]; + }else { + arg = tcg_target_call_oarg_regs[1 ]; + arg =softmmu_args_2 (arg, &lo, &hi); + ld64.args_ct_str[0 ] = arg_letter[lo]; + ld64.args_ct_str[1 ] = arg_letter[hi]; + arg = tcg_target_call_iarg_regs[1 ]; +if (TARGET_LONG_BITS ==32 ) { + ld64.args_ct_str[2 ] = arg_letter[arg]; + }else { + arg =softmmu_args_2 (arg, &lo, &hi); + ld64.args_ct_str[2 ] = arg_letter[lo]; + ld64.args_ct_str[3 ] = arg_letter[hi]; + } + } +return &ld64; + }case INDEX_op_qemu_st_i64: -return (TCG_TARGET_REG_BITS ==64 ? &S_S - :TARGET_LONG_BITS ==32 ? &S_S_S : &S_S_S_S ); + { +static TCGTargetOpDef st64; +if (TCG_TARGET_REG_BITS ==64 ) { + st64.args_ct_str[1 ] = arg_letter[tcg_target_call_iarg_regs[1 ]]; + st64.args_ct_str[0 ] = arg_letter[tcg_target_call_iarg_regs[2 ]]; + }else { + arg = tcg_target_call_iarg_regs[1 ]; +if (TARGET_LONG_BITS ==32 ) { + st64.args_ct_str[2 ] = arg_letter[arg++]; + }else { + arg =softmmu_args_2 (arg, &lo, &hi); + st64.args_ct_str[2 ] = arg_letter[lo]; + st64.args_ct_str[3 ] = arg_letter[hi]; + } + arg =softmmu_args_2 (arg, &lo, &hi); + st64.args_ct_str[0 ] = arg_letter[lo]; + st64.args_ct_str[1 ] = arg_letter[hi]; + } +return &st64; + } +#else +case INDEX_op_qemu_ld_i32: +case INDEX_op_qemu_st_i32: +return TARGET_LONG_BITS <=TCG_TARGET_REG_BITS ? &r_r : &r_r_r; +case INDEX_op_qemu_ld_i64: +case INDEX_op_qemu_st_i64: +if (TCG_TARGET_REG_BITS ==64 ) { +return &r_r; + }else if (TARGET_LONG_BITS ==32 ) { +return &r_r_r; + }else { +return &r_r_r_r; + } +#endif default :return NULL ;
Signature · 1 line
2.17.2
PATCH v2 25/37 tcg/ppc: Use TCG_TARGET_NEED_LDST_OOL_LABELS
In reply to Richard Henderson--- tcg/ppc/tcg-target.h | 2 +- tcg/ppc/tcg-target.inc.c | 326 +++++++++++++++++---------------------- 2 files changed, 141 insertions(+), 187 deletions(-)
tcg/ppc/tcg-target.h +1 -1
@@ -130,7 +130,7 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_DEFAULT_MO (0)#ifdef CONFIG_SOFTMMU -#define TCG_TARGET_NEED_LDST_LABELS +#define TCG_TARGET_NEED_LDST_OOL_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS
tcg/ppc/tcg-target.inc.c +140 -186
406 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 26/37 tcg: Clean up generic bswap32
In reply to Richard HendersonBased on the only current user, Sparc:
New code uses 1 constant that takes 2 insns to create, plus 8. Old code used 2 constants that took 2 insns to create, plus 9. The result is a new total of 10 vs an old total of 13.
--- tcg/tcg-op.c | 54 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-)
tcg/tcg-op.c +27 -27
@@ -1012,22 +1012,22 @@ void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)if (TCG_TARGET_HAS_bswap32_i32) {tcg_gen_op2_i32 (INDEX_op_bswap32_i32, ret, arg); }else { -TCGv_i32 t0, t1; - t0 =tcg_temp_new_i32 (); - t1 =tcg_temp_new_i32 (); +TCGv_i32 t0 =tcg_temp_new_i32 (); +TCGv_i32 t1 =tcg_temp_new_i32 (); +TCGv_i32 t2 =tcg_const_i32 (0x00ff00ff ); -tcg_gen_shli_i32 (t0, arg,24 ); +/* arg = abcd */ +tcg_gen_shri_i32 (t0, arg,8 );/* t0 = .abc */ +tcg_gen_and_i32 (t1, arg, t2);/* t1 = .b.d */ +tcg_gen_and_i32 (t0, t0, t2);/* t0 = .a.c */ +tcg_temp_free_i32 (t2); +tcg_gen_shli_i32 (t1, t1,8 );/* t1 = b.d. */ +tcg_gen_or_i32 (ret, t0, t1);/* ret = badc */ -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 (t0, ret,16 );/* t0 = ..ba */ +tcg_gen_shli_i32 (t1, ret,16 );/* t1 = dc.. */ +tcg_gen_or_i32 (ret, t0, t1);/* ret = dcba */ -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);tcg_temp_free_i32 (t0);tcg_temp_free_i32 (t1); }
@@ -1638,23 +1638,23 @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg) }else if (TCG_TARGET_HAS_bswap32_i64) {tcg_gen_op2_i64 (INDEX_op_bswap32_i64, ret, arg); }else { -TCGv_i64 t0, t1; - t0 =tcg_temp_new_i64 (); - t1 =tcg_temp_new_i64 (); +TCGv_i64 t0 =tcg_temp_new_i64 (); +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_const_i64 (0x00ff00ff ); -tcg_gen_shli_i64 (t0, arg,24 ); -tcg_gen_ext32u_i64 (t0, t0); +/* arg = ....abcd */ +tcg_gen_shri_i64 (t0, arg,8 );/* t0 = .....abc */ +tcg_gen_and_i64 (t1, arg, t2);/* t1 = .....b.d */ +tcg_gen_and_i64 (t0, t0, t2);/* t0 = .....a.c */ +tcg_temp_free_i64 (t2); +tcg_gen_shli_i64 (t1, t1,8 );/* t1 = ....b.d. */ +tcg_gen_or_i64 (ret, t0, t1);/* ret = ....badc */ -tcg_gen_andi_i64 (t1, arg,0x0000ff00 ); -tcg_gen_shli_i64 (t1, t1,8 ); -tcg_gen_or_i64 (t0, t0, t1); +tcg_gen_shli_i64 (t1, ret,48 );/* t1 = dc...... */ +tcg_gen_shri_i64 (t0, ret,16 );/* t0 = ......ba */ +tcg_gen_shri_i64 (t1, ret,32 );/* t1 = ....dc.. */ +tcg_gen_or_i64 (ret, t0, t1);/* ret = ....dcba */ -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); }
Signature · 1 line
2.17.2
PATCH v2 27/37 tcg: Clean up generic bswap64
In reply to Richard HendersonBased on the only current user, Sparc:
New code uses 2 constants that take 2 insns to load from constant pool, plus 13. Old code used 6 constants that took 1 or 2 insns to create, plus 21. The result is a new total of 17 vs an old total of 29.
--- tcg/tcg-op.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-)
tcg/tcg-op.c +18 -25
@@ -1678,37 +1678,30 @@ void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg) }else {TCGv_i64 t0 =tcg_temp_new_i64 ();TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); -tcg_gen_shli_i64 (t0, arg,56 ); +/* arg = abcdefgh */ +tcg_gen_movi_i64 (t2,0x00ff00ff00ff00ffull ); +tcg_gen_shri_i64 (t0, arg,8 );/* t0 = .abcdefg */ +tcg_gen_and_i64 (t1, arg, t2);/* t1 = .b.d.f.h */ +tcg_gen_and_i64 (t0, t0, t2);/* t0 = .a.c.e.g */ +tcg_gen_shli_i64 (t1, t1,8 );/* t1 = b.d.f.h. */ +tcg_gen_or_i64 (ret, t0, t1);/* ret = badcfehg */ -tcg_gen_andi_i64 (t1, arg,0x0000ff00 ); -tcg_gen_shli_i64 (t1, t1,40 ); -tcg_gen_or_i64 (t0, t0, t1); +tcg_gen_movi_i64 (t2,0x0000ffff0000ffffull ); +tcg_gen_shri_i64 (t0, ret,16 );/* t0 = ..badcfe */ +tcg_gen_and_i64 (t1, ret, t2);/* t1 = ..dc..hg */ +tcg_gen_and_i64 (t0, t0, t2);/* t0 = ..ba..fe */ +tcg_gen_shli_i64 (t1, t1,16 );/* t1 = dc..hg.. */ +tcg_gen_or_i64 (ret, t0, t1);/* ret = dcbahgfe */ -tcg_gen_andi_i64 (t1, arg,0x00ff0000 ); -tcg_gen_shli_i64 (t1, t1,24 ); -tcg_gen_or_i64 (t0, t0, t1); +tcg_gen_shri_i64 (t0, ret,32 );/* t0 = ....dcba */ +tcg_gen_shli_i64 (t1, ret,32 );/* t1 = hgfe.... */ +tcg_gen_or_i64 (ret, t0, t1);/* ret = hgfedcba */ -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);tcg_temp_free_i64 (t0);tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); } }
Signature · 1 line
2.17.2
PATCH v2 28/37 tcg/optimize: Optimize bswap
In reply to Richard HendersonSomehow we forgot these operations, once upon a time. This will allow immediate stores to have their bswap optimized away.
--- tcg/optimize.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tcg/optimize.c +12 -0
@@ -353,6 +353,15 @@ static TCGArg do_constant_folding_2(TCGOpcode op, TCGArg x, TCGArg y) CASE_OP_32_64(ext16u):return (uint16_t )x; + CASE_OP_32_64(bswap16): +return bswap16 (x); + + CASE_OP_32_64(bswap32): +return bswap32 (x); + +case INDEX_op_bswap64_i64: +return bswap64 (x); +case INDEX_op_ext_i32_i64:case INDEX_op_ext32s_i64:return (int32_t )x;
@@ -1105,6 +1114,9 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(ext16s): CASE_OP_32_64(ext16u): CASE_OP_32_64(ctpop): + CASE_OP_32_64(bswap16): + CASE_OP_32_64(bswap32): + case INDEX_op_bswap64_i64: case INDEX_op_ext32s_i64: case INDEX_op_ext32u_i64: case INDEX_op_ext_i32_i64:
Signature · 1 line
2.17.2
PATCH v2 29/37 tcg: Add TCG_TARGET_HAS_MEMORY_BSWAP
In reply to Richard HendersonFor now, defined universally as true, since we previously required backends to implement swapped memory operations. Future patches may now remove that support where it is onerous.
--- tcg/aarch64/tcg-target.h | 1 + tcg/arm/tcg-target.h | 1 + tcg/i386/tcg-target.h | 2 + tcg/mips/tcg-target.h | 1 + tcg/ppc/tcg-target.h | 1 + tcg/s390/tcg-target.h | 1 + tcg/sparc/tcg-target.h | 1 + tcg/tci/tcg-target.h | 2 + tcg/tcg-op.c | 118 ++++++++++++++++++++++++++++++++++++++- 9 files changed, 126 insertions(+), 2 deletions(-)
tcg/aarch64/tcg-target.h +1 -0
@@ -137,6 +137,7 @@ typedef enum {#define TCG_TARGET_HAS_mul_vec 1#define TCG_TARGET_DEFAULT_MO (0) +#define TCG_TARGET_HAS_MEMORY_BSWAP 1static inline void flush_icache_range (uintptr_t start,uintptr_t stop) {
tcg/arm/tcg-target.h +1 -0
@@ -131,6 +131,7 @@ enum { };#define TCG_TARGET_DEFAULT_MO (0) +#define TCG_TARGET_HAS_MEMORY_BSWAP 1static inline void flush_icache_range (uintptr_t start,uintptr_t stop) {
tcg/i386/tcg-target.h +2 -0
@@ -219,6 +219,8 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,#define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD) +#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_OOL_LABELS #endif
tcg/mips/tcg-target.h +1 -0
@@ -203,6 +203,7 @@ extern bool use_mips32r2_instructions;#endif #define TCG_TARGET_DEFAULT_MO (0) +#define TCG_TARGET_HAS_MEMORY_BSWAP 1static inline void flush_icache_range (uintptr_t start,uintptr_t stop) {
tcg/ppc/tcg-target.h +1 -0
@@ -128,6 +128,7 @@ void flush_icache_range(uintptr_t start, uintptr_t stop);void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_DEFAULT_MO (0) +#define TCG_TARGET_HAS_MEMORY_BSWAP 1#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_OOL_LABELS
tcg/s390/tcg-target.h +1 -0
@@ -135,6 +135,7 @@ extern uint64_t s390_facilities;#define TCG_TARGET_CALL_STACK_OFFSET 160#define TCG_TARGET_EXTEND_ARGS 1 +#define TCG_TARGET_HAS_MEMORY_BSWAP 1#define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD)
tcg/sparc/tcg-target.h +1 -0
@@ -164,6 +164,7 @@ extern bool use_vis3_instructions;#define TCG_AREG0 TCG_REG_I0#define TCG_TARGET_DEFAULT_MO (0) +#define TCG_TARGET_HAS_MEMORY_BSWAP 1static inline void flush_icache_range (uintptr_t start,uintptr_t stop) {
tcg/tci/tcg-target.h +2 -0
@@ -198,6 +198,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)We prefer consistency across hosts on this. */ #define TCG_TARGET_DEFAULT_MO (0) +#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_addr,uintptr_t addr) {
tcg/tcg-op.c +116 -2
165 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 30/37 tcg/i386: Adjust TCG_TARGET_HAS_MEMORY_BSWAP
In reply to Richard HendersonAlways true for softmmu and when movbe is available. In the softmmu case we always have call-clobbered scratch registers available, and having the bswap in the softmmu thunk maximizes code sharing.
For user-only and without movbe, leave this to generic code.
--- tcg/i386/tcg-target.h | 5 ++ tcg/i386/tcg-target.inc.c | 122 ++++++++++++++++++++++++-------------- 2 files changed, 82 insertions(+), 45 deletions(-)
tcg/i386/tcg-target.h +5 -0
@@ -101,6 +101,7 @@ extern bool have_bmi1;extern bool have_popcnt;extern bool have_avx1;extern bool have_avx2; +extern bool have_movbe;/* optional instructions */ #define TCG_TARGET_HAS_div2_i32 1
@@ -219,7 +220,11 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,#define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD) +#ifdef CONFIG_SOFTMMU #define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#else +#define TCG_TARGET_HAS_MEMORY_BSWAP have_movbe +#endif #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_OOL_LABELS
tcg/i386/tcg-target.inc.c +77 -45
235 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 31/37 tcg/aarch64: Set TCG_TARGET_HAS_MEMORY_BSWAP to false
In reply to Richard HendersonThis allows us to remove some code from the backend, allowing the generic code to emit any extra bswaps.
--- tcg/aarch64/tcg-target.h | 2 +- tcg/aarch64/tcg-target.inc.c | 51 +++++++----------------------------- 2 files changed, 10 insertions(+), 43 deletions(-)
tcg/aarch64/tcg-target.h +1 -1
@@ -137,7 +137,7 @@ typedef enum {#define TCG_TARGET_HAS_mul_vec 1#define TCG_TARGET_DEFAULT_MO (0) -#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#define TCG_TARGET_HAS_MEMORY_BSWAP 0static inline void flush_icache_range (uintptr_t start,uintptr_t stop) {
tcg/aarch64/tcg-target.inc.c +9 -42
107 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 32/37 tcg/arm: Set TCG_TARGET_HAS_MEMORY_BSWAP to false for user-only
In reply to Richard HendersonLetting the generic code emit any bswaps allows us to avoid reserving an extra register for CONFIG_USER_ONLY. For SOFTMMU, where we have free call-clobbered registers anyway, leaving the bswap in the out-of-line thunk maximizes code sharing.
--- tcg/arm/tcg-target.h | 4 ++ tcg/arm/tcg-target.inc.c | 129 +++++++++++++-------------------------- 2 files changed, 48 insertions(+), 85 deletions(-)
tcg/arm/tcg-target.h +4 -0
@@ -131,7 +131,11 @@ enum { };#define TCG_TARGET_DEFAULT_MO (0) +#ifdef CONFIG_SOFTMMU #define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#else +#define TCG_TARGET_HAS_MEMORY_BSWAP 0 +#endif static inline void flush_icache_range (uintptr_t start,uintptr_t stop) {
tcg/arm/tcg-target.inc.c +44 -85
278 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 33/37 tcg/i386: Propagate is64 to tcg_out_qemu_ld_direct
In reply to Richard HendersonThis can save a few rex prefixes for qemu_ld_i32.
--- tcg/i386/tcg-target.inc.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
tcg/i386/tcg-target.inc.c +13 -11
@@ -1815,10 +1815,11 @@ static inline void setup_guest_base_seg(void) { }static void tcg_out_qemu_ld_direct (TCGContext *s,TCGReg datalo,TCGReg datahi,TCGReg base,int index,intptr_t ofs, -int seg,TCGMemOp memop) +int seg,bool is64,TCGMemOp memop) {bool use_bswap = memop &MO_BSWAP ;bool use_movbe = false; +int rexw = is64 *P_REXW ;int movop = OPC_MOVL_GvEv;/*
@@ -1843,7 +1844,7 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi, base, index, 0, ofs);break ;case MO_SB : -tcg_out_modrm_sib_offset (s,OPC_MOVSBL +P_REXW + seg, datalo, +tcg_out_modrm_sib_offset (s,OPC_MOVSBL + rexw + seg, datalo, base, index,0 , ofs);break ;case MO_UW :
@@ -1871,14 +1872,15 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi,if (use_movbe) {tcg_out_modrm_sib_offset (s, OPC_MOVBE_GyMy +P_DATA16 + seg, datalo, base, index,0 , ofs); -tcg_out_ext16s (s, datalo, datalo,P_REXW ); - }else { -tcg_out_modrm_sib_offset (s,OPC_MOVSWL +P_REXW + seg, +tcg_out_ext16s (s, datalo, datalo, rexw); + }else if (use_bswap) { +tcg_out_modrm_sib_offset (s,OPC_MOVSWL + seg, + datalo, base, index,0 , ofs); +tcg_out_rolw_8 (s, datalo); +tcg_out_ext16s (s, datalo, datalo, rexw); + }else { +tcg_out_modrm_sib_offset (s,OPC_MOVSWL + rexw + seg, datalo, base, index,0 , ofs); -if (use_bswap) { -tcg_out_rolw_8 (s, datalo); -tcg_out_ext16s (s, datalo, datalo,P_REXW ); - } }break ;case MO_UL :
@@ -2004,7 +2006,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) }tcg_out_qemu_ld_direct (s, datalo, datahi, - base, index, offset, seg, opc); + base, index, offset, seg, is64, opc); }#endif }
@@ -2202,7 +2204,7 @@ static tcg_insn_unit *tcg_out_qemu_ldst_ool(TCGContext *s, bool is_ld,/* TLB Hit. */ if (is_ld) { -tcg_out_qemu_ld_direct (s, datalo, datahi, base,-1 ,0 ,0 , opc); +tcg_out_qemu_ld_direct (s, datalo, datahi, base,-1 ,0 ,0 , is_64, opc); }else {tcg_out_qemu_st_direct (s, datalo, datahi, base,0 ,0 , opc); }
Signature · 1 line
2.17.2
PATCH v2 34/37 tcg/i386: Restrict user-only qemu_st_i32 values to q-regs
In reply to Richard HendersonThis is one more step toward the removal of all scratch registers during user-only guest memory operations.
--- tcg/i386/tcg-target.inc.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
tcg/i386/tcg-target.inc.c +13 -10
@@ -240,7 +240,17 @@ static const char *constrain_memop_arg(QemuMemArgType type, bool is_64, int hi)#else static const char *constrain_memop_arg (QemuMemArgType type,bool is_64,int hi) { -return "L" ; +if (TCG_TARGET_REG_BITS ==64 ) { +/* Temps are still needed for guest_base && !guest_base_flags. */ +return "L" ; + }else if (type ==ARG_STVAL && !is_64) { +/* Byte stores must happen from q-regs. Because of this, we must +* constrain all INDEX_op_qemu_st_i32 to use q-regs. +*/ +return "q" ; + }else { +return "r" ; + } }#endif /* CONFIG_SOFTMMU */
@@ -2038,15 +2048,8 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg datalo, TCGReg datahi,switch (memop &MO_SIZE ) {case MO_8 : -/* -* In 32-bit mode, 8-bit stores can only happen from [abcd]x. -* ??? Adjust constraints such that this is is forced, then -* we won't need a scratch at all for user-only. -*/ -if (TCG_TARGET_REG_BITS ==32 && datalo >=4 ) { -tcg_out_mov (s,TCG_TYPE_I32 , scratch, datalo); - datalo = scratch; - } +/* In 32-bit mode, 8-bit stores can only happen from [abcd]x. */ +tcg_debug_assert (TCG_TARGET_REG_BITS ==64 || datalo <4 );tcg_out_modrm_offset (s, OPC_MOVB_EvGv +P_REXB_R + seg, datalo, base, ofs);break ;
Signature · 1 line
2.17.2
PATCH v2 35/37 tcg/i386: Add setup_guest_base_seg for FreeBSD
In reply to Richard Henderson--- tcg/i386/tcg-target.inc.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tcg/i386/tcg-target.inc.c +10 -0
@@ -1818,6 +1818,16 @@ static inline void setup_guest_base_seg(void) guest_base_flags = P_GS; } } +#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) +# include <machine/sysarch.h> + +static int guest_base_flags; +static inline void setup_guest_base_seg (void ) +{ +if (sysarch (AMD64_SET_GSBASE , &guest_base) ==0 ) { + guest_base_flags =P_GS ; + } +}#else # define guest_base_flags 0static inline void setup_guest_base_seg (void ) { }
Signature · 1 line
2.17.2
PATCH v2 36/37 tcg/i386: Require segment syscalls to succeed
In reply to Richard HendersonThere ought be no reason they should ever fail. If we don't know how to set a segment base register for user-only (NetBSD, OpenBSD?), then error out if we cannot proceed.
This is one more step toward the removal of all scratch registers during user-only guest memory operations.
--- tcg/i386/tcg-target.inc.c | 54 +++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 31 deletions(-)
tcg/i386/tcg-target.inc.c +23 -31
@@ -1814,9 +1814,12 @@ int arch_prctl(int code, unsigned long addr);static int guest_base_flags;static inline void setup_guest_base_seg (void ) { -if (arch_prctl (ARCH_SET_GS , guest_base) ==0 ) { - guest_base_flags =P_GS ; +/* There is no reason this syscall should fail. */ +if (arch_prctl (ARCH_SET_GS , guest_base) <0 ) { +perror ("arch_prctl(ARCH_SET_GS)" ); +exit (1 ); } + guest_base_flags =P_GS ; }#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)# include <machine/sysarch.h>
@@ -1824,13 +1827,28 @@ static inline void setup_guest_base_seg(void)static int guest_base_flags;static inline void setup_guest_base_seg (void ) { -if (sysarch (AMD64_SET_GSBASE , &guest_base) ==0 ) { - guest_base_flags =P_GS ; +/* There is no reason this syscall should fail. */ +if (sysarch (AMD64_SET_GSBASE , &guest_base) <0 ) { +perror ("sysarch(AMD64_SET_GSBASE)" ); +exit (1 ); } + guest_base_flags =P_GS ; }#else # define guest_base_flags 0 -static inline void setup_guest_base_seg (void ) { } +static inline void setup_guest_base_seg (void ) +{ +/* +* Verify we can proceed without scratch registers. +* If guest_base > INT32_MAX, then it would need to be loaded. +* If 32-bit guest, the address would need to be zero-extended. +*/ +if (TCG_TARGET_REG_BITS ==64 + && (TARGET_LONG_BITS ==32 || guest_base >INT32_MAX )) { +error_report ("Segment base register not supported on this OS" ); +exit (1 ); + } +}#endif /* SOFTMMU */ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi,
@@ -2013,16 +2031,6 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)if (TCG_TARGET_REG_BITS >TARGET_LONG_BITS ) { seg |=P_ADDR32 ; } - }else if (TCG_TARGET_REG_BITS ==64 ) { -if (TARGET_LONG_BITS ==32 ) { -tcg_out_ext32u (s,TCG_REG_L0 , base); - base =TCG_REG_L0 ; - } -if (offset != guest_base) { -tcg_out_movi (s,TCG_TYPE_I64 ,TCG_REG_L1 , guest_base); - index =TCG_REG_L1 ; - offset =0 ; - } } tcg_out_qemu_ld_direct(s, datalo, datahi,
@@ -2156,22 +2164,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)if (TCG_TARGET_REG_BITS >TARGET_LONG_BITS ) { seg |=P_ADDR32 ; } - }else if (TCG_TARGET_REG_BITS ==64 ) { -/* ??? Note that we can't use the same SIB addressing scheme -as for loads, since we require L0 free for bswap. */ -if (offset != guest_base) { -if (TARGET_LONG_BITS ==32 ) { -tcg_out_ext32u (s,TCG_REG_L0 , base); - base =TCG_REG_L0 ; - } -tcg_out_movi (s,TCG_TYPE_I64 ,TCG_REG_L1 , guest_base); -tgen_arithr (s,ARITH_ADD +P_REXW ,TCG_REG_L1 , base); - base =TCG_REG_L1 ; - offset =0 ; - }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);
Signature · 1 line
2.17.2
PATCH v2 37/37 tcg/i386: Remove L constraint
In reply to Richard HendersonWe no longer need any scratch registers for user-only memory ops.
--- tcg/i386/tcg-target.inc.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
tcg/i386/tcg-target.inc.c +1 -12
@@ -240,10 +240,7 @@ static const char *constrain_memop_arg(QemuMemArgType type, bool is_64, int hi)#else static const char *constrain_memop_arg (QemuMemArgType type,bool is_64,int hi) { -if (TCG_TARGET_REG_BITS ==64 ) { -/* Temps are still needed for guest_base && !guest_base_flags. */ -return "L" ; - }else if (type ==ARG_STVAL && !is_64) { +if (TCG_TARGET_REG_BITS ==32 && type ==ARG_STVAL && !is_64) {/* Byte stores must happen from q-regs. Because of this, we must * constrain all INDEX_op_qemu_st_i32 to use q-regs. */
@@ -353,14 +350,6 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, ct->u.regs |=ALL_VECTOR_REGS ;break ; -/* qemu_ld/st address constraint */ -case 'L' : - ct->ct |=TCG_CT_REG ; - ct->u.regs =TCG_TARGET_REG_BITS ==64 ?0xffff :0xff ; -tcg_regset_reset_reg (ct->u.regs,TCG_REG_L0 ); -tcg_regset_reset_reg (ct->u.regs,TCG_REG_L1 ); -break ; -case 'e' : ct->ct |= (type ==TCG_TYPE_I32 ?TCG_CT_CONST :TCG_CT_CONST_S32 );break ;
Signature · 1 line
2.17.2
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Message-id: [email protected]
Type: series
Subject: [Qemu-devel] [PATCH for-4.0 v2 00/37] tcg: Assorted cleanups
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
fc046e8 tcg/i386: Remove L constraint
25a6e0e tcg/i386: Require segment syscalls to succeed 5e0fd5d tcg/i386: Add setup_guest_base_seg for FreeBSD d68fe20 tcg/i386: Restrict user-only qemu_st_i32 values to q-regs 85fcd2d tcg/i386: Propagate is64 to tcg_out_qemu_ld_direct a3178a9 tcg/arm: Set TCG_TARGET_HAS_MEMORY_BSWAP to false for user-only 4d0c5fc tcg/aarch64: Set TCG_TARGET_HAS_MEMORY_BSWAP to false 676c67e tcg/i386: Adjust TCG_TARGET_HAS_MEMORY_BSWAP
38c85b7 tcg: Add TCG_TARGET_HAS_MEMORY_BSWAP
d3a1899 tcg/optimize: Optimize bswap
3ad8388 tcg: Clean up generic bswap64
affd2d8 tcg: Clean up generic bswap32
fd89430 tcg/ppc: Use TCG_TARGET_NEED_LDST_OOL_LABELS
8aa5784 tcg/ppc: Force qemu_ld/st arguments into fixed registers af59cb6 tcg/ppc: Change TCG_TARGET_CALL_ALIGN_ARGS to bool 26bfc9a tcg/ppc: Add constraints for R7-R8
6cd8567 tcg/ppc: Split out tcg_out_call_int
d40e505 tcg/ppc: Parameterize the temps for tcg_out_tlb_read acfcb89 tcg/arm: Use TCG_TARGET_NEED_LDST_OOL_LABELS
5516052 tcg/arm: Force qemu_ld/st arguments into fixed registers 46ad1f6 tcg/arm: Reduce the number of temps for tcg_out_tlb_read 24abc30 tcg/arm: Add constraints for R0-R5
94b24c4 tcg/arm: Parameterize the temps for tcg_out_tlb_read 91b0db1 tcg/aarch64: Use TCG_TARGET_NEED_LDST_OOL_LABELS 7129f8e tcg/aarch64: Use B not BL for tcg_out_goto_long c770cee tcg/aarch64: Parameterize the temp for tcg_out_goto_long 412bf17 tcg/aarch64: Parameterize the temps for tcg_out_tlb_read 2ffa3ee tcg/aarch64: Add constraints for x0, x1, x2
a403293 tcg/i386: Use TCG_TARGET_NEED_LDST_OOL_LABELS a65b8a9 tcg/i386: Force qemu_ld/st arguments into fixed registers 4053d4c tcg/i386: Change TCG_REG_L[01] to not overlap function arguments c9e6cd5 tcg/i386: Return a base register from tcg_out_tlb_load a601058 tcg/i386: Add constraints for r8 and r9
41701df tcg: Add TCG_TARGET_NEED_LDST_OOL_LABELS
fdb09e0 tcg: Return success from patch_reloc
8dab265 tcg/i386: Move TCG_REG_CALL_STACK from define to enum 58990b6 tcg/i386: Always use %ebp for TCG_AREG0
=== OUTPUT BEGIN ===
Checking PATCH 1/37: tcg/i386: Always use %ebp for TCG_AREG0... Checking PATCH 2/37: tcg/i386: Move TCG_REG_CALL_STACK from define to enum... Checking PATCH 3/37: tcg: Return success from patch_reloc... Checking PATCH 4/37: tcg: Add TCG_TARGET_NEED_LDST_OOL_LABELS...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #47:
new file mode 100644
total: 0 errors, 1 warnings, 192 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 5/37: tcg/i386: Add constraints for r8 and r9...
Checking PATCH 6/37: tcg/i386: Return a base register from tcg_out_tlb_load... Checking PATCH 7/37: tcg/i386: Change TCG_REG_L[01] to not overlap function arguments... Checking PATCH 8/37: tcg/i386: Force qemu_ld/st arguments into fixed registers... Checking PATCH 9/37: tcg/i386: Use TCG_TARGET_NEED_LDST_OOL_LABELS... Checking PATCH 10/37: tcg/aarch64: Add constraints for x0, x1, x2... Checking PATCH 11/37: tcg/aarch64: Parameterize the temps for tcg_out_tlb_read... Checking PATCH 12/37: tcg/aarch64: Parameterize the temp for tcg_out_goto_long... Checking PATCH 13/37: tcg/aarch64: Use B not BL for tcg_out_goto_long... Checking PATCH 14/37: tcg/aarch64: Use TCG_TARGET_NEED_LDST_OOL_LABELS... Checking PATCH 15/37: tcg/arm: Parameterize the temps for tcg_out_tlb_read... Checking PATCH 16/37: tcg/arm: Add constraints for R0-R5...
Checking PATCH 17/37: tcg/arm: Reduce the number of temps for tcg_out_tlb_read... Checking PATCH 18/37: tcg/arm: Force qemu_ld/st arguments into fixed registers... Checking PATCH 19/37: tcg/arm: Use TCG_TARGET_NEED_LDST_OOL_LABELS...
ERROR: externs should be avoided in .c files
#169: FILE: tcg/arm/tcg-target.inc.c:1483:
+ TCGReg addrlo __attribute__((unused));
ERROR: externs should be avoided in .c files
#170: FILE: tcg/arm/tcg-target.inc.c:1484:
+ TCGReg addrhi __attribute__((unused));
ERROR: externs should be avoided in .c files
#171: FILE: tcg/arm/tcg-target.inc.c:1485:
+ TCGReg datalo __attribute__((unused));
ERROR: externs should be avoided in .c files
#172: FILE: tcg/arm/tcg-target.inc.c:1486:
+ TCGReg datahi __attribute__((unused));
ERROR: externs should be avoided in .c files
#224: FILE: tcg/arm/tcg-target.inc.c:1602:
+ TCGReg addrlo __attribute__((unused));
ERROR: externs should be avoided in .c files
#225: FILE: tcg/arm/tcg-target.inc.c:1603:
+ TCGReg addrhi __attribute__((unused));
ERROR: externs should be avoided in .c files
#226: FILE: tcg/arm/tcg-target.inc.c:1604:
+ TCGReg datalo __attribute__((unused));
ERROR: externs should be avoided in .c files
#227: FILE: tcg/arm/tcg-target.inc.c:1605:
+ TCGReg datahi __attribute__((unused));
total: 8 errors, 0 warnings, 368 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 20/37: tcg/ppc: Parameterize the temps for tcg_out_tlb_read... Checking PATCH 21/37: tcg/ppc: Split out tcg_out_call_int... Checking PATCH 22/37: tcg/ppc: Add constraints for R7-R8...
Checking PATCH 23/37: tcg/ppc: Change TCG_TARGET_CALL_ALIGN_ARGS to bool... Checking PATCH 24/37: tcg/ppc: Force qemu_ld/st arguments into fixed registers...
ERROR: do not initialise statics to 0 or NULL
#52: FILE: tcg/ppc/tcg-target.inc.c:1749:
+ static bool is_be = false;
total: 1 errors, 0 warnings, 207 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 25/37: tcg/ppc: Use TCG_TARGET_NEED_LDST_OOL_LABELS...
ERROR: externs should be avoided in .c files
#262: FILE: tcg/ppc/tcg-target.inc.c:1690:
+ TCGReg datalo __attribute__((unused));
ERROR: externs should be avoided in .c files
#263: FILE: tcg/ppc/tcg-target.inc.c:1691:
+ TCGReg datahi __attribute__((unused));
ERROR: externs should be avoided in .c files
#264: FILE: tcg/ppc/tcg-target.inc.c:1692:
+ TCGReg addrlo __attribute__((unused));
ERROR: externs should be avoided in .c files
#322: FILE: tcg/ppc/tcg-target.inc.c:1748:
+ TCGReg datalo __attribute__((unused));
ERROR: externs should be avoided in .c files
#323: FILE: tcg/ppc/tcg-target.inc.c:1749:
+ TCGReg datahi __attribute__((unused));
ERROR: externs should be avoided in .c files
#324: FILE: tcg/ppc/tcg-target.inc.c:1750:
+ TCGReg addrlo __attribute__((unused));
ERROR: externs should be avoided in .c files
#325: FILE: tcg/ppc/tcg-target.inc.c:1751:
+ TCGReg addrhi __attribute__((unused));
total: 7 errors, 0 warnings, 414 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 26/37: tcg: Clean up generic bswap32... Checking PATCH 27/37: tcg: Clean up generic bswap64... Checking PATCH 28/37: tcg/optimize: Optimize bswap...
ERROR: spaces required around that ':' (ctx:VxE) #21: FILE: tcg/optimize.c:356:
+ CASE_OP_32_64(bswap16):
^
ERROR: spaces required around that ':' (ctx:VxE)
#24: FILE: tcg/optimize.c:359:
+ CASE_OP_32_64(bswap32):
^
ERROR: spaces required around that ':' (ctx:VxE)
#37: FILE: tcg/optimize.c:1117:
+ CASE_OP_32_64(bswap16):
^
ERROR: spaces required around that ':' (ctx:VxE)
#38: FILE: tcg/optimize.c:1118:
+ CASE_OP_32_64(bswap32):
^
total: 4 errors, 0 warnings, 24 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 29/37: tcg: Add TCG_TARGET_HAS_MEMORY_BSWAP...
Checking PATCH 30/37: tcg/i386: Adjust TCG_TARGET_HAS_MEMORY_BSWAP... Checking PATCH 31/37: tcg/aarch64: Set TCG_TARGET_HAS_MEMORY_BSWAP to false... Checking PATCH 32/37: tcg/arm: Set TCG_TARGET_HAS_MEMORY_BSWAP to false for user-only...
ERROR: space prohibited after that '&' (ctx:WxW)
#206: FILE: tcg/arm/tcg-target.inc.c:1525:
+ && (datalo & 1) == 0 && datahi == datalo + 1) {
^total: 1 errors, 0 warnings, 289 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 33/37: tcg/i386: Propagate is64 to tcg_out_qemu_ld_direct... Checking PATCH 34/37: tcg/i386: Restrict user-only qemu_st_i32 values to q-regs... Checking PATCH 35/37: tcg/i386: Add setup_guest_base_seg for FreeBSD...
ERROR: space prohibited between function name and open parenthesis '(' #17: FILE: tcg/i386/tcg-target.inc.c:1821:
+#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
ERROR: space prohibited between function name and open parenthesis '(' #17: FILE: tcg/i386/tcg-target.inc.c:1821:
+#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
total: 2 errors, 0 warnings, 16 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 36/37: tcg/i386: Require segment syscalls to succeed... Checking PATCH 37/37: tcg/i386: Remove L constraint...
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 2 lines · Richard Henderson
This includes everything queued so far -- softmmu out-of-line patches
for patches 1-9.
I am sad to report that on a Skylake host, this series gives a ~10% average slowdown for x86_64-softmmu SPEC06int (I'm reporting speedup, so <1 means slowdown):
https://imgur.com/a/25iu8Yl
Turns out that despite the higher icache hit, the IPC ends up being lower. For instance, here are perf counts when running hmmer x3 right after booting up (bootup is included in the counts, but hmmer is run 3 times in a row):
- Before:
249,392,070,159 cycles
781,327,593,681 instructions # 3.13 insn per cycle
85,914,418,873 branches
242,572,820 branch-misses # 0.28% of all branches
1,567,954,032 L1-icache-load-misses70.559864567 seconds time elapsed
- After:
277,806,651,701 cycles
813,619,725,225 instructions # 2.93 insn per cycle
132,453,633,831 branches
306,969,989 branch-misses # 0.23% of all branches
1,250,619,057 L1-icache-load-misses78.420517079 seconds time elapsed
On the bright side, in an older system (Sandy Bridge), I get a fairly neutral average perf impact, with some workloads speeding up and others slowing down:
https://imgur.com/a/AokDbkm
(Note that v1 of this series gave an overall slowdown, so that's progress.)
Given the above, perhaps the best way forward is to add a configure flag to disable OOL thunks, unless you have any further optimizations coming up.
Thanks,
Emilio