Skip to content
Snippets Groups Projects
postprocess_template.c 90.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • 		"movq %%mm2, %%mm1		\n\t"
    		"punpcklwd %%mm4, %%mm2		\n\t"
    		"punpckhwd %%mm4, %%mm1		\n\t"
    
    		"movd %%mm0, (%0)		\n\t"
    		"psrlq $32, %%mm0		\n\t"
    		"movd %%mm0, (%%eax)		\n\t"
    		"movd %%mm3, (%%eax, %1)	\n\t"
    		"psrlq $32, %%mm3		\n\t"
    		"movd %%mm3, (%%eax, %1, 2)	\n\t"
    		"movd %%mm2, (%0, %1, 4)	\n\t"
    		"psrlq $32, %%mm2		\n\t"
    
    		"movd %%mm2, (%%edx)		\n\t"
    		"movd %%mm1, (%%edx, %1)	\n\t"
    
    		"movd %%mm1, (%%edx, %1, 2)	\n\t"
    
    
    
    		"movq 64(%2), %%mm0		\n\t" // 12345678
    		"movq 80(%2), %%mm1		\n\t" // abcdefgh
    		"movq %%mm0, %%mm2		\n\t" // 12345678
    		"punpcklbw %%mm1, %%mm0		\n\t" // 1a2b3c4d
    		"punpckhbw %%mm1, %%mm2		\n\t" // 5e6f7g8h
    
    		"movq 96(%2), %%mm1		\n\t"
    		"movq 112(%2), %%mm3		\n\t"
    		"movq %%mm1, %%mm4		\n\t"
    		"punpcklbw %%mm3, %%mm1		\n\t"
    		"punpckhbw %%mm3, %%mm4		\n\t"
    
    		"movq %%mm0, %%mm3		\n\t"
    		"punpcklwd %%mm1, %%mm0		\n\t"
    		"punpckhwd %%mm1, %%mm3		\n\t"
    		"movq %%mm2, %%mm1		\n\t"
    		"punpcklwd %%mm4, %%mm2		\n\t"
    		"punpckhwd %%mm4, %%mm1		\n\t"
    
    		"movd %%mm0, 4(%0)		\n\t"
    		"psrlq $32, %%mm0		\n\t"
    		"movd %%mm0, 4(%%eax)		\n\t"
    		"movd %%mm3, 4(%%eax, %1)	\n\t"
    		"psrlq $32, %%mm3		\n\t"
    		"movd %%mm3, 4(%%eax, %1, 2)	\n\t"
    		"movd %%mm2, 4(%0, %1, 4)	\n\t"
    		"psrlq $32, %%mm2		\n\t"
    
    		"movd %%mm2, 4(%%edx)		\n\t"
    		"movd %%mm1, 4(%%edx, %1)	\n\t"
    
    		"movd %%mm1, 4(%%edx, %1, 2)	\n\t"
    
    	: "%eax", "%edx"
    
    static void inline RENAME(tempNoiseReducer)(uint8_t *src, int stride,
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				    uint8_t *tempBlured, uint32_t *tempBluredPast, int *maxNoise)
    
    	// to save a register (FIXME do this outside of the loops)
    	tempBluredPast[127]= maxNoise[0];
    	tempBluredPast[128]= maxNoise[1];
    	tempBluredPast[129]= maxNoise[2];
            
    
    #define FAST_L2_DIFF
    //#define L1_DIFF //u should change the thresholds too if u try that one
    #if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
    	asm volatile(
    		"leal (%2, %2, 2), %%eax			\n\t" // 3*stride
    
    		"leal (%2, %2, 4), %%edx			\n\t" // 5*stride
    		"leal (%%edx, %2, 2), %%ecx			\n\t" // 7*stride
    
    //	%x	%x+%2	%x+2%2	%x+eax	%x+4%2	%x+edx	%x+2eax	%x+ecx	%x+8%2
    
    //FIXME reorder?
    #ifdef L1_DIFF //needs mmx2
    		"movq (%0), %%mm0				\n\t" // L0
    		"psadbw (%1), %%mm0				\n\t" // |L0-R0|
    		"movq (%0, %2), %%mm1				\n\t" // L1
    		"psadbw (%1, %2), %%mm1				\n\t" // |L1-R1|
    		"movq (%0, %2, 2), %%mm2			\n\t" // L2
    		"psadbw (%1, %2, 2), %%mm2			\n\t" // |L2-R2|
    		"movq (%0, %%eax), %%mm3			\n\t" // L3
    		"psadbw (%1, %%eax), %%mm3			\n\t" // |L3-R3|
    
    		"movq (%0, %2, 4), %%mm4			\n\t" // L4
    		"paddw %%mm1, %%mm0				\n\t"
    		"psadbw (%1, %2, 4), %%mm4			\n\t" // |L4-R4|
    
    		"movq (%0, %%edx), %%mm5			\n\t" // L5
    
    		"psadbw (%1, %%edx), %%mm5			\n\t" // |L5-R5|
    
    		"movq (%0, %%eax, 2), %%mm6			\n\t" // L6
    		"paddw %%mm3, %%mm0				\n\t"
    		"psadbw (%1, %%eax, 2), %%mm6			\n\t" // |L6-R6|
    		"movq (%0, %%ecx), %%mm7			\n\t" // L7
    		"paddw %%mm4, %%mm0				\n\t"
    		"psadbw (%1, %%ecx), %%mm7			\n\t" // |L7-R7|
    		"paddw %%mm5, %%mm6				\n\t"
    		"paddw %%mm7, %%mm6				\n\t"
    		"paddw %%mm6, %%mm0				\n\t"
    #elif defined (FAST_L2_DIFF)
    		"pcmpeqb %%mm7, %%mm7				\n\t"
    
    		"movq "MANGLE(b80)", %%mm6			\n\t"
    
    		"pxor %%mm0, %%mm0				\n\t"
    #define L2_DIFF_CORE(a, b)\
    		"movq " #a ", %%mm5				\n\t"\
    		"movq " #b ", %%mm2				\n\t"\
    		"pxor %%mm7, %%mm2				\n\t"\
    		PAVGB(%%mm2, %%mm5)\
    		"paddb %%mm6, %%mm5				\n\t"\
    		"movq %%mm5, %%mm2				\n\t"\
    		"psllw $8, %%mm5				\n\t"\
    		"pmaddwd %%mm5, %%mm5				\n\t"\
    		"pmaddwd %%mm2, %%mm2				\n\t"\
    		"paddd %%mm2, %%mm5				\n\t"\
    		"psrld $14, %%mm5				\n\t"\
    		"paddd %%mm5, %%mm0				\n\t"
    
    L2_DIFF_CORE((%0), (%1))
    L2_DIFF_CORE((%0, %2), (%1, %2))
    L2_DIFF_CORE((%0, %2, 2), (%1, %2, 2))
    L2_DIFF_CORE((%0, %%eax), (%1, %%eax))
    L2_DIFF_CORE((%0, %2, 4), (%1, %2, 4))
    
    L2_DIFF_CORE((%0, %%edx), (%1, %%edx))
    
    L2_DIFF_CORE((%0, %%eax,2), (%1, %%eax,2))
    L2_DIFF_CORE((%0, %%ecx), (%1, %%ecx))
    
    #else
    		"pxor %%mm7, %%mm7				\n\t"
    		"pxor %%mm0, %%mm0				\n\t"
    #define L2_DIFF_CORE(a, b)\
    		"movq " #a ", %%mm5				\n\t"\
    		"movq " #b ", %%mm2				\n\t"\
    		"movq %%mm5, %%mm1				\n\t"\
    		"movq %%mm2, %%mm3				\n\t"\
    		"punpcklbw %%mm7, %%mm5				\n\t"\
    		"punpckhbw %%mm7, %%mm1				\n\t"\
    		"punpcklbw %%mm7, %%mm2				\n\t"\
    		"punpckhbw %%mm7, %%mm3				\n\t"\
    		"psubw %%mm2, %%mm5				\n\t"\
    		"psubw %%mm3, %%mm1				\n\t"\
    		"pmaddwd %%mm5, %%mm5				\n\t"\
    		"pmaddwd %%mm1, %%mm1				\n\t"\
    		"paddd %%mm1, %%mm5				\n\t"\
    		"paddd %%mm5, %%mm0				\n\t"
    
    L2_DIFF_CORE((%0), (%1))
    L2_DIFF_CORE((%0, %2), (%1, %2))
    L2_DIFF_CORE((%0, %2, 2), (%1, %2, 2))
    L2_DIFF_CORE((%0, %%eax), (%1, %%eax))
    L2_DIFF_CORE((%0, %2, 4), (%1, %2, 4))
    
    L2_DIFF_CORE((%0, %%edx), (%1, %%edx))
    
    L2_DIFF_CORE((%0, %%eax,2), (%1, %%eax,2))
    L2_DIFF_CORE((%0, %%ecx), (%1, %%ecx))
    
    #endif
    
    		"movq %%mm0, %%mm4				\n\t"
    		"psrlq $32, %%mm0				\n\t"
    		"paddd %%mm0, %%mm4				\n\t"
    		"movd %%mm4, %%ecx				\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		"shll $2, %%ecx					\n\t"
    
    		"movl %3, %%edx					\n\t"
    		"addl -4(%%edx), %%ecx				\n\t"
    		"addl 4(%%edx), %%ecx				\n\t"
    		"addl -1024(%%edx), %%ecx			\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		"addl $4, %%ecx					\n\t"
    
    		"addl 1024(%%edx), %%ecx			\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		"shrl $3, %%ecx					\n\t"
    
    		"movl %%ecx, (%%edx)				\n\t"
    
    //		"movl %3, %%ecx					\n\t"
    
    //		"movl %%ecx, test				\n\t"
    //		"jmp 4f \n\t"
    
    		"cmpl 512(%%edx), %%ecx				\n\t"
    
    		"cmpl 516(%%edx), %%ecx				\n\t"
    
    		"leal (%%eax, %2, 2), %%edx			\n\t" // 5*stride
    		"leal (%%edx, %2, 2), %%ecx			\n\t" // 7*stride
    
    		"movq (%0), %%mm0				\n\t" // L0
    		"movq (%0, %2), %%mm1				\n\t" // L1
    		"movq (%0, %2, 2), %%mm2			\n\t" // L2
    		"movq (%0, %%eax), %%mm3			\n\t" // L3
    		"movq (%0, %2, 4), %%mm4			\n\t" // L4
    
    		"movq (%0, %%edx), %%mm5			\n\t" // L5
    
    		"movq (%0, %%eax, 2), %%mm6			\n\t" // L6
    		"movq (%0, %%ecx), %%mm7			\n\t" // L7
    		"movq %%mm0, (%1)				\n\t" // L0
    		"movq %%mm1, (%1, %2)				\n\t" // L1
    		"movq %%mm2, (%1, %2, 2)			\n\t" // L2
    		"movq %%mm3, (%1, %%eax)			\n\t" // L3
    		"movq %%mm4, (%1, %2, 4)			\n\t" // L4
    
    		"movq %%mm5, (%1, %%edx)			\n\t" // L5
    
    		"movq %%mm6, (%1, %%eax, 2)			\n\t" // L6
    		"movq %%mm7, (%1, %%ecx)			\n\t" // L7
    		"jmp 4f						\n\t"
    
    		"1:						\n\t"
    
    		"leal (%%eax, %2, 2), %%edx			\n\t" // 5*stride
    		"leal (%%edx, %2, 2), %%ecx			\n\t" // 7*stride
    
    		"movq (%0, %%edx), %%mm5			\n\t" // L5
    		PAVGB((%1, %%edx), %%mm5)			      // L5
    
    		"movq (%0, %%eax, 2), %%mm6			\n\t" // L6
    
    		"movq %%mm0, (%1)				\n\t" // R0
    		"movq %%mm1, (%1, %2)				\n\t" // R1
    		"movq %%mm2, (%1, %2, 2)			\n\t" // R2
    		"movq %%mm3, (%1, %%eax)			\n\t" // R3
    		"movq %%mm4, (%1, %2, 4)			\n\t" // R4
    
    		"movq %%mm5, (%1, %%edx)			\n\t" // R5
    
    		"movq %%mm6, (%1, %%eax, 2)			\n\t" // R6
    		"movq %%mm7, (%1, %%ecx)			\n\t" // R7
    		"movq %%mm0, (%0)				\n\t" // L0
    		"movq %%mm1, (%0, %2)				\n\t" // L1
    		"movq %%mm2, (%0, %2, 2)			\n\t" // L2
    		"movq %%mm3, (%0, %%eax)			\n\t" // L3
    		"movq %%mm4, (%0, %2, 4)			\n\t" // L4
    
    		"movq %%mm5, (%0, %%edx)			\n\t" // L5
    
    		"movq %%mm6, (%0, %%eax, 2)			\n\t" // L6
    		"movq %%mm7, (%0, %%ecx)			\n\t" // L7
    		"jmp 4f						\n\t"
    
    		"2:						\n\t"
    
    		"cmpl 508(%%edx), %%ecx				\n\t"
    
    		"leal (%%eax, %2, 2), %%edx			\n\t" // 5*stride
    		"leal (%%edx, %2, 2), %%ecx			\n\t" // 7*stride
    
    		"movq (%0), %%mm0				\n\t" // L0
    		"movq (%0, %2), %%mm1				\n\t" // L1
    		"movq (%0, %2, 2), %%mm2			\n\t" // L2
    		"movq (%0, %%eax), %%mm3			\n\t" // L3
    		"movq (%1), %%mm4				\n\t" // R0
    		"movq (%1, %2), %%mm5				\n\t" // R1
    		"movq (%1, %2, 2), %%mm6			\n\t" // R2
    		"movq (%1, %%eax), %%mm7			\n\t" // R3
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		"movq %%mm0, (%1)				\n\t" // R0
    		"movq %%mm1, (%1, %2)				\n\t" // R1
    		"movq %%mm2, (%1, %2, 2)			\n\t" // R2
    		"movq %%mm3, (%1, %%eax)			\n\t" // R3
    		"movq %%mm0, (%0)				\n\t" // L0
    		"movq %%mm1, (%0, %2)				\n\t" // L1
    		"movq %%mm2, (%0, %2, 2)			\n\t" // L2
    		"movq %%mm3, (%0, %%eax)			\n\t" // L3
    
    		"movq (%0, %2, 4), %%mm0			\n\t" // L4
    
    		"movq (%0, %%edx), %%mm1			\n\t" // L5
    
    		"movq (%0, %%eax, 2), %%mm2			\n\t" // L6
    		"movq (%0, %%ecx), %%mm3			\n\t" // L7
    		"movq (%1, %2, 4), %%mm4			\n\t" // R4
    
    		"movq (%1, %%edx), %%mm5			\n\t" // R5
    
    		"movq (%1, %%eax, 2), %%mm6			\n\t" // R6
    		"movq (%1, %%ecx), %%mm7			\n\t" // R7
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		"movq %%mm0, (%1, %2, 4)			\n\t" // R4
    
    		"movq %%mm1, (%1, %%edx)			\n\t" // R5
    
    		"movq %%mm2, (%1, %%eax, 2)			\n\t" // R6
    		"movq %%mm3, (%1, %%ecx)			\n\t" // R7
    		"movq %%mm0, (%0, %2, 4)			\n\t" // L4
    
    		"movq %%mm1, (%0, %%edx)			\n\t" // L5
    
    		"movq %%mm2, (%0, %%eax, 2)			\n\t" // L6
    		"movq %%mm3, (%0, %%ecx)			\n\t" // L7
    		"jmp 4f						\n\t"
    
    		"3:						\n\t"
    
    		"leal (%%eax, %2, 2), %%edx			\n\t" // 5*stride
    		"leal (%%edx, %2, 2), %%ecx			\n\t" // 7*stride
    
    		"movq (%0), %%mm0				\n\t" // L0
    		"movq (%0, %2), %%mm1				\n\t" // L1
    		"movq (%0, %2, 2), %%mm2			\n\t" // L2
    		"movq (%0, %%eax), %%mm3			\n\t" // L3
    		"movq (%1), %%mm4				\n\t" // R0
    		"movq (%1, %2), %%mm5				\n\t" // R1
    		"movq (%1, %2, 2), %%mm6			\n\t" // R2
    		"movq (%1, %%eax), %%mm7			\n\t" // R3
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		"movq %%mm0, (%1)				\n\t" // R0
    		"movq %%mm1, (%1, %2)				\n\t" // R1
    		"movq %%mm2, (%1, %2, 2)			\n\t" // R2
    		"movq %%mm3, (%1, %%eax)			\n\t" // R3
    		"movq %%mm0, (%0)				\n\t" // L0
    		"movq %%mm1, (%0, %2)				\n\t" // L1
    		"movq %%mm2, (%0, %2, 2)			\n\t" // L2
    		"movq %%mm3, (%0, %%eax)			\n\t" // L3
    
    		"movq (%0, %2, 4), %%mm0			\n\t" // L4
    
    		"movq (%0, %%edx), %%mm1			\n\t" // L5
    
    		"movq (%0, %%eax, 2), %%mm2			\n\t" // L6
    		"movq (%0, %%ecx), %%mm3			\n\t" // L7
    		"movq (%1, %2, 4), %%mm4			\n\t" // R4
    
    		"movq (%1, %%edx), %%mm5			\n\t" // R5
    
    		"movq (%1, %%eax, 2), %%mm6			\n\t" // R6
    		"movq (%1, %%ecx), %%mm7			\n\t" // R7
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		PAVGB(%%mm4, %%mm0)
    		PAVGB(%%mm5, %%mm1)
    		PAVGB(%%mm6, %%mm2)
    		PAVGB(%%mm7, %%mm3)
    		"movq %%mm0, (%1, %2, 4)			\n\t" // R4
    
    		"movq %%mm1, (%1, %%edx)			\n\t" // R5
    
    		"movq %%mm2, (%1, %%eax, 2)			\n\t" // R6
    		"movq %%mm3, (%1, %%ecx)			\n\t" // R7
    		"movq %%mm0, (%0, %2, 4)			\n\t" // L4
    
    		"movq %%mm1, (%0, %%edx)			\n\t" // L5
    
    		"movq %%mm2, (%0, %%eax, 2)			\n\t" // L6
    		"movq %%mm3, (%0, %%ecx)			\n\t" // L7
    
    		"4:						\n\t"
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		:: "r" (src), "r" (tempBlured), "r"(stride), "m" (tempBluredPast)
    
    		: "%eax", "%edx", "%ecx", "memory"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	int i;
    
    
    	for(y=0; y<8; y++)
    	{
    		int x;
    		for(x=0; x<8; x++)
    		{
    			int ref= tempBlured[ x + y*stride ];
    			int cur= src[ x + y*stride ];
    			int d1=ref - cur;
    
    //			if(x==0 || x==7) d1+= d1>>1;
    //			if(y==0 || y==7) d1+= d1>>1;
    //			d+= ABS(d1);
    			d+= d1*d1;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	i=d;
    	d= 	(
    		4*d
    		+(*(tempBluredPast-256))
    		+(*(tempBluredPast-1))+ (*(tempBluredPast+1))
    		+(*(tempBluredPast+256))
    		+4)>>3;
    	*tempBluredPast=i;
    //	((*tempBluredPast)*3 + d + 2)>>2;
    
    
    //printf("%d %d %d\n", maxNoise[0], maxNoise[1], maxNoise[2]);
    /*
    Switch between
     1  0  0  0  0  0  0  (0)
    64 32 16  8  4  2  1  (1)
    64 48 36 27 20 15 11 (33) (approx)
    64 56 49 43 37 33 29 (200) (approx)
    */
    	if(d > maxNoise[1])
    	{
    		if(d < maxNoise[2])
    		{
    			for(y=0; y<8; y++)
    			{
    				int x;
    				for(x=0; x<8; x++)
    				{
    					int ref= tempBlured[ x + y*stride ];
    					int cur= src[ x + y*stride ];
    					tempBlured[ x + y*stride ]=
    					src[ x + y*stride ]=
    						(ref + cur + 1)>>1;
    				}
    			}
    		}
    		else
    		{
    			for(y=0; y<8; y++)
    			{
    				int x;
    				for(x=0; x<8; x++)
    				{
    					tempBlured[ x + y*stride ]= src[ x + y*stride ];
    				}
    			}
    		}
    	}
    	else
    	{
    		if(d < maxNoise[0])
    		{
    			for(y=0; y<8; y++)
    			{
    				int x;
    				for(x=0; x<8; x++)
    				{
    					int ref= tempBlured[ x + y*stride ];
    					int cur= src[ x + y*stride ];
    					tempBlured[ x + y*stride ]=
    					src[ x + y*stride ]=
    						(ref*7 + cur + 4)>>3;
    				}
    			}
    		}
    		else
    		{
    			for(y=0; y<8; y++)
    			{
    				int x;
    				for(x=0; x<8; x++)
    				{
    					int ref= tempBlured[ x + y*stride ];
    					int cur= src[ x + y*stride ];
    					tempBlured[ x + y*stride ]=
    					src[ x + y*stride ]=
    						(ref*3 + cur + 2)>>2;
    				}
    			}
    		}
    	}
    
    static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
    
    	QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c);
    
    /**
     * Copies a block from src to dst and fixes the blacklevel
    
     * levelFix == 0 -> dont touch the brighness & contrast
    
    static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, uint8_t src[], int srcStride,
    
    	int levelFix, int64_t *packedOffsetAndScale)
    
    #ifdef HAVE_MMX
    					asm volatile(
    
    						"movq (%%eax), %%mm2	\n\t" // packedYOffset
    						"movq 8(%%eax), %%mm3	\n\t" // packedYScale
    						"leal (%2,%4), %%eax	\n\t"
    						"leal (%3,%5), %%edx	\n\t"
    
    #ifdef HAVE_MMX2
    #define SCALED_CPY(src1, src2, dst1, dst2)					\
    						"movq " #src1 ", %%mm0	\n\t"\
    						"movq " #src1 ", %%mm5	\n\t"\
    						"movq " #src2 ", %%mm1	\n\t"\
    						"movq " #src2 ", %%mm6	\n\t"\
    						"punpcklbw %%mm0, %%mm0 \n\t"\
    						"punpckhbw %%mm5, %%mm5 \n\t"\
    						"punpcklbw %%mm1, %%mm1 \n\t"\
    						"punpckhbw %%mm6, %%mm6 \n\t"\
    						"pmulhuw %%mm3, %%mm0	\n\t"\
    						"pmulhuw %%mm3, %%mm5	\n\t"\
    						"pmulhuw %%mm3, %%mm1	\n\t"\
    						"pmulhuw %%mm3, %%mm6	\n\t"\
    						"psubw %%mm2, %%mm0	\n\t"\
    						"psubw %%mm2, %%mm5	\n\t"\
    						"psubw %%mm2, %%mm1	\n\t"\
    						"psubw %%mm2, %%mm6	\n\t"\
    						"packuswb %%mm5, %%mm0	\n\t"\
    						"packuswb %%mm6, %%mm1	\n\t"\
    						"movq %%mm0, " #dst1 "	\n\t"\
    						"movq %%mm1, " #dst2 "	\n\t"\
    
    #else //HAVE_MMX2
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    #define SCALED_CPY(src1, src2, dst1, dst2)					\
    						"movq " #src1 ", %%mm0	\n\t"\
    						"movq " #src1 ", %%mm5	\n\t"\
    
    						"punpcklbw %%mm4, %%mm0 \n\t"\
    						"punpckhbw %%mm4, %%mm5 \n\t"\
    
    						"psubw %%mm2, %%mm0	\n\t"\
    						"psubw %%mm2, %%mm5	\n\t"\
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    						"movq " #src2 ", %%mm1	\n\t"\
    
    						"psllw $6, %%mm0	\n\t"\
    						"psllw $6, %%mm5	\n\t"\
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    						"movq " #src2 ", %%mm6	\n\t"\
    
    						"pmulhw %%mm3, %%mm5	\n\t"\
    						"punpcklbw %%mm4, %%mm1 \n\t"\
    
    						"punpckhbw %%mm4, %%mm6 \n\t"\
    
    						"psubw %%mm2, %%mm1	\n\t"\
    
    						"psllw $6, %%mm1	\n\t"\
    
    						"pmulhw %%mm3, %%mm6	\n\t"\
    						"packuswb %%mm5, %%mm0	\n\t"\
    						"packuswb %%mm6, %%mm1	\n\t"\
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    						"movq %%mm0, " #dst1 "	\n\t"\
    						"movq %%mm1, " #dst2 "	\n\t"\
    
    
    SCALED_CPY((%2)       , (%2, %4)      , (%3)       , (%3, %5))
    SCALED_CPY((%2, %4, 2), (%%eax, %4, 2), (%3, %5, 2), (%%edx, %5, 2))
    SCALED_CPY((%2, %4, 4), (%%eax, %4, 4), (%3, %5, 4), (%%edx, %5, 4))
    						"leal (%%eax,%4,4), %%eax	\n\t"
    						"leal (%%edx,%5,4), %%edx	\n\t"
    SCALED_CPY((%%eax, %4), (%%eax, %4, 2), (%%edx, %5), (%%edx, %5, 2))
    
    						: "=&a" (packedOffsetAndScale)
    						: "0" (packedOffsetAndScale),
    						"r"(src),
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    						"r"(dst),
    						"r" (srcStride),
    
    						: "%edx"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				for(i=0; i<8; i++)
    
    					memcpy(	&(dst[dstStride*i]),
    						&(src[srcStride*i]), BLOCK_SIZE);
    #endif
    	}
    	else
    	{
    #ifdef HAVE_MMX
    					asm volatile(
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    						"leal (%0,%2), %%eax	\n\t"
    
    						"leal (%1,%3), %%edx	\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    #define SIMPLE_CPY(src1, src2, dst1, dst2)				\
    						"movq " #src1 ", %%mm0	\n\t"\
    						"movq " #src2 ", %%mm1	\n\t"\
    						"movq %%mm0, " #dst1 "	\n\t"\
    						"movq %%mm1, " #dst2 "	\n\t"\
    
    SIMPLE_CPY((%0)       , (%0, %2)      , (%1)       , (%1, %3))
    
    SIMPLE_CPY((%0, %2, 2), (%%eax, %2, 2), (%1, %3, 2), (%%edx, %3, 2))
    SIMPLE_CPY((%0, %2, 4), (%%eax, %2, 4), (%1, %3, 4), (%%edx, %3, 4))
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    						"leal (%%eax,%2,4), %%eax	\n\t"
    
    						"leal (%%edx,%3,4), %%edx	\n\t"
    SIMPLE_CPY((%%eax, %2), (%%eax, %2, 2), (%%edx, %3), (%%edx, %3, 2))
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    
    						: : "r" (src),
    						"r" (dst),
    						"r" (srcStride),
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    						"r" (dstStride)
    
    						: "%eax", "%edx"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				for(i=0; i<8; i++)
    
    					memcpy(	&(dst[dstStride*i]),
    						&(src[srcStride*i]), BLOCK_SIZE);
    #endif
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    /**
     * Duplicates the given 8 src pixels ? times upward
     */
    static inline void RENAME(duplicate)(uint8_t src[], int stride)
    {
    #ifdef HAVE_MMX
    	asm volatile(
    		"movq (%0), %%mm0		\n\t"
    		"addl %1, %0			\n\t"
    		"movq %%mm0, (%0)		\n\t"
    		"movq %%mm0, (%0, %1)		\n\t"
    		"movq %%mm0, (%0, %1, 2)	\n\t"
    		: "+r" (src)
    		: "r" (-stride)
    	);
    #else
    	int i;
    	uint8_t *p=src;
    	for(i=0; i<3; i++)
    	{
    		p-= stride;
    		memcpy(p, src, 8);
    	}
    #endif
    }
    
    
    /**
     * Filters array of bytes (Y or U or V values)
     */
    
    static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
    
    	QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c2)
    
    	PPContext __attribute__((aligned(8))) c= *c2; //copy to stack for faster access
    
    #ifdef COMPILE_TIME_MODE
    	const int mode= COMPILE_TIME_MODE;
    #else
    
    	const int mode= isColor ? c.ppMode.chromMode : c.ppMode.lumMode;
    
    	int black=0, white=255; // blackest black and whitest white in the picture
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	int QPCorrecture= 256*256;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	int copyAhead;
    
    
    	//FIXME remove
    	uint64_t * const yHistogram= c.yHistogram;
    	uint8_t * const tempSrc= c.tempSrc;
    	uint8_t * const tempDst= c.tempDst;
    
    	c.dcOffset= c.ppMode.maxDcDiff;
    	c.dcThreshold= c.ppMode.maxDcDiff*2 + 1;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    #ifdef HAVE_MMX
    
    	c.mmxDcOffset= 0x7F - c.dcOffset;
    	c.mmxDcThreshold= 0x7F - c.dcThreshold;
    
    	c.mmxDcOffset*= 0x0101010101010101LL;
    	c.mmxDcThreshold*= 0x0101010101010101LL;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    #endif
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	if(mode & CUBIC_IPOL_DEINT_FILTER) copyAhead=16;
    
    	else if(   (mode & LINEAR_BLEND_DEINT_FILTER)
    		|| (mode & FFMPEG_DEINT_FILTER)) copyAhead=14;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	else if(   (mode & V_DEBLOCK)
    		|| (mode & LINEAR_IPOL_DEINT_FILTER)
    		|| (mode & MEDIAN_DEINT_FILTER)) copyAhead=13;
    	else if(mode & V_X1_FILTER) copyAhead=11;
    
    //	else if(mode & V_RK1_FILTER) copyAhead=10;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	else if(mode & DERING) copyAhead=9;
    	else copyAhead=8;
    
    	copyAhead-= 8;
    
    
    		int i;
    		uint64_t maxClipped;
    		uint64_t clipped;
    		double scale;
    
    
    		c.frameNum++;
    		// first frame is fscked so we ignore it
    		if(c.frameNum == 1) yHistogram[0]= width*height/64*15/256;
    
    //			printf("%d ", yHistogram[i]);
    		}
    //		printf("\n\n");
    
    		/* we allways get a completly black picture first */
    		maxClipped= (uint64_t)(sum * maxClippedThreshold);
    
    		for(black=255; black>0; black--)
    		{
    			if(clipped < maxClipped) break;
    			clipped-= yHistogram[black];
    		}
    
    		clipped= sum;
    		for(white=0; white<256; white++)
    		{
    			if(clipped < maxClipped) break;
    			clipped-= yHistogram[white];
    		}
    
    
    		scale= (double)(c.ppMode.maxAllowedY - c.ppMode.minAllowedY) / (double)(white-black);
    
    		c.packedYScale= (uint16_t)(scale*256.0 + 0.5);
    		c.packedYOffset= (((black*c.packedYScale)>>8) - c.ppMode.minAllowedY) & 0xFFFF;
    
    		c.packedYScale= (uint16_t)(scale*1024.0 + 0.5);
    		c.packedYOffset= (black - c.ppMode.minAllowedY) & 0xFFFF;
    
    		c.packedYOffset|= c.packedYOffset<<32;
    		c.packedYOffset|= c.packedYOffset<<16;
    
    		c.packedYScale|= c.packedYScale<<32;
    		c.packedYScale|= c.packedYScale<<16;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		
    		if(mode & LEVEL_FIX)	QPCorrecture= (int)(scale*256*256 + 0.5);
    		else			QPCorrecture= 256*256;
    
    		c.packedYScale= 0x0100010001000100LL;
    		c.packedYOffset= 0;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		QPCorrecture= 256*256;
    
    	/* copy & deinterlace first row of blocks */
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	y=-BLOCK_SIZE;
    	{
    		uint8_t *srcBlock= &(src[y*srcStride]);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		uint8_t *dstBlock= tempDst + dstStride;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    		// From this point on it is guranteed that we can read and write 16 lines downward
    		// finish 1 block before the next otherwise well 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<width; x+=BLOCK_SIZE)
    		{
    
    #ifdef HAVE_MMX2
    /*
    			prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
    			prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
    			prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
    			prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
    */
    
    			asm(
    				"movl %4, %%eax			\n\t"
    				"shrl $2, %%eax			\n\t"
    				"andl $6, %%eax			\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"addl %5, %%eax			\n\t"
    
    				"movl %%eax, %%edx		\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"imul %1, %%eax			\n\t"
    
    				"imul %3, %%edx			\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"prefetchnta 32(%%eax, %0)	\n\t"
    
    				"prefetcht0 32(%%edx, %2)	\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"addl %1, %%eax			\n\t"
    
    				"addl %3, %%edx			\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"prefetchnta 32(%%eax, %0)	\n\t"
    
    				"prefetcht0 32(%%edx, %2)	\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			:: "r" (srcBlock), "r" (srcStride), "r" (dstBlock), "r" (dstStride),
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			"m" (x), "m" (copyAhead)
    
    			: "%eax", "%edx"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			);
    
    #elif defined(HAVE_3DNOW)
    //FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ...
    /*			prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
    			prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
    			prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
    			prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
    */
    #endif
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			RENAME(blockCopy)(dstBlock + dstStride*8, dstStride,
    
    				srcBlock + srcStride*8, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    			RENAME(duplicate)(dstBlock + dstStride*8, dstStride);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    			if(mode & LINEAR_IPOL_DEINT_FILTER)
    
    				RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			else if(mode & LINEAR_BLEND_DEINT_FILTER)
    
    				RENAME(deInterlaceBlendLinear)(dstBlock, dstStride);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			else if(mode & MEDIAN_DEINT_FILTER)
    
    				RENAME(deInterlaceMedian)(dstBlock, dstStride);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			else if(mode & CUBIC_IPOL_DEINT_FILTER)
    
    				RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
    
    			else if(mode & FFMPEG_DEINT_FILTER)
    				RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    /*			else if(mode & CUBIC_BLEND_DEINT_FILTER)
    
    				RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    */
    			dstBlock+=8;
    			srcBlock+=8;
    		}
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		memcpy(dst, tempDst + 9*dstStride, copyAhead*dstStride );
    
    //printf("\n");
    
    	for(y=0; y<height; y+=BLOCK_SIZE)
    
    	{
    		//1% speedup if these are here instead of the inner loop
    		uint8_t *srcBlock= &(src[y*srcStride]);
    		uint8_t *dstBlock= &(dst[y*dstStride]);
    
    #ifdef HAVE_MMX
    
    		uint8_t *tempBlock1= c.tempBlocks;
    		uint8_t *tempBlock2= c.tempBlocks + 8;
    
    #endif
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    #ifdef ARCH_X86
    		int *QPptr= isColor ? &QPs[(y>>3)*QPStride] :&QPs[(y>>4)*QPStride];
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		int QPDelta= isColor ? (-1) : 1<<31;
    		int QPFrac= 1<<30;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    #endif
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		/* can we mess with a 8x16 block from srcBlock/dstBlock downwards and 1 line upwards
    		   if not than use a temporary buffer */
    
    		if(y+15 >= height)
    		{
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			/* copy from line (copyAhead) to (copyAhead+7) of src, these will be copied with
    
    			   blockcopy to dst later */
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			memcpy(tempSrc + srcStride*copyAhead, srcBlock + srcStride*copyAhead,
    				srcStride*MAX(height-y-copyAhead, 0) );
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			/* duplicate last line of src to fill the void upto line (copyAhead+7) */
    			for(i=MAX(height-y, 8); i<copyAhead+8; i++)
    
    				memcpy(tempSrc + srcStride*i, src + srcStride*(height-1), srcStride);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			/* copy up to (copyAhead+1) lines of dst (line -1 to (copyAhead-1))*/
    			memcpy(tempDst, dstBlock - dstStride, dstStride*MIN(height-y+1, copyAhead+1) );
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			/* duplicate last line of dst to fill the void upto line (copyAhead) */
    			for(i=height-y+1; i<=copyAhead; i++)
    
    				memcpy(tempDst + dstStride*i, dst + dstStride*(height-1), dstStride);
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			dstBlock= tempDst + dstStride;
    
    			srcBlock= tempSrc;
    		}
    
    //printf("\n");
    
    		// From this point on it is guranteed that we can read and write 16 lines downward
    
    		// finish 1 block before the next otherwise well 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<width; x+=BLOCK_SIZE)
    
    #ifdef HAVE_MMX
    
    #endif
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    #ifdef ARCH_X86
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			asm volatile(
    				"addl %2, %1		\n\t"
    				"sbbl %%eax, %%eax	\n\t"
    				"shll $2, %%eax		\n\t"
    				"subl %%eax, %0		\n\t"
    				: "+r" (QPptr), "+m" (QPFrac)
    				: "r" (QPDelta)
    				: "%eax"
    			);
    #else
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
                                    QPs[(y>>3)*QPStride + (x>>3)]:
                                    QPs[(y>>4)*QPStride + (x>>4)];
    #endif
    			if(!isColor)
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			{
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				QP= (QP* QPCorrecture + 256*128)>>16;
    
    				yHistogram[ srcBlock[srcStride*12 + 4] ]++;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			}
    
    //printf("%d ", QP);
    			c.QP= QP;
    
    			asm volatile(
    
    				"movd %1, %%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, %0			\n\t"
    				: "=m" (c.pQPb) 
    				: "r" (QP)
    
    #ifdef HAVE_MMX2
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    /*
    			prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
    			prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
    			prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
    			prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
    */
    
    			asm(
    				"movl %4, %%eax			\n\t"
    				"shrl $2, %%eax			\n\t"
    				"andl $6, %%eax			\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"addl %5, %%eax			\n\t"
    
    				"movl %%eax, %%edx		\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"imul %1, %%eax			\n\t"
    
    				"imul %3, %%edx			\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"prefetchnta 32(%%eax, %0)	\n\t"
    
    				"prefetcht0 32(%%edx, %2)	\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"addl %1, %%eax			\n\t"
    
    				"addl %3, %%edx			\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				"prefetchnta 32(%%eax, %0)	\n\t"
    
    				"prefetcht0 32(%%edx, %2)	\n\t"
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			:: "r" (srcBlock), "r" (srcStride), "r" (dstBlock), "r" (dstStride),
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    			"m" (x), "m" (copyAhead)
    
    			: "%eax", "%edx"
    
    #elif defined(HAVE_3DNOW)
    //FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ...
    
    /*			prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
    			prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
    			prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
    			prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
    
    			RENAME(blockCopy)(dstBlock + dstStride*copyAhead, dstStride,
    
    				srcBlock + srcStride*copyAhead, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
    
    
    			if(mode & LINEAR_IPOL_DEINT_FILTER)
    
    				RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
    
    			else if(mode & LINEAR_BLEND_DEINT_FILTER)
    
    				RENAME(deInterlaceBlendLinear)(dstBlock, dstStride);
    
    			else if(mode & MEDIAN_DEINT_FILTER)
    
    				RENAME(deInterlaceMedian)(dstBlock, dstStride);
    
    			else if(mode & CUBIC_IPOL_DEINT_FILTER)
    
    				RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
    
    			else if(mode & FFMPEG_DEINT_FILTER)
    				RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
    
    /*			else if(mode & CUBIC_BLEND_DEINT_FILTER)
    
    				RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
    
    			/* only deblock if we have 2 blocks */
    			if(y + 8 < height)
    			{
    
    				if(mode & V_X1_FILTER)
    					RENAME(vertX1Filter)(dstBlock, stride, &c);
    
    					if( RENAME(isVertDC)(dstBlock, stride, &c))
    
    						if(RENAME(isVertMinMaxOk)(dstBlock, stride, &c))
    							RENAME(doVertLowPass)(dstBlock, stride, &c);
    
    						RENAME(doVertDefFilter)(dstBlock, stride, &c);
    
    			RENAME(transpose1)(tempBlock1, tempBlock2, dstBlock, dstStride);
    
    			/* check if we have a previous block to deblock it with dstBlock */
    
    			if(x - 8 >= 0)
    
    				if(mode & H_X1_FILTER)
    					RENAME(vertX1Filter)(tempBlock1, 16, &c);
    
    					if( RENAME(isVertDC)(tempBlock1, 16, &c))
    
    						if(RENAME(isVertMinMaxOk)(tempBlock1, 16, &c))
    							RENAME(doVertLowPass)(tempBlock1, 16, &c);
    
    						RENAME(doVertDefFilter)(tempBlock1, 16, &c);
    
    				RENAME(transpose2)(dstBlock-4, dstStride, tempBlock1 + 4*16);
    
    				if(mode & H_X1_FILTER)
    					horizX1Filter(dstBlock-4, stride, QP);
    				else if(mode & H_DEBLOCK)
    
    					if( isHorizDC(dstBlock-4, stride, &c))
    
    						if(isHorizMinMaxOk(dstBlock-4, stride, QP))
    							doHorizLowPass(dstBlock-4, stride, QP);
    
    						doHorizDefFilter(dstBlock-4, stride, QP);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    				if(mode & DERING)
    				{
    				//FIXME filter first line
    
    					if(y>0) RENAME(dering)(dstBlock - stride - 8, stride, &c);