2.9
[glibc/nacl-glibc.git] / sysdeps / i386 / i686 / memmove.S
blobb93b5c729f2cf00859efcf1a493f453a49a35282
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
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
45         cfi_adjust_cfa_offset (4)
47         movl    LEN(%esp), %ecx
48         movl    DEST(%esp), %edi
49         cfi_rel_offset (edi, 0)
50         movl    %esi, %edx
51         movl    SRC(%esp), %esi
52         cfi_register (esi, edx)
53         CHECK_BOUNDS_BOTH_WIDE (%edi, DEST(%esp), %ecx)
54         CHECK_BOUNDS_BOTH_WIDE (%esi, SRC(%esp), %ecx)
56         movl    %edi, %eax
57         subl    %esi, %eax
58         cmpl    %eax, %edi
59         jae     3f
61         cld
62         shrl    $1, %ecx
63         jnc     1f
64         movsb
65 1:      shrl    $1, %ecx
66         jnc     2f
67         movsw
68 2:      rep
69         movsl
70         movl    %edx, %esi
71         cfi_restore (esi)
72         movl    DEST(%esp), %eax
73         RETURN_BOUNDED_POINTER (DEST(%esp))
75         popl    %edi
76         cfi_adjust_cfa_offset (-4)
77         cfi_restore (edi)
79         LEAVE
80         RET_PTR
82         cfi_adjust_cfa_offset (4)
83         cfi_rel_offset (edi, 0)
84         cfi_register (esi, edx)
86         /* Backward copying.  */
87 3:      std
88         leal    -1(%edi, %ecx), %edi
89         leal    -1(%esi, %ecx), %esi
90         shrl    $1, %ecx
91         jnc     1f
92         movsb
93 1:      subl    $1, %edi
94         subl    $1, %esi
95         shrl    $1, %ecx
96         jnc     2f
97         movsw
98 2:      subl    $2, %edi
99         subl    $2, %esi
100         rep
101         movsl
102         movl    %edx, %esi
103         cfi_restore (esi)
104         movl    DEST(%esp), %eax
105         RETURN_BOUNDED_POINTER (DEST(%esp))
107         cld
108         popl    %edi
109         cfi_adjust_cfa_offset (-4)
110         cfi_restore (edi)
112         LEAVE
113         RET_PTR
114 END (BP_SYM (memmove))
115 libc_hidden_builtin_def (memmove)