1 /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper (drepper@gnu.ai.mit.edu).
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <https://www.gnu.org/licenses/>. */
21 /* This function is defined neither in ANSI nor POSIX standards but is
22 also not invented here. */
25 #include "asm-syntax.h"
27 #define PARMS 4 /* no space for saved regs */
37 subl %eax, %ecx /* magic: reduce number of loop variants
38 to one using addressing mode */
40 /* Here we would like to write
45 but the assembler is too smart and optimizes for the shortest
46 form where the number only needs one byte. But if we could
47 have the long form we would not need the alignment. */
49 .byte 0x81, 0xe8 /* This is `subl $0x00000004, %eax' */
52 /* Four times unfolded loop with only one loop counter. This
53 is achieved by the use of index+base addressing mode. As the
54 loop counter we use the destination address because this is
56 L(1): addl $4, %eax /* increment loop counter */
58 movb (%eax,%ecx), %dl /* load current char */
59 movb %dl, (%eax) /* and store it */
60 testb %dl, %dl /* was it NUL? */
61 jz L(2) /* yes, then exit */
63 movb 1(%eax,%ecx), %dl /* load current char */
64 movb %dl, 1(%eax) /* and store it */
65 testb %dl, %dl /* was it NUL? */
66 jz L(3) /* yes, then exit */
68 movb 2(%eax,%ecx), %dl /* load current char */
69 movb %dl, 2(%eax) /* and store it */
70 testb %dl, %dl /* was it NUL? */
71 jz L(4) /* yes, then exit */
73 movb 3(%eax,%ecx), %dl /* load current char */
74 movb %dl, 3(%eax) /* and store it */
75 testb %dl, %dl /* was it NUL? */
76 jnz L(1) /* no, then continue loop */
78 incl %eax /* correct loop counter */
86 weak_alias (__stpcpy, stpcpy)
87 libc_hidden_def (__stpcpy)
88 libc_hidden_builtin_def (stpcpy)