00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <inttypes.h>
00025 #include "config.h"
00026 #include "libswscale/swscale.h"
00027 #include "libswscale/swscale_internal.h"
00028 #include "libavutil/cpu.h"
00029 #include "yuv2rgb_altivec.h"
00030
00031 #define vzero vec_splat_s32(0)
00032
00033 static inline void
00034 altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW)
00035 {
00036 register int i;
00037 vector unsigned int altivec_vectorShiftInt19 =
00038 vec_add(vec_splat_u32(10), vec_splat_u32(9));
00039 if ((uintptr_t)dest % 16) {
00040
00041
00042 vector unsigned char perm1;
00043 vector signed int v1;
00044 for (i = 0 ; (i < dstW) &&
00045 (((uintptr_t)dest + i) % 16) ; i++) {
00046 int t = val[i] >> 19;
00047 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
00048 }
00049 perm1 = vec_lvsl(i << 2, val);
00050 v1 = vec_ld(i << 2, val);
00051 for ( ; i < (dstW - 15); i+=16) {
00052 int offset = i << 2;
00053 vector signed int v2 = vec_ld(offset + 16, val);
00054 vector signed int v3 = vec_ld(offset + 32, val);
00055 vector signed int v4 = vec_ld(offset + 48, val);
00056 vector signed int v5 = vec_ld(offset + 64, val);
00057 vector signed int v12 = vec_perm(v1, v2, perm1);
00058 vector signed int v23 = vec_perm(v2, v3, perm1);
00059 vector signed int v34 = vec_perm(v3, v4, perm1);
00060 vector signed int v45 = vec_perm(v4, v5, perm1);
00061
00062 vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19);
00063 vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19);
00064 vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19);
00065 vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19);
00066 vector unsigned short vs1 = vec_packsu(vA, vB);
00067 vector unsigned short vs2 = vec_packsu(vC, vD);
00068 vector unsigned char vf = vec_packsu(vs1, vs2);
00069 vec_st(vf, i, dest);
00070 v1 = v5;
00071 }
00072 } else {
00073 for (i = 0; i < (dstW - 15); i+=16) {
00074 int offset = i << 2;
00075 vector signed int v1 = vec_ld(offset, val);
00076 vector signed int v2 = vec_ld(offset + 16, val);
00077 vector signed int v3 = vec_ld(offset + 32, val);
00078 vector signed int v4 = vec_ld(offset + 48, val);
00079 vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19);
00080 vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19);
00081 vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19);
00082 vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19);
00083 vector unsigned short vs1 = vec_packsu(v5, v6);
00084 vector unsigned short vs2 = vec_packsu(v7, v8);
00085 vector unsigned char vf = vec_packsu(vs1, vs2);
00086 vec_st(vf, i, dest);
00087 }
00088 }
00089 for ( ; i < dstW ; i++) {
00090 int t = val[i] >> 19;
00091 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
00092 }
00093 }
00094
00095
00096 static void
00097 yuv2planeX_altivec(const int16_t *filter, int filterSize,
00098 const int16_t **src, uint8_t *dest, int dstW,
00099 const uint8_t *dither, int offset)
00100 {
00101 register int i, j;
00102 DECLARE_ALIGNED(16, int, val)[dstW];
00103
00104 for (i=0; i<dstW; i++)
00105 val[i] = dither[(i + offset) & 7] << 12;
00106
00107 for (j = 0; j < filterSize; j++) {
00108 vector signed short l1, vLumFilter = vec_ld(j << 1, filter);
00109 vector unsigned char perm, perm0 = vec_lvsl(j << 1, filter);
00110 vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0);
00111 vLumFilter = vec_splat(vLumFilter, 0);
00112
00113 perm = vec_lvsl(0, src[j]);
00114 l1 = vec_ld(0, src[j]);
00115
00116 for (i = 0; i < (dstW - 7); i+=8) {
00117 int offset = i << 2;
00118 vector signed short l2 = vec_ld((i << 1) + 16, src[j]);
00119
00120 vector signed int v1 = vec_ld(offset, val);
00121 vector signed int v2 = vec_ld(offset + 16, val);
00122
00123 vector signed short ls = vec_perm(l1, l2, perm);
00124
00125 vector signed int i1 = vec_mule(vLumFilter, ls);
00126 vector signed int i2 = vec_mulo(vLumFilter, ls);
00127
00128 vector signed int vf1 = vec_mergeh(i1, i2);
00129 vector signed int vf2 = vec_mergel(i1, i2);
00130
00131 vector signed int vo1 = vec_add(v1, vf1);
00132 vector signed int vo2 = vec_add(v2, vf2);
00133
00134 vec_st(vo1, offset, val);
00135 vec_st(vo2, offset + 16, val);
00136
00137 l1 = l2;
00138 }
00139 for ( ; i < dstW; i++) {
00140 val[i] += src[j][i] * filter[j];
00141 }
00142 }
00143 altivec_packIntArrayToCharArray(val, dest, dstW);
00144 }
00145
00146 static void hScale_altivec_real(SwsContext *c, int16_t *dst, int dstW,
00147 const uint8_t *src, const int16_t *filter,
00148 const int32_t *filterPos, int filterSize)
00149 {
00150 register int i;
00151 DECLARE_ALIGNED(16, int, tempo)[4];
00152
00153 if (filterSize % 4) {
00154 for (i=0; i<dstW; i++) {
00155 register int j;
00156 register int srcPos = filterPos[i];
00157 register int val = 0;
00158 for (j=0; j<filterSize; j++) {
00159 val += ((int)src[srcPos + j])*filter[filterSize*i + j];
00160 }
00161 dst[i] = FFMIN(val>>7, (1<<15)-1);
00162 }
00163 }
00164 else
00165 switch (filterSize) {
00166 case 4:
00167 for (i=0; i<dstW; i++) {
00168 register int srcPos = filterPos[i];
00169
00170 vector unsigned char src_v0 = vec_ld(srcPos, src);
00171 vector unsigned char src_v1, src_vF;
00172 vector signed short src_v, filter_v;
00173 vector signed int val_vEven, val_s;
00174 if ((((uintptr_t)src + srcPos) % 16) > 12) {
00175 src_v1 = vec_ld(srcPos + 16, src);
00176 }
00177 src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
00178
00179 src_v =
00180 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00181
00182 src_v = vec_mergeh(src_v, (vector signed short)vzero);
00183
00184 filter_v = vec_ld(i << 3, filter);
00185
00186
00187
00188
00189
00190
00191 if ((i << 3) % 16)
00192 filter_v = vec_mergel(filter_v, (vector signed short)vzero);
00193 else
00194 filter_v = vec_mergeh(filter_v, (vector signed short)vzero);
00195
00196 val_vEven = vec_mule(src_v, filter_v);
00197 val_s = vec_sums(val_vEven, vzero);
00198 vec_st(val_s, 0, tempo);
00199 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1);
00200 }
00201 break;
00202
00203 case 8:
00204 for (i=0; i<dstW; i++) {
00205 register int srcPos = filterPos[i];
00206
00207 vector unsigned char src_v0 = vec_ld(srcPos, src);
00208 vector unsigned char src_v1, src_vF;
00209 vector signed short src_v, filter_v;
00210 vector signed int val_v, val_s;
00211 if ((((uintptr_t)src + srcPos) % 16) > 8) {
00212 src_v1 = vec_ld(srcPos + 16, src);
00213 }
00214 src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
00215
00216 src_v =
00217 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00218 filter_v = vec_ld(i << 4, filter);
00219
00220
00221 val_v = vec_msums(src_v, filter_v, (vector signed int)vzero);
00222 val_s = vec_sums(val_v, vzero);
00223 vec_st(val_s, 0, tempo);
00224 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1);
00225 }
00226 break;
00227
00228 case 16:
00229 for (i=0; i<dstW; i++) {
00230 register int srcPos = filterPos[i];
00231
00232 vector unsigned char src_v0 = vec_ld(srcPos, src);
00233 vector unsigned char src_v1 = vec_ld(srcPos + 16, src);
00234 vector unsigned char src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src));
00235
00236 vector signed short src_vA =
00237 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00238 vector signed short src_vB =
00239 (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF));
00240
00241 vector signed short filter_v0 = vec_ld(i << 5, filter);
00242 vector signed short filter_v1 = vec_ld((i << 5) + 16, filter);
00243
00244
00245 vector signed int val_acc = vec_msums(src_vA, filter_v0, (vector signed int)vzero);
00246 vector signed int val_v = vec_msums(src_vB, filter_v1, val_acc);
00247
00248 vector signed int val_s = vec_sums(val_v, vzero);
00249
00250 vec_st(val_s, 0, tempo);
00251 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1);
00252 }
00253 break;
00254
00255 default:
00256 for (i=0; i<dstW; i++) {
00257 register int j;
00258 register int srcPos = filterPos[i];
00259
00260 vector signed int val_s, val_v = (vector signed int)vzero;
00261 vector signed short filter_v0R = vec_ld(i * 2 * filterSize, filter);
00262 vector unsigned char permF = vec_lvsl((i * 2 * filterSize), filter);
00263
00264 vector unsigned char src_v0 = vec_ld(srcPos, src);
00265 vector unsigned char permS = vec_lvsl(srcPos, src);
00266
00267 for (j = 0 ; j < filterSize - 15; j += 16) {
00268 vector unsigned char src_v1 = vec_ld(srcPos + j + 16, src);
00269 vector unsigned char src_vF = vec_perm(src_v0, src_v1, permS);
00270
00271 vector signed short src_vA =
00272 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00273 vector signed short src_vB =
00274 (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF));
00275
00276 vector signed short filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter);
00277 vector signed short filter_v2R = vec_ld((i * 2 * filterSize) + (j * 2) + 32, filter);
00278 vector signed short filter_v0 = vec_perm(filter_v0R, filter_v1R, permF);
00279 vector signed short filter_v1 = vec_perm(filter_v1R, filter_v2R, permF);
00280
00281 vector signed int val_acc = vec_msums(src_vA, filter_v0, val_v);
00282 val_v = vec_msums(src_vB, filter_v1, val_acc);
00283
00284 filter_v0R = filter_v2R;
00285 src_v0 = src_v1;
00286 }
00287
00288 if (j < filterSize-7) {
00289
00290
00291 vector unsigned char src_v1, src_vF;
00292 vector signed short src_v, filter_v1R, filter_v;
00293 if ((((uintptr_t)src + srcPos) % 16) > 8) {
00294 src_v1 = vec_ld(srcPos + j + 16, src);
00295 }
00296 src_vF = vec_perm(src_v0, src_v1, permS);
00297
00298 src_v =
00299 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF));
00300
00301
00302 filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter);
00303 filter_v = vec_perm(filter_v0R, filter_v1R, permF);
00304
00305 val_v = vec_msums(src_v, filter_v, val_v);
00306 }
00307
00308 val_s = vec_sums(val_v, vzero);
00309
00310 vec_st(val_s, 0, tempo);
00311 dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1);
00312 }
00313
00314 }
00315 }
00316
00317 void ff_sws_init_swScale_altivec(SwsContext *c)
00318 {
00319 enum PixelFormat dstFormat = c->dstFormat;
00320
00321 if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
00322 return;
00323
00324 if (c->srcBpc == 8 && c->dstBpc <= 10) {
00325 c->hyScale = c->hcScale = hScale_altivec_real;
00326 }
00327 if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) &&
00328 dstFormat != PIX_FMT_NV12 && dstFormat != PIX_FMT_NV21 &&
00329 !c->alpPixBuf) {
00330 c->yuv2planeX = yuv2planeX_altivec;
00331 }
00332
00333
00334
00335 if (!(c->flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->alpPixBuf) {
00336 switch (c->dstFormat) {
00337 case PIX_FMT_ABGR: c->yuv2packedX = ff_yuv2abgr_X_altivec; break;
00338 case PIX_FMT_BGRA: c->yuv2packedX = ff_yuv2bgra_X_altivec; break;
00339 case PIX_FMT_ARGB: c->yuv2packedX = ff_yuv2argb_X_altivec; break;
00340 case PIX_FMT_RGBA: c->yuv2packedX = ff_yuv2rgba_X_altivec; break;
00341 case PIX_FMT_BGR24: c->yuv2packedX = ff_yuv2bgr24_X_altivec; break;
00342 case PIX_FMT_RGB24: c->yuv2packedX = ff_yuv2rgb24_X_altivec; break;
00343 }
00344 }
00345 }