(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / i386 / i586 / strcpy.S
blobf7c1986b4ba85d68ba21fabc8d5e64e818477b46
1 /* strcpy/stpcpy implementation for i586.
2    Copyright (C) 1997, 2000, 2003 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, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
21 #include <sysdep.h>
22 #include "asm-syntax.h"
23 #include "bp-sym.h"
24 #include "bp-asm.h"
26 #define PARMS   LINKAGE+12      /* space for 3 saved regs */
27 #define RTN     PARMS
28 #define DEST    RTN+RTN_SIZE
29 #define SRC     DEST+PTR_SIZE
31 #ifndef USE_AS_STPCPY
32 # define STRCPY strcpy
33 #endif
35 #define magic 0xfefefeff
37         .text
38 ENTRY (BP_SYM (STRCPY))
39         ENTER
41         pushl   %edi
42         pushl   %esi
43         pushl   %ebx
45         movl    DEST(%esp), %edi
46         movl    SRC(%esp), %esi
47         CHECK_BOUNDS_LOW (%edi, DEST(%esp))
48         CHECK_BOUNDS_LOW (%esi, SRC(%esp))
50         xorl    %eax, %eax
51         leal    -1(%esi), %ecx
53         movl    $magic, %ebx
54         andl    $3, %ecx
56 #ifdef PIC
57         call    2f
58 2:      popl    %edx
59         /* 0xb is the distance between 2: and 1: but we avoid writing
60            1f-2b because the assembler generates worse code.  */
61         leal    0xb(%edx,%ecx,8), %ecx
62 #else
63         leal    1f(,%ecx,8), %ecx
64 #endif
66         jmp     *%ecx
68         .align 8
70         orb     (%esi), %al
71         jz      L(end)
72         stosb
73         xorl    %eax, %eax
74         incl    %esi
76         orb     (%esi), %al
77         jz      L(end)
78         stosb
79         xorl    %eax, %eax
80         incl    %esi
82         orb     (%esi), %al
83         jz      L(end)
84         stosb
85         xorl    %eax, %eax
86         incl    %esi
88 L(1):   movl    (%esi), %ecx
89         leal    4(%esi),%esi
91         subl    %ecx, %eax
92         addl    %ebx, %ecx
94         decl    %eax
95         jnc     L(3)
97         movl    %ecx, %edx
98         xorl    %ecx, %eax
100         subl    %ebx, %edx
101         andl    $~magic, %eax
103         jne     L(4)
105         movl    %edx, (%edi)
106         leal    4(%edi),%edi
108         jmp     L(1)
110 L(3):   movl    %ecx, %edx
112         subl    %ebx, %edx
114 L(4):   movb    %dl, (%edi)
115         testb   %dl, %dl
117         movl    %edx, %eax
118         jz      L(end2)
120         shrl    $16, %eax
121         movb    %dh, 1(%edi)
122 #ifdef USE_AS_STPCPY
123         addl    $1, %edi
124 #endif
126         cmpb    $0, %dh
127         jz      L(end2)
129 #ifdef USE_AS_STPCPY
130         movb    %al, 1(%edi)
131         addl    $1, %edi
133         cmpb    $0, %al
134         jz      L(end2)
136         addl    $1, %edi
137 #else
138         movb    %al, 2(%edi)
139         testb   %al, %al
141         leal    3(%edi), %edi
142         jz      L(end2)
143 #endif
145 L(end): movb    %ah, (%edi)
147 L(end2):
148         /* GKM FIXME: check high bounds  */
149 #ifdef USE_AS_STPCPY
150         movl    %edi, %eax
151 #else
152         movl    DEST(%esp), %eax
153 #endif
154         RETURN_BOUNDED_POINTER (DEST(%esp))
155         popl    %ebx
156         popl    %esi
157         popl    %edi
159         LEAVE
160         RET_PTR
161 END (BP_SYM (STRCPY))
162 #ifndef USE_AS_STPCPY
163 libc_hidden_builtin_def (strcpy)
164 #endif