]>
Commit | Line | Data |
---|---|---|
8f5ca04b RM |
1 | /* stpcpy -- copy SRC to DEST returning the address of the terminating '\0' |
2 | in DEST. | |
3 | For Intel 80x86, x>=3. | |
cccda09f | 4 | Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. |
8f5ca04b RM |
5 | Contributed by Ulrich Drepper (drepper@gnu.ai.mit.edu). |
6 | This file is part of the GNU C Library. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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. */ | |
22 | ||
23 | /* This function is defined neither in ANSI nor POSIX standards but is | |
24 | also not invented here. */ | |
25 | ||
26 | #include <sysdep.h> | |
27 | #include "asm-syntax.h" | |
28 | ||
29 | /* | |
30 | INPUT PARAMETERS: | |
31 | dest (sp + 4) | |
32 | src (sp + 8) | |
33 | */ | |
34 | ||
35 | .text | |
36 | ENTRY (__stpcpy) | |
37 | movl 4(%esp), %eax /* load destination pointer */ | |
38 | movl 8(%esp), %ecx /* load source pointer */ | |
39 | ||
40 | subl %eax, %ecx /* magic: reduce number of loop variants | |
41 | to one using addressing mode */ | |
42 | ||
43 | /* Here we would like to write | |
44 | ||
45 | subl $4, %eax | |
46 | ALIGN (4) | |
47 | ||
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. */ | |
51 | ||
52 | .byte 0x81, 0xe8 /* This is `subl $0x00000004, %eax' */ | |
53 | .long 0x00000004 | |
54 | ||
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 | |
58 | also the result. */ | |
59 | L1: addl $4, %eax /* increment loop counter */ | |
60 | ||
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 */ | |
65 | ||
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 */ | |
70 | ||
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 */ | |
75 | ||
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 */ | |
80 | ||
81 | incl %eax /* correct loop counter */ | |
82 | L4: incl %eax | |
83 | L3: incl %eax | |
84 | L2: | |
85 | ret | |
6ed0492f | 86 | END (__stpcpy) |
8f5ca04b RM |
87 | |
88 | weak_alias (__stpcpy, stpcpy) |