[PATCH v2 05/28] target/ppc/mmu_common.c: Move calculation of a value closer to its usage

BALATON Zoltan posted 28 patches 1 year, 9 months ago
Maintainers: BALATON Zoltan <balaton@eik.bme.hu>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>
There is a newer version of this series
[PATCH v2 05/28] target/ppc/mmu_common.c: Move calculation of a value closer to its usage
Posted by BALATON Zoltan 1 year, 9 months ago
In mmubooke_check_tlb() prot2 is calculated first but only used after
an unrelated check that can return before tha value is used. Move the
calculation after the check, closer to where it is used, to keep them
together and avoid computing it when not needed.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 target/ppc/mmu_common.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
index 751403f1c8..168ff842a5 100644
--- a/target/ppc/mmu_common.c
+++ b/target/ppc/mmu_common.c
@@ -634,12 +634,6 @@ static int mmubooke_check_tlb(CPUPPCState *env, ppcemb_tlb_t *tlb,
         return -1;
     }
 
-    if (FIELD_EX64(env->msr, MSR, PR)) {
-        prot2 = tlb->prot & 0xF;
-    } else {
-        prot2 = (tlb->prot >> 4) & 0xF;
-    }
-
     /* Check the address space */
     if ((access_type == MMU_INST_FETCH ?
         FIELD_EX64(env->msr, MSR, IR) :
@@ -648,6 +642,11 @@ static int mmubooke_check_tlb(CPUPPCState *env, ppcemb_tlb_t *tlb,
         return -1;
     }
 
+    if (FIELD_EX64(env->msr, MSR, PR)) {
+        prot2 = tlb->prot & 0xF;
+    } else {
+        prot2 = (tlb->prot >> 4) & 0xF;
+    }
     *prot = prot2;
     if (prot2 & prot_for_access_type(access_type)) {
         qemu_log_mask(CPU_LOG_MMU, "%s: good TLB!\n", __func__);
-- 
2.30.9
Re: [PATCH v2 05/28] target/ppc/mmu_common.c: Move calculation of a value closer to its usage
Posted by Nicholas Piggin 1 year, 9 months ago
On Thu May 2, 2024 at 9:43 AM AEST, BALATON Zoltan wrote:
> In mmubooke_check_tlb() prot2 is calculated first but only used after
> an unrelated check that can return before tha value is used. Move the
> calculation after the check, closer to where it is used, to keep them
> together and avoid computing it when not needed.
>
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>

Reviwed-by: Nicholas Piggin <npiggin@gmail.com>

> ---
>  target/ppc/mmu_common.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
> index 751403f1c8..168ff842a5 100644
> --- a/target/ppc/mmu_common.c
> +++ b/target/ppc/mmu_common.c
> @@ -634,12 +634,6 @@ static int mmubooke_check_tlb(CPUPPCState *env, ppcemb_tlb_t *tlb,
>          return -1;
>      }
>  
> -    if (FIELD_EX64(env->msr, MSR, PR)) {
> -        prot2 = tlb->prot & 0xF;
> -    } else {
> -        prot2 = (tlb->prot >> 4) & 0xF;
> -    }
> -
>      /* Check the address space */
>      if ((access_type == MMU_INST_FETCH ?
>          FIELD_EX64(env->msr, MSR, IR) :
> @@ -648,6 +642,11 @@ static int mmubooke_check_tlb(CPUPPCState *env, ppcemb_tlb_t *tlb,
>          return -1;
>      }
>  
> +    if (FIELD_EX64(env->msr, MSR, PR)) {
> +        prot2 = tlb->prot & 0xF;
> +    } else {
> +        prot2 = (tlb->prot >> 4) & 0xF;
> +    }
>      *prot = prot2;
>      if (prot2 & prot_for_access_type(access_type)) {
>          qemu_log_mask(CPU_LOG_MMU, "%s: good TLB!\n", __func__);