1 /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
3 Copyright (C) 1994-2013 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 <http://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"
29 #define PARMS LINKAGE /* no space for saved regs */
31 #define DEST RTN+RTN_SIZE
32 #define SRC DEST+PTR_SIZE
35 ENTRY (BP_SYM (__stpcpy))
40 CHECK_BOUNDS_LOW (%eax, DEST(%esp))
41 CHECK_BOUNDS_LOW (%ecx, SRC(%esp))
42 subl %eax, %ecx /* magic: reduce number of loop variants
43 to one using addressing mode */
45 /* Here we would like to write
50 but the assembler is too smart and optimizes for the shortest
51 form where the number only needs one byte. But if we could
52 have the long form we would not need the alignment. */
54 .byte 0x81, 0xe8 /* This is `subl $0x00000004, %eax' */
57 /* Four times unfolded loop with only one loop counter. This
58 is achieved by the use of index+base addressing mode. As the
59 loop counter we use the destination address because this is
61 L(1): addl $4, %eax /* increment loop counter */
63 movb (%eax,%ecx), %dl /* load current char */
64 movb %dl, (%eax) /* and store it */
65 testb %dl, %dl /* was it NUL? */
66 jz L(2) /* yes, then exit */
68 movb 1(%eax,%ecx), %dl /* load current char */
69 movb %dl, 1(%eax) /* and store it */
70 testb %dl, %dl /* was it NUL? */
71 jz L(3) /* yes, then exit */
73 movb 2(%eax,%ecx), %dl /* load current char */
74 movb %dl, 2(%eax) /* and store it */
75 testb %dl, %dl /* was it NUL? */
76 jz L(4) /* yes, then exit */
78 movb 3(%eax,%ecx), %dl /* load current char */
79 movb %dl, 3(%eax) /* and store it */
80 testb %dl, %dl /* was it NUL? */
81 jnz L(1) /* no, then continue loop */
83 incl %eax /* correct loop counter */
87 CHECK_BOUNDS_HIGH (%eax, DEST(%esp), jb)
88 RETURN_BOUNDED_POINTER (DEST(%esp))
92 END (BP_SYM (__stpcpy))
94 weak_alias (BP_SYM (__stpcpy), BP_SYM (stpcpy))
95 libc_hidden_def (__stpcpy)
96 libc_hidden_builtin_def (stpcpy)