From 55207c949e92c91d0f6c83514d34ffe314f0c263 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Mon, 14 Feb 2022 14:05:32 +0000 Subject: [PATCH] Correct to memmoveu32 for when forward copying is needed --- src/CoreIO.cpp | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/CoreIO.cpp b/src/CoreIO.cpp index 16b8ae7b..282b84b3 100644 --- a/src/CoreIO.cpp +++ b/src/CoreIO.cpp @@ -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; + } } }