OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / string / x86_64 / memcpy.S
1 /* Highly optimized version for x86-64.
2    Copyright (C) 1997, 2000, 2002, 2003, 2004 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.
5
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.
10
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.
15
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.  */
20
21 #include "_glibc_inc.h"
22
23 /* BEWARE: `#ifdef memcpy' means that memcpy is redefined as `mempcpy',
24    and the return value is the byte after the last one copied in
25    the destination. */
26 #define MEMPCPY_P (defined memcpy)
27
28         .text
29 #if defined PIC && !defined NOT_IN_libc
30 ENTRY (__memcpy_chk)
31         cmpq    %rdx, %rcx
32         jb      HIDDEN_JUMPTARGET (__chk_fail)
33 END (__memcpy_chk)
34 #endif
35 ENTRY (BP_SYM (memcpy))
36         /* Cutoff for the big loop is a size of 32 bytes since otherwise
37            the loop will never be entered.  */
38         cmpq    $32, %rdx
39         movq    %rdx, %rcx
40 #if !MEMPCPY_P
41         movq    %rdi, %r10      /* Save value. */
42 #endif
43
44         /* We need this in any case.  */
45         cld
46
47         jbe     1f
48
49         /* Align destination.  */
50         movq    %rdi, %rax
51         negq    %rax
52         andq    $7, %rax
53         subq    %rax, %rcx
54         xchgq   %rax, %rcx
55
56         rep; movsb
57
58         movq    %rax, %rcx
59         subq    $32, %rcx
60         js      2f
61
62         .p2align 4
63 3:
64
65         /* Now correct the loop counter.  Please note that in the following
66            code the flags are not changed anymore.  */
67         subq    $32, %rcx
68
69         movq    (%rsi), %rax
70         movq    8(%rsi), %rdx
71         movq    16(%rsi), %r8
72         movq    24(%rsi), %r9
73         movq    %rax, (%rdi)
74         movq    %rdx, 8(%rdi)
75         movq    %r8, 16(%rdi)
76         movq    %r9, 24(%rdi)
77
78         leaq    32(%rsi), %rsi
79         leaq    32(%rdi), %rdi
80
81         jns     3b
82
83         /* Correct extra loop counter modification.  */
84 2:      addq    $32, %rcx
85 1:      rep; movsb
86
87 #if MEMPCPY_P
88         movq    %rdi, %rax              /* Set return value.  */
89 #else
90         movq    %r10, %rax              /* Set return value.  */
91         
92 #endif
93         ret
94
95 END (BP_SYM (memcpy))
96 #if !MEMPCPY_P
97 libc_hidden_def(memcpy)
98 #endif