Using 128 entry look up table for coef models
authorDeb Mukherjee <debargha@google.com>
Wed, 22 May 2013 14:28:29 +0000 (07:28 -0700)
committerDeb Mukherjee <debargha@google.com>
Wed, 22 May 2013 15:44:31 +0000 (08:44 -0700)
Reverts to using 128 bit LUT for the coef models rather than 48
to ease hardware implementation.

Also incorporates some cleanups including removing various
hooks to support different lookup tables based on block_type and
ref_type.

Change-Id: I54100c120cca07a2ebd3a7776bc4630fa6a153f6

vp9/common/vp9_entropy.c
vp9/common/vp9_entropy.h
vp9/decoder/vp9_detokenize.c
vp9/encoder/vp9_bitstream.c
vp9/encoder/vp9_rdopt.c
vp9/encoder/vp9_tokenize.c
vp9/encoder/vp9_tokenize.h

index 1f1c5d9..b7860e0 100644 (file)
@@ -423,111 +423,166 @@ const vp9_tree_index vp9_coefmodel_tree[6] = {
 
 // beta = 8
 const vp9_prob vp9_modelcoefprobs_pareto8[COEFPROB_MODELS][MODEL_NODES] = {
-  {   3,  86, 128,   6,  86,  23,  88,  29},
-  {   9,  86, 129,  17,  88,  61,  94,  76},
-  {  20,  88, 130,  38,  91, 118, 106, 136},
-  {  31,  90, 131,  58,  94, 156, 117, 171},
-  {  42,  91, 132,  75,  97, 183, 127, 194},
-  {  52,  93, 133,  90, 100, 201, 137, 208},
-  {  62,  94, 135, 105, 103, 214, 146, 218},
-  {  71,  96, 136, 117, 106, 224, 155, 225},
-  {  80,  98, 137, 129, 109, 231, 162, 231},
-  {  89,  99, 138, 140, 112, 236, 170, 235},
-  {  97, 101, 140, 149, 115, 240, 176, 238},
-  { 105, 103, 141, 158, 118, 243, 182, 240},
-  { 113, 104, 142, 166, 120, 245, 187, 242},
-  { 120, 106, 143, 173, 123, 247, 192, 244},
-  { 127, 108, 145, 180, 126, 249, 197, 245},
-  { 134, 110, 146, 186, 129, 250, 201, 246},
-  { 140, 112, 147, 192, 132, 251, 205, 247},
-  { 146, 114, 149, 197, 135, 252, 208, 248},
-  { 152, 115, 150, 201, 138, 252, 211, 248},
-  { 158, 117, 151, 206, 140, 253, 214, 249},
-  { 163, 119, 153, 210, 143, 253, 217, 249},
-  { 168, 121, 154, 213, 146, 254, 220, 250},
-  { 173, 123, 155, 217, 148, 254, 222, 250},
-  { 178, 125, 157, 220, 151, 254, 224, 251},
-  { 183, 127, 158, 222, 153, 254, 226, 251},
-  { 187, 129, 160, 225, 156, 255, 228, 251},
-  { 191, 132, 161, 227, 159, 255, 229, 251},
-  { 195, 134, 163, 230, 161, 255, 231, 252},
-  { 199, 136, 164, 232, 163, 255, 232, 252},
-  { 202, 138, 166, 233, 166, 255, 233, 252},
-  { 206, 140, 167, 235, 168, 255, 235, 252},
-  { 212, 145, 170, 238, 173, 255, 237, 252},
-  { 218, 149, 173, 241, 177, 255, 239, 253},
-  { 223, 154, 177, 243, 182, 255, 240, 253},
-  { 228, 159, 180, 245, 186, 255, 242, 253},
-  { 232, 164, 184, 247, 190, 255, 243, 253},
-  { 236, 169, 187, 248, 194, 255, 244, 253},
-  { 239, 174, 191, 249, 198, 255, 245, 254},
-  { 242, 179, 195, 250, 202, 255, 246, 254},
-  { 244, 185, 199, 251, 206, 255, 247, 254},
-  { 247, 191, 203, 252, 209, 255, 248, 254},
-  { 249, 197, 207, 253, 213, 255, 249, 254},
-  { 250, 203, 212, 253, 216, 255, 249, 254},
-  { 252, 209, 217, 254, 220, 255, 250, 254},
-  { 253, 216, 222, 254, 224, 255, 251, 254},
-  { 254, 224, 228, 255, 227, 255, 251, 254},
-  { 255, 232, 235, 255, 232, 255, 252, 254},
-  { 255, 246, 247, 255, 239, 255, 253, 255}
-};
-
-void vp9_get_model_distribution(vp9_prob p, vp9_prob *tree_probs,
-                                int b, int r) {
+  {  3,  86, 128,   6,  86,  23,  88,  29},
+  {  9,  86, 129,  17,  88,  61,  94,  76},
+  { 15,  87, 129,  28,  89,  93, 100, 110},
+  { 20,  88, 130,  38,  91, 118, 106, 136},
+  { 26,  89, 131,  48,  92, 139, 111, 156},
+  { 31,  90, 131,  58,  94, 156, 117, 171},
+  { 37,  90, 132,  66,  95, 171, 122, 184},
+  { 42,  91, 132,  75,  97, 183, 127, 194},
+  { 47,  92, 133,  83,  98, 193, 132, 202},
+  { 52,  93, 133,  90, 100, 201, 137, 208},
+  { 57,  94, 134,  98, 101, 208, 142, 214},
+  { 62,  94, 135, 105, 103, 214, 146, 218},
+  { 66,  95, 135, 111, 104, 219, 151, 222},
+  { 71,  96, 136, 117, 106, 224, 155, 225},
+  { 76,  97, 136, 123, 107, 227, 159, 228},
+  { 80,  98, 137, 129, 109, 231, 162, 231},
+  { 84,  98, 138, 134, 110, 234, 166, 233},
+  { 89,  99, 138, 140, 112, 236, 170, 235},
+  { 93, 100, 139, 145, 113, 238, 173, 236},
+  { 97, 101, 140, 149, 115, 240, 176, 238},
+  {101, 102, 140, 154, 116, 242, 179, 239},
+  {105, 103, 141, 158, 118, 243, 182, 240},
+  {109, 104, 141, 162, 119, 244, 185, 241},
+  {113, 104, 142, 166, 120, 245, 187, 242},
+  {116, 105, 143, 170, 122, 246, 190, 243},
+  {120, 106, 143, 173, 123, 247, 192, 244},
+  {123, 107, 144, 177, 125, 248, 195, 244},
+  {127, 108, 145, 180, 126, 249, 197, 245},
+  {130, 109, 145, 183, 128, 249, 199, 245},
+  {134, 110, 146, 186, 129, 250, 201, 246},
+  {137, 111, 147, 189, 131, 251, 203, 246},
+  {140, 112, 147, 192, 132, 251, 205, 247},
+  {143, 113, 148, 194, 133, 251, 207, 247},
+  {146, 114, 149, 197, 135, 252, 208, 248},
+  {149, 115, 149, 199, 136, 252, 210, 248},
+  {152, 115, 150, 201, 138, 252, 211, 248},
+  {155, 116, 151, 204, 139, 253, 213, 249},
+  {158, 117, 151, 206, 140, 253, 214, 249},
+  {161, 118, 152, 208, 142, 253, 216, 249},
+  {163, 119, 153, 210, 143, 253, 217, 249},
+  {166, 120, 153, 212, 144, 254, 218, 250},
+  {168, 121, 154, 213, 146, 254, 220, 250},
+  {171, 122, 155, 215, 147, 254, 221, 250},
+  {173, 123, 155, 217, 148, 254, 222, 250},
+  {176, 124, 156, 218, 150, 254, 223, 250},
+  {178, 125, 157, 220, 151, 254, 224, 251},
+  {180, 126, 157, 221, 152, 254, 225, 251},
+  {183, 127, 158, 222, 153, 254, 226, 251},
+  {185, 128, 159, 224, 155, 255, 227, 251},
+  {187, 129, 160, 225, 156, 255, 228, 251},
+  {189, 131, 160, 226, 157, 255, 228, 251},
+  {191, 132, 161, 227, 159, 255, 229, 251},
+  {193, 133, 162, 228, 160, 255, 230, 252},
+  {195, 134, 163, 230, 161, 255, 231, 252},
+  {197, 135, 163, 231, 162, 255, 231, 252},
+  {199, 136, 164, 232, 163, 255, 232, 252},
+  {201, 137, 165, 233, 165, 255, 233, 252},
+  {202, 138, 166, 233, 166, 255, 233, 252},
+  {204, 139, 166, 234, 167, 255, 234, 252},
+  {206, 140, 167, 235, 168, 255, 235, 252},
+  {207, 141, 168, 236, 169, 255, 235, 252},
+  {209, 142, 169, 237, 171, 255, 236, 252},
+  {210, 144, 169, 237, 172, 255, 236, 252},
+  {212, 145, 170, 238, 173, 255, 237, 252},
+  {214, 146, 171, 239, 174, 255, 237, 253},
+  {215, 147, 172, 240, 175, 255, 238, 253},
+  {216, 148, 173, 240, 176, 255, 238, 253},
+  {218, 149, 173, 241, 177, 255, 239, 253},
+  {219, 150, 174, 241, 179, 255, 239, 253},
+  {220, 152, 175, 242, 180, 255, 240, 253},
+  {222, 153, 176, 242, 181, 255, 240, 253},
+  {223, 154, 177, 243, 182, 255, 240, 253},
+  {224, 155, 178, 244, 183, 255, 241, 253},
+  {225, 156, 178, 244, 184, 255, 241, 253},
+  {226, 158, 179, 244, 185, 255, 242, 253},
+  {228, 159, 180, 245, 186, 255, 242, 253},
+  {229, 160, 181, 245, 187, 255, 242, 253},
+  {230, 161, 182, 246, 188, 255, 243, 253},
+  {231, 163, 183, 246, 189, 255, 243, 253},
+  {232, 164, 184, 247, 190, 255, 243, 253},
+  {233, 165, 185, 247, 191, 255, 244, 253},
+  {234, 166, 185, 247, 192, 255, 244, 253},
+  {235, 168, 186, 248, 193, 255, 244, 253},
+  {236, 169, 187, 248, 194, 255, 244, 253},
+  {236, 170, 188, 248, 195, 255, 245, 253},
+  {237, 171, 189, 249, 196, 255, 245, 254},
+  {238, 173, 190, 249, 197, 255, 245, 254},
+  {239, 174, 191, 249, 198, 255, 245, 254},
+  {240, 175, 192, 249, 199, 255, 246, 254},
+  {240, 177, 193, 250, 200, 255, 246, 254},
+  {241, 178, 194, 250, 201, 255, 246, 254},
+  {242, 179, 195, 250, 202, 255, 246, 254},
+  {242, 181, 196, 250, 203, 255, 247, 254},
+  {243, 182, 197, 251, 204, 255, 247, 254},
+  {244, 184, 198, 251, 205, 255, 247, 254},
+  {244, 185, 199, 251, 206, 255, 247, 254},
+  {245, 186, 200, 251, 207, 255, 247, 254},
+  {246, 188, 201, 252, 207, 255, 248, 254},
+  {246, 189, 202, 252, 208, 255, 248, 254},
+  {247, 191, 203, 252, 209, 255, 248, 254},
+  {247, 192, 204, 252, 210, 255, 248, 254},
+  {248, 194, 205, 252, 211, 255, 248, 254},
+  {248, 195, 206, 252, 212, 255, 249, 254},
+  {249, 197, 207, 253, 213, 255, 249, 254},
+  {249, 198, 208, 253, 214, 255, 249, 254},
+  {250, 200, 210, 253, 215, 255, 249, 254},
+  {250, 201, 211, 253, 215, 255, 249, 254},
+  {250, 203, 212, 253, 216, 255, 249, 254},
+  {251, 204, 213, 253, 217, 255, 250, 254},
+  {251, 206, 214, 254, 218, 255, 250, 254},
+  {252, 207, 216, 254, 219, 255, 250, 254},
+  {252, 209, 217, 254, 220, 255, 250, 254},
+  {252, 211, 218, 254, 221, 255, 250, 254},
+  {253, 213, 219, 254, 222, 255, 250, 254},
+  {253, 214, 221, 254, 223, 255, 250, 254},
+  {253, 216, 222, 254, 224, 255, 251, 254},
+  {253, 218, 224, 254, 225, 255, 251, 254},
+  {254, 220, 225, 254, 225, 255, 251, 254},
+  {254, 222, 227, 255, 226, 255, 251, 254},
+  {254, 224, 228, 255, 227, 255, 251, 254},
+  {254, 226, 230, 255, 228, 255, 251, 254},
+  {255, 228, 231, 255, 230, 255, 251, 254},
+  {255, 230, 233, 255, 231, 255, 252, 254},
+  {255, 232, 235, 255, 232, 255, 252, 254},
+  {255, 235, 237, 255, 233, 255, 252, 254},
+  {255, 238, 240, 255, 235, 255, 252, 255},
+  {255, 241, 243, 255, 236, 255, 252, 254},
+  {255, 246, 247, 255, 239, 255, 253, 255}
+};
+
+static void extend_model_to_full_distribution(vp9_prob p,
+                                              vp9_prob *tree_probs) {
+  const int l = ((p - 1) / 2);
   const vp9_prob (*model)[MODEL_NODES];
   model = vp9_modelcoefprobs_pareto8;
-  if (p == 1) {
+  if (p & 1) {
     vpx_memcpy(tree_probs + UNCONSTRAINED_NODES,
-               model[2], MODEL_NODES * sizeof(vp9_prob));
-  } else if (p == 2) {
+               model[l], MODEL_NODES * sizeof(vp9_prob));
+  } else {
     // interpolate
     int i;
     for (i = UNCONSTRAINED_NODES; i < ENTROPY_NODES; ++i)
-      tree_probs[i] = (model[0][i - UNCONSTRAINED_NODES] +
-                       model[1][i - UNCONSTRAINED_NODES]) >> 1;
-  } else if (p < 119) {
-    // interpolate
-    int i, k, l;
-    k = (p - 3) & 3;
-    l = ((p - 3) >> 2) + 1;
-    if (k) {
-      for (i = UNCONSTRAINED_NODES; i < ENTROPY_NODES; ++i)
-        tree_probs[i] = (model[l][i - UNCONSTRAINED_NODES] * (4 - k) +
-                         model[l + 1][i - UNCONSTRAINED_NODES] * k + 1) >> 2;
-    } else {
-      vpx_memcpy(tree_probs + UNCONSTRAINED_NODES,
-                 model[l], MODEL_NODES * sizeof(vp9_prob));
-    }
-  } else {
-    // interpolate
-    int i, k, l;
-    k = (p - 119) & 7;
-    l = ((p - 119) >> 3) + 30;
-    if (k) {
-      for (i = UNCONSTRAINED_NODES; i < ENTROPY_NODES; ++i)
-        tree_probs[i] = (model[l][i - UNCONSTRAINED_NODES] * (8 - k) +
-                         model[l + 1][i - UNCONSTRAINED_NODES] * k + 3) >> 3;
-    } else {
-      vpx_memcpy(tree_probs + UNCONSTRAINED_NODES,
-                 model[l], MODEL_NODES * sizeof(vp9_prob));
-    }
+      tree_probs[i] = (model[l][i - UNCONSTRAINED_NODES] +
+                       model[l + 1][i - UNCONSTRAINED_NODES]) >> 1;
   }
 }
 
-void vp9_model_to_full_probs(const vp9_prob *model, int b, int r, vp9_prob *full) {
-  vpx_memcpy(full, model, sizeof(vp9_prob) * UNCONSTRAINED_NODES);
-  vp9_get_model_distribution(model[PIVOT_NODE], full, b, r);
+void vp9_model_to_full_probs(const vp9_prob *model, vp9_prob *full) {
+  if (full != model)
+    vpx_memcpy(full, model, sizeof(vp9_prob) * UNCONSTRAINED_NODES);
+  extend_model_to_full_distribution(model[PIVOT_NODE], full);
 }
 
 void vp9_model_to_full_probs_sb(
     vp9_prob model[COEF_BANDS][PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES],
-    int b, int r,
     vp9_prob full[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]) {
   int c, p;
   for (c = 0; c < COEF_BANDS; ++c)
     for (p = 0; p < PREV_COEF_CONTEXTS; ++p) {
-      vp9_model_to_full_probs(model[c][p], b, r, full[c][p]);
+      vp9_model_to_full_probs(model[c][p], full[c][p]);
     }
 }
 
index 068719e..8794b85 100644 (file)
@@ -155,13 +155,11 @@ extern int vp9_get_coef_context(const int *scan, const int *neighbors,
 const int *vp9_get_coef_neighbors_handle(const int *scan, int *pad);
 
 
-// 48 lists of probabilities are stored for the following ONE node probs:
-// 1, (count 1)
-// 3, 7, 11, 15, ..., 115, 119, (count 30)
-// 127, 135, 143, ..., 247, 255 (count 17)
+// 128 lists of probabilities are stored for the following ONE node probs:
+// 1, 3, 5, 7, ..., 253, 255
 // In between probabilities are interpolated linearly
 
-#define COEFPROB_MODELS             48
+#define COEFPROB_MODELS             128
 
 #define UNCONSTRAINED_NODES         3
 #define MODEL_NODES                 (ENTROPY_NODES - UNCONSTRAINED_NODES)
@@ -180,16 +178,13 @@ typedef unsigned int vp9_coeff_stats_model[REF_TYPES][COEF_BANDS]
 extern void vp9_full_to_model_counts(
     vp9_coeff_count_model *model_count, vp9_coeff_count *full_count);
 
-void vp9_model_to_full_probs(const vp9_prob *model, int b, int r, vp9_prob *full);
+void vp9_model_to_full_probs(const vp9_prob *model, vp9_prob *full);
 
 void vp9_model_to_full_probs_sb(
     vp9_prob model[COEF_BANDS][PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES],
-    int b, int r,
     vp9_prob full[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]);
 
 extern const vp9_prob vp9_modelcoefprobs[COEFPROB_MODELS][ENTROPY_NODES - 1];
-void vp9_get_model_distribution(vp9_prob model, vp9_prob *tree_probs,
-                                int b, int r);
 
 static INLINE const int* get_scan_4x4(TX_TYPE tx_type) {
   switch (tx_type) {
index 1b0991b..546de5f 100644 (file)
@@ -206,7 +206,7 @@ SKIP_START:
     }
     // Load full probabilities if not already loaded
     if (!load_map[band][pt]) {
-      vp9_model_to_full_probs(coef_probs[band][pt], type, ref,
+      vp9_model_to_full_probs(coef_probs[band][pt],
                               coef_probs_full[band][pt]);
       load_map[band][pt] = 1;
     }
index 9f32680..c3de1c9 100644 (file)
@@ -420,7 +420,8 @@ static int prob_diff_update_savings_search_model(const unsigned int *ct,
   int i, old_b, new_b, update_b, savings, bestsavings, step;
   int newp;
   vp9_prob bestnewp, newplist[ENTROPY_NODES], oldplist[ENTROPY_NODES];
-  vp9_model_to_full_probs(oldp, b, r, oldplist);
+  vp9_model_to_full_probs(oldp, oldplist);
+  vpx_memcpy(newplist, oldp, sizeof(vp9_prob) * UNCONSTRAINED_NODES);
   for (i = UNCONSTRAINED_NODES, old_b = 0; i < ENTROPY_NODES; ++i)
     old_b += cost_branch256(ct + 2 * i, oldplist[i]);
   old_b += cost_branch256(ct + 2 * PIVOT_NODE, oldplist[PIVOT_NODE]);
@@ -433,7 +434,7 @@ static int prob_diff_update_savings_search_model(const unsigned int *ct,
   for (; newp != oldp[PIVOT_NODE]; newp += step) {
     if (newp < 1 || newp > 255) continue;
     newplist[PIVOT_NODE] = newp;
-    vp9_get_model_distribution(newp, newplist, b, r);
+    vp9_model_to_full_probs(newplist, newplist);
     for (i = UNCONSTRAINED_NODES, new_b = 0; i < ENTROPY_NODES; ++i)
       new_b += cost_branch256(ct + 2 * i, newplist[i]);
     new_b += cost_branch256(ct + 2 * PIVOT_NODE, newplist[PIVOT_NODE]);
@@ -485,8 +486,7 @@ static void pack_mb_tokens(vp9_writer* const bc,
       break;
     }
     if (t >= TWO_TOKEN) {
-      vp9_model_to_full_probs(p->context_tree,
-                              p->block_type, p->ref_type, probs);
+      vp9_model_to_full_probs(p->context_tree, probs);
       pp = probs;
     } else {
       pp = p->context_tree;
index ea57319..5fe3fee 100644 (file)
@@ -115,7 +115,7 @@ static void fill_token_costs(vp9_coeff_count *c,
       for (k = 0; k < COEF_BANDS; k++)
         for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
           vp9_prob probs[ENTROPY_NODES];
-          vp9_model_to_full_probs(p[i][j][k][l], i, j, probs);
+          vp9_model_to_full_probs(p[i][j][k][l], probs);
           vp9_cost_tokens_skip((int *)c[i][j][k][l], probs,
                                vp9_coef_tree);
         }
@@ -292,7 +292,7 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
       above_ec = A[0] != 0;
       left_ec = L[0] != 0;
       vp9_model_to_full_probs_sb(cm->fc.coef_probs_4x4[type][ref],
-                                 type, ref, coef_probs);
+                                 coef_probs);
       seg_eob = 16;
       scan = get_scan_4x4(tx_type);
       band_translate = vp9_coefband_trans_4x4;
@@ -308,7 +308,7 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
       left_ec = (L[0] + L[1]) != 0;
       scan = get_scan_8x8(tx_type);
       vp9_model_to_full_probs_sb(cm->fc.coef_probs_8x8[type][ref],
-                                 type, ref, coef_probs);
+                                 coef_probs);
       seg_eob = 64;
       band_translate = vp9_coefband_trans_8x8plus;
       break;
@@ -321,7 +321,7 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
           get_tx_type_16x16(xd, y + (x >> 2)) : DCT_DCT;
       scan = get_scan_16x16(tx_type);
       vp9_model_to_full_probs_sb(cm->fc.coef_probs_16x16[type][ref],
-                                 type, ref, coef_probs);
+                                 coef_probs);
       seg_eob = 256;
       above_ec = (A[0] + A[1] + A[2] + A[3]) != 0;
       left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
@@ -331,7 +331,7 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
     case TX_32X32:
       scan = vp9_default_zig_zag1d_32x32;
       vp9_model_to_full_probs_sb(cm->fc.coef_probs_32x32[type][ref],
-                                 type, ref, coef_probs);
+                                 coef_probs);
       seg_eob = 1024;
       above_ec = (A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] + A[7]) != 0;
       left_ec = (L[0] + L[1] + L[2] + L[3] + L[4] + L[5] + L[6] + L[7]) != 0;
index 87bde28..a1991b6 100644 (file)
@@ -224,8 +224,6 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
 
     t->token = token;
     t->context_tree = coef_probs[type][ref][band][pt];
-    t->block_type = type;
-    t->ref_type = ref;
     t->skip_eob_node = (c > 0) && (token_cache[scan[c - 1]] == 0);
     assert(vp9_coef_encodings[t->token].len - t->skip_eob_node > 0);
 
index 3332dad..08236c4 100644 (file)
@@ -26,8 +26,6 @@ typedef struct {
   int16_t         extra;
   uint8_t         token;
   uint8_t         skip_eob_node;
-  uint8_t         block_type;
-  uint8_t         ref_type;
 } TOKENEXTRA;
 
 typedef int64_t vp9_coeff_accum[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]