Skip to contentSkip to conversation

cpu: Drop unnecessary dynamic casts in *_env_get_cpu()

PATCH In review Andreas Färber 2 participants 3 messages Jun 28, 2013 – Jun 29, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cpu: Drop unnecessary dynamic casts in *_env_get_cpu()

A transition from CPUFooState to FooCPU can be considered safe, just like FooCPU::env access in the opposite direction. The only benefit of the FOO_CPU() casts would be protection against bogus CPUFooState pointers, but then surrounding code would likely break, too.

This should slightly improve interrupt etc. performance.

---
v1 -> v2:
* Generalized from ppc to all targets.

 target-alpha/cpu-qom.h      | 2 +-
 target-arm/cpu-qom.h        | 2 +-
 target-cris/cpu-qom.h       | 2 +-
 target-i386/cpu-qom.h       | 2 +-
 target-lm32/cpu-qom.h       | 2 +-
 target-m68k/cpu-qom.h       | 2 +-
 target-microblaze/cpu-qom.h | 2 +-
 target-mips/cpu-qom.h       | 2 +-
 target-moxie/cpu.h          | 2 +-
 target-openrisc/cpu.h       | 2 +-
 target-ppc/cpu-qom.h        | 2 +-
 target-s390x/cpu-qom.h      | 2 +-
 target-sh4/cpu-qom.h        | 2 +-
 target-sparc/cpu-qom.h      | 2 +-
 target-unicore32/cpu-qom.h  | 2 +-
 target-xtensa/cpu-qom.h     | 2 +-
 16 files changed, 16 insertions(+), 16 deletions(-)
target-alpha/cpu-qom.h +1 -1
index 94e4a54..60125b1 100644
@@ -67,7 +67,7 @@ typedef struct AlphaCPU {
 
 static inline AlphaCPU *alpha_env_get_cpu(CPUAlphaState *env)
 {
-    return ALPHA_CPU(container_of(env, AlphaCPU, env));
+    return container_of(env, AlphaCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(alpha_env_get_cpu(e))
target-arm/cpu-qom.h +1 -1
index ef6261f..48ba605 100644
@@ -127,7 +127,7 @@ typedef struct ARMCPU {
 
 static inline ARMCPU *arm_env_get_cpu(CPUARMState *env)
 {
-    return ARM_CPU(container_of(env, ARMCPU, env));
+    return container_of(env, ARMCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(arm_env_get_cpu(e))
target-cris/cpu-qom.h +1 -1
index e08bdb1..af7d14d 100644
@@ -66,7 +66,7 @@ typedef struct CRISCPU {
 
 static inline CRISCPU *cris_env_get_cpu(CPUCRISState *env)
 {
-    return CRIS_CPU(container_of(env, CRISCPU, env));
+    return container_of(env, CRISCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(cris_env_get_cpu(e))
target-i386/cpu-qom.h +1 -1
index b7c70d6..7e55e5f 100644
@@ -72,7 +72,7 @@ typedef struct X86CPU {
 
 static inline X86CPU *x86_env_get_cpu(CPUX86State *env)
 {
-    return X86_CPU(container_of(env, X86CPU, env));
+    return container_of(env, X86CPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(x86_env_get_cpu(e))
target-lm32/cpu-qom.h +1 -1
index 5ef884b..e3bb619 100644
@@ -64,7 +64,7 @@ typedef struct LM32CPU {
 
 static inline LM32CPU *lm32_env_get_cpu(CPULM32State *env)
 {
-    return LM32_CPU(container_of(env, LM32CPU, env));
+    return container_of(env, LM32CPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(lm32_env_get_cpu(e))
target-m68k/cpu-qom.h +1 -1
index 2436c13..858bf30 100644
@@ -63,7 +63,7 @@ typedef struct M68kCPU {
 
 static inline M68kCPU *m68k_env_get_cpu(CPUM68KState *env)
 {
-    return M68K_CPU(container_of(env, M68kCPU, env));
+    return container_of(env, M68kCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(m68k_env_get_cpu(e))
target-microblaze/cpu-qom.h +1 -1
index 3e9c206..ec2b989 100644
@@ -64,7 +64,7 @@ typedef struct MicroBlazeCPU {
 
 static inline MicroBlazeCPU *mb_env_get_cpu(CPUMBState *env)
 {
-    return MICROBLAZE_CPU(container_of(env, MicroBlazeCPU, env));
+    return container_of(env, MicroBlazeCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(mb_env_get_cpu(e))
target-mips/cpu-qom.h +1 -1
index a7ff9e6..654744a 100644
@@ -67,7 +67,7 @@ typedef struct MIPSCPU {
 
 static inline MIPSCPU *mips_env_get_cpu(CPUMIPSState *env)
 {
-    return MIPS_CPU(container_of(env, MIPSCPU, env));
+    return container_of(env, MIPSCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(mips_env_get_cpu(e))
target-moxie/cpu.h +1 -1
index 374b24a..72d02c2 100644
@@ -106,7 +106,7 @@ typedef struct MoxieCPU {
 
 static inline MoxieCPU *moxie_env_get_cpu(CPUMoxieState *env)
 {
-    return MOXIE_CPU(container_of(env, MoxieCPU, env));
+    return container_of(env, MoxieCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(moxie_env_get_cpu(e))
target-openrisc/cpu.h +1 -1
index 80a82df..2cc5724 100644
@@ -335,7 +335,7 @@ typedef struct OpenRISCCPU {
 
 static inline OpenRISCCPU *openrisc_env_get_cpu(CPUOpenRISCState *env)
 {
-    return OPENRISC_CPU(container_of(env, OpenRISCCPU, env));
+    return container_of(env, OpenRISCCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(openrisc_env_get_cpu(e))
target-ppc/cpu-qom.h +1 -1
index 84ba105..7132599 100644
@@ -91,7 +91,7 @@ typedef struct PowerPCCPU {
 
 static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
 {
-    return POWERPC_CPU(container_of(env, PowerPCCPU, env));
+    return container_of(env, PowerPCCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(ppc_env_get_cpu(e))
target-s390x/cpu-qom.h +1 -1
index ec32d21..4c091e3 100644
@@ -64,7 +64,7 @@ typedef struct S390CPU {
 
 static inline S390CPU *s390_env_get_cpu(CPUS390XState *env)
 {
-    return S390_CPU(container_of(env, S390CPU, env));
+    return container_of(env, S390CPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(s390_env_get_cpu(e))
target-sh4/cpu-qom.h +1 -1
index 01d1637..c229a9a 100644
@@ -76,7 +76,7 @@ typedef struct SuperHCPU {
 
 static inline SuperHCPU *sh_env_get_cpu(CPUSH4State *env)
 {
-    return SUPERH_CPU(container_of(env, SuperHCPU, env));
+    return container_of(env, SuperHCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(sh_env_get_cpu(e))
target-sparc/cpu-qom.h +1 -1
index 97c1ec7..033a5b5 100644
@@ -68,7 +68,7 @@ typedef struct SPARCCPU {
 
 static inline SPARCCPU *sparc_env_get_cpu(CPUSPARCState *env)
 {
-    return SPARC_CPU(container_of(env, SPARCCPU, env));
+    return container_of(env, SPARCCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(sparc_env_get_cpu(e))
target-unicore32/cpu-qom.h +1 -1
index 7eec448..350d480 100644
@@ -53,7 +53,7 @@ typedef struct UniCore32CPU {
 
 static inline UniCore32CPU *uc32_env_get_cpu(CPUUniCore32State *env)
 {
-    return UNICORE32_CPU(container_of(env, UniCore32CPU, env));
+    return container_of(env, UniCore32CPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(uc32_env_get_cpu(e))
target-xtensa/cpu-qom.h +1 -1
index 30506cf..31e7498 100644
@@ -73,7 +73,7 @@ typedef struct XtensaCPU {
 
 static inline XtensaCPU *xtensa_env_get_cpu(const CPUXtensaState *env)
 {
-    return XTENSA_CPU(container_of(env, XtensaCPU, env));
+    return container_of(env, XtensaCPU, env);
 }
 
 #define ENV_GET_CPU(e) CPU(xtensa_env_get_cpu(e))
Signature · 1 line
1.8.1.4
Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Andreas Färber

A transition from CPUFooState to FooCPU can be considered safe, just like FooCPU::env access in the opposite direction. The only benefit of the FOO_CPU() casts would be protection against bogus CPUFooState pointers, but then surrounding code would likely break, too.

This should slightly improve interrupt etc. performance.

r~

author Applied
#2 lore raw

Am 28.06.2013 19:32, schrieb Richard Henderson:

Quoted 7 lines · Andreas Färber
Quoted 6 lines

A transition from CPUFooState to FooCPU can be considered safe, just like FooCPU::env access in the opposite direction. The only benefit of the FOO_CPU() casts would be protection against bogus CPUFooState pointers, but then surrounding code would likely break, too.

Quoted 6 lines
Quoted 4 lines

This should slightly improve interrupt etc. performance.

Thanks, applied to qom-cpu (with extended commit message):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg