]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/powerpc32/power4/wordcopy.c
Update copyright notices with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc32 / power4 / wordcopy.c
CommitLineData
04067002 1/* _memcopy.c -- subroutines for memory copy functions.
568035b7 2 Copyright (C) 1991-2013 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
PE
17 License along with the GNU C Library; if not, see
18 <http://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
29void
30_wordcopy_fwd_aligned (dstp, srcp, len)
31 long int dstp;
32 long int srcp;
33 size_t len;
34{
35 op_t a0, a1;
36
37 if (len & 1)
38 {
39 ((op_t *) dstp)[0] = ((op_t *) srcp)[0];
40
41 if (len == 1)
42 return;
43 srcp += OPSIZ;
44 dstp += OPSIZ;
45 len -= 1;
46 }
47
48 do
49 {
50 a0 = ((op_t *) srcp)[0];
51 a1 = ((op_t *) srcp)[1];
52 ((op_t *) dstp)[0] = a0;
53 ((op_t *) dstp)[1] = a1;
54
55 srcp += 2 * OPSIZ;
56 dstp += 2 * OPSIZ;
57 len -= 2;
58 }
59 while (len != 0);
60}
61
62/* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
63 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
64 DSTP should be aligned for memory operations on `op_t's, but SRCP must
65 *not* be aligned. */
66
67void
68_wordcopy_fwd_dest_aligned (dstp, srcp, len)
69 long int dstp;
70 long int srcp;
71 size_t len;
72{
73 op_t a0, a1, a2;
74 int sh_1, sh_2;
75
76 /* Calculate how to shift a word read at the memory operation
77 aligned srcp to make it aligned for copy. */
78
79 sh_1 = 8 * (srcp % OPSIZ);
80 sh_2 = 8 * OPSIZ - sh_1;
81
82 /* Make SRCP aligned by rounding it down to the beginning of the `op_t'
83 it points in the middle of. */
84 srcp &= -OPSIZ;
85 a0 = ((op_t *) srcp)[0];
86
87 if (len & 1)
88 {
89 a1 = ((op_t *) srcp)[1];
90 ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
91
92 if (len == 1)
93 return;
94
95 a0 = a1;
96 srcp += OPSIZ;
97 dstp += OPSIZ;
98 len -= 1;
99 }
100
101 do
102 {
103 a1 = ((op_t *) srcp)[1];
104 a2 = ((op_t *) srcp)[2];
105 ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
106 ((op_t *) dstp)[1] = MERGE (a1, sh_1, a2, sh_2);
107 a0 = a2;
108
109 srcp += 2 * OPSIZ;
110 dstp += 2 * OPSIZ;
111 len -= 2;
112 }
113 while (len != 0);
114}
115
116/* _wordcopy_bwd_aligned -- Copy block finishing right before
117 SRCP to block finishing right before DSTP with LEN `op_t' words
118 (not LEN bytes!). Both SRCP and DSTP should be aligned for memory
119 operations on `op_t's. */
120
121void
122_wordcopy_bwd_aligned (dstp, srcp, len)
123 long int dstp;
124 long int srcp;
125 size_t len;
126{
127 op_t a0, a1;
128
129 if (len & 1)
130 {
131 srcp -= OPSIZ;
132 dstp -= OPSIZ;
133 ((op_t *) dstp)[0] = ((op_t *) srcp)[0];
134
135 if (len == 1)
136 return;
137 len -= 1;
138 }
139
140 do
141 {
142 srcp -= 2 * OPSIZ;
143 dstp -= 2 * OPSIZ;
144
145 a1 = ((op_t *) srcp)[1];
146 a0 = ((op_t *) srcp)[0];
147 ((op_t *) dstp)[1] = a1;
148 ((op_t *) dstp)[0] = a0;
149
150 len -= 2;
151 }
152 while (len != 0);
153}
154
155/* _wordcopy_bwd_dest_aligned -- Copy block finishing right
156 before SRCP to block finishing right before DSTP with LEN `op_t'
157 words (not LEN bytes!). DSTP should be aligned for memory
158 operations on `op_t', but SRCP must *not* be aligned. */
159
160void
161_wordcopy_bwd_dest_aligned (dstp, srcp, len)
162 long int dstp;
163 long int srcp;
164 size_t len;
165{
166 op_t a0, a1, a2;
167 int sh_1, sh_2;
168
169 /* Calculate how to shift a word read at the memory operation
170 aligned srcp to make it aligned for copy. */
171
172 sh_1 = 8 * (srcp % OPSIZ);
173 sh_2 = 8 * OPSIZ - sh_1;
174
175 /* Make srcp aligned by rounding it down to the beginning of the op_t
176 it points in the middle of. */
177 srcp &= -OPSIZ;
178 a2 = ((op_t *) srcp)[0];
179
180 if (len & 1)
181 {
182 srcp -= OPSIZ;
183 dstp -= OPSIZ;
184 a1 = ((op_t *) srcp)[0];
185 ((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2);
186
187 if (len == 1)
188 return;
189
190 a2 = a1;
191 len -= 1;
192 }
193
194 do
195 {
196 srcp -= 2 * OPSIZ;
197 dstp -= 2 * OPSIZ;
198
199 a1 = ((op_t *) srcp)[1];
200 a0 = ((op_t *) srcp)[0];
201 ((op_t *) dstp)[1] = MERGE (a1, sh_1, a2, sh_2);
202 ((op_t *) dstp)[0] = MERGE (a0, sh_1, a1, sh_2);
203 a2 = a0;
204
205 len -= 2;
206 }
207 while (len != 0);
208}