00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define vzero vec_splat_s32(0)
00025
00026 static inline void
00027 altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) {
00028 register int i;
00029 vector unsigned int altivec_vectorShiftInt19 =
00030 vec_add(vec_splat_u32(10), vec_splat_u32(9));
00031 if ((unsigned long)dest % 16) {
00032
00033
00034 vector unsigned char perm1;
00035 vector signed int v1;
00036 for (i = 0 ; (i < dstW) &&
00037 (((unsigned long)dest + i) % 16) ; i++) {
00038 int t = val[i] >> 19;
00039 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
00040 }
00041 perm1 = vec_lvsl(i << 2, val);
00042 v1 = vec_ld(i << 2, val);
00043 for ( ; i < (dstW - 15); i+=16) {
00044 int offset = i << 2;
00045 vector signed int v2 = vec_ld(offset + 16, val);
00046 vector signed int v3 = vec_ld(offset + 32, val);
00047 vector signed int v4 = vec_ld(offset + 48, val);
00048 vector signed int v5 = vec_ld(offset + 64, val);
00049 vector signed int v12 = vec_perm(v1, v2, perm1);
00050 vector signed int v23 = vec_perm(v2, v3, perm1);
00051 vector signed int v34 = vec_perm(v3, v4, perm1);
00052 vector signed int v45 = vec_perm(v4, v5, perm1);
00053
00054 vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19);
00055 vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19);
00056 vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19);
00057 vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19);
00058 vector unsigned short vs1 = vec_packsu(vA, vB);
00059 vector unsigned short vs2 = vec_packsu(vC, vD);
00060 vector unsigned char vf = vec_packsu(vs1, vs2);
00061 vec_st(vf, i, dest);
00062 v1 = v5;
00063 }
00064 } else {
00065 for (i = 0; i < (dstW - 15); i+=16) {
00066 int offset = i << 2;
00067 vector signed int v1 = vec_ld(offset, val);
00068 vector signed int v2 = vec_ld(offset + 16, val);
00069 vector signed int v3 = vec_ld(offset + 32, val);
00070 vector signed int v4 = vec_ld(offset + 48, val);
00071 vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19);
00072 vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19);
00073 vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19);
00074 vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19);
00075 vector unsigned short vs1 = vec_packsu(v5, v6);
00076 vector unsigned short vs2 = vec_packsu(v7, v8);
00077 vector unsigned char vf = vec_packsu(vs1, vs2);
00078 vec_st(vf, i, dest);
00079 }
00080 }
00081 for ( ; i < dstW ; i++) {
00082 int t = val[i] >> 19;
00083 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
00084 }
00085 }
00086
00087 static inline void
00088 yuv2yuvX_altivec_real(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
00089 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
00090 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW)
00091 {
00092 const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)};
00093 register int i, j;
00094 {
00095 int __attribute__ ((aligned (16))) val[dstW];
00096
00097 for (i = 0; i < (dstW -7); i+=4) {
00098 vec_st(vini, i << 2, val);
00099 }
00100 for (; i < dstW; i++) {
00101 val[i] = (1 << 18);
00102 }
00103
00104 for (j = 0; j < lumFilterSize; j++) {
00105 vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter);
00106 vector unsigned char perm, perm0 = vec_lvsl(j << 1, lumFilter);
00107 vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0);
00108 vLumFilter = vec_splat(vLumFilter, 0);
00109
00110 perm = vec_lvsl(0, lumSrc[j]);
00111 l1 = vec_ld(0, lumSrc[j]);
00112
00113 for (i = 0; i < (dstW - 7); i+=8) {
00114 int offset = i << 2;
00115 vector signed short l2 = vec_ld((i << 1) + 16, lumSrc[j]);
00116
00117 vector signed int v1 = vec_ld(offset, val);
00118 vector signed int v2 = vec_ld(offset + 16, val);
00119
00120 vector signed short ls = vec_perm(l1, l2, perm);
00121
00122 vector signed int i1 = vec_mule(vLumFilter, ls);
00123 vector signed int i2 = vec_mulo(vLumFilter, ls);
00124
00125 vector signed int vf1 = vec_mergeh(i1, i2);
00126 vector signed int vf2 = vec_mergel(i1, i2);
00127
00128 vector signed int vo1 = vec_add(v1, vf1);
00129 vector signed int vo2 = vec_add(v2, vf2);
00130
00131 vec_st(vo1, offset, val);
00132 vec_st(vo2, offset + 16, val);
00133
00134 l1 = l2;
00135 }
00136 for ( ; i < dstW; i++) {
00137 val[i] += lumSrc[j][i] * lumFilter[j];
00138 }
00139 }
00140 altivec_packIntArrayToCharArray(val, dest, dstW);
00141 }
00142 if (uDest != 0) {
00143 int __attribute__ ((aligned (16))) u[chrDstW];
00144 int __attribute__ ((aligned (16))) v[chrDstW];
00145
00146 for (i = 0; i < (chrDstW -7); i+=4) {
00147 vec_st(vini, i << 2, u);
00148 vec_st(vini, i << 2, v);
00149 }
00150 for (; i < chrDstW; i++) {
00151 u[i] = (1 << 18);
00152 v[i] = (1 << 18);
00153 }
00154
00155 for (j = 0; j < chrFilterSize; j++) {
00156 vector signed short l1, l1_V, vChrFilter = vec_ld(j << 1, chrFilter);
00157 vector unsigned char perm, perm0 = vec_lvsl(j << 1, chrFilter);
00158 vChrFilter = vec_perm(vChrFilter, vChrFilter, perm0);
00159 vChrFilter = vec_splat(vChrFilter, 0);
00160
00161 perm = vec_lvsl(0, chrSrc[j]);
00162 l1 = vec_ld(0, chrSrc[j]);
00163 l1_V = vec_ld(2048 << 1, chrSrc[j]);
00164
00165 for (i = 0; i < (chrDstW - 7); i+=8) {
00166 int offset = i << 2;
00167 vector signed short l2 = vec_ld((i << 1) + 16, chrSrc[j]);
00168 vector signed short l2_V = vec_ld(((i + 2048) << 1) + 16, chrSrc[j]);
00169
00170 vector signed int v1 = vec_ld(offset, u);
00171 vector signed int v2 = vec_ld(offset + 16, u);
00172 vector signed int v1_V = vec_ld(offset, v);
00173 vector signed int v2_V = vec_ld(offset + 16, v);
00174
00175 vector signed short ls = vec_perm(l1, l2, perm);
00176 vector signed short ls_V = vec_perm(l1_V, l2_V, perm);
00177
00178 vector signed int i1 = vec_mule(vChrFilter, ls);
00179 vector signed int i2 = vec_mulo(vChrFilter, ls);
00180 vector signed int i1_V = vec_mule(vChrFilter, ls_V);
00181 vector signed int i2_V = vec_mulo(vChrFilter, ls_V);
00182
00183 vector signed int vf1 = vec_mergeh(i1, i2);
00184 vector signed int vf2 = vec_mergel(i1, i2);
00185 vector signed int vf1_V = vec_mergeh(i1_V, i2_V);
00186 vector signed int vf2_V = vec_mergel(i1_V, i2_V);
00187
00188 vector signed int vo1 = vec_add(v1, vf1);
00189 vector signed int vo2 = vec_add(v2, vf2);
00190 vector signed int vo1_V = vec_add(v1_V, vf1_V);
00191 vector signed int vo2_V = vec_add(v2_V, vf2_V);
00192
00193 vec_st(vo1, offset, u);
00194 vec_st(vo2, offset + 16, u);
00195 vec_st(vo1_V, offset, v);
00196 vec_st(vo2_V, offset + 16, v);
00197
00198 l1 = l2;
00199 l1_V = l2_V;
00200 }
00201 for ( ; i < chrDstW; i++) {
00202 u[i] += chrSrc[j][i] * chrFilter[j];
00203 v[i] += chrSrc[j][i + 2048] * chrFilter[j];
00204 }
00205 }
00206 altivec_packIntArrayToCharArray(u, uDest, chrDstW);
00207 altivec_packIntArrayToCharArray(v, vDest, chrDstW);
00208 }
00209 }
00210
00211 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) {
00212 register int i;
00213 int __attribute__ ((aligned (16))) tempo[4];
00214
00215 if (filterSize % 4) {
00216 for (i=0; i<dstW; i++) {
00217 register int j;
00218 register int srcPos = filterPos[i];
00219 register int val = 0;
00220 for (j=0; j<filterSize; j++) {
00221 val += ((int)src[srcPos + j])*filter[filterSize*i + j];
00222 }
00223 dst[i] = FFMIN(val>>7, (1<<15)-1);
00224 }
00225 }
00226 else
00227 switch (filterSize) {
00228 case 4:
00229 {
00230 for (i=0; i<dstW; i++) {
00231 register int srcPos = filterPos[i];
00232
00233 vector unsigned char src_v0 = vec_ld(srcPos, src);
00234 vector unsigned char src_v1, src_vF;
00235 vector signed short src_v, filter_v;
00236 vector signed int val_vEven, val_s;
00237 if ((((int)src + srcPos)% 16) > 12) {
00238 src_v1 = vec_ld(srcPos + 16, src);
00239 }
00240 src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
00241
00242 src_v =
00243 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00244
00245 src_v = vec_mergeh(src_v, (vector signed short)vzero);
00246
00247 filter_v = vec_ld(i << 3, filter);
00248
00249
00250
00251
00252
00253
00254 if ((i << 3) % 16)
00255 filter_v = vec_mergel(filter_v, (vector signed short)vzero);
00256 else
00257 filter_v = vec_mergeh(filter_v, (vector signed short)vzero);
00258
00259 val_vEven = vec_mule(src_v, filter_v);
00260 val_s = vec_sums(val_vEven, vzero);
00261 vec_st(val_s, 0, tempo);
00262 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1);
00263 }
00264 }
00265 break;
00266
00267 case 8:
00268 {
00269 for (i=0; i<dstW; i++) {
00270 register int srcPos = filterPos[i];
00271
00272 vector unsigned char src_v0 = vec_ld(srcPos, src);
00273 vector unsigned char src_v1, src_vF;
00274 vector signed short src_v, filter_v;
00275 vector signed int val_v, val_s;
00276 if ((((int)src + srcPos)% 16) > 8) {
00277 src_v1 = vec_ld(srcPos + 16, src);
00278 }
00279 src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
00280
00281 src_v =
00282 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00283 filter_v = vec_ld(i << 4, filter);
00284
00285
00286 val_v = vec_msums(src_v, filter_v, (vector signed int)vzero);
00287 val_s = vec_sums(val_v, vzero);
00288 vec_st(val_s, 0, tempo);
00289 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1);
00290 }
00291 }
00292 break;
00293
00294 case 16:
00295 {
00296 for (i=0; i<dstW; i++) {
00297 register int srcPos = filterPos[i];
00298
00299 vector unsigned char src_v0 = vec_ld(srcPos, src);
00300 vector unsigned char src_v1 = vec_ld(srcPos + 16, src);
00301 vector unsigned char src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
00302
00303 vector signed short src_vA =
00304 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00305 vector signed short src_vB =
00306 (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF));
00307
00308 vector signed short filter_v0 = vec_ld(i << 5, filter);
00309 vector signed short filter_v1 = vec_ld((i << 5) + 16, filter);
00310
00311
00312 vector signed int val_acc = vec_msums(src_vA, filter_v0, (vector signed int)vzero);
00313 vector signed int val_v = vec_msums(src_vB, filter_v1, val_acc);
00314
00315 vector signed int val_s = vec_sums(val_v, vzero);
00316
00317 vec_st(val_s, 0, tempo);
00318 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1);
00319 }
00320 }
00321 break;
00322
00323 default:
00324 {
00325 for (i=0; i<dstW; i++) {
00326 register int j;
00327 register int srcPos = filterPos[i];
00328
00329 vector signed int val_s, val_v = (vector signed int)vzero;
00330 vector signed short filter_v0R = vec_ld(i * 2 * filterSize, filter);
00331 vector unsigned char permF = vec_lvsl((i * 2 * filterSize), filter);
00332
00333 vector unsigned char src_v0 = vec_ld(srcPos, src);
00334 vector unsigned char permS = vec_lvsl(srcPos, src);
00335
00336 for (j = 0 ; j < filterSize - 15; j += 16) {
00337 vector unsigned char src_v1 = vec_ld(srcPos + j + 16, src);
00338 vector unsigned char src_vF = vec_perm(src_v0, src_v1, permS);
00339
00340 vector signed short src_vA =
00341 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00342 vector signed short src_vB =
00343 (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF));
00344
00345 vector signed short filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter);
00346 vector signed short filter_v2R = vec_ld((i * 2 * filterSize) + (j * 2) + 32, filter);
00347 vector signed short filter_v0 = vec_perm(filter_v0R, filter_v1R, permF);
00348 vector signed short filter_v1 = vec_perm(filter_v1R, filter_v2R, permF);
00349
00350 vector signed int val_acc = vec_msums(src_vA, filter_v0, val_v);
00351 val_v = vec_msums(src_vB, filter_v1, val_acc);
00352
00353 filter_v0R = filter_v2R;
00354 src_v0 = src_v1;
00355 }
00356
00357 if (j < filterSize-7) {
00358
00359
00360 vector unsigned char src_v1, src_vF;
00361 vector signed short src_v, filter_v1R, filter_v;
00362 if ((((int)src + srcPos)% 16) > 8) {
00363 src_v1 = vec_ld(srcPos + j + 16, src);
00364 }
00365 src_vF = vec_perm(src_v0, src_v1, permS);
00366
00367 src_v =
00368 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00369
00370
00371 filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter);
00372 filter_v = vec_perm(filter_v0R, filter_v1R, permF);
00373
00374 val_v = vec_msums(src_v, filter_v, val_v);
00375 }
00376
00377 val_s = vec_sums(val_v, vzero);
00378
00379 vec_st(val_s, 0, tempo);
00380 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1);
00381 }
00382
00383 }
00384 }
00385 }
00386
00387 static inline int yv12toyuy2_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
00388 int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) {
00389 uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY;
00390
00391 uint8_t *ysrc = src[0];
00392 uint8_t *usrc = src[1];
00393 uint8_t *vsrc = src[2];
00394 const int width = c->srcW;
00395 const int height = srcSliceH;
00396 const int lumStride = srcStride[0];
00397 const int chromStride = srcStride[1];
00398 const int dstStride = dstStride_a[0];
00399 const vector unsigned char yperm = vec_lvsl(0, ysrc);
00400 const int vertLumPerChroma = 2;
00401 register unsigned int y;
00402
00403 if (width&15) {
00404 yv12toyuy2(ysrc, usrc, vsrc, dst, c->srcW, srcSliceH, lumStride, chromStride, dstStride);
00405 return srcSliceH;
00406 }
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416 for (y=0; y<height; y++) {
00417 int i;
00418 for (i = 0; i < width - 31; i+= 32) {
00419 const unsigned int j = i >> 1;
00420 vector unsigned char v_yA = vec_ld(i, ysrc);
00421 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
00422 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
00423 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
00424 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
00425 vector unsigned char v_uA = vec_ld(j, usrc);
00426 vector unsigned char v_uB = vec_ld(j + 16, usrc);
00427 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
00428 vector unsigned char v_vA = vec_ld(j, vsrc);
00429 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
00430 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
00431 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00432 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
00433 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
00434 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
00435 vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b);
00436 vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b);
00437 vec_st(v_yuy2_0, (i << 1), dst);
00438 vec_st(v_yuy2_1, (i << 1) + 16, dst);
00439 vec_st(v_yuy2_2, (i << 1) + 32, dst);
00440 vec_st(v_yuy2_3, (i << 1) + 48, dst);
00441 }
00442 if (i < width) {
00443 const unsigned int j = i >> 1;
00444 vector unsigned char v_y1 = vec_ld(i, ysrc);
00445 vector unsigned char v_u = vec_ld(j, usrc);
00446 vector unsigned char v_v = vec_ld(j, vsrc);
00447 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00448 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
00449 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
00450 vec_st(v_yuy2_0, (i << 1), dst);
00451 vec_st(v_yuy2_1, (i << 1) + 16, dst);
00452 }
00453 if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
00454 usrc += chromStride;
00455 vsrc += chromStride;
00456 }
00457 ysrc += lumStride;
00458 dst += dstStride;
00459 }
00460
00461 return srcSliceH;
00462 }
00463
00464 static inline int yv12touyvy_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
00465 int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) {
00466 uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY;
00467
00468 uint8_t *ysrc = src[0];
00469 uint8_t *usrc = src[1];
00470 uint8_t *vsrc = src[2];
00471 const int width = c->srcW;
00472 const int height = srcSliceH;
00473 const int lumStride = srcStride[0];
00474 const int chromStride = srcStride[1];
00475 const int dstStride = dstStride_a[0];
00476 const int vertLumPerChroma = 2;
00477 const vector unsigned char yperm = vec_lvsl(0, ysrc);
00478 register unsigned int y;
00479
00480 if (width&15) {
00481 yv12touyvy(ysrc, usrc, vsrc, dst, c->srcW, srcSliceH, lumStride, chromStride, dstStride);
00482 return srcSliceH;
00483 }
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 for (y=0; y<height; y++) {
00494 int i;
00495 for (i = 0; i < width - 31; i+= 32) {
00496 const unsigned int j = i >> 1;
00497 vector unsigned char v_yA = vec_ld(i, ysrc);
00498 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
00499 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
00500 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
00501 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
00502 vector unsigned char v_uA = vec_ld(j, usrc);
00503 vector unsigned char v_uB = vec_ld(j + 16, usrc);
00504 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
00505 vector unsigned char v_vA = vec_ld(j, vsrc);
00506 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
00507 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
00508 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00509 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
00510 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
00511 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
00512 vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2);
00513 vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2);
00514 vec_st(v_uyvy_0, (i << 1), dst);
00515 vec_st(v_uyvy_1, (i << 1) + 16, dst);
00516 vec_st(v_uyvy_2, (i << 1) + 32, dst);
00517 vec_st(v_uyvy_3, (i << 1) + 48, dst);
00518 }
00519 if (i < width) {
00520 const unsigned int j = i >> 1;
00521 vector unsigned char v_y1 = vec_ld(i, ysrc);
00522 vector unsigned char v_u = vec_ld(j, usrc);
00523 vector unsigned char v_v = vec_ld(j, vsrc);
00524 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00525 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
00526 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
00527 vec_st(v_uyvy_0, (i << 1), dst);
00528 vec_st(v_uyvy_1, (i << 1) + 16, dst);
00529 }
00530 if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
00531 usrc += chromStride;
00532 vsrc += chromStride;
00533 }
00534 ysrc += lumStride;
00535 dst += dstStride;
00536 }
00537 return srcSliceH;
00538 }