Skip to contentSkip to conversation

target/sparc: Use memcpy() in memcpy32()

PATCH Superseded Philippe Mathieu-Daudé 3 participants 3 messages Dec 4, 2024 – Dec 5, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/sparc: Use memcpy() in memcpy32()

Rather than manually copying each register, use
the libc memcpy(), which is well optimized.

---
Worth renaming as reg8cpy()?

---
 target/sparc/win_helper.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
target/sparc/win_helper.c +1 -8
index b53fc9ce940..dab0ff00ccc 100644
@@ -26,14 +26,7 @@
 
 static inline void memcpy32(target_ulong *dst, const target_ulong *src)
 {
-    dst[0] = src[0];
-    dst[1] = src[1];
-    dst[2] = src[2];
-    dst[3] = src[3];
-    dst[4] = src[4];
-    dst[5] = src[5];
-    dst[6] = src[6];
-    dst[7] = src[7];
+    memcpy(dst, src, 8 * sizeof(target_ulong));
 }
 
 void cpu_set_cwp(CPUSPARCState *env, int new_cwp)
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Philippe Mathieu-Daudé

Rather than manually copying each register, use
the libc memcpy(), which is well optimized.

---
Worth renaming as reg8cpy()?

---
  target/sparc/win_helper.c | 9 +--------
  1 file changed, 1 insertion(+), 8 deletions(-)
target/sparc/win_helper.c +0 -2
index b53fc9ce940..dab0ff00ccc 100644
@@ -26,14 +26,7 @@
 
  static inline void memcpy32(target_ulong *dst, const target_ulong *src)
  {
-    dst[0] = src[0];
-    dst[1] = src[1];

target/sparc/win_helper.c line 32

Quoted 10 lines
target/sparc/win_helper.c +1 -6
-    dst[2] = src[2];
-    dst[3] = src[3];
-    dst[4] = src[4];
-    dst[5] = src[5];
-    dst[6] = src[6];
-    dst[7] = src[7];
+    memcpy(dst, src, 8 * sizeof(target_ulong));
  }
 
  void cpu_set_cwp(CPUSPARCState *env, int new_cwp)

Potentially we could go further and just remove the memcpy32 function.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 20 lines · Philippe Mathieu-Daudé

Rather than manually copying each register, use
the libc memcpy(), which is well optimized.

---
Worth renaming as reg8cpy()?

---
  target/sparc/win_helper.c | 9 +--------
  1 file changed, 1 insertion(+), 8 deletions(-)
target/sparc/win_helper.c +0 -2
index b53fc9ce940..dab0ff00ccc 100644
@@ -26,14 +26,7 @@
 
  static inline void memcpy32(target_ulong *dst, const target_ulong *src)
  {
-    dst[0] = src[0];
-    dst[1] = src[1];

target/sparc/win_helper.c line 32

Quoted 10 lines
target/sparc/win_helper.c +1 -6
-    dst[2] = src[2];
-    dst[3] = src[3];
-    dst[4] = src[4];
-    dst[5] = src[5];
-    dst[6] = src[6];
-    dst[7] = src[7];
+    memcpy(dst, src, 8 * sizeof(target_ulong));
  }
 
  void cpu_set_cwp(CPUSPARCState *env, int new_cwp)

Once upon a time, calling the libc function was slower. That optimization is probably at least 10 years out of date. I imagine this gets expanded inline as a vector copy these days.

I'll agree with Pierrick that we can probably remove the function too.

r~