Fix issues in x86 memcpy-ssse3.S
[glibc.git] / sysdeps / i386 / i686 / memmove.S
blob981f14f4e0a9fb78d742c8dd9cc3e947d72d5959
1 /* Copy memory block and return pointer to beginning of destination block
2    For Intel 80x86, x>=6.
3    This file is part of the GNU C Library.
4    Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
5    Contributed by Ulrich Drepper <drepper@cygnus.com>, 2003.
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public
9    License as published by the Free Software Foundation; either
10    version 2.1 of the License, or (at your option) any later version.
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; if not, write to the Free
19    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20    02111-1307 USA.  */
22 #include <sysdep.h>
23 #include "asm-syntax.h"
24 #include "bp-sym.h"
25 #include "bp-asm.h"
27 #define PARMS   LINKAGE+4       /* one spilled register */
28 #define RTN     PARMS
30         .text
32 #ifdef USE_AS_BCOPY
33 # define SRC    RTN+RTN_SIZE
34 # define DEST   SRC+PTR_SIZE
35 # define LEN    DEST+PTR_SIZE
36 #else
37 # define DEST   RTN+RTN_SIZE
38 # define SRC    DEST+PTR_SIZE
39 # define LEN    SRC+PTR_SIZE
41 # if defined PIC && !defined NOT_IN_libc
42 ENTRY_CHK (__memmove_chk)
43         movl    12(%esp), %eax
44         cmpl    %eax, 16(%esp)
45         jb      HIDDEN_JUMPTARGET (__chk_fail)
46 END_CHK (__memmove_chk)
47 # endif
48 #endif
50 ENTRY (BP_SYM (memmove))
51         ENTER
53         pushl   %edi
54         cfi_adjust_cfa_offset (4)
56         movl    LEN(%esp), %ecx
57         movl    DEST(%esp), %edi
58         cfi_rel_offset (edi, 0)
59         movl    %esi, %edx
60         movl    SRC(%esp), %esi
61         cfi_register (esi, edx)
62         CHECK_BOUNDS_BOTH_WIDE (%edi, DEST(%esp), %ecx)
63         CHECK_BOUNDS_BOTH_WIDE (%esi, SRC(%esp), %ecx)
65         movl    %edi, %eax
66         subl    %esi, %eax
67         cmpl    %eax, %edi
68         jae     3f
70         cld
71         shrl    $1, %ecx
72         jnc     1f
73         movsb
74 1:      shrl    $1, %ecx
75         jnc     2f
76         movsw
77 2:      rep
78         movsl
79         movl    %edx, %esi
80         cfi_restore (esi)
81 #ifndef USE_AS_BCOPY
82         movl    DEST(%esp), %eax
83         RETURN_BOUNDED_POINTER (DEST(%esp))
84 #endif
86         popl    %edi
87         cfi_adjust_cfa_offset (-4)
88         cfi_restore (edi)
90         LEAVE
91         RET_PTR
93         cfi_adjust_cfa_offset (4)
94         cfi_rel_offset (edi, 0)
95         cfi_register (esi, edx)
97         /* Backward copying.  */
98 3:      std
99         leal    -1(%edi, %ecx), %edi
100         leal    -1(%esi, %ecx), %esi
101         shrl    $1, %ecx
102         jnc     1f
103         movsb
104 1:      subl    $1, %edi
105         subl    $1, %esi
106         shrl    $1, %ecx
107         jnc     2f
108         movsw
109 2:      subl    $2, %edi
110         subl    $2, %esi
111         rep
112         movsl
113         movl    %edx, %esi
114         cfi_restore (esi)
115 #ifndef USE_AS_BCOPY
116         movl    DEST(%esp), %eax
117         RETURN_BOUNDED_POINTER (DEST(%esp))
118 #endif
120         cld
121         popl    %edi
122         cfi_adjust_cfa_offset (-4)
123         cfi_restore (edi)
125         LEAVE
126         RET_PTR
127 END (BP_SYM (memmove))
128 #ifndef USE_AS_BCOPY
129 libc_hidden_builtin_def (memmove)
130 #endif