/* Copyright (C) 2001 Michael Niedermayer (michaelni@gmx.at) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* C MMX MMX2 3DNow* isVertDC Ec Ec isVertMinMaxOk Ec Ec doVertLowPass E e e* doVertDefFilter Ec Ec Ec isHorizDC Ec Ec isHorizMinMaxOk a doHorizLowPass E a a* doHorizDefFilter E ac ac deRing Vertical RKAlgo1 E a a* Vertical X1 a E E* Horizontal X1 a E E* * i dont have a 3dnow CPU -> its untested E = Exact implementation e = allmost exact implementation a = alternative / approximate impl c = checked against the other implementations (-vo md5) */ /* TODO: verify that everything workes as it should (how?) reduce the time wasted on the mem transfer implement dering implement everything in C at least (done at the moment but ...) unroll stuff if instructions depend too much on the prior one we use 8x8 blocks for the horizontal filters, opendivx seems to use 8x4? move YScale thing to the end instead of fixing QP write a faster and higher quality deblocking filter :) do something about the speed of the horizontal filters make the mainloop more flexible (variable number of blocks at once (the if/else stuff per block is slowing things down) compare the quality & speed of all filters implement a few simple deinterlacing filters split this huge file ... Notes: */ /* Changelog: use the CVS log 0.1.3 bugfixes: last 3 lines not brightness/contrast corrected brightness statistics messed up with initial black pic changed initial values of the brightness statistics C++ -> C conversation QP range question solved (very likely 1<=QP<=32 according to arpi) new experimental vertical deblocking filter RK filter has 3dNow support now (untested) 0.1.2 fixed a bug in the horizontal default filter 3dnow version of the Horizontal & Vertical Lowpass filters mmx version of the Horizontal Default filter mmx2 & C versions of a simple filter described in a paper from ramkishor & karandikar added mode flags & quality2mode function 0.1.1 */ #include #include #include #include "../config.h" //#undef HAVE_MMX2 //#define HAVE_3DNOW //#undef HAVE_MMX #include "postprocess.h" static uint64_t packedYOffset= 0x0000000000000000LL; static uint64_t packedYScale= 0x0100010001000100LL; static uint64_t w05= 0x0005000500050005LL; static uint64_t w20= 0x0020002000200020LL; static uint64_t w1400= 0x1400140014001400LL; static uint64_t bm00000001= 0x00000000000000FFLL; static uint64_t bm00010000= 0x000000FF00000000LL; static uint64_t bm00001000= 0x00000000FF000000LL; static uint64_t bm10000000= 0xFF00000000000000LL; static uint64_t bm10000001= 0xFF000000000000FFLL; static uint64_t bm11000011= 0xFFFF00000000FFFFLL; static uint64_t bm00000011= 0x000000000000FFFFLL; static uint64_t bm11111110= 0xFFFFFFFFFFFFFF00LL; static uint64_t bm11000000= 0xFFFF000000000000LL; static uint64_t bm00011000= 0x000000FFFF000000LL; static uint64_t bm00110011= 0x0000FFFF0000FFFFLL; static uint64_t bm11001100= 0xFFFF0000FFFF0000LL; static uint64_t b00= 0x0000000000000000LL; static uint64_t b01= 0x0101010101010101LL; static uint64_t b02= 0x0202020202020202LL; static uint64_t b0F= 0x0F0F0F0F0F0F0F0FLL; static uint64_t bFF= 0xFFFFFFFFFFFFFFFFLL; static uint64_t b20= 0x2020202020202020LL; static uint64_t b80= 0x8080808080808080LL; static uint64_t b7E= 0x7E7E7E7E7E7E7E7ELL; static uint64_t b7C= 0x7C7C7C7C7C7C7C7CLL; static uint64_t b3F= 0x3F3F3F3F3F3F3F3FLL; static uint64_t temp0=0; static uint64_t temp1=0; static uint64_t temp2=0; static uint64_t temp3=0; static uint64_t temp4=0; static uint64_t temp5=0; static uint64_t pQPb=0; static uint8_t tempBlock[16*16]; int hFlatnessThreshold= 56 - 16; int vFlatnessThreshold= 56 - 16; //amount of "black" u r willing to loose to get a brightness corrected picture double maxClippedThreshold= 0.01; int maxAllowedY=255; //FIXME can never make a movie´s black brighter (anyone needs that?) int minAllowedY=0; static inline long long rdtsc() { long long l; asm volatile( "rdtsc\n\t" : "=A" (l) ); // printf("%d\n", int(l/1000)); return l; } static inline void prefetchnta(void *p) { asm volatile( "prefetchnta (%0)\n\t" : : "r" (p) ); } static inline void prefetcht0(void *p) { asm volatile( "prefetcht0 (%0)\n\t" : : "r" (p) ); } static inline void prefetcht1(void *p) { asm volatile( "prefetcht1 (%0)\n\t" : : "r" (p) ); } static inline void prefetcht2(void *p) { asm volatile( "prefetcht2 (%0)\n\t" : : "r" (p) ); } //FIXME? |255-0| = 1 (shouldnt be a problem ...) /** * Check if the middle 8x8 Block in the given 8x10 block is flat */ static inline int isVertDC(uint8_t src[], int stride){ // return true; int numEq= 0; int y; src+= stride; // src points to begin of the 8x8 Block #ifdef HAVE_MMX asm volatile( // "int $3 \n\t" "pushl %1\n\t" "movq b7E, %%mm7 \n\t" // mm7 = 0x7F "movq b7C, %%mm6 \n\t" // mm6 = 0x7D "movq (%1), %%mm0 \n\t" "addl %2, %1 \n\t" "movq (%1), %%mm1 \n\t" "psubb %%mm1, %%mm0 \n\t" // mm0 = differnece "paddb %%mm7, %%mm0 \n\t" "pcmpgtb %%mm6, %%mm0 \n\t" "addl %2, %1 \n\t" "movq (%1), %%mm2 \n\t" "psubb %%mm2, %%mm1 \n\t" "paddb %%mm7, %%mm1 \n\t" "pcmpgtb %%mm6, %%mm1 \n\t" "paddb %%mm1, %%mm0 \n\t" "addl %2, %1 \n\t" "movq (%1), %%mm1 \n\t" "psubb %%mm1, %%mm2 \n\t" "paddb %%mm7, %%mm2 \n\t" "pcmpgtb %%mm6, %%mm2 \n\t" "paddb %%mm2, %%mm0 \n\t" "addl %2, %1 \n\t" "movq (%1), %%mm2 \n\t" "psubb %%mm2, %%mm1 \n\t" "paddb %%mm7, %%mm1 \n\t" "pcmpgtb %%mm6, %%mm1 \n\t" "paddb %%mm1, %%mm0 \n\t" "addl %2, %1 \n\t" "movq (%1), %%mm1 \n\t" "psubb %%mm1, %%mm2 \n\t" "paddb %%mm7, %%mm2 \n\t" "pcmpgtb %%mm6, %%mm2 \n\t" "paddb %%mm2, %%mm0 \n\t" "addl %2, %1 \n\t" "movq (%1), %%mm2 \n\t" "psubb %%mm2, %%mm1 \n\t" "paddb %%mm7, %%mm1 \n\t" "pcmpgtb %%mm6, %%mm1 \n\t" "paddb %%mm1, %%mm0 \n\t" "addl %2, %1 \n\t" "movq (%1), %%mm1 \n\t" "psubb %%mm1, %%mm2 \n\t" "paddb %%mm7, %%mm2 \n\t" "pcmpgtb %%mm6, %%mm2 \n\t" "paddb %%mm2, %%mm0 \n\t" " \n\t" "movq %%mm0, %%mm1 \n\t" "psrlw $8, %%mm0 \n\t" "paddb %%mm1, %%mm0 \n\t" "movq %%mm0, %%mm1 \n\t" "psrlq $16, %%mm0 \n\t" "paddb %%mm1, %%mm0 \n\t" "movq %%mm0, %%mm1 \n\t" "psrlq $32, %%mm0 \n\t" "paddb %%mm1, %%mm0 \n\t" "popl %1\n\t" "movd %%mm0, %0 \n\t" : "=r" (numEq) : "r" (src), "r" (stride) ); // printf("%d\n", numEq); numEq= (256 - (numEq & 0xFF)) &0xFF; // int asmEq= numEq; // numEq=0; // uint8_t *temp= src; #else for(y=0; y 0) { printf("\nasm:%d c:%d\n", asmEq, numEq); for(int y=0; y<8; y++) { for(int x=0; x<8; x++) { printf("%d ", temp[x + y*stride]); } printf("\n"); } } */ // for(int i=0; i vFlatnessThreshold) ? 1 : 0; } static inline int isVertMinMaxOk(uint8_t src[], int stride, int QP) { #ifdef HAVE_MMX int isOk; asm volatile( // "int $3 \n\t" "movq (%1, %2), %%mm0 \n\t" "movq (%1, %2, 8), %%mm1 \n\t" "movq %%mm0, %%mm2 \n\t" "psubusb %%mm1, %%mm0 \n\t" "psubusb %%mm2, %%mm1 \n\t" "por %%mm1, %%mm0 \n\t" // ABS Diff "movq pQPb, %%mm7 \n\t" // QP,..., QP "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP "psubusb %%mm7, %%mm0 \n\t" // Diff <= 2QP -> 0 "pcmpeqd b00, %%mm0 \n\t" "psrlq $16, %%mm0 \n\t" "pcmpeqd bFF, %%mm0 \n\t" // "movd %%mm0, (%1, %2, 4)\n\t" "movd %%mm0, %0 \n\t" : "=r" (isOk) : "r" (src), "r" (stride) ); return isOk ? 1 : 0; #else int isOk2= 1; int x; for(x=0; x 2*QP) isOk2=0; } /* if(isOk && !isOk2 || !isOk && isOk2) { printf("\nasm:%d c:%d QP:%d\n", isOk, isOk2, QP); for(int y=0; y<9; y++) { for(int x=0; x<8; x++) { printf("%d ", src[x + y*stride]); } printf("\n"); } } */ return isOk2; #endif } /** * Do a vertical low pass filter on the 8x10 block (only write to the 8x8 block in the middle) * useing the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16 */ static inline void doVertLowPass(uint8_t *src, int stride, int QP) { // QP= 64; #if defined (HAVE_MMX2) || defined (HAVE_3DNOW) //#ifdef HAVE_MMX2 asm volatile( //"movv %0 %1 %2\n\t" "pushl %0 \n\t" "movq pQPb, %%mm0 \n\t" // QP,..., QP // "movq bFF , %%mm0 \n\t" // QP,..., QP "movq (%0), %%mm6 \n\t" "movq (%0, %1), %%mm5 \n\t" "movq %%mm5, %%mm1 \n\t" "movq %%mm6, %%mm2 \n\t" "psubusb %%mm6, %%mm5 \n\t" "psubusb %%mm1, %%mm2 \n\t" "por %%mm5, %%mm2 \n\t" // ABS Diff of lines "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0 "pcmpeqb b00, %%mm2 \n\t" // diff <= QP -> FF "pand %%mm2, %%mm6 \n\t" "pandn %%mm1, %%mm2 \n\t" "por %%mm2, %%mm6 \n\t"// First Line to Filter "movq (%0, %1, 8), %%mm5 \n\t" "leal (%0, %1, 4), %%eax \n\t" "leal (%0, %1, 8), %%ebx \n\t" "subl %1, %%ebx \n\t" "addl %1, %0 \n\t" // %0 points to line 1 not 0 "movq (%0, %1, 8), %%mm7 \n\t" "movq %%mm5, %%mm1 \n\t" "movq %%mm7, %%mm2 \n\t" "psubusb %%mm7, %%mm5 \n\t" "psubusb %%mm1, %%mm2 \n\t" "por %%mm5, %%mm2 \n\t" // ABS Diff of lines "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0 "pcmpeqb b00, %%mm2 \n\t" // diff <= QP -> FF "pand %%mm2, %%mm7 \n\t" "pandn %%mm1, %%mm2 \n\t" "por %%mm2, %%mm7 \n\t" // First Line to Filter // 1 2 3 4 5 6 7 8 // %0 %0+%1 %0+2%1 eax %0+4%1 eax+2%1 ebx eax+4%1 // 6 4 2 2 1 1 // 6 4 4 2 // 6 8 2 /* "movq %%mm6, %%mm2 \n\t" //1 "movq %%mm6, %%mm3 \n\t" //1 "paddusb b02, %%mm3 \n\t" "psrlw $2, %%mm3 \n\t" //1 /4 "pand b3F, %%mm3 \n\t" "psubb %%mm3, %%mm2 \n\t" "movq (%0, %1), %%mm0 \n\t" // 1 "movq %%mm0, %%mm1 \n\t" // 1 "paddusb b02, %%mm0 \n\t" "psrlw $2, %%mm0 \n\t" // 1 /4 "pand b3F, %%mm0 \n\t" "paddusb %%mm2, %%mm0 \n\t" //3 1 /4 */ "movq (%0, %1), %%mm0 \n\t" // 1 "movq %%mm0, %%mm1 \n\t" // 1 PAVGB(%%mm6, %%mm0) //1 1 /2 PAVGB(%%mm6, %%mm0) //3 1 /4 "movq (%0, %1, 4), %%mm2 \n\t" // 1 "movq %%mm2, %%mm5 \n\t" // 1 PAVGB((%%eax), %%mm2) // 11 /2 PAVGB((%0, %1, 2), %%mm2) // 211 /4 "movq %%mm2, %%mm3 \n\t" // 211 /4 "movq (%0), %%mm4 \n\t" // 1 PAVGB(%%mm4, %%mm3) // 4 211 /8 PAVGB(%%mm0, %%mm3) //642211 /16 "movq %%mm3, (%0) \n\t" // X // mm1=2 mm2=3(211) mm4=1 mm5=5 mm6=0 mm7=9 "movq %%mm1, %%mm0 \n\t" // 1 PAVGB(%%mm6, %%mm0) //1 1 /2 "movq %%mm4, %%mm3 \n\t" // 1 PAVGB((%0,%1,2), %%mm3) // 1 1 /2 PAVGB((%%eax,%1,2), %%mm5) // 11 /2 PAVGB((%%eax), %%mm5) // 211 /4 PAVGB(%%mm5, %%mm3) // 2 2211 /8 PAVGB(%%mm0, %%mm3) //4242211 /16 "movq %%mm3, (%0,%1) \n\t" // X // mm1=2 mm2=3(211) mm4=1 mm5=4(211) mm6=0 mm7=9 PAVGB(%%mm4, %%mm6) //11 /2 "movq (%%ebx), %%mm0 \n\t" // 1 PAVGB((%%eax, %1, 2), %%mm0) // 11/2 "movq %%mm0, %%mm3 \n\t" // 11/2 PAVGB(%%mm1, %%mm0) // 2 11/4 PAVGB(%%mm6, %%mm0) //222 11/8 PAVGB(%%mm2, %%mm0) //22242211/16 "movq (%0, %1, 2), %%mm2 \n\t" // 1 "movq %%mm0, (%0, %1, 2) \n\t" // X // mm1=2 mm2=3 mm3=6(11) mm4=1 mm5=4(211) mm6=0(11) mm7=9 "movq (%%eax, %1, 4), %%mm0 \n\t" // 1 PAVGB((%%ebx), %%mm0) // 11 /2 PAVGB(%%mm0, %%mm6) //11 11 /4 PAVGB(%%mm1, %%mm4) // 11 /2 PAVGB(%%mm2, %%mm1) // 11 /2 PAVGB(%%mm1, %%mm6) //1122 11 /8 PAVGB(%%mm5, %%mm6) //112242211 /16 "movq (%%eax), %%mm5 \n\t" // 1 "movq %%mm6, (%%eax) \n\t" // X // mm0=7(11) mm1=2(11) mm2=3 mm3=6(11) mm4=1(11) mm5=4 mm7=9 "movq (%%eax, %1, 4), %%mm6 \n\t" // 1 PAVGB(%%mm7, %%mm6) // 11 /2 PAVGB(%%mm4, %%mm6) // 11 11 /4 PAVGB(%%mm3, %%mm6) // 11 2211 /8 PAVGB(%%mm5, %%mm2) // 11 /2 "movq (%0, %1, 4), %%mm4 \n\t" // 1 PAVGB(%%mm4, %%mm2) // 112 /4 PAVGB(%%mm2, %%mm6) // 112242211 /16 "movq %%mm6, (%0, %1, 4) \n\t" // X // mm0=7(11) mm1=2(11) mm2=3(112) mm3=6(11) mm4=5 mm5=4 mm7=9 PAVGB(%%mm7, %%mm1) // 11 2 /4 PAVGB(%%mm4, %%mm5) // 11 /2 PAVGB(%%mm5, %%mm0) // 11 11 /4 "movq (%%eax, %1, 2), %%mm6 \n\t" // 1 PAVGB(%%mm6, %%mm1) // 11 4 2 /8 PAVGB(%%mm0, %%mm1) // 11224222 /16 // "pxor %%mm1, %%mm1 \n\t" "movq %%mm1, (%%eax, %1, 2) \n\t" // X // mm2=3(112) mm3=6(11) mm4=5 mm5=4(11) mm6=6 mm7=9 PAVGB((%%ebx), %%mm2) // 112 4 /8 "movq (%%eax, %1, 4), %%mm0 \n\t" // 1 PAVGB(%%mm0, %%mm6) // 1 1 /2 PAVGB(%%mm7, %%mm6) // 1 12 /4 PAVGB(%%mm2, %%mm6) // 1122424 /4 // "pxor %%mm6, %%mm6 \n\t" "movq %%mm6, (%%ebx) \n\t" // X // mm0=8 mm3=6(11) mm4=5 mm5=4(11) mm7=9 PAVGB(%%mm7, %%mm5) // 11 2 /4 PAVGB(%%mm7, %%mm5) // 11 6 /8 PAVGB(%%mm3, %%mm0) // 112 /4 PAVGB(%%mm0, %%mm5) // 112246 /16 // "pxor %%mm5, %%mm5 \n\t" // "movq pQPb, %%mm5 \n\t" "movq %%mm5, (%%eax, %1, 4) \n\t" // X "popl %0\n\t" : : "r" (src), "r" (stride) : "%eax", "%ebx" ); #else const int l1= stride; const int l2= stride + l1; const int l3= stride + l2; const int l4= stride + l3; const int l5= stride + l4; const int l6= stride + l5; const int l7= stride + l6; const int l8= stride + l7; const int l9= stride + l8; int x; for(x=0; x>4; src[l2]= ((src[l2]<<2) + (first + sums[0] + sums[3]<<1) + sums[5] + 8)>>4; src[l3]= ((src[l3]<<2) + (first + sums[1] + sums[4]<<1) + sums[6] + 8)>>4; src[l4]= ((src[l4]<<2) + (sums[2] + sums[5]<<1) + sums[0] + sums[7] + 8)>>4; src[l5]= ((src[l5]<<2) + (sums[3] + sums[6]<<1) + sums[1] + sums[8] + 8)>>4; src[l6]= ((src[l6]<<2) + (last + sums[7] + sums[4]<<1) + sums[2] + 8)>>4; src[l7]= ((last + src[l7]<<2) + (src[l8] + sums[5]<<1) + sums[3] + 8)>>4; src[l8]= ((sums[8]<<2) + (last + sums[6]<<1) + sums[4] + 8)>>4; src++; } #endif } /** * Experimental implementation of the filter (Algorithm 1) described in a paper from Ramkishor & Karandikar * values are correctly clipped (MMX2) * values are wraparound (C) * conclusion: its fast, but introduces ugly horizontal patterns if there is a continious gradient 0 8 16 24 x = 8 x/2 = 4 x/8 = 1 1 12 12 23 */ static inline void vertRK1Filter(uint8_t *src, int stride, int QP) { #if defined (HAVE_MMX2) || defined (HAVE_3DNOW) // FIXME rounding asm volatile( "pxor %%mm7, %%mm7 \n\t" // 0 "movq b80, %%mm6 \n\t" // MIN_SIGNED_BYTE "leal (%0, %1), %%eax \n\t" "leal (%%eax, %1, 4), %%ebx \n\t" // 0 1 2 3 4 5 6 7 8 9 // %0 eax eax+%1 eax+2%1 %0+4%1 ebx ebx+%1 ebx+2%1 %0+8%1 ebx+4%1 "movq pQPb, %%mm0 \n\t" // QP,..., QP "movq %%mm0, %%mm1 \n\t" // QP,..., QP "paddusb b02, %%mm0 \n\t" "psrlw $2, %%mm0 \n\t" "pand b3F, %%mm0 \n\t" // QP/4,..., QP/4 "paddusb %%mm1, %%mm0 \n\t" // QP*1.25 ... "movq (%0, %1, 4), %%mm2 \n\t" // line 4 "movq (%%ebx), %%mm3 \n\t" // line 5 "movq %%mm2, %%mm4 \n\t" // line 4 "pcmpeqb %%mm5, %%mm5 \n\t" // -1 "pxor %%mm2, %%mm5 \n\t" // -line 4 - 1 PAVGB(%%mm3, %%mm5) "paddb %%mm6, %%mm5 \n\t" // (l5-l4)/2 "psubusb %%mm3, %%mm4 \n\t" "psubusb %%mm2, %%mm3 \n\t" "por %%mm3, %%mm4 \n\t" // |l4 - l5| "psubusb %%mm0, %%mm4 \n\t" "pcmpeqb %%mm7, %%mm4 \n\t" "pand %%mm4, %%mm5 \n\t" // d/2 // "paddb %%mm6, %%mm2 \n\t" // line 4 + 0x80 "paddb %%mm5, %%mm2 \n\t" // "psubb %%mm6, %%mm2 \n\t" "movq %%mm2, (%0,%1, 4) \n\t" "movq (%%ebx), %%mm2 \n\t" // "paddb %%mm6, %%mm2 \n\t" // line 5 + 0x80 "psubb %%mm5, %%mm2 \n\t" // "psubb %%mm6, %%mm2 \n\t" "movq %%mm2, (%%ebx) \n\t" "paddb %%mm6, %%mm5 \n\t" "psrlw $2, %%mm5 \n\t" "pand b3F, %%mm5 \n\t" "psubb b20, %%mm5 \n\t" // (l5-l4)/8 "movq (%%eax, %1, 2), %%mm2 \n\t" "paddb %%mm6, %%mm2 \n\t" // line 3 + 0x80 "paddsb %%mm5, %%mm2 \n\t" "psubb %%mm6, %%mm2 \n\t" "movq %%mm2, (%%eax, %1, 2) \n\t" "movq (%%ebx, %1), %%mm2 \n\t" "paddb %%mm6, %%mm2 \n\t" // line 6 + 0x80 "psubsb %%mm5, %%mm2 \n\t" "psubb %%mm6, %%mm2 \n\t" "movq %%mm2, (%%ebx, %1) \n\t" : : "r" (src), "r" (stride) : "%eax", "%ebx" ); #else const int l1= stride; const int l2= stride + l1; const int l3= stride + l2; const int l4= stride + l3; const int l5= stride + l4; const int l6= stride + l5; const int l7= stride + l6; const int l8= stride + l7; const int l9= stride + l8; int x; for(x=0; x0 ) { src[l3] = (6*v2 + 4*v3 + 3*v4 + 2*v5 + v6 )/16; src[l4] = (3*v2 + 3*v3 + 4*v4 + 3*v5 + 2*v6 + v7 )/16; src[l5] = (1*v2 + 2*v3 + 3*v4 + 4*v5 + 3*v6 + 3*v7)/16; src[l6] = ( 1*v3 + 2*v4 + 3*v5 + 4*v6 + 6*v7)/16; } src++; } */ #endif } /** * Experimental Filter 1 (Horizontal) * will not damage linear gradients * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter * can only smooth blocks at the expected locations (it cant smooth them if they did move) * MMX2 version does correct clipping C version doesnt * not identical with the vertical one */ static inline void horizX1Filter(uint8_t *src, int stride, int QP) { int y; static uint64_t *lut= NULL; if(lut==NULL) { int i; lut= (uint64_t*)memalign(8, 256*8); for(i=0; i<256; i++) { int v= i < 128 ? 2*i : 2*(i-256); /* //Simulate 112242211 9-Tap filter uint64_t a= (v/16) & 0xFF; uint64_t b= (v/8) & 0xFF; uint64_t c= (v/4) & 0xFF; uint64_t d= (3*v/8) & 0xFF; */ //Simulate piecewise linear interpolation uint64_t a= (v/16) & 0xFF; uint64_t b= (v*3/16) & 0xFF; uint64_t c= (v*5/16) & 0xFF; uint64_t d= (7*v/16) & 0xFF; uint64_t A= (0x100 - a)&0xFF; uint64_t B= (0x100 - b)&0xFF; uint64_t C= (0x100 - c)&0xFF; uint64_t D= (0x100 - c)&0xFF; lut[i] = (a<<56) | (b<<48) | (c<<40) | (d<<32) | (D<<24) | (C<<16) | (B<<8) | (A); //lut[i] = (v<<32) | (v<<24); } } #if defined (HAVE_MMX2) || defined (HAVE_3DNOW) asm volatile( "pxor %%mm7, %%mm7 \n\t" // 0 // "movq b80, %%mm6 \n\t" // MIN_SIGNED_BYTE "leal (%0, %1), %%eax \n\t" "leal (%%eax, %1, 4), %%ebx \n\t" "movq b80, %%mm6 \n\t" "movd pQPb, %%mm5 \n\t" // QP "movq %%mm5, %%mm4 \n\t" "paddusb %%mm5, %%mm5 \n\t" // 2QP "paddusb %%mm5, %%mm4 \n\t" // 3QP "pxor %%mm5, %%mm5 \n\t" // 0 "psubb %%mm4, %%mm5 \n\t" // -3QP "por bm11111110, %%mm5 \n\t" // ...,FF,FF,-3QP "psllq $24, %%mm5 \n\t" // 0 1 2 3 4 5 6 7 8 9 // %0 eax eax+%1 eax+2%1 %0+4%1 ebx ebx+%1 ebx+2%1 %0+8%1 ebx+4%1 #define HX1old(a) \ "movd " #a ", %%mm0 \n\t"\ "movd 4" #a ", %%mm1 \n\t"\ "punpckldq %%mm1, %%mm0 \n\t"\ "movq %%mm0, %%mm1 \n\t"\ "movq %%mm0, %%mm2 \n\t"\ "psrlq $8, %%mm1 \n\t"\ "psubusb %%mm1, %%mm2 \n\t"\ "psubusb %%mm0, %%mm1 \n\t"\ "por %%mm2, %%mm1 \n\t" /* p´x = |px - p(x+1)| */\ "pcmpeqb %%mm7, %%mm2 \n\t" /* p´x = sgn[px - p(x+1)] */\ "pshufw $0x00, %%mm1, %%mm3 \n\t" /* p´5 = |p1 - p2| */\ PAVGB(%%mm1, %%mm3) /* p´5 = (|p2-p1| + |p6-p5|)/2 */\ "psrlq $16, %%mm3 \n\t" /* p´3 = (|p2-p1| + |p6-p5|)/2 */\ "psubusb %%mm3, %%mm1 \n\t" /* |p3-p4|-(|p2-p1| + |p6-p5|)/2 */\ "paddb %%mm5, %%mm1 \n\t"\ "psubusb %%mm5, %%mm1 \n\t"\ PAVGB(%%mm7, %%mm1)\ "pxor %%mm2, %%mm1 \n\t"\ "psubb %%mm2, %%mm1 \n\t"\ "psrlq $24, %%mm1 \n\t"\ "movd %%mm1, %%ecx \n\t"\ "paddb %%mm6, %%mm0 \n\t"\ "paddsb (%3, %%ecx, 8), %%mm0 \n\t"\ "paddb %%mm6, %%mm0 \n\t"\ "movq %%mm0, " #a " \n\t"\ /* HX1old((%0)) HX1old((%%eax)) HX1old((%%eax, %1)) HX1old((%%eax, %1, 2)) HX1old((%0, %1, 4)) HX1old((%%ebx)) HX1old((%%ebx, %1)) HX1old((%%ebx, %1, 2)) */ //FIXME add some comments, its unreadable ... #define HX1b(a, c, b, d) \ "movd " #a ", %%mm0 \n\t"\ "movd 4" #a ", %%mm1 \n\t"\ "punpckldq %%mm1, %%mm0 \n\t"\ "movd " #b ", %%mm4 \n\t"\ "movq %%mm0, %%mm1 \n\t"\ "movq %%mm0, %%mm2 \n\t"\ "psrlq $8, %%mm1 \n\t"\ "movd 4" #b ", %%mm3 \n\t"\ "psubusb %%mm1, %%mm2 \n\t"\ "psubusb %%mm0, %%mm1 \n\t"\ "por %%mm2, %%mm1 \n\t" /* p´x = |px - p(x+1)| */\ "pcmpeqb %%mm7, %%mm2 \n\t" /* p´x = sgn[px - p(x+1)] */\ "punpckldq %%mm3, %%mm4 \n\t"\ "movq %%mm1, %%mm3 \n\t"\ "psllq $32, %%mm3 \n\t" /* p´5 = |p1 - p2| */\ PAVGB(%%mm1, %%mm3) /* p´5 = (|p2-p1| + |p6-p5|)/2 */\ "paddb %%mm6, %%mm0 \n\t"\ "psrlq $16, %%mm3 \n\t" /* p´3 = (|p2-p1| + |p6-p5|)/2 */\ "psubusb %%mm3, %%mm1 \n\t" /* |p3-p4|-(|p2-p1| + |p6-p5|)/2 */\ "movq %%mm4, %%mm3 \n\t"\ "paddb %%mm5, %%mm1 \n\t"\ "psubusb %%mm5, %%mm1 \n\t"\ "psrlq $8, %%mm3 \n\t"\ PAVGB(%%mm7, %%mm1)\ "pxor %%mm2, %%mm1 \n\t"\ "psubb %%mm2, %%mm1 \n\t"\ "movq %%mm4, %%mm2 \n\t"\ "psrlq $24, %%mm1 \n\t"\ "psubusb %%mm3, %%mm2 \n\t"\ "movd %%mm1, %%ecx \n\t"\ "psubusb %%mm4, %%mm3 \n\t"\ "paddsb (%2, %%ecx, 8), %%mm0 \n\t"\ "por %%mm2, %%mm3 \n\t" /* p´x = |px - p(x+1)| */\ "paddb %%mm6, %%mm0 \n\t"\ "pcmpeqb %%mm7, %%mm2 \n\t" /* p´x = sgn[px - p(x+1)] */\ "movq %%mm3, %%mm1 \n\t"\ "psllq $32, %%mm1 \n\t" /* p´5 = |p1 - p2| */\ "movq %%mm0, " #a " \n\t"\ PAVGB(%%mm3, %%mm1) /* p´5 = (|p2-p1| + |p6-p5|)/2 */\ "paddb %%mm6, %%mm4 \n\t"\ "psrlq $16, %%mm1 \n\t" /* p´3 = (|p2-p1| + |p6-p5|)/2 */\ "psubusb %%mm1, %%mm3 \n\t" /* |p3-p4|-(|p2-p1| + |p6-p5|)/2 */\ "paddb %%mm5, %%mm3 \n\t"\ "psubusb %%mm5, %%mm3 \n\t"\ PAVGB(%%mm7, %%mm3)\ "pxor %%mm2, %%mm3 \n\t"\ "psubb %%mm2, %%mm3 \n\t"\ "psrlq $24, %%mm3 \n\t"\ "movd " #c ", %%mm0 \n\t"\ "movd 4" #c ", %%mm1 \n\t"\ "punpckldq %%mm1, %%mm0 \n\t"\ "paddb %%mm6, %%mm0 \n\t"\ "paddsb (%2, %%ecx, 8), %%mm0 \n\t"\ "paddb %%mm6, %%mm0 \n\t"\ "movq %%mm0, " #c " \n\t"\ "movd %%mm3, %%ecx \n\t"\ "movd " #d ", %%mm0 \n\t"\ "paddsb (%2, %%ecx, 8), %%mm4 \n\t"\ "movd 4" #d ", %%mm1 \n\t"\ "paddb %%mm6, %%mm4 \n\t"\ "punpckldq %%mm1, %%mm0 \n\t"\ "movq %%mm4, " #b " \n\t"\ "paddb %%mm6, %%mm0 \n\t"\ "paddsb (%2, %%ecx, 8), %%mm0 \n\t"\ "paddb %%mm6, %%mm0 \n\t"\ "movq %%mm0, " #d " \n\t"\ HX1b((%0),(%%eax),(%%eax, %1),(%%eax, %1, 2)) HX1b((%0, %1, 4),(%%ebx),(%%ebx, %1),(%%ebx, %1, 2)) : : "r" (src), "r" (stride), "r" (lut) : "%eax", "%ebx", "%ecx" ); #else //FIXME (has little in common with the mmx2 version) for(y=0; y> 6; d*= SIGN(-middleEnergy); if(q>0) { d= d<0 ? 0 : d; d= d>q ? q : d; } else { d= d>0 ? 0 : d; d= d 0) { // printf("\nasm:%d c:%d\n", asmEq, numEq); for(int y=0; y<8; y++) { for(int x=0; x<8; x++) { printf("%d ", src[x + y*stride]); } printf("\n"); } } */ // printf("%d\n", numEq); return numEq > hFlatnessThreshold; } static inline int isHorizMinMaxOk(uint8_t src[], int stride, int QP) { #ifdef MMX_FIXME FIXME int isOk; asm volatile( // "int $3 \n\t" "movq (%1, %2), %%mm0 \n\t" "movq (%1, %2, 8), %%mm1 \n\t" "movq %%mm0, %%mm2 \n\t" "psubusb %%mm1, %%mm0 \n\t" "psubusb %%mm2, %%mm1 \n\t" "por %%mm1, %%mm0 \n\t" // ABS Diff "movq pQPb, %%mm7 \n\t" // QP,..., QP "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP "psubusb %%mm7, %%mm0 \n\t" // Diff <= 2QP -> 0 "pcmpeqd b00, %%mm0 \n\t" "psrlq $16, %%mm0 \n\t" "pcmpeqd bFF, %%mm0 \n\t" // "movd %%mm0, (%1, %2, 4)\n\t" "movd %%mm0, %0 \n\t" : "=r" (isOk) : "r" (src), "r" (stride) ); return isOk; #else if(abs(src[0] - src[7]) > 2*QP) return 0; return 1; #endif } static inline void doHorizDefFilterAndCopyBack(uint8_t dst[], int stride, int QP) { #ifdef HAVE_MMX asm volatile( "pushl %0 \n\t" "pxor %%mm7, %%mm7 \n\t" "movq bm00001000, %%mm6 \n\t" "movd %2, %%mm5 \n\t" // QP "movq %%mm5, %%mm4 \n\t" "paddusb %%mm5, %%mm5 \n\t" // 2QP "paddusb %%mm5, %%mm4 \n\t" // 3QP "psllq $24, %%mm4 \n\t" "pxor %%mm5, %%mm5 \n\t" // 0 "psubb %%mm4, %%mm5 \n\t" // -QP "leal tempBlock, %%eax \n\t" //FIXME? "unroll by 2" and mix #ifdef HAVE_MMX2 #define HDF(i) \ "movq " #i "(%%eax), %%mm0 \n\t"\ "movq %%mm0, %%mm1 \n\t"\ "movq %%mm0, %%mm2 \n\t"\ "psrlq $8, %%mm1 \n\t"\ "psubusb %%mm1, %%mm2 \n\t"\ "psubusb %%mm0, %%mm1 \n\t"\ "por %%mm2, %%mm1 \n\t" /* p´x = |px - p(x+1)| */\ "pcmpeqb %%mm7, %%mm2 \n\t" /* p´x = sgn[px - p(x+1)] */\ "pshufw $0x00, %%mm1, %%mm3 \n\t" /* p´5 = |p1 - p2| */\ "pminub %%mm1, %%mm3 \n\t" /* p´5 = min(|p2-p1|, |p6-p5|)*/\ "psrlq $16, %%mm3 \n\t" /* p´3 = min(|p2-p1|, |p6-p5|)*/\ "psubusb %%mm3, %%mm1 \n\t" /* |p3-p4|-min(|p1-p2|,|p5-p6|) */\ "paddb %%mm5, %%mm1 \n\t"\ "psubusb %%mm5, %%mm1 \n\t"\ "psrlw $2, %%mm1 \n\t"\ "pxor %%mm2, %%mm1 \n\t"\ "psubb %%mm2, %%mm1 \n\t"\ "pand %%mm6, %%mm1 \n\t"\ "psubb %%mm1, %%mm0 \n\t"\ "psllq $8, %%mm1 \n\t"\ "paddb %%mm1, %%mm0 \n\t"\ "movd %%mm0, (%0) \n\t"\ "psrlq $32, %%mm0 \n\t"\ "movd %%mm0, 4(%0) \n\t" #else #define HDF(i)\ "movq " #i "(%%eax), %%mm0 \n\t"\ "movq %%mm0, %%mm1 \n\t"\ "movq %%mm0, %%mm2 \n\t"\ "psrlq $8, %%mm1 \n\t"\ "psubusb %%mm1, %%mm2 \n\t"\ "psubusb %%mm0, %%mm1 \n\t"\ "por %%mm2, %%mm1 \n\t" /* p´x = |px - p(x+1)| */\ "pcmpeqb %%mm7, %%mm2 \n\t" /* p´x = sgn[px - p(x+1)] */\ "movq %%mm1, %%mm3 \n\t"\ "psllq $32, %%mm3 \n\t"\ "movq %%mm3, %%mm4 \n\t"\ "psubusb %%mm1, %%mm4 \n\t"\ "psubb %%mm4, %%mm3 \n\t"\ "psrlq $16, %%mm3 \n\t" /* p´3 = min(|p2-p1|, |p6-p5|)*/\ "psubusb %%mm3, %%mm1 \n\t" /* |p3-p4|-min(|p1-p2|,|p5,ü6|) */\ "paddb %%mm5, %%mm1 \n\t"\ "psubusb %%mm5, %%mm1 \n\t"\ "psrlw $2, %%mm1 \n\t"\ "pxor %%mm2, %%mm1 \n\t"\ "psubb %%mm2, %%mm1 \n\t"\ "pand %%mm6, %%mm1 \n\t"\ "psubb %%mm1, %%mm0 \n\t"\ "psllq $8, %%mm1 \n\t"\ "paddb %%mm1, %%mm0 \n\t"\ "movd %%mm0, (%0) \n\t"\ "psrlq $32, %%mm0 \n\t"\ "movd %%mm0, 4(%0) \n\t" #endif HDF(0) "addl %1, %0 \n\t" HDF(8) "addl %1, %0 \n\t" HDF(16) "addl %1, %0 \n\t" HDF(24) "addl %1, %0 \n\t" HDF(32) "addl %1, %0 \n\t" HDF(40) "addl %1, %0 \n\t" HDF(48) "addl %1, %0 \n\t" HDF(56) "popl %0 \n\t" : : "r" (dst), "r" (stride), "r" (QP) : "%eax" ); #else uint8_t *src= tempBlock; int y; for(y=0; y> 6; d*= SIGN(-middleEnergy); if(q>0) { d= d<0 ? 0 : d; d= d>q ? q : d; } else { d= d>0 ? 0 : d; d= d>4; dst[1]= ((dst[1]<<2) + (first + sums[0] + sums[3]<<1) + sums[5] + 8)>>4; dst[2]= ((dst[2]<<2) + (first + sums[1] + sums[4]<<1) + sums[6] + 8)>>4; dst[3]= ((dst[3]<<2) + (sums[2] + sums[5]<<1) + sums[0] + sums[7] + 8)>>4; dst[4]= ((dst[4]<<2) + (sums[3] + sums[6]<<1) + sums[1] + sums[8] + 8)>>4; dst[5]= ((dst[5]<<2) + (last + sums[7] + sums[4]<<1) + sums[2] + 8)>>4; dst[6]= ((last + dst[6]<<2) + (dst[7] + sums[5]<<1) + sums[3] + 8)>>4; dst[7]= ((sums[8]<<2) + (last + sums[6]<<1) + sums[4] + 8)>>4; dst+= stride; temp+= TEMP_STRIDE; } #endif } static inline void dering(uint8_t src[], int stride, int QP) { //FIXME #ifdef HAVE_MMX2X asm volatile( "leal (%0, %1), %%eax \n\t" "leal (%%eax, %1, 4), %%ebx \n\t" // 0 1 2 3 4 5 6 7 8 9 // %0 eax eax+%1 eax+2%1 %0+4%1 ebx ebx+%1 ebx+2%1 %0+8%1 ebx+4%1 "pcmpeq %%mm6, %%mm6 \n\t" "pxor %%mm7, %%mm7 \n\t" #define FIND_MIN_MAX(addr)\ "movq (" #addr "), %%mm0, \n\t"\ "pminub %%mm0, %%mm6 \n\t"\ "pmaxub %%mm0, %%mm7 \n\t" FIND_MIN_MAX(%0) FIND_MIN_MAX(%%eax) FIND_MIN_MAX(%%eax, %1) FIND_MIN_MAX(%%eax, %1, 2) FIND_MIN_MAX(%0, %1, 4) FIND_MIN_MAX(%%ebx) FIND_MIN_MAX(%%ebx, %1) FIND_MIN_MAX(%%ebx, %1, 2) FIND_MIN_MAX(%0, %1, 8) FIND_MIN_MAX(%%ebx, %1, 2) "movq %%mm6, %%mm4 \n\t" "psrlq $32, %%mm6 \n\t" "pminub %%mm4, %%mm6 \n\t" "movq %%mm6, %%mm4 \n\t" "psrlq $16, %%mm6 \n\t" "pminub %%mm4, %%mm6 \n\t" "movq %%mm6, %%mm4 \n\t" "psrlq $8, %%mm6 \n\t" "pminub %%mm4, %%mm6 \n\t" // min of pixels "movq %%mm7, %%mm4 \n\t" "psrlq $32, %%mm7 \n\t" "pmaxub %%mm4, %%mm7 \n\t" "movq %%mm7, %%mm4 \n\t" "psrlq $16, %%mm7 \n\t" "pmaxub %%mm4, %%mm7 \n\t" "movq %%mm7, %%mm4 \n\t" "psrlq $8, %%mm7 \n\t" "pmaxub %%mm4, %%mm7 \n\t" // max of pixels PAVGB(%%mm6, %%mm7) // (max + min)/2 : : "r" (src), "r" (stride), "r" (QP) : "%eax", "%ebx" ); #else //FIXME #endif } /** * ... * the mode value is interpreted as a quality value if its negative, its range is then (-1 ... -63) * -63 is best quality -1 is worst */ //extern "C"{ void postprocess(unsigned char * src[], int src_stride, unsigned char * dst[], int dst_stride, int horizontal_size, int vertical_size, QP_STORE_T *QP_store, int QP_stride, int mode) { if(mode<0) mode= getModeForQuality(-mode); /* long long T= rdtsc(); for(int y=vertical_size-1; y>=0 ; y--) memcpy(dst[0] + y*src_stride, src[0] + y*src_stride,src_stride); // memcpy(dst[0], src[0],src_stride*vertical_size); printf("%4dk\r", (rdtsc()-T)/1000); return; */ /* long long T= rdtsc(); while( (rdtsc() - T)/1000 < 4000); return; */ postProcess(src[0], src_stride, dst[0], dst_stride, horizontal_size, vertical_size, QP_store, QP_stride, 0, mode); horizontal_size >>= 1; vertical_size >>= 1; src_stride >>= 1; dst_stride >>= 1; mode= ((mode&0xFF)>>4) | (mode&0xFFFFFF00); if(1) { postProcess(src[1], src_stride, dst[1], dst_stride, horizontal_size, vertical_size, QP_store, QP_stride, 1, mode); postProcess(src[2], src_stride, dst[2], dst_stride, horizontal_size, vertical_size, QP_store, QP_stride, 1, mode); } else { memcpy(dst[1], src[1], src_stride*horizontal_size); memcpy(dst[2], src[2], src_stride*horizontal_size); } } /** * gets the mode flags for a given quality (larger values mean slower but better postprocessing) * 0 <= quality < 64 */ int getModeForQuality(int quality){ int modes[6]= { LUM_V_DEBLOCK, LUM_V_DEBLOCK | LUM_H_DEBLOCK, LUM_V_DEBLOCK | LUM_H_DEBLOCK | CHROM_V_DEBLOCK, LUM_V_DEBLOCK | LUM_H_DEBLOCK | CHROM_V_DEBLOCK | CHROM_H_DEBLOCK, LUM_V_DEBLOCK | LUM_H_DEBLOCK | CHROM_V_DEBLOCK | CHROM_H_DEBLOCK | LUM_DERING, LUM_V_DEBLOCK | LUM_H_DEBLOCK | CHROM_V_DEBLOCK | CHROM_H_DEBLOCK | LUM_DERING | CHROM_DERING }; return modes[ (quality*6) >>6 ]; } //} // extern "C" /** * Copies a block from src to dst and fixes the blacklevel * numLines must be a multiple of 4 * levelFix == 0 -> dont touch the brighness & contrast */ static inline void blockCopy(uint8_t dst[], int dstStride, uint8_t src[], int srcStride, int numLines, int levelFix) { int i; if(levelFix) { #ifdef HAVE_MMX asm volatile( "movl %4, %%eax \n\t" "movl %%eax, temp0\n\t" "pushl %0 \n\t" "pushl %1 \n\t" "leal (%2,%2), %%eax \n\t" "leal (%3,%3), %%ebx \n\t" "movq packedYOffset, %%mm2 \n\t" "movq packedYScale, %%mm3 \n\t" #define SCALED_CPY \ "movq (%0), %%mm0 \n\t"\ "movq (%0,%2), %%mm1 \n\t"\ "psubusb %%mm2, %%mm0 \n\t"\ "psubusb %%mm2, %%mm1 \n\t"\ "pxor %%mm4, %%mm4 \n\t"\ "pxor %%mm5, %%mm5 \n\t"\ "punpcklbw %%mm0, %%mm4 \n\t"\ "punpckhbw %%mm0, %%mm5 \n\t"\ "pmulhuw %%mm3, %%mm4 \n\t"\ "pmulhuw %%mm3, %%mm5 \n\t"\ "packuswb %%mm5, %%mm4 \n\t"\ "movq %%mm4, (%1) \n\t"\ "pxor %%mm4, %%mm4 \n\t"\ "pxor %%mm5, %%mm5 \n\t"\ "punpcklbw %%mm1, %%mm4 \n\t"\ "punpckhbw %%mm1, %%mm5 \n\t"\ "pmulhuw %%mm3, %%mm4 \n\t"\ "pmulhuw %%mm3, %%mm5 \n\t"\ "packuswb %%mm5, %%mm4 \n\t"\ "movq %%mm4, (%1, %3) \n\t"\ "1: \n\t" SCALED_CPY "addl %%eax, %0 \n\t" "addl %%ebx, %1 \n\t" SCALED_CPY "addl %%eax, %0 \n\t" "addl %%ebx, %1 \n\t" "decl temp0 \n\t" "jnz 1b \n\t" "popl %1 \n\t" "popl %0 \n\t" : : "r" (src), "r" (dst), "r" (srcStride), "r" (dstStride), "m" (numLines>>2) : "%eax", "%ebx" ); #else for(i=0; i>2) : "%eax", "%ebx" ); #else for(i=0; i0; black--) { if(clipped < maxClipped) break; clipped-= yHistogram[black]; } clipped= sum; for(white=0; white<256; white++) { if(clipped < maxClipped) break; clipped-= yHistogram[white]; } // we cant handle negative correctures packedYOffset= MAX(black - minAllowedY, 0); packedYOffset|= packedYOffset<<32; packedYOffset|= packedYOffset<<16; packedYOffset|= packedYOffset<<8; scale= (double)(maxAllowedY - minAllowedY) / (double)(white-black); packedYScale= (uint16_t)(scale*256.0 + 0.5); packedYScale|= packedYScale<<32; packedYScale|= packedYScale<<16; } else { packedYScale= 0x0100010001000100LL; packedYOffset= 0; } for(x=0; x *3 to start uint8_t *vertBlock= &(dstBlock[dstStride*3]); // finish 1 block before the next otherwise we´ll might have a problem // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing for(x=0; x>3)*QPStride + (x>>3)]: QPs[(y>>4)*QPStride + (x>>4)]; if(!isColor && (mode & LEVEL_FIX)) QP= (QP* (packedYScale &0xFFFF))>>8; #ifdef HAVE_MMX asm volatile( "movd %0, %%mm7 \n\t" "packuswb %%mm7, %%mm7 \n\t" // 0, 0, 0, QP, 0, 0, 0, QP "packuswb %%mm7, %%mm7 \n\t" // 0,QP, 0, QP, 0,QP, 0, QP "packuswb %%mm7, %%mm7 \n\t" // QP,..., QP "movq %%mm7, pQPb \n\t" : : "r" (QP) ); #endif if(y + 12 < height) { #ifdef MORE_TIMEING T0= rdtsc(); #endif #ifdef HAVE_MMX2 prefetchnta(vertSrcBlock + (((x>>3)&3) + 2)*srcStride + 32); prefetchnta(vertSrcBlock + (((x>>3)&3) + 6)*srcStride + 32); prefetcht0(vertBlock + (((x>>3)&3) + 2)*dstStride + 32); prefetcht0(vertBlock + (((x>>3)&3) + 6)*dstStride + 32); #elif defined(HAVE_3DNOW) //FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ... /* prefetch(vertSrcBlock + (((x>>3)&3) + 2)*srcStride + 32); prefetch(vertSrcBlock + (((x>>3)&3) + 6)*srcStride + 32); prefetchw(vertBlock + (((x>>3)&3) + 2)*dstStride + 32); prefetchw(vertBlock + (((x>>3)&3) + 6)*dstStride + 32); */ #endif if(!isColor) yHistogram[ srcBlock[0] ]++; blockCopy(vertBlock + dstStride*2, dstStride, vertSrcBlock + srcStride*2, srcStride, 8, mode & LEVEL_FIX); #ifdef MORE_TIMEING T1= rdtsc(); memcpyTime+= T1-T0; T0=T1; #endif if(mode & V_DEBLOCK) { if(mode & V_RK1_FILTER) vertRK1Filter(vertBlock, stride, QP); else if(mode & V_X1_FILTER) vertX1Filter(vertBlock, stride, QP); else { if( isVertDC(vertBlock, stride)) { if(isVertMinMaxOk(vertBlock, stride, QP)) doVertLowPass(vertBlock, stride, QP); } else doVertDefFilter(vertBlock, stride, QP); } } #ifdef MORE_TIMEING T1= rdtsc(); vertTime+= T1-T0; T0=T1; #endif } else blockCopy(vertBlock + dstStride*1, dstStride, vertSrcBlock + srcStride*1, srcStride, 4, mode & LEVEL_FIX); if(x - 8 >= 0 && x