[compiler-rt] [compiler-rt][AArch64] Provide basic implementations of SME memcpy/memmove in case of strictly aligned memory access (PR #138250)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri May 9 02:08:15 PDT 2025


================
@@ -22,3 +23,46 @@ const void *__arm_sc_memchr(const void *src, int c,
 
   return NULL;
 }
+
+#ifndef __ARM_FEATURE_UNALIGNED
+
+static void *memcpy_fwd(void *dest, const void *src,
+                        size_t n) __arm_streaming_compatible {
+  unsigned char *destp = (unsigned char *)dest;
+  const unsigned char *srcp = (const unsigned char *)src;
+
+  for (size_t i = 0; i < n; ++i)
+    destp[i] = srcp[i];
+  return dest;
+}
+
+static void *memcpy_rev(void *dest, const void *src,
+                        size_t n) __arm_streaming_compatible {
+  unsigned char *destp = (unsigned char *)dest;
+  const unsigned char *srcp = (const unsigned char *)src;
+
+  while (n > 0) {
+    --n;
+    destp[n] = srcp[n];
+  }
+  return dest;
+}
+
+void *__arm_sc_memcpy(void *__restrict dest, const void *__restrict src,
+                      size_t n) __arm_streaming_compatible {
+  return memcpy_fwd(dest, src, n);
+}
+
+void *__arm_sc_memmove(void *dest, const void *src,
+                       size_t n) __arm_streaming_compatible {
+  unsigned char *destp = (unsigned char *)dest;
+  const unsigned char *srcp = (const unsigned char *)src;
+
+  if ((srcp > (destp + n)) || (destp > (srcp + n)))
+    return __arm_sc_memcpy(dest, src, n);
----------------
david-arm wrote:

I assume you're calling `__arm_sc_memcpy` because it has the `__restrict` attributes on the pointers and you're hoping the compiler will take advantage of that during compilation?

https://github.com/llvm/llvm-project/pull/138250


More information about the llvm-commits mailing list