1 /* memcopy.h -- definitions for memory copy functions.  i386 version.
2    Copyright (C) 1991-2021 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the 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    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #include <sysdeps/generic/memcopy.h>
20 
21 #undef	OP_T_THRES
22 #define	OP_T_THRES	8
23 
24 #undef	BYTE_COPY_FWD
25 #define BYTE_COPY_FWD(dst_bp, src_bp, nbytes)				      \
26   do {									      \
27     int __d0;								      \
28     asm volatile(/* Clear the direction flag, so copying goes forward.  */    \
29 		 "cld\n"						      \
30 		 /* Copy bytes.  */					      \
31 		 "rep\n"						      \
32 		 "movsb" :						      \
33 		 "=D" (dst_bp), "=S" (src_bp), "=c" (__d0) :		      \
34 		 "0" (dst_bp), "1" (src_bp), "2" (nbytes) :		      \
35 		 "memory");						      \
36   } while (0)
37 
38 #undef	BYTE_COPY_BWD
39 #define BYTE_COPY_BWD(dst_ep, src_ep, nbytes)				      \
40   do									      \
41     {									      \
42       int __d0;								      \
43       asm volatile(/* Set the direction flag, so copying goes backwards.  */  \
44 		   "std\n"						      \
45 		   /* Copy bytes.  */					      \
46 		   "rep\n"						      \
47 		   "movsb\n"						      \
48 		   /* Clear the dir flag.  Convention says it should be 0. */ \
49 		   "cld" :						      \
50 		   "=D" (dst_ep), "=S" (src_ep), "=c" (__d0) :		      \
51 		   "0" (dst_ep - 1), "1" (src_ep - 1), "2" (nbytes) :	      \
52 		   "memory");						      \
53       dst_ep += 1;							      \
54       src_ep += 1;							      \
55     } while (0)
56 
57 #undef	WORD_COPY_FWD
58 #define WORD_COPY_FWD(dst_bp, src_bp, nbytes_left, nbytes)		      \
59   do									      \
60     {									      \
61       int __d0;								      \
62       asm volatile(/* Clear the direction flag, so copying goes forward.  */  \
63 		   "cld\n"						      \
64 		   /* Copy longwords.  */				      \
65 		   "rep\n"						      \
66 		   "movsl" :						      \
67  		   "=D" (dst_bp), "=S" (src_bp), "=c" (__d0) :		      \
68 		   "0" (dst_bp), "1" (src_bp), "2" ((nbytes) / 4) :	      \
69 		   "memory");						      \
70       (nbytes_left) = (nbytes) % 4;					      \
71     } while (0)
72 
73 #undef	WORD_COPY_BWD
74 #define WORD_COPY_BWD(dst_ep, src_ep, nbytes_left, nbytes)		      \
75   do									      \
76     {									      \
77       int __d0;								      \
78       asm volatile(/* Set the direction flag, so copying goes backwards.  */  \
79 		   "std\n"						      \
80 		   /* Copy longwords.  */				      \
81 		   "rep\n"						      \
82 		   "movsl\n"						      \
83 		   /* Clear the dir flag.  Convention says it should be 0. */ \
84 		   "cld" :						      \
85 		   "=D" (dst_ep), "=S" (src_ep), "=c" (__d0) :		      \
86 		   "0" (dst_ep - 4), "1" (src_ep - 4), "2" ((nbytes) / 4) :   \
87 		   "memory");						      \
88       dst_ep += 4;							      \
89       src_ep += 4;							      \
90       (nbytes_left) = (nbytes) % 4;					      \
91     } while (0)
92