1 /* stpcpy -- copy SRC to DEST returning the address of the terminating '\0'
4 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
5 Contributed by Ulrich Drepper (drepper@gnu.ai.mit.edu).
6 This file is part of the GNU C Library.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 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 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with the GNU C Library; see the file COPYING.LIB. If
20 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This function is defined neither in ANSI nor POSIX standards but is
24 also not invented here. */
27 #include "asm-syntax.h"
37 movl 4(%esp), %eax /* load destination pointer */
38 movl 8(%esp), %ecx /* load source pointer */
40 subl %eax, %ecx /* magic: reduce number of loop variants
41 to one using addressing mode */
43 /* Here we would like to write
48 but the assembler is too smart and optimizes for the shortest
49 form where the number only needs one byte. But if we could
50 have the long form we would not need the alignment. */
52 .byte 0x81, 0xe8 /* This is `subl $0x00000004, %eax' */
55 /* Four times unfolded loop with only one loop counter. This
56 is achieved by the use of index+base adressing mode. As the
57 loop counter we use the destination address because this is
59 L1: addl $4, %eax /* increment loop counter */
61 movb (%eax,%ecx), %dl /* load current char */
62 movb %dl, (%eax) /* and store it */
63 testb %dl, %dl /* was it NUL? */
64 jz L2 /* yes, then exit */
66 movb 1(%eax,%ecx), %dl /* load current char */
67 movb %dl, 1(%eax) /* and store it */
68 testb %dl, %dl /* was it NUL? */
69 jz L3 /* yes, then exit */
71 movb 2(%eax,%ecx), %dl /* load current char */
72 movb %dl, 2(%eax) /* and store it */
73 testb %dl, %dl /* was it NUL? */
74 jz L4 /* yes, then exit */
76 movb 3(%eax,%ecx), %dl /* load current char */
77 movb %dl, 3(%eax) /* and store it */
78 testb %dl, %dl /* was it NUL? */
79 jnz L1 /* no, then continue loop */
81 incl %eax /* correct loop counter */
87 weak_alias (__stpcpy, stpcpy)