- int omx = bmx, omy = bmy;
- int costs[4];
- int stride = 64; // candidates are either all hpel or all qpel, so one stride is enough
- pixel *src0, *src1, *src2, *src3;
- src0 = h->mc.get_ref( pix, &stride, m->p_fref, m->i_stride[0], omx, omy-2, bw, bh+1, &m->weight[0] );
- src2 = h->mc.get_ref( pix+32, &stride, m->p_fref, m->i_stride[0], omx-2, omy, bw+4, bh, &m->weight[0] );
- src1 = src0 + stride;
- src3 = src2 + 1;
- h->pixf.fpelcmp_x4[i_pixel]( m->p_fenc[0], src0, src1, src2, src3, stride, costs );
- COPY2_IF_LT( bcost, costs[0] + p_cost_mvx[omx ] + p_cost_mvy[omy-2], bmy, omy-2 );
- COPY2_IF_LT( bcost, costs[1] + p_cost_mvx[omx ] + p_cost_mvy[omy+2], bmy, omy+2 );
- COPY3_IF_LT( bcost, costs[2] + p_cost_mvx[omx-2] + p_cost_mvy[omy ], bmx, omx-2, bmy, omy );
- COPY3_IF_LT( bcost, costs[3] + p_cost_mvx[omx+2] + p_cost_mvy[omy ], bmx, omx+2, bmy, omy );
- if( (bmx == omx) & (bmy == omy) )
- break;
+ /* try the subpel component of the predicted mv */
+ if( h->mb.i_subpel_refine < 3 )
+ {
+ int mx = x264_clip3( m->mvp[0], h->mb.mv_min_spel[0]+2, h->mb.mv_max_spel[0]-2 );
+ int my = x264_clip3( m->mvp[1], h->mb.mv_min_spel[1]+2, h->mb.mv_max_spel[1]-2 );
+ if( (mx-bmx)|(my-bmy) )
+ COST_MV_SAD( mx, my );
+ }
+
+ bcost <<= 6;
+ for( int i = hpel_iters; i > 0; i-- )
+ {
+ int omx = bmx, omy = bmy;
+ intptr_t stride = 64; // candidates are either all hpel or all qpel, so one stride is enough
+ pixel *src0, *src1, *src2, *src3;
+ src0 = h->mc.get_ref( pix, &stride, m->p_fref, m->i_stride[0], omx, omy-2, bw, bh+1, &m->weight[0] );
+ src2 = h->mc.get_ref( pix+32, &stride, m->p_fref, m->i_stride[0], omx-2, omy, bw+4, bh, &m->weight[0] );
+ src1 = src0 + stride;
+ src3 = src2 + 1;
+ h->pixf.fpelcmp_x4[i_pixel]( m->p_fenc[0], src0, src1, src2, src3, stride, costs );
+ costs[0] += p_cost_mvx[omx ] + p_cost_mvy[omy-2];
+ costs[1] += p_cost_mvx[omx ] + p_cost_mvy[omy+2];
+ costs[2] += p_cost_mvx[omx-2] + p_cost_mvy[omy ];
+ costs[3] += p_cost_mvx[omx+2] + p_cost_mvy[omy ];
+ COPY1_IF_LT( bcost, (costs[0]<<6)+2 );
+ COPY1_IF_LT( bcost, (costs[1]<<6)+6 );
+ COPY1_IF_LT( bcost, (costs[2]<<6)+16 );
+ COPY1_IF_LT( bcost, (costs[3]<<6)+48 );
+ if( !(bcost&63) )
+ break;
+ bmx -= (bcost<<26)>>29;
+ bmy -= (bcost<<29)>>29;
+ bcost &= ~63;
+ }
+ bcost >>= 6;