Mercurial > mplayer.hg
annotate libswscale/ppc/swscale_altivec_template.c @ 29308:880c5d014d37
Use DECLARE_ALIGNED macro instead of __attribute__((aligned)) for ppc code.
author | ramiro |
---|---|
date | Thu, 04 Jun 2009 22:50:38 +0000 |
parents | 882a1f5613e1 |
children | c080f1f5c07e |
rev | line source |
---|---|
29060 | 1 /* |
2 * AltiVec-enhanced yuv2yuvX | |
3 * | |
4 * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org> | |
5 * based on the equivalent C code in swscale.c | |
6 * | |
7 * This file is part of FFmpeg. | |
8 * | |
9 * FFmpeg is free software; you can redistribute it and/or | |
10 * modify it under the terms of the GNU Lesser General Public | |
11 * License as published by the Free Software Foundation; either | |
12 * version 2.1 of the License, or (at your option) any later version. | |
13 * | |
14 * FFmpeg is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * Lesser General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU Lesser General Public | |
20 * License along with FFmpeg; if not, write to the Free Software | |
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 */ | |
23 | |
24 #define vzero vec_splat_s32(0) | |
25 | |
26 static inline void | |
27 altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) { | |
28 register int i; | |
29 vector unsigned int altivec_vectorShiftInt19 = | |
30 vec_add(vec_splat_u32(10), vec_splat_u32(9)); | |
31 if ((unsigned long)dest % 16) { | |
32 /* badly aligned store, we force store alignment */ | |
33 /* and will handle load misalignment on val w/ vec_perm */ | |
34 vector unsigned char perm1; | |
35 vector signed int v1; | |
36 for (i = 0 ; (i < dstW) && | |
37 (((unsigned long)dest + i) % 16) ; i++) { | |
38 int t = val[i] >> 19; | |
39 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); | |
40 } | |
41 perm1 = vec_lvsl(i << 2, val); | |
42 v1 = vec_ld(i << 2, val); | |
43 for ( ; i < (dstW - 15); i+=16) { | |
44 int offset = i << 2; | |
45 vector signed int v2 = vec_ld(offset + 16, val); | |
46 vector signed int v3 = vec_ld(offset + 32, val); | |
47 vector signed int v4 = vec_ld(offset + 48, val); | |
48 vector signed int v5 = vec_ld(offset + 64, val); | |
49 vector signed int v12 = vec_perm(v1, v2, perm1); | |
50 vector signed int v23 = vec_perm(v2, v3, perm1); | |
51 vector signed int v34 = vec_perm(v3, v4, perm1); | |
52 vector signed int v45 = vec_perm(v4, v5, perm1); | |
53 | |
54 vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19); | |
55 vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19); | |
56 vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19); | |
57 vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19); | |
58 vector unsigned short vs1 = vec_packsu(vA, vB); | |
59 vector unsigned short vs2 = vec_packsu(vC, vD); | |
60 vector unsigned char vf = vec_packsu(vs1, vs2); | |
61 vec_st(vf, i, dest); | |
62 v1 = v5; | |
63 } | |
64 } else { // dest is properly aligned, great | |
65 for (i = 0; i < (dstW - 15); i+=16) { | |
66 int offset = i << 2; | |
67 vector signed int v1 = vec_ld(offset, val); | |
68 vector signed int v2 = vec_ld(offset + 16, val); | |
69 vector signed int v3 = vec_ld(offset + 32, val); | |
70 vector signed int v4 = vec_ld(offset + 48, val); | |
71 vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19); | |
72 vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19); | |
73 vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19); | |
74 vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19); | |
75 vector unsigned short vs1 = vec_packsu(v5, v6); | |
76 vector unsigned short vs2 = vec_packsu(v7, v8); | |
77 vector unsigned char vf = vec_packsu(vs1, vs2); | |
78 vec_st(vf, i, dest); | |
79 } | |
80 } | |
81 for ( ; i < dstW ; i++) { | |
82 int t = val[i] >> 19; | |
83 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); | |
84 } | |
85 } | |
86 | |
87 static inline void | |
29239
882a1f5613e1
Add missing const qualifiers to AltiVec function parameters where appropriate.
diego
parents:
29060
diff
changeset
|
88 yuv2yuvX_altivec_real(const int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, |
882a1f5613e1
Add missing const qualifiers to AltiVec function parameters where appropriate.
diego
parents:
29060
diff
changeset
|
89 const int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, |
29060 | 90 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW) |
91 { | |
92 const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)}; | |
93 register int i, j; | |
94 { | |
29308
880c5d014d37
Use DECLARE_ALIGNED macro instead of __attribute__((aligned)) for ppc code.
ramiro
parents:
29239
diff
changeset
|
95 DECLARE_ALIGNED(16, int, val[dstW]); |
29060 | 96 |
97 for (i = 0; i < (dstW -7); i+=4) { | |
98 vec_st(vini, i << 2, val); | |
99 } | |
100 for (; i < dstW; i++) { | |
101 val[i] = (1 << 18); | |
102 } | |
103 | |
104 for (j = 0; j < lumFilterSize; j++) { | |
105 vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter); | |
106 vector unsigned char perm, perm0 = vec_lvsl(j << 1, lumFilter); | |
107 vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0); | |
108 vLumFilter = vec_splat(vLumFilter, 0); // lumFilter[j] is loaded 8 times in vLumFilter | |
109 | |
110 perm = vec_lvsl(0, lumSrc[j]); | |
111 l1 = vec_ld(0, lumSrc[j]); | |
112 | |
113 for (i = 0; i < (dstW - 7); i+=8) { | |
114 int offset = i << 2; | |
115 vector signed short l2 = vec_ld((i << 1) + 16, lumSrc[j]); | |
116 | |
117 vector signed int v1 = vec_ld(offset, val); | |
118 vector signed int v2 = vec_ld(offset + 16, val); | |
119 | |
120 vector signed short ls = vec_perm(l1, l2, perm); // lumSrc[j][i] ... lumSrc[j][i+7] | |
121 | |
122 vector signed int i1 = vec_mule(vLumFilter, ls); | |
123 vector signed int i2 = vec_mulo(vLumFilter, ls); | |
124 | |
125 vector signed int vf1 = vec_mergeh(i1, i2); | |
126 vector signed int vf2 = vec_mergel(i1, i2); // lumSrc[j][i] * lumFilter[j] ... lumSrc[j][i+7] * lumFilter[j] | |
127 | |
128 vector signed int vo1 = vec_add(v1, vf1); | |
129 vector signed int vo2 = vec_add(v2, vf2); | |
130 | |
131 vec_st(vo1, offset, val); | |
132 vec_st(vo2, offset + 16, val); | |
133 | |
134 l1 = l2; | |
135 } | |
136 for ( ; i < dstW; i++) { | |
137 val[i] += lumSrc[j][i] * lumFilter[j]; | |
138 } | |
139 } | |
140 altivec_packIntArrayToCharArray(val, dest, dstW); | |
141 } | |
142 if (uDest != 0) { | |
29308
880c5d014d37
Use DECLARE_ALIGNED macro instead of __attribute__((aligned)) for ppc code.
ramiro
parents:
29239
diff
changeset
|
143 DECLARE_ALIGNED(16, int, u[chrDstW]); |
880c5d014d37
Use DECLARE_ALIGNED macro instead of __attribute__((aligned)) for ppc code.
ramiro
parents:
29239
diff
changeset
|
144 DECLARE_ALIGNED(16, int, v[chrDstW]); |
29060 | 145 |
146 for (i = 0; i < (chrDstW -7); i+=4) { | |
147 vec_st(vini, i << 2, u); | |
148 vec_st(vini, i << 2, v); | |
149 } | |
150 for (; i < chrDstW; i++) { | |
151 u[i] = (1 << 18); | |
152 v[i] = (1 << 18); | |
153 } | |
154 | |
155 for (j = 0; j < chrFilterSize; j++) { | |
156 vector signed short l1, l1_V, vChrFilter = vec_ld(j << 1, chrFilter); | |
157 vector unsigned char perm, perm0 = vec_lvsl(j << 1, chrFilter); | |
158 vChrFilter = vec_perm(vChrFilter, vChrFilter, perm0); | |
159 vChrFilter = vec_splat(vChrFilter, 0); // chrFilter[j] is loaded 8 times in vChrFilter | |
160 | |
161 perm = vec_lvsl(0, chrSrc[j]); | |
162 l1 = vec_ld(0, chrSrc[j]); | |
163 l1_V = vec_ld(2048 << 1, chrSrc[j]); | |
164 | |
165 for (i = 0; i < (chrDstW - 7); i+=8) { | |
166 int offset = i << 2; | |
167 vector signed short l2 = vec_ld((i << 1) + 16, chrSrc[j]); | |
168 vector signed short l2_V = vec_ld(((i + 2048) << 1) + 16, chrSrc[j]); | |
169 | |
170 vector signed int v1 = vec_ld(offset, u); | |
171 vector signed int v2 = vec_ld(offset + 16, u); | |
172 vector signed int v1_V = vec_ld(offset, v); | |
173 vector signed int v2_V = vec_ld(offset + 16, v); | |
174 | |
175 vector signed short ls = vec_perm(l1, l2, perm); // chrSrc[j][i] ... chrSrc[j][i+7] | |
176 vector signed short ls_V = vec_perm(l1_V, l2_V, perm); // chrSrc[j][i+2048] ... chrSrc[j][i+2055] | |
177 | |
178 vector signed int i1 = vec_mule(vChrFilter, ls); | |
179 vector signed int i2 = vec_mulo(vChrFilter, ls); | |
180 vector signed int i1_V = vec_mule(vChrFilter, ls_V); | |
181 vector signed int i2_V = vec_mulo(vChrFilter, ls_V); | |
182 | |
183 vector signed int vf1 = vec_mergeh(i1, i2); | |
184 vector signed int vf2 = vec_mergel(i1, i2); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] | |
185 vector signed int vf1_V = vec_mergeh(i1_V, i2_V); | |
186 vector signed int vf2_V = vec_mergel(i1_V, i2_V); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] | |
187 | |
188 vector signed int vo1 = vec_add(v1, vf1); | |
189 vector signed int vo2 = vec_add(v2, vf2); | |
190 vector signed int vo1_V = vec_add(v1_V, vf1_V); | |
191 vector signed int vo2_V = vec_add(v2_V, vf2_V); | |
192 | |
193 vec_st(vo1, offset, u); | |
194 vec_st(vo2, offset + 16, u); | |
195 vec_st(vo1_V, offset, v); | |
196 vec_st(vo2_V, offset + 16, v); | |
197 | |
198 l1 = l2; | |
199 l1_V = l2_V; | |
200 } | |
201 for ( ; i < chrDstW; i++) { | |
202 u[i] += chrSrc[j][i] * chrFilter[j]; | |
203 v[i] += chrSrc[j][i + 2048] * chrFilter[j]; | |
204 } | |
205 } | |
206 altivec_packIntArrayToCharArray(u, uDest, chrDstW); | |
207 altivec_packIntArrayToCharArray(v, vDest, chrDstW); | |
208 } | |
209 } | |
210 | |
29239
882a1f5613e1
Add missing const qualifiers to AltiVec function parameters where appropriate.
diego
parents:
29060
diff
changeset
|
211 static inline void hScale_altivec_real(int16_t *dst, int dstW, |
882a1f5613e1
Add missing const qualifiers to AltiVec function parameters where appropriate.
diego
parents:
29060
diff
changeset
|
212 const uint8_t *src, int srcW, |
882a1f5613e1
Add missing const qualifiers to AltiVec function parameters where appropriate.
diego
parents:
29060
diff
changeset
|
213 int xInc, const int16_t *filter, |
882a1f5613e1
Add missing const qualifiers to AltiVec function parameters where appropriate.
diego
parents:
29060
diff
changeset
|
214 const int16_t *filterPos, int filterSize) |
882a1f5613e1
Add missing const qualifiers to AltiVec function parameters where appropriate.
diego
parents:
29060
diff
changeset
|
215 { |
29060 | 216 register int i; |
29308
880c5d014d37
Use DECLARE_ALIGNED macro instead of __attribute__((aligned)) for ppc code.
ramiro
parents:
29239
diff
changeset
|
217 DECLARE_ALIGNED(16, int, tempo[4]); |
29060 | 218 |
219 if (filterSize % 4) { | |
220 for (i=0; i<dstW; i++) { | |
221 register int j; | |
222 register int srcPos = filterPos[i]; | |
223 register int val = 0; | |
224 for (j=0; j<filterSize; j++) { | |
225 val += ((int)src[srcPos + j])*filter[filterSize*i + j]; | |
226 } | |
227 dst[i] = FFMIN(val>>7, (1<<15)-1); | |
228 } | |
229 } | |
230 else | |
231 switch (filterSize) { | |
232 case 4: | |
233 { | |
234 for (i=0; i<dstW; i++) { | |
235 register int srcPos = filterPos[i]; | |
236 | |
237 vector unsigned char src_v0 = vec_ld(srcPos, src); | |
238 vector unsigned char src_v1, src_vF; | |
239 vector signed short src_v, filter_v; | |
240 vector signed int val_vEven, val_s; | |
241 if ((((int)src + srcPos)% 16) > 12) { | |
242 src_v1 = vec_ld(srcPos + 16, src); | |
243 } | |
244 src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); | |
245 | |
246 src_v = // vec_unpackh sign-extends... | |
247 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); | |
248 // now put our elements in the even slots | |
249 src_v = vec_mergeh(src_v, (vector signed short)vzero); | |
250 | |
251 filter_v = vec_ld(i << 3, filter); | |
252 // The 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2). | |
253 | |
254 // The neat trick: We only care for half the elements, | |
255 // high or low depending on (i<<3)%16 (it's 0 or 8 here), | |
256 // and we're going to use vec_mule, so we choose | |
257 // carefully how to "unpack" the elements into the even slots. | |
258 if ((i << 3) % 16) | |
259 filter_v = vec_mergel(filter_v, (vector signed short)vzero); | |
260 else | |
261 filter_v = vec_mergeh(filter_v, (vector signed short)vzero); | |
262 | |
263 val_vEven = vec_mule(src_v, filter_v); | |
264 val_s = vec_sums(val_vEven, vzero); | |
265 vec_st(val_s, 0, tempo); | |
266 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); | |
267 } | |
268 } | |
269 break; | |
270 | |
271 case 8: | |
272 { | |
273 for (i=0; i<dstW; i++) { | |
274 register int srcPos = filterPos[i]; | |
275 | |
276 vector unsigned char src_v0 = vec_ld(srcPos, src); | |
277 vector unsigned char src_v1, src_vF; | |
278 vector signed short src_v, filter_v; | |
279 vector signed int val_v, val_s; | |
280 if ((((int)src + srcPos)% 16) > 8) { | |
281 src_v1 = vec_ld(srcPos + 16, src); | |
282 } | |
283 src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); | |
284 | |
285 src_v = // vec_unpackh sign-extends... | |
286 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); | |
287 filter_v = vec_ld(i << 4, filter); | |
288 // the 4 above is 3 (filterSize == 8) + 1 (sizeof(short) == 2) | |
289 | |
290 val_v = vec_msums(src_v, filter_v, (vector signed int)vzero); | |
291 val_s = vec_sums(val_v, vzero); | |
292 vec_st(val_s, 0, tempo); | |
293 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); | |
294 } | |
295 } | |
296 break; | |
297 | |
298 case 16: | |
299 { | |
300 for (i=0; i<dstW; i++) { | |
301 register int srcPos = filterPos[i]; | |
302 | |
303 vector unsigned char src_v0 = vec_ld(srcPos, src); | |
304 vector unsigned char src_v1 = vec_ld(srcPos + 16, src); | |
305 vector unsigned char src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); | |
306 | |
307 vector signed short src_vA = // vec_unpackh sign-extends... | |
308 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); | |
309 vector signed short src_vB = // vec_unpackh sign-extends... | |
310 (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF)); | |
311 | |
312 vector signed short filter_v0 = vec_ld(i << 5, filter); | |
313 vector signed short filter_v1 = vec_ld((i << 5) + 16, filter); | |
314 // the 5 above are 4 (filterSize == 16) + 1 (sizeof(short) == 2) | |
315 | |
316 vector signed int val_acc = vec_msums(src_vA, filter_v0, (vector signed int)vzero); | |
317 vector signed int val_v = vec_msums(src_vB, filter_v1, val_acc); | |
318 | |
319 vector signed int val_s = vec_sums(val_v, vzero); | |
320 | |
321 vec_st(val_s, 0, tempo); | |
322 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); | |
323 } | |
324 } | |
325 break; | |
326 | |
327 default: | |
328 { | |
329 for (i=0; i<dstW; i++) { | |
330 register int j; | |
331 register int srcPos = filterPos[i]; | |
332 | |
333 vector signed int val_s, val_v = (vector signed int)vzero; | |
334 vector signed short filter_v0R = vec_ld(i * 2 * filterSize, filter); | |
335 vector unsigned char permF = vec_lvsl((i * 2 * filterSize), filter); | |
336 | |
337 vector unsigned char src_v0 = vec_ld(srcPos, src); | |
338 vector unsigned char permS = vec_lvsl(srcPos, src); | |
339 | |
340 for (j = 0 ; j < filterSize - 15; j += 16) { | |
341 vector unsigned char src_v1 = vec_ld(srcPos + j + 16, src); | |
342 vector unsigned char src_vF = vec_perm(src_v0, src_v1, permS); | |
343 | |
344 vector signed short src_vA = // vec_unpackh sign-extends... | |
345 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); | |
346 vector signed short src_vB = // vec_unpackh sign-extends... | |
347 (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF)); | |
348 | |
349 vector signed short filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter); | |
350 vector signed short filter_v2R = vec_ld((i * 2 * filterSize) + (j * 2) + 32, filter); | |
351 vector signed short filter_v0 = vec_perm(filter_v0R, filter_v1R, permF); | |
352 vector signed short filter_v1 = vec_perm(filter_v1R, filter_v2R, permF); | |
353 | |
354 vector signed int val_acc = vec_msums(src_vA, filter_v0, val_v); | |
355 val_v = vec_msums(src_vB, filter_v1, val_acc); | |
356 | |
357 filter_v0R = filter_v2R; | |
358 src_v0 = src_v1; | |
359 } | |
360 | |
361 if (j < filterSize-7) { | |
362 // loading src_v0 is useless, it's already done above | |
363 //vector unsigned char src_v0 = vec_ld(srcPos + j, src); | |
364 vector unsigned char src_v1, src_vF; | |
365 vector signed short src_v, filter_v1R, filter_v; | |
366 if ((((int)src + srcPos)% 16) > 8) { | |
367 src_v1 = vec_ld(srcPos + j + 16, src); | |
368 } | |
369 src_vF = vec_perm(src_v0, src_v1, permS); | |
370 | |
371 src_v = // vec_unpackh sign-extends... | |
372 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); | |
373 // loading filter_v0R is useless, it's already done above | |
374 //vector signed short filter_v0R = vec_ld((i * 2 * filterSize) + j, filter); | |
375 filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter); | |
376 filter_v = vec_perm(filter_v0R, filter_v1R, permF); | |
377 | |
378 val_v = vec_msums(src_v, filter_v, val_v); | |
379 } | |
380 | |
381 val_s = vec_sums(val_v, vzero); | |
382 | |
383 vec_st(val_s, 0, tempo); | |
384 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); | |
385 } | |
386 | |
387 } | |
388 } | |
389 } | |
390 | |
391 static inline int yv12toyuy2_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
392 int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) { | |
393 uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; | |
394 // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); | |
395 uint8_t *ysrc = src[0]; | |
396 uint8_t *usrc = src[1]; | |
397 uint8_t *vsrc = src[2]; | |
398 const int width = c->srcW; | |
399 const int height = srcSliceH; | |
400 const int lumStride = srcStride[0]; | |
401 const int chromStride = srcStride[1]; | |
402 const int dstStride = dstStride_a[0]; | |
403 const vector unsigned char yperm = vec_lvsl(0, ysrc); | |
404 const int vertLumPerChroma = 2; | |
405 register unsigned int y; | |
406 | |
407 if (width&15) { | |
408 yv12toyuy2(ysrc, usrc, vsrc, dst, c->srcW, srcSliceH, lumStride, chromStride, dstStride); | |
409 return srcSliceH; | |
410 } | |
411 | |
412 /* This code assumes: | |
413 | |
414 1) dst is 16 bytes-aligned | |
415 2) dstStride is a multiple of 16 | |
416 3) width is a multiple of 16 | |
417 4) lum & chrom stride are multiples of 8 | |
418 */ | |
419 | |
420 for (y=0; y<height; y++) { | |
421 int i; | |
422 for (i = 0; i < width - 31; i+= 32) { | |
423 const unsigned int j = i >> 1; | |
424 vector unsigned char v_yA = vec_ld(i, ysrc); | |
425 vector unsigned char v_yB = vec_ld(i + 16, ysrc); | |
426 vector unsigned char v_yC = vec_ld(i + 32, ysrc); | |
427 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); | |
428 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); | |
429 vector unsigned char v_uA = vec_ld(j, usrc); | |
430 vector unsigned char v_uB = vec_ld(j + 16, usrc); | |
431 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); | |
432 vector unsigned char v_vA = vec_ld(j, vsrc); | |
433 vector unsigned char v_vB = vec_ld(j + 16, vsrc); | |
434 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); | |
435 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); | |
436 vector unsigned char v_uv_b = vec_mergel(v_u, v_v); | |
437 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); | |
438 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); | |
439 vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b); | |
440 vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b); | |
441 vec_st(v_yuy2_0, (i << 1), dst); | |
442 vec_st(v_yuy2_1, (i << 1) + 16, dst); | |
443 vec_st(v_yuy2_2, (i << 1) + 32, dst); | |
444 vec_st(v_yuy2_3, (i << 1) + 48, dst); | |
445 } | |
446 if (i < width) { | |
447 const unsigned int j = i >> 1; | |
448 vector unsigned char v_y1 = vec_ld(i, ysrc); | |
449 vector unsigned char v_u = vec_ld(j, usrc); | |
450 vector unsigned char v_v = vec_ld(j, vsrc); | |
451 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); | |
452 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); | |
453 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); | |
454 vec_st(v_yuy2_0, (i << 1), dst); | |
455 vec_st(v_yuy2_1, (i << 1) + 16, dst); | |
456 } | |
457 if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { | |
458 usrc += chromStride; | |
459 vsrc += chromStride; | |
460 } | |
461 ysrc += lumStride; | |
462 dst += dstStride; | |
463 } | |
464 | |
465 return srcSliceH; | |
466 } | |
467 | |
468 static inline int yv12touyvy_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
469 int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) { | |
470 uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; | |
471 // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); | |
472 uint8_t *ysrc = src[0]; | |
473 uint8_t *usrc = src[1]; | |
474 uint8_t *vsrc = src[2]; | |
475 const int width = c->srcW; | |
476 const int height = srcSliceH; | |
477 const int lumStride = srcStride[0]; | |
478 const int chromStride = srcStride[1]; | |
479 const int dstStride = dstStride_a[0]; | |
480 const int vertLumPerChroma = 2; | |
481 const vector unsigned char yperm = vec_lvsl(0, ysrc); | |
482 register unsigned int y; | |
483 | |
484 if (width&15) { | |
485 yv12touyvy(ysrc, usrc, vsrc, dst, c->srcW, srcSliceH, lumStride, chromStride, dstStride); | |
486 return srcSliceH; | |
487 } | |
488 | |
489 /* This code assumes: | |
490 | |
491 1) dst is 16 bytes-aligned | |
492 2) dstStride is a multiple of 16 | |
493 3) width is a multiple of 16 | |
494 4) lum & chrom stride are multiples of 8 | |
495 */ | |
496 | |
497 for (y=0; y<height; y++) { | |
498 int i; | |
499 for (i = 0; i < width - 31; i+= 32) { | |
500 const unsigned int j = i >> 1; | |
501 vector unsigned char v_yA = vec_ld(i, ysrc); | |
502 vector unsigned char v_yB = vec_ld(i + 16, ysrc); | |
503 vector unsigned char v_yC = vec_ld(i + 32, ysrc); | |
504 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); | |
505 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); | |
506 vector unsigned char v_uA = vec_ld(j, usrc); | |
507 vector unsigned char v_uB = vec_ld(j + 16, usrc); | |
508 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); | |
509 vector unsigned char v_vA = vec_ld(j, vsrc); | |
510 vector unsigned char v_vB = vec_ld(j + 16, vsrc); | |
511 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); | |
512 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); | |
513 vector unsigned char v_uv_b = vec_mergel(v_u, v_v); | |
514 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); | |
515 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); | |
516 vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2); | |
517 vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2); | |
518 vec_st(v_uyvy_0, (i << 1), dst); | |
519 vec_st(v_uyvy_1, (i << 1) + 16, dst); | |
520 vec_st(v_uyvy_2, (i << 1) + 32, dst); | |
521 vec_st(v_uyvy_3, (i << 1) + 48, dst); | |
522 } | |
523 if (i < width) { | |
524 const unsigned int j = i >> 1; | |
525 vector unsigned char v_y1 = vec_ld(i, ysrc); | |
526 vector unsigned char v_u = vec_ld(j, usrc); | |
527 vector unsigned char v_v = vec_ld(j, vsrc); | |
528 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); | |
529 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); | |
530 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); | |
531 vec_st(v_uyvy_0, (i << 1), dst); | |
532 vec_st(v_uyvy_1, (i << 1) + 16, dst); | |
533 } | |
534 if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { | |
535 usrc += chromStride; | |
536 vsrc += chromStride; | |
537 } | |
538 ysrc += lumStride; | |
539 dst += dstStride; | |
540 } | |
541 return srcSliceH; | |
542 } |