target-alpha PALcode improvements
cover target-alpha PALcode improvements
Rather than copying around a block of 8 registers when we swap modes, let the translator map code generated for PALmode to the shadow regs directly. This simplifies PALmode entry and exit sufficiently to allow these insns to be performed inline.
Sadly, the speedup for this is in the noise. But I still think it makes sense.
r~
Richard Henderson (3):
target-alpha: Use separate TCGv temporaries for the shadow registers
target-alpha: Inline call_pal
target-alpha: Inline hw_ret
target-alpha/cpu.h | 3 +- target-alpha/gdbstub.c | 4 +- target-alpha/helper.c | 63 ++++++--------- target-alpha/helper.h | 3 - target-alpha/machine.c | 4 +- target-alpha/sys_helper.c | 22 ----- target-alpha/translate.c | 201 ++++++++++++++++++++++++++++++---------------- 7 files changed, 166 insertions(+), 134 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/3 target-alpha: Use separate TCGv temporaries for the shadow registers
This avoids having to manually swap them around when swapping to and from PALmode. We simply encode the shadow registers into the translation.
The VMStateDescription version changes, because the meaning of "shadow" changes in the save file when in PALmode. It would be possible to fix this, but I don't think it's worth the effort.
--- target-alpha/cpu.h | 3 +- target-alpha/gdbstub.c | 4 +- target-alpha/helper.c | 63 ++++++++----------- target-alpha/machine.c | 4 +- target-alpha/sys_helper.c | 10 +-- target-alpha/translate.c | 153 ++++++++++++++++++++++++++++++---------------- 6 files changed, 134 insertions(+), 103 deletions(-)
target-alpha/cpu.h +2 -1
@@ -445,8 +445,9 @@ void QEMU_NORETURN arith_excp(CPUAlphaState *, uintptr_t, int, uint64_t);uint64_t cpu_alpha_load_fpcr (CPUAlphaState *env);void cpu_alpha_store_fpcr (CPUAlphaState *env,uint64_t val); +uint64_t cpu_alpha_load_gr (CPUAlphaState *env,unsigned reg); +void cpu_alpha_store_gr (CPUAlphaState *env,unsigned reg,uint64_t val);#ifndef CONFIG_USER_ONLY -void swap_shadow_regs (CPUAlphaState *env); QEMU_NORETURN void alpha_cpu_unassigned_access(CPUState *cpu, hwaddr addr,bool is_write,bool is_exec,int unused,unsigned size);
target-alpha/gdbstub.c +2 -2
@@ -30,7 +30,7 @@ int alpha_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)switch (n) { case 0 ... 30: - val = env->ir[n]; + val =cpu_alpha_load_gr (env, n);break ; case 32 ... 62: d.d = env->fir[n -32 ];
@@ -66,7 +66,7 @@ int alpha_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)switch (n) { case 0 ... 30: - env->ir[n] = tmp; +cpu_alpha_store_gr (env, n, tmp);break ; case 32 ... 62: d.ll = tmp;
target-alpha/helper.c +26 -37
87 lines not on this page · raw message
target-alpha/machine.c +2 -2
@@ -70,8 +70,8 @@ static VMStateField vmstate_env_fields[] = {static const VMStateDescription vmstate_env = { .name ="env" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = vmstate_env_fields, };
target-alpha/sys_helper.c +2 -8
@@ -45,10 +45,7 @@ void helper_hw_ret(CPUAlphaState *env, uint64_t a) env->pc = a & ~3 ; env->intr_flag =0 ; env->lock_addr =-1 ; -if ((a &1 ) ==0 ) { - env->pal_mode =0 ; -swap_shadow_regs (env); - } + env->pal_mode = a &1 ; }void helper_call_pal (CPUAlphaState *env,uint64_t pc,uint64_t entry_ofs)
@@ -56,10 +53,7 @@ void helper_call_pal(CPUAlphaState *env, uint64_t pc, uint64_t entry_ofs)int pal_mode = env->pal_mode; env->exc_addr = pc | pal_mode; env->pc = env->palbr + entry_ofs; -if (!pal_mode) { - env->pal_mode =1 ; -swap_shadow_regs (env); - } + env->pal_mode =1 ; }void helper_tbia (CPUAlphaState *env)
target-alpha/translate.c +100 -53
350 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 2/3 target-alpha: Inline call_pal
In reply to Richard Henderson--- target-alpha/helper.h | 1 - target-alpha/sys_helper.c | 8 -------- target-alpha/translate.c | 33 ++++++++++++++++++++++++--------- 3 files changed, 24 insertions(+), 18 deletions(-)
target-alpha/helper.h +0 -1
@@ -92,7 +92,6 @@ DEF_HELPER_FLAGS_2(ieee_input_s, TCG_CALL_NO_WG, void, env, i64)#if !defined (CONFIG_USER_ONLY ) DEF_HELPER_2(hw_ret, void, env, i64) -DEF_HELPER_3(call_pal, void, env, i64, i64) DEF_HELPER_2(ldl_phys, i64, env, i64)DEF_HELPER_2 (ldq_phys, i64, env, i64)
target-alpha/sys_helper.c +0 -8
@@ -48,14 +48,6 @@ void helper_hw_ret(CPUAlphaState *env, uint64_t a) env->pal_mode = a &1 ; } -void helper_call_pal (CPUAlphaState *env,uint64_t pc,uint64_t entry_ofs) -{ -int pal_mode = env->pal_mode; - env->exc_addr = pc | pal_mode; - env->pc = env->palbr + entry_ofs; - env->pal_mode =1 ; -} -void helper_tbia (CPUAlphaState *env) {tlb_flush (CPU (alpha_env_get_cpu (env)),1 );
target-alpha/translate.c +24 -9
@@ -42,6 +42,9 @@ typedef struct DisasContext DisasContext;struct DisasContext {struct TranslationBlock *tb;uint64_t pc; +#ifndef CONFIG_USER_ONLY +uint64_t palbr; +#endif int mem_idx;/* Current rounding mode for this TB. */
@@ -1206,15 +1209,24 @@ static ExitStatus gen_call_pal(DisasContext *ctx, int palcode)return gen_excp (ctx,EXCP_CALL_PAL , palcode);#else { -TCGv pc =tcg_const_i64 (ctx->pc); -TCGv entry =tcg_const_i64 (palcode &0x80 - ?0x2000 + (palcode -0x80 ) *64 - :0x1000 + palcode *64 ); +TCGv tmp =tcg_temp_new (); +uint64_t exc_addr = ctx->pc; +uint64_t entry = ctx->palbr; + +if (ctx->tb->flags &TB_FLAGS_PAL_MODE ) { + exc_addr |=1 ; + }else { +tcg_gen_movi_i64 (tmp,1 ); +tcg_gen_st8_i64 (tmp, cpu_env, offsetof(CPUAlphaState , pal_mode)); + } -gen_helper_call_pal (cpu_env, pc, entry); +tcg_gen_movi_i64 (tmp, exc_addr); +tcg_gen_st_i64 (tmp, cpu_env, offsetof(CPUAlphaState , exc_addr)); +tcg_temp_free (tmp); -tcg_temp_free (entry); -tcg_temp_free (pc); + entry += (palcode &0x80 + ?0x2000 + (palcode -0x80 ) *64 + :0x1000 + palcode *64 );/* Since the destination is running in PALmode, we don't really need the page permissions check. We'll see the existence of
@@ -1222,11 +1234,13 @@ static ExitStatus gen_call_pal(DisasContext *ctx, int palcode)we change the PAL base register. */ if (!ctx->singlestep_enabled && !(ctx->tb->cflags &CF_LAST_IO )) {tcg_gen_goto_tb (0 ); +tcg_gen_movi_i64 (cpu_pc, entry);tcg_gen_exit_tb ((uintptr_t )ctx->tb);return EXIT_GOTO_TB ; + }else { +tcg_gen_movi_i64 (cpu_pc, entry); +return EXIT_PC_UPDATED ; } - - return EXIT_PC_UPDATED; }#endif }
@@ -2861,6 +2875,7 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu,#ifdef CONFIG_USER_ONLY ctx.ir = cpu_std_ir;#else + ctx.palbr = env->palbr; ctx.ir = (tb->flags &TB_FLAGS_PAL_MODE ? cpu_pal_ir : cpu_std_ir);#endif
Signature · 1 line
2.1.0
PATCH 3/3 target-alpha: Inline hw_ret
In reply to Richard Henderson--- target-alpha/helper.h | 2 -- target-alpha/sys_helper.c | 8 -------- target-alpha/translate.c | 15 ++++++++++----- 3 files changed, 10 insertions(+), 15 deletions(-)
target-alpha/helper.h +0 -2
@@ -91,8 +91,6 @@ DEF_HELPER_FLAGS_2(ieee_input_cmp, TCG_CALL_NO_WG, void, env, i64) DEF_HELPER_FLAGS_2(ieee_input_s, TCG_CALL_NO_WG, void, env, i64)#if !defined (CONFIG_USER_ONLY ) -DEF_HELPER_2(hw_ret, void, env, i64) - DEF_HELPER_2(ldl_phys, i64, env, i64) DEF_HELPER_2(ldq_phys, i64, env, i64)DEF_HELPER_2 (ldl_l_phys, i64, env, i64)
target-alpha/sys_helper.c +0 -8
@@ -40,14 +40,6 @@ uint64_t helper_load_pcc(CPUAlphaState *env)/* PALcode support special instructions */ #ifndef CONFIG_USER_ONLY -void helper_hw_ret (CPUAlphaState *env,uint64_t a) -{ - env->pc = a & ~3 ; - env->intr_flag =0 ; - env->lock_addr =-1 ; - env->pal_mode = a &1 ; -} -void helper_tbia (CPUAlphaState *env) {tlb_flush (CPU (alpha_env_get_cpu (env)),1 );
target-alpha/translate.c +10 -5
@@ -2635,13 +2635,18 @@ static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)/* Pre-EV6 CPUs interpreted this as HW_REI, loading the return address from EXC_ADDR. This turns out to be useful for our emulation PALcode, so continue to accept it. */ - tmp =tcg_temp_new (); -tcg_gen_ld_i64 (tmp, cpu_env, offsetof(CPUAlphaState , exc_addr)); -gen_helper_hw_ret (cpu_env, tmp); - tcg_temp_free(tmp); + ctx->lit = vb =tcg_temp_new (); + tcg_gen_ld_i64(vb, cpu_env, offsetof(CPUAlphaState, exc_addr)); }else { -gen_helper_hw_ret (cpu_env,load_gpr (ctx, rb)); + vb =load_gpr (ctx, rb); } + tmp =tcg_temp_new (); +tcg_gen_movi_i64 (tmp,0 ); +tcg_gen_st8_i64 (tmp, cpu_env, offsetof(CPUAlphaState , intr_flag)); +tcg_gen_movi_i64 (cpu_lock_addr,-1 ); +tcg_gen_andi_i64 (tmp, vb,1 ); +tcg_gen_st8_i64 (tmp, cpu_env, offsetof(CPUAlphaState , pal_mode)); +tcg_gen_andi_i64 (cpu_pc, vb, ~3 ); ret =EXIT_PC_UPDATED ;break ;#else
Signature · 1 line
2.1.0
Quoted 7 lines · Richard Henderson
Rather than copying around a block of 8 registers when we swap modes, let the translator map code generated for PALmode to the shadow regs directly. This simplifies PALmode entry and exit sufficiently to allow these insns to be performed inline.
Sadly, the speedup for this is in the noise. But I still think it makes sense.
That's usually the case nowadays. It seems all TCG related part are already well optimized, and that most targets are now limited by the MMU emulation. That said I agree it makes sense, and also makes the code cleaner (even if bigger).
Quoted 9 lines
r~
Richard Henderson (3):
target-alpha: Use separate TCGv temporaries for the shadow registers
target-alpha: Inlinecall_pal
target-alpha: Inlinehw_ret
Quoted 8 lines
target-alpha/cpu.h | 3 +- target-alpha/gdbstub.c | 4 +- target-alpha/helper.c | 63 ++++++--------- target-alpha/helper.h | 3 - target-alpha/machine.c | 4 +- target-alpha/sys_helper.c | 22 ----- target-alpha/translate.c | 201 ++++++++++++++++++++++++++++++---------------- 7 files changed, 166 insertions(+), 134 deletions(-)
The whole series is:
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net