target/hppa: Speed up hppa_is_pa20()
PATCH v2 1/1 target/hppa: Speed up hppa_is_pa20()
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.
v2:
- moved init to hppa_cpu_initfn() and is_pa20 to end of CPUArchState struct (feedback by Richard)
target/hppa/cpu.c +1 -0
@@ -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 ); }
target/hppa/cpu.h +3 -1
@@ -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)
Quoted 6 lines · Helge Deller
Although the
hppa_is_pa20()helper is costly due to string comparisms inobject_dynamic_cast(), it is called quite often during memory lookups and at each start of a block of instruction translations. Speedhppa_is_pa20()up by callingobject_dynamic_cast()only once at CPU creation and store the result in theis_pa20of struct CPUArchState.
Quoted 6 lines
Signed-off-by Helge Deller <[email protected]>v2:
- moved init tohppa_cpu_initfn()andis_pa20to end of CPUArchState struct (feedback by Richard)
r~
Quoted 1 line · Helge Deller
Although the
hppa_is_pa20()helper is costly due to string comparisms in
"comparisms" -> "comparison"?
Quoted 16 lines
object_dynamic_cast(), it is called quite often during memory lookups and at each start of a block of instruction translations. Speedhppa_is_pa20()up by callingobject_dynamic_cast()only once at CPU creation and store the result in theis_pa20of struct CPUArchState.Signed-off-by Helge Deller <[email protected]>v2:
- moved init tohppa_cpu_initfn()andis_pa20to end of CPUArchState struct (feedback by Richard)target/hppa/cpu.c +0
-0
target/hppa/cpu.c static void hppa_cpu_initfn(Object *obj) · line 202
Quoted 4 lines
target/hppa/cpu.c +1
-0@@ -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);
target/hppa/cpu.c static void hppa_cpu_initfn(Object *obj) · line 205
Quoted 3 lines
target/hppa/cpu.c +0
-0cpu_hppa_loaded_fr0 (env);cpu_hppa_put_psw (env,PSW_W ); }