Commit 2d3958bf authored by Fiona Glaser's avatar Fiona Glaser

Faster x264_exp2fix8

22->13 cycles on Core 2 with mfpmath=sse
parent 252fcf4b
......@@ -161,15 +161,14 @@ static const uint8_t exp2_lut[64] = {
177, 182, 186, 191, 196, 201, 206, 211, 216, 221, 226, 232, 237, 242, 248, 253,
};
/* Not a general-purpose function; multiplies input by -1/6 to convert
* qp to qscale. */
static ALWAYS_INLINE int x264_exp2fix8( float x )
{
int i, f;
x += 8;
if( x <= 0 ) return 0;
if( x >= 16 ) return 0xffff;
i = x;
f = (x-i)*64;
return (exp2_lut[f]+256) << i >> 8;
if( x >= 512.f/6.f ) return 0;
if( x <= -512.f/6.f ) return 0xffff;
int i = x*(-64.f/6.f) + 512;
return (exp2_lut[i&63]+256) << (i>>6) >> 8;
}
static const float log2_lut[128] = {
......
......@@ -251,7 +251,7 @@ void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame )
frame->f_qp_offset[mb_x + mb_y*h->mb.i_mb_stride] =
frame->f_qp_offset_aq[mb_x + mb_y*h->mb.i_mb_stride] = qp_adj;
if( h->frames.b_have_lowres )
frame->i_inv_qscale_factor[mb_x + mb_y*h->mb.i_mb_stride] = x264_exp2fix8(qp_adj*(-1.f/6.f));
frame->i_inv_qscale_factor[mb_x + mb_y*h->mb.i_mb_stride] = x264_exp2fix8(qp_adj);
}
}
......
......@@ -389,7 +389,7 @@ static int x264_slicetype_frame_cost_recalculate( x264_t *h, x264_frame_t **fram
int i_mb_xy = h->mb.i_mb_x + h->mb.i_mb_y*h->mb.i_mb_stride;
int i_mb_cost = frames[b]->lowres_costs[b-p0][p1-b][i_mb_xy];
float qp_adj = frames[b]->f_qp_offset[i_mb_xy];
i_mb_cost = (i_mb_cost * x264_exp2fix8(qp_adj*(-1.f/6.f)) + 128) >> 8;
i_mb_cost = (i_mb_cost * x264_exp2fix8(qp_adj) + 128) >> 8;
row_satd[ h->mb.i_mb_y ] += i_mb_cost;
if( (h->mb.i_mb_y > 0 && h->mb.i_mb_y < h->sps->i_mb_height - 1 &&
h->mb.i_mb_x > 0 && h->mb.i_mb_x < h->sps->i_mb_width - 1) ||
......@@ -410,6 +410,9 @@ static void x264_macroblock_tree_finish( x264_t *h, x264_frame_t *frame, int b_b
memcpy( frame->f_qp_offset, frame->f_qp_offset_aq, sizeof( frame->f_qp_offset ) );
else
{
/* Allow the strength to be adjusted via qcompress, since the two
* concepts are very similar. */
float strength = 5.0f * (1.0f - h->param.rc.f_qcompress);
for( mb_index = 0; mb_index < h->mb.i_mb_count; mb_index++ )
{
int intra_cost = (frame->i_intra_cost[mb_index] * frame->i_inv_qscale_factor[mb_index]+128)>>8;
......@@ -417,9 +420,7 @@ static void x264_macroblock_tree_finish( x264_t *h, x264_frame_t *frame, int b_b
{
int propagate_cost = frame->i_propagate_cost[mb_index];
float log2_ratio = x264_log2(intra_cost + propagate_cost) - x264_log2(intra_cost);
/* Allow the constant to be adjusted via qcompress, since the two
* concepts are very similar. */
frame->f_qp_offset[mb_index] = frame->f_qp_offset_aq[mb_index] - 5.0 * (1.0 - h->param.rc.f_qcompress) * log2_ratio;
frame->f_qp_offset[mb_index] = frame->f_qp_offset_aq[mb_index] - strength * log2_ratio;
}
}
}
......
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