unpoison_partition_ctx: Move the fake context to the end

It's less invasive and helps make future changes easier.

Change-Id: I0f858462f14109ace4d76a31daeac4289c94bc6e
diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h
index 7caeb1c..67a587b 100644
--- a/av1/common/onyxc_int.h
+++ b/av1/common/onyxc_int.h
@@ -792,7 +792,7 @@
   else if (!has_rows && has_cols)
     return PARTITION_CONTEXTS_PRIMARY + PARTITION_BLOCK_SIZES + bsl;
   else
-    return -1;  // Bogus context, forced SPLIT
+    return PARTITION_CONTEXTS;  // Bogus context, forced SPLIT
 #else
   const PARTITION_CONTEXT *above_ctx = xd->above_seg_context + mi_col;
   const PARTITION_CONTEXT *left_ctx =
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index cb7e27c..c2f4f11 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -1961,8 +1961,9 @@
 #if CONFIG_UNPOISON_PARTITION_CTX
   const int ctx =
       partition_plane_context(xd, mi_row, mi_col, has_rows, has_cols, bsize);
-  const aom_prob *const probs = ctx >= 0 ? cm->fc->partition_prob[ctx] : NULL;
-  FRAME_COUNTS *const counts = ctx >= 0 ? xd->counts : NULL;
+  const aom_prob *const probs =
+      ctx < PARTITION_CONTEXTS ? cm->fc->partition_prob[ctx] : NULL;
+  FRAME_COUNTS *const counts = ctx < PARTITION_CONTEXTS ? xd->counts : NULL;
 #else
   const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
   const aom_prob *const probs = cm->fc->partition_prob[ctx];
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 357a41b..2bd6291 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -2533,7 +2533,8 @@
                                                 bsize)
                       : 0;
 #if CONFIG_UNPOISON_PARTITION_CTX
-  const aom_prob *const probs = ctx >= 0 ? cm->fc->partition_prob[ctx] : NULL;
+  const aom_prob *const probs =
+      ctx < PARTITION_CONTEXTS ? cm->fc->partition_prob[ctx] : NULL;
 #else
   const aom_prob *const probs = cm->fc->partition_prob[ctx];
 #endif
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 73b6fe8..0701aaf 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -2843,14 +2843,11 @@
                        bsize, ctx_none, INT64_MAX);
 
       if (none_rdc.rate < INT_MAX) {
-        none_rdc.rate += cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX]
-                                            [PARTITION_NONE];
+        none_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
         none_rdc.rdcost =
             RDCOST(x->rdmult, x->rddiv, none_rdc.rate, none_rdc.dist);
 #if CONFIG_SUPERTX
-        none_rate_nocoef +=
-            cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX]
-                               [PARTITION_NONE];
+        none_rate_nocoef += cpi->partition_cost[pl][PARTITION_NONE];
 #endif
       }
 
@@ -3024,13 +3021,11 @@
   }
 
   if (last_part_rdc.rate < INT_MAX) {
-    last_part_rdc.rate +=
-        cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX][partition];
+    last_part_rdc.rate += cpi->partition_cost[pl][partition];
     last_part_rdc.rdcost =
         RDCOST(x->rdmult, x->rddiv, last_part_rdc.rate, last_part_rdc.dist);
 #if CONFIG_SUPERTX
-    last_part_rate_nocoef +=
-        cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX][partition];
+    last_part_rate_nocoef += cpi->partition_cost[pl][partition];
 #endif
   }
 
@@ -3105,23 +3100,17 @@
         encode_sb(cpi, td, tile_info, tp, mi_row + y_idx, mi_col + x_idx,
                   OUTPUT_ENABLED, split_subsize, pc_tree->split[i], NULL);
 
-      chosen_rdc.rate += cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX]
-                                            [PARTITION_NONE];
+      chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
 #if CONFIG_SUPERTX
-      chosen_rate_nocoef +=
-          cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX]
-                             [PARTITION_SPLIT];
+      chosen_rate_nocoef += cpi->partition_cost[pl][PARTITION_SPLIT];
 #endif
     }
     if (chosen_rdc.rate < INT_MAX) {
-      chosen_rdc.rate += cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX]
-                                            [PARTITION_SPLIT];
+      chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT];
       chosen_rdc.rdcost =
           RDCOST(x->rdmult, x->rddiv, chosen_rdc.rate, chosen_rdc.dist);
 #if CONFIG_SUPERTX
-      chosen_rate_nocoef +=
-          cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX]
-                             [PARTITION_NONE];
+      chosen_rate_nocoef += cpi->partition_cost[pl][PARTITION_NONE];
 #endif
     }
   }
@@ -3643,13 +3632,11 @@
                                          has_rows, has_cols,
 #endif
                                          bsize);
-        sum_rdc.rate +=
-            cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX][partition];
+        sum_rdc.rate += cpi->partition_cost[pl][partition];
         sum_rdc.rdcost =
             RDCOST(x->rdmult, x->rddiv, sum_rdc.rate, sum_rdc.dist);
 #if CONFIG_SUPERTX
-        sum_rate_nocoef +=
-            cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX][partition];
+        sum_rate_nocoef += cpi->partition_cost[pl][partition];
 #endif
         if (sum_rdc.rdcost < best_rdc->rdcost) {
 #if CONFIG_SUPERTX
@@ -3712,8 +3699,7 @@
 #endif
                                          bsize);
 #endif  // CONFIG_CB4X4
-  const int *partition_cost =
-      cpi->partition_cost[pl + CONFIG_UNPOISON_PARTITION_CTX];
+  const int *partition_cost = cpi->partition_cost[pl];
 #if CONFIG_SUPERTX
   int this_rate_nocoef, sum_rate_nocoef = 0, best_rate_nocoef = INT_MAX;
   int abort_flag;
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index fff0176..417f15c 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -398,42 +398,40 @@
 
     if (cpi->sf.partition_search_type != VAR_BASED_PARTITION ||
         cm->frame_type == KEY_FRAME) {
-#if CONFIG_UNPOISON_PARTITION_CTX
-      cpi->partition_cost[0][PARTITION_NONE] = INT_MAX;
-      cpi->partition_cost[0][PARTITION_HORZ] = INT_MAX;
-      cpi->partition_cost[0][PARTITION_VERT] = INT_MAX;
-      cpi->partition_cost[0][PARTITION_SPLIT] = 0;
-#endif
 #if CONFIG_EXT_PARTITION_TYPES
       for (i = 0; i < PARTITION_PLOFFSET; ++i)
-        av1_cost_tokens(cpi->partition_cost[CONFIG_UNPOISON_PARTITION_CTX + i],
-                        cm->fc->partition_prob[i], av1_partition_tree);
+        av1_cost_tokens(cpi->partition_cost[i], cm->fc->partition_prob[i],
+                        av1_partition_tree);
       for (; i < PARTITION_CONTEXTS_PRIMARY; ++i)
-        av1_cost_tokens(cpi->partition_cost[CONFIG_UNPOISON_PARTITION_CTX + i],
-                        cm->fc->partition_prob[i], av1_ext_partition_tree);
+        av1_cost_tokens(cpi->partition_cost[i], cm->fc->partition_prob[i],
+                        av1_ext_partition_tree);
 #else
       for (i = 0; i < PARTITION_CONTEXTS_PRIMARY; ++i)
-        av1_cost_tokens(cpi->partition_cost[CONFIG_UNPOISON_PARTITION_CTX + i],
-                        cm->fc->partition_prob[i], av1_partition_tree);
+        av1_cost_tokens(cpi->partition_cost[i], cm->fc->partition_prob[i],
+                        av1_partition_tree);
 #endif  // CONFIG_EXT_PARTITION_TYPES
 #if CONFIG_UNPOISON_PARTITION_CTX
       for (; i < PARTITION_CONTEXTS_PRIMARY + PARTITION_BLOCK_SIZES; ++i) {
         aom_prob p = cm->fc->partition_prob[i][PARTITION_VERT];
         assert(p > 0);
-        cpi->partition_cost[1 + i][PARTITION_NONE] = INT_MAX;
-        cpi->partition_cost[1 + i][PARTITION_HORZ] = INT_MAX;
-        cpi->partition_cost[1 + i][PARTITION_VERT] = av1_cost_bit(p, 0);
-        cpi->partition_cost[1 + i][PARTITION_SPLIT] = av1_cost_bit(p, 1);
+        cpi->partition_cost[i][PARTITION_NONE] = INT_MAX;
+        cpi->partition_cost[i][PARTITION_HORZ] = INT_MAX;
+        cpi->partition_cost[i][PARTITION_VERT] = av1_cost_bit(p, 0);
+        cpi->partition_cost[i][PARTITION_SPLIT] = av1_cost_bit(p, 1);
       }
       for (; i < PARTITION_CONTEXTS_PRIMARY + 2 * PARTITION_BLOCK_SIZES; ++i) {
         aom_prob p = cm->fc->partition_prob[i][PARTITION_HORZ];
         assert(p > 0);
-        cpi->partition_cost[1 + i][PARTITION_NONE] = INT_MAX;
-        cpi->partition_cost[1 + i][PARTITION_HORZ] = av1_cost_bit(p, 0);
-        cpi->partition_cost[1 + i][PARTITION_VERT] = INT_MAX;
-        cpi->partition_cost[1 + i][PARTITION_SPLIT] = av1_cost_bit(p, 1);
+        cpi->partition_cost[i][PARTITION_NONE] = INT_MAX;
+        cpi->partition_cost[i][PARTITION_HORZ] = av1_cost_bit(p, 0);
+        cpi->partition_cost[i][PARTITION_VERT] = INT_MAX;
+        cpi->partition_cost[i][PARTITION_SPLIT] = av1_cost_bit(p, 1);
       }
-#endif
+      cpi->partition_cost[PARTITION_CONTEXTS][PARTITION_NONE] = INT_MAX;
+      cpi->partition_cost[PARTITION_CONTEXTS][PARTITION_HORZ] = INT_MAX;
+      cpi->partition_cost[PARTITION_CONTEXTS][PARTITION_VERT] = INT_MAX;
+      cpi->partition_cost[PARTITION_CONTEXTS][PARTITION_SPLIT] = 0;
+#endif  // CONFIG_UNPOISON_PARTITION_CTX
     }
 
     fill_mode_costs(cpi);