Skip to content

Commit 5c27cbd

Browse files
hdellerphilmd
authored andcommitted
target/hppa: Speed up hppa_is_pa20()
Although the hppa_is_pa20() helper is costly due to string comparisons 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 <[email protected]> Co-developed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]>
1 parent 46f7be0 commit 5c27cbd

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

target/hppa/cpu.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)
193193
tcg_cflags_set(cs, CF_PCREL);
194194
}
195195

196+
static void hppa_cpu_initfn(Object *obj)
197+
{
198+
CPUHPPAState *env = cpu_env(CPU(obj));
199+
200+
env->is_pa20 = !!object_dynamic_cast(obj, TYPE_HPPA64_CPU);
201+
}
202+
196203
static void hppa_cpu_reset_hold(Object *obj, ResetType type)
197204
{
198205
HPPACPUClass *scc = HPPA_CPU_GET_CLASS(obj);
@@ -282,6 +289,7 @@ static const TypeInfo hppa_cpu_type_infos[] = {
282289
.parent = TYPE_CPU,
283290
.instance_size = sizeof(HPPACPU),
284291
.instance_align = __alignof(HPPACPU),
292+
.instance_init = hppa_cpu_initfn,
285293
.abstract = false,
286294
.class_size = sizeof(HPPACPUClass),
287295
.class_init = hppa_cpu_class_init,

target/hppa/cpu.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ typedef struct CPUArchState {
266266

267267
/* Fields up to this point are cleared by a CPU reset */
268268
struct {} end_reset_fields;
269+
270+
bool is_pa20;
269271
} CPUHPPAState;
270272

271273
/**
@@ -297,9 +299,9 @@ struct HPPACPUClass {
297299

298300
#include "exec/cpu-all.h"
299301

300-
static inline bool hppa_is_pa20(CPUHPPAState *env)
302+
static inline bool hppa_is_pa20(const CPUHPPAState *env)
301303
{
302-
return object_dynamic_cast(OBJECT(env_cpu(env)), TYPE_HPPA64_CPU) != NULL;
304+
return env->is_pa20;
303305
}
304306

305307
static inline int HPPA_BTLB_ENTRIES(CPUHPPAState *env)

0 commit comments

Comments
 (0)