00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "../common.h"
00017 #include "../dsputil.h"
00018 #include "mmx.h"
00019
00020 #define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align)))
00021
00023
00024
00025
00026
00027
00028
00029
00030
00032
00033 #define BITS_FRW_ACC 3 //; 2 or 3 for accuracy
00034 #define SHIFT_FRW_COL BITS_FRW_ACC
00035 #define SHIFT_FRW_ROW (BITS_FRW_ACC + 17 - 3)
00036 #define RND_FRW_ROW (1 << (SHIFT_FRW_ROW-1))
00037
00038
00039
00040 static const int16_t fdct_tg_all_16[] ATTR_ALIGN(8) = {
00041 13036, 13036, 13036, 13036,
00042 27146, 27146, 27146, 27146,
00043 -21746, -21746, -21746, -21746,
00044 };
00045
00046 static const int16_t ocos_4_16[4] ATTR_ALIGN(8) = {
00047 23170, 23170, 23170, 23170,
00048 };
00049
00050 static const int64_t fdct_one_corr ATTR_ALIGN(8) = 0x0001000100010001LL;
00051
00052 static const int32_t fdct_r_row[2] ATTR_ALIGN(8) = {RND_FRW_ROW, RND_FRW_ROW };
00053
00054 struct
00055 {
00056 const int32_t fdct_r_row_sse2[4] ATTR_ALIGN(16);
00057 } fdct_r_row_sse2 ATTR_ALIGN(16)=
00058 {{
00059 RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW
00060 }};
00061
00062
00063 static const int16_t tab_frw_01234567[] ATTR_ALIGN(8) = {
00064 16384, 16384, 22725, 19266,
00065 16384, 16384, 12873, 4520,
00066 21407, 8867, 19266, -4520,
00067 -8867, -21407, -22725, -12873,
00068 16384, -16384, 12873, -22725,
00069 -16384, 16384, 4520, 19266,
00070 8867, -21407, 4520, -12873,
00071 21407, -8867, 19266, -22725,
00072
00073 22725, 22725, 31521, 26722,
00074 22725, 22725, 17855, 6270,
00075 29692, 12299, 26722, -6270,
00076 -12299, -29692, -31521, -17855,
00077 22725, -22725, 17855, -31521,
00078 -22725, 22725, 6270, 26722,
00079 12299, -29692, 6270, -17855,
00080 29692, -12299, 26722, -31521,
00081
00082 21407, 21407, 29692, 25172,
00083 21407, 21407, 16819, 5906,
00084 27969, 11585, 25172, -5906,
00085 -11585, -27969, -29692, -16819,
00086 21407, -21407, 16819, -29692,
00087 -21407, 21407, 5906, 25172,
00088 11585, -27969, 5906, -16819,
00089 27969, -11585, 25172, -29692,
00090
00091 19266, 19266, 26722, 22654,
00092 19266, 19266, 15137, 5315,
00093 25172, 10426, 22654, -5315,
00094 -10426, -25172, -26722, -15137,
00095 19266, -19266, 15137, -26722,
00096 -19266, 19266, 5315, 22654,
00097 10426, -25172, 5315, -15137,
00098 25172, -10426, 22654, -26722,
00099
00100 16384, 16384, 22725, 19266,
00101 16384, 16384, 12873, 4520,
00102 21407, 8867, 19266, -4520,
00103 -8867, -21407, -22725, -12873,
00104 16384, -16384, 12873, -22725,
00105 -16384, 16384, 4520, 19266,
00106 8867, -21407, 4520, -12873,
00107 21407, -8867, 19266, -22725,
00108
00109 19266, 19266, 26722, 22654,
00110 19266, 19266, 15137, 5315,
00111 25172, 10426, 22654, -5315,
00112 -10426, -25172, -26722, -15137,
00113 19266, -19266, 15137, -26722,
00114 -19266, 19266, 5315, 22654,
00115 10426, -25172, 5315, -15137,
00116 25172, -10426, 22654, -26722,
00117
00118 21407, 21407, 29692, 25172,
00119 21407, 21407, 16819, 5906,
00120 27969, 11585, 25172, -5906,
00121 -11585, -27969, -29692, -16819,
00122 21407, -21407, 16819, -29692,
00123 -21407, 21407, 5906, 25172,
00124 11585, -27969, 5906, -16819,
00125 27969, -11585, 25172, -29692,
00126
00127 22725, 22725, 31521, 26722,
00128 22725, 22725, 17855, 6270,
00129 29692, 12299, 26722, -6270,
00130 -12299, -29692, -31521, -17855,
00131 22725, -22725, 17855, -31521,
00132 -22725, 22725, 6270, 26722,
00133 12299, -29692, 6270, -17855,
00134 29692, -12299, 26722, -31521,
00135 };
00136
00137 struct
00138 {
00139 const int16_t tab_frw_01234567_sse2[256] ATTR_ALIGN(16);
00140 } tab_frw_01234567_sse2 ATTR_ALIGN(16) =
00141 {{
00142
00143 #define TABLE_SSE2 C4, C4, C1, C3, -C6, -C2, -C1, -C5, \
00144 C4, C4, C5, C7, C2, C6, C3, -C7, \
00145 -C4, C4, C7, C3, C6, -C2, C7, -C5, \
00146 C4, -C4, C5, -C1, C2, -C6, C3, -C1,
00147
00148 #define C1 22725
00149 #define C2 21407
00150 #define C3 19266
00151 #define C4 16384
00152 #define C5 12873
00153 #define C6 8867
00154 #define C7 4520
00155 TABLE_SSE2
00156
00157 #undef C1
00158 #undef C2
00159 #undef C3
00160 #undef C4
00161 #undef C5
00162 #undef C6
00163 #undef C7
00164 #define C1 31521
00165 #define C2 29692
00166 #define C3 26722
00167 #define C4 22725
00168 #define C5 17855
00169 #define C6 12299
00170 #define C7 6270
00171 TABLE_SSE2
00172
00173 #undef C1
00174 #undef C2
00175 #undef C3
00176 #undef C4
00177 #undef C5
00178 #undef C6
00179 #undef C7
00180 #define C1 29692
00181 #define C2 27969
00182 #define C3 25172
00183 #define C4 21407
00184 #define C5 16819
00185 #define C6 11585
00186 #define C7 5906
00187 TABLE_SSE2
00188
00189 #undef C1
00190 #undef C2
00191 #undef C3
00192 #undef C4
00193 #undef C5
00194 #undef C6
00195 #undef C7
00196 #define C1 26722
00197 #define C2 25172
00198 #define C3 22654
00199 #define C4 19266
00200 #define C5 15137
00201 #define C6 10426
00202 #define C7 5315
00203 TABLE_SSE2
00204
00205 #undef C1
00206 #undef C2
00207 #undef C3
00208 #undef C4
00209 #undef C5
00210 #undef C6
00211 #undef C7
00212 #define C1 22725
00213 #define C2 21407
00214 #define C3 19266
00215 #define C4 16384
00216 #define C5 12873
00217 #define C6 8867
00218 #define C7 4520
00219 TABLE_SSE2
00220
00221 #undef C1
00222 #undef C2
00223 #undef C3
00224 #undef C4
00225 #undef C5
00226 #undef C6
00227 #undef C7
00228 #define C1 26722
00229 #define C2 25172
00230 #define C3 22654
00231 #define C4 19266
00232 #define C5 15137
00233 #define C6 10426
00234 #define C7 5315
00235 TABLE_SSE2
00236
00237 #undef C1
00238 #undef C2
00239 #undef C3
00240 #undef C4
00241 #undef C5
00242 #undef C6
00243 #undef C7
00244 #define C1 29692
00245 #define C2 27969
00246 #define C3 25172
00247 #define C4 21407
00248 #define C5 16819
00249 #define C6 11585
00250 #define C7 5906
00251 TABLE_SSE2
00252
00253 #undef C1
00254 #undef C2
00255 #undef C3
00256 #undef C4
00257 #undef C5
00258 #undef C6
00259 #undef C7
00260 #define C1 31521
00261 #define C2 29692
00262 #define C3 26722
00263 #define C4 22725
00264 #define C5 17855
00265 #define C6 12299
00266 #define C7 6270
00267 TABLE_SSE2
00268 }};
00269
00270
00271 static always_inline void fdct_col(const int16_t *in, int16_t *out, int offset)
00272 {
00273 movq_m2r(*(in + offset + 1 * 8), mm0);
00274 movq_m2r(*(in + offset + 6 * 8), mm1);
00275 movq_r2r(mm0, mm2);
00276 movq_m2r(*(in + offset + 2 * 8), mm3);
00277 paddsw_r2r(mm1, mm0);
00278 movq_m2r(*(in + offset + 5 * 8), mm4);
00279 psllw_i2r(SHIFT_FRW_COL, mm0);
00280 movq_m2r(*(in + offset + 0 * 8), mm5);
00281 paddsw_r2r(mm3, mm4);
00282 paddsw_m2r(*(in + offset + 7 * 8), mm5);
00283 psllw_i2r(SHIFT_FRW_COL, mm4);
00284 movq_r2r(mm0, mm6);
00285 psubsw_r2r(mm1, mm2);
00286 movq_m2r(*(fdct_tg_all_16 + 4), mm1);
00287 psubsw_r2r(mm4, mm0);
00288 movq_m2r(*(in + offset + 3 * 8), mm7);
00289 pmulhw_r2r(mm0, mm1);
00290 paddsw_m2r(*(in + offset + 4 * 8), mm7);
00291 psllw_i2r(SHIFT_FRW_COL, mm5);
00292 paddsw_r2r(mm4, mm6);
00293 psllw_i2r(SHIFT_FRW_COL, mm7);
00294 movq_r2r(mm5, mm4);
00295 psubsw_r2r(mm7, mm5);
00296 paddsw_r2r(mm5, mm1);
00297 paddsw_r2r(mm7, mm4);
00298 por_m2r(fdct_one_corr, mm1);
00299 psllw_i2r(SHIFT_FRW_COL + 1, mm2);
00300 pmulhw_m2r(*(fdct_tg_all_16 + 4), mm5);
00301 movq_r2r(mm4, mm7);
00302 psubsw_m2r(*(in + offset + 5 * 8), mm3);
00303 psubsw_r2r(mm6, mm4);
00304 movq_r2m(mm1, *(out + offset + 2 * 8));
00305 paddsw_r2r(mm6, mm7);
00306 movq_m2r(*(in + offset + 3 * 8), mm1);
00307 psllw_i2r(SHIFT_FRW_COL + 1, mm3);
00308 psubsw_m2r(*(in + offset + 4 * 8), mm1);
00309 movq_r2r(mm2, mm6);
00310 movq_r2m(mm4, *(out + offset + 4 * 8));
00311 paddsw_r2r(mm3, mm2);
00312 pmulhw_m2r(*ocos_4_16, mm2);
00313 psubsw_r2r(mm3, mm6);
00314 pmulhw_m2r(*ocos_4_16, mm6);
00315 psubsw_r2r(mm0, mm5);
00316 por_m2r(fdct_one_corr, mm5);
00317 psllw_i2r(SHIFT_FRW_COL, mm1);
00318 por_m2r(fdct_one_corr, mm2);
00319 movq_r2r(mm1, mm4);
00320 movq_m2r(*(in + offset + 0 * 8), mm3);
00321 paddsw_r2r(mm6, mm1);
00322 psubsw_m2r(*(in + offset + 7 * 8), mm3);
00323 psubsw_r2r(mm6, mm4);
00324 movq_m2r(*(fdct_tg_all_16 + 0), mm0);
00325 psllw_i2r(SHIFT_FRW_COL, mm3);
00326 movq_m2r(*(fdct_tg_all_16 + 8), mm6);
00327 pmulhw_r2r(mm1, mm0);
00328 movq_r2m(mm7, *(out + offset + 0 * 8));
00329 pmulhw_r2r(mm4, mm6);
00330 movq_r2m(mm5, *(out + offset + 6 * 8));
00331 movq_r2r(mm3, mm7);
00332 movq_m2r(*(fdct_tg_all_16 + 8), mm5);
00333 psubsw_r2r(mm2, mm7);
00334 paddsw_r2r(mm2, mm3);
00335 pmulhw_r2r(mm7, mm5);
00336 paddsw_r2r(mm3, mm0);
00337 paddsw_r2r(mm4, mm6);
00338 pmulhw_m2r(*(fdct_tg_all_16 + 0), mm3);
00339 por_m2r(fdct_one_corr, mm0);
00340 paddsw_r2r(mm7, mm5);
00341 psubsw_r2r(mm6, mm7);
00342 movq_r2m(mm0, *(out + offset + 1 * 8));
00343 paddsw_r2r(mm4, mm5);
00344 movq_r2m(mm7, *(out + offset + 3 * 8));
00345 psubsw_r2r(mm1, mm3);
00346 movq_r2m(mm5, *(out + offset + 5 * 8));
00347 movq_r2m(mm3, *(out + offset + 7 * 8));
00348 }
00349
00350
00351 static always_inline void fdct_row_sse2(const int16_t *in, int16_t *out)
00352 {
00353 asm volatile(
00354 ".macro FDCT_ROW_SSE2_H1 i t \n\t"
00355 "movq \\i(%0), %%xmm2 \n\t"
00356 "movq \\i+8(%0), %%xmm0 \n\t"
00357 "movdqa \\t+32(%1), %%xmm3 \n\t"
00358 "movdqa \\t+48(%1), %%xmm7 \n\t"
00359 "movdqa \\t(%1), %%xmm4 \n\t"
00360 "movdqa \\t+16(%1), %%xmm5 \n\t"
00361 ".endm \n\t"
00362 ".macro FDCT_ROW_SSE2_H2 i t \n\t"
00363 "movq \\i(%0), %%xmm2 \n\t"
00364 "movq \\i+8(%0), %%xmm0 \n\t"
00365 "movdqa \\t+32(%1), %%xmm3 \n\t"
00366 "movdqa \\t+48(%1), %%xmm7 \n\t"
00367 ".endm \n\t"
00368 ".macro FDCT_ROW_SSE2 i \n\t"
00369 "movq %%xmm2, %%xmm1 \n\t"
00370 "pshuflw $27, %%xmm0, %%xmm0 \n\t"
00371 "paddsw %%xmm0, %%xmm1 \n\t"
00372 "psubsw %%xmm0, %%xmm2 \n\t"
00373 "punpckldq %%xmm2, %%xmm1 \n\t"
00374 "pshufd $78, %%xmm1, %%xmm2 \n\t"
00375 "pmaddwd %%xmm2, %%xmm3 \n\t"
00376 "pmaddwd %%xmm1, %%xmm7 \n\t"
00377 "pmaddwd %%xmm5, %%xmm2 \n\t"
00378 "pmaddwd %%xmm4, %%xmm1 \n\t"
00379 "paddd %%xmm7, %%xmm3 \n\t"
00380 "paddd %%xmm2, %%xmm1 \n\t"
00381 "paddd %%xmm6, %%xmm3 \n\t"
00382 "paddd %%xmm6, %%xmm1 \n\t"
00383 "psrad %3, %%xmm3 \n\t"
00384 "psrad %3, %%xmm1 \n\t"
00385 "packssdw %%xmm3, %%xmm1 \n\t"
00386 "movdqa %%xmm1, \\i(%4) \n\t"
00387 ".endm \n\t"
00388 "movdqa (%2), %%xmm6 \n\t"
00389 "FDCT_ROW_SSE2_H1 0 0 \n\t"
00390 "FDCT_ROW_SSE2 0 \n\t"
00391 "FDCT_ROW_SSE2_H2 64 0 \n\t"
00392 "FDCT_ROW_SSE2 64 \n\t"
00393
00394 "FDCT_ROW_SSE2_H1 16 64 \n\t"
00395 "FDCT_ROW_SSE2 16 \n\t"
00396 "FDCT_ROW_SSE2_H2 112 64 \n\t"
00397 "FDCT_ROW_SSE2 112 \n\t"
00398
00399 "FDCT_ROW_SSE2_H1 32 128 \n\t"
00400 "FDCT_ROW_SSE2 32 \n\t"
00401 "FDCT_ROW_SSE2_H2 96 128 \n\t"
00402 "FDCT_ROW_SSE2 96 \n\t"
00403
00404 "FDCT_ROW_SSE2_H1 48 192 \n\t"
00405 "FDCT_ROW_SSE2 48 \n\t"
00406 "FDCT_ROW_SSE2_H2 80 192 \n\t"
00407 "FDCT_ROW_SSE2 80 \n\t"
00408 :
00409 : "r" (in), "r" (tab_frw_01234567_sse2.tab_frw_01234567_sse2), "r" (fdct_r_row_sse2.fdct_r_row_sse2), "i" (SHIFT_FRW_ROW), "r" (out)
00410 );
00411 }
00412
00413 static always_inline void fdct_row_mmx2(const int16_t *in, int16_t *out, const int16_t *table)
00414 {
00415 pshufw_m2r(*(in + 4), mm5, 0x1B);
00416 movq_m2r(*(in + 0), mm0);
00417 movq_r2r(mm0, mm1);
00418 paddsw_r2r(mm5, mm0);
00419 psubsw_r2r(mm5, mm1);
00420 movq_r2r(mm0, mm2);
00421 punpckldq_r2r(mm1, mm0);
00422 punpckhdq_r2r(mm1, mm2);
00423 movq_m2r(*(table + 0), mm1);
00424 movq_m2r(*(table + 4), mm3);
00425 movq_m2r(*(table + 8), mm4);
00426 movq_m2r(*(table + 12), mm5);
00427 movq_m2r(*(table + 16), mm6);
00428 movq_m2r(*(table + 20), mm7);
00429 pmaddwd_r2r(mm0, mm1);
00430 pmaddwd_r2r(mm2, mm3);
00431 pmaddwd_r2r(mm0, mm4);
00432 pmaddwd_r2r(mm2, mm5);
00433 pmaddwd_r2r(mm0, mm6);
00434 pmaddwd_r2r(mm2, mm7);
00435 pmaddwd_m2r(*(table + 24), mm0);
00436 pmaddwd_m2r(*(table + 28), mm2);
00437 paddd_r2r(mm1, mm3);
00438 paddd_r2r(mm4, mm5);
00439 paddd_r2r(mm6, mm7);
00440 paddd_r2r(mm0, mm2);
00441 movq_m2r(*fdct_r_row, mm0);
00442 paddd_r2r(mm0, mm3);
00443 paddd_r2r(mm0, mm5);
00444 paddd_r2r(mm0, mm7);
00445 paddd_r2r(mm0, mm2);
00446 psrad_i2r(SHIFT_FRW_ROW, mm3);
00447 psrad_i2r(SHIFT_FRW_ROW, mm5);
00448 psrad_i2r(SHIFT_FRW_ROW, mm7);
00449 psrad_i2r(SHIFT_FRW_ROW, mm2);
00450 packssdw_r2r(mm5, mm3);
00451 packssdw_r2r(mm2, mm7);
00452 movq_r2m(mm3, *(out + 0));
00453 movq_r2m(mm7, *(out + 4));
00454 }
00455
00456 static always_inline void fdct_row_mmx(const int16_t *in, int16_t *out, const int16_t *table)
00457 {
00458
00459 movd_m2r(*(in + 6), mm1);
00460 punpcklwd_m2r(*(in + 4), mm1);
00461 movq_r2r(mm1, mm2);
00462 psrlq_i2r(0x20, mm1);
00463 movq_m2r(*(in + 0), mm0);
00464 punpcklwd_r2r(mm2, mm1);
00465 movq_r2r(mm0, mm5);
00466 paddsw_r2r(mm1, mm0);
00467 psubsw_r2r(mm1, mm5);
00468 movq_r2r(mm0, mm2);
00469 punpckldq_r2r(mm5, mm0);
00470 punpckhdq_r2r(mm5, mm2);
00471 movq_m2r(*(table + 0), mm1);
00472 movq_m2r(*(table + 4), mm3);
00473 movq_m2r(*(table + 8), mm4);
00474 movq_m2r(*(table + 12), mm5);
00475 movq_m2r(*(table + 16), mm6);
00476 movq_m2r(*(table + 20), mm7);
00477 pmaddwd_r2r(mm0, mm1);
00478 pmaddwd_r2r(mm2, mm3);
00479 pmaddwd_r2r(mm0, mm4);
00480 pmaddwd_r2r(mm2, mm5);
00481 pmaddwd_r2r(mm0, mm6);
00482 pmaddwd_r2r(mm2, mm7);
00483 pmaddwd_m2r(*(table + 24), mm0);
00484 pmaddwd_m2r(*(table + 28), mm2);
00485 paddd_r2r(mm1, mm3);
00486 paddd_r2r(mm4, mm5);
00487 paddd_r2r(mm6, mm7);
00488 paddd_r2r(mm0, mm2);
00489 movq_m2r(*fdct_r_row, mm0);
00490 paddd_r2r(mm0, mm3);
00491 paddd_r2r(mm0, mm5);
00492 paddd_r2r(mm0, mm7);
00493 paddd_r2r(mm0, mm2);
00494 psrad_i2r(SHIFT_FRW_ROW, mm3);
00495 psrad_i2r(SHIFT_FRW_ROW, mm5);
00496 psrad_i2r(SHIFT_FRW_ROW, mm7);
00497 psrad_i2r(SHIFT_FRW_ROW, mm2);
00498 packssdw_r2r(mm5, mm3);
00499 packssdw_r2r(mm2, mm7);
00500 movq_r2m(mm3, *(out + 0));
00501 movq_r2m(mm7, *(out + 4));
00502 }
00503
00504 void ff_fdct_mmx(int16_t *block)
00505 {
00506 int64_t align_tmp[16] ATTR_ALIGN(8);
00507 int16_t * const block_tmp= (int16_t*)align_tmp;
00508 int16_t *block1, *out;
00509 const int16_t *table;
00510 int i;
00511
00512 block1 = block_tmp;
00513 fdct_col(block, block1, 0);
00514 fdct_col(block, block1, 4);
00515
00516 block1 = block_tmp;
00517 table = tab_frw_01234567;
00518 out = block;
00519 for(i=8;i>0;i--) {
00520 fdct_row_mmx(block1, out, table);
00521 block1 += 8;
00522 table += 32;
00523 out += 8;
00524 }
00525 }
00526
00527 void ff_fdct_mmx2(int16_t *block)
00528 {
00529 int64_t align_tmp[16] ATTR_ALIGN(8);
00530 int16_t * const block_tmp= (int16_t*)align_tmp;
00531 int16_t *block1, *out;
00532 const int16_t *table;
00533 int i;
00534
00535 block1 = block_tmp;
00536 fdct_col(block, block1, 0);
00537 fdct_col(block, block1, 4);
00538
00539 block1 = block_tmp;
00540 table = tab_frw_01234567;
00541 out = block;
00542 for(i=8;i>0;i--) {
00543 fdct_row_mmx2(block1, out, table);
00544 block1 += 8;
00545 table += 32;
00546 out += 8;
00547 }
00548 }
00549
00550 void ff_fdct_sse2(int16_t *block)
00551 {
00552 int64_t align_tmp[16] ATTR_ALIGN(8);
00553 int16_t * const block_tmp= (int16_t*)align_tmp;
00554 int16_t *block1;
00555
00556 block1 = block_tmp;
00557 fdct_col(block, block1, 0);
00558 fdct_col(block, block1, 4);
00559
00560 fdct_row_sse2(block1, block);
00561 }
00562