Update copyright notices with scripts/update-copyrights.
[glibc.git] / sysdeps / powerpc / powerpc64 / power6 / wordcopy.c
blobf19829c2be63221317b56faf74f8ab9d855cdae0
1 /* _memcopy.c -- subroutines for memory copy functions.
2 Copyright (C) 1991-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Torbjorn Granlund (tege@sics.se).
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 /* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */
22 #include <stddef.h>
23 #include <memcopy.h>
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. */
29 void
30 _wordcopy_fwd_aligned (dstp, srcp, len)
31 long int dstp;
32 long int srcp;
33 size_t len;
35 op_t a0, a1;
37 if (len & 1)
39 ((op_t *) dstp)[0] = ((op_t *) srcp)[0];
41 if (len == 1)
42 return;
43 srcp += OPSIZ;
44 dstp += OPSIZ;
45 len -= 1;
50 a0 = ((op_t *) srcp)[0];
51 a1 = ((op_t *) srcp)[1];
52 ((op_t *) dstp)[0] = a0;
53 ((op_t *) dstp)[1] = a1;
55 srcp += 2 * OPSIZ;
56 dstp += 2 * OPSIZ;
57 len -= 2;
59 while (len != 0);
62 #define fwd_align_merge(align) \
63 do \
64 { \
65 a1 = ((op_t *) srcp)[1]; \
66 a2 = ((op_t *) srcp)[2]; \
67 ((op_t *) dstp)[0] = MERGE (a0, align*8, a1, (64-align*8)); \
68 ((op_t *) dstp)[1] = MERGE (a1, align*8, a2, (64-align*8)); \
69 a0 = a2; \
70 srcp += 2 * OPSIZ; \
71 dstp += 2 * OPSIZ; \
72 len -= 2; \
73 } \
74 while (len != 0)
77 /* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
78 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
79 DSTP should be aligned for memory operations on `op_t's, but SRCP must
80 *not* be aligned. */
82 void
83 _wordcopy_fwd_dest_aligned (dstp, srcp, len)
84 long int dstp;
85 long int srcp;
86 size_t len;
88 op_t a0, a1, a2;
89 int sh_1, sh_2;
90 int align;
92 /* Calculate how to shift a word read at the memory operation
93 aligned srcp to make it aligned for copy. */
95 align = srcp % OPSIZ;
96 sh_1 = 8 * (srcp % OPSIZ);
97 sh_2 = 8 * OPSIZ - sh_1;
99 /* Make SRCP aligned by rounding it down to the beginning of the `op_t'
100 it points in the middle of. */
101 srcp &= -OPSIZ;
102 a0 = ((op_t *) srcp)[0];
104 if (len & 1)
106 a1 = ((op_t *) srcp)[1];
107 ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
109 if (len == 1)
110 return;
112 a0 = a1;
113 srcp += OPSIZ;
114 dstp += OPSIZ;
115 len -= 1;
118 fwd_align_merge (align);
122 /* _wordcopy_bwd_aligned -- Copy block finishing right before
123 SRCP to block finishing right before DSTP with LEN `op_t' words
124 (not LEN bytes!). Both SRCP and DSTP should be aligned for memory
125 operations on `op_t's. */
127 void
128 _wordcopy_bwd_aligned (dstp, srcp, len)
129 long int dstp;
130 long int srcp;
131 size_t len;
133 op_t a0, a1;
135 if (len & 1)
137 srcp -= OPSIZ;
138 dstp -= OPSIZ;
139 ((op_t *) dstp)[0] = ((op_t *) srcp)[0];
141 if (len == 1)
142 return;
143 len -= 1;
148 srcp -= 2 * OPSIZ;
149 dstp -= 2 * OPSIZ;
151 a1 = ((op_t *) srcp)[1];
152 a0 = ((op_t *) srcp)[0];
153 ((op_t *) dstp)[1] = a1;
154 ((op_t *) dstp)[0] = a0;
156 len -= 2;
158 while (len != 0);
161 #define bwd_align_merge(align) \
162 do \
164 srcp -= 2 * OPSIZ; \
165 dstp -= 2 * OPSIZ; \
166 a1 = ((op_t *) srcp)[1]; \
167 a0 = ((op_t *) srcp)[0]; \
168 ((op_t *) dstp)[1] = MERGE (a1, align*8, a2, (64-align*8)); \
169 ((op_t *) dstp)[0] = MERGE (a0, align*8, a1, (64-align*8)); \
170 a2 = a0; \
171 len -= 2; \
173 while (len != 0)
175 /* _wordcopy_bwd_dest_aligned -- Copy block finishing right
176 before SRCP to block finishing right before DSTP with LEN `op_t'
177 words (not LEN bytes!). DSTP should be aligned for memory
178 operations on `op_t', but SRCP must *not* be aligned. */
180 void
181 _wordcopy_bwd_dest_aligned (dstp, srcp, len)
182 long int dstp;
183 long int srcp;
184 size_t len;
186 op_t a0, a1, a2;
187 int sh_1, sh_2;
188 int align;
190 /* Calculate how to shift a word read at the memory operation
191 aligned srcp to make it aligned for copy. */
193 align = srcp % OPSIZ;
194 sh_1 = 8 * (srcp % OPSIZ);
195 sh_2 = 8 * OPSIZ - sh_1;
197 /* Make srcp aligned by rounding it down to the beginning of the op_t
198 it points in the middle of. */
199 srcp &= -OPSIZ;
200 a2 = ((op_t *) srcp)[0];
202 if (len & 1)
204 srcp -= OPSIZ;
205 dstp -= OPSIZ;
206 a1 = ((op_t *) srcp)[0];
207 ((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2);
209 if (len == 1)
210 return;
212 a2 = a1;
213 len -= 1;
216 bwd_align_merge (align);