diff options
author | Guillaume Chatelet <gchatelet@google.com> | 2020-11-23 17:30:39 +0000 |
---|---|---|
committer | Guillaume Chatelet <gchatelet@google.com> | 2020-11-30 08:24:10 +0000 |
commit | 699d17d4d64e9b1cf6db0443e87a700104e94aca (patch) | |
tree | a164ce8caf8abdf653e0d531fdb8f34fa1eaae59 /libc/test | |
parent | ec6c5e920a89db0e1c5f73b8349ee0b84192072d (diff) | |
download | llvm-project-699d17d4d64e9b1cf6db0443e87a700104e94aca.tar.gz |
[libc] Improve memcpy copy loop
Rewriting loop so the terminating condition does not depend on the loop body
Differential Revision: https://reviews.llvm.org/D91976
Diffstat (limited to 'libc/test')
-rw-r--r-- | libc/test/src/string/memory_utils/memcpy_utils_test.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/libc/test/src/string/memory_utils/memcpy_utils_test.cpp b/libc/test/src/string/memory_utils/memcpy_utils_test.cpp index 7e32fb4f3080..93c0c48c8976 100644 --- a/libc/test/src/string/memory_utils/memcpy_utils_test.cpp +++ b/libc/test/src/string/memory_utils/memcpy_utils_test.cpp @@ -162,7 +162,23 @@ TEST(MemcpyUtilsTest, CopyBlockOverlap) { TEST(MemcpyUtilsTest, CopyAlignedBlocks) { auto &trace = GetTrace(); - // Destination is aligned already. + // Destination is aligned and multiple of alignment. + // "1111" + trace.Clear(); + CopyAlignedBlocks<4>(I(0), I(0), 4); + EXPECT_STREQ(trace.Write(), "2222"); + EXPECT_STREQ(trace.Read(), "2222"); + + // Destination is aligned and multiple of alignment. + // "11110000" + // + "00001111" + // = "11111111" + trace.Clear(); + CopyAlignedBlocks<4>(I(0), I(0), 8); + EXPECT_STREQ(trace.Write(), "11111111"); + EXPECT_STREQ(trace.Read(), "11111111"); + + // Destination is aligned already overlap at end. // "1111000000000" // + "0000111100000" // + "0000000011110" @@ -173,7 +189,7 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) { EXPECT_STREQ(trace.Write(), "1111111112221"); EXPECT_STREQ(trace.Read(), "1111111112221"); - // Misaligned destination + // Misaligned destination. // "01111000000000" // + "00001111000000" // + "00000000111100" @@ -183,6 +199,16 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) { CopyAlignedBlocks<4>(I(1), I(0), 13); EXPECT_STREQ(trace.Write(), "01112111112211"); EXPECT_STREQ(trace.Read(), "1112111112211"); + + // Misaligned destination aligned at end. + // "011110000000" + // + "000011110000" + // + "000000001111" + // = "011121111111" + trace.Clear(); + CopyAlignedBlocks<4>(I(1), I(0), 11); + EXPECT_STREQ(trace.Write(), "011121111111"); + EXPECT_STREQ(trace.Read(), "11121111111"); } TEST(MemcpyUtilsTest, MaxReloads) { |