[compiler-rt] [AArch64][compiler-rt] Add memcpy, memset, memmove, memchr simple imp… (PR #77496)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 06:20:35 PST 2024


================
@@ -0,0 +1,108 @@
+// REQUIRES: linux, aarch64-target-arch, aarch64-sme-available
+// RUN: %clangxx_builtins %s %librt -o %t && %run %t
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define N 16
+
+extern "C" {
+void *__arm_sc_memcpy(void *, const void *, size_t);
+void *__arm_sc_memset(void *, int, size_t);
+void *__arm_sc_memmove(void *, const void *, size_t);
+void *__arm_sc_memchr(const void *, int, size_t);
+}
+
+class MemoryArea {
----------------
sdesmalen-arm wrote:

Just an idea (no need to copy this literally), but I think you'd get more value from using a class like this if you'd do something like this:
```
template <unsigned N>
class Buffer {
public:
  uint8_t ptr[N];

  Buffer(int Stride = 0) {
    for (unsigned I=0; I < N; I+= Stride) {
      Src[I] = I;
    }
  }

  // to more quickly check that the result buffer matches a specific buffer.
  Buffer(std::initializer_list<...> S) { }

  bool assert_equal(const Buffer &Other) {
    // check here that ptr == Other.ptr
  }
};
```
Then you can do things like:
```
{ // test 1
  Memory<8> Src(1), Dst;
  __arm_sc_memcpy(Dst.ptr, Src.ptr, 8);
  Dst.assert_equal(Src);
  Dst.assert_equal({0, 1, 2, 3, 4, 5, 6, 7});
}
{ // test 2
  Memory<8> SrcDst(1);
  __arm_sc_memcpy(SrcDst.ptr + 1, SrcDst.ptr, 7);
  SrcDst.assert_equal({0, 0, 1, 2, 3, 4, 5, 6});
}
```
You could also compare it to the result from a regular `memcpy`.

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


More information about the llvm-commits mailing list