[PATCH v5 05/17] exec/memory.h: make devend_memop "target defines" agnostic

Pierrick Bouvier posted 17 patches 2 weeks, 6 days ago
There is a newer version of this series
[PATCH v5 05/17] exec/memory.h: make devend_memop "target defines" agnostic
Posted by Pierrick Bouvier 2 weeks, 6 days ago
Will allow to make system/memory.c common later.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 include/exec/memory.h | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index da21e9150b5..069021ac3ff 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -3138,25 +3138,17 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
 MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
                               uint8_t c, hwaddr len, MemTxAttrs attrs);
 
-#ifdef COMPILING_PER_TARGET
 /* enum device_endian to MemOp.  */
 static inline MemOp devend_memop(enum device_endian end)
 {
     QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
                       DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
 
-#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
-    /* Swap if non-host endianness or native (target) endianness */
-    return (end == DEVICE_HOST_ENDIAN) ? 0 : MO_BSWAP;
-#else
-    const int non_host_endianness =
-        DEVICE_LITTLE_ENDIAN ^ DEVICE_BIG_ENDIAN ^ DEVICE_HOST_ENDIAN;
-
-    /* In this case, native (target) endianness needs no swap.  */
-    return (end == non_host_endianness) ? MO_BSWAP : 0;
-#endif
+    bool big_endian = (end == DEVICE_NATIVE_ENDIAN
+                       ? target_words_bigendian()
+                       : end == DEVICE_BIG_ENDIAN);
+    return big_endian ? MO_BE : MO_LE;
 }
-#endif /* COMPILING_PER_TARGET */
 
 /*
  * Inhibit technologies that require discarding of pages in RAM blocks, e.g.,
-- 
2.39.5
Re: [PATCH v5 05/17] exec/memory.h: make devend_memop "target defines" agnostic
Posted by Philippe Mathieu-Daudé 2 weeks, 3 days ago
On 14/3/25 18:31, Pierrick Bouvier wrote:
> Will allow to make system/memory.c common later.
> 
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   include/exec/memory.h | 16 ++++------------
>   1 file changed, 4 insertions(+), 12 deletions(-)
> 
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index da21e9150b5..069021ac3ff 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -3138,25 +3138,17 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
>   MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
>                                 uint8_t c, hwaddr len, MemTxAttrs attrs);
>   
> -#ifdef COMPILING_PER_TARGET
>   /* enum device_endian to MemOp.  */
>   static inline MemOp devend_memop(enum device_endian end)
>   {
>       QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
>                         DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
>   
> -#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
> -    /* Swap if non-host endianness or native (target) endianness */
> -    return (end == DEVICE_HOST_ENDIAN) ? 0 : MO_BSWAP;
> -#else
> -    const int non_host_endianness =
> -        DEVICE_LITTLE_ENDIAN ^ DEVICE_BIG_ENDIAN ^ DEVICE_HOST_ENDIAN;
> -
> -    /* In this case, native (target) endianness needs no swap.  */
> -    return (end == non_host_endianness) ? MO_BSWAP : 0;
> -#endif
> +    bool big_endian = (end == DEVICE_NATIVE_ENDIAN
> +                       ? target_words_bigendian()
> +                       : end == DEVICE_BIG_ENDIAN);

Unnecessary parenthesis?

> +    return big_endian ? MO_BE : MO_LE;
>   }
> -#endif /* COMPILING_PER_TARGET */
>   
>   /*
>    * Inhibit technologies that require discarding of pages in RAM blocks, e.g.,
Re: [PATCH v5 05/17] exec/memory.h: make devend_memop "target defines" agnostic
Posted by Pierrick Bouvier 2 weeks, 3 days ago
On 3/17/25 08:48, Philippe Mathieu-Daudé wrote:
> On 14/3/25 18:31, Pierrick Bouvier wrote:
>> Will allow to make system/memory.c common later.
>>
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>>    include/exec/memory.h | 16 ++++------------
>>    1 file changed, 4 insertions(+), 12 deletions(-)
>>
>> diff --git a/include/exec/memory.h b/include/exec/memory.h
>> index da21e9150b5..069021ac3ff 100644
>> --- a/include/exec/memory.h
>> +++ b/include/exec/memory.h
>> @@ -3138,25 +3138,17 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
>>    MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
>>                                  uint8_t c, hwaddr len, MemTxAttrs attrs);
>>    
>> -#ifdef COMPILING_PER_TARGET
>>    /* enum device_endian to MemOp.  */
>>    static inline MemOp devend_memop(enum device_endian end)
>>    {
>>        QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
>>                          DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
>>    
>> -#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
>> -    /* Swap if non-host endianness or native (target) endianness */
>> -    return (end == DEVICE_HOST_ENDIAN) ? 0 : MO_BSWAP;
>> -#else
>> -    const int non_host_endianness =
>> -        DEVICE_LITTLE_ENDIAN ^ DEVICE_BIG_ENDIAN ^ DEVICE_HOST_ENDIAN;
>> -
>> -    /* In this case, native (target) endianness needs no swap.  */
>> -    return (end == non_host_endianness) ? MO_BSWAP : 0;
>> -#endif
>> +    bool big_endian = (end == DEVICE_NATIVE_ENDIAN
>> +                       ? target_words_bigendian()
>> +                       : end == DEVICE_BIG_ENDIAN);
> 
> Unnecessary parenthesis?
> 

Not strictly needed indeed.
Code is refactored in patch 14 anyways.

>> +    return big_endian ? MO_BE : MO_LE;
>>    }
>> -#endif /* COMPILING_PER_TARGET */
>>    
>>    /*
>>     * Inhibit technologies that require discarding of pages in RAM blocks, e.g.,
>