RE: [PATCH 2/3] riscv: optimized memmove

From: David Laight
Date: Sun Jan 28 2024 - 07:47:37 EST


From: Jisheng Zhang
> Sent: 28 January 2024 11:10
>
> When the destination buffer is before the source one, or when the
> buffers doesn't overlap, it's safe to use memcpy() instead, which is
> optimized to use a bigger data size possible.
>
..
> + * Simply check if the buffer overlaps an call memcpy() in case,
> + * otherwise do a simple one byte at time backward copy.

I'd at least do a 64bit copy loop if the addresses are aligned.

Thinks a bit more....

Put the copy 64 bytes code (the body of the memcpy() loop)
into it an inline function and call it with increasing addresses
in memcpy() are decrementing addresses in memmove.

So memcpy() contains:
src_lim = src_lim + count;
... alignment copy
for (; src + 64 <= src_lim; src += 64; dest += 64)
copy_64_bytes(dest, src);
... tail copy

Then you can do something very similar for backwards copies.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)