[PATCH v5 06/18] riscv: Add RVV memmove for multiarch and non-multiarch

Peter Bergner bergner@tenstorrent.com
Tue May 5 02:52:18 GMT 2026


I'm removing Hau Hsu <hau.hsu@sifive.com> from the CC list, since mail
has been bouncing from this address in my previous replies.


On 2/3/26 9:05 AM, Yao Zihong wrote:
> +    /* If src is equal or after dst, all data in src will be loaded before
> +    overwrited for the overlapping case. We could use faster `forward-copy`. */
> +    bgeu src, dst, L(forward_copy_loop)
> +    add src_backward_ptr, src, num
> +    add dst_backward_ptr, dst, num
> +    /* If dst inside source data range, we need to use `backward_copy_loop` to
> +    handle the overlapping issue. */
> +    bltu dst, src_backward_ptr, L(backward_copy_loop)

Since we need to compare DST and SRC to see whether we can use the forward
copy loop or whether we have to use the backward copy loop, I think we can
rewrite the code above to also optimize the special case of DST == SRC and
return immediately in that case.

We should be able to subtract DST and SRC and if the difference is zero,
we can return immediately.  Otherwise, we can compare that difference to
NUM to see whether there is 1) any overlap or 2) whether DST < SRC (given
the sign of the difference).  I think checking for 1) and 2) should be
doable in one unsigned conditional branch insn.

Peter




More information about the Libc-alpha mailing list