Skip to content

Commit aa9db51

Browse files
committed
[libc] Align src buffer instead of dst buffer
We used to align destination buffer instead of source buffer for the loop of block copy. This is a mistake. Differential Revision: https://reviews.llvm.org/D93457
1 parent 223a6f9 commit aa9db51

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

libc/src/string/memory_utils/memcpy_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void CopyAlignedBlocks(char *__restrict dst, const char *__restrict src,
9090
CopyBlock<kBlockSize>(dst, src); // Copy first block
9191

9292
// Copy aligned blocks
93-
const size_t ofla = offset_from_last_aligned<kBlockSize>(dst);
93+
const size_t ofla = offset_from_last_aligned<kBlockSize>(src);
9494
const size_t limit = count + ofla - kBlockSize;
9595
for (size_t offset = kBlockSize; offset < limit; offset += kBlockSize)
9696
CopyBlock<kBlockSize>(dst - ofla + offset, src - ofla + offset);

libc/test/src/string/memory_utils/memcpy_utils_test.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ TEST(MemcpyUtilsTest, CopyBlockOverlap) {
162162

163163
TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
164164
auto &trace = GetTrace();
165-
// Destination is aligned and multiple of alignment.
165+
// Source is aligned and multiple of alignment.
166166
// "1111"
167167
trace.Clear();
168168
CopyAlignedBlocks<4>(I(0), I(0), 4);
169169
EXPECT_STREQ(trace.Write(), "2222");
170170
EXPECT_STREQ(trace.Read(), "2222");
171171

172-
// Destination is aligned and multiple of alignment.
172+
// Source is aligned and multiple of alignment.
173173
// "11110000"
174174
// + "00001111"
175175
// = "11111111"
@@ -178,7 +178,7 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
178178
EXPECT_STREQ(trace.Write(), "11111111");
179179
EXPECT_STREQ(trace.Read(), "11111111");
180180

181-
// Destination is aligned already overlap at end.
181+
// Source is aligned already overlap at end.
182182
// "1111000000000"
183183
// + "0000111100000"
184184
// + "0000000011110"
@@ -189,26 +189,26 @@ TEST(MemcpyUtilsTest, CopyAlignedBlocks) {
189189
EXPECT_STREQ(trace.Write(), "1111111112221");
190190
EXPECT_STREQ(trace.Read(), "1111111112221");
191191

192-
// Misaligned destination.
192+
// Misaligned source.
193193
// "01111000000000"
194194
// + "00001111000000"
195195
// + "00000000111100"
196196
// + "00000000001111"
197197
// = "01112111112211"
198198
trace.Clear();
199-
CopyAlignedBlocks<4>(I(1), I(0), 13);
200-
EXPECT_STREQ(trace.Write(), "01112111112211");
201-
EXPECT_STREQ(trace.Read(), "1112111112211");
199+
CopyAlignedBlocks<4>(I(0), I(1), 13);
200+
EXPECT_STREQ(trace.Write(), "1112111112211");
201+
EXPECT_STREQ(trace.Read(), "01112111112211");
202202

203-
// Misaligned destination aligned at end.
203+
// Misaligned source aligned at end.
204204
// "011110000000"
205205
// + "000011110000"
206206
// + "000000001111"
207207
// = "011121111111"
208208
trace.Clear();
209-
CopyAlignedBlocks<4>(I(1), I(0), 11);
210-
EXPECT_STREQ(trace.Write(), "011121111111");
211-
EXPECT_STREQ(trace.Read(), "11121111111");
209+
CopyAlignedBlocks<4>(I(0), I(1), 11);
210+
EXPECT_STREQ(trace.Write(), "11121111111");
211+
EXPECT_STREQ(trace.Read(), "011121111111");
212212
}
213213

214214
TEST(MemcpyUtilsTest, MaxReloads) {

0 commit comments

Comments
 (0)