Commit 734bd83030 for qemu.org
commit 734bd8303027cfc566c9507b08ceff9d3bc2cd71
Author: Philippe Mathieu-Daudé <philmd@linaro.org>
Date: Wed May 6 14:37:24 2026 +0200
target/mips: Reduce CPUState scope when used with CPU_FOREACH()
When possible, reduce CPUState variable scope.
Prefer cpu_env(cpu) over &cpu->env.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Message-Id: <20260415215539.92629-8-philmd@linaro.org>
diff --git a/target/mips/internal.h b/target/mips/internal.h
index 95b8b7bb9c..2fd5ffa304 100644
--- a/target/mips/internal.h
+++ b/target/mips/internal.h
@@ -280,7 +280,7 @@ static inline int mips_vpe_active(CPUMIPSState *env)
static inline int mips_vp_active(CPUMIPSState *env)
{
- CPUState *other_cs = first_cpu;
+ CPUState *cs = first_cpu;
/* Check if the VP disabled other VPs (which means the VP is enabled) */
if ((env->CP0_VPControl >> CP0VPCtl_DIS) & 1) {
@@ -288,10 +288,11 @@ static inline int mips_vp_active(CPUMIPSState *env)
}
/* Check if the virtual processor is disabled due to a DVP */
- CPU_FOREACH(other_cs) {
- MIPSCPU *other_cpu = MIPS_CPU(other_cs);
- if ((&other_cpu->env != env) &&
- ((other_cpu->env.CP0_VPControl >> CP0VPCtl_DIS) & 1)) {
+ CPU_FOREACH(cs) {
+ CPUMIPSState *other_env = cpu_env(cs);
+
+ if ((other_env != env) &&
+ ((other_env->CP0_VPControl >> CP0VPCtl_DIS) & 1)) {
return 0;
}
}
diff --git a/target/mips/tcg/system/cp0_helper.c b/target/mips/tcg/system/cp0_helper.c
index 123d5c217c..8b83ba1639 100644
--- a/target/mips/tcg/system/cp0_helper.c
+++ b/target/mips/tcg/system/cp0_helper.c
@@ -1566,13 +1566,14 @@ target_ulong helper_emt(void)
target_ulong helper_dvpe(CPUMIPSState *env)
{
- CPUState *other_cs = first_cpu;
MIPSCPU *cpu = env_archcpu(env);
target_ulong prev = cpu->mvp->CP0_MVPControl;
if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
- CPU_FOREACH(other_cs) {
- MIPSCPU *other_cpu = MIPS_CPU(other_cs);
+ CPUState *cs = first_cpu;
+
+ CPU_FOREACH(cs) {
+ MIPSCPU *other_cpu = MIPS_CPU(cs);
/* Turn off all VPEs except the one executing the dvpe. */
if (&other_cpu->env != env) {
other_cpu->mvp->CP0_MVPControl &= ~(1 << CP0MVPCo_EVP);
@@ -1585,13 +1586,14 @@ target_ulong helper_dvpe(CPUMIPSState *env)
target_ulong helper_evpe(CPUMIPSState *env)
{
- CPUState *other_cs = first_cpu;
MIPSCPU *cpu = env_archcpu(env);
target_ulong prev = cpu->mvp->CP0_MVPControl;
if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
- CPU_FOREACH(other_cs) {
- MIPSCPU *other_cpu = MIPS_CPU(other_cs);
+ CPUState *cs = first_cpu;
+
+ CPU_FOREACH(cs) {
+ MIPSCPU *other_cpu = MIPS_CPU(cs);
if (&other_cpu->env != env
/* If the VPE is WFI, don't disturb its sleep. */
@@ -1608,12 +1610,13 @@ target_ulong helper_evpe(CPUMIPSState *env)
/* R6 Multi-threading */
target_ulong helper_dvp(CPUMIPSState *env)
{
- CPUState *other_cs = first_cpu;
target_ulong prev = env->CP0_VPControl;
if (!((env->CP0_VPControl >> CP0VPCtl_DIS) & 1)) {
- CPU_FOREACH(other_cs) {
- MIPSCPU *other_cpu = MIPS_CPU(other_cs);
+ CPUState *cpu = first_cpu;
+
+ CPU_FOREACH(cpu) {
+ MIPSCPU *other_cpu = MIPS_CPU(cpu);
/* Turn off all VPs except the one executing the dvp. */
if (&other_cpu->env != env) {
mips_vpe_sleep(other_cpu);
@@ -1626,12 +1629,13 @@ target_ulong helper_dvp(CPUMIPSState *env)
target_ulong helper_evp(CPUMIPSState *env)
{
- CPUState *other_cs = first_cpu;
target_ulong prev = env->CP0_VPControl;
if ((env->CP0_VPControl >> CP0VPCtl_DIS) & 1) {
- CPU_FOREACH(other_cs) {
- MIPSCPU *other_cpu = MIPS_CPU(other_cs);
+ CPUState *cpu = first_cpu;
+
+ CPU_FOREACH(cpu) {
+ MIPSCPU *other_cpu = MIPS_CPU(cpu);
if ((&other_cpu->env != env) && !mips_vp_is_wfi(other_cpu)) {
/*
* If the VP is WFI, don't disturb its sleep.
diff --git a/target/mips/tcg/system/tlb_helper.c b/target/mips/tcg/system/tlb_helper.c
index b989c7e5bd..45cbeb40a2 100644
--- a/target/mips/tcg/system/tlb_helper.c
+++ b/target/mips/tcg/system/tlb_helper.c
@@ -346,15 +346,14 @@ void helper_ginvt(CPUMIPSState *env, target_ulong arg, uint32_t type)
uint32_t invMsgVPN2 = arg & (TARGET_PAGE_MASK << 1);
uint8_t invMsgR = 0;
uint32_t invMsgMMid = env->CP0_MemoryMapID;
- CPUState *other_cs = first_cpu;
+ CPUState *cpu = first_cpu;
#ifdef TARGET_MIPS64
invMsgR = extract64(arg, 62, 2);
#endif
- CPU_FOREACH(other_cs) {
- MIPSCPU *other_cpu = MIPS_CPU(other_cs);
- global_invalidate_tlb(&other_cpu->env, invMsgVPN2, invMsgR, invMsgMMid,
+ CPU_FOREACH(cpu) {
+ global_invalidate_tlb(cpu_env(cpu), invMsgVPN2, invMsgR, invMsgMMid,
invAll, invVAMMid, invMMid, invVA);
}
}