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

Guillaume Chatelet via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Sep 9 06:13:22 PDT 2021


gchatelet accepted this revision.
gchatelet added inline comments.
This revision is now accepted and ready to land.


================
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);
+}
----------------
gchatelet wrote:
> 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.
> 
> 
Let's submit this as is. `memmove` is the next function I'll be working on so I'll add the relevant facilities when I start working on it.


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