+static void mbtree_propagate_list( x264_t *h, uint16_t *ref_costs, int16_t (*mvs)[2],
+ int16_t *propagate_amount, uint16_t *lowres_costs,
+ int bipred_weight, int mb_y, int len, int list )
+{
+ unsigned stride = h->mb.i_mb_stride;
+ unsigned width = h->mb.i_mb_width;
+ unsigned height = h->mb.i_mb_height;
+
+ for( unsigned i = 0; i < len; i++ )
+ {
+ int lists_used = lowres_costs[i]>>LOWRES_COST_SHIFT;
+
+ if( !(lists_used & (1 << list)) )
+ continue;
+
+ int listamount = propagate_amount[i];
+ /* Apply bipred weighting. */
+ if( lists_used == 3 )
+ listamount = (listamount * bipred_weight + 32) >> 6;
+
+ /* Early termination for simple case of mv0. */
+ if( !M32( mvs[i] ) )
+ {
+ MC_CLIP_ADD( ref_costs[mb_y*stride + i], listamount );
+ continue;
+ }
+
+ int x = mvs[i][0];
+ int y = mvs[i][1];
+ unsigned mbx = (x>>5)+i;
+ unsigned mby = (y>>5)+mb_y;
+ unsigned idx0 = mbx + mby * stride;
+ unsigned idx2 = idx0 + stride;
+ x &= 31;
+ y &= 31;
+ int idx0weight = (32-y)*(32-x);
+ int idx1weight = (32-y)*x;
+ int idx2weight = y*(32-x);
+ int idx3weight = y*x;
+ idx0weight = (idx0weight * listamount + 512) >> 10;
+ idx1weight = (idx1weight * listamount + 512) >> 10;
+ idx2weight = (idx2weight * listamount + 512) >> 10;
+ idx3weight = (idx3weight * listamount + 512) >> 10;
+
+ if( mbx < width-1 && mby < height-1 )
+ {
+ MC_CLIP_ADD( ref_costs[idx0+0], idx0weight );
+ MC_CLIP_ADD( ref_costs[idx0+1], idx1weight );
+ MC_CLIP_ADD( ref_costs[idx2+0], idx2weight );
+ MC_CLIP_ADD( ref_costs[idx2+1], idx3weight );
+ }
+ else
+ {
+ /* Note: this takes advantage of unsigned representation to
+ * catch negative mbx/mby. */
+ if( mby < height )
+ {
+ if( mbx < width )
+ MC_CLIP_ADD( ref_costs[idx0+0], idx0weight );
+ if( mbx+1 < width )
+ MC_CLIP_ADD( ref_costs[idx0+1], idx1weight );
+ }
+ if( mby+1 < height )
+ {
+ if( mbx < width )
+ MC_CLIP_ADD( ref_costs[idx2+0], idx2weight );
+ if( mbx+1 < width )
+ MC_CLIP_ADD( ref_costs[idx2+1], idx3weight );
+ }
+ }
+ }
+}
+
+void x264_mc_init( int cpu, x264_mc_functions_t *pf, int cpu_independent )