EC_MULTISYMBOL: Add new context tables.

These are optimized for EOB_TOKEN being associated
with the current position, not the previous.

CBP tables cover EOB_TOKEN for the the whole block.

This change causes a performance regression until
EOB_TOKEN is merged into the coding scheme.

Change-Id: Ica3a12ed97285cbae204ce3cc1a7e658ebcacc9f
diff --git a/av1/common/entropy.c b/av1/common/entropy.c
index 2fe7ace..a3cc11c 100644
--- a/av1/common/entropy.c
+++ b/av1/common/entropy.c
@@ -3487,6 +3487,432 @@
     },
 };
 #else
+#if CONFIG_EC_MULTISYMBOL
+static const av1_coeff_probs_model default_coef_probs_4x4[PLANE_TYPES] = {
+  { // Y plane
+    { // Intra
+      { // Band 0
+        {97, 27, 144}, {81, 38, 128}, {51, 42, 99}
+      },
+      { // Band 1
+        {74, 113, 204}, {68, 101, 199}, {50, 87, 173},
+        {31, 76, 133}, {13, 55, 86}, {3, 30, 39}
+      },
+      { // Band 2
+        {83, 156, 222}, {74, 127, 215}, {46, 101, 179},
+        {30, 80, 129}, {14, 57, 81}, {3, 27, 37}
+      },
+      { // Band 3
+        {105, 164, 233}, {84, 128, 224}, {49, 92, 175},
+        {28, 60, 114}, {12, 34, 53}, {20, 59, 98}
+      },
+      { // Band 4
+        {131, 159, 243}, {98, 123, 228}, {40, 78, 151},
+        {19, 46, 97}, {13, 47, 19}, {19, 16, 19}
+      },
+      { // Band 5
+        {192, 71, 241}, {174, 70, 226}, {125, 46, 153},
+        {108, 49, 116}, {82, 24, 46}, {60, 14, 30}
+      }
+    },
+    { // Inter
+      { // Band 0
+        {111, 66, 218}, {107, 87, 211}, {93, 99, 207}
+      },
+      { // Band 1
+        {107, 166, 250}, {107, 143, 247}, {73, 119, 221},
+        {43, 91, 166}, {17, 74, 102}, {3, 70, 53}
+      },
+      { // Band 2
+        {126, 177, 251}, {109, 148, 246}, {64, 99, 204},
+        {42, 68, 140}, {28, 52, 84}, {20, 34, 1}
+      },
+      { // Band 3
+        {143, 178, 252}, {114, 144, 245}, {46, 92, 188},
+        {45, 65, 104}, {40, 44, 76}, {1, 1, 1}
+      },
+      { // Band 4
+        {163, 159, 251}, {120, 131, 243}, {47, 81, 182},
+        {32, 39, 128}, {33, 44, 56}, {1, 17, 34}
+      },
+      { // Band 5
+        {209, 94, 251}, {190, 81, 241}, {139, 45, 147},
+        {123, 35, 73}, {118, 1, 118}, {3, 16, 42}
+      }
+    }
+  },
+  { // UV plane
+    { // Intra
+      { // Band 0
+        {189, 37, 229}, {145, 68, 205}, {99, 74, 171}
+      },
+      { // Band 1
+        {153, 139, 242}, {135, 125, 235}, {84, 100, 200},
+        {49, 75, 162}, {9, 21, 84}, {3, 31, 69}
+      },
+      { // Band 2
+        {165, 165, 244}, {128, 144, 240}, {68, 94, 204},
+        {39, 72, 132}, {22, 44, 93}, {26, 73, 26}
+      },
+      { // Band 3
+        {181, 174, 246}, {142, 132, 241}, {81, 96, 212},
+        {41, 70, 166}, {9, 48, 92}, {1, 19, 38}
+      },
+      { // Band 4
+        {197, 159, 251}, {168, 121, 245}, {107, 75, 218},
+        {70, 43, 158}, {1, 128, 1}, {1, 18, 37}
+      },
+      { // Band 5
+        {231, 79, 255}, {211, 74, 249}, {157, 104, 210},
+        {128, 102, 213}, {12, 34, 96}, {2, 20, 47}
+      }
+    },
+    { // Inter
+      { // Band 0
+        {220, 53, 252}, {191, 80, 248}, {154, 100, 245}
+      },
+      { // Band 1
+        {205, 153, 255}, {182, 147, 254}, {110, 131, 231},
+        {68, 114, 161}, {50, 114, 140}, {1, 33, 57}
+      },
+      { // Band 2
+        {213, 171, 255}, {184, 163, 254}, {116, 104, 235},
+        {79, 71, 207}, {1, 41, 79}, {1, 20, 39}
+      },
+      { // Band 3
+        {223, 158, 255}, {203, 137, 255}, {111, 142, 244},
+        {2, 255, 133}, {1, 44, 85}, {1, 22, 47}
+      },
+      { // Band 4
+        {232, 148, 255}, {222, 123, 255}, {255, 128, 255},
+        {3, 61, 124}, {1, 41, 84}, {1, 21, 52}
+      },
+      { // Band 5
+        {248, 92, 255}, {248, 96, 255}, {69, 58, 184},
+        {31, 44, 137}, {14, 38, 105}, {8, 23, 61}
+      }
+    }
+  }
+};
+static const av1_coeff_probs_model default_coef_probs_8x8[PLANE_TYPES] = {
+  { // Y plane
+    { // Intra
+      { // Band 0
+        {112, 31, 159}, {72, 37, 119}, {22, 35, 68}
+      },
+      { // Band 1
+        {42, 109, 174}, {45, 99, 172}, {32, 84, 149},
+        {18, 69, 119}, {6, 46, 76}, {1, 19, 31}
+      },
+      { // Band 2
+        {40, 154, 202}, {35, 126, 191}, {19, 98, 160},
+        {10, 75, 122}, {5, 53, 82}, {1, 23, 39}
+      },
+      { // Band 3
+        {39, 176, 215}, {28, 135, 200}, {11, 93, 156},
+        {5, 63, 109}, {1, 36, 64}, {1, 14, 26}
+      },
+      { // Band 4
+        {41, 191, 230}, {25, 147, 212}, {9, 97, 160},
+        {3, 65, 109}, {1, 33, 58}, {1, 14, 20}
+      },
+      { // Band 5
+        {68, 203, 242}, {40, 159, 220}, {12, 97, 153},
+        {5, 58, 97}, {1, 29, 55}, {1, 11, 18}
+      }
+    },
+    { // Inter
+      { // Band 0
+        {99, 67, 221}, {86, 80, 204}, {60, 87, 184}
+      },
+      { // Band 1
+        {73, 169, 246}, {79, 158, 242}, {50, 135, 220},
+        {30, 113, 181}, {18, 76, 126}, {5, 54, 85}
+      },
+      { // Band 2
+        {90, 184, 250}, {78, 162, 243}, {47, 118, 214},
+        {35, 85, 171}, {32, 53, 115}, {20, 28, 76}
+      },
+      { // Band 3
+        {109, 197, 252}, {89, 172, 247}, {52, 119, 217},
+        {37, 80, 161}, {23, 44, 100}, {1, 18, 34}
+      },
+      { // Band 4
+        {132, 202, 254}, {110, 175, 251}, {63, 128, 228},
+        {37, 86, 168}, {64, 91, 102}, {1, 17, 34}
+      },
+      { // Band 5
+        {126, 204, 253}, {100, 174, 250}, {50, 148, 237},
+        {25, 90, 133}, {1, 64, 85}, {3, 16, 42}
+      }
+    }
+  },
+  { // UV plane
+    { // Intra
+      { // Band 0
+        {195, 35, 235}, {137, 63, 201}, {62, 70, 145}
+      },
+      { // Band 1
+        {110, 158, 233}, {102, 143, 227}, {60, 120, 199},
+        {30, 85, 156}, {9, 50, 90}, {1, 16, 33}
+      },
+      { // Band 2
+        {102, 185, 233}, {71, 152, 224}, {29, 111, 187},
+        {18, 74, 138}, {4, 56, 87}, {1, 18, 46}
+      },
+      { // Band 3
+        {101, 205, 239}, {66, 161, 229}, {23, 109, 183},
+        {9, 85, 135}, {5, 71, 142}, {1, 1, 102}
+      },
+      { // Band 4
+        {109, 216, 243}, {69, 168, 233}, {23, 119, 191},
+        {8, 137, 115}, {1, 54, 98}, {1, 1, 255}
+      },
+      { // Band 5
+        {139, 224, 249}, {98, 176, 238}, {55, 129, 187},
+        {25, 101, 131}, {26, 59, 154}, {2, 20, 47}
+      }
+    },
+    { // Inter
+      { // Band 0
+        {220, 72, 254}, {176, 108, 251}, {114, 132, 247}
+      },
+      { // Band 1
+        {161, 185, 255}, {141, 185, 254}, {131, 180, 249},
+        {111, 164, 186}, {50, 98, 142}, {1, 128, 1}
+      },
+      { // Band 2
+        {171, 195, 255}, {133, 184, 254}, {68, 140, 231},
+        {102, 96, 205}, {1, 1, 128}, {1, 20, 39}
+      },
+      { // Band 3
+        {180, 206, 255}, {148, 191, 254}, {83, 157, 241},
+        {128, 171, 128}, {1, 44, 85}, {1, 22, 47}
+      },
+      { // Band 4
+        {194, 214, 255}, {159, 188, 255}, {122, 148, 250},
+        {3, 255, 124}, {1, 41, 84}, {1, 21, 52}
+      },
+      { // Band 5
+        {231, 217, 255}, {209, 149, 255}, {205, 145, 205},
+        {31, 44, 137}, {14, 38, 105}, {8, 23, 61}
+      }
+    }
+  }
+};
+static const av1_coeff_probs_model default_coef_probs_16x16[PLANE_TYPES] = {
+  { // Y plane
+    { // Intra
+      { // Band 0
+        {91, 31, 117}, {49, 31, 89}, {14, 25, 48}
+      },
+      { // Band 1
+        {31, 97, 151}, {33, 89, 148}, {28, 76, 133},
+        {17, 60, 106}, {7, 42, 72}, {1, 19, 32}
+      },
+      { // Band 2
+        {28, 152, 182}, {28, 120, 174}, {15, 93, 146},
+        {9, 72, 116}, {5, 47, 82}, {1, 21, 37}
+      },
+      { // Band 3
+        {29, 174, 203}, {23, 127, 187}, {9, 89, 145},
+        {2, 56, 100}, {1, 31, 56}, {1, 12, 25}
+      },
+      { // Band 4
+        {28, 193, 220}, {17, 141, 197}, {4, 87, 142},
+        {1, 54, 95}, {1, 31, 56}, {1, 12, 26}
+      },
+      { // Band 5
+        {29, 221, 240}, {11, 167, 215}, {2, 93, 149},
+        {1, 58, 100}, {1, 35, 61}, {1, 16, 28}
+      }
+    },
+    { // Inter
+      { // Band 0
+        {108, 52, 214}, {84, 60, 186}, {45, 69, 161}
+      },
+      { // Band 1
+        {43, 164, 236}, {57, 161, 233}, {38, 146, 214},
+        {24, 120, 182}, {15, 80, 126}, {5, 28, 66}
+      },
+      { // Band 2
+        {58, 187, 242}, {47, 163, 234}, {28, 118, 204},
+        {26, 82, 165}, {21, 54, 112}, {4, 28, 55}
+      },
+      { // Band 3
+        {65, 201, 248}, {51, 170, 239}, {22, 117, 204},
+        {11, 81, 159}, {10, 43, 102}, {1, 1, 1}
+      },
+      { // Band 4
+        {80, 206, 252}, {57, 179, 245}, {25, 129, 214},
+        {16, 97, 170}, {6, 60, 130}, {1, 128, 1}
+      },
+      { // Band 5
+        {97, 217, 253}, {68, 186, 250}, {26, 138, 216},
+        {20, 105, 166}, {11, 78, 111}, {3, 16, 42}
+      }
+    }
+  },
+  { // UV plane
+    { // Intra
+      { // Band 0
+        {181, 37, 233}, {121, 55, 192}, {46, 52, 124}
+      },
+      { // Band 1
+        {108, 157, 221}, {98, 140, 215}, {59, 124, 187},
+        {34, 92, 158}, {9, 68, 112}, {1, 41, 70}
+      },
+      { // Band 2
+        {80, 188, 223}, {46, 153, 204}, {25, 91, 173},
+        {11, 73, 131}, {5, 43, 82}, {1, 17, 91}
+      },
+      { // Band 3
+        {63, 209, 228}, {31, 157, 206}, {8, 104, 167},
+        {3, 63, 122}, {1, 44, 87}, {1, 43, 51}
+      },
+      { // Band 4
+        {52, 220, 234}, {22, 165, 216}, {4, 104, 163},
+        {2, 62, 129}, {1, 33, 50}, {1, 26, 28}
+      },
+      { // Band 5
+        {58, 238, 242}, {24, 183, 224}, {4, 109, 172},
+        {2, 87, 141}, {1, 52, 79}, {1, 51, 64}
+      }
+    },
+    { // Inter
+      { // Band 0
+        {224, 52, 250}, {188, 81, 239}, {138, 114, 228}
+      },
+      { // Band 1
+        {131, 206, 255}, {128, 193, 254}, {119, 173, 247},
+        {106, 127, 187}, {50, 100, 124}, {1, 96, 1}
+      },
+      { // Band 2
+        {123, 214, 254}, {86, 194, 254}, {64, 119, 221},
+        {43, 51, 128}, {1, 32, 110}, {1, 20, 39}
+      },
+      { // Band 3
+        {115, 223, 255}, {78, 200, 254}, {75, 164, 203},
+        {128, 85, 255}, {1, 44, 85}, {1, 22, 47}
+      },
+      { // Band 4
+        {132, 226, 255}, {88, 207, 254}, {20, 140, 225},
+        {3, 61, 124}, {1, 41, 84}, {1, 21, 52}
+      },
+      { // Band 5
+        {180, 236, 255}, {138, 223, 254}, {73, 166, 238},
+        {31, 255, 137}, {14, 38, 105}, {8, 23, 61}
+      }
+    }
+  }
+};
+static const av1_coeff_probs_model default_coef_probs_32x32[PLANE_TYPES] = {
+  { // Y plane
+    { // Intra
+      { // Band 0
+        {163, 26, 188}, {78, 29, 105}, {22, 22, 48}
+      },
+      { // Band 1
+        {72, 93, 168}, {74, 91, 170}, {62, 72, 151},
+        {37, 55, 112}, {10, 33, 63}, {1, 14, 23}
+      },
+      { // Band 2
+        {41, 163, 182}, {36, 136, 177}, {20, 102, 153},
+        {10, 76, 114}, {5, 45, 71}, {1, 17, 27}
+      },
+      { // Band 3
+        {43, 202, 213}, {28, 142, 193}, {10, 90, 141},
+        {2, 51, 93}, {1, 24, 48}, {1, 10, 19}
+      },
+      { // Band 4
+        {46, 216, 220}, {26, 150, 199}, {7, 87, 136},
+        {2, 49, 86}, {1, 28, 47}, {1, 12, 24}
+      },
+      { // Band 5
+        {19, 241, 237}, {5, 172, 200}, {1, 82, 126},
+        {1, 47, 79}, {1, 29, 47}, {1, 14, 25}
+      }
+    },
+    { // Inter
+      { // Band 0
+        {185, 20, 226}, {151, 26, 187}, {109, 34, 144}
+      },
+      { // Band 1
+        {56, 151, 227}, {76, 165, 232}, {62, 161, 222},
+        {47, 139, 201}, {29, 106, 150}, {14, 61, 98}
+      },
+      { // Band 2
+        {57, 200, 237}, {43, 164, 227}, {22, 106, 190},
+        {14, 68, 140}, {10, 48, 90}, {1, 15, 40}
+      },
+      { // Band 3
+        {46, 209, 238}, {28, 165, 225}, {7, 107, 180},
+        {2, 69, 125}, {2, 36, 94}, {1, 1, 1}
+      },
+      { // Band 4
+        {55, 225, 248}, {28, 181, 237}, {7, 117, 198},
+        {6, 77, 144}, {3, 60, 90}, {1, 1, 1}
+      },
+      { // Band 5
+        {63, 243, 251}, {27, 193, 242}, {4, 124, 200},
+        {1, 58, 153}, {1, 59, 124}, {3, 16, 42}
+      }
+    }
+  },
+  { // UV plane
+    { // Intra
+      { // Band 0
+        {208, 28, 218}, {183, 32, 188}, {169, 21, 189}
+      },
+      { // Band 1
+        {205, 124, 247}, {190, 96, 240}, {233, 89, 233},
+        {177, 44, 212}, {59, 58, 59}, {32, 33, 38}
+      },
+      { // Band 2
+        {194, 195, 250}, {179, 190, 226}, {32, 174, 128},
+        {32, 85, 128}, {12, 64, 122}, {1, 85, 90}
+      },
+      { // Band 3
+        {149, 232, 249}, {95, 159, 227}, {28, 91, 171},
+        {28, 102, 114}, {1, 1, 73}, {1, 19, 38}
+      },
+      { // Band 4
+        {154, 239, 246}, {138, 151, 235}, {1, 123, 138},
+        {128, 183, 255}, {1, 128, 1}, {1, 18, 37}
+      },
+      { // Band 5
+        {157, 255, 253}, {75, 171, 241}, {43, 102, 171},
+        {30, 44, 136}, {12, 34, 96}, {2, 20, 47}
+      }
+    },
+    { // Inter
+      { // Band 0
+        {249, 13, 248}, {238, 14, 220}, {225, 16, 174}
+      },
+      { // Band 1
+        {190, 189, 254}, {169, 134, 253}, {124, 179, 248},
+        {138, 131, 223}, {64, 133, 192}, {1, 85, 128}
+      },
+      { // Band 2
+        {139, 212, 254}, {126, 177, 255}, {93, 39, 186},
+        {1, 1, 171}, {1, 41, 79}, {1, 20, 39}
+      },
+      { // Band 3
+        {153, 216, 255}, {165, 204, 255}, {1, 1, 255},
+        {2, 73, 133}, {1, 1, 1}, {1, 22, 47}
+      },
+      { // Band 4
+        {147, 226, 254}, {119, 196, 255}, {1, 128, 255},
+        {1, 1, 171}, {1, 1, 1}, {1, 21, 52}
+      },
+      { // Band 5
+        {168, 240, 255}, {95, 179, 255}, {1, 171, 1},
+        {31, 44, 137}, {14, 38, 105}, {8, 23, 61}
+      }
+    }
+  }
+};
+#else  // CONFIG_EC_MULTISYMBOL
 static const av1_coeff_probs_model default_coef_probs_4x4[PLANE_TYPES] = {
   {  // Y plane
     {  // Intra
@@ -3822,8 +4248,10 @@
     }
   }
 };
+#endif  // EC_MULTISYMBOL
 
 #if CONFIG_TX64X64
+// FIXME. Optimize for EC_MULTISYMBOL
 static const av1_coeff_probs_model default_coef_probs_64x64[PLANE_TYPES] = {
   {  // Y plane
     {  // Intra
@@ -3909,6 +4337,52 @@
 };
 #endif  // CONFIG_TX64X64
 #endif  // CONFIG_ENTROPY
+#if CONFIG_EC_MULTISYMBOL
+static const aom_prob av1_default_blockzero_probs[TX_SIZES][PLANE_TYPES]
+                                           [REF_TYPES][BLOCKZ_CONTEXTS] = {
+  { // TX_4x4
+    { // Y plane
+      { 195, 84, 8, },  // Intra
+      { 191, 124, 25, },  // Inter
+    },
+    { // UV plane
+      { 214, 132, 42, },  // Intra
+      { 229, 143, 46, },  // Inter
+    },
+  },
+  { // TX_8x8
+    { // Y plane
+      { 125, 52, 6, },  // Intra
+      { 202, 108, 18, },  // Inter
+    },
+    { // UV plane
+      { 212, 113, 29, },  // Intra
+      { 225, 144, 42, },  // Inter
+    },
+  },
+  { // TX_16x16
+    { // Y plane
+      { 7, 5, 1, },  // Intra
+      { 19, 19, 3, },  // Inter
+    },
+    { // UV plane
+      { 211, 96, 22, },  // Intra
+      { 233, 146, 43, },  // Inter
+    },
+  },
+  { // TX_32x32
+    { //  Y plane
+      { 17, 7, 1, },  // Intra
+      { 36, 29, 10, },  // Inter
+    },
+    { // UV plane
+      { 181, 61, 10, },  // Intra
+      { 197, 82, 25, },  // Inter
+    },
+  },
+};
+#endif
+
 /* clang-format on */
 
 static void extend_to_full_distribution(aom_prob *probs, aom_prob p) {
@@ -3977,6 +4451,7 @@
 #endif  // CONFIG_TX64X64
 #endif  // CONFIG_ENTROPY
 #if CONFIG_EC_MULTISYMBOL
+  av1_copy(cm->fc->blockzero_probs, av1_default_blockzero_probs);
   av1_coef_pareto_cdfs(cm->fc);
 #endif  // CONFIG_EC_MULTISYMBOL
 }
diff --git a/av1/common/entropy.h b/av1/common/entropy.h
index 5cc7b1b..b9c9a2f 100644
--- a/av1/common/entropy.h
+++ b/av1/common/entropy.h
@@ -128,6 +128,9 @@
    distinct bands). */
 
 #define COEFF_CONTEXTS 6
+#if CONFIG_EC_MULTISYMBOL
+#define BLOCKZ_CONTEXTS 3
+#endif
 #define COEFF_CONTEXTS0 3  // for band 0
 #define BAND_COEFF_CONTEXTS(band) \
   ((band) == 0 ? COEFF_CONTEXTS0 : COEFF_CONTEXTS)
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index 7a5e0e3..28d9637 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -87,6 +87,7 @@
 #if CONFIG_EC_MULTISYMBOL
   coeff_cdf_model coef_tail_cdfs[TX_SIZES][PLANE_TYPES];
   coeff_cdf_model coef_head_cdfs[TX_SIZES][PLANE_TYPES];
+  aom_prob blockzero_probs[TX_SIZES][PLANE_TYPES][REF_TYPES][BLOCKZ_CONTEXTS];
 #endif  // CONFIG_EC_MULTISYMBOL
   aom_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
                                  [SWITCHABLE_FILTERS - 1];