Message ID | Z3BouGUFFP87PJyx@p100 (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v2] target/hppa: Speed up hppa_is_pa20() | expand |
On 12/28/24 13:08, Helge Deller wrote: > Although the hppa_is_pa20() helper is costly due to string comparisms in > object_dynamic_cast(), it is called quite often during memory lookups > and at each start of a block of instruction translations. > Speed hppa_is_pa20() up by calling object_dynamic_cast() only once at > CPU creation and store the result in the is_pa20 of struct CPUArchState. > > Signed-off-by: Helge Deller <deller@gmx.de> > > v2: > - moved init to hppa_cpu_initfn() and is_pa20 to end of CPUArchState struct > (feedback by Richard) > Reviewed-by: Richard Henderson <richard.henderson@linaro.org> r~
On 28/12/24 22:08, Helge Deller wrote: > Although the hppa_is_pa20() helper is costly due to string comparisms in "comparisms" -> "comparison"? > object_dynamic_cast(), it is called quite often during memory lookups > and at each start of a block of instruction translations. > Speed hppa_is_pa20() up by calling object_dynamic_cast() only once at > CPU creation and store the result in the is_pa20 of struct CPUArchState. > > Signed-off-by: Helge Deller <deller@gmx.de> > > v2: > - moved init to hppa_cpu_initfn() and is_pa20 to end of CPUArchState struct > (feedback by Richard) > > diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c > index b908cf65c6..05de952a87 100644 > --- a/target/hppa/cpu.c > +++ b/target/hppa/cpu.c > @@ -199,6 +199,7 @@ static void hppa_cpu_initfn(Object *obj) > CPUHPPAState *env = &cpu->env; > > cs->exception_index = -1; > + env->is_pa20 = object_dynamic_cast(obj, TYPE_HPPA64_CPU); Personally I find explicit casts to boolean clearer: env->is_pa20 = !!object_dynamic_cast(obj, TYPE_HPPA64_CPU); > cpu_hppa_loaded_fr0(env); > cpu_hppa_put_psw(env, PSW_W); > } Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c index b908cf65c6..05de952a87 100644 --- a/target/hppa/cpu.c +++ b/target/hppa/cpu.c @@ -199,6 +199,7 @@ static void hppa_cpu_initfn(Object *obj) CPUHPPAState *env = &cpu->env; cs->exception_index = -1; + env->is_pa20 = object_dynamic_cast(obj, TYPE_HPPA64_CPU); cpu_hppa_loaded_fr0(env); cpu_hppa_put_psw(env, PSW_W); } diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h index 32a674a8b8..288ce6d98a 100644 --- a/target/hppa/cpu.h +++ b/target/hppa/cpu.h @@ -266,6 +266,8 @@ typedef struct CPUArchState { /* Fields up to this point are cleared by a CPU reset */ struct {} end_reset_fields; + + bool is_pa20; } CPUHPPAState; /** @@ -299,7 +301,7 @@ struct HPPACPUClass { static inline bool hppa_is_pa20(CPUHPPAState *env) { - return object_dynamic_cast(OBJECT(env_cpu(env)), TYPE_HPPA64_CPU) != NULL; + return env->is_pa20; } static inline int HPPA_BTLB_ENTRIES(CPUHPPAState *env)
Although the hppa_is_pa20() helper is costly due to string comparisms in object_dynamic_cast(), it is called quite often during memory lookups and at each start of a block of instruction translations. Speed hppa_is_pa20() up by calling object_dynamic_cast() only once at CPU creation and store the result in the is_pa20 of struct CPUArchState. Signed-off-by: Helge Deller <deller@gmx.de> v2: - moved init to hppa_cpu_initfn() and is_pa20 to end of CPUArchState struct (feedback by Richard)