]>
Commit | Line | Data |
---|---|---|
04067002 | 1 | /* _memcopy.c -- subroutines for memory copy functions. |
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 | /* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */ | |
21 | ||
22 | #include <stddef.h> | |
23 | #include <memcopy.h> | |
24 | ||
25 | /* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to | |
26 | block beginning at DSTP with LEN `op_t' words (not LEN bytes!). | |
27 | Both SRCP and DSTP should be aligned for memory operations on `op_t's. */ | |
28 | ||
ea5a72f8 AZ |
29 | #ifndef WORDCOPY_FWD_ALIGNED |
30 | # define WORDCOPY_FWD_ALIGNED _wordcopy_fwd_aligned | |
31 | #endif | |
32 | ||
04067002 | 33 | void |
ea5a72f8 | 34 | WORDCOPY_FWD_ALIGNED (long int dstp, long int srcp, size_t len) |
04067002 UD |
35 | { |
36 | op_t a0, a1; | |
37 | ||
38 | if (len & 1) | |
39 | { | |
40 | ((op_t *) dstp)[0] = ((op_t *) srcp)[0]; | |
9c84384c | 41 | |
04067002 UD |
42 | if (len == 1) |
43 | return; | |
44 | srcp += OPSIZ; | |
45 | dstp += OPSIZ; | |
46 | len -= 1; | |
47 | } | |
48 | ||
49 | do | |
50 | { | |
51 | a0 = ((op_t *) srcp)[0]; | |
52 | a1 = ((op_t *) srcp)[1]; | |
53 | ((op_t *) dstp)[0] = a0; | |
54 | ((op_t *) dstp)[1] = a1; | |
55 | ||
56 | srcp += 2 * OPSIZ; | |
57 | dstp += 2 * OPSIZ; | |
58 | len -= 2; | |
59 | } | |
60 | while (len != 0); | |
61 | } | |
62 | ||
63 | /* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to | |
64 | block beginning at DSTP with LEN `op_t' words (not LEN bytes!). | |
65 | DSTP should be aligned for memory operations on `op_t's, but SRCP must | |
66 | *not* be aligned. */ | |
67 | ||
ea5a72f8 AZ |
68 | #ifndef WORDCOPY_FWD_DEST_ALIGNED |
69 | # define WORDCOPY_FWD_DEST_ALIGNED _wordcopy_fwd_dest_aligned | |
70 | #endif | |
71 | ||
04067002 | 72 | void |
ea5a72f8 | 73 | WORDCOPY_FWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len) |
04067002 UD |
74 | { |
75 | op_t a0, a1, a2; | |
76 | int sh_1, sh_2; | |
77 | ||
78 | /* Calculate how to shift a word read at the memory operation | |
79 | aligned srcp to make it aligned for copy. */ | |
80 | ||
81 | sh_1 = 8 * (srcp % OPSIZ); | |
82 | sh_2 = 8 * OPSIZ - sh_1; | |
83 | ||
84 | /* Make SRCP aligned by rounding it down to the beginning of the `op_t' | |
85 | it points in the middle of. */ | |
86 | srcp &= -OPSIZ; | |
87 | a0 = ((op_t *) srcp)[0]; | |
88 | ||
89 | if (len & 1) | |
90 | { | |
91 | a1 = ((op_t *) srcp)[1]; | |
92 | ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2); | |
9c84384c | 93 | |
04067002 UD |
94 | if (len == 1) |
95 | return; | |
9c84384c | 96 | |
04067002 UD |
97 | a0 = a1; |
98 | srcp += OPSIZ; | |
99 | dstp += OPSIZ; | |
100 | len -= 1; | |
101 | } | |
102 | ||
103 | do | |
104 | { | |
105 | a1 = ((op_t *) srcp)[1]; | |
106 | a2 = ((op_t *) srcp)[2]; | |
107 | ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2); | |
108 | ((op_t *) dstp)[1] = MERGE (a1, sh_1, a2, sh_2); | |
109 | a0 = a2; | |
110 | ||
111 | srcp += 2 * OPSIZ; | |
112 | dstp += 2 * OPSIZ; | |
113 | len -= 2; | |
114 | } | |
115 | while (len != 0); | |
116 | } | |
117 | ||
118 | /* _wordcopy_bwd_aligned -- Copy block finishing right before | |
119 | SRCP to block finishing right before DSTP with LEN `op_t' words | |
120 | (not LEN bytes!). Both SRCP and DSTP should be aligned for memory | |
121 | operations on `op_t's. */ | |
122 | ||
ea5a72f8 AZ |
123 | #ifndef WORDCOPY_BWD_ALIGNED |
124 | # define WORDCOPY_BWD_ALIGNED _wordcopy_bwd_aligned | |
125 | #endif | |
126 | ||
04067002 | 127 | void |
ea5a72f8 | 128 | WORDCOPY_BWD_ALIGNED (long int dstp, long int srcp, size_t len) |
04067002 UD |
129 | { |
130 | op_t a0, a1; | |
131 | ||
132 | if (len & 1) | |
133 | { | |
134 | srcp -= OPSIZ; | |
135 | dstp -= OPSIZ; | |
136 | ((op_t *) dstp)[0] = ((op_t *) srcp)[0]; | |
9c84384c | 137 | |
04067002 UD |
138 | if (len == 1) |
139 | return; | |
140 | len -= 1; | |
141 | } | |
142 | ||
143 | do | |
144 | { | |
145 | srcp -= 2 * OPSIZ; | |
146 | dstp -= 2 * OPSIZ; | |
147 | ||
148 | a1 = ((op_t *) srcp)[1]; | |
149 | a0 = ((op_t *) srcp)[0]; | |
150 | ((op_t *) dstp)[1] = a1; | |
151 | ((op_t *) dstp)[0] = a0; | |
152 | ||
153 | len -= 2; | |
154 | } | |
155 | while (len != 0); | |
156 | } | |
157 | ||
158 | /* _wordcopy_bwd_dest_aligned -- Copy block finishing right | |
159 | before SRCP to block finishing right before DSTP with LEN `op_t' | |
160 | words (not LEN bytes!). DSTP should be aligned for memory | |
161 | operations on `op_t', but SRCP must *not* be aligned. */ | |
162 | ||
ea5a72f8 AZ |
163 | #ifndef WORDCOPY_BWD_DEST_ALIGNED |
164 | # define WORDCOPY_BWD_DEST_ALIGNED _wordcopy_bwd_dest_aligned | |
165 | #endif | |
166 | ||
04067002 | 167 | void |
ea5a72f8 | 168 | WORDCOPY_BWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len) |
04067002 UD |
169 | { |
170 | op_t a0, a1, a2; | |
171 | int sh_1, sh_2; | |
172 | ||
173 | /* Calculate how to shift a word read at the memory operation | |
174 | aligned srcp to make it aligned for copy. */ | |
175 | ||
176 | sh_1 = 8 * (srcp % OPSIZ); | |
177 | sh_2 = 8 * OPSIZ - sh_1; | |
178 | ||
179 | /* Make srcp aligned by rounding it down to the beginning of the op_t | |
180 | it points in the middle of. */ | |
181 | srcp &= -OPSIZ; | |
182 | a2 = ((op_t *) srcp)[0]; | |
183 | ||
184 | if (len & 1) | |
185 | { | |
186 | srcp -= OPSIZ; | |
187 | dstp -= OPSIZ; | |
188 | a1 = ((op_t *) srcp)[0]; | |
189 | ((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2); | |
190 | ||
191 | if (len == 1) | |
192 | return; | |
193 | ||
194 | a2 = a1; | |
195 | len -= 1; | |
196 | } | |
197 | ||
198 | do | |
199 | { | |
200 | srcp -= 2 * OPSIZ; | |
201 | dstp -= 2 * OPSIZ; | |
202 | ||
203 | a1 = ((op_t *) srcp)[1]; | |
204 | a0 = ((op_t *) srcp)[0]; | |
205 | ((op_t *) dstp)[1] = MERGE (a1, sh_1, a2, sh_2); | |
206 | ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2); | |
207 | a2 = a0; | |
208 | ||
209 | len -= 2; | |
210 | } | |
211 | while (len != 0); | |
212 | } |