[libc-commits] [PATCH] D152811: [libc] Dispatch memmove to memcpy when buffers are disjoint

Clement Courbet via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jun 13 07:12:45 PDT 2023


courbet added inline comments.


================
Comment at: libc/src/string/memory_utils/utils.h:87
 
+// Returns true iff memory regions [p1, p1 + size] and [p2, 2 + size] are
+// disjoint.
----------------
typo: `p2`


================
Comment at: libc/src/string/memory_utils/utils.h:89
+// disjoint.
+LIBC_INLINE bool disjoint(const void *p1, const void *p2, size_t size) {
+  const char *a = static_cast<const char *>(p1);
----------------
[nit] `is_disjoint`


================
Comment at: libc/src/string/memory_utils/utils.h:93
+  if (a > b) {
+    // Swap a and b, this is compile down to conditionnal move for aarch64 / x86
+    // and RISCV with zbb extension.
----------------
compiles


================
Comment at: libc/src/string/memory_utils/utils.h:95
+    // and RISCV with zbb extension.
+    auto tmp = a;
+    a = b;
----------------
`const char*`


================
Comment at: libc/test/src/string/memory_utils/utils_test.cpp:148
+TEST(LlvmLibcUtilsTest, DisjointBuffers) {
+  char a, b;
+  EXPECT_TRUE(disjoint(&a, &b, 0));
----------------
The layout of this is not guaramteed. Let's do :  `char ps[3`].


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152811/new/

https://reviews.llvm.org/D152811



More information about the libc-commits mailing list