Merge "Synchronize tx_size counts in the decoder" into nextgenv2
diff --git a/aom_dsp/aom_dsp_rtcd_defs.pl b/aom_dsp/aom_dsp_rtcd_defs.pl
index 6d873bc..d6fa90b 100644
--- a/aom_dsp/aom_dsp_rtcd_defs.pl
+++ b/aom_dsp/aom_dsp_rtcd_defs.pl
@@ -701,6 +701,34 @@
 #
 if (aom_config("CONFIG_AV1_ENCODER") eq "yes") {
   if (aom_config("CONFIG_AOM_HIGHBITDEPTH") eq "yes") {
+    add_proto qw/void aom_fdct4x4/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct4x4 sse2/;
+
+    add_proto qw/void aom_fdct4x4_1/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct4x4_1 sse2/;
+
+    add_proto qw/void aom_fdct8x8/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct8x8 sse2/;
+
+    add_proto qw/void aom_fdct8x8_1/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct8x8_1 sse2/;
+
+    add_proto qw/void aom_fdct16x16/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct16x16 sse2/;
+
+    add_proto qw/void aom_fdct16x16_1/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct16x16_1 sse2 avx2/;
+
+    add_proto qw/void aom_fdct32x32/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct32x32 sse2 avx2/;
+
+    add_proto qw/void aom_fdct32x32_rd/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct32x32_rd sse2 avx2/;
+
+    add_proto qw/void aom_fdct32x32_1/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct32x32_1 sse2 avx2/;
+
+    # High bit depth
     add_proto qw/void aom_highbd_fdct4x4/, "const int16_t *input, tran_low_t *output, int stride";
     specialize qw/aom_highbd_fdct4x4 sse2/;
 
@@ -724,33 +752,34 @@
 
     add_proto qw/void aom_highbd_fdct32x32_1/, "const int16_t *input, tran_low_t *output, int stride";
     specialize qw/aom_highbd_fdct32x32_1/;
-  }   # CONFIG_AOM_HIGHBITDEPTH
-  add_proto qw/void aom_fdct4x4/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct4x4 sse2 msa/;
+  } else {
+    add_proto qw/void aom_fdct4x4/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct4x4 sse2 msa/;
 
-  add_proto qw/void aom_fdct4x4_1/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct4x4_1 sse2/;
+    add_proto qw/void aom_fdct4x4_1/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct4x4_1 sse2/;
 
-  add_proto qw/void aom_fdct8x8/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct8x8 sse2 neon msa/, "$ssse3_x86_64";
+    add_proto qw/void aom_fdct8x8/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct8x8 sse2 neon msa/, "$ssse3_x86_64";
 
-  add_proto qw/void aom_fdct8x8_1/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct8x8_1 sse2 neon msa/;
+    add_proto qw/void aom_fdct8x8_1/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct8x8_1 sse2 neon msa/;
 
-  add_proto qw/void aom_fdct16x16/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct16x16 sse2 msa/;
+    add_proto qw/void aom_fdct16x16/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct16x16 sse2 msa/;
 
-  add_proto qw/void aom_fdct16x16_1/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct16x16_1 sse2 avx2 msa/;
+    add_proto qw/void aom_fdct16x16_1/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct16x16_1 sse2 avx2 msa/;
 
-  add_proto qw/void aom_fdct32x32/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct32x32 sse2 avx2 msa/;
+    add_proto qw/void aom_fdct32x32/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct32x32 sse2 avx2 msa/;
 
-  add_proto qw/void aom_fdct32x32_rd/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct32x32_rd sse2 avx2 msa/;
+    add_proto qw/void aom_fdct32x32_rd/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct32x32_rd sse2 avx2 msa/;
 
-  add_proto qw/void aom_fdct32x32_1/, "const int16_t *input, tran_low_t *output, int stride";
-  specialize qw/aom_fdct32x32_1 sse2 avx2 msa/;
+    add_proto qw/void aom_fdct32x32_1/, "const int16_t *input, tran_low_t *output, int stride";
+    specialize qw/aom_fdct32x32_1 sse2 avx2 msa/;
+  }  # CONFIG_AOM_HIGHBITDEPTH
 }  # CONFIG_AV1_ENCODER
 
 #
diff --git a/av1/common/av1_convolve.c b/av1/common/av1_convolve.c
index 1f8d623..270ab70 100644
--- a/av1/common/av1_convolve.c
+++ b/av1/common/av1_convolve.c
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
 #include <assert.h>
 #include <string.h>
 
diff --git a/av1/common/av1_convolve.h b/av1/common/av1_convolve.h
index 804c102..dafa032 100644
--- a/av1/common/av1_convolve.h
+++ b/av1/common/av1_convolve.h
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
 #ifndef AV1_COMMON_AV1_CONVOLVE_H_
 #define AV1_COMMON_AV1_CONVOLVE_H_
 #include "av1/common/filter.h"
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c
index ecad3f4..bf5519b 100644
--- a/av1/common/entropymode.c
+++ b/av1/common/entropymode.c
@@ -567,117 +567,117 @@
                                     [PALETTE_COLORS - 1] = {
                                       {
                                           // 2 colors
-                                          { 230, 255, 128, 128, 128, 128, 128 },
-                                          { 214, 255, 128, 128, 128, 128, 128 },
-                                          { 128, 128, 128, 128, 128, 128, 128 },
-                                          { 128, 128, 128, 128, 128, 128, 128 },
-                                          { 128, 128, 128, 128, 128, 128, 128 },
-                                          { 240, 255, 128, 128, 128, 128, 128 },
-                                          { 73, 255, 128, 128, 128, 128, 128 },
-                                          { 128, 128, 128, 128, 128, 128, 128 },
-                                          { 130, 255, 128, 128, 128, 128, 128 },
-                                          { 227, 255, 128, 128, 128, 128, 128 },
-                                          { 128, 128, 128, 128, 128, 128, 128 },
-                                          { 188, 255, 128, 128, 128, 128, 128 },
-                                          { 75, 255, 128, 128, 128, 128, 128 },
-                                          { 250, 255, 128, 128, 128, 128, 128 },
-                                          { 223, 255, 128, 128, 128, 128, 128 },
-                                          { 252, 255, 128, 128, 128, 128, 128 },
+                                          { 230, 0, 0, 0, 0, 0, 0 },
+                                          { 214, 0, 0, 0, 0, 0, 0 },
+                                          { 0, 0, 0, 0, 0, 0, 0 },
+                                          { 0, 0, 0, 0, 0, 0, 0 },
+                                          { 0, 0, 0, 0, 0, 0, 0 },
+                                          { 240, 0, 0, 0, 0, 0, 0 },
+                                          { 73, 0, 0, 0, 0, 0, 0 },
+                                          { 0, 0, 0, 0, 0, 0, 0 },
+                                          { 130, 0, 0, 0, 0, 0, 0 },
+                                          { 227, 0, 0, 0, 0, 0, 0 },
+                                          { 0, 0, 0, 0, 0, 0, 0 },
+                                          { 188, 0, 0, 0, 0, 0, 0 },
+                                          { 75, 0, 0, 0, 0, 0, 0 },
+                                          { 250, 0, 0, 0, 0, 0, 0 },
+                                          { 223, 0, 0, 0, 0, 0, 0 },
+                                          { 252, 0, 0, 0, 0, 0, 0 },
                                       },
                                       {
                                           // 3 colors
-                                          { 229, 137, 255, 128, 128, 128, 128 },
-                                          { 197, 120, 255, 128, 128, 128, 128 },
-                                          { 107, 195, 255, 128, 128, 128, 128 },
-                                          { 128, 128, 128, 128, 128, 128, 128 },
-                                          { 27, 151, 255, 128, 128, 128, 128 },
-                                          { 230, 130, 255, 128, 128, 128, 128 },
-                                          { 37, 230, 255, 128, 128, 128, 128 },
-                                          { 67, 221, 255, 128, 128, 128, 128 },
-                                          { 124, 230, 255, 128, 128, 128, 128 },
-                                          { 195, 109, 255, 128, 128, 128, 128 },
-                                          { 99, 122, 255, 128, 128, 128, 128 },
-                                          { 205, 208, 255, 128, 128, 128, 128 },
-                                          { 40, 235, 255, 128, 128, 128, 128 },
-                                          { 251, 132, 255, 128, 128, 128, 128 },
-                                          { 237, 186, 255, 128, 128, 128, 128 },
-                                          { 253, 112, 255, 128, 128, 128, 128 },
+                                          { 229, 137, 0, 0, 0, 0, 0 },
+                                          { 197, 120, 0, 0, 0, 0, 0 },
+                                          { 107, 195, 0, 0, 0, 0, 0 },
+                                          { 0, 0, 0, 0, 0, 0, 0 },
+                                          { 27, 151, 0, 0, 0, 0, 0 },
+                                          { 230, 130, 0, 0, 0, 0, 0 },
+                                          { 37, 230, 0, 0, 0, 0, 0 },
+                                          { 67, 221, 0, 0, 0, 0, 0 },
+                                          { 124, 230, 0, 0, 0, 0, 0 },
+                                          { 195, 109, 0, 0, 0, 0, 0 },
+                                          { 99, 122, 0, 0, 0, 0, 0 },
+                                          { 205, 208, 0, 0, 0, 0, 0 },
+                                          { 40, 235, 0, 0, 0, 0, 0 },
+                                          { 251, 132, 0, 0, 0, 0, 0 },
+                                          { 237, 186, 0, 0, 0, 0, 0 },
+                                          { 253, 112, 0, 0, 0, 0, 0 },
                                       },
                                       {
                                           // 4 colors
-                                          { 195, 87, 128, 255, 128, 128, 128 },
-                                          { 143, 100, 123, 255, 128, 128, 128 },
-                                          { 94, 124, 119, 255, 128, 128, 128 },
-                                          { 77, 91, 130, 255, 128, 128, 128 },
-                                          { 39, 114, 178, 255, 128, 128, 128 },
-                                          { 222, 94, 125, 255, 128, 128, 128 },
-                                          { 44, 203, 132, 255, 128, 128, 128 },
-                                          { 68, 175, 122, 255, 128, 128, 128 },
-                                          { 110, 187, 124, 255, 128, 128, 128 },
-                                          { 152, 91, 128, 255, 128, 128, 128 },
-                                          { 70, 109, 181, 255, 128, 128, 128 },
-                                          { 133, 113, 164, 255, 128, 128, 128 },
-                                          { 47, 205, 133, 255, 128, 128, 128 },
-                                          { 247, 94, 136, 255, 128, 128, 128 },
-                                          { 205, 122, 146, 255, 128, 128, 128 },
-                                          { 251, 100, 141, 255, 128, 128, 128 },
+                                          { 195, 87, 128, 0, 0, 0, 0 },
+                                          { 143, 100, 123, 0, 0, 0, 0 },
+                                          { 94, 124, 119, 0, 0, 0, 0 },
+                                          { 77, 91, 130, 0, 0, 0, 0 },
+                                          { 39, 114, 178, 0, 0, 0, 0 },
+                                          { 222, 94, 125, 0, 0, 0, 0 },
+                                          { 44, 203, 132, 0, 0, 0, 0 },
+                                          { 68, 175, 122, 0, 0, 0, 0 },
+                                          { 110, 187, 124, 0, 0, 0, 0 },
+                                          { 152, 91, 128, 0, 0, 0, 0 },
+                                          { 70, 109, 181, 0, 0, 0, 0 },
+                                          { 133, 113, 164, 0, 0, 0, 0 },
+                                          { 47, 205, 133, 0, 0, 0, 0 },
+                                          { 247, 94, 136, 0, 0, 0, 0 },
+                                          { 205, 122, 146, 0, 0, 0, 0 },
+                                          { 251, 100, 141, 0, 0, 0, 0 },
                                       },
                                       {
                                           // 5 colors
-                                          { 195, 65, 84, 125, 255, 128, 128 },
-                                          { 150, 76, 84, 121, 255, 128, 128 },
-                                          { 94, 110, 81, 117, 255, 128, 128 },
-                                          { 79, 85, 91, 139, 255, 128, 128 },
-                                          { 26, 102, 139, 127, 255, 128, 128 },
-                                          { 220, 73, 91, 119, 255, 128, 128 },
-                                          { 38, 203, 86, 127, 255, 128, 128 },
-                                          { 61, 186, 72, 124, 255, 128, 128 },
-                                          { 132, 199, 84, 128, 255, 128, 128 },
-                                          { 172, 52, 62, 120, 255, 128, 128 },
-                                          { 102, 89, 121, 122, 255, 128, 128 },
-                                          { 182, 48, 69, 186, 255, 128, 128 },
-                                          { 36, 206, 87, 126, 255, 128, 128 },
-                                          { 249, 55, 67, 122, 255, 128, 128 },
-                                          { 218, 88, 75, 122, 255, 128, 128 },
-                                          { 253, 64, 80, 119, 255, 128, 128 },
+                                          { 195, 65, 84, 125, 0, 0, 0 },
+                                          { 150, 76, 84, 121, 0, 0, 0 },
+                                          { 94, 110, 81, 117, 0, 0, 0 },
+                                          { 79, 85, 91, 139, 0, 0, 0 },
+                                          { 26, 102, 139, 127, 0, 0, 0 },
+                                          { 220, 73, 91, 119, 0, 0, 0 },
+                                          { 38, 203, 86, 127, 0, 0, 0 },
+                                          { 61, 186, 72, 124, 0, 0, 0 },
+                                          { 132, 199, 84, 128, 0, 0, 0 },
+                                          { 172, 52, 62, 120, 0, 0, 0 },
+                                          { 102, 89, 121, 122, 0, 0, 0 },
+                                          { 182, 48, 69, 186, 0, 0, 0 },
+                                          { 36, 206, 87, 126, 0, 0, 0 },
+                                          { 249, 55, 67, 122, 0, 0, 0 },
+                                          { 218, 88, 75, 122, 0, 0, 0 },
+                                          { 253, 64, 80, 119, 0, 0, 0 },
                                       },
                                       {
                                           // 6 colors
-                                          { 182, 54, 64, 75, 118, 255, 128 },
-                                          { 126, 67, 70, 76, 116, 255, 128 },
-                                          { 79, 92, 67, 85, 120, 255, 128 },
-                                          { 63, 61, 81, 118, 132, 255, 128 },
-                                          { 21, 80, 105, 83, 119, 255, 128 },
-                                          { 215, 72, 74, 74, 111, 255, 128 },
-                                          { 50, 176, 63, 79, 120, 255, 128 },
-                                          { 72, 148, 66, 77, 120, 255, 128 },
-                                          { 105, 177, 57, 78, 130, 255, 128 },
-                                          { 150, 66, 66, 80, 127, 255, 128 },
-                                          { 81, 76, 109, 85, 116, 255, 128 },
-                                          { 113, 81, 62, 96, 148, 255, 128 },
-                                          { 54, 179, 69, 82, 121, 255, 128 },
-                                          { 244, 47, 48, 67, 118, 255, 128 },
-                                          { 198, 83, 53, 65, 121, 255, 128 },
-                                          { 250, 42, 51, 69, 110, 255, 128 },
+                                          { 182, 54, 64, 75, 118, 0, 0 },
+                                          { 126, 67, 70, 76, 116, 0, 0 },
+                                          { 79, 92, 67, 85, 120, 0, 0 },
+                                          { 63, 61, 81, 118, 132, 0, 0 },
+                                          { 21, 80, 105, 83, 119, 0, 0 },
+                                          { 215, 72, 74, 74, 111, 0, 0 },
+                                          { 50, 176, 63, 79, 120, 0, 0 },
+                                          { 72, 148, 66, 77, 120, 0, 0 },
+                                          { 105, 177, 57, 78, 130, 0, 0 },
+                                          { 150, 66, 66, 80, 127, 0, 0 },
+                                          { 81, 76, 109, 85, 116, 0, 0 },
+                                          { 113, 81, 62, 96, 148, 0, 0 },
+                                          { 54, 179, 69, 82, 121, 0, 0 },
+                                          { 244, 47, 48, 67, 118, 0, 0 },
+                                          { 198, 83, 53, 65, 121, 0, 0 },
+                                          { 250, 42, 51, 69, 110, 0, 0 },
                                       },
                                       {
                                           // 7 colors
-                                          { 182, 45, 54, 62, 74, 113, 255 },
-                                          { 124, 63, 57, 62, 77, 114, 255 },
-                                          { 77, 80, 56, 66, 76, 117, 255 },
-                                          { 63, 57, 69, 98, 85, 131, 255 },
-                                          { 19, 81, 98, 63, 80, 116, 255 },
-                                          { 215, 56, 60, 63, 68, 105, 255 },
-                                          { 50, 174, 50, 60, 79, 118, 255 },
-                                          { 68, 151, 50, 58, 73, 117, 255 },
-                                          { 104, 182, 53, 57, 79, 127, 255 },
-                                          { 156, 50, 51, 63, 77, 111, 255 },
-                                          { 88, 67, 97, 59, 82, 120, 255 },
-                                          { 114, 81, 46, 65, 103, 132, 255 },
-                                          { 55, 166, 57, 66, 82, 120, 255 },
-                                          { 245, 34, 38, 43, 63, 114, 255 },
-                                          { 203, 68, 45, 47, 60, 118, 255 },
-                                          { 250, 35, 37, 47, 66, 110, 255 },
+                                          { 182, 45, 54, 62, 74, 113, 0 },
+                                          { 124, 63, 57, 62, 77, 114, 0 },
+                                          { 77, 80, 56, 66, 76, 117, 0 },
+                                          { 63, 57, 69, 98, 85, 131, 0 },
+                                          { 19, 81, 98, 63, 80, 116, 0 },
+                                          { 215, 56, 60, 63, 68, 105, 0 },
+                                          { 50, 174, 50, 60, 79, 118, 0 },
+                                          { 68, 151, 50, 58, 73, 117, 0 },
+                                          { 104, 182, 53, 57, 79, 127, 0 },
+                                          { 156, 50, 51, 63, 77, 111, 0 },
+                                          { 88, 67, 97, 59, 82, 120, 0 },
+                                          { 114, 81, 46, 65, 103, 132, 0 },
+                                          { 55, 166, 57, 66, 82, 120, 0 },
+                                          { 245, 34, 38, 43, 63, 114, 0 },
+                                          { 203, 68, 45, 47, 60, 118, 0 },
+                                          { 250, 35, 37, 47, 66, 110, 0 },
                                       },
                                       {
                                           // 8 colors
@@ -700,141 +700,144 @@
                                       }
                                     };
 
-const aom_prob av1_default_palette_uv_color_prob
-    [PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS]
-    [PALETTE_COLORS - 1] = { {
-                                 // 2 colors
-                                 { 228, 255, 128, 128, 128, 128, 128 },
-                                 { 195, 255, 128, 128, 128, 128, 128 },
-                                 { 128, 128, 128, 128, 128, 128, 128 },
-                                 { 128, 128, 128, 128, 128, 128, 128 },
-                                 { 128, 128, 128, 128, 128, 128, 128 },
-                                 { 228, 255, 128, 128, 128, 128, 128 },
-                                 { 71, 255, 128, 128, 128, 128, 128 },
-                                 { 128, 128, 128, 128, 128, 128, 128 },
-                                 { 129, 255, 128, 128, 128, 128, 128 },
-                                 { 206, 255, 128, 128, 128, 128, 128 },
-                                 { 128, 128, 128, 128, 128, 128, 128 },
-                                 { 136, 255, 128, 128, 128, 128, 128 },
-                                 { 98, 255, 128, 128, 128, 128, 128 },
-                                 { 236, 255, 128, 128, 128, 128, 128 },
-                                 { 222, 255, 128, 128, 128, 128, 128 },
-                                 { 249, 255, 128, 128, 128, 128, 128 },
-                             },
-                             {
-                                 // 3 colors
-                                 { 198, 136, 255, 128, 128, 128, 128 },
-                                 { 178, 105, 255, 128, 128, 128, 128 },
-                                 { 100, 206, 255, 128, 128, 128, 128 },
-                                 { 128, 128, 128, 128, 128, 128, 128 },
-                                 { 12, 136, 255, 128, 128, 128, 128 },
-                                 { 219, 134, 255, 128, 128, 128, 128 },
-                                 { 50, 198, 255, 128, 128, 128, 128 },
-                                 { 61, 231, 255, 128, 128, 128, 128 },
-                                 { 110, 209, 255, 128, 128, 128, 128 },
-                                 { 173, 106, 255, 128, 128, 128, 128 },
-                                 { 145, 166, 255, 128, 128, 128, 128 },
-                                 { 156, 175, 255, 128, 128, 128, 128 },
-                                 { 69, 183, 255, 128, 128, 128, 128 },
-                                 { 241, 163, 255, 128, 128, 128, 128 },
-                                 { 224, 160, 255, 128, 128, 128, 128 },
-                                 { 246, 154, 255, 128, 128, 128, 128 },
-                             },
-                             {
-                                 // 4 colors
-                                 { 173, 88, 143, 255, 128, 128, 128 },
-                                 { 146, 81, 127, 255, 128, 128, 128 },
-                                 { 84, 134, 102, 255, 128, 128, 128 },
-                                 { 69, 138, 140, 255, 128, 128, 128 },
-                                 { 31, 103, 200, 255, 128, 128, 128 },
-                                 { 217, 101, 139, 255, 128, 128, 128 },
-                                 { 51, 174, 121, 255, 128, 128, 128 },
-                                 { 64, 177, 109, 255, 128, 128, 128 },
-                                 { 96, 179, 145, 255, 128, 128, 128 },
-                                 { 164, 77, 114, 255, 128, 128, 128 },
-                                 { 87, 94, 156, 255, 128, 128, 128 },
-                                 { 105, 57, 173, 255, 128, 128, 128 },
-                                 { 63, 158, 137, 255, 128, 128, 128 },
-                                 { 236, 102, 156, 255, 128, 128, 128 },
-                                 { 197, 115, 153, 255, 128, 128, 128 },
-                                 { 245, 106, 154, 255, 128, 128, 128 },
-                             },
-                             {
-                                 // 5 colors
-                                 { 179, 64, 97, 129, 255, 128, 128 },
-                                 { 137, 56, 88, 125, 255, 128, 128 },
-                                 { 82, 107, 61, 118, 255, 128, 128 },
-                                 { 59, 113, 86, 115, 255, 128, 128 },
-                                 { 23, 88, 118, 130, 255, 128, 128 },
-                                 { 213, 66, 90, 125, 255, 128, 128 },
-                                 { 37, 181, 103, 121, 255, 128, 128 },
-                                 { 47, 188, 61, 131, 255, 128, 128 },
-                                 { 104, 185, 103, 144, 255, 128, 128 },
-                                 { 163, 39, 76, 112, 255, 128, 128 },
-                                 { 94, 74, 131, 126, 255, 128, 128 },
-                                 { 142, 42, 103, 163, 255, 128, 128 },
-                                 { 53, 162, 99, 149, 255, 128, 128 },
-                                 { 239, 54, 84, 108, 255, 128, 128 },
-                                 { 203, 84, 110, 147, 255, 128, 128 },
-                                 { 248, 70, 105, 151, 255, 128, 128 },
-                             },
-                             {
-                                 // 6 colors
-                                 { 189, 50, 67, 90, 130, 255, 128 },
-                                 { 114, 50, 55, 90, 123, 255, 128 },
-                                 { 66, 76, 54, 82, 128, 255, 128 },
-                                 { 43, 69, 69, 80, 129, 255, 128 },
-                                 { 22, 59, 87, 88, 141, 255, 128 },
-                                 { 203, 49, 68, 87, 122, 255, 128 },
-                                 { 43, 157, 74, 104, 146, 255, 128 },
-                                 { 54, 138, 51, 95, 138, 255, 128 },
-                                 { 82, 171, 58, 102, 146, 255, 128 },
-                                 { 129, 38, 59, 64, 168, 255, 128 },
-                                 { 56, 67, 119, 92, 112, 255, 128 },
-                                 { 96, 62, 53, 132, 82, 255, 128 },
-                                 { 60, 147, 77, 108, 145, 255, 128 },
-                                 { 238, 76, 73, 93, 148, 255, 128 },
-                                 { 189, 86, 73, 103, 157, 255, 128 },
-                                 { 246, 62, 75, 83, 167, 255, 128 },
-                             },
-                             {
-                                 // 7 colors
-                                 { 179, 42, 51, 73, 99, 134, 255 },
-                                 { 119, 52, 52, 61, 64, 114, 255 },
-                                 { 53, 77, 35, 65, 71, 131, 255 },
-                                 { 38, 70, 51, 68, 89, 144, 255 },
-                                 { 23, 65, 128, 73, 97, 131, 255 },
-                                 { 210, 47, 52, 63, 81, 143, 255 },
-                                 { 42, 159, 57, 68, 98, 143, 255 },
-                                 { 49, 153, 45, 82, 93, 143, 255 },
-                                 { 81, 169, 52, 72, 113, 151, 255 },
-                                 { 136, 46, 35, 56, 75, 96, 255 },
-                                 { 57, 84, 109, 47, 107, 131, 255 },
-                                 { 128, 78, 57, 36, 128, 85, 255 },
-                                 { 54, 149, 68, 77, 94, 153, 255 },
-                                 { 243, 58, 50, 71, 81, 167, 255 },
-                                 { 189, 92, 64, 70, 121, 173, 255 },
-                                 { 248, 35, 38, 51, 82, 201, 255 },
-                             },
-                             {
-                                 // 8 colors
-                                 { 201, 40, 36, 42, 64, 92, 123 },
-                                 { 116, 43, 33, 43, 73, 102, 128 },
-                                 { 46, 77, 37, 69, 62, 78, 150 },
-                                 { 40, 65, 52, 50, 76, 89, 133 },
-                                 { 28, 48, 91, 17, 64, 77, 133 },
-                                 { 218, 43, 43, 37, 56, 72, 163 },
-                                 { 41, 155, 44, 83, 82, 129, 180 },
-                                 { 44, 141, 29, 55, 64, 89, 147 },
-                                 { 92, 166, 48, 45, 59, 126, 179 },
-                                 { 169, 35, 49, 41, 36, 99, 139 },
-                                 { 55, 77, 77, 56, 60, 75, 156 },
-                                 { 155, 81, 51, 64, 57, 182, 255 },
-                                 { 60, 134, 49, 49, 93, 128, 174 },
-                                 { 244, 98, 51, 46, 22, 73, 238 },
-                                 { 189, 70, 40, 87, 93, 79, 201 },
-                                 { 248, 54, 49, 40, 29, 42, 227 },
-                             } };
+const aom_prob
+    av1_default_palette_uv_color_prob[PALETTE_MAX_SIZE - 1]
+                                     [PALETTE_COLOR_CONTEXTS]
+                                     [PALETTE_COLORS - 1] = {
+                                       {
+                                           // 2 colors
+                                           { 228, 0, 0, 0, 0, 0, 0 },
+                                           { 195, 0, 0, 0, 0, 0, 0 },
+                                           { 0, 0, 0, 0, 0, 0, 0 },
+                                           { 0, 0, 0, 0, 0, 0, 0 },
+                                           { 0, 0, 0, 0, 0, 0, 0 },
+                                           { 228, 0, 0, 0, 0, 0, 0 },
+                                           { 71, 0, 0, 0, 0, 0, 0 },
+                                           { 0, 0, 0, 0, 0, 0, 0 },
+                                           { 129, 0, 0, 0, 0, 0, 0 },
+                                           { 206, 0, 0, 0, 0, 0, 0 },
+                                           { 0, 0, 0, 0, 0, 0, 0 },
+                                           { 136, 0, 0, 0, 0, 0, 0 },
+                                           { 98, 0, 0, 0, 0, 0, 0 },
+                                           { 236, 0, 0, 0, 0, 0, 0 },
+                                           { 222, 0, 0, 0, 0, 0, 0 },
+                                           { 249, 0, 0, 0, 0, 0, 0 },
+                                       },
+                                       {
+                                           // 3 colors
+                                           { 198, 136, 0, 0, 0, 0, 0 },
+                                           { 178, 105, 0, 0, 0, 0, 0 },
+                                           { 100, 206, 0, 0, 0, 0, 0 },
+                                           { 0, 0, 0, 0, 0, 0, 0 },
+                                           { 12, 136, 0, 0, 0, 0, 0 },
+                                           { 219, 134, 0, 0, 0, 0, 0 },
+                                           { 50, 198, 0, 0, 0, 0, 0 },
+                                           { 61, 231, 0, 0, 0, 0, 0 },
+                                           { 110, 209, 0, 0, 0, 0, 0 },
+                                           { 173, 106, 0, 0, 0, 0, 0 },
+                                           { 145, 166, 0, 0, 0, 0, 0 },
+                                           { 156, 175, 0, 0, 0, 0, 0 },
+                                           { 69, 183, 0, 0, 0, 0, 0 },
+                                           { 241, 163, 0, 0, 0, 0, 0 },
+                                           { 224, 160, 0, 0, 0, 0, 0 },
+                                           { 246, 154, 0, 0, 0, 0, 0 },
+                                       },
+                                       {
+                                           // 4 colors
+                                           { 173, 88, 143, 0, 0, 0, 0 },
+                                           { 146, 81, 127, 0, 0, 0, 0 },
+                                           { 84, 134, 102, 0, 0, 0, 0 },
+                                           { 69, 138, 140, 0, 0, 0, 0 },
+                                           { 31, 103, 200, 0, 0, 0, 0 },
+                                           { 217, 101, 139, 0, 0, 0, 0 },
+                                           { 51, 174, 121, 0, 0, 0, 0 },
+                                           { 64, 177, 109, 0, 0, 0, 0 },
+                                           { 96, 179, 145, 0, 0, 0, 0 },
+                                           { 164, 77, 114, 0, 0, 0, 0 },
+                                           { 87, 94, 156, 0, 0, 0, 0 },
+                                           { 105, 57, 173, 0, 0, 0, 0 },
+                                           { 63, 158, 137, 0, 0, 0, 0 },
+                                           { 236, 102, 156, 0, 0, 0, 0 },
+                                           { 197, 115, 153, 0, 0, 0, 0 },
+                                           { 245, 106, 154, 0, 0, 0, 0 },
+                                       },
+                                       {
+                                           // 5 colors
+                                           { 179, 64, 97, 129, 0, 0, 0 },
+                                           { 137, 56, 88, 125, 0, 0, 0 },
+                                           { 82, 107, 61, 118, 0, 0, 0 },
+                                           { 59, 113, 86, 115, 0, 0, 0 },
+                                           { 23, 88, 118, 130, 0, 0, 0 },
+                                           { 213, 66, 90, 125, 0, 0, 0 },
+                                           { 37, 181, 103, 121, 0, 0, 0 },
+                                           { 47, 188, 61, 131, 0, 0, 0 },
+                                           { 104, 185, 103, 144, 0, 0, 0 },
+                                           { 163, 39, 76, 112, 0, 0, 0 },
+                                           { 94, 74, 131, 126, 0, 0, 0 },
+                                           { 142, 42, 103, 163, 0, 0, 0 },
+                                           { 53, 162, 99, 149, 0, 0, 0 },
+                                           { 239, 54, 84, 108, 0, 0, 0 },
+                                           { 203, 84, 110, 147, 0, 0, 0 },
+                                           { 248, 70, 105, 151, 0, 0, 0 },
+                                       },
+                                       {
+                                           // 6 colors
+                                           { 189, 50, 67, 90, 130, 0, 0 },
+                                           { 114, 50, 55, 90, 123, 0, 0 },
+                                           { 66, 76, 54, 82, 128, 0, 0 },
+                                           { 43, 69, 69, 80, 129, 0, 0 },
+                                           { 22, 59, 87, 88, 141, 0, 0 },
+                                           { 203, 49, 68, 87, 122, 0, 0 },
+                                           { 43, 157, 74, 104, 146, 0, 0 },
+                                           { 54, 138, 51, 95, 138, 0, 0 },
+                                           { 82, 171, 58, 102, 146, 0, 0 },
+                                           { 129, 38, 59, 64, 168, 0, 0 },
+                                           { 56, 67, 119, 92, 112, 0, 0 },
+                                           { 96, 62, 53, 132, 82, 0, 0 },
+                                           { 60, 147, 77, 108, 145, 0, 0 },
+                                           { 238, 76, 73, 93, 148, 0, 0 },
+                                           { 189, 86, 73, 103, 157, 0, 0 },
+                                           { 246, 62, 75, 83, 167, 0, 0 },
+                                       },
+                                       {
+                                           // 7 colors
+                                           { 179, 42, 51, 73, 99, 134, 0 },
+                                           { 119, 52, 52, 61, 64, 114, 0 },
+                                           { 53, 77, 35, 65, 71, 131, 0 },
+                                           { 38, 70, 51, 68, 89, 144, 0 },
+                                           { 23, 65, 128, 73, 97, 131, 0 },
+                                           { 210, 47, 52, 63, 81, 143, 0 },
+                                           { 42, 159, 57, 68, 98, 143, 0 },
+                                           { 49, 153, 45, 82, 93, 143, 0 },
+                                           { 81, 169, 52, 72, 113, 151, 0 },
+                                           { 136, 46, 35, 56, 75, 96, 0 },
+                                           { 57, 84, 109, 47, 107, 131, 0 },
+                                           { 128, 78, 57, 36, 128, 85, 0 },
+                                           { 54, 149, 68, 77, 94, 153, 0 },
+                                           { 243, 58, 50, 71, 81, 167, 0 },
+                                           { 189, 92, 64, 70, 121, 173, 0 },
+                                           { 248, 35, 38, 51, 82, 201, 0 },
+                                       },
+                                       {
+                                           // 8 colors
+                                           { 201, 40, 36, 42, 64, 92, 123 },
+                                           { 116, 43, 33, 43, 73, 102, 128 },
+                                           { 46, 77, 37, 69, 62, 78, 150 },
+                                           { 40, 65, 52, 50, 76, 89, 133 },
+                                           { 28, 48, 91, 17, 64, 77, 133 },
+                                           { 218, 43, 43, 37, 56, 72, 163 },
+                                           { 41, 155, 44, 83, 82, 129, 180 },
+                                           { 44, 141, 29, 55, 64, 89, 147 },
+                                           { 92, 166, 48, 45, 59, 126, 179 },
+                                           { 169, 35, 49, 41, 36, 99, 139 },
+                                           { 55, 77, 77, 56, 60, 75, 156 },
+                                           { 155, 81, 51, 64, 57, 182, 255 },
+                                           { 60, 134, 49, 49, 93, 128, 174 },
+                                           { 244, 98, 51, 46, 22, 73, 238 },
+                                           { 189, 70, 40, 87, 93, 79, 201 },
+                                           { 248, 54, 49, 40, 29, 42, 227 },
+                                       }
+                                     };
 
 static const int palette_color_context_lookup[PALETTE_COLOR_CONTEXTS] = {
   // (3, 0, 0, 0), (3, 2, 0, 0), (3, 3, 2, 0), (3, 3, 2, 2),
@@ -902,30 +905,24 @@
 int av1_get_palette_color_context(const uint8_t *color_map, int cols, int r,
                                   int c, int n, uint8_t *color_order,
                                   int *color_idx) {
-  int i, j, max, max_idx, temp;
+  int i;
+  // The +10 below should not be needed. But we get a warning "array subscript
+  // is above array bounds [-Werror=array-bounds]" without it, possibly due to
+  // this (or similar) bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
   int scores[PALETTE_MAX_SIZE + 10];
-  int weights[4] = { 3, 2, 3, 2 };
+  const int weights[4] = { 3, 2, 3, 2 };
   int color_ctx = 0;
   int color_neighbors[4];
   int inverse_color_order[PALETTE_MAX_SIZE];
   assert(n <= PALETTE_MAX_SIZE);
 
-  if (c - 1 >= 0)
-    color_neighbors[0] = color_map[r * cols + c - 1];
-  else
-    color_neighbors[0] = -1;
-  if (c - 1 >= 0 && r - 1 >= 0)
-    color_neighbors[1] = color_map[(r - 1) * cols + c - 1];
-  else
-    color_neighbors[1] = -1;
-  if (r - 1 >= 0)
-    color_neighbors[2] = color_map[(r - 1) * cols + c];
-  else
-    color_neighbors[2] = -1;
-  if (r - 1 >= 0 && c + 1 <= cols - 1)
-    color_neighbors[3] = color_map[(r - 1) * cols + c + 1];
-  else
-    color_neighbors[3] = -1;
+  color_neighbors[0] = (c - 1 >= 0) ? color_map[r * cols + c - 1] : -1;
+  color_neighbors[1] =
+      (c - 1 >= 0 && r - 1 >= 0) ? color_map[(r - 1) * cols + c - 1] : -1;
+  color_neighbors[2] = (r - 1 >= 0) ? color_map[(r - 1) * cols + c] : -1;
+  color_neighbors[3] = (r - 1 >= 0 && c + 1 <= cols - 1)
+                           ? color_map[(r - 1) * cols + c + 1]
+                           : -1;
 
   for (i = 0; i < PALETTE_MAX_SIZE; ++i) {
     color_order[i] = i;
@@ -933,23 +930,25 @@
   }
   memset(scores, 0, PALETTE_MAX_SIZE * sizeof(scores[0]));
   for (i = 0; i < 4; ++i) {
-    if (color_neighbors[i] >= 0) scores[color_neighbors[i]] += weights[i];
+    if (color_neighbors[i] >= 0) {
+      scores[color_neighbors[i]] += weights[i];
+    }
   }
 
+  // Get the top 4 scores (sorted from large to small).
   for (i = 0; i < 4; ++i) {
-    max = scores[i];
-    max_idx = i;
-    j = i + 1;
-    while (j < n) {
+    int max = scores[i];
+    int max_idx = i;
+    int j;
+    for (j = i + 1; j < n; ++j) {
       if (scores[j] > max) {
         max = scores[j];
         max_idx = j;
       }
-      ++j;
     }
 
     if (max_idx != i) {
-      temp = scores[i];
+      int temp = scores[i];
       scores[i] = scores[max_idx];
       scores[max_idx] = temp;
 
diff --git a/av1/common/reconinter.h b/av1/common/reconinter.h
index 351c7d4..5082d7b 100644
--- a/av1/common/reconinter.h
+++ b/av1/common/reconinter.h
@@ -418,7 +418,6 @@
                           const YV12_BUFFER_CONFIG *src, int mi_row, int mi_col,
                           const struct scale_factors *sf);
 
-#if CONFIG_DUAL_FILTER
 // Detect if the block have sub-pixel level motion vectors
 // per component.
 static INLINE int has_subpel_mv_component(const MODE_INFO *const mi,
@@ -460,57 +459,21 @@
 
   return 0;
 }
-#endif
 
 static INLINE int av1_is_interp_needed(const MACROBLOCKD *const xd) {
   MODE_INFO *const mi = xd->mi[0];
-  MB_MODE_INFO *const mbmi = &mi->mbmi;
-  const BLOCK_SIZE bsize = mbmi->sb_type;
-  const int is_compound = has_second_ref(mbmi);
-  int intpel_mv = 1;
-  int plane;
-
-#if SUPPORT_NONINTERPOLATING_FILTERS
-  // TODO(debargha): This is is currently only for experimentation
-  // with non-interpolating filters. Remove later.
-  // If any of the filters are non-interpolating, then indicate the
-  // interpolation filter always.
-  int i;
-  for (i = 0; i < SWITCHABLE_FILTERS; ++i) {
-    if (!IsInterpolatingFilter(i)) return 1;
-  }
-#endif
-
-  // For scaled references, interpolation filter is indicated all the time.
-  if (av1_is_scaled(&xd->block_refs[0]->sf)) return 1;
-  if (is_compound && av1_is_scaled(&xd->block_refs[1]->sf)) return 1;
-
-  if (bsize < BLOCK_8X8) {
-    for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
-      const PARTITION_TYPE bp = BLOCK_8X8 - bsize;
-      const struct macroblockd_plane *const pd = &xd->plane[plane];
-      const int have_vsplit = bp != PARTITION_HORZ;
-      const int have_hsplit = bp != PARTITION_VERT;
-      const int num_4x4_w = 2 >> ((!have_vsplit) | pd->subsampling_x);
-      const int num_4x4_h = 2 >> ((!have_hsplit) | pd->subsampling_y);
-      int ref;
-      for (ref = 0; ref < 1 + is_compound; ++ref) {
-        int x, y;
-        for (y = 0; y < num_4x4_h; ++y)
-          for (x = 0; x < num_4x4_w; ++x) {
-            const MV mv = average_split_mvs(pd, mi, ref, y * 2 + x);
-            if (mv_has_subpel(&mv)) return 1;
-          }
+  const int is_compound = has_second_ref(&mi->mbmi);
+  int ref;
+  for (ref = 0; ref < 1 + is_compound; ++ref) {
+    int row_col;
+    for (row_col = 0; row_col < 2; ++row_col) {
+      const int dir = (ref << 1) + row_col;
+      if (has_subpel_mv_component(mi, xd, dir)) {
+        return 1;
       }
     }
-    return 0;
-  } else {
-    intpel_mv = !mv_has_subpel(&mbmi->mv[0].as_mv);
-    if (is_compound && intpel_mv) {
-      intpel_mv &= !mv_has_subpel(&mbmi->mv[1].as_mv);
-    }
   }
-  return !intpel_mv;
+  return 0;
 }
 
 #if CONFIG_MOTION_VAR