]> granicus.if.org Git - libvpx/commitdiff
Make cost_coeffs() more efficient.
authorRonald S. Bultje <rbultje@google.com>
Thu, 7 Feb 2013 01:16:36 +0000 (17:16 -0800)
committerRonald S. Bultje <rbultje@google.com>
Sat, 9 Feb 2013 00:32:24 +0000 (16:32 -0800)
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

index 370374164cfd9fccd646a5d4f475057719e2eb85..e45e8d692d942c098acdbe2d7f8697a55dffd2e5 100644 (file)
@@ -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