[PATCH 06/13] tests/tcg/plugins: Use the ld/st_endian_p() API

Philippe Mathieu-Daudé posted 13 patches 1 month, 3 weeks ago
[PATCH 06/13] tests/tcg/plugins: Use the ld/st_endian_p() API
Posted by Philippe Mathieu-Daudé 1 month, 3 weeks ago
Refactor to use the recently introduced ld/st_endian_p() API
No logical change intended.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tests/tcg/plugins/mem.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c
index b0fa8a9f27..3586d05587 100644
--- a/tests/tcg/plugins/mem.c
+++ b/tests/tcg/plugins/mem.c
@@ -163,13 +163,9 @@ static void update_region_info(uint64_t region, uint64_t offset,
     {
         uint16_t *p = (uint16_t *) &ri->data[offset];
         if (is_store) {
-            if (be) {
-                stw_be_p(p, value.data.u16);
-            } else {
-                stw_le_p(p, value.data.u16);
-            }
+            stw_endian_p(be, p, value.data.u16);
         } else {
-            uint16_t val = be ? lduw_be_p(p) : lduw_le_p(p);
+            uint16_t val = lduw_endian_p(be, p);
             unseen_data = val != value.data.u16;
         }
         break;
@@ -178,13 +174,9 @@ static void update_region_info(uint64_t region, uint64_t offset,
     {
         uint32_t *p = (uint32_t *) &ri->data[offset];
         if (is_store) {
-            if (be) {
-                stl_be_p(p, value.data.u32);
-            } else {
-                stl_le_p(p, value.data.u32);
-            }
+            stl_endian_p(be, p, value.data.u32);
         } else {
-            uint32_t val = be ? ldl_be_p(p) : ldl_le_p(p);
+            uint32_t val = ldl_endian_p(be, p);
             unseen_data = val != value.data.u32;
         }
         break;
@@ -193,13 +185,9 @@ static void update_region_info(uint64_t region, uint64_t offset,
     {
         uint64_t *p = (uint64_t *) &ri->data[offset];
         if (is_store) {
-            if (be) {
-                stq_be_p(p, value.data.u64);
-            } else {
-                stq_le_p(p, value.data.u64);
-            }
+            stq_endian_p(be, p, value.data.u64);
         } else {
-            uint64_t val = be ? ldq_be_p(p) : ldq_le_p(p);
+            uint64_t val = ldq_endian_p(be, p);
             unseen_data = val != value.data.u64;
         }
         break;
-- 
2.45.2


Re: [PATCH 06/13] tests/tcg/plugins: Use the ld/st_endian_p() API
Posted by Alex Bennée 1 month, 3 weeks ago
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Refactor to use the recently introduced ld/st_endian_p() API
> No logical change intended.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Acked-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH 06/13] tests/tcg/plugins: Use the ld/st_endian_p() API
Posted by Pierrick Bouvier 1 month, 3 weeks ago
On 9/30/24 00:34, Philippe Mathieu-Daudé wrote:
> Refactor to use the recently introduced ld/st_endian_p() API
> No logical change intended.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   tests/tcg/plugins/mem.c | 24 ++++++------------------
>   1 file changed, 6 insertions(+), 18 deletions(-)
> 
> diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c
> index b0fa8a9f27..3586d05587 100644
> --- a/tests/tcg/plugins/mem.c
> +++ b/tests/tcg/plugins/mem.c
> @@ -163,13 +163,9 @@ static void update_region_info(uint64_t region, uint64_t offset,
>       {
>           uint16_t *p = (uint16_t *) &ri->data[offset];
>           if (is_store) {
> -            if (be) {
> -                stw_be_p(p, value.data.u16);
> -            } else {
> -                stw_le_p(p, value.data.u16);
> -            }
> +            stw_endian_p(be, p, value.data.u16);
>           } else {
> -            uint16_t val = be ? lduw_be_p(p) : lduw_le_p(p);
> +            uint16_t val = lduw_endian_p(be, p);
>               unseen_data = val != value.data.u16;
>           }
>           break;
> @@ -178,13 +174,9 @@ static void update_region_info(uint64_t region, uint64_t offset,
>       {
>           uint32_t *p = (uint32_t *) &ri->data[offset];
>           if (is_store) {
> -            if (be) {
> -                stl_be_p(p, value.data.u32);
> -            } else {
> -                stl_le_p(p, value.data.u32);
> -            }
> +            stl_endian_p(be, p, value.data.u32);
>           } else {
> -            uint32_t val = be ? ldl_be_p(p) : ldl_le_p(p);
> +            uint32_t val = ldl_endian_p(be, p);
>               unseen_data = val != value.data.u32;
>           }
>           break;
> @@ -193,13 +185,9 @@ static void update_region_info(uint64_t region, uint64_t offset,
>       {
>           uint64_t *p = (uint64_t *) &ri->data[offset];
>           if (is_store) {
> -            if (be) {
> -                stq_be_p(p, value.data.u64);
> -            } else {
> -                stq_le_p(p, value.data.u64);
> -            }
> +            stq_endian_p(be, p, value.data.u64);
>           } else {
> -            uint64_t val = be ? ldq_be_p(p) : ldq_le_p(p);
> +            uint64_t val = ldq_endian_p(be, p);
>               unseen_data = val != value.data.u64;
>           }
>           break;

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>