Commit 900479bb authored by Loren Merritt's avatar Loren Merritt

optimize h264_loop_filter_strength_mmx2

244->160 cycles on core2

Originally committed as revision 21462 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 27000636
...@@ -796,18 +796,19 @@ static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40] ...@@ -796,18 +796,19 @@ static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40]
int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field ) { int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field ) {
int dir; int dir;
__asm__ volatile( __asm__ volatile(
"pxor %%mm7, %%mm7 \n\t" "movq %0, %%mm7 \n"
"movq %0, %%mm6 \n\t" "movq %1, %%mm6 \n"
"movq %1, %%mm5 \n\t" ::"m"(ff_pb_1), "m"(ff_pb_3)
"movq %2, %%mm4 \n\t"
::"m"(ff_pb_1), "m"(ff_pb_3), "m"(ff_pb_7)
); );
if(field) if(field)
__asm__ volatile( __asm__ volatile(
"movq %0, %%mm5 \n\t" "movq %0, %%mm6 \n"
"movq %1, %%mm4 \n\t" ::"m"(ff_pb_3_1)
::"m"(ff_pb_3_1), "m"(ff_pb_7_3)
); );
__asm__ volatile(
"movq %%mm6, %%mm5 \n"
"paddb %%mm5, %%mm5 \n"
:);
// could do a special case for dir==0 && edges==1, but it only reduces the // could do a special case for dir==0 && edges==1, but it only reduces the
// average filter time by 1.2% // average filter time by 1.2%
...@@ -815,89 +816,84 @@ static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40] ...@@ -815,89 +816,84 @@ static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40]
const x86_reg d_idx = dir ? -8 : -1; const x86_reg d_idx = dir ? -8 : -1;
const int mask_mv = dir ? mask_mv1 : mask_mv0; const int mask_mv = dir ? mask_mv1 : mask_mv0;
DECLARE_ALIGNED_8(const uint64_t, mask_dir) = dir ? 0 : 0xffffffffffffffffULL; DECLARE_ALIGNED_8(const uint64_t, mask_dir) = dir ? 0 : 0xffffffffffffffffULL;
int b_idx, edge, l; int b_idx, edge;
for( b_idx=12, edge=0; edge<edges; edge+=step, b_idx+=8*step ) { for( b_idx=12, edge=0; edge<edges; edge+=step, b_idx+=8*step ) {
__asm__ volatile( __asm__ volatile(
"pand %0, %%mm0 \n\t" "pand %0, %%mm0 \n\t"
::"m"(mask_dir) ::"m"(mask_dir)
); );
if(!(mask_mv & edge)) { if(!(mask_mv & edge)) {
__asm__ volatile("pxor %%mm0, %%mm0 \n\t":); if(bidir) {
for( l = bidir; l >= 0; l-- ) {
__asm__ volatile( __asm__ volatile(
"movd (%0), %%mm1 \n\t" "movd (%1,%0), %%mm2 \n"
"punpckldq (%0,%1), %%mm1 \n\t" "punpckldq 40(%1,%0), %%mm2 \n" // { ref0[bn], ref1[bn] }
"punpckldq %%mm1, %%mm2 \n\t" "pshufw $0x44, (%1), %%mm0 \n" // { ref0[b], ref0[b] }
"pcmpeqb %%mm2, %%mm1 \n\t" "pshufw $0x44, 40(%1), %%mm1 \n" // { ref1[b], ref1[b] }
"paddb %%mm6, %%mm1 \n\t" "pshufw $0x4E, %%mm2, %%mm3 \n"
"punpckhbw %%mm7, %%mm1 \n\t" // ref[b] != ref[bn] "psubb %%mm2, %%mm0 \n" // { ref0[b]!=ref0[bn], ref0[b]!=ref1[bn] }
"por %%mm1, %%mm0 \n\t" "psubb %%mm3, %%mm1 \n" // { ref1[b]!=ref1[bn], ref1[b]!=ref0[bn] }
"1: \n"
"movq (%2), %%mm1 \n\t" "por %%mm1, %%mm0 \n"
"movq 8(%2), %%mm2 \n\t" "movq (%2,%0,4), %%mm1 \n"
"psubw (%2,%1,4), %%mm1 \n\t" "movq 8(%2,%0,4), %%mm2 \n"
"psubw 8(%2,%1,4), %%mm2 \n\t" "movq %%mm1, %%mm3 \n"
"packsswb %%mm2, %%mm1 \n\t" "movq %%mm2, %%mm4 \n"
"paddb %%mm5, %%mm1 \n\t" "psubw (%2), %%mm1 \n"
"pminub %%mm4, %%mm1 \n\t" "psubw 8(%2), %%mm2 \n"
"pcmpeqb %%mm4, %%mm1 \n\t" // abs(mv[b] - mv[bn]) >= limit "psubw 160(%2), %%mm3 \n"
"por %%mm1, %%mm0 \n\t" "psubw 168(%2), %%mm4 \n"
::"r"(ref[l]+b_idx), "packsswb %%mm2, %%mm1 \n"
"r"(d_idx), "packsswb %%mm4, %%mm3 \n"
"r"(mv[l]+b_idx) "paddb %%mm6, %%mm1 \n"
"paddb %%mm6, %%mm3 \n"
"psubusb %%mm5, %%mm1 \n" // abs(mv[b] - mv[bn]) >= limit
"psubusb %%mm5, %%mm3 \n"
"packsswb %%mm3, %%mm1 \n"
"add $40, %0 \n"
"cmp $40, %0 \n"
"jl 1b \n"
"sub $80, %0 \n"
"pshufw $0x4E, %%mm1, %%mm1 \n"
"por %%mm1, %%mm0 \n"
"pshufw $0x4E, %%mm0, %%mm1 \n"
"pminub %%mm1, %%mm0 \n"
::"r"(d_idx),
"r"(ref[0]+b_idx),
"r"(mv[0]+b_idx)
); );
} } else {
if(bidir==1){
__asm__ volatile("pxor %%mm3, %%mm3 \n\t":);
for( l = bidir; l >= 0; l-- ) {
__asm__ volatile( __asm__ volatile(
"movd (%0), %%mm1 \n\t" "movd (%1), %%mm0 \n"
"punpckldq (%1), %%mm1 \n\t" "psubb (%1,%0), %%mm0 \n" // ref[b] != ref[bn]
"punpckldq %%mm1, %%mm2 \n\t" "movq (%2), %%mm1 \n"
"pcmpeqb %%mm2, %%mm1 \n\t" "movq 8(%2), %%mm2 \n"
"paddb %%mm6, %%mm1 \n\t" "psubw (%2,%0,4), %%mm1 \n"
"punpckhbw %%mm7, %%mm1 \n\t" // ref[b] != ref[bn] "psubw 8(%2,%0,4), %%mm2 \n"
"por %%mm1, %%mm3 \n\t" "packsswb %%mm2, %%mm1 \n"
"paddb %%mm6, %%mm1 \n"
"movq (%2), %%mm1 \n\t" "psubusb %%mm5, %%mm1 \n" // abs(mv[b] - mv[bn]) >= limit
"movq 8(%2), %%mm2 \n\t" "packsswb %%mm1, %%mm1 \n"
"psubw (%3), %%mm1 \n\t" "por %%mm1, %%mm0 \n"
"psubw 8(%3), %%mm2 \n\t" ::"r"(d_idx),
"packsswb %%mm2, %%mm1 \n\t" "r"(ref[0]+b_idx),
"paddb %%mm5, %%mm1 \n\t" "r"(mv[0]+b_idx)
"pminub %%mm4, %%mm1 \n\t"
"pcmpeqb %%mm4, %%mm1 \n\t" // abs(mv[b] - mv[bn]) >= limit
"por %%mm1, %%mm3 \n\t"
::"r"(ref[l]+b_idx),
"r"(ref[1-l]+b_idx+d_idx),
"r"(mv[l][b_idx]),
"r"(mv[1-l][b_idx+d_idx])
); );
}
__asm__ volatile(
"pcmpeqw %%mm7, %%mm3 \n\t"
"psubusw %%mm3, %%mm0 \n\t"
:);
} }
} }
__asm__ volatile( __asm__ volatile(
"movd %0, %%mm1 \n\t" "movd %0, %%mm1 \n"
"por %1, %%mm1 \n\t" "por %1, %%mm1 \n" // nnz[b] || nnz[bn]
"punpcklbw %%mm7, %%mm1 \n\t"
"pcmpgtw %%mm7, %%mm1 \n\t" // nnz[b] || nnz[bn]
::"m"(nnz[b_idx]), ::"m"(nnz[b_idx]),
"m"(nnz[b_idx+d_idx]) "m"(nnz[b_idx+d_idx])
); );
__asm__ volatile( __asm__ volatile(
"pcmpeqw %%mm7, %%mm0 \n\t" "pminub %%mm7, %%mm1 \n"
"pcmpeqw %%mm7, %%mm0 \n\t" "pminub %%mm7, %%mm0 \n"
"psrlw $15, %%mm0 \n\t" // nonzero -> 1 "psllw $1, %%mm1 \n"
"psrlw $14, %%mm1 \n\t" "pxor %%mm2, %%mm2 \n"
"movq %%mm0, %%mm2 \n\t" "pmaxub %%mm0, %%mm1 \n"
"por %%mm1, %%mm2 \n\t" "punpcklbw %%mm2, %%mm1 \n"
"psrlw $1, %%mm1 \n\t" "movq %%mm1, %0 \n"
"pandn %%mm2, %%mm1 \n\t"
"movq %%mm1, %0 \n\t"
:"=m"(*bS[dir][edge]) :"=m"(*bS[dir][edge])
::"memory" ::"memory"
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment