Mon Jun 24 19:57:01 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[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\n"                                                  \
45                    /* Clear the dir flag.  Convention says it should be 0. */ \
46                    "cld" :                                                    \
47                    "=D" (dst_ep), "=S" (src_ep) :                             \
48                    "0" (dst_ep - 1), "1" (src_ep - 1), "c" (nbytes) :         \
49                    "cx");                                                     \
50       dst_ep += 1;                                                            \
51       src_ep += 1;                                                            \
52     } while (0)
53
54 #undef  WORD_COPY_FWD
55 #define WORD_COPY_FWD(dst_bp, src_bp, nbytes_left, nbytes)                    \
56   do                                                                          \
57     {                                                                         \
58       asm volatile(/* Clear the direction flag, so copying goes forward.  */  \
59                    "cld\n"                                                    \
60                    /* Copy longwords.  */                                     \
61                    "rep\n"                                                    \
62                    "movsl" :                                                  \
63                    "=D" (dst_bp), "=S" (src_bp) :                             \
64                    "0" (dst_bp), "1" (src_bp), "c" ((nbytes) / 4) :           \
65                    "cx");                                                     \
66       (nbytes_left) = (nbytes) % 4;                                           \
67     } while (0)
68
69 #undef  WORD_COPY_BWD
70 #define WORD_COPY_BWD(dst_ep, src_ep, nbytes_left, nbytes)                    \
71   do                                                                          \
72     {                                                                         \
73       asm volatile(/* Set the direction flag, so copying goes backwards.  */  \
74                    "std\n"                                                    \
75                    /* Copy longwords.  */                                     \
76                    "rep\n"                                                    \
77                    "movsl\n"                                                  \
78                    /* Clear the dir flag.  Convention says it should be 0. */ \
79                    "cld" :                                                    \
80                    "=D" (dst_ep), "=S" (src_ep) :                             \
81                    "0" (dst_ep - 4), "1" (src_ep - 4), "c" ((nbytes) / 4) :   \
82                    "cx");                                                     \
83       dst_ep += 4;                                                            \
84       src_ep += 4;                                                            \
85       (nbytes_left) = (nbytes) % 4;                                           \
86     } while (0)