(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / i386 / i686 / memmove.S
blob951e139ad4a5b19d80f78368c2e1d71c75e43b9d
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 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
29 #define DEST    RTN+RTN_SIZE
30 #define SRC     DEST+PTR_SIZE
31 #define LEN     SRC+PTR_SIZE
33         .text
34 #if defined PIC && !defined NOT_IN_libc
35 ENTRY (__memmove_chk)
36         movl    12(%esp), %eax
37         cmpl    %eax, 16(%esp)
38         jb      HIDDEN_JUMPTARGET (__chk_fail)
39 END (__memmove_chk)
40 #endif
41 ENTRY (BP_SYM (memmove))
42         ENTER
44         pushl   %edi
46         movl    LEN(%esp), %ecx
47         movl    DEST(%esp), %edi
48         movl    %esi, %edx
49         movl    SRC(%esp), %esi
50         CHECK_BOUNDS_BOTH_WIDE (%edi, DEST(%esp), %ecx)
51         CHECK_BOUNDS_BOTH_WIDE (%esi, SRC(%esp), %ecx)
53         movl    %edi, %eax
54         subl    %esi, %eax
55         cmpl    %eax, %edi
56         jae     3f
58         cld
59         shrl    $1, %ecx
60         jnc     1f
61         movsb
62 1:      shrl    $1, %ecx
63         jnc     2f
64         movsw
65 2:      rep
66         movsl
67         movl    %edx, %esi
68         movl    DEST(%esp), %eax
69         RETURN_BOUNDED_POINTER (DEST(%esp))
71         popl    %edi
73         LEAVE
74         RET_PTR
76         /* Backward copying.  */
77 3:      std
78         leal    -1(%edi, %ecx), %edi
79         leal    -1(%esi, %ecx), %esi
80         shrl    $1, %ecx
81         jnc     1f
82         movsb
83 1:      subl    $1, %edi
84         subl    $1, %esi
85         shrl    $1, %ecx
86         jnc     2f
87         movsw
88 2:      subl    $2, %edi
89         subl    $2, %esi
90         rep
91         movsl
92         movl    %edx, %esi
93         movl    DEST(%esp), %eax
94         RETURN_BOUNDED_POINTER (DEST(%esp))
96         cld
97         popl    %edi
99         LEAVE
100         RET_PTR
101 END (BP_SYM (memmove))
102 libc_hidden_builtin_def (memmove)