Well, I suggested it, so here's my attempt to switch powerpc64's
libc memmove.S over to 64 bits:
* Treat length parameter as 64 bits (size_t) instead of 32 (u_int).
* Set up the main loop to copy 64-bit doublewords instead of 32-bit
words.
This definitely needs double and triple checking.
Things I wonder about, but didn't touch:
* Why is the memcpy entry point commented out?
* END... STRONG? WEAK? BUILTIN?
Index: memmove.S
===================================================================
RCS file: /cvs/src/lib/libc/arch/powerpc64/string/memmove.S,v
retrieving revision 1.1
diff -u -p -r1.1 memmove.S
--- memmove.S 25 Jun 2020 02:34:22 -0000 1.1
+++ memmove.S 26 Jun 2020 22:22:51 -0000
@@ -39,7 +39,7 @@
* ==========================================================================
*/
-#include "SYS.h"
+#include "DEFS.h"
.text
@@ -64,45 +64,45 @@ ENTRY(memmove)
/* start of dest */
fwd:
- addi %r4, %r4, -4 /* Back up src and dst pointers */
- addi %r8, %r8, -4 /* due to auto-update of 'load' */
+ addi %r4, %r4, -8 /* Back up src and dst pointers */
+ addi %r8, %r8, -8 /* due to auto-update of 'load' */
- srwi. %r9,%r5,2 /* How many words in total cnt */
- beq- last1 /* Handle byte by byte if < 4 */
+ srdi. %r9,%r5,3 /* Doublewords in total count */
+ beq- last1 /* Handle byte by byte if < 8 */
/* bytes total */
- mtctr %r9 /* Count of words for loop */
- lwzu %r7, 4(%r4) /* Preload first word */
+ mtctr %r9 /* Count of dwords for loop */
+ ldu %r7, 8(%r4) /* Preload first doubleword */
b g1
g0: /* Main loop */
- lwzu %r7, 4(%r4) /* Load a new word */
- stwu %r6, 4(%r8) /* Store previous word */
+ ldu %r7, 8(%r4) /* Load a new doubleword */
+ stdu %r6, 8(%r8) /* Store previous doubleword */
g1:
bdz- last /* Dec cnt, and branch if just */
- /* one word to store */
- lwzu %r6, 4(%r4) /* Load another word */
- stwu %r7, 4(%r8) /* Store previous word */
+ /* one doubleword to store */
+ ldu %r6, 8(%r4) /* Load another doubleword */
+ stdu %r7, 8(%r8) /* Store previous doubleword */
bdnz+ g0 /* Dec cnt, and loop again if */
- /* more words */
- mr %r7, %r6 /* If word count -> 0, then... */
+ /* more doublewords */
+ mr %r7, %r6 /* If dword count -> 0, then... */
last:
- stwu %r7, 4(%r8) /* ... store last word */
+ stdu %r7, 8(%r8) /* ... store last doubleword */
last1: /* Byte-by-byte copy */
- clrlwi. %r5,%r5,30 /* If count -> 0, then ... */
+ clrldi. %r5,%r5,61 /* If count -> 0, then ... */
beqlr /* we're done */
mtctr %r5 /* else load count for loop */
- lbzu %r6, 4(%r4) /* 1st byte: update addr by 4 */
- stbu %r6, 4(%r8) /* since we pre-adjusted by 4 */
+ lbzu %r6, 8(%r4) /* 1st byte: update addr by 8 */
+ stbu %r6, 8(%r8) /* since we pre-adjusted by 8 */
bdzlr- /* in anticipation of main loop */
last2:
@@ -120,40 +120,40 @@ reverse:
add %r4, %r4, %r5 /* Work from end to beginning */
add %r8, %r8, %r5 /* so add count to string ptrs */
- srwi. %r9,%r5,2 /* Words in total count */
- beq- rlast1 /* Handle byte by byte if < 4 */
+ srdi. %r9,%r5,3 /* Doublewords in total count */
+ beq- rlast1 /* Handle byte by byte if < 8 */
/* bytes total */
- mtctr %r9 /* Count of words for loop */
+ mtctr %r9 /* Count of dwords for loop */
- lwzu %r7, -4(%r4) /* Preload first word */
+ ldu %r7, -8(%r4) /* Preload first doubleword */
b rg1
rg0: /* Main loop */
- lwzu %r7, -4(%r4) /* Load a new word */
- stwu %r6, -4(%r8) /* Store previous word */
+ ldu %r7, -8(%r4) /* Load a new doubleword */
+ stdu %r6, -8(%r8) /* Store previous doubleword */
rg1:
bdz- rlast /* Dec cnt, and branch if just */
- /* one word to store */
+ /* one doubleword to store */
- lwzu %r6, -4(%r4) /* Load another word */
- stwu %r7, -4(%r8) /* Store previous word */
+ ldu %r6, -8(%r4) /* Load another doubleword */
+ stdu %r7, -8(%r8) /* Store previous doubleword */
bdnz+ rg0 /* Dec cnt, and loop again if */
- /* more words */
+ /* more doublewords */
- mr %r7, %r6 /* If word count -> 0, then... */
+ mr %r7, %r6 /* If dword count -> 0, then... */
rlast:
- stwu %r7, -4(%r8) /* ... store last word */
+ stdu %r7, -8(%r8) /* ... store last doubleword */
rlast1: /* Byte-by-byte copy
*/
- clrlwi. %r5,%r5,30 /* If count -> 0, then... */
+ clrldi. %r5,%r5,61 /* If count -> 0, then... */
beqlr /* ... we're done */
mtctr %r5 /* else load count for loop */
--
Christian "naddy" Weisgerber [email protected]