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