]>
Commit | Line | Data |
---|---|---|
04067002 | 1 | /* memcopy.h -- definitions for memory copy functions. Generic C version. |
04277e02 | 2 | Copyright (C) 1991-2019 Free Software Foundation, Inc. |
04067002 UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Torbjorn Granlund (tege@sics.se). | |
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 | |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
04067002 UD |
19 | |
20 | /* The strategy of the memory functions is: | |
21 | ||
22 | 1. Copy bytes until the destination pointer is aligned. | |
23 | ||
24 | 2. Copy words in unrolled loops. If the source and destination | |
25 | are not aligned in the same way, use word memory operations, | |
26 | but shift and merge two read words before writing. | |
27 | ||
28 | 3. Copy the few remaining bytes. | |
29 | ||
30 | This is fast on processors that have at least 10 registers for | |
31 | allocation by GCC, and that can access memory at reg+const in one | |
32 | instruction. | |
33 | ||
34 | I made an "exhaustive" test of this memmove when I wrote it, | |
35 | exhaustive in the sense that I tried all alignment and length | |
36 | combinations, with and without overlap. */ | |
37 | ||
38 | #include <sysdeps/generic/memcopy.h> | |
39 | ||
40 | /* The macros defined in this file are: | |
41 | ||
42 | BYTE_COPY_FWD(dst_beg_ptr, src_beg_ptr, nbytes_to_copy) | |
43 | ||
44 | BYTE_COPY_BWD(dst_end_ptr, src_end_ptr, nbytes_to_copy) | |
45 | ||
46 | WORD_COPY_FWD(dst_beg_ptr, src_beg_ptr, nbytes_remaining, nbytes_to_copy) | |
47 | ||
48 | WORD_COPY_BWD(dst_end_ptr, src_end_ptr, nbytes_remaining, nbytes_to_copy) | |
49 | ||
50 | MERGE(old_word, sh_1, new_word, sh_2) | |
51 | [I fail to understand. I feel stupid. --roland] | |
52 | */ | |
53 | ||
54 | ||
55 | /* Threshold value for when to enter the unrolled loops. */ | |
56 | #undef OP_T_THRES | |
57 | #define OP_T_THRES 16 | |
58 | ||
59 | /* Copy exactly NBYTES bytes from SRC_BP to DST_BP, | |
60 | without any assumptions about alignment of the pointers. */ | |
61 | #undef BYTE_COPY_FWD | |
62 | #define BYTE_COPY_FWD(dst_bp, src_bp, nbytes) \ | |
63 | do \ | |
64 | { \ | |
65 | size_t __nbytes = (nbytes); \ | |
66 | if (__nbytes & 1) \ | |
67 | { \ | |
68 | ((byte *) dst_bp)[0] = ((byte *) src_bp)[0]; \ | |
69 | src_bp += 1; \ | |
70 | dst_bp += 1; \ | |
71 | __nbytes -= 1; \ | |
72 | } \ | |
73 | while (__nbytes > 0) \ | |
74 | { \ | |
75 | byte __x = ((byte *) src_bp)[0]; \ | |
76 | byte __y = ((byte *) src_bp)[1]; \ | |
77 | src_bp += 2; \ | |
78 | __nbytes -= 2; \ | |
79 | ((byte *) dst_bp)[0] = __x; \ | |
80 | ((byte *) dst_bp)[1] = __y; \ | |
81 | dst_bp += 2; \ | |
82 | } \ | |
83 | } while (0) | |
84 | ||
85 | /* Copy exactly NBYTES_TO_COPY bytes from SRC_END_PTR to DST_END_PTR, | |
86 | beginning at the bytes right before the pointers and continuing towards | |
87 | smaller addresses. Don't assume anything about alignment of the | |
88 | pointers. */ | |
89 | #undef BYTE_COPY_BWD | |
90 | #define BYTE_COPY_BWD(dst_ep, src_ep, nbytes) \ | |
91 | do \ | |
92 | { \ | |
93 | size_t __nbytes = (nbytes); \ | |
94 | if (__nbytes & 1) \ | |
95 | { \ | |
96 | src_ep -= 1; \ | |
97 | dst_ep -= 1; \ | |
98 | ((byte *) dst_ep)[0] = ((byte *) src_ep)[0]; \ | |
99 | __nbytes -= 1; \ | |
100 | } \ | |
101 | while (__nbytes > 0) \ | |
102 | { \ | |
103 | byte __x, __y; \ | |
104 | src_ep -= 2; \ | |
105 | __y = ((byte *) src_ep)[1]; \ | |
106 | __x = ((byte *) src_ep)[0]; \ | |
107 | dst_ep -= 2; \ | |
108 | __nbytes -= 2; \ | |
109 | ((byte *) dst_ep)[1] = __y; \ | |
110 | ((byte *) dst_ep)[0] = __x; \ | |
111 | } \ | |
112 | } while (0) | |
27b75f56 AZ |
113 | |
114 | /* The powerpc memcpy implementation is safe to use for memmove. */ | |
115 | #undef MEMCPY_OK_FOR_FWD_MEMMOVE | |
116 | #define MEMCPY_OK_FOR_FWD_MEMMOVE 1 |