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