[PATCH 05/12] target/mips: Introduce mo_endian() helper

Philippe Mathieu-Daudé posted 12 patches 2 months, 3 weeks ago
There is a newer version of this series
[PATCH 05/12] target/mips: Introduce mo_endian() helper
Posted by Philippe Mathieu-Daudé 2 months, 3 weeks ago
Introduce mo_endian() which returns the endian MemOp
corresponding to the vCPU DisasContext.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/mips/tcg/translate.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/target/mips/tcg/translate.h b/target/mips/tcg/translate.h
index 2b6646b339..54955437ef 100644
--- a/target/mips/tcg/translate.h
+++ b/target/mips/tcg/translate.h
@@ -240,4 +240,9 @@ static inline bool cpu_is_bigendian(DisasContext *ctx)
     return extract32(ctx->CP0_Config0, CP0C0_BE, 1);
 }
 
+static inline MemOp mo_endian(DisasContext *dc)
+{
+    return cpu_is_bigendian(dc) ? MO_BE : MO_LE;
+}
+
 #endif
-- 
2.45.2


Re: [PATCH 05/12] target/mips: Introduce mo_endian() helper
Posted by Richard Henderson 2 months, 2 weeks ago
On 9/30/24 02:10, Philippe Mathieu-Daudé wrote:
> Introduce mo_endian() which returns the endian MemOp
> corresponding to the vCPU DisasContext.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/mips/tcg/translate.h | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/target/mips/tcg/translate.h b/target/mips/tcg/translate.h
> index 2b6646b339..54955437ef 100644
> --- a/target/mips/tcg/translate.h
> +++ b/target/mips/tcg/translate.h
> @@ -240,4 +240,9 @@ static inline bool cpu_is_bigendian(DisasContext *ctx)
>       return extract32(ctx->CP0_Config0, CP0C0_BE, 1);
>   }
>   
> +static inline MemOp mo_endian(DisasContext *dc)
> +{
> +    return cpu_is_bigendian(dc) ? MO_BE : MO_LE;
> +}

Based on patch 6, I think you'd better pass 'bool reversed' to this function.
Then

     disas_is_bigendian(dc) ^ reversed ? MO_BE : MO_LE;

r~