[libc-commits] [PATCH] D109316: [libc] Some clean work with memmove.

Guillaume Chatelet via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Sep 6 08:35:17 PDT 2021


gchatelet added inline comments.


================
Comment at: libc/src/string/memmove.cpp:52-55
   // TODO: Optimize `move_byte_xxx(...)` functions.
-  if (dest_c < src_c)
-    move_byte_forward(dest_c, src_c, count);
-  if (dest_c > src_c)
-    move_byte_backward(dest_c, src_c, count);
-  return dest;
+  if (dst > src)
+    move_byte_backward(dst, src, count);
+}
----------------
cheng.w wrote:
> @gchatelet Is it possible to have an elementary operation `CopyBackward`? It copies aligned `kBlockSize` bytes backward.
> Acting like:
> ```
> CopyBackward<kBlockSize>(dst, src, count) {
>   for (size_t i = count / kBlockSize; i > 0; --i)
>     Copy(dst + i * kBlockSize, src + i * kBlockSize, kBlockSize)
> }  
> ```
> 
The current framework uses the following API to perform an align copy ([[ https://github.com/llvm/llvm-project/blob/dc453dcf760e6d558da3a4d7fff301baa5f37aba/libc/src/string/x86_64/memcpy.cpp#L96 | code in context ]])
```
Copy<Align<Element, Arg::Dst>::Then<Loop<Element>>>(dst, src, count);
```

To make it backward, we would need to provide `ReverseAlign` and `ReverseLoop` operations. It's doable but quite unique to memmove. I'll have a look in the next few days.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109316



More information about the libc-commits mailing list