comparison libmpeg2/idct_mmx.c @ 26393:2506f1b0bdbe

Backport SSE2-optimized IDCT routines from upstream libmpeg2. Thanks to Alexander Strange for finding and fixing some bugs.
author diego
date Sat, 12 Apr 2008 22:42:00 +0000
parents c2276d97cc11
children fd18fa10de53
comparison
equal deleted inserted replaced
26392:f41b913170ea 26393:2506f1b0bdbe
39 #define ROW_SHIFT 15 39 #define ROW_SHIFT 15
40 #define COL_SHIFT 6 40 #define COL_SHIFT 6
41 41
42 #define round(bias) ((int)(((bias)+0.5) * (1<<ROW_SHIFT))) 42 #define round(bias) ((int)(((bias)+0.5) * (1<<ROW_SHIFT)))
43 #define rounder(bias) {round (bias), round (bias)} 43 #define rounder(bias) {round (bias), round (bias)}
44 #define rounder_sse2(bias) {round (bias), round (bias), round (bias), round (bias)}
44 45
45 46
46 #if 0 47 #if 0
47 /* C row IDCT - it is just here to document the MMXEXT and MMX versions */ 48 /* C row IDCT - it is just here to document the MMXEXT and MMX versions */
48 static inline void idct_row (int16_t * row, int offset, 49 static inline void idct_row (int16_t * row, int offset,
81 row[7] = (a0 - b0) >> ROW_SHIFT; 82 row[7] = (a0 - b0) >> ROW_SHIFT;
82 } 83 }
83 #endif 84 #endif
84 85
85 86
87 /* SSE2 row IDCT */
88 #define sse2_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, c4, c6, \
89 c4, -c6, c4, -c2, \
90 c4, c6, -c4, -c2, \
91 -c4, c2, c4, -c6, \
92 c1, c3, c3, -c7, \
93 c5, -c1, c7, -c5, \
94 c5, c7, -c1, -c5, \
95 c7, c3, c3, -c1 }
96
97 #define SSE2_IDCT_2ROW(table, row1, row2, round1, round2) do { \
98 /* no scheduling: trust in out of order execution */ \
99 /* based on Intel AP-945 */ \
100 /* (http://cache-www.intel.com/cd/00/00/01/76/17680_w_idct.pdf) */ \
101 \
102 /* input */ /* 1: row1= x7 x5 x3 x1 x6 x4 x2 x0 */ \
103 pshufd_r2r (row1, xmm1, 0); /* 1: xmm1= x2 x0 x2 x0 x2 x0 x2 x0 */ \
104 pmaddwd_m2r (table[0], xmm1); /* 1: xmm1= x2*C + x0*C ... */ \
105 pshufd_r2r (row1, xmm3, 0xaa); /* 1: xmm3= x3 x1 x3 x1 x3 x1 x3 x1 */ \
106 pmaddwd_m2r (table[2*8], xmm3); /* 1: xmm3= x3*C + x1*C ... */ \
107 pshufd_r2r (row1, xmm2, 0x55); /* 1: xmm2= x6 x4 x6 x4 x6 x4 x6 x4 */ \
108 pshufd_r2r (row1, row1, 0xff); /* 1: row1= x7 x5 x7 x5 x7 x5 x7 x5 */ \
109 pmaddwd_m2r (table[1*8], xmm2); /* 1: xmm2= x6*C + x4*C ... */ \
110 paddd_m2r (round1, xmm1); /* 1: xmm1= x2*C + x0*C + round ... */ \
111 pmaddwd_m2r (table[3*8], row1); /* 1: row1= x7*C + x5*C ... */ \
112 pshufd_r2r (row2, xmm5, 0); /* 2: */ \
113 pshufd_r2r (row2, xmm6, 0x55); /* 2: */ \
114 pmaddwd_m2r (table[0], xmm5); /* 2: */ \
115 paddd_r2r (xmm2, xmm1); /* 1: xmm1= a[] */ \
116 movdqa_r2r (xmm1, xmm2); /* 1: xmm2= a[] */ \
117 pshufd_r2r (row2, xmm7, 0xaa); /* 2: */ \
118 pmaddwd_m2r (table[1*8], xmm6); /* 2: */ \
119 paddd_r2r (xmm3, row1); /* 1: row1= b[]= 7*C+5*C+3*C+1*C ... */ \
120 pshufd_r2r (row2, row2, 0xff); /* 2: */ \
121 psubd_r2r (row1, xmm2); /* 1: xmm2= a[] - b[] */ \
122 pmaddwd_m2r (table[2*8], xmm7); /* 2: */ \
123 paddd_r2r (xmm1, row1); /* 1: row1= a[] + b[] */ \
124 psrad_i2r (ROW_SHIFT, xmm2); /* 1: xmm2= result 4...7 */ \
125 paddd_m2r (round2, xmm5); /* 2: */ \
126 pmaddwd_m2r (table[3*8], row2); /* 2: */ \
127 paddd_r2r (xmm6, xmm5); /* 2: */ \
128 movdqa_r2r (xmm5, xmm6); /* 2: */ \
129 psrad_i2r (ROW_SHIFT, row1); /* 1: row1= result 0...4 */ \
130 pshufd_r2r (xmm2, xmm2, 0x1b); /* 1: [0 1 2 3] -> [3 2 1 0] */ \
131 packssdw_r2r (xmm2, row1); /* 1: row1= result[] */ \
132 paddd_r2r (xmm7, row2); /* 2: */ \
133 psubd_r2r (row2, xmm6); /* 2: */ \
134 paddd_r2r (xmm5, row2); /* 2: */ \
135 psrad_i2r (ROW_SHIFT, xmm6); /* 2: */ \
136 psrad_i2r (ROW_SHIFT, row2); /* 2: */ \
137 pshufd_r2r (xmm6, xmm6, 0x1b); /* 2: */ \
138 packssdw_r2r (xmm6, row2); /* 2: */ \
139 } while (0)
140
141
86 /* MMXEXT row IDCT */ 142 /* MMXEXT row IDCT */
87 143
88 #define mmxext_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, -c4, -c2, \ 144 #define mmxext_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, -c4, -c2, \
89 c4, c6, c4, c6, \ 145 c4, c6, c4, c6, \
90 c1, c3, -c1, -c5, \ 146 c1, c3, -c1, -c5, \
398 col[7*8] = y7; 454 col[7*8] = y7;
399 } 455 }
400 #endif 456 #endif
401 457
402 458
403 /* MMX column IDCT */
404 static inline void idct_col (int16_t * const col, const int offset)
405 {
406 #define T1 13036 459 #define T1 13036
407 #define T2 27146 460 #define T2 27146
408 #define T3 43790 461 #define T3 43790
409 #define C4 23170 462 #define C4 23170
410 463
464
465 /* SSE2 column IDCT */
466 static inline void sse2_idct_col (int16_t * const col)
467 {
468 /* Almost identical to mmxext version: */
469 /* just do both 4x8 columns in paraller */
470
471 static const short t1_vector[] ATTR_ALIGN(16) = {T1,T1,T1,T1,T1,T1,T1,T1};
472 static const short t2_vector[] ATTR_ALIGN(16) = {T2,T2,T2,T2,T2,T2,T2,T2};
473 static const short t3_vector[] ATTR_ALIGN(16) = {T3,T3,T3,T3,T3,T3,T3,T3};
474 static const short c4_vector[] ATTR_ALIGN(16) = {C4,C4,C4,C4,C4,C4,C4,C4};
475
476 #if defined(__x86_64__)
477
478 /* INPUT: block in xmm8 ... xmm15 */
479
480 movdqa_m2r (*t1_vector, xmm0); /* xmm0 = T1 */
481 movdqa_r2r (xmm9, xmm1); /* xmm1 = x1 */
482
483 movdqa_r2r (xmm0, xmm2); /* xmm2 = T1 */
484 pmulhw_r2r (xmm1, xmm0); /* xmm0 = T1*x1 */
485
486 movdqa_m2r (*t3_vector, xmm5); /* xmm5 = T3 */
487 pmulhw_r2r (xmm15, xmm2); /* xmm2 = T1*x7 */
488
489 movdqa_r2r (xmm5, xmm7); /* xmm7 = T3-1 */
490 psubsw_r2r (xmm15, xmm0); /* xmm0 = v17 */
491
492 movdqa_m2r (*t2_vector, xmm9); /* xmm9 = T2 */
493 pmulhw_r2r (xmm11, xmm5); /* xmm5 = (T3-1)*x3 */
494
495 paddsw_r2r (xmm2, xmm1); /* xmm1 = u17 */
496 pmulhw_r2r (xmm13, xmm7); /* xmm7 = (T3-1)*x5 */
497
498 movdqa_r2r (xmm9, xmm2); /* xmm2 = T2 */
499 paddsw_r2r (xmm11, xmm5); /* xmm5 = T3*x3 */
500
501 pmulhw_r2r (xmm10, xmm9); /* xmm9 = T2*x2 */
502 paddsw_r2r (xmm13, xmm7); /* xmm7 = T3*x5 */
503
504 psubsw_r2r (xmm13, xmm5); /* xmm5 = v35 */
505 paddsw_r2r (xmm11, xmm7); /* xmm7 = u35 */
506
507 movdqa_r2r (xmm0, xmm6); /* xmm6 = v17 */
508 pmulhw_r2r (xmm14, xmm2); /* xmm2 = T2*x6 */
509
510 psubsw_r2r (xmm5, xmm0); /* xmm0 = b3 */
511 psubsw_r2r (xmm14, xmm9); /* xmm9 = v26 */
512
513 paddsw_r2r (xmm6, xmm5); /* xmm5 = v12 */
514 movdqa_r2r (xmm0, xmm11); /* xmm11 = b3 */
515
516 movdqa_r2r (xmm1, xmm6); /* xmm6 = u17 */
517 paddsw_r2r (xmm10, xmm2); /* xmm2 = u26 */
518
519 paddsw_r2r (xmm7, xmm6); /* xmm6 = b0 */
520 psubsw_r2r (xmm7, xmm1); /* xmm1 = u12 */
521
522 movdqa_r2r (xmm1, xmm7); /* xmm7 = u12 */
523 paddsw_r2r (xmm5, xmm1); /* xmm1 = u12+v12 */
524
525 movdqa_m2r (*c4_vector, xmm0); /* xmm0 = C4/2 */
526 psubsw_r2r (xmm5, xmm7); /* xmm7 = u12-v12 */
527
528 movdqa_r2r (xmm6, xmm4); /* xmm4 = b0 */
529 pmulhw_r2r (xmm0, xmm1); /* xmm1 = b1/2 */
530
531 movdqa_r2r (xmm9, xmm6); /* xmm6 = v26 */
532 pmulhw_r2r (xmm0, xmm7); /* xmm7 = b2/2 */
533
534 movdqa_r2r (xmm8, xmm10); /* xmm10 = x0 */
535 movdqa_r2r (xmm8, xmm0); /* xmm0 = x0 */
536
537 psubsw_r2r (xmm12, xmm10); /* xmm10 = v04 */
538 paddsw_r2r (xmm12, xmm0); /* xmm0 = u04 */
539
540 paddsw_r2r (xmm10, xmm9); /* xmm9 = a1 */
541 movdqa_r2r (xmm0, xmm8); /* xmm8 = u04 */
542
543 psubsw_r2r (xmm6, xmm10); /* xmm10 = a2 */
544 paddsw_r2r (xmm2, xmm8); /* xmm5 = a0 */
545
546 paddsw_r2r (xmm1, xmm1); /* xmm1 = b1 */
547 psubsw_r2r (xmm2, xmm0); /* xmm0 = a3 */
548
549 paddsw_r2r (xmm7, xmm7); /* xmm7 = b2 */
550 movdqa_r2r (xmm10, xmm13); /* xmm13 = a2 */
551
552 movdqa_r2r (xmm9, xmm14); /* xmm14 = a1 */
553 paddsw_r2r (xmm7, xmm10); /* xmm10 = a2+b2 */
554
555 psraw_i2r (COL_SHIFT,xmm10); /* xmm10 = y2 */
556 paddsw_r2r (xmm1, xmm9); /* xmm9 = a1+b1 */
557
558 psraw_i2r (COL_SHIFT, xmm9); /* xmm9 = y1 */
559 psubsw_r2r (xmm1, xmm14); /* xmm14 = a1-b1 */
560
561 psubsw_r2r (xmm7, xmm13); /* xmm13 = a2-b2 */
562 psraw_i2r (COL_SHIFT,xmm14); /* xmm14 = y6 */
563
564 movdqa_r2r (xmm8, xmm15); /* xmm15 = a0 */
565 psraw_i2r (COL_SHIFT,xmm13); /* xmm13 = y5 */
566
567 paddsw_r2r (xmm4, xmm8); /* xmm8 = a0+b0 */
568 psubsw_r2r (xmm4, xmm15); /* xmm15 = a0-b0 */
569
570 psraw_i2r (COL_SHIFT, xmm8); /* xmm8 = y0 */
571 movdqa_r2r (xmm0, xmm12); /* xmm12 = a3 */
572
573 psubsw_r2r (xmm11, xmm12); /* xmm12 = a3-b3 */
574 psraw_i2r (COL_SHIFT,xmm15); /* xmm15 = y7 */
575
576 paddsw_r2r (xmm0, xmm11); /* xmm11 = a3+b3 */
577 psraw_i2r (COL_SHIFT,xmm12); /* xmm12 = y4 */
578
579 psraw_i2r (COL_SHIFT,xmm11); /* xmm11 = y3 */
580
581 /* OUTPUT: block in xmm8 ... xmm15 */
582
583 #else
584 movdqa_m2r (*t1_vector, xmm0); /* xmm0 = T1 */
585
586 movdqa_m2r (*(col+1*8), xmm1); /* xmm1 = x1 */
587 movdqa_r2r (xmm0, xmm2); /* xmm2 = T1 */
588
589 movdqa_m2r (*(col+7*8), xmm4); /* xmm4 = x7 */
590 pmulhw_r2r (xmm1, xmm0); /* xmm0 = T1*x1 */
591
592 movdqa_m2r (*t3_vector, xmm5); /* xmm5 = T3 */
593 pmulhw_r2r (xmm4, xmm2); /* xmm2 = T1*x7 */
594
595 movdqa_m2r (*(col+5*8), xmm6); /* xmm6 = x5 */
596 movdqa_r2r (xmm5, xmm7); /* xmm7 = T3-1 */
597
598 movdqa_m2r (*(col+3*8), xmm3); /* xmm3 = x3 */
599 psubsw_r2r (xmm4, xmm0); /* xmm0 = v17 */
600
601 movdqa_m2r (*t2_vector, xmm4); /* xmm4 = T2 */
602 pmulhw_r2r (xmm3, xmm5); /* xmm5 = (T3-1)*x3 */
603
604 paddsw_r2r (xmm2, xmm1); /* xmm1 = u17 */
605 pmulhw_r2r (xmm6, xmm7); /* xmm7 = (T3-1)*x5 */
606
607 /* slot */
608
609 movdqa_r2r (xmm4, xmm2); /* xmm2 = T2 */
610 paddsw_r2r (xmm3, xmm5); /* xmm5 = T3*x3 */
611
612 pmulhw_m2r (*(col+2*8), xmm4); /* xmm4 = T2*x2 */
613 paddsw_r2r (xmm6, xmm7); /* xmm7 = T3*x5 */
614
615 psubsw_r2r (xmm6, xmm5); /* xmm5 = v35 */
616 paddsw_r2r (xmm3, xmm7); /* xmm7 = u35 */
617
618 movdqa_m2r (*(col+6*8), xmm3); /* xmm3 = x6 */
619 movdqa_r2r (xmm0, xmm6); /* xmm6 = v17 */
620
621 pmulhw_r2r (xmm3, xmm2); /* xmm2 = T2*x6 */
622 psubsw_r2r (xmm5, xmm0); /* xmm0 = b3 */
623
624 psubsw_r2r (xmm3, xmm4); /* xmm4 = v26 */
625 paddsw_r2r (xmm6, xmm5); /* xmm5 = v12 */
626
627 movdqa_r2m (xmm0, *(col+3*8)); /* save b3 in scratch0 */
628 movdqa_r2r (xmm1, xmm6); /* xmm6 = u17 */
629
630 paddsw_m2r (*(col+2*8), xmm2); /* xmm2 = u26 */
631 paddsw_r2r (xmm7, xmm6); /* xmm6 = b0 */
632
633 psubsw_r2r (xmm7, xmm1); /* xmm1 = u12 */
634 movdqa_r2r (xmm1, xmm7); /* xmm7 = u12 */
635
636 movdqa_m2r (*(col+0*8), xmm3); /* xmm3 = x0 */
637 paddsw_r2r (xmm5, xmm1); /* xmm1 = u12+v12 */
638
639 movdqa_m2r (*c4_vector, xmm0); /* xmm0 = C4/2 */
640 psubsw_r2r (xmm5, xmm7); /* xmm7 = u12-v12 */
641
642 movdqa_r2m (xmm6, *(col+5*8)); /* save b0 in scratch1 */
643 pmulhw_r2r (xmm0, xmm1); /* xmm1 = b1/2 */
644
645 movdqa_r2r (xmm4, xmm6); /* xmm6 = v26 */
646 pmulhw_r2r (xmm0, xmm7); /* xmm7 = b2/2 */
647
648 movdqa_m2r (*(col+4*8), xmm5); /* xmm5 = x4 */
649 movdqa_r2r (xmm3, xmm0); /* xmm0 = x0 */
650
651 psubsw_r2r (xmm5, xmm3); /* xmm3 = v04 */
652 paddsw_r2r (xmm5, xmm0); /* xmm0 = u04 */
653
654 paddsw_r2r (xmm3, xmm4); /* xmm4 = a1 */
655 movdqa_r2r (xmm0, xmm5); /* xmm5 = u04 */
656
657 psubsw_r2r (xmm6, xmm3); /* xmm3 = a2 */
658 paddsw_r2r (xmm2, xmm5); /* xmm5 = a0 */
659
660 paddsw_r2r (xmm1, xmm1); /* xmm1 = b1 */
661 psubsw_r2r (xmm2, xmm0); /* xmm0 = a3 */
662
663 paddsw_r2r (xmm7, xmm7); /* xmm7 = b2 */
664 movdqa_r2r (xmm3, xmm2); /* xmm2 = a2 */
665
666 movdqa_r2r (xmm4, xmm6); /* xmm6 = a1 */
667 paddsw_r2r (xmm7, xmm3); /* xmm3 = a2+b2 */
668
669 psraw_i2r (COL_SHIFT, xmm3); /* xmm3 = y2 */
670 paddsw_r2r (xmm1, xmm4); /* xmm4 = a1+b1 */
671
672 psraw_i2r (COL_SHIFT, xmm4); /* xmm4 = y1 */
673 psubsw_r2r (xmm1, xmm6); /* xmm6 = a1-b1 */
674
675 movdqa_m2r (*(col+5*8), xmm1); /* xmm1 = b0 */
676 psubsw_r2r (xmm7, xmm2); /* xmm2 = a2-b2 */
677
678 psraw_i2r (COL_SHIFT, xmm6); /* xmm6 = y6 */
679 movdqa_r2r (xmm5, xmm7); /* xmm7 = a0 */
680
681 movdqa_r2m (xmm4, *(col+1*8)); /* save y1 */
682 psraw_i2r (COL_SHIFT, xmm2); /* xmm2 = y5 */
683
684 movdqa_r2m (xmm3, *(col+2*8)); /* save y2 */
685 paddsw_r2r (xmm1, xmm5); /* xmm5 = a0+b0 */
686
687 movdqa_m2r (*(col+3*8), xmm4); /* xmm4 = b3 */
688 psubsw_r2r (xmm1, xmm7); /* xmm7 = a0-b0 */
689
690 psraw_i2r (COL_SHIFT, xmm5); /* xmm5 = y0 */
691 movdqa_r2r (xmm0, xmm3); /* xmm3 = a3 */
692
693 movdqa_r2m (xmm2, *(col+5*8)); /* save y5 */
694 psubsw_r2r (xmm4, xmm3); /* xmm3 = a3-b3 */
695
696 psraw_i2r (COL_SHIFT, xmm7); /* xmm7 = y7 */
697 paddsw_r2r (xmm0, xmm4); /* xmm4 = a3+b3 */
698
699 movdqa_r2m (xmm5, *(col+0*8)); /* save y0 */
700 psraw_i2r (COL_SHIFT, xmm3); /* xmm3 = y4 */
701
702 movdqa_r2m (xmm6, *(col+6*8)); /* save y6 */
703 psraw_i2r (COL_SHIFT, xmm4); /* xmm4 = y3 */
704
705 movdqa_r2m (xmm7, *(col+7*8)); /* save y7 */
706
707 movdqa_r2m (xmm3, *(col+4*8)); /* save y4 */
708
709 movdqa_r2m (xmm4, *(col+3*8)); /* save y3 */
710 #endif
711 }
712
713
714 /* MMX column IDCT */
715 static inline void idct_col (int16_t * const col, const int offset)
716 {
411 static const short t1_vector[] ATTR_ALIGN(8) = {T1,T1,T1,T1}; 717 static const short t1_vector[] ATTR_ALIGN(8) = {T1,T1,T1,T1};
412 static const short t2_vector[] ATTR_ALIGN(8) = {T2,T2,T2,T2}; 718 static const short t2_vector[] ATTR_ALIGN(8) = {T2,T2,T2,T2};
413 static const short t3_vector[] ATTR_ALIGN(8) = {T3,T3,T3,T3}; 719 static const short t3_vector[] ATTR_ALIGN(8) = {T3,T3,T3,T3};
414 static const short c4_vector[] ATTR_ALIGN(8) = {C4,C4,C4,C4}; 720 static const short c4_vector[] ATTR_ALIGN(8) = {C4,C4,C4,C4};
415 721
594 \ 900 \
595 idct_col (block, 0); \ 901 idct_col (block, 0); \
596 idct_col (block, 4); \ 902 idct_col (block, 4); \
597 } 903 }
598 904
905 static inline void sse2_idct (int16_t * const block)
906 {
907 static const int16_t table04[] ATTR_ALIGN(16) =
908 sse2_table (22725, 21407, 19266, 16384, 12873, 8867, 4520);
909 static const int16_t table17[] ATTR_ALIGN(16) =
910 sse2_table (31521, 29692, 26722, 22725, 17855, 12299, 6270);
911 static const int16_t table26[] ATTR_ALIGN(16) =
912 sse2_table (29692, 27969, 25172, 21407, 16819, 11585, 5906);
913 static const int16_t table35[] ATTR_ALIGN(16) =
914 sse2_table (26722, 25172, 22654, 19266, 15137, 10426, 5315);
915
916 static const int32_t rounder0_128[] ATTR_ALIGN(16) =
917 rounder_sse2 ((1 << (COL_SHIFT - 1)) - 0.5);
918 static const int32_t rounder4_128[] ATTR_ALIGN(16) = rounder_sse2 (0);
919 static const int32_t rounder1_128[] ATTR_ALIGN(16) =
920 rounder_sse2 (1.25683487303); /* C1*(C1/C4+C1+C7)/2 */
921 static const int32_t rounder7_128[] ATTR_ALIGN(16) =
922 rounder_sse2 (-0.25); /* C1*(C7/C4+C7-C1)/2 */
923 static const int32_t rounder2_128[] ATTR_ALIGN(16) =
924 rounder_sse2 (0.60355339059); /* C2 * (C6+C2)/2 */
925 static const int32_t rounder6_128[] ATTR_ALIGN(16) =
926 rounder_sse2 (-0.25); /* C2 * (C6-C2)/2 */
927 static const int32_t rounder3_128[] ATTR_ALIGN(16) =
928 rounder_sse2 (0.087788325588); /* C3*(-C3/C4+C3+C5)/2 */
929 static const int32_t rounder5_128[] ATTR_ALIGN(16) =
930 rounder_sse2 (-0.441341716183); /* C3*(-C5/C4+C5-C3)/2 */
931
932 #if defined(__x86_64__)
933 movdqa_m2r (block[0*8], xmm8);
934 movdqa_m2r (block[4*8], xmm12);
935 SSE2_IDCT_2ROW (table04, xmm8, xmm12, *rounder0_128, *rounder4_128);
936
937 movdqa_m2r (block[1*8], xmm9);
938 movdqa_m2r (block[7*8], xmm15);
939 SSE2_IDCT_2ROW (table17, xmm9, xmm15, *rounder1_128, *rounder7_128);
940
941 movdqa_m2r (block[2*8], xmm10);
942 movdqa_m2r (block[6*8], xmm14);
943 SSE2_IDCT_2ROW (table26, xmm10, xmm14, *rounder2_128, *rounder6_128);
944
945 movdqa_m2r (block[3*8], xmm11);
946 movdqa_m2r (block[5*8], xmm13);
947 SSE2_IDCT_2ROW (table35, xmm11, xmm13, *rounder3_128, *rounder5_128);
948
949 /* OUTPUT: block in xmm8 ... xmm15 */
950
951 #else
952 movdqa_m2r (block[0*8], xmm0);
953 movdqa_m2r (block[4*8], xmm4);
954 SSE2_IDCT_2ROW (table04, xmm0, xmm4, *rounder0_128, *rounder4_128);
955 movdqa_r2m (xmm0, block[0*8]);
956 movdqa_r2m (xmm4, block[4*8]);
957
958 movdqa_m2r (block[1*8], xmm0);
959 movdqa_m2r (block[7*8], xmm4);
960 SSE2_IDCT_2ROW (table17, xmm0, xmm4, *rounder1_128, *rounder7_128);
961 movdqa_r2m (xmm0, block[1*8]);
962 movdqa_r2m (xmm4, block[7*8]);
963
964 movdqa_m2r (block[2*8], xmm0);
965 movdqa_m2r (block[6*8], xmm4);
966 SSE2_IDCT_2ROW (table26, xmm0, xmm4, *rounder2_128, *rounder6_128);
967 movdqa_r2m (xmm0, block[2*8]);
968 movdqa_r2m (xmm4, block[6*8]);
969
970 movdqa_m2r (block[3*8], xmm0);
971 movdqa_m2r (block[5*8], xmm4);
972 SSE2_IDCT_2ROW (table35, xmm0, xmm4, *rounder3_128, *rounder5_128);
973 movdqa_r2m (xmm0, block[3*8]);
974 movdqa_r2m (xmm4, block[5*8]);
975 #endif
976
977 sse2_idct_col (block);
978 }
979
980 static void sse2_block_copy (int16_t * const block, uint8_t * dest,
981 const int stride)
982 {
983 #if defined(__x86_64__)
984 /* INPUT: block in xmm8 ... xmm15 */
985 packuswb_r2r (xmm8, xmm8);
986 packuswb_r2r (xmm9, xmm9);
987 movq_r2m (xmm8, *(dest+0*stride));
988 packuswb_r2r (xmm10, xmm10);
989 movq_r2m (xmm9, *(dest+1*stride));
990 packuswb_r2r (xmm11, xmm11);
991 movq_r2m (xmm10, *(dest+2*stride));
992 packuswb_r2r (xmm12, xmm12);
993 movq_r2m (xmm11, *(dest+3*stride));
994 packuswb_r2r (xmm13, xmm13);
995 movq_r2m (xmm12, *(dest+4*stride));
996 packuswb_r2r (xmm14, xmm14);
997 movq_r2m (xmm13, *(dest+5*stride));
998 packuswb_r2r (xmm15, xmm15);
999 movq_r2m (xmm14, *(dest+6*stride));
1000 movq_r2m (xmm15, *(dest+7*stride));
1001 #else
1002 movdqa_m2r (*(block+0*8), xmm0);
1003 movdqa_m2r (*(block+1*8), xmm1);
1004 movdqa_m2r (*(block+2*8), xmm2);
1005 packuswb_r2r (xmm0, xmm0);
1006 movdqa_m2r (*(block+3*8), xmm3);
1007 packuswb_r2r (xmm1, xmm1);
1008 movdqa_m2r (*(block+4*8), xmm4);
1009 packuswb_r2r (xmm2, xmm2);
1010 movdqa_m2r (*(block+5*8), xmm5);
1011 packuswb_r2r (xmm3, xmm3);
1012 movdqa_m2r (*(block+6*8), xmm6);
1013 packuswb_r2r (xmm4, xmm4);
1014 movdqa_m2r (*(block+7*8), xmm7);
1015 movq_r2m (xmm0, *(dest+0*stride));
1016 packuswb_r2r (xmm5, xmm5);
1017 movq_r2m (xmm1, *(dest+1*stride));
1018 packuswb_r2r (xmm6, xmm6);
1019 movq_r2m (xmm2, *(dest+2*stride));
1020 packuswb_r2r (xmm7, xmm7);
1021 movq_r2m (xmm3, *(dest+3*stride));
1022 movq_r2m (xmm4, *(dest+4*stride));
1023 movq_r2m (xmm5, *(dest+5*stride));
1024 movq_r2m (xmm6, *(dest+6*stride));
1025 movq_r2m (xmm7, *(dest+7*stride));
1026 #endif
1027 }
599 1028
600 #define COPY_MMX(offset,r0,r1,r2) \ 1029 #define COPY_MMX(offset,r0,r1,r2) \
601 do { \ 1030 do { \
602 movq_m2r (*(block+offset), r0); \ 1031 movq_m2r (*(block+offset), r0); \
603 dest += stride; \ 1032 dest += stride; \
623 COPY_MMX (6*8, mm0, mm1, mm2); 1052 COPY_MMX (6*8, mm0, mm1, mm2);
624 COPY_MMX (7*8, mm2, mm3, mm0); 1053 COPY_MMX (7*8, mm2, mm3, mm0);
625 movq_r2m (mm2, *(dest+stride)); 1054 movq_r2m (mm2, *(dest+stride));
626 } 1055 }
627 1056
1057 #define ADD_SSE2_2ROW(op, block0, block1)\
1058 do { \
1059 movq_m2r (*(dest), xmm1); \
1060 movq_m2r (*(dest+stride), xmm2); \
1061 punpcklbw_r2r (xmm0, xmm1); \
1062 punpcklbw_r2r (xmm0, xmm2); \
1063 paddsw_##op (block0, xmm1); \
1064 paddsw_##op (block1, xmm2); \
1065 packuswb_r2r (xmm1, xmm1); \
1066 packuswb_r2r (xmm2, xmm2); \
1067 movq_r2m (xmm1, *(dest)); \
1068 movq_r2m (xmm2, *(dest+stride)); \
1069 dest += 2*stride; \
1070 } while (0)
1071
1072 static void sse2_block_add (int16_t * const block, uint8_t * dest,
1073 const int stride)
1074 {
1075 pxor_r2r(xmm0, xmm0);
1076 #if defined(__x86_64__)
1077 /* INPUT: block in xmm8 ... xmm15 */
1078 ADD_SSE2_2ROW(r2r, xmm8, xmm9);
1079 ADD_SSE2_2ROW(r2r, xmm10, xmm11);
1080 ADD_SSE2_2ROW(r2r, xmm12, xmm13);
1081 ADD_SSE2_2ROW(r2r, xmm14, xmm15);
1082 #else
1083 ADD_SSE2_2ROW(m2r, *(block+0*8), *(block+1*8));
1084 ADD_SSE2_2ROW(m2r, *(block+2*8), *(block+3*8));
1085 ADD_SSE2_2ROW(m2r, *(block+4*8), *(block+5*8));
1086 ADD_SSE2_2ROW(m2r, *(block+6*8), *(block+7*8));
1087 #endif
1088 }
628 1089
629 #define ADD_MMX(offset,r1,r2,r3,r4) \ 1090 #define ADD_MMX(offset,r1,r2,r3,r4) \
630 do { \ 1091 do { \
631 movq_m2r (*(dest+2*stride), r1); \ 1092 movq_m2r (*(dest+2*stride), r1); \
632 packuswb_r2r (r4, r3); \ 1093 packuswb_r2r (r4, r3); \
665 ADD_MMX (7*8, mm3, mm4, mm1, mm2); 1126 ADD_MMX (7*8, mm3, mm4, mm1, mm2);
666 packuswb_r2r (mm4, mm3); 1127 packuswb_r2r (mm4, mm3);
667 movq_r2m (mm3, *(dest+stride)); 1128 movq_r2m (mm3, *(dest+stride));
668 } 1129 }
669 1130
1131
1132 static inline void sse2_block_zero (int16_t * const block)
1133 {
1134 pxor_r2r (xmm0, xmm0);
1135 movdqa_r2m (xmm0, *(block+0*8));
1136 movdqa_r2m (xmm0, *(block+1*8));
1137 movdqa_r2m (xmm0, *(block+2*8));
1138 movdqa_r2m (xmm0, *(block+3*8));
1139 movdqa_r2m (xmm0, *(block+4*8));
1140 movdqa_r2m (xmm0, *(block+5*8));
1141 movdqa_r2m (xmm0, *(block+6*8));
1142 movdqa_r2m (xmm0, *(block+7*8));
1143 }
670 1144
671 static inline void block_zero (int16_t * const block) 1145 static inline void block_zero (int16_t * const block)
672 { 1146 {
673 pxor_r2r (mm0, mm0); 1147 pxor_r2r (mm0, mm0);
674 movq_r2m (mm0, *(block+0*4)); 1148 movq_r2m (mm0, *(block+0*4));
750 movq_r2m (mm2, *(dest + stride)); 1224 movq_r2m (mm2, *(dest + stride));
751 psubusb_r2r (mm1, mm3); 1225 psubusb_r2r (mm1, mm3);
752 movq_r2m (mm3, *(dest + 2*stride)); 1226 movq_r2m (mm3, *(dest + 2*stride));
753 } 1227 }
754 1228
1229 void mpeg2_idct_copy_sse2 (int16_t * const block, uint8_t * const dest,
1230 const int stride)
1231 {
1232 sse2_idct (block);
1233 sse2_block_copy (block, dest, stride);
1234 sse2_block_zero (block);
1235 }
1236
1237 void mpeg2_idct_add_sse2 (const int last, int16_t * const block,
1238 uint8_t * const dest, const int stride)
1239 {
1240 if (last != 129 || (block[0] & (7 << 4)) == (4 << 4)) {
1241 sse2_idct (block);
1242 sse2_block_add (block, dest, stride);
1243 sse2_block_zero (block);
1244 } else
1245 block_add_DC (block, dest, stride, CPU_MMXEXT);
1246 }
1247
755 1248
756 declare_idct (mmxext_idct, mmxext_table, 1249 declare_idct (mmxext_idct, mmxext_table,
757 mmxext_row_head, mmxext_row, mmxext_row_tail, mmxext_row_mid) 1250 mmxext_row_head, mmxext_row, mmxext_row_tail, mmxext_row_mid)
758 1251
759 void mpeg2_idct_copy_mmxext (int16_t * const block, uint8_t * const dest, 1252 void mpeg2_idct_copy_mmxext (int16_t * const block, uint8_t * const dest,