2 * Adapted by Guillaume Morin <guillaume@morinfr.org> from strcpy.S
3 * written by J.T. Conklin <jtc@acorntoolworks.com>
7 #include <machine/asm.h>
11 * This stpcpy implementation copies a byte at a time until the
12 * source pointer is aligned to a word boundary, it then copies by
13 * words until it finds a word containing a zero byte, and finally
14 * copies by bytes until the end of the string is reached.
16 * While this may result in unaligned stores if the source and
17 * destination pointers are unaligned with respect to each other,
18 * it is still faster than either byte copies or the overhead of
19 * an implementation suitable for machines with strict alignment
23 .globl stpcpy,__stpcpy
26 movabsq $0x0101010101010101,%r8
27 movabsq $0x8080808080808080,%r9
30 * Align source to a word boundary.
31 * Consider unrolling loop?
59 * In rare cases, the above loop may exit prematurely. We must
60 * return to the loop if none of the bytes in the word equal 0.
64 testb %dl,%dl /* 1st byte == 0? */
70 testb %dl,%dl /* 2nd byte == 0? */
76 testb %dl,%dl /* 3rd byte == 0? */
82 testb %dl,%dl /* 4th byte == 0? */
88 testb %dl,%dl /* 5th byte == 0? */
94 testb %dl,%dl /* 6th byte == 0? */
100 testb %dl,%dl /* 7th byte == 0? */
107 testb %dl,%dl /* 8th byte == 0? */
116 .section .note.GNU-stack,"",%progbits