[PATCH v4 2/5] target/ppc: used ternary operator when registering MAS

Bruno Larsen (billionai) posted 5 patches 4 years, 8 months ago
There is a newer version of this series
[PATCH v4 2/5] target/ppc: used ternary operator when registering MAS
Posted by Bruno Larsen (billionai) 4 years, 8 months ago
The write calback decision when registering the MAS SPR has been turned
into a ternary operation, rather than an if-then-else block.

Signed-off-by: Bruno Larsen (billionai) <bruno.larsen@eldorado.org.br>
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/ppc/cpu_init.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index b696469d1a..40719f6480 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -1205,15 +1205,12 @@ static void register_BookE206_sprs(CPUPPCState *env, uint32_t mas_mask,
     /* TLB assist registers */
     /* XXX : not implemented */
     for (i = 0; i < 8; i++) {
-        void (*uea_write)(DisasContext *ctx, int sprn, int gprn) =
-            &spr_write_generic32;
-        if (i == 2 && (mas_mask & (1 << i)) && (env->insns_flags & PPC_64B)) {
-            uea_write = &spr_write_generic;
-        }
         if (mas_mask & (1 << i)) {
             spr_register(env, mas_sprn[i], mas_names[i],
                          SPR_NOACCESS, SPR_NOACCESS,
-                         &spr_read_generic, uea_write,
+                         &spr_read_generic,
+                         (i == 2 && (env->insns_flags & PPC_64B))
+                         ? &spr_write_generic : &spr_write_generic32,
                          0x00000000);
         }
     }
-- 
2.17.1


Re: [PATCH v4 2/5] target/ppc: used ternary operator when registering MAS
Posted by Richard Henderson 4 years, 8 months ago
On 5/24/21 6:59 AM, Bruno Larsen (billionai) wrote:
> The write calback decision when registering the MAS SPR has been turned
> into a ternary operation, rather than an if-then-else block.
> 
> Signed-off-by: Bruno Larsen (billionai)<bruno.larsen@eldorado.org.br>
> Suggested-by: Richard Henderson<richard.henderson@linaro.org>
> ---
>   target/ppc/cpu_init.c | 9 +++------
>   1 file changed, 3 insertions(+), 6 deletions(-)

The commit message here says what, but it doesn't say why.

The important part of the change is making the references to spr_write_generic* 
conditional, via SYS_ARG(), so that the code compiles out for !CONFIG_TCG.

The actual code change is fine:
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

Re: [PATCH v4 2/5] target/ppc: used ternary operator when registering MAS
Posted by David Gibson 4 years, 8 months ago
On Mon, May 24, 2021 at 10:32:18AM -0700, Richard Henderson wrote:
> On 5/24/21 6:59 AM, Bruno Larsen (billionai) wrote:
> > The write calback decision when registering the MAS SPR has been turned
> > into a ternary operation, rather than an if-then-else block.
> > 
> > Signed-off-by: Bruno Larsen (billionai)<bruno.larsen@eldorado.org.br>
> > Suggested-by: Richard Henderson<richard.henderson@linaro.org>
> > ---
> >   target/ppc/cpu_init.c | 9 +++------
> >   1 file changed, 3 insertions(+), 6 deletions(-)
> 
> The commit message here says what, but it doesn't say why.

Right, and "why" is generally the more important thing to be in a
commit message.

> The important part of the change is making the references to
> spr_write_generic* conditional, via SYS_ARG(), so that the code compiles out
> for !CONFIG_TCG.
> 
> The actual code change is fine:
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> 
> r~
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson