Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / i386 / i686 / memcpy.S
blob0aa19da6015cc2c6a554586c53b62dc2b8e112f5
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) 1999, 2000, 2003, 2004, 2008 Free Software Foundation, Inc.
5    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
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, see
19    <http://www.gnu.org/licenses/>.  */
21 #include <sysdep.h>
22 #include "asm-syntax.h"
23 #include "bp-sym.h"
24 #include "bp-asm.h"
26 #define PARMS   LINKAGE         /* no space for saved regs */
27 #define RTN     PARMS
28 #define DEST    RTN+RTN_SIZE
29 #define SRC     DEST+PTR_SIZE
30 #define LEN     SRC+PTR_SIZE
32         .text
33 #if defined PIC && !defined NOT_IN_libc
34 ENTRY_CHK (__memcpy_chk)
35         movl    12(%esp), %eax
36         cmpl    %eax, 16(%esp)
37         jb      HIDDEN_JUMPTARGET (__chk_fail)
38 END_CHK (__memcpy_chk)
39 #endif
40 ENTRY (BP_SYM (memcpy))
41         ENTER
43         movl    %edi, %eax
44         movl    DEST(%esp), %edi
45         movl    %esi, %edx
46         movl    SRC(%esp), %esi
48         movl    %edi, %ecx
49         xorl    %esi, %ecx
50         andl    $3, %ecx
51         movl    LEN(%esp), %ecx
52         cld
53         jne     .Lunaligned
55         cmpl    $3, %ecx
56         jbe     .Lunaligned
58         testl   $3, %esi
59         je      1f
60         movsb
61         decl    %ecx
62         testl   $3, %esi
63         je      1f
64         movsb
65         decl    %ecx
66         testl   $3, %esi
67         je      1f
68         movsb
69         decl    %ecx
70 1:      pushl   %eax
71         movl    %ecx, %eax
72         shrl    $2, %ecx
73         andl    $3, %eax
74         rep
75         movsl
76         movl    %eax, %ecx
77         rep
78         movsb
79         popl    %eax
81 .Lend:  movl    %eax, %edi
82         movl    %edx, %esi
83         movl    DEST(%esp), %eax
84         RETURN_BOUNDED_POINTER (DEST(%esp))
86         LEAVE
87         RET_PTR
89         /* When we come here the pointers do not have the same
90            alignment or the length is too short.  No need to optimize for
91            aligned memory accesses. */
92 .Lunaligned:
93         shrl    $1, %ecx
94         jnc     1f
95         movsb
96 1:      shrl    $1, %ecx
97         jnc     2f
98         movsw
99 2:      rep
100         movsl
101         jmp     .Lend
102 END (BP_SYM (memcpy))
103 libc_hidden_builtin_def (memcpy)