]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/i386/i586/strcpy.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / i386 / i586 / strcpy.S
1 /* strcpy/stpcpy implementation for i586.
2 Copyright (C) 1997-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <sysdep.h>
21 #include "asm-syntax.h"
22
23 #define PARMS 4+12 /* space for 3 saved regs */
24 #define RTN PARMS
25 #define DEST RTN
26 #define SRC DEST+4
27
28 #ifndef USE_AS_STPCPY
29 # define STRCPY strcpy
30 #endif
31
32 #define magic 0xfefefeff
33
34 .text
35 ENTRY (STRCPY)
36
37 pushl %edi
38 cfi_adjust_cfa_offset (4)
39 pushl %esi
40 cfi_adjust_cfa_offset (4)
41 pushl %ebx
42 cfi_adjust_cfa_offset (4)
43
44 movl DEST(%esp), %edi
45 cfi_rel_offset (edi, 8)
46 movl SRC(%esp), %esi
47 cfi_rel_offset (esi, 4)
48
49 xorl %eax, %eax
50 leal -1(%esi), %ecx
51
52 movl $magic, %ebx
53 cfi_rel_offset (ebx, 0)
54 andl $3, %ecx
55
56 cmpb $2, %cl
57 je L(Src2)
58 ja L(Src3)
59 cmpb $1, %cl
60 je L(Src1)
61
62 L(Src0):
63 orb (%esi), %al
64 jz L(end)
65 stosb
66 xorl %eax, %eax
67 incl %esi
68
69 L(Src1):
70 orb (%esi), %al
71 jz L(end)
72 stosb
73 xorl %eax, %eax
74 incl %esi
75
76 L(Src2):
77 orb (%esi), %al
78 jz L(end)
79 stosb
80 xorl %eax, %eax
81 incl %esi
82
83 L(Src3):
84 movl (%esi), %ecx
85 leal 4(%esi),%esi
86
87 subl %ecx, %eax
88 addl %ebx, %ecx
89
90 decl %eax
91 jnc L(3)
92
93 movl %ecx, %edx
94 xorl %ecx, %eax
95
96 subl %ebx, %edx
97 andl $~magic, %eax
98
99 jne L(4)
100
101 movl %edx, (%edi)
102 leal 4(%edi),%edi
103
104 jmp L(Src3)
105
106 L(3): movl %ecx, %edx
107
108 subl %ebx, %edx
109
110 L(4): movb %dl, (%edi)
111 testb %dl, %dl
112
113 movl %edx, %eax
114 jz L(end2)
115
116 shrl $16, %eax
117 movb %dh, 1(%edi)
118 #ifdef USE_AS_STPCPY
119 addl $1, %edi
120 #endif
121
122 cmpb $0, %dh
123 jz L(end2)
124
125 #ifdef USE_AS_STPCPY
126 movb %al, 1(%edi)
127 addl $1, %edi
128
129 cmpb $0, %al
130 jz L(end2)
131
132 addl $1, %edi
133 #else
134 movb %al, 2(%edi)
135 testb %al, %al
136
137 leal 3(%edi), %edi
138 jz L(end2)
139 #endif
140
141 L(end): movb %ah, (%edi)
142
143 L(end2):
144 #ifdef USE_AS_STPCPY
145 movl %edi, %eax
146 #else
147 movl DEST(%esp), %eax
148 #endif
149 popl %ebx
150 cfi_adjust_cfa_offset (-4)
151 cfi_restore (ebx)
152 popl %esi
153 cfi_adjust_cfa_offset (-4)
154 cfi_restore (esi)
155 popl %edi
156 cfi_adjust_cfa_offset (-4)
157 cfi_restore (edi)
158
159 ret
160 END (STRCPY)
161 #ifndef USE_AS_STPCPY
162 libc_hidden_builtin_def (strcpy)
163 #endif