powerpc: Cleanup fenv_private.h
[glibc.git] / sysdeps / powerpc / power6 / wordcopy.c
blobf48ef609fd4c0ccaf0fd0b5c623b9ce1b92ba967
1 /* _memcopy.c -- subroutines for memory copy functions.
2 Copyright (C) 1991-2016 Free Software Foundation, Inc.
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).
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.
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.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 /* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */
23 #include <stddef.h>
24 #include <memcopy.h>
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. */
30 #ifndef WORDCOPY_FWD_ALIGNED
31 # define WORDCOPY_FWD_ALIGNED _wordcopy_fwd_aligned
32 #endif
34 void
35 WORDCOPY_FWD_ALIGNED (long int dstp, long int srcp, size_t len)
37 op_t a0, a1;
39 if (len & 1)
41 ((op_t *) dstp)[0] = ((op_t *) srcp)[0];
43 if (len == 1)
44 return;
45 srcp += OPSIZ;
46 dstp += OPSIZ;
47 len -= 1;
52 a0 = ((op_t *) srcp)[0];
53 a1 = ((op_t *) srcp)[1];
54 ((op_t *) dstp)[0] = a0;
55 ((op_t *) dstp)[1] = a1;
57 srcp += 2 * OPSIZ;
58 dstp += 2 * OPSIZ;
59 len -= 2;
61 while (len != 0);
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. */
69 #define fwd_align_merge(align) \
70 do \
71 { \
72 a1 = ((op_t *) srcp)[1]; \
73 a2 = ((op_t *) srcp)[2]; \
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)); \
76 a0 = a2; \
77 srcp += 2 * OPSIZ; \
78 dstp += 2 * OPSIZ; \
79 len -= 2; \
80 } \
81 while (len != 0)
83 #ifndef WORDCOPY_FWD_DEST_ALIGNED
84 # define WORDCOPY_FWD_DEST_ALIGNED _wordcopy_fwd_dest_aligned
85 #endif
87 void
88 WORDCOPY_FWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len)
90 op_t a0, a1, a2;
91 int sh_1, sh_2;
92 int align;
94 /* Calculate how to shift a word read at the memory operation
95 aligned srcp to make it aligned for copy. */
97 align = srcp % OPSIZ;
98 sh_1 = 8 * (srcp % OPSIZ);
99 sh_2 = 8 * OPSIZ - sh_1;
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];
106 if (len & 1)
108 a1 = ((op_t *) srcp)[1];
109 ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
111 if (len == 1)
112 return;
114 a0 = a1;
115 srcp += OPSIZ;
116 dstp += OPSIZ;
117 len -= 1;
120 fwd_align_merge (align);
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. */
129 #ifndef WORDCOPY_BWD_ALIGNED
130 # define WORDCOPY_BWD_ALIGNED _wordcopy_bwd_aligned
131 #endif
133 void
134 WORDCOPY_BWD_ALIGNED (long int dstp, long int srcp, size_t len)
136 op_t a0, a1;
138 if (len & 1)
140 srcp -= OPSIZ;
141 dstp -= OPSIZ;
142 ((op_t *) dstp)[0] = ((op_t *) srcp)[0];
144 if (len == 1)
145 return;
146 len -= 1;
151 srcp -= 2 * OPSIZ;
152 dstp -= 2 * OPSIZ;
154 a1 = ((op_t *) srcp)[1];
155 a0 = ((op_t *) srcp)[0];
156 ((op_t *) dstp)[1] = a1;
157 ((op_t *) dstp)[0] = a0;
159 len -= 2;
161 while (len != 0);
164 #define bwd_align_merge(align) \
165 do \
167 srcp -= 2 * OPSIZ; \
168 dstp -= 2 * OPSIZ; \
169 a1 = ((op_t *) srcp)[1]; \
170 a0 = ((op_t *) srcp)[0]; \
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)); \
173 a2 = a0; \
174 len -= 2; \
176 while (len != 0)
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. */
183 #ifndef WORDCOPY_BWD_DEST_ALIGNED
184 # define WORDCOPY_BWD_DEST_ALIGNED _wordcopy_bwd_dest_aligned
185 #endif
187 void
188 WORDCOPY_BWD_DEST_ALIGNED (long int dstp, long int srcp, size_t len)
190 op_t a0, a1, a2;
191 int sh_1, sh_2;
192 int align;
194 /* Calculate how to shift a word read at the memory operation
195 aligned srcp to make it aligned for copy. */
197 align = srcp % OPSIZ;
198 sh_1 = 8 * (srcp % OPSIZ);
199 sh_2 = 8 * OPSIZ - sh_1;
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];
206 if (len & 1)
208 srcp -= OPSIZ;
209 dstp -= OPSIZ;
210 a1 = ((op_t *) srcp)[0];
211 ((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2);
213 if (len == 1)
214 return;
216 a2 = a1;
217 len -= 1;
220 bwd_align_merge (align);