diff mbox series

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

Message ID 20240930073450.33195-7-philmd@linaro.org
State New
Headers show
Series hw: Add ld/st_endian() APIs | expand

Commit Message

Philippe Mathieu-Daudé Sept. 30, 2024, 7:34 a.m. UTC
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(-)

Comments

Pierrick Bouvier Oct. 1, 2024, 4:50 p.m. UTC | #1
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>
Alex Bennée Oct. 2, 2024, 12:18 p.m. UTC | #2
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>
diff mbox series

Patch

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;