]>
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 | Updated for POWER6 by Steven Munroe (sjmunroe@us.ibm.com). | |
6 | ||
7 | The GNU C Library is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU Lesser General Public | |
9 | License as published by the Free Software Foundation; either | |
10 | version 2.1 of the License, or (at your option) any later version. | |
11 | ||
12 | The GNU C Library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
18 | License along with the GNU C Library; if not, see |
19 | <http://www.gnu.org/licenses/>. */ | |
04067002 UD |
20 | |
21 | /* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */ | |
22 | ||
23 | #include <stddef.h> | |
24 | #include <memcopy.h> | |
25 | ||
26 | /* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to | |
27 | block beginning at DSTP with LEN `op_t' words (not LEN bytes!). | |
28 | Both SRCP and DSTP should be aligned for memory operations on `op_t's. */ | |
29 | ||
ea5a72f8 AZ |
30 | #ifndef WORDCOPY_FWD_ALIGNED |
31 | # define WORDCOPY_FWD_ALIGNED _wordcopy_fwd_aligned | |
32 | #endif | |
33 | ||
04067002 | 34 | void |
ea5a72f8 | 35 | WORDCOPY_FWD_ALIGNED (long int dstp, long int srcp, size_t len) |
04067002 UD |
36 | { |
37 | op_t a0, a1; | |
38 | ||
39 | if (len & 1) | |
40 | { | |
41 | ((op_t *) dstp)[0] = ((op_t *) srcp)[0]; | |
9c84384c | 42 | |
04067002 UD |
43 | if (len == 1) |
44 | return; | |
45 | srcp += OPSIZ; | |
46 | dstp += OPSIZ; | |
47 | len -= 1; | |
48 | } | |
49 | ||
50 | do | |
51 | { | |
52 | a0 = ((op_t *) srcp)[0]; | |
53 | a1 = ((op_t *) srcp)[1]; | |
54 | ((op_t *) dstp)[0] = a0; | |
55 | ((op_t *) dstp)[1] = a1; | |
56 | ||
57 | srcp += 2 * OPSIZ; | |
58 | dstp += 2 * OPSIZ; | |
59 | len -= 2; | |
60 | } | |
61 | while (len != 0); | |
62 | } | |
63 | ||
64 | /* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to | |
65 | block beginning at DSTP with LEN `op_t' words (not LEN bytes!). | |
66 | DSTP should be aligned for memory operations on `op_t's, but SRCP must | |
67 | *not* be aligned. */ | |
68 | ||
b282631e WS |
69 | #define fwd_align_merge(align) \ |
70 | do \ | |
71 | { \ | |
72 | a1 = ((op_t *) srcp)[1]; \ | |
73 | a2 = ((op_t *) srcp)[2]; \ | |
ea5a72f8 AZ |
74 | ((op_t *) dstp)[0] = MERGE (a0, align*8, a1, (__WORDSIZE-align*8)); \ |
75 | ((op_t *) dstp)[1] = MERGE (a1, align*8, a2, (__WORDSIZE-align*8)); \ | |
b282631e WS |
76 | a0 = a2; \ |
77 | srcp += 2 * OPSIZ; \ | |
78 | dstp += 2 * OPSIZ; \ | |
79 | len -= 2; \ | |
80 | } \ | |
81 | while (len != 0) | |
82 | ||
ea5a72f8 AZ |
83 | #ifndef WORDCOPY_FWD_DEST_ALIGNED |
84 | # define WORDCOPY_FWD_DEST_ALIGNED _wordcopy_fwd_dest_aligned | |
85 | #endif | |
86 | ||
04067002 | 87 | void |
ea5a72f8 | 88 | WORDCOPY_FWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len) |
04067002 UD |
89 | { |
90 | op_t a0, a1, a2; | |
91 | int sh_1, sh_2; | |
92 | int align; | |
93 | ||
94 | /* Calculate how to shift a word read at the memory operation | |
95 | aligned srcp to make it aligned for copy. */ | |
96 | ||
97 | align = srcp % OPSIZ; | |
98 | sh_1 = 8 * (srcp % OPSIZ); | |
99 | sh_2 = 8 * OPSIZ - sh_1; | |
100 | ||
101 | /* Make SRCP aligned by rounding it down to the beginning of the `op_t' | |
102 | it points in the middle of. */ | |
103 | srcp &= -OPSIZ; | |
104 | a0 = ((op_t *) srcp)[0]; | |
105 | ||
106 | if (len & 1) | |
107 | { | |
108 | a1 = ((op_t *) srcp)[1]; | |
109 | ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2); | |
9c84384c | 110 | |
04067002 UD |
111 | if (len == 1) |
112 | return; | |
9c84384c | 113 | |
04067002 UD |
114 | a0 = a1; |
115 | srcp += OPSIZ; | |
116 | dstp += OPSIZ; | |
117 | len -= 1; | |
118 | } | |
119 | ||
6b652f46 | 120 | fwd_align_merge (align); |
04067002 UD |
121 | |
122 | } | |
123 | ||
124 | /* _wordcopy_bwd_aligned -- Copy block finishing right before | |
125 | SRCP to block finishing right before DSTP with LEN `op_t' words | |
126 | (not LEN bytes!). Both SRCP and DSTP should be aligned for memory | |
127 | operations on `op_t's. */ | |
128 | ||
ea5a72f8 AZ |
129 | #ifndef WORDCOPY_BWD_ALIGNED |
130 | # define WORDCOPY_BWD_ALIGNED _wordcopy_bwd_aligned | |
131 | #endif | |
132 | ||
04067002 | 133 | void |
ea5a72f8 | 134 | WORDCOPY_BWD_ALIGNED (long int dstp, long int srcp, size_t len) |
04067002 UD |
135 | { |
136 | op_t a0, a1; | |
137 | ||
138 | if (len & 1) | |
139 | { | |
140 | srcp -= OPSIZ; | |
141 | dstp -= OPSIZ; | |
142 | ((op_t *) dstp)[0] = ((op_t *) srcp)[0]; | |
9c84384c | 143 | |
04067002 UD |
144 | if (len == 1) |
145 | return; | |
146 | len -= 1; | |
147 | } | |
148 | ||
149 | do | |
150 | { | |
151 | srcp -= 2 * OPSIZ; | |
152 | dstp -= 2 * OPSIZ; | |
153 | ||
154 | a1 = ((op_t *) srcp)[1]; | |
155 | a0 = ((op_t *) srcp)[0]; | |
156 | ((op_t *) dstp)[1] = a1; | |
157 | ((op_t *) dstp)[0] = a0; | |
158 | ||
159 | len -= 2; | |
160 | } | |
161 | while (len != 0); | |
162 | } | |
163 | ||
b282631e WS |
164 | #define bwd_align_merge(align) \ |
165 | do \ | |
166 | { \ | |
167 | srcp -= 2 * OPSIZ; \ | |
168 | dstp -= 2 * OPSIZ; \ | |
169 | a1 = ((op_t *) srcp)[1]; \ | |
170 | a0 = ((op_t *) srcp)[0]; \ | |
ea5a72f8 AZ |
171 | ((op_t *) dstp)[1] = MERGE (a1, align*8, a2, (__WORDSIZE-align*8)); \ |
172 | ((op_t *) dstp)[0] = MERGE (a0, align*8, a1, (__WORDSIZE-align*8)); \ | |
b282631e WS |
173 | a2 = a0; \ |
174 | len -= 2; \ | |
175 | } \ | |
176 | while (len != 0) | |
177 | ||
04067002 UD |
178 | /* _wordcopy_bwd_dest_aligned -- Copy block finishing right |
179 | before SRCP to block finishing right before DSTP with LEN `op_t' | |
180 | words (not LEN bytes!). DSTP should be aligned for memory | |
181 | operations on `op_t', but SRCP must *not* be aligned. */ | |
182 | ||
ea5a72f8 AZ |
183 | #ifndef WORDCOPY_BWD_DEST_ALIGNED |
184 | # define WORDCOPY_BWD_DEST_ALIGNED _wordcopy_bwd_dest_aligned | |
185 | #endif | |
186 | ||
04067002 | 187 | void |
ea5a72f8 | 188 | WORDCOPY_BWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len) |
04067002 UD |
189 | { |
190 | op_t a0, a1, a2; | |
191 | int sh_1, sh_2; | |
192 | int align; | |
193 | ||
194 | /* Calculate how to shift a word read at the memory operation | |
195 | aligned srcp to make it aligned for copy. */ | |
196 | ||
197 | align = srcp % OPSIZ; | |
198 | sh_1 = 8 * (srcp % OPSIZ); | |
199 | sh_2 = 8 * OPSIZ - sh_1; | |
200 | ||
201 | /* Make srcp aligned by rounding it down to the beginning of the op_t | |
202 | it points in the middle of. */ | |
203 | srcp &= -OPSIZ; | |
204 | a2 = ((op_t *) srcp)[0]; | |
205 | ||
206 | if (len & 1) | |
207 | { | |
208 | srcp -= OPSIZ; | |
209 | dstp -= OPSIZ; | |
210 | a1 = ((op_t *) srcp)[0]; | |
211 | ((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2); | |
212 | ||
213 | if (len == 1) | |
214 | return; | |
215 | ||
216 | a2 = a1; | |
217 | len -= 1; | |
218 | } | |
219 | ||
6b652f46 | 220 | bwd_align_merge (align); |
04067002 | 221 | } |