00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "config.h"
00022 #if HAVE_ALTIVEC_H
00023 #include <altivec.h>
00024 #endif
00025 #include "libavutil/common.h"
00026 #include "libavcodec/dsputil.h"
00027 #include "dsputil_ppc.h"
00028 #include "dsputil_altivec.h"
00029
00030 #define vs16(v) ((vector signed short)(v))
00031 #define vs32(v) ((vector signed int)(v))
00032 #define vu8(v) ((vector unsigned char)(v))
00033 #define vu16(v) ((vector unsigned short)(v))
00034 #define vu32(v) ((vector unsigned int)(v))
00035
00036
00037 #define C1 0.98078525066375732421875000
00038 #define C2 0.92387950420379638671875000
00039 #define C3 0.83146959543228149414062500
00040 #define C4 0.70710676908493041992187500
00041 #define C5 0.55557024478912353515625000
00042 #define C6 0.38268342614173889160156250
00043 #define C7 0.19509032368659973144531250
00044 #define SQRT_2 1.41421353816986083984375000
00045
00046
00047 #define W0 -(2 * C2)
00048 #define W1 (2 * C6)
00049 #define W2 (SQRT_2 * C6)
00050 #define W3 (SQRT_2 * C3)
00051 #define W4 (SQRT_2 * (-C1 + C3 + C5 - C7))
00052 #define W5 (SQRT_2 * ( C1 + C3 - C5 + C7))
00053 #define W6 (SQRT_2 * ( C1 + C3 + C5 - C7))
00054 #define W7 (SQRT_2 * ( C1 + C3 - C5 - C7))
00055 #define W8 (SQRT_2 * ( C7 - C3))
00056 #define W9 (SQRT_2 * (-C1 - C3))
00057 #define WA (SQRT_2 * (-C3 - C5))
00058 #define WB (SQRT_2 * ( C5 - C3))
00059
00060
00061 static vector float fdctconsts[3] = {
00062 { W0, W1, W2, W3 },
00063 { W4, W5, W6, W7 },
00064 { W8, W9, WA, WB }
00065 };
00066
00067 #define LD_W0 vec_splat(cnsts0, 0)
00068 #define LD_W1 vec_splat(cnsts0, 1)
00069 #define LD_W2 vec_splat(cnsts0, 2)
00070 #define LD_W3 vec_splat(cnsts0, 3)
00071 #define LD_W4 vec_splat(cnsts1, 0)
00072 #define LD_W5 vec_splat(cnsts1, 1)
00073 #define LD_W6 vec_splat(cnsts1, 2)
00074 #define LD_W7 vec_splat(cnsts1, 3)
00075 #define LD_W8 vec_splat(cnsts2, 0)
00076 #define LD_W9 vec_splat(cnsts2, 1)
00077 #define LD_WA vec_splat(cnsts2, 2)
00078 #define LD_WB vec_splat(cnsts2, 3)
00079
00080
00081 #define FDCTROW(b0,b1,b2,b3,b4,b5,b6,b7) \
00082 x0 = vec_add(b0, b7); \
00083 x7 = vec_sub(b0, b7); \
00084 x1 = vec_add(b1, b6); \
00085 x6 = vec_sub(b1, b6); \
00086 x2 = vec_add(b2, b5); \
00087 x5 = vec_sub(b2, b5); \
00088 x3 = vec_add(b3, b4); \
00089 x4 = vec_sub(b3, b4); \
00090 \
00091 b7 = vec_add(x0, x3); \
00092 b1 = vec_add(x1, x2); \
00093 b0 = vec_add(b7, b1); \
00094 b4 = vec_sub(b7, b1); \
00095 \
00096 b2 = vec_sub(x0, x3); \
00097 b6 = vec_sub(x1, x2); \
00098 b5 = vec_add(b6, b2); \
00099 cnst = LD_W2; \
00100 b5 = vec_madd(cnst, b5, mzero); \
00101 cnst = LD_W1; \
00102 b2 = vec_madd(cnst, b2, b5); \
00103 cnst = LD_W0; \
00104 b6 = vec_madd(cnst, b6, b5); \
00105 \
00106 x0 = vec_add(x4, x7); \
00107 x1 = vec_add(x5, x6); \
00108 x2 = vec_add(x4, x6); \
00109 x3 = vec_add(x5, x7); \
00110 x8 = vec_add(x2, x3); \
00111 cnst = LD_W3; \
00112 x8 = vec_madd(cnst, x8, mzero); \
00113 \
00114 cnst = LD_W8; \
00115 x0 = vec_madd(cnst, x0, mzero); \
00116 cnst = LD_W9; \
00117 x1 = vec_madd(cnst, x1, mzero); \
00118 cnst = LD_WA; \
00119 x2 = vec_madd(cnst, x2, x8); \
00120 cnst = LD_WB; \
00121 x3 = vec_madd(cnst, x3, x8); \
00122 \
00123 cnst = LD_W4; \
00124 b7 = vec_madd(cnst, x4, x0); \
00125 cnst = LD_W5; \
00126 b5 = vec_madd(cnst, x5, x1); \
00127 cnst = LD_W6; \
00128 b3 = vec_madd(cnst, x6, x1); \
00129 cnst = LD_W7; \
00130 b1 = vec_madd(cnst, x7, x0); \
00131 \
00132 b7 = vec_add(b7, x2); \
00133 b5 = vec_add(b5, x3); \
00134 b3 = vec_add(b3, x2); \
00135 b1 = vec_add(b1, x3); \
00136
00137
00138 #define FDCTCOL(b0,b1,b2,b3,b4,b5,b6,b7) \
00139 x0 = vec_add(b0, b7); \
00140 x7 = vec_sub(b0, b7); \
00141 x1 = vec_add(b1, b6); \
00142 x6 = vec_sub(b1, b6); \
00143 x2 = vec_add(b2, b5); \
00144 x5 = vec_sub(b2, b5); \
00145 x3 = vec_add(b3, b4); \
00146 x4 = vec_sub(b3, b4); \
00147 \
00148 b7 = vec_add(x0, x3); \
00149 b1 = vec_add(x1, x2); \
00150 b0 = vec_add(b7, b1); \
00151 b4 = vec_sub(b7, b1); \
00152 \
00153 b2 = vec_sub(x0, x3); \
00154 b6 = vec_sub(x1, x2); \
00155 b5 = vec_add(b6, b2); \
00156 cnst = LD_W2; \
00157 b5 = vec_madd(cnst, b5, mzero); \
00158 cnst = LD_W1; \
00159 b2 = vec_madd(cnst, b2, b5); \
00160 cnst = LD_W0; \
00161 b6 = vec_madd(cnst, b6, b5); \
00162 \
00163 x0 = vec_add(x4, x7); \
00164 x1 = vec_add(x5, x6); \
00165 x2 = vec_add(x4, x6); \
00166 x3 = vec_add(x5, x7); \
00167 x8 = vec_add(x2, x3); \
00168 cnst = LD_W3; \
00169 x8 = vec_madd(cnst, x8, mzero); \
00170 \
00171 cnst = LD_W8; \
00172 x0 = vec_madd(cnst, x0, mzero); \
00173 cnst = LD_W9; \
00174 x1 = vec_madd(cnst, x1, mzero); \
00175 cnst = LD_WA; \
00176 x2 = vec_madd(cnst, x2, x8); \
00177 cnst = LD_WB; \
00178 x3 = vec_madd(cnst, x3, x8); \
00179 \
00180 cnst = LD_W4; \
00181 b7 = vec_madd(cnst, x4, x0); \
00182 cnst = LD_W5; \
00183 b5 = vec_madd(cnst, x5, x1); \
00184 cnst = LD_W6; \
00185 b3 = vec_madd(cnst, x6, x1); \
00186 cnst = LD_W7; \
00187 b1 = vec_madd(cnst, x7, x0); \
00188 \
00189 b7 = vec_add(b7, x2); \
00190 b5 = vec_add(b5, x3); \
00191 b3 = vec_add(b3, x2); \
00192 b1 = vec_add(b1, x3); \
00193
00194
00195
00196
00197
00198
00199 void fdct_altivec(int16_t *block)
00200 {
00201 POWERPC_PERF_DECLARE(altivec_fdct, 1);
00202 vector signed short *bp;
00203 vector float *cp;
00204 vector float b00, b10, b20, b30, b40, b50, b60, b70;
00205 vector float b01, b11, b21, b31, b41, b51, b61, b71;
00206 vector float mzero, cnst, cnsts0, cnsts1, cnsts2;
00207 vector float x0, x1, x2, x3, x4, x5, x6, x7, x8;
00208
00209 POWERPC_PERF_START_COUNT(altivec_fdct, 1);
00210
00211
00212
00213
00214 mzero = ((vector float)vec_splat_u32(-1));
00215 mzero = ((vector float)vec_sl(vu32(mzero), vu32(mzero)));
00216 cp = fdctconsts;
00217 cnsts0 = vec_ld(0, cp); cp++;
00218 cnsts1 = vec_ld(0, cp); cp++;
00219 cnsts2 = vec_ld(0, cp);
00220
00221
00222
00223
00224 #define MERGE_S16(hl,a,b) vec_merge##hl(vs16(a), vs16(b))
00225
00226 bp = (vector signed short*)block;
00227 b00 = ((vector float)vec_ld(0, bp));
00228 b40 = ((vector float)vec_ld(16*4, bp));
00229 b01 = ((vector float)MERGE_S16(h, b00, b40));
00230 b11 = ((vector float)MERGE_S16(l, b00, b40));
00231 bp++;
00232 b10 = ((vector float)vec_ld(0, bp));
00233 b50 = ((vector float)vec_ld(16*4, bp));
00234 b21 = ((vector float)MERGE_S16(h, b10, b50));
00235 b31 = ((vector float)MERGE_S16(l, b10, b50));
00236 bp++;
00237 b20 = ((vector float)vec_ld(0, bp));
00238 b60 = ((vector float)vec_ld(16*4, bp));
00239 b41 = ((vector float)MERGE_S16(h, b20, b60));
00240 b51 = ((vector float)MERGE_S16(l, b20, b60));
00241 bp++;
00242 b30 = ((vector float)vec_ld(0, bp));
00243 b70 = ((vector float)vec_ld(16*4, bp));
00244 b61 = ((vector float)MERGE_S16(h, b30, b70));
00245 b71 = ((vector float)MERGE_S16(l, b30, b70));
00246
00247 x0 = ((vector float)MERGE_S16(h, b01, b41));
00248 x1 = ((vector float)MERGE_S16(l, b01, b41));
00249 x2 = ((vector float)MERGE_S16(h, b11, b51));
00250 x3 = ((vector float)MERGE_S16(l, b11, b51));
00251 x4 = ((vector float)MERGE_S16(h, b21, b61));
00252 x5 = ((vector float)MERGE_S16(l, b21, b61));
00253 x6 = ((vector float)MERGE_S16(h, b31, b71));
00254 x7 = ((vector float)MERGE_S16(l, b31, b71));
00255
00256 b00 = ((vector float)MERGE_S16(h, x0, x4));
00257 b10 = ((vector float)MERGE_S16(l, x0, x4));
00258 b20 = ((vector float)MERGE_S16(h, x1, x5));
00259 b30 = ((vector float)MERGE_S16(l, x1, x5));
00260 b40 = ((vector float)MERGE_S16(h, x2, x6));
00261 b50 = ((vector float)MERGE_S16(l, x2, x6));
00262 b60 = ((vector float)MERGE_S16(h, x3, x7));
00263 b70 = ((vector float)MERGE_S16(l, x3, x7));
00264
00265 #undef MERGE_S16
00266
00267
00268
00269
00270
00271
00272
00273 #if 1
00274
00275 x0 = ((vector float)vec_add(vs16(b00), vs16(b70)));
00276 x7 = ((vector float)vec_sub(vs16(b00), vs16(b70)));
00277 x1 = ((vector float)vec_add(vs16(b10), vs16(b60)));
00278 x6 = ((vector float)vec_sub(vs16(b10), vs16(b60)));
00279 x2 = ((vector float)vec_add(vs16(b20), vs16(b50)));
00280 x5 = ((vector float)vec_sub(vs16(b20), vs16(b50)));
00281 x3 = ((vector float)vec_add(vs16(b30), vs16(b40)));
00282 x4 = ((vector float)vec_sub(vs16(b30), vs16(b40)));
00283
00284 b70 = ((vector float)vec_add(vs16(x0), vs16(x3)));
00285 b10 = ((vector float)vec_add(vs16(x1), vs16(x2)));
00286
00287 b00 = ((vector float)vec_add(vs16(b70), vs16(b10)));
00288 b40 = ((vector float)vec_sub(vs16(b70), vs16(b10)));
00289
00290 #define CTF0(n) \
00291 b##n##1 = ((vector float)vec_unpackl(vs16(b##n##0))); \
00292 b##n##0 = ((vector float)vec_unpackh(vs16(b##n##0))); \
00293 b##n##1 = vec_ctf(vs32(b##n##1), 0); \
00294 b##n##0 = vec_ctf(vs32(b##n##0), 0);
00295
00296 CTF0(0);
00297 CTF0(4);
00298
00299 b20 = ((vector float)vec_sub(vs16(x0), vs16(x3)));
00300 b60 = ((vector float)vec_sub(vs16(x1), vs16(x2)));
00301
00302 CTF0(2);
00303 CTF0(6);
00304
00305 #undef CTF0
00306
00307 x0 = vec_add(b60, b20);
00308 x1 = vec_add(b61, b21);
00309
00310 cnst = LD_W2;
00311 x0 = vec_madd(cnst, x0, mzero);
00312 x1 = vec_madd(cnst, x1, mzero);
00313 cnst = LD_W1;
00314 b20 = vec_madd(cnst, b20, x0);
00315 b21 = vec_madd(cnst, b21, x1);
00316 cnst = LD_W0;
00317 b60 = vec_madd(cnst, b60, x0);
00318 b61 = vec_madd(cnst, b61, x1);
00319
00320 #define CTFX(x,b) \
00321 b##0 = ((vector float)vec_unpackh(vs16(x))); \
00322 b##1 = ((vector float)vec_unpackl(vs16(x))); \
00323 b##0 = vec_ctf(vs32(b##0), 0); \
00324 b##1 = vec_ctf(vs32(b##1), 0); \
00325
00326 CTFX(x4, b7);
00327 CTFX(x5, b5);
00328 CTFX(x6, b3);
00329 CTFX(x7, b1);
00330
00331 #undef CTFX
00332
00333
00334 x0 = vec_add(b70, b10);
00335 x1 = vec_add(b50, b30);
00336 x2 = vec_add(b70, b30);
00337 x3 = vec_add(b50, b10);
00338 x8 = vec_add(x2, x3);
00339 cnst = LD_W3;
00340 x8 = vec_madd(cnst, x8, mzero);
00341
00342 cnst = LD_W8;
00343 x0 = vec_madd(cnst, x0, mzero);
00344 cnst = LD_W9;
00345 x1 = vec_madd(cnst, x1, mzero);
00346 cnst = LD_WA;
00347 x2 = vec_madd(cnst, x2, x8);
00348 cnst = LD_WB;
00349 x3 = vec_madd(cnst, x3, x8);
00350
00351 cnst = LD_W4;
00352 b70 = vec_madd(cnst, b70, x0);
00353 cnst = LD_W5;
00354 b50 = vec_madd(cnst, b50, x1);
00355 cnst = LD_W6;
00356 b30 = vec_madd(cnst, b30, x1);
00357 cnst = LD_W7;
00358 b10 = vec_madd(cnst, b10, x0);
00359
00360 b70 = vec_add(b70, x2);
00361 b50 = vec_add(b50, x3);
00362 b30 = vec_add(b30, x2);
00363 b10 = vec_add(b10, x3);
00364
00365
00366 x0 = vec_add(b71, b11);
00367 x1 = vec_add(b51, b31);
00368 x2 = vec_add(b71, b31);
00369 x3 = vec_add(b51, b11);
00370 x8 = vec_add(x2, x3);
00371 cnst = LD_W3;
00372 x8 = vec_madd(cnst, x8, mzero);
00373
00374 cnst = LD_W8;
00375 x0 = vec_madd(cnst, x0, mzero);
00376 cnst = LD_W9;
00377 x1 = vec_madd(cnst, x1, mzero);
00378 cnst = LD_WA;
00379 x2 = vec_madd(cnst, x2, x8);
00380 cnst = LD_WB;
00381 x3 = vec_madd(cnst, x3, x8);
00382
00383 cnst = LD_W4;
00384 b71 = vec_madd(cnst, b71, x0);
00385 cnst = LD_W5;
00386 b51 = vec_madd(cnst, b51, x1);
00387 cnst = LD_W6;
00388 b31 = vec_madd(cnst, b31, x1);
00389 cnst = LD_W7;
00390 b11 = vec_madd(cnst, b11, x0);
00391
00392 b71 = vec_add(b71, x2);
00393 b51 = vec_add(b51, x3);
00394 b31 = vec_add(b31, x2);
00395 b11 = vec_add(b11, x3);
00396
00397 #else
00398
00399 #define CTF(n) \
00400 vs32(b##n##1) = vec_unpackl(vs16(b##n##0)); \
00401 vs32(b##n##0) = vec_unpackh(vs16(b##n##0)); \
00402 b##n##1 = vec_ctf(vs32(b##n##1), 0); \
00403 b##n##0 = vec_ctf(vs32(b##n##0), 0); \
00404
00405 CTF(0);
00406 CTF(1);
00407 CTF(2);
00408 CTF(3);
00409 CTF(4);
00410 CTF(5);
00411 CTF(6);
00412 CTF(7);
00413
00414 #undef CTF
00415
00416
00417 FDCTROW(b00, b10, b20, b30, b40, b50, b60, b70);
00418 FDCTROW(b01, b11, b21, b31, b41, b51, b61, b71);
00419 #endif
00420
00421
00422
00423 x0 = vec_mergel(b00, b20);
00424 x1 = vec_mergeh(b00, b20);
00425 x2 = vec_mergel(b10, b30);
00426 x3 = vec_mergeh(b10, b30);
00427
00428 b00 = vec_mergeh(x1, x3);
00429 b10 = vec_mergel(x1, x3);
00430 b20 = vec_mergeh(x0, x2);
00431 b30 = vec_mergel(x0, x2);
00432
00433 x4 = vec_mergel(b41, b61);
00434 x5 = vec_mergeh(b41, b61);
00435 x6 = vec_mergel(b51, b71);
00436 x7 = vec_mergeh(b51, b71);
00437
00438 b41 = vec_mergeh(x5, x7);
00439 b51 = vec_mergel(x5, x7);
00440 b61 = vec_mergeh(x4, x6);
00441 b71 = vec_mergel(x4, x6);
00442
00443 x0 = vec_mergel(b01, b21);
00444 x1 = vec_mergeh(b01, b21);
00445 x2 = vec_mergel(b11, b31);
00446 x3 = vec_mergeh(b11, b31);
00447
00448 x4 = vec_mergel(b40, b60);
00449 x5 = vec_mergeh(b40, b60);
00450 x6 = vec_mergel(b50, b70);
00451 x7 = vec_mergeh(b50, b70);
00452
00453 b40 = vec_mergeh(x1, x3);
00454 b50 = vec_mergel(x1, x3);
00455 b60 = vec_mergeh(x0, x2);
00456 b70 = vec_mergel(x0, x2);
00457
00458 b01 = vec_mergeh(x5, x7);
00459 b11 = vec_mergel(x5, x7);
00460 b21 = vec_mergeh(x4, x6);
00461 b31 = vec_mergel(x4, x6);
00462
00463
00464
00465 FDCTCOL(b00, b10, b20, b30, b40, b50, b60, b70);
00466 FDCTCOL(b01, b11, b21, b31, b41, b51, b61, b71);
00467
00468
00469
00470 #define CTS(n) \
00471 b##n##0 = vec_round(b##n##0); \
00472 b##n##1 = vec_round(b##n##1); \
00473 b##n##0 = ((vector float)vec_cts(b##n##0, 0)); \
00474 b##n##1 = ((vector float)vec_cts(b##n##1, 0)); \
00475 b##n##0 = ((vector float)vec_pack(vs32(b##n##0), vs32(b##n##1))); \
00476 vec_st(vs16(b##n##0), 0, bp);
00477
00478 bp = (vector signed short*)block;
00479 CTS(0); bp++;
00480 CTS(1); bp++;
00481 CTS(2); bp++;
00482 CTS(3); bp++;
00483 CTS(4); bp++;
00484 CTS(5); bp++;
00485 CTS(6); bp++;
00486 CTS(7);
00487
00488 #undef CTS
00489
00490
00491 POWERPC_PERF_STOP_COUNT(altivec_fdct, 1);
00492 }
00493
00494