Back to index

glibc  2.9
memcopy.h
Go to the documentation of this file.
00001 /* memcopy.h -- definitions for memory copy functions.  i386 version.
00002    Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Torbjorn Granlund (tege@sics.se).
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <sysdeps/generic/memcopy.h>
00022 
00023 #undef OP_T_THRES
00024 #define       OP_T_THRES    8
00025 
00026 #undef BYTE_COPY_FWD
00027 #define BYTE_COPY_FWD(dst_bp, src_bp, nbytes)                               \
00028   do {                                                               \
00029     int __d0;                                                        \
00030     asm volatile(/* Clear the direction flag, so copying goes forward.  */    \
00031                "cld\n"                                               \
00032                /* Copy bytes.  */                                    \
00033                "rep\n"                                               \
00034                "movsb" :                                             \
00035                "=D" (dst_bp), "=S" (src_bp), "=c" (__d0) :                  \
00036                "0" (dst_bp), "1" (src_bp), "2" (nbytes) :                   \
00037                "memory");                                            \
00038   } while (0)
00039 
00040 #undef BYTE_COPY_BWD
00041 #define BYTE_COPY_BWD(dst_ep, src_ep, nbytes)                               \
00042   do                                                                 \
00043     {                                                                \
00044       int __d0;                                                             \
00045       asm volatile(/* Set the direction flag, so copying goes backwards.  */  \
00046                  "std\n"                                             \
00047                  /* Copy bytes.  */                                         \
00048                  "rep\n"                                             \
00049                  "movsb\n"                                           \
00050                  /* Clear the dir flag.  Convention says it should be 0. */ \
00051                  "cld" :                                             \
00052                  "=D" (dst_ep), "=S" (src_ep), "=c" (__d0) :                \
00053                  "0" (dst_ep - 1), "1" (src_ep - 1), "2" (nbytes) :         \
00054                  "memory");                                          \
00055       dst_ep += 1;                                                   \
00056       src_ep += 1;                                                   \
00057     } while (0)
00058 
00059 #undef WORD_COPY_FWD
00060 #define WORD_COPY_FWD(dst_bp, src_bp, nbytes_left, nbytes)                  \
00061   do                                                                 \
00062     {                                                                \
00063       int __d0;                                                             \
00064       asm volatile(/* Clear the direction flag, so copying goes forward.  */  \
00065                  "cld\n"                                             \
00066                  /* Copy longwords.  */                              \
00067                  "rep\n"                                             \
00068                  "movsl" :                                           \
00069                  "=D" (dst_bp), "=S" (src_bp), "=c" (__d0) :                \
00070                  "0" (dst_bp), "1" (src_bp), "2" ((nbytes) / 4) :           \
00071                  "memory");                                          \
00072       (nbytes_left) = (nbytes) % 4;                                         \
00073     } while (0)
00074 
00075 #undef WORD_COPY_BWD
00076 #define WORD_COPY_BWD(dst_ep, src_ep, nbytes_left, nbytes)                  \
00077   do                                                                 \
00078     {                                                                \
00079       int __d0;                                                             \
00080       asm volatile(/* Set the direction flag, so copying goes backwards.  */  \
00081                  "std\n"                                             \
00082                  /* Copy longwords.  */                              \
00083                  "rep\n"                                             \
00084                  "movsl\n"                                           \
00085                  /* Clear the dir flag.  Convention says it should be 0. */ \
00086                  "cld" :                                             \
00087                  "=D" (dst_ep), "=S" (src_ep), "=c" (__d0) :                \
00088                  "0" (dst_ep - 4), "1" (src_ep - 4), "2" ((nbytes) / 4) :   \
00089                  "memory");                                          \
00090       dst_ep += 4;                                                   \
00091       src_ep += 4;                                                   \
00092       (nbytes_left) = (nbytes) % 4;                                         \
00093     } while (0)