Skip to content

Commit

Permalink
Correct to memmoveu32 for when forward copying is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dc42 committed Feb 14, 2022
1 parent 943328f commit 55207c9
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/CoreIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,34 +427,41 @@ void __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) memcp

if ((numWords & 1) != 0)
{
*dst++ = *src++;
*dst = *src;
}
}

// Optimised version of memmove for when we know that the source and destination are 32-bit aligned and a whole number of 32-bit words are to be copied
void __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) memmoveu32(uint32_t *_ecv_array dst, const uint32_t *_ecv_array src, size_t numWords) noexcept
{
dst += numWords;
src += numWords;

while (numWords >= 4)
if (dst <= src)
{
*--dst = *--src;
*--dst = *--src;
*--dst = *--src;
*--dst = *--src;
numWords -= 4;
memcpyu32(dst, src, numWords);
}

if ((numWords & 2) != 0)
else
{
*--dst = *--src;
*--dst = *--src;
}
dst += numWords;
src += numWords;

if ((numWords & 1) != 0)
{
*--dst = *--src;
while (numWords >= 4)
{
*--dst = *--src;
*--dst = *--src;
*--dst = *--src;
*--dst = *--src;
numWords -= 4;
}

if ((numWords & 2) != 0)
{
*--dst = *--src;
*--dst = *--src;
}

if ((numWords & 1) != 0)
{
*--dst = *--src;
}
}
}

Expand Down

0 comments on commit 55207c9

Please sign in to comment.