Commit d76232ff authored by Willy Tarreau's avatar Willy Tarreau Committed by Paul E. McKenney

tools/nolibc/string: slightly simplify memmove()

The direction test inside the loop was not always completely optimized,
resulting in a larger than necessary function. This change adds a
direction variable that is set out of the loop. Now the function is down
to 48 bytes on x86, 32 on ARM and 68 on mips. It's worth noting that other
approaches were attempted (including relying on the up and down functions)
but they were only slightly beneficial on x86 and cost more on others.
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
parent d8dcc2d8
...@@ -50,14 +50,22 @@ void *_nolibc_memcpy_down(void *dst, const void *src, size_t len) ...@@ -50,14 +50,22 @@ void *_nolibc_memcpy_down(void *dst, const void *src, size_t len)
static __attribute__((unused)) static __attribute__((unused))
void *memmove(void *dst, const void *src, size_t len) void *memmove(void *dst, const void *src, size_t len)
{ {
ssize_t pos = (dst <= src) ? -1 : (long)len; size_t dir, pos;
void *ret = dst;
while (len--) { pos = len;
pos += (dst <= src) ? 1 : -1; dir = -1;
((char *)dst)[pos] = ((char *)src)[pos];
if (dst < src) {
pos = -1;
dir = 1;
} }
return ret;
while (len) {
pos += dir;
((char *)dst)[pos] = ((const char *)src)[pos];
len--;
}
return dst;
} }
/* must be exported, as it's used by libgcc on ARM */ /* must be exported, as it's used by libgcc on ARM */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment