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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 22 00:34:27 PST 2024


================
@@ -0,0 +1,122 @@
+// REQUIRES: aarch64-target-arch, aarch64-sme-available
+// RUN: %clangxx_builtins %s %librt -o %t && %run %t
+
+#include <cassert>
+#include <initializer_list>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+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);
+}
+
+template <unsigned N> class Memory {
+public:
+  uint8_t ptr[N];
+  unsigned size;
+
+  Memory(unsigned Stride = 0) {
+    size = N;
+    if (Stride == 0)
+      return;
+    for (unsigned I = 0, Elem = 0; I < N; I++) {
+      ptr[I] = I * Stride;
+    }
+  }
+
+  void assert_equal(const Memory &Other) {
+    assert(N == Other.size);
+    assert(memcmp(ptr, Other.ptr, N) == 0);
+  }
+
+  void assert_equal(std::initializer_list<uint8_t> S) {
+    assert(N == S.size());
+    auto It = S.begin();
+    for (unsigned I = 0; I < N; I++) {
+      assert(ptr[I] == *It++);
----------------
MaskRay wrote:

drop braces around simple single statement

compiler-rt/lib/builtins uses `lower_case` variable naming.

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


More information about the llvm-commits mailing list