Formerly ieee754/Dist.~5~
[kopensolaris-gnu/glibc.git] / sysdeps / i386 / memcopy.h
1 /* memcopy.h -- definitions for memory copy functions.  i386 version.
2    Copyright (C) 1991 Free Software Foundation, Inc.
3    Contributed by Torbjorn Granlund (tege@sics.se).
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB.  If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA.  */
19
20 #include <sysdeps/generic/memcopy.h>
21
22 #undef  OP_T_THRES
23 #define OP_T_THRES      8
24
25 #undef  BYTE_COPY_FWD
26 #define BYTE_COPY_FWD(dst_bp, src_bp, nbytes)                                 \
27   asm volatile(/* Clear the direction flag, so copying goes forward.  */      \
28                "cld\n"                                                        \
29                /* Copy bytes.  */                                             \
30                "rep\n"                                                        \
31                "movsb" :                                                      \
32                "=D" (dst_bp), "=S" (src_bp) :                                 \
33                "0" (dst_bp), "1" (src_bp), "c" (nbytes) :                     \
34                "cx")
35
36 #undef  BYTE_COPY_BWD
37 #define BYTE_COPY_BWD(dst_ep, src_ep, nbytes)                                 \
38   do                                                                          \
39     {                                                                         \
40       asm volatile(/* Set the direction flag, so copying goes backwards.  */  \
41                    "std\n"                                                    \
42                    /* Copy bytes.  */                                         \
43                    "rep\n"                                                    \
44                    "movsb" :                                                  \
45                    "=D" (dst_ep), "=S" (src_ep) :                             \
46                    "0" (dst_ep - 1), "1" (src_ep - 1), "c" (nbytes) :         \
47                    "cx");                                                     \
48       dst_ep += 1;                                                            \
49       src_ep += 1;                                                            \
50     } while (0)
51
52 #undef  WORD_COPY_FWD
53 #define WORD_COPY_FWD(dst_bp, src_bp, nbytes_left, nbytes)                    \
54   do                                                                          \
55     {                                                                         \
56       asm volatile("cld\n"                                                    \
57                    /* Copy longwords.  */                                     \
58                    "rep\n"                                                    \
59                    "movsl" :                                                  \
60                    "=D" (dst_bp), "=S" (src_bp) :                             \
61                    "0" (dst_bp), "1" (src_bp), "c" ((nbytes) / 4) :           \
62                    "cx");                                                     \
63       (nbytes_left) = (nbytes) % 4;                                           \
64     } while (0)
65
66 #undef  WORD_COPY_BWD
67 #define WORD_COPY_BWD(dst_ep, src_ep, nbytes_left, nbytes)                    \
68   do                                                                          \
69     {                                                                         \
70       asm volatile("std\n"                                                    \
71                    "rep\n"                                                    \
72                    "movsl" :                                                  \
73                    "=D" (dst_ep), "=S" (src_ep) :                             \
74                    "0" (dst_ep - 4), "1" (src_ep - 4), "c" (nbytes) :         \
75                    "cx");                                                     \
76       dst_ep += 4;                                                            \
77       src_ep += 4;                                                            \
78       (nbytes_left) = (nbytes) % 4;                                           \
79     } while (0)