Skip to contentSkip to conversation

hw/misc/macio/cuda: Simplify using the ldst API

PATCH In review Philippe Mathieu-Daudé via 3 participants 3 messages Jan 24, 2022 – Jan 26, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/misc/macio/cuda: Simplify using the ldst API

This code is easier to review using the load/store API.

---
 hw/misc/macio/cuda.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/misc/macio/cuda.c +3 -6
index e917a6a095..f1186671bf 100644
@@ -36,6 +36,7 @@
 #include "sysemu/runstate.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
+#include "qemu/bswap.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "trace.h"
@@ -345,10 +346,7 @@ static bool cuda_cmd_get_time(CUDAState *s,
 
     ti = s->tick_offset + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)
                            / NANOSECONDS_PER_SECOND);
-    out_data[0] = ti >> 24;
-    out_data[1] = ti >> 16;
-    out_data[2] = ti >> 8;
-    out_data[3] = ti;
+    stl_be_p(out_data, ti);
     *out_len = 4;
     return true;
 }
@@ -363,8 +361,7 @@ static bool cuda_cmd_set_time(CUDAState *s,
         return false;
     }
 
-    ti = (((uint32_t)in_data[0]) << 24) + (((uint32_t)in_data[1]) << 16)
-         + (((uint32_t)in_data[2]) << 8) + in_data[3];
+    ti = ldl_be_p(in_data);
     s->tick_offset = ti - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)
                            / NANOSECONDS_PER_SECOND);
     return true;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Philippe Mathieu-Daudé via

This code is easier to review using the load/store API.

---
  hw/misc/macio/cuda.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
Signature · 4 lines
Matheus K. Ferst
Instituto de Pesquisas ELDORADO <http://www.eldorado.org.br/>
Analista de Software
Aviso Legal - Disclaimer <https://www.eldorado.org.br/disclaimer.html>
Reviewed-by on v1 1/1
#2 lore raw
In reply to Philippe Mathieu-Daudé via
Quoted 32 lines · Philippe Mathieu-Daudé via

This code is easier to review using the load/store API.

---
  hw/misc/macio/cuda.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
hw/misc/macio/cuda.c +2 -4
index e917a6a095..f1186671bf 100644
@@ -36,6 +36,7 @@
  #include "sysemu/runstate.h"
  #include "qapi/error.h"
  #include "qemu/cutils.h"
+#include "qemu/bswap.h"
  #include "qemu/log.h"
  #include "qemu/module.h"
  #include "trace.h"
@@ -345,10 +346,7 @@ static bool cuda_cmd_get_time(CUDAState *s,
 
      ti = s->tick_offset + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)
                             / NANOSECONDS_PER_SECOND);
-    out_data[0] = ti >> 24;
-    out_data[1] = ti >> 16;
-    out_data[2] = ti >> 8;
-    out_data[3] = ti;
+    stl_be_p(out_data, ti);
      *out_len = 4;
      return true;
  }

hw/misc/macio/cuda.c static bool cuda_cmd_set_time(CUDAState *s, · line 367

Quoted 9 lines
hw/misc/macio/cuda.c +1 -2
@@ -363,8 +361,7 @@ static bool cuda_cmd_set_time(CUDAState *s,
          return false;
      }
 
-    ti = (((uint32_t)in_data[0]) << 24) + (((uint32_t)in_data[1]) << 16)
-         + (((uint32_t)in_data[2]) << 8) + in_data[3];
+    ti = ldl_be_p(in_data);
      s->tick_offset = ti - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)
                             / NANOSECONDS_PER_SECOND);
      return true;

Looks fine to me.

ATB,

Mark.