Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / i386 / i586 / memcpy.S
blobff44dc9bc8d3f1e9728f37adb65830743fbfdb66
1 /* Highly optimized version for i586.
2    Copyright (C) 1997, 2000, 2003, 2005 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, see
18    <http://www.gnu.org/licenses/>.  */
20 #include <sysdep.h>
21 #include "asm-syntax.h"
22 #include "bp-sym.h"
23 #include "bp-asm.h"
25 /* BEWARE: `#ifdef memcpy' means that memcpy is redefined as `mempcpy',
26    and the return value is the byte after the last one copied in
27    the destination. */
28 #define MEMPCPY_P (defined memcpy)
30 #define PARMS   LINKAGE+8       /* space for 2 saved regs */
31 #define RTN     PARMS
32 #define DEST    RTN+RTN_SIZE
33 #define SRC     DEST+PTR_SIZE
34 #define LEN     SRC+PTR_SIZE
36         .text
37 #if defined PIC && !defined NOT_IN_libc
38 ENTRY (__memcpy_chk)
39         movl    12(%esp), %eax
40         cmpl    %eax, 16(%esp)
41         jb      HIDDEN_JUMPTARGET (__chk_fail)
42 END (__memcpy_chk)
43 #endif
44 ENTRY (BP_SYM (memcpy))
45         ENTER
47         pushl   %edi
48         cfi_adjust_cfa_offset (4)
49         pushl   %esi
50         cfi_adjust_cfa_offset (4)
52         movl    DEST(%esp), %edi
53         cfi_rel_offset (edi, 4)
54         movl    SRC(%esp), %esi
55         cfi_rel_offset (esi, 0)
56         movl    LEN(%esp), %ecx
57         CHECK_BOUNDS_BOTH_WIDE (%edi, DEST(%esp), %ecx)
58         CHECK_BOUNDS_BOTH_WIDE (%esi, SRC(%esp), %ecx)
59         movl    %edi, %eax
61         /* We need this in any case.  */
62         cld
64         /* Cutoff for the big loop is a size of 32 bytes since otherwise
65            the loop will never be entered.  */
66         cmpl    $32, %ecx
67         jbe     L(1)
69         negl    %eax
70         andl    $3, %eax
71         subl    %eax, %ecx
72         xchgl   %eax, %ecx
74         rep; movsb
76         movl    %eax, %ecx
77         subl    $32, %ecx
78         js      L(2)
80         /* Read ahead to make sure we write in the cache since the stupid
81            i586 designers haven't implemented read-on-write-miss.  */
82         movl    (%edi), %eax
83 L(3):   movl    28(%edi), %edx
85         /* Now correct the loop counter.  Please note that in the following
86            code the flags are not changed anymore.  */
87         subl    $32, %ecx
89         movl    (%esi), %eax
90         movl    4(%esi), %edx
91         movl    %eax, (%edi)
92         movl    %edx, 4(%edi)
93         movl    8(%esi), %eax
94         movl    12(%esi), %edx
95         movl    %eax, 8(%edi)
96         movl    %edx, 12(%edi)
97         movl    16(%esi), %eax
98         movl    20(%esi), %edx
99         movl    %eax, 16(%edi)
100         movl    %edx, 20(%edi)
101         movl    24(%esi), %eax
102         movl    28(%esi), %edx
103         movl    %eax, 24(%edi)
104         movl    %edx, 28(%edi)
106         leal    32(%esi), %esi
107         leal    32(%edi), %edi
109         jns     L(3)
111         /* Correct extra loop counter modification.  */
112 L(2):   addl    $32, %ecx
113 #if !MEMPCPY_P
114         movl    DEST(%esp), %eax
115 #endif
117 L(1):   rep; movsb
119 #if MEMPCPY_P
120         movl    %edi, %eax
121 #endif
123         popl    %esi
124         cfi_adjust_cfa_offset (-4)
125         cfi_restore (esi)
126         popl    %edi
127         cfi_adjust_cfa_offset (-4)
128         cfi_restore (edi)
130         LEAVE
131         RET_PTR
132 END (BP_SYM (memcpy))
133 #if !MEMPCPY_P
134 libc_hidden_builtin_def (memcpy)
135 #endif