This is an archive of the discontinued LLVM Phabricator instance.

[libc] Some clean work with memmove.
ClosedPublic

Authored by cheng.w on Sep 6 2021, 4:32 AM.

Details

Summary
  • Replace move_byte_forward() with memcpy. In memcpy implementation,

it copies bytes forward from beginning to end. Otherwise, memmove unit
tests will break.

  • Make memmove unit tests work.

Diff Detail

Event Timeline

cheng.w created this revision.Sep 6 2021, 4:32 AM
cheng.w requested review of this revision.Sep 6 2021, 4:32 AM
cheng.w added inline comments.Sep 6 2021, 4:39 AM
libc/src/string/memmove.cpp
52–55

@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)
}
gchatelet added inline comments.Sep 6 2021, 8:35 AM
libc/src/string/memmove.cpp
52–55

The current framework uses the following API to perform an align copy (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.

gchatelet accepted this revision.Sep 9 2021, 6:13 AM
gchatelet added inline comments.
libc/src/string/memmove.cpp
52–55

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.

This revision is now accepted and ready to land.Sep 9 2021, 6:13 AM
This revision was automatically updated to reflect the committed changes.