tcp/mips: Change TCG_AREG0 (fp -> s0)
PATCH 1/1 tcp/mips: Change TCG_AREG0 (fp -> s0)
Register fp is a bad choice for compilations without optimisation, because the compiler makes heavy use of this register (so the resulting code crashes).
Register s0 was used for TCG_AREG1 in earlier releases, but was no longer used and is now free for TCG_AREG0.
The resulting code works for compilations without optimisation (tested with qemu mips in qemu mips on x86 host).
--- dyngen-exec.h | 2 +- tcg/mips/tcg-target.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
dyngen-exec.h +1 -1
@@ -61,7 +61,7 @@ extern int printf(const char *, ...);#elif defined(__hppa__)#define AREG0 "r17"#elif defined(__mips__) -#define AREG0 "fp" +#define AREG0 "s0"#elif defined(__sparc__)#ifdef CONFIG_SOLARIS #define AREG0 "g2"
tcg/mips/tcg-target.h +1 -1
@@ -97,7 +97,7 @@ enum {#undef TCG_TARGET_HAS_ext16u_i32/* andi rt, rs, 0xffff */ /* Note: must be synced with dyngen-exec.h */ -#define TCG_AREG0 TCG_REG_FP +#define TCG_AREG0 TCG_REG_S0/* guest base is supported */ #define TCG_TARGET_HAS_GUEST_BASE
Signature · 1 line
1.5.6.5
Quoted 3 lines · Stefan Weil
Register fp is a bad choice for compilations without optimisation, because the compiler makes heavy use of this register (so the resulting code crashes).
I don't fully understand why the compiler makes use of this register in code where env is declared as register fp.
Quoted 6 lines
Register s0 was used for
TCG_AREG1in earlier releases, but was no longer used and is now free forTCG_AREG0.The resulting code works for compilations without optimisation (tested with qemu mips in qemu mips on x86 host).
The patch is not complete, at least some changes are missing to tcg_target_callee_save_regs.
Quoted 37 lines
Cc Aurelien Jarno <[email protected]>Signed-off-by Stefan Weil <[email protected]>--- dyngen-exec.h | 2 +- tcg/mips/tcg-target.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)dyngen-exec.h +1
-1@@ -61,7 +61,7 @@ extern int printf(const char *, ...);#elif defined(__hppa__)#define AREG0 "r17"#elif defined(__mips__) -#define AREG0 "fp" +#define AREG0 "s0"#elif defined(__sparc__)#ifdef CONFIG_SOLARIS #define AREG0 "g2"tcg/mips/tcg-target.h +1
-1@@ -97,7 +97,7 @@ enum {#undef TCG_TARGET_HAS_ext16u_i32/* andi rt, rs, 0xffff */ /* Note: must be synced with dyngen-exec.h */ -#define TCG_AREG0 TCG_REG_FP +#define TCG_AREG0 TCG_REG_S0/* guest base is supported */ #define TCG_TARGET_HAS_GUEST_BASE Signature · 1 line
1.5.6.5
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 7 lines · Stefan Weil
Quoted 3 lines
Register fp is a bad choice for compilations without optimisation, because the compiler makes heavy use of this register (so the resulting code crashes).
I don't fully understand why the compiler makes use of this register in code where env is declared as register fp.
The frame pointer (and certain other registers, typically stack pointer, link register, PIC base, TLS base, etc.) are special. They have predefined uses, usually specified by the relevant platform ABI.
Defining a global register variable (or using -ffixed-reg) only excludes these registers from general register allocation. It does not prevent them being used for specific purposes. The user is responsible for ensuring that any assumptions/requirements made by the ABI are still met.
In some cases gcc can diagnose invalid uses. In others the overlap may be legitimate, but not necessarily what we intended in qemu.
Paul
Quoted 10 lines · Aurelien Jarno
Quoted 4 lines · Stefan Weil
Register fp is a bad choice for compilations without optimisation, because the compiler makes heavy use of this register (so the resulting code crashes).
I don't fully understand why the compiler makes use of this register in code where env is declared as register fp.
fp = frame pointer is special. See Paul's answer.
Quoted 4 lines
Quoted 4 lines
Register s0 was used for
TCG_AREG1in earlier releases, but was no longer used and is now free forTCG_AREG0.
Quoted 8 lines
Quoted 4 lines
The resulting code works for compilations without optimisation (tested with qemu mips in qemu mips on x86 host).
The patch is not complete, at least some changes are missing to
tcg_target_callee_save_regs.
Thanks. I'll send an updated patch.
Regards, Stefan
PATCH 1/1 tcp/mips: Change TCG_AREG0 (fp -> s0)
Register fp (frame pointer) is a bad choice for compilations without optimisation, because the compiler makes heavy use of this register (so the resulting code crashes).
Register s0 was used for TCG_AREG1 in earlier releases, but was no longer used and is now free for TCG_AREG0.
The resulting code works for compilations without optimisation (tested with qemu mips in qemu mips on x86 host).
v2:
* Remove s0 from tcg_target_callee_save_regs and add fp there. Hint from Aurelien Jarno, thanks.
* Add fp to list of reserved registers.
--- dyngen-exec.h | 2 +- tcg/mips/tcg-target.c | 6 ++++-- tcg/mips/tcg-target.h | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
dyngen-exec.h +1 -1
@@ -61,7 +61,7 @@ extern int printf(const char *, ...);#elif defined(__hppa__)#define AREG0 "r17"#elif defined(__mips__) -#define AREG0 "fp" +#define AREG0 "s0"#elif defined(__sparc__)#ifdef CONFIG_SOLARIS #define AREG0 "g2"
tcg/mips/tcg-target.c +4 -2
@@ -1450,7 +1450,9 @@ static const TCGTargetOpDef mips_op_defs[] = { };static int tcg_target_callee_save_regs[] = { +#if 0 /* used for the global env (TCG_AREG0), so no need to save */TCG_REG_S0 , +#endifTCG_REG_S1 ,TCG_REG_S2 ,TCG_REG_S3 ,
@@ -1459,8 +1461,7 @@ static int tcg_target_callee_save_regs[] = {TCG_REG_S6 ,TCG_REG_S7 ,TCG_REG_GP , -/* TCG_REG_FP, */ /* currently used for the global env, so np -need to save */ +TCG_REG_FP , TCG_REG_RA, /* should be last for ABI compliance */ };
@@ -1524,6 +1525,7 @@ void tcg_target_init(TCGContext *s)tcg_regset_set_reg (s->reserved_regs,TCG_REG_AT );/* internal use */ tcg_regset_set_reg (s->reserved_regs,TCG_REG_T0 );/* internal use */ tcg_regset_set_reg (s->reserved_regs,TCG_REG_RA );/* return address */ +tcg_regset_set_reg (s->reserved_regs,TCG_REG_FP );/* frame pointer */ tcg_regset_set_reg (s->reserved_regs,TCG_REG_SP );/* stack pointer */ tcg_add_target_add_op_defs (mips_op_defs);
tcg/mips/tcg-target.h +1 -1
@@ -97,7 +97,7 @@ enum {#undef TCG_TARGET_HAS_ext16u_i32/* andi rt, rs, 0xffff */ /* Note: must be synced with dyngen-exec.h */ -#define TCG_AREG0 TCG_REG_FP +#define TCG_AREG0 TCG_REG_S0/* guest base is supported */ #define TCG_TARGET_HAS_GUEST_BASE
Signature · 1 line
1.7.0
Quoted 1 line · Stefan Weil
* Add fp to list of reserved registers.
This is unnecessary. The register is not a frame pointer within tcg generated code. It's available for use as a call-saved register.
r~
PATCH 1/1 tcp/mips: Change TCG_AREG0 (fp -> s0)
Register fp (frame pointer) is a bad choice for compilations without optimisation, because the compiler makes heavy use of this register (so the resulting code crashes).
Register s0 had been used for TCG_AREG1 in earlier releases, but was no longer used and is now free for TCG_AREG0.
The resulting code works for compilations without optimisation (tested with qemu mips in qemu mips on x86 host).
v2:
* Remove s0 from tcg_target_callee_save_regs and add fp there. Hint from Aurelien Jarno, thanks.
* Add fp to list of reserved registers.
v3:
* Don't add fp to list of reserved registers
Thanks to Richard Henderson.
* Remove s0 from tcg_target_reg_alloc_order.
--- dyngen-exec.h | 2 +- tcg/mips/tcg-target.c | 7 +++++-- tcg/mips/tcg-target.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-)
dyngen-exec.h +1 -1
@@ -59,7 +59,7 @@ extern int printf(const char *, ...);#elif defined(__hppa__)#define AREG0 "r17"#elif defined(__mips__) -#define AREG0 "fp" +#define AREG0 "s0"#elif defined(__sparc__)#ifdef CONFIG_SOLARIS #define AREG0 "g2"
tcg/mips/tcg-target.c +5 -2
@@ -69,7 +69,9 @@ static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {/* check if we really need so many registers :P */ static const int tcg_target_reg_alloc_order[] = { +#if 0 /* used for the global env (TCG_AREG0), so don't use it here */TCG_REG_S0 , +#endifTCG_REG_S1 ,TCG_REG_S2 ,TCG_REG_S3 ,
@@ -1450,7 +1452,9 @@ static const TCGTargetOpDef mips_op_defs[] = { };static int tcg_target_callee_save_regs[] = { +#if 0 /* used for the global env (TCG_AREG0), so no need to save */TCG_REG_S0 , +#endifTCG_REG_S1 ,TCG_REG_S2 ,TCG_REG_S3 ,
@@ -1459,8 +1463,7 @@ static int tcg_target_callee_save_regs[] = {TCG_REG_S6 ,TCG_REG_S7 ,TCG_REG_GP , -/* TCG_REG_FP, */ /* currently used for the global env, so np -need to save */ +TCG_REG_FP , TCG_REG_RA, /* should be last for ABI compliance */ };
tcg/mips/tcg-target.h +1 -1
@@ -97,7 +97,7 @@ enum {#undef TCG_TARGET_HAS_ext16u_i32/* andi rt, rs, 0xffff */ /* Note: must be synced with dyngen-exec.h */ -#define TCG_AREG0 TCG_REG_FP +#define TCG_AREG0 TCG_REG_S0/* guest base is supported */ #define TCG_TARGET_HAS_GUEST_BASE
Signature · 1 line
1.7.0
Quoted 52 lines · Stefan Weil
Register fp (frame pointer) is a bad choice for compilations without optimisation, because the compiler makes heavy use of this register (so the resulting code crashes).
Register s0 had been used for
TCG_AREG1in earlier releases, but was no longer used and is now free forTCG_AREG0.The resulting code works for compilations without optimisation (tested with qemu mips in qemu mips on x86 host).
v2:
* Remove s0 from
tcg_target_callee_save_regsand add fp there. Hint from Aurelien Jarno, thanks.* Add fp to list of reserved registers.
v3:
* Don't add fp to list of reserved registers
Thanks to Richard Henderson.* Remove s0 from
tcg_target_reg_alloc_order.Cc Aurelien Jarno <[email protected]>Cc Richard Henderson <[email protected]>Signed-off-by Stefan Weil <[email protected]>--- dyngen-exec.h | 2 +- tcg/mips/tcg-target.c | 7 +++++-- tcg/mips/tcg-target.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-)dyngen-exec.h +1
-1@@ -59,7 +59,7 @@ extern int printf(const char *, ...);#elif defined(__hppa__)#define AREG0 "r17"#elif defined(__mips__) -#define AREG0 "fp" +#define AREG0 "s0"#elif defined(__sparc__)#ifdef CONFIG_SOLARIS #define AREG0 "g2"tcg/mips/tcg-target.c +0
-0
tcg/mips/tcg-target.c static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { · line 74
Quoted 6 lines
tcg/mips/tcg-target.c +2
-0@@ -69,7 +69,9 @@ static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {/* check if we really need so many registers :P */ static const int tcg_target_reg_alloc_order[] = { +#if 0 /* used for the global env (TCG_AREG0), so don't use it here */TCG_REG_S0 , +#endif
This is not something necessary. The fact this register is declared as TCG_AREG0, will make TCG skip this automatically.
Quoted 40 lines
tcg/mips/tcg-target.c +3
-2TCG_REG_S1 ,TCG_REG_S2 , TCG_REG_S3,@@ -1450,7 +1452,9 @@ static const TCGTargetOpDef mips_op_defs[] = { };static int tcg_target_callee_save_regs[] = { +#if 0 /* used for the global env (TCG_AREG0), so no need to save */TCG_REG_S0 , +#endifTCG_REG_S1 ,TCG_REG_S2 ,TCG_REG_S3 ,@@ -1459,8 +1463,7 @@ static int tcg_target_callee_save_regs[] = {TCG_REG_S6 ,TCG_REG_S7 ,TCG_REG_GP , -/* TCG_REG_FP, */ /* currently used for the global env, so np -need to save */ +TCG_REG_FP , TCG_REG_RA, /* should be last for ABI compliance */ };tcg/mips/tcg-target.h +1
-1@@ -97,7 +97,7 @@ enum {#undef TCG_TARGET_HAS_ext16u_i32/* andi rt, rs, 0xffff */ /* Note: must be synced with dyngen-exec.h */ -#define TCG_AREG0 TCG_REG_FP +#define TCG_AREG0 TCG_REG_S0/* guest base is supported */ #define TCG_TARGET_HAS_GUEST_BASE Signature · 1 line
1.7.0
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net