Remove probability model for uni_comp_ref

Change-Id: I7c09b63aadefef3350d713e03b822447c9472509
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c
index f24b7c3..3f7637c 100644
--- a/av1/common/entropymode.c
+++ b/av1/common/entropymode.c
@@ -1405,11 +1405,6 @@
             { AOM_CDF2(2842) } };
 
 #if CONFIG_EXT_COMP_REFS
-static const aom_prob
-    default_uni_comp_ref_p[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1] = {
-      { 88, 30, 28 }, { 218, 97, 105 }, { 254, 180, 196 }
-    };
-
 static const aom_cdf_prob default_comp_ref_type_cdf[COMP_REF_TYPE_CONTEXTS]
                                                    [CDF_SIZE(2)] = {
                                                      { AOM_CDF2(8 * 128) },
@@ -3280,7 +3275,6 @@
 #endif  // CONFIG_EXT_INTRA_MOD
   av1_copy(fc->comp_inter_cdf, default_comp_inter_cdf);
 #if CONFIG_EXT_COMP_REFS
-  av1_copy(fc->uni_comp_ref_prob, default_uni_comp_ref_p);
   av1_copy(fc->comp_ref_type_cdf, default_comp_ref_type_cdf);
   av1_copy(fc->uni_comp_ref_cdf, default_uni_comp_ref_cdf);
 #endif  // CONFIG_EXT_COMP_REFS
@@ -3382,13 +3376,6 @@
   const FRAME_CONTEXT *pre_fc = cm->pre_fc;
   const FRAME_COUNTS *counts = &cm->counts;
 
-#if CONFIG_EXT_COMP_REFS
-  for (i = 0; i < UNI_COMP_REF_CONTEXTS; i++)
-    for (j = 0; j < (UNIDIR_COMP_REFS - 1); j++)
-      fc->uni_comp_ref_prob[i][j] = av1_mode_mv_merge_probs(
-          pre_fc->uni_comp_ref_prob[i][j], counts->uni_comp_ref[i][j]);
-#endif  // CONFIG_EXT_COMP_REFS
-
   for (i = 0; i < REF_CONTEXTS; i++)
     for (j = 0; j < (FWD_REFS - 1); j++)
       fc->comp_ref_prob[i][j] = mode_mv_merge_probs(pre_fc->comp_ref_prob[i][j],
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index e24f492..9aa9676 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -161,7 +161,6 @@
   aom_cdf_prob comp_inter_cdf[COMP_INTER_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob single_ref_cdf[REF_CONTEXTS][SINGLE_REFS - 1][CDF_SIZE(2)];
 #if CONFIG_EXT_COMP_REFS
-  aom_prob uni_comp_ref_prob[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1];
   aom_cdf_prob comp_ref_type_cdf[COMP_REF_TYPE_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob uni_comp_ref_cdf[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1]
                                [CDF_SIZE(2)];
@@ -319,13 +318,11 @@
   unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
 #if CONFIG_ENTROPY_STATS
   unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
-#endif  // CONFIG_ENTROPY_STATS
 #if CONFIG_EXT_COMP_REFS
-#if CONFIG_ENTROPY_STATS
   unsigned int comp_ref_type[COMP_REF_TYPE_CONTEXTS][2];
-#endif  // CONFIG_ENTROPY_STATS
   unsigned int uni_comp_ref[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1][2];
 #endif  // CONFIG_EXT_COMP_REFS
+#endif  // CONFIG_ENTROPY_STATS
 #if CONFIG_ENTROPY_STATS
   unsigned int single_ref[REF_CONTEXTS][SINGLE_REFS - 1][2];
 #endif  // CONFIG_ENTROPY_STATS
diff --git a/av1/common/pred_common.h b/av1/common/pred_common.h
index 73c8f99..cd01276 100644
--- a/av1/common/pred_common.h
+++ b/av1/common/pred_common.h
@@ -202,28 +202,10 @@
 
 int av1_get_pred_context_uni_comp_ref_p(const MACROBLOCKD *xd);
 
-static INLINE aom_prob av1_get_pred_prob_uni_comp_ref_p(const AV1_COMMON *cm,
-                                                        const MACROBLOCKD *xd) {
-  const int pred_context = av1_get_pred_context_uni_comp_ref_p(xd);
-  return cm->fc->uni_comp_ref_prob[pred_context][0];
-}
-
 int av1_get_pred_context_uni_comp_ref_p1(const MACROBLOCKD *xd);
 
-static INLINE aom_prob
-av1_get_pred_prob_uni_comp_ref_p1(const AV1_COMMON *cm, const MACROBLOCKD *xd) {
-  const int pred_context = av1_get_pred_context_uni_comp_ref_p1(xd);
-  return cm->fc->uni_comp_ref_prob[pred_context][1];
-}
-
 int av1_get_pred_context_uni_comp_ref_p2(const MACROBLOCKD *xd);
 
-static INLINE aom_prob
-av1_get_pred_prob_uni_comp_ref_p2(const AV1_COMMON *cm, const MACROBLOCKD *xd) {
-  const int pred_context = av1_get_pred_context_uni_comp_ref_p2(xd);
-  return cm->fc->uni_comp_ref_prob[pred_context][2];
-}
-
 static INLINE aom_cdf_prob *av1_get_comp_reference_type_cdf(
     const MACROBLOCKD *xd) {
   const int pred_context = av1_get_comp_reference_type_context(xd);
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 8b969d3..fa2b1d9 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -3099,7 +3099,7 @@
 
 #ifdef NDEBUG
 #define debug_check_frame_counts(cm) (void)0
-#else  // !NDEBUG
+#else   // !NDEBUG
 // Counts should only be incremented when frame_parallel_decoding_mode and
 // error_resilient_mode are disabled.
 static void debug_check_frame_counts(const AV1_COMMON *const cm) {
@@ -3125,10 +3125,6 @@
                  sizeof(cm->counts.motion_mode)));
   assert(!memcmp(cm->counts.intra_inter, zero_counts.intra_inter,
                  sizeof(cm->counts.intra_inter)));
-#if CONFIG_EXT_COMP_REFS
-  assert(!memcmp(cm->counts.uni_comp_ref, zero_counts.uni_comp_ref,
-                 sizeof(cm->counts.uni_comp_ref)));
-#endif  // CONFIG_EXT_COMP_REFS
   assert(!memcmp(cm->counts.comp_ref, zero_counts.comp_ref,
                  sizeof(cm->counts.comp_ref)));
   assert(!memcmp(cm->counts.comp_bwdref, zero_counts.comp_bwdref,
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 45e7a17..4da19a7 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1336,23 +1336,14 @@
       const COMP_REFERENCE_TYPE comp_ref_type = read_comp_reference_type(xd, r);
 
       if (comp_ref_type == UNIDIR_COMP_REFERENCE) {
-        const int ctx = av1_get_pred_context_uni_comp_ref_p(xd);
         const int bit = READ_REF_BIT2(uni_comp_ref_p);
-        if (counts) ++counts->uni_comp_ref[ctx][0][bit];
-
         if (bit) {
           ref_frame[0] = BWDREF_FRAME;
           ref_frame[1] = ALTREF_FRAME;
         } else {
-          const int ctx1 = av1_get_pred_context_uni_comp_ref_p1(xd);
           const int bit1 = READ_REF_BIT2(uni_comp_ref_p1);
-          if (counts) ++counts->uni_comp_ref[ctx1][1][bit1];
-
           if (bit1) {
-            const int ctx2 = av1_get_pred_context_uni_comp_ref_p2(xd);
             const int bit2 = READ_REF_BIT2(uni_comp_ref_p2);
-            if (counts) ++counts->uni_comp_ref[ctx2][2][bit2];
-
             if (bit2) {
               ref_frame[0] = LAST_FRAME;
               ref_frame[1] = GOLDEN_FRAME;
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 7bbc201..983599c 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -288,6 +288,8 @@
 #if CONFIG_EXT_COMP_REFS
   int comp_ref_type_cost[COMP_REF_TYPE_CONTEXTS]
                         [CDF_SIZE(COMP_REFERENCE_TYPES)];
+  int uni_comp_ref_cost[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1]
+                       [CDF_SIZE(2)];
 #endif  // CONFIG_EXT_COMP_REFS
   int inter_compound_mode_cost[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES];
 #if CONFIG_JNT_COMP
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 169d7cd..5c6f861 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -912,15 +912,29 @@
 
           if (comp_ref_type == UNIDIR_COMP_REFERENCE) {
             const int bit = (ref0 == BWDREF_FRAME);
+            if (allow_update_cdf)
+              update_cdf(av1_get_pred_cdf_uni_comp_ref_p(xd), bit, 2);
+#if CONFIG_ENTROPY_STATS
             counts->uni_comp_ref[av1_get_pred_context_uni_comp_ref_p(xd)][0]
                                 [bit]++;
+#endif  // CONFIG_ENTROPY_STATS
             if (!bit) {
               const int bit1 = (ref1 == LAST3_FRAME || ref1 == GOLDEN_FRAME);
+              if (allow_update_cdf)
+                update_cdf(av1_get_pred_cdf_uni_comp_ref_p1(xd), bit1, 2);
+#if CONFIG_ENTROPY_STATS
               counts->uni_comp_ref[av1_get_pred_context_uni_comp_ref_p1(xd)][1]
                                   [bit1]++;
+#endif  // CONFIG_ENTROPY_STATS
               if (bit1) {
+                if (allow_update_cdf) {
+                  update_cdf(av1_get_pred_cdf_uni_comp_ref_p2(xd),
+                             ref1 == GOLDEN_FRAME, 2);
+                }
+#if CONFIG_ENTROPY_STATS
                 counts->uni_comp_ref[av1_get_pred_context_uni_comp_ref_p2(xd)]
                                     [2][ref1 == GOLDEN_FRAME]++;
+#endif  // CONFIG_ENTROPY_STATS
               }
             }
           } else {
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 59d2d47..7da5608 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -243,6 +243,13 @@
       av1_cost_tokens_from_cdf(x->comp_ref_type_cost[i],
                                fc->comp_ref_type_cdf[i], NULL);
     }
+
+    for (i = 0; i < UNI_COMP_REF_CONTEXTS; ++i) {
+      for (j = 0; j < UNIDIR_COMP_REFS - 1; ++j) {
+        av1_cost_tokens_from_cdf(x->uni_comp_ref_cost[i][j],
+                                 fc->uni_comp_ref_cdf[i][j], NULL);
+      }
+    }
 #endif  // CONFIG_EXT_COMP_REFS
 
     for (i = 0; i < INTRA_INTER_CONTEXTS; ++i) {
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index a172028..1593d08 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -5919,25 +5919,26 @@
         }
       }
 
-      aom_prob uni_comp_ref_p = av1_get_pred_prob_uni_comp_ref_p(cm, xd);
-      aom_prob uni_comp_ref_p1 = av1_get_pred_prob_uni_comp_ref_p1(cm, xd);
-      aom_prob uni_comp_ref_p2 = av1_get_pred_prob_uni_comp_ref_p2(cm, xd);
-
+      const int uni_comp_ref_ctx_p = av1_get_pred_context_uni_comp_ref_p(xd);
+      const int uni_comp_ref_ctx_p1 = av1_get_pred_context_uni_comp_ref_p1(xd);
+      const int uni_comp_ref_ctx_p2 = av1_get_pred_context_uni_comp_ref_p2(xd);
       ref_costs_comp[LAST_FRAME][LAST2_FRAME] =
           base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][0] +
-          av1_cost_bit(uni_comp_ref_p, 0) + av1_cost_bit(uni_comp_ref_p1, 0);
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p][0][0] +
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p1][1][0];
       ref_costs_comp[LAST_FRAME][LAST3_FRAME] =
           base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][0] +
-          av1_cost_bit(uni_comp_ref_p, 0) + av1_cost_bit(uni_comp_ref_p1, 1) +
-          av1_cost_bit(uni_comp_ref_p2, 0);
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p][0][0] +
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p1][1][1] +
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p2][2][0];
       ref_costs_comp[LAST_FRAME][GOLDEN_FRAME] =
           base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][0] +
-          av1_cost_bit(uni_comp_ref_p, 0) + av1_cost_bit(uni_comp_ref_p1, 1) +
-          av1_cost_bit(uni_comp_ref_p2, 1);
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p][0][0] +
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p1][1][1] +
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p2][2][1];
       ref_costs_comp[BWDREF_FRAME][ALTREF_FRAME] =
           base_cost + x->comp_ref_type_cost[comp_ref_type_ctx][0] +
-          av1_cost_bit(uni_comp_ref_p, 1);
-
+          x->uni_comp_ref_cost[uni_comp_ref_ctx_p][0][1];
 #else   // !CONFIG_EXT_COMP_REFS
 
       ref_costs_comp[LAST_FRAME] = ref_costs_comp[LAST2_FRAME] =