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