Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / i386 / i586 / strcpy.S
blobb06149153249fd9b4b14801a794a0eec9246d52e
1 /* strcpy/stpcpy implementation for i586.
2    Copyright (C) 1997-2014 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
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.
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.
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/>.  */
20 #include <sysdep.h>
21 #include "asm-syntax.h"
23 #define PARMS   4+12    /* space for 3 saved regs */
24 #define RTN     PARMS
25 #define DEST    RTN
26 #define SRC     DEST+4
28 #ifndef USE_AS_STPCPY
29 # define STRCPY strcpy
30 #endif
32 #define magic 0xfefefeff
34         .text
35 ENTRY (STRCPY)
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)
44         movl    DEST(%esp), %edi
45         cfi_rel_offset (edi, 8)
46         movl    SRC(%esp), %esi
47         cfi_rel_offset (esi, 4)
49         xorl    %eax, %eax
50         leal    -1(%esi), %ecx
52         movl    $magic, %ebx
53         cfi_rel_offset (ebx, 0)
54         andl    $3, %ecx
56 #ifdef PIC
57         call    2f
58         cfi_adjust_cfa_offset (4)
59 2:      popl    %edx
60         cfi_adjust_cfa_offset (-4)
61         /* 0xb is the distance between 2: and 1: but we avoid writing
62            1f-2b because the assembler generates worse code.  */
63         leal    0xb(%edx,%ecx,8), %ecx
64 #else
65         leal    1f(,%ecx,8), %ecx
66 #endif
68         jmp     *%ecx
70         .align 8
72         orb     (%esi), %al
73         jz      L(end)
74         stosb
75         xorl    %eax, %eax
76         incl    %esi
78         orb     (%esi), %al
79         jz      L(end)
80         stosb
81         xorl    %eax, %eax
82         incl    %esi
84         orb     (%esi), %al
85         jz      L(end)
86         stosb
87         xorl    %eax, %eax
88         incl    %esi
90 L(1):   movl    (%esi), %ecx
91         leal    4(%esi),%esi
93         subl    %ecx, %eax
94         addl    %ebx, %ecx
96         decl    %eax
97         jnc     L(3)
99         movl    %ecx, %edx
100         xorl    %ecx, %eax
102         subl    %ebx, %edx
103         andl    $~magic, %eax
105         jne     L(4)
107         movl    %edx, (%edi)
108         leal    4(%edi),%edi
110         jmp     L(1)
112 L(3):   movl    %ecx, %edx
114         subl    %ebx, %edx
116 L(4):   movb    %dl, (%edi)
117         testb   %dl, %dl
119         movl    %edx, %eax
120         jz      L(end2)
122         shrl    $16, %eax
123         movb    %dh, 1(%edi)
124 #ifdef USE_AS_STPCPY
125         addl    $1, %edi
126 #endif
128         cmpb    $0, %dh
129         jz      L(end2)
131 #ifdef USE_AS_STPCPY
132         movb    %al, 1(%edi)
133         addl    $1, %edi
135         cmpb    $0, %al
136         jz      L(end2)
138         addl    $1, %edi
139 #else
140         movb    %al, 2(%edi)
141         testb   %al, %al
143         leal    3(%edi), %edi
144         jz      L(end2)
145 #endif
147 L(end): movb    %ah, (%edi)
149 L(end2):
150 #ifdef USE_AS_STPCPY
151         movl    %edi, %eax
152 #else
153         movl    DEST(%esp), %eax
154 #endif
155         popl    %ebx
156         cfi_adjust_cfa_offset (-4)
157         cfi_restore (ebx)
158         popl    %esi
159         cfi_adjust_cfa_offset (-4)
160         cfi_restore (esi)
161         popl    %edi
162         cfi_adjust_cfa_offset (-4)
163         cfi_restore (edi)
165         ret
166 END (STRCPY)
167 #ifndef USE_AS_STPCPY
168 libc_hidden_builtin_def (strcpy)
169 #endif