50 #define BITS_FRW_ACC 3 //; 2 or 3 for accuracy
51 #define SHIFT_FRW_COL BITS_FRW_ACC
52 #define SHIFT_FRW_ROW (BITS_FRW_ACC + 17 - 3)
53 #define RND_FRW_ROW (1 << (SHIFT_FRW_ROW-1))
56 #define X8(x) x,x,x,x,x,x,x,x
69 DECLARE_ALIGNED(16,
static const int16_t, fdct_one_corr)[8] = { X8(1) };
83 16384, 16384, 22725, 19266,
84 16384, 16384, 12873, 4520,
85 21407, 8867, 19266, -4520,
86 -8867, -21407, -22725, -12873,
87 16384, -16384, 12873, -22725,
88 -16384, 16384, 4520, 19266,
89 8867, -21407, 4520, -12873,
90 21407, -8867, 19266, -22725,
92 22725, 22725, 31521, 26722,
93 22725, 22725, 17855, 6270,
94 29692, 12299, 26722, -6270,
95 -12299, -29692, -31521, -17855,
96 22725, -22725, 17855, -31521,
97 -22725, 22725, 6270, 26722,
98 12299, -29692, 6270, -17855,
99 29692, -12299, 26722, -31521,
101 21407, 21407, 29692, 25172,
102 21407, 21407, 16819, 5906,
103 27969, 11585, 25172, -5906,
104 -11585, -27969, -29692, -16819,
105 21407, -21407, 16819, -29692,
106 -21407, 21407, 5906, 25172,
107 11585, -27969, 5906, -16819,
108 27969, -11585, 25172, -29692,
110 19266, 19266, 26722, 22654,
111 19266, 19266, 15137, 5315,
112 25172, 10426, 22654, -5315,
113 -10426, -25172, -26722, -15137,
114 19266, -19266, 15137, -26722,
115 -19266, 19266, 5315, 22654,
116 10426, -25172, 5315, -15137,
117 25172, -10426, 22654, -26722,
119 16384, 16384, 22725, 19266,
120 16384, 16384, 12873, 4520,
121 21407, 8867, 19266, -4520,
122 -8867, -21407, -22725, -12873,
123 16384, -16384, 12873, -22725,
124 -16384, 16384, 4520, 19266,
125 8867, -21407, 4520, -12873,
126 21407, -8867, 19266, -22725,
128 19266, 19266, 26722, 22654,
129 19266, 19266, 15137, 5315,
130 25172, 10426, 22654, -5315,
131 -10426, -25172, -26722, -15137,
132 19266, -19266, 15137, -26722,
133 -19266, 19266, 5315, 22654,
134 10426, -25172, 5315, -15137,
135 25172, -10426, 22654, -26722,
137 21407, 21407, 29692, 25172,
138 21407, 21407, 16819, 5906,
139 27969, 11585, 25172, -5906,
140 -11585, -27969, -29692, -16819,
141 21407, -21407, 16819, -29692,
142 -21407, 21407, 5906, 25172,
143 11585, -27969, 5906, -16819,
144 27969, -11585, 25172, -29692,
146 22725, 22725, 31521, 26722,
147 22725, 22725, 17855, 6270,
148 29692, 12299, 26722, -6270,
149 -12299, -29692, -31521, -17855,
150 22725, -22725, 17855, -31521,
151 -22725, 22725, 6270, 26722,
152 12299, -29692, 6270, -17855,
153 29692, -12299, 26722, -31521,
159 } tab_frw_01234567_sse2 =
162 #define TABLE_SSE2 C4, C4, C1, C3, -C6, -C2, -C1, -C5, \
163 C4, C4, C5, C7, C2, C6, C3, -C7, \
164 -C4, C4, C7, C3, C6, -C2, C7, -C5, \
165 C4, -C4, C5, -C1, C2, -C6, C3, -C1,
289 #define S(s) AV_TOSTRING(s) //AV_STRINGIFY is too long
291 #define FDCT_COL(cpu, mm, mov)\
292 static av_always_inline void fdct_col_##cpu(const int16_t *in, int16_t *out, int offset)\
295 #mov" 16(%0), %%"#mm"0 \n\t" \
296 #mov" 96(%0), %%"#mm"1 \n\t" \
297 #mov" %%"#mm"0, %%"#mm"2 \n\t" \
298 #mov" 32(%0), %%"#mm"3 \n\t" \
299 "paddsw %%"#mm"1, %%"#mm"0 \n\t" \
300 #mov" 80(%0), %%"#mm"4 \n\t" \
301 "psllw $"S(SHIFT_FRW_COL)", %%"#mm"0 \n\t" \
302 #mov" (%0), %%"#mm"5 \n\t" \
303 "paddsw %%"#mm"3, %%"#mm"4 \n\t" \
304 "paddsw 112(%0), %%"#mm"5 \n\t" \
305 "psllw $"S(SHIFT_FRW_COL)", %%"#mm"4 \n\t" \
306 #mov" %%"#mm"0, %%"#mm"6 \n\t" \
307 "psubsw %%"#mm"1, %%"#mm"2 \n\t" \
308 #mov" 16(%1), %%"#mm"1 \n\t" \
309 "psubsw %%"#mm"4, %%"#mm"0 \n\t" \
310 #mov" 48(%0), %%"#mm"7 \n\t" \
311 "pmulhw %%"#mm"0, %%"#mm"1 \n\t" \
312 "paddsw 64(%0), %%"#mm"7 \n\t" \
313 "psllw $"S(SHIFT_FRW_COL)", %%"#mm"5 \n\t" \
314 "paddsw %%"#mm"4, %%"#mm"6 \n\t" \
315 "psllw $"S(SHIFT_FRW_COL)", %%"#mm"7 \n\t" \
316 #mov" %%"#mm"5, %%"#mm"4 \n\t" \
317 "psubsw %%"#mm"7, %%"#mm"5 \n\t" \
318 "paddsw %%"#mm"5, %%"#mm"1 \n\t" \
319 "paddsw %%"#mm"7, %%"#mm"4 \n\t" \
320 "por (%2), %%"#mm"1 \n\t" \
321 "psllw $"S(SHIFT_FRW_COL)"+1, %%"#mm"2 \n\t" \
322 "pmulhw 16(%1), %%"#mm"5 \n\t" \
323 #mov" %%"#mm"4, %%"#mm"7 \n\t" \
324 "psubsw 80(%0), %%"#mm"3 \n\t" \
325 "psubsw %%"#mm"6, %%"#mm"4 \n\t" \
326 #mov" %%"#mm"1, 32(%3) \n\t" \
327 "paddsw %%"#mm"6, %%"#mm"7 \n\t" \
328 #mov" 48(%0), %%"#mm"1 \n\t" \
329 "psllw $"S(SHIFT_FRW_COL)"+1, %%"#mm"3 \n\t" \
330 "psubsw 64(%0), %%"#mm"1 \n\t" \
331 #mov" %%"#mm"2, %%"#mm"6 \n\t" \
332 #mov" %%"#mm"4, 64(%3) \n\t" \
333 "paddsw %%"#mm"3, %%"#mm"2 \n\t" \
334 "pmulhw (%4), %%"#mm"2 \n\t" \
335 "psubsw %%"#mm"3, %%"#mm"6 \n\t" \
336 "pmulhw (%4), %%"#mm"6 \n\t" \
337 "psubsw %%"#mm"0, %%"#mm"5 \n\t" \
338 "por (%2), %%"#mm"5 \n\t" \
339 "psllw $"S(SHIFT_FRW_COL)", %%"#mm"1 \n\t" \
340 "por (%2), %%"#mm"2 \n\t" \
341 #mov" %%"#mm"1, %%"#mm"4 \n\t" \
342 #mov" (%0), %%"#mm"3 \n\t" \
343 "paddsw %%"#mm"6, %%"#mm"1 \n\t" \
344 "psubsw 112(%0), %%"#mm"3 \n\t" \
345 "psubsw %%"#mm"6, %%"#mm"4 \n\t" \
346 #mov" (%1), %%"#mm"0 \n\t" \
347 "psllw $"S(SHIFT_FRW_COL)", %%"#mm"3 \n\t" \
348 #mov" 32(%1), %%"#mm"6 \n\t" \
349 "pmulhw %%"#mm"1, %%"#mm"0 \n\t" \
350 #mov" %%"#mm"7, (%3) \n\t" \
351 "pmulhw %%"#mm"4, %%"#mm"6 \n\t" \
352 #mov" %%"#mm"5, 96(%3) \n\t" \
353 #mov" %%"#mm"3, %%"#mm"7 \n\t" \
354 #mov" 32(%1), %%"#mm"5 \n\t" \
355 "psubsw %%"#mm"2, %%"#mm"7 \n\t" \
356 "paddsw %%"#mm"2, %%"#mm"3 \n\t" \
357 "pmulhw %%"#mm"7, %%"#mm"5 \n\t" \
358 "paddsw %%"#mm"3, %%"#mm"0 \n\t" \
359 "paddsw %%"#mm"4, %%"#mm"6 \n\t" \
360 "pmulhw (%1), %%"#mm"3 \n\t" \
361 "por (%2), %%"#mm"0 \n\t" \
362 "paddsw %%"#mm"7, %%"#mm"5 \n\t" \
363 "psubsw %%"#mm"6, %%"#mm"7 \n\t" \
364 #mov" %%"#mm"0, 16(%3) \n\t" \
365 "paddsw %%"#mm"4, %%"#mm"5 \n\t" \
366 #mov" %%"#mm"7, 48(%3) \n\t" \
367 "psubsw %%"#mm"1, %%"#mm"3 \n\t" \
368 #mov" %%"#mm"5, 80(%3) \n\t" \
369 #mov" %%"#mm"3, 112(%3) \n\t" \
371 : "r" (in + offset), "r" (fdct_tg_all_16), "r" (fdct_one_corr), \
372 "r" (out + offset), "r" (ocos_4_16)); \
375 FDCT_COL(mmx, mm, movq)
376 FDCT_COL(sse2, xmm, movdqa)
381 #define FDCT_ROW_SSE2_H1(i,t) \
382 "movq " #i "(%0), %%xmm2 \n\t" \
383 "movq " #i "+8(%0), %%xmm0 \n\t" \
384 "movdqa " #t "+32(%1), %%xmm3 \n\t" \
385 "movdqa " #t "+48(%1), %%xmm7 \n\t" \
386 "movdqa " #t "(%1), %%xmm4 \n\t" \
387 "movdqa " #t "+16(%1), %%xmm5 \n\t"
389 #define FDCT_ROW_SSE2_H2(i,t) \
390 "movq " #i "(%0), %%xmm2 \n\t" \
391 "movq " #i "+8(%0), %%xmm0 \n\t" \
392 "movdqa " #t "+32(%1), %%xmm3 \n\t" \
393 "movdqa " #t "+48(%1), %%xmm7 \n\t"
395 #define FDCT_ROW_SSE2(i) \
396 "movq %%xmm2, %%xmm1 \n\t" \
397 "pshuflw $27, %%xmm0, %%xmm0 \n\t" \
398 "paddsw %%xmm0, %%xmm1 \n\t" \
399 "psubsw %%xmm0, %%xmm2 \n\t" \
400 "punpckldq %%xmm2, %%xmm1 \n\t" \
401 "pshufd $78, %%xmm1, %%xmm2 \n\t" \
402 "pmaddwd %%xmm2, %%xmm3 \n\t" \
403 "pmaddwd %%xmm1, %%xmm7 \n\t" \
404 "pmaddwd %%xmm5, %%xmm2 \n\t" \
405 "pmaddwd %%xmm4, %%xmm1 \n\t" \
406 "paddd %%xmm7, %%xmm3 \n\t" \
407 "paddd %%xmm2, %%xmm1 \n\t" \
408 "paddd %%xmm6, %%xmm3 \n\t" \
409 "paddd %%xmm6, %%xmm1 \n\t" \
410 "psrad %3, %%xmm3 \n\t" \
411 "psrad %3, %%xmm1 \n\t" \
412 "packssdw %%xmm3, %%xmm1 \n\t" \
413 "movdqa %%xmm1, " #i "(%4) \n\t"
415 "movdqa (%2), %%xmm6 \n\t"
416 FDCT_ROW_SSE2_H1(0,0)
418 FDCT_ROW_SSE2_H2(64,0)
421 FDCT_ROW_SSE2_H1(16,64)
423 FDCT_ROW_SSE2_H2(112,64)
426 FDCT_ROW_SSE2_H1(32,128)
428 FDCT_ROW_SSE2_H2(96,128)
431 FDCT_ROW_SSE2_H1(48,192)
433 FDCT_ROW_SSE2_H2(80,192)
436 : "
r" (in), "
r" (tab_frw_01234567_sse2.tab_frw_01234567_sse2),
439 "%xmm4", "%xmm5", "%xmm6", "%xmm7")
443 static
av_always_inline void fdct_row_mmxext(const int16_t *in, int16_t *out,
444 const int16_t *
table)
447 "pshufw $0x1B, 8(%0), %%mm5 \n\t"
448 "movq (%0), %%mm0 \n\t"
449 "movq %%mm0, %%mm1 \n\t"
450 "paddsw %%mm5, %%mm0 \n\t"
451 "psubsw %%mm5, %%mm1 \n\t"
452 "movq %%mm0, %%mm2 \n\t"
453 "punpckldq %%mm1, %%mm0 \n\t"
454 "punpckhdq %%mm1, %%mm2 \n\t"
455 "movq (%1), %%mm1 \n\t"
456 "movq 8(%1), %%mm3 \n\t"
457 "movq 16(%1), %%mm4 \n\t"
458 "movq 24(%1), %%mm5 \n\t"
459 "movq 32(%1), %%mm6 \n\t"
460 "movq 40(%1), %%mm7 \n\t"
461 "pmaddwd %%mm0, %%mm1 \n\t"
462 "pmaddwd %%mm2, %%mm3 \n\t"
463 "pmaddwd %%mm0, %%mm4 \n\t"
464 "pmaddwd %%mm2, %%mm5 \n\t"
465 "pmaddwd %%mm0, %%mm6 \n\t"
466 "pmaddwd %%mm2, %%mm7 \n\t"
467 "pmaddwd 48(%1), %%mm0 \n\t"
468 "pmaddwd 56(%1), %%mm2 \n\t"
469 "paddd %%mm1, %%mm3 \n\t"
470 "paddd %%mm4, %%mm5 \n\t"
471 "paddd %%mm6, %%mm7 \n\t"
472 "paddd %%mm0, %%mm2 \n\t"
473 "movq (%2), %%mm0 \n\t"
474 "paddd %%mm0, %%mm3 \n\t"
475 "paddd %%mm0, %%mm5 \n\t"
476 "paddd %%mm0, %%mm7 \n\t"
477 "paddd %%mm0, %%mm2 \n\t"
478 "psrad $"S(SHIFT_FRW_ROW)
", %%mm3 \n\t"
479 "psrad $"S(SHIFT_FRW_ROW)
", %%mm5 \n\t"
480 "psrad $"S(SHIFT_FRW_ROW)
", %%mm7 \n\t"
481 "psrad $"S(SHIFT_FRW_ROW)
", %%mm2 \n\t"
482 "packssdw %%mm5, %%mm3 \n\t"
483 "packssdw %%mm2, %%mm7 \n\t"
484 "movq %%mm3, (%3) \n\t"
485 "movq %%mm7, 8(%3) \n\t"
487 :
"r" (
in),
"r" (table),
"r" (fdct_r_row),
"r" (out));
490 static av_always_inline void fdct_row_mmx(
const int16_t *in, int16_t *out,
const int16_t *table)
494 "movd 12(%0), %%mm1 \n\t"
495 "punpcklwd 8(%0), %%mm1 \n\t"
496 "movq %%mm1, %%mm2 \n\t"
497 "psrlq $0x20, %%mm1 \n\t"
498 "movq 0(%0), %%mm0 \n\t"
499 "punpcklwd %%mm2, %%mm1 \n\t"
500 "movq %%mm0, %%mm5 \n\t"
501 "paddsw %%mm1, %%mm0 \n\t"
502 "psubsw %%mm1, %%mm5 \n\t"
503 "movq %%mm0, %%mm2 \n\t"
504 "punpckldq %%mm5, %%mm0 \n\t"
505 "punpckhdq %%mm5, %%mm2 \n\t"
506 "movq 0(%1), %%mm1 \n\t"
507 "movq 8(%1), %%mm3 \n\t"
508 "movq 16(%1), %%mm4 \n\t"
509 "movq 24(%1), %%mm5 \n\t"
510 "movq 32(%1), %%mm6 \n\t"
511 "movq 40(%1), %%mm7 \n\t"
512 "pmaddwd %%mm0, %%mm1 \n\t"
513 "pmaddwd %%mm2, %%mm3 \n\t"
514 "pmaddwd %%mm0, %%mm4 \n\t"
515 "pmaddwd %%mm2, %%mm5 \n\t"
516 "pmaddwd %%mm0, %%mm6 \n\t"
517 "pmaddwd %%mm2, %%mm7 \n\t"
518 "pmaddwd 48(%1), %%mm0 \n\t"
519 "pmaddwd 56(%1), %%mm2 \n\t"
520 "paddd %%mm1, %%mm3 \n\t"
521 "paddd %%mm4, %%mm5 \n\t"
522 "paddd %%mm6, %%mm7 \n\t"
523 "paddd %%mm0, %%mm2 \n\t"
524 "movq (%2), %%mm0 \n\t"
525 "paddd %%mm0, %%mm3 \n\t"
526 "paddd %%mm0, %%mm5 \n\t"
527 "paddd %%mm0, %%mm7 \n\t"
528 "paddd %%mm0, %%mm2 \n\t"
529 "psrad $"S(SHIFT_FRW_ROW)
", %%mm3 \n\t"
530 "psrad $"S(SHIFT_FRW_ROW)
", %%mm5 \n\t"
531 "psrad $"S(SHIFT_FRW_ROW)
", %%mm7 \n\t"
532 "psrad $"S(SHIFT_FRW_ROW)
", %%mm2 \n\t"
533 "packssdw %%mm5, %%mm3 \n\t"
534 "packssdw %%mm2, %%mm7 \n\t"
535 "movq %%mm3, 0(%3) \n\t"
536 "movq %%mm7, 8(%3) \n\t"
538 :
"r" (
in),
"r" (table),
"r" (fdct_r_row),
"r" (out));
544 int16_t *
block1= (int16_t*)align_tmp;
545 const int16_t *table= tab_frw_01234567;
548 fdct_col_mmx(block, block1, 0);
549 fdct_col_mmx(block, block1, 4);
552 fdct_row_mmx(block1, block, table);
561 #if HAVE_MMXEXT_INLINE
566 int16_t *block1= (int16_t*)align_tmp;
567 const int16_t *table= tab_frw_01234567;
570 fdct_col_mmx(block, block1, 0);
571 fdct_col_mmx(block, block1, 4);
574 fdct_row_mmxext(block1, block, table);
588 int16_t *
const block1= (int16_t*)align_tmp;
590 fdct_col_sse2(block, block1, 0);
591 fdct_row_sse2(block1, block);
void ff_fdct_mmxext(int16_t *block)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static const uint16_t table[]
void ff_fdct_sse2(int16_t *block)
void ff_fdct_mmx(int16_t *block)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define XMM_CLOBBERS_ONLY(...)
common internal and external API header
static int16_t block1[64]