From 639b863d2276d8100a5e585fa5ab9bf2d3983946 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 6 Feb 2013 17:16:36 -0800 Subject: [PATCH] Make cost_coeffs() more efficient. Cache the constant offset in one variable to prevent re-loading that in each loop iteration, and mark the function as inline so we can use the fact that the transform size is always known in the caller. Almost 1% faster encoding overall. Change-Id: Id78325a60b025057d8f4ecd9003a74086ccbf85a --- vp9/encoder/vp9_rdopt.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 3703741..e45e8d6 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -424,11 +424,11 @@ int vp9_uvsse(MACROBLOCK *x) { #else #define PT pt #endif -static int cost_coeffs(MACROBLOCK *mb, - BLOCKD *b, PLANE_TYPE type, - ENTROPY_CONTEXT *a, - ENTROPY_CONTEXT *l, - TX_SIZE tx_size) { +static INLINE int cost_coeffs(MACROBLOCK *mb, + BLOCKD *b, PLANE_TYPE type, + ENTROPY_CONTEXT *a, + ENTROPY_CONTEXT *l, + TX_SIZE tx_size) { int pt; const int eob = b->eob; MACROBLOCKD *xd = &mb->e_mbd; @@ -440,6 +440,9 @@ static int cost_coeffs(MACROBLOCK *mb, int16_t *qcoeff_ptr = b->qcoeff; const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? get_tx_type(xd, b) : DCT_DCT; + unsigned int (*token_costs)[PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS] = + (tx_type == DCT_DCT) ? mb->token_costs[tx_size][type] : + mb->hybrid_token_costs[tx_size][type]; #if CONFIG_NEWCOEFCONTEXT const int *neighbors; int pn; @@ -504,7 +507,7 @@ static int cost_coeffs(MACROBLOCK *mb, for (; c < eob; c++) { int v = qcoeff_ptr[scan[c]]; int t = vp9_dct_value_tokens_ptr[v].Token; - cost += mb->hybrid_token_costs[tx_size][type][band[c]][PT][t]; + cost += token_costs[band[c]][PT][t]; cost += vp9_dct_value_cost_ptr[v]; pt = vp9_prev_token_class[t]; #if CONFIG_NEWCOEFCONTEXT @@ -522,7 +525,7 @@ static int cost_coeffs(MACROBLOCK *mb, for (; c < eob; c++) { int v = qcoeff_ptr[scan[c]]; int t = vp9_dct_value_tokens_ptr[v].Token; - cost += mb->token_costs[tx_size][type][band[c]][pt][t]; + cost += token_costs[band[c]][pt][t]; cost += vp9_dct_value_cost_ptr[v]; pt = vp9_prev_token_class[t]; #if CONFIG_NEWCOEFCONTEXT -- 2.7.4