PR 7
[glibc.git] / sysdeps / x86_64 / memcpy.S
blobd9fde6e459f8d7da57399f931478797b5a561487
1 /* Highly optimized version for x86-64.
2    Copyright (C) 1997, 2000, 2002, 2003 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Based on i586 version 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, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
21 #include <sysdep.h>
22 #include "asm-syntax.h"
23 #include "bp-sym.h"
24 #include "bp-asm.h"
26 /* BEWARE: `#ifdef memcpy' means that memcpy is redefined as `mempcpy',
27    and the return value is the byte after the last one copied in
28    the destination. */
29 #define MEMPCPY_P (defined memcpy)
31         .text
32 ENTRY (BP_SYM (memcpy))
33         /* Cutoff for the big loop is a size of 32 bytes since otherwise
34            the loop will never be entered.  */
35         cmpq    $32, %rdx
36         movq    %rdx, %rcx
37 #if !MEMPCPY_P
38         movq    %rdi, %r10      /* Save value. */
39 #endif
41         /* We need this in any case.  */
42         cld
44         jbe     1f
46         /* Align destination.  */
47         movq    %rdi, %rax
48         negq    %rax
49         andq    $7, %rax
50         subq    %rax, %rcx
51         xchgq   %rax, %rcx
53         rep; movsb
55         movq    %rax, %rcx
56         subq    $32, %rcx
57         js      2f
59         .p2align 4
62         /* Now correct the loop counter.  Please note that in the following
63            code the flags are not changed anymore.  */
64         subq    $32, %rcx
66         movq    (%rsi), %rax
67         movq    8(%rsi), %rdx
68         movq    16(%rsi), %r8
69         movq    24(%rsi), %r9
70         movq    %rax, (%rdi)
71         movq    %rdx, 8(%rdi)
72         movq    %r8, 16(%rdi)
73         movq    %r9, 24(%rdi)
75         leaq    32(%rsi), %rsi
76         leaq    32(%rdi), %rdi
78         jns     3b
80         /* Correct extra loop counter modification.  */
81 2:      addq    $32, %rcx
82 1:      rep; movsb
84 #if MEMPCPY_P
85         movq    %rdi, %rax              /* Set return value.  */
86 #else
87         movq    %r10, %rax              /* Set return value.  */
88         
89 #endif
90         ret
92 END (BP_SYM (memcpy))
93 libc_hidden_builtin_def (memcpy)