shithub: libvpx

Download patch

ref: 639b863d2276d8100a5e585fa5ab9bf2d3983946
parent: 6dfc95fe63a52945350a7c8a234e87a4a55645db
author: Ronald S. Bultje <rbultje@google.com>
date: Wed Feb 6 12:16:36 EST 2013

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

--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -424,11 +424,11 @@
 #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 @@
   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 @@
     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 @@
     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