1 /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
3 Copyright (C) 1994, 1995, 1996, 1997 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 Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 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 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* This function is defined neither in ANSI nor POSIX standards but is
23 also not invented here. */
26 #include "asm-syntax.h"
36 movl 4(%esp), %eax /* load destination pointer */
37 movl 8(%esp), %ecx /* load source pointer */
39 subl %eax, %ecx /* magic: reduce number of loop variants
40 to one using addressing mode */
42 /* Here we would like to write
47 but the assembler is too smart and optimizes for the shortest
48 form where the number only needs one byte. But if we could
49 have the long form we would not need the alignment. */
51 .byte 0x81, 0xe8 /* This is `subl $0x00000004, %eax' */
54 /* Four times unfolded loop with only one loop counter. This
55 is achieved by the use of index+base addressing mode. As the
56 loop counter we use the destination address because this is
58 L(1): addl $4, %eax /* increment loop counter */
60 movb (%eax,%ecx), %dl /* load current char */
61 movb %dl, (%eax) /* and store it */
62 testb %dl, %dl /* was it NUL? */
63 jz L(2) /* yes, then exit */
65 movb 1(%eax,%ecx), %dl /* load current char */
66 movb %dl, 1(%eax) /* and store it */
67 testb %dl, %dl /* was it NUL? */
68 jz L(3) /* yes, then exit */
70 movb 2(%eax,%ecx), %dl /* load current char */
71 movb %dl, 2(%eax) /* and store it */
72 testb %dl, %dl /* was it NUL? */
73 jz L(4) /* yes, then exit */
75 movb 3(%eax,%ecx), %dl /* load current char */
76 movb %dl, 3(%eax) /* and store it */
77 testb %dl, %dl /* was it NUL? */
78 jnz L(1) /* no, then continue loop */
80 incl %eax /* correct loop counter */
87 weak_alias (__stpcpy, stpcpy)