diff mbox series

[v2,2/5] target/mips: Replace GET_LMASK() macro by get_lmask(32) function

Message ID 20210818215517.2560994-3-f4bug@amsat.org
State New
Headers show
Series target/mips: Replace TARGET_WORDS_BIGENDIAN by cpu_is_bigendian() | expand

Commit Message

Philippe Mathieu-Daudé Aug. 18, 2021, 9:55 p.m. UTC
The target endianess information is stored in the BigEndian
bit of the Config0 register in CP0.

Replace the GET_LMASK() macro by an inlined get_lmask() function,
passing CPUMIPSState and the word size as argument.

We can remove one use of the TARGET_WORDS_BIGENDIAN definition.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 target/mips/tcg/ldst_helper.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

Comments

Richard Henderson Aug. 18, 2021, 10:35 p.m. UTC | #1
On 8/18/21 11:55 AM, Philippe Mathieu-Daudé wrote:
> The target endianess information is stored in the BigEndian
> bit of the Config0 register in CP0.
> 
> Replace the GET_LMASK() macro by an inlined get_lmask() function,
> passing CPUMIPSState and the word size as argument.
> 
> We can remove one use of the TARGET_WORDS_BIGENDIAN definition.
> 
> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
> ---
>   target/mips/tcg/ldst_helper.c | 32 +++++++++++++++++++++-----------
>   1 file changed, 21 insertions(+), 11 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Philippe Mathieu-Daudé Aug. 19, 2021, 9:16 a.m. UTC | #2
On 8/18/21 11:55 PM, Philippe Mathieu-Daudé wrote:
> The target endianess information is stored in the BigEndian
> bit of the Config0 register in CP0.
> 
> Replace the GET_LMASK() macro by an inlined get_lmask() function,
> passing CPUMIPSState and the word size as argument.
> 
> We can remove one use of the TARGET_WORDS_BIGENDIAN definition.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  target/mips/tcg/ldst_helper.c | 32 +++++++++++++++++++++-----------
>  1 file changed, 21 insertions(+), 11 deletions(-)
> 
> diff --git a/target/mips/tcg/ldst_helper.c b/target/mips/tcg/ldst_helper.c
> index 8d1dfea6766..c48a2818681 100644
> --- a/target/mips/tcg/ldst_helper.c
> +++ b/target/mips/tcg/ldst_helper.c
> @@ -57,30 +57,39 @@ static inline bool cpu_is_bigendian(CPUMIPSState *env)
>      return extract32(env->CP0_Config0, CP0C0_BE, 1);
>  }
>  
> -#ifdef TARGET_WORDS_BIGENDIAN
> -#define GET_LMASK(v) ((v) & 3)
> -#else
> -#define GET_LMASK(v) (((v) & 3) ^ 3)
> -#endif
> +static inline target_ulong get_lmask(CPUMIPSState *env,
> +                                     target_ulong value, unsigned bits)
> +{
> +    unsigned mask = (bits / BITS_PER_BYTE) - 1;
> +
> +    value &= mask;
> +
> +    if (cpu_is_bigendian(env)) {

Obviously:

       if (!cpu_is_bigendian(env)) {

> +        value ^= mask;
> +    }
> +
> +    return value;
> +}
>  
>  void helper_swl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
>                  int mem_idx)
>  {
> +    target_ulong lmask = get_lmask(env, arg2, 32);
>      int dir = cpu_is_bigendian(env) ? 1 : -1;
>  
>      cpu_stb_mmuidx_ra(env, arg2, (uint8_t)(arg1 >> 24), mem_idx, GETPC());
>  
> -    if (GET_LMASK(arg2) <= 2) {
> +    if (lmask <= 2) {
>          cpu_stb_mmuidx_ra(env, arg2 + 1 * dir, (uint8_t)(arg1 >> 16),
>                            mem_idx, GETPC());
>      }
>  
> -    if (GET_LMASK(arg2) <= 1) {
> +    if (lmask <= 1) {
>          cpu_stb_mmuidx_ra(env, arg2 + 2 * dir, (uint8_t)(arg1 >> 8),
>                            mem_idx, GETPC());
>      }
>  
> -    if (GET_LMASK(arg2) == 0) {
> +    if (lmask == 0) {
>          cpu_stb_mmuidx_ra(env, arg2 + 3 * dir, (uint8_t)arg1,
>                            mem_idx, GETPC());
>      }
> @@ -89,21 +98,22 @@ void helper_swl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
>  void helper_swr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
>                  int mem_idx)
>  {
> +    target_ulong lmask = get_lmask(env, arg2, 32);
>      int dir = cpu_is_bigendian(env) ? 1 : -1;
>  
>      cpu_stb_mmuidx_ra(env, arg2, (uint8_t)arg1, mem_idx, GETPC());
>  
> -    if (GET_LMASK(arg2) >= 1) {
> +    if (lmask >= 1) {
>          cpu_stb_mmuidx_ra(env, arg2 - 1 * dir, (uint8_t)(arg1 >> 8),
>                            mem_idx, GETPC());
>      }
>  
> -    if (GET_LMASK(arg2) >= 2) {
> +    if (lmask >= 2) {
>          cpu_stb_mmuidx_ra(env, arg2 - 2 * dir, (uint8_t)(arg1 >> 16),
>                            mem_idx, GETPC());
>      }
>  
> -    if (GET_LMASK(arg2) == 3) {
> +    if (lmask == 3) {
>          cpu_stb_mmuidx_ra(env, arg2 - 3 * dir, (uint8_t)(arg1 >> 24),
>                            mem_idx, GETPC());
>      }
>
diff mbox series

Patch

diff --git a/target/mips/tcg/ldst_helper.c b/target/mips/tcg/ldst_helper.c
index 8d1dfea6766..c48a2818681 100644
--- a/target/mips/tcg/ldst_helper.c
+++ b/target/mips/tcg/ldst_helper.c
@@ -57,30 +57,39 @@  static inline bool cpu_is_bigendian(CPUMIPSState *env)
     return extract32(env->CP0_Config0, CP0C0_BE, 1);
 }
 
-#ifdef TARGET_WORDS_BIGENDIAN
-#define GET_LMASK(v) ((v) & 3)
-#else
-#define GET_LMASK(v) (((v) & 3) ^ 3)
-#endif
+static inline target_ulong get_lmask(CPUMIPSState *env,
+                                     target_ulong value, unsigned bits)
+{
+    unsigned mask = (bits / BITS_PER_BYTE) - 1;
+
+    value &= mask;
+
+    if (cpu_is_bigendian(env)) {
+        value ^= mask;
+    }
+
+    return value;
+}
 
 void helper_swl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
                 int mem_idx)
 {
+    target_ulong lmask = get_lmask(env, arg2, 32);
     int dir = cpu_is_bigendian(env) ? 1 : -1;
 
     cpu_stb_mmuidx_ra(env, arg2, (uint8_t)(arg1 >> 24), mem_idx, GETPC());
 
-    if (GET_LMASK(arg2) <= 2) {
+    if (lmask <= 2) {
         cpu_stb_mmuidx_ra(env, arg2 + 1 * dir, (uint8_t)(arg1 >> 16),
                           mem_idx, GETPC());
     }
 
-    if (GET_LMASK(arg2) <= 1) {
+    if (lmask <= 1) {
         cpu_stb_mmuidx_ra(env, arg2 + 2 * dir, (uint8_t)(arg1 >> 8),
                           mem_idx, GETPC());
     }
 
-    if (GET_LMASK(arg2) == 0) {
+    if (lmask == 0) {
         cpu_stb_mmuidx_ra(env, arg2 + 3 * dir, (uint8_t)arg1,
                           mem_idx, GETPC());
     }
@@ -89,21 +98,22 @@  void helper_swl(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
 void helper_swr(CPUMIPSState *env, target_ulong arg1, target_ulong arg2,
                 int mem_idx)
 {
+    target_ulong lmask = get_lmask(env, arg2, 32);
     int dir = cpu_is_bigendian(env) ? 1 : -1;
 
     cpu_stb_mmuidx_ra(env, arg2, (uint8_t)arg1, mem_idx, GETPC());
 
-    if (GET_LMASK(arg2) >= 1) {
+    if (lmask >= 1) {
         cpu_stb_mmuidx_ra(env, arg2 - 1 * dir, (uint8_t)(arg1 >> 8),
                           mem_idx, GETPC());
     }
 
-    if (GET_LMASK(arg2) >= 2) {
+    if (lmask >= 2) {
         cpu_stb_mmuidx_ra(env, arg2 - 2 * dir, (uint8_t)(arg1 >> 16),
                           mem_idx, GETPC());
     }
 
-    if (GET_LMASK(arg2) == 3) {
+    if (lmask == 3) {
         cpu_stb_mmuidx_ra(env, arg2 - 3 * dir, (uint8_t)(arg1 >> 24),
                           mem_idx, GETPC());
     }