Re: [PATCH 05/12] RISC-V: memmove() size optimized version: Replace lb with lbu
Kito Cheng <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CA+yXCZCVjbZc8otv_T6Z+RsMTndAqtFyxaP=0BuXN8sXqUOQgA@mail.gmail.com> |
LGTM On Wed, Apr 9, 2025 at 2:58 PM m fally <[email protected]> wrote: > > Replace lb with lbu to avoid unnecessary sign extension. > > Reviewed-by: Christian Herber <[email protected]> > Signed-off-by: m fally <[email protected]> > --- > newlib/libc/machine/riscv/memmove.S | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/newlib/libc/machine/riscv/memmove.S b/newlib/libc/machine/riscv/memmove.S > index 36fe00eba..671a6a158 100644 > --- a/newlib/libc/machine/riscv/memmove.S > +++ b/newlib/libc/machine/riscv/memmove.S > @@ -20,15 +20,15 @@ memmove: > li a3, 1 > bgtu a1, a0, .Lcopy /* in case of source address > destination address, copy from start to end of the specified memory area */ > > - li a3, -1 /* otherwhise, we need to start copying from the end of the specified memory area, therefore after each copied byte, increment the addresses by -1 */ > - add a4, a4, a2 /* add the number of bytes to be copied to both addresses. this gives an incorrect address, */ > + li a3, -1 /* otherwhise, start copying from the end of the specified memory area in order to prevent data loss in case of overlapping memory areas.*/ > + add a4, a4, a2 /* add the number of bytes to be copied to both addresses. this gives us the address one byte past the end of the memory area we want to copy, */ > add a1, a1, a2 /* therefore we need to subtract 1 from both addresses in the next step before starting the copying process. */ > > .Lincrement: > add a4, a4, a3 /* in case of source address < destination address, increment both addresses by -1 before copying any data to obtain the correct start addresses */ > add a1, a1, a3 > .Lcopy: > - lb a5, 0(a1) /* copy bytes as long as a2 (= the number of bytes to be copied) > 0 */ > + lbu a5, 0(a1) /* copy bytes as long as a2 (= the number of bytes to be copied) > 0 */ > sb a5, 0(a4) > add a2, a2, -1 > bnez a2, .Lincrement > -- > 2.49.0 >