aboutsummaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorm fally <marlene.fally@gmail.com>2025-04-10 13:23:01 +0200
committerJeff Johnston <jjohnstn@redhat.com>2025-04-11 16:47:56 -0400
commita9cfc2b8b44e035dbc479a1a9db3e9613699c9b1 (patch)
tree50aca7aa976c589efc9dc210aeee67609f06e2ac /newlib
parent4a6070a1a0d5433adac9609bae180a95a919122b (diff)
downloadnewlib-a9cfc2b8b44e035dbc479a1a9db3e9613699c9b1.zip
newlib-a9cfc2b8b44e035dbc479a1a9db3e9613699c9b1.tar.gz
newlib-a9cfc2b8b44e035dbc479a1a9db3e9613699c9b1.tar.bz2
RISC-V: memmove() size optimized version: Add comments
Since the algorithm in this version of memmove() is different from the original version, add comments to give a description. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Reviewed-by: Eric Salem <ericsalem@gmail.com> Signed-off-by: m fally <marlene.fally@gmail.com>
Diffstat (limited to 'newlib')
-rw-r--r--newlib/libc/machine/riscv/memmove.S16
1 files changed, 8 insertions, 8 deletions
diff --git a/newlib/libc/machine/riscv/memmove.S b/newlib/libc/machine/riscv/memmove.S
index a77ac44..36fe00e 100644
--- a/newlib/libc/machine/riscv/memmove.S
+++ b/newlib/libc/machine/riscv/memmove.S
@@ -14,21 +14,21 @@
.global memmove
.type memmove, @function
memmove:
- beqz a2, .Ldone
+ beqz a2, .Ldone /* in case there are 0 bytes to be copied, return immediately */
- mv a4, a0
+ mv a4, a0 /* copy the destination address over to a4, since memmove should return that address in a0 at the end */
li a3, 1
- bgtu a1, a0, .Lcopy
+ bgtu a1, a0, .Lcopy /* in case of source address > destination address, copy from start to end of the specified memory area */
- li a3, -1
- add a4, a4, a2
- add a1, a1, a2
+ 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, */
+ 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
+ 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)
+ lb 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