1 /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
3 Copyright (C) 1994, 1995, 1996, 1997, 2000, 2002, 2004
4 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6 Contributed by Ulrich Drepper (drepper@gnu.ai.mit.edu).
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, see
20 <http://www.gnu.org/licenses/>. */
22 /* This function is defined neither in ANSI nor POSIX standards but is
23 also not invented here. */
26 #include "asm-syntax.h"
30 #define PARMS LINKAGE /* no space for saved regs */
32 #define DEST RTN+RTN_SIZE
33 #define SRC DEST+PTR_SIZE
36 ENTRY (BP_SYM (__stpcpy))
41 CHECK_BOUNDS_LOW (%eax, DEST(%esp))
42 CHECK_BOUNDS_LOW (%ecx, SRC(%esp))
43 subl %eax, %ecx /* magic: reduce number of loop variants
44 to one using addressing mode */
46 /* Here we would like to write
51 but the assembler is too smart and optimizes for the shortest
52 form where the number only needs one byte. But if we could
53 have the long form we would not need the alignment. */
55 .byte 0x81, 0xe8 /* This is `subl $0x00000004, %eax' */
58 /* Four times unfolded loop with only one loop counter. This
59 is achieved by the use of index+base addressing mode. As the
60 loop counter we use the destination address because this is
62 L(1): addl $4, %eax /* increment loop counter */
64 movb (%eax,%ecx), %dl /* load current char */
65 movb %dl, (%eax) /* and store it */
66 testb %dl, %dl /* was it NUL? */
67 jz L(2) /* yes, then exit */
69 movb 1(%eax,%ecx), %dl /* load current char */
70 movb %dl, 1(%eax) /* and store it */
71 testb %dl, %dl /* was it NUL? */
72 jz L(3) /* yes, then exit */
74 movb 2(%eax,%ecx), %dl /* load current char */
75 movb %dl, 2(%eax) /* and store it */
76 testb %dl, %dl /* was it NUL? */
77 jz L(4) /* yes, then exit */
79 movb 3(%eax,%ecx), %dl /* load current char */
80 movb %dl, 3(%eax) /* and store it */
81 testb %dl, %dl /* was it NUL? */
82 jnz L(1) /* no, then continue loop */
84 incl %eax /* correct loop counter */
88 CHECK_BOUNDS_HIGH (%eax, DEST(%esp), jb)
89 RETURN_BOUNDED_POINTER (DEST(%esp))
93 END (BP_SYM (__stpcpy))
95 weak_alias (BP_SYM (__stpcpy), BP_SYM (stpcpy))
96 libc_hidden_def (__stpcpy)
97 libc_hidden_builtin_def (stpcpy)