Merge "Adds higher precision for homography model 3rd row" into nextgenv2
diff --git a/configure b/configure
index 2620369..ced8cb2 100755
--- a/configure
+++ b/configure
@@ -288,6 +288,7 @@
     ext_partition_types
     ext_tile
     obmc
+    warped_motion
     entropy
     bidir_pred
 "
diff --git a/test/active_map_refresh_test.cc b/test/active_map_refresh_test.cc
index 83d2443..9dd35b8 100644
--- a/test/active_map_refresh_test.cc
+++ b/test/active_map_refresh_test.cc
@@ -125,11 +125,18 @@
                           ::testing::Values(::libvpx_test::kRealTime),
                           ::testing::Range(5, 6));
 #if CONFIG_VP10
+#if CONFIG_EXT_PARTITION
 INSTANTIATE_TEST_CASE_P(
-    DISABLED_VP10, ActiveMapRefreshTest,
+    DISABLED_VP10,
+    ActiveMapRefreshTest,
     ::testing::Combine(
         ::testing::Values(static_cast<const libvpx_test::CodecFactory *>(
             &libvpx_test::kVP10)),
         ::testing::Values(::libvpx_test::kRealTime), ::testing::Range(5, 6)));
+#else
+VP10_INSTANTIATE_TEST_CASE(ActiveMapRefreshTest,
+                           ::testing::Values(::libvpx_test::kRealTime),
+                           ::testing::Range(5, 6));
+#endif  // CONFIG_EXT_PARTITION
 #endif  // CONFIG_VP10
 }  // namespace
diff --git a/test/test.mk b/test/test.mk
index a4a7c63..9a87a80 100644
--- a/test/test.mk
+++ b/test/test.mk
@@ -185,7 +185,6 @@
 LIBVPX_TEST_SRCS-$(HAVE_SSSE3) += masked_variance_test.cc
 LIBVPX_TEST_SRCS-$(HAVE_SSSE3) += masked_sad_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP10_ENCODER) += blend_mask6_test.cc
-LIBVPX_TEST_SRCS-$(CONFIG_VP10_ENCODER) += vp10_wedge_utils_test.cc
 endif
 
 ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
diff --git a/test/vp10_wedge_utils_test.cc b/test/vp10_wedge_utils_test.cc
deleted file mode 100644
index 9d93c75..0000000
--- a/test/vp10_wedge_utils_test.cc
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "third_party/googletest/src/include/gtest/gtest.h"
-
-#include "./vpx_config.h"
-#include "vpx_ports/mem.h"
-
-#include "./vpx_dsp_rtcd.h"
-#include "./vp10_rtcd.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-
-#include "vp10/common/enums.h"
-
-#include "test/array_utils.h"
-#include "test/assertion_helpers.h"
-#include "test/function_equivalence_test.h"
-#include "test/randomise.h"
-#include "test/register_state_check.h"
-#include "test/snapshot.h"
-
-#define WEDGE_WEIGHT_BITS 6
-#define MAX_MASK_VALUE  (1 << (WEDGE_WEIGHT_BITS))
-
-using std::tr1::make_tuple;
-using libvpx_test::FunctionEquivalenceTest;
-using libvpx_test::Snapshot;
-using libvpx_test::Randomise;
-using libvpx_test::array_utils::arraySet;
-using libvpx_test::assertion_helpers::ArraysEq;
-using libvpx_test::assertion_helpers::ArraysEqWithin;
-
-namespace {
-
-static const int16_t int13_max = (1<<12) - 1;
-
-//////////////////////////////////////////////////////////////////////////////
-// vp10_wedge_sse_from_residuals - functionality
-//////////////////////////////////////////////////////////////////////////////
-
-class WedgeUtilsSSEFuncTest : public testing::Test {
- protected:
-  Snapshot snapshot;
-  Randomise randomise;
-};
-
-static void equiv_blend_residuals(int16_t *r,
-                                  const int16_t *r0,
-                                  const int16_t *r1,
-                                  const uint8_t *m,
-                                  int N) {
-  for (int i = 0 ; i < N ; i++) {
-    const int32_t m0 = m[i];
-    const int32_t m1 = MAX_MASK_VALUE - m0;
-    const int16_t R = m0 * r0[i] + m1 * r1[i];
-    // Note that this rounding is designed to match the result
-    // you would get when actually blending the 2 predictors and computing
-    // the residuals.
-    r[i] = ROUND_POWER_OF_TWO(R - 1, WEDGE_WEIGHT_BITS);
-  }
-}
-
-static uint64_t equiv_sse_from_residuals(const int16_t *r0,
-                                         const int16_t *r1,
-                                         const uint8_t *m,
-                                         int N) {
-  uint64_t acc = 0;
-  for (int i = 0 ; i < N ; i++) {
-    const int32_t m0 = m[i];
-    const int32_t m1 = MAX_MASK_VALUE - m0;
-    const int16_t R = m0 * r0[i] + m1 * r1[i];
-    const int32_t r = ROUND_POWER_OF_TWO(R - 1, WEDGE_WEIGHT_BITS);
-    acc += r * r;
-  }
-  return acc;
-}
-
-TEST_F(WedgeUtilsSSEFuncTest, ResidualBlendingEquiv) {
-  for (int i = 0 ; i < 1000 && !HasFatalFailure(); i++) {
-    uint8_t s[MAX_SB_SQUARE];
-    uint8_t p0[MAX_SB_SQUARE];
-    uint8_t p1[MAX_SB_SQUARE];
-    uint8_t p[MAX_SB_SQUARE];
-
-    int16_t r0[MAX_SB_SQUARE];
-    int16_t r1[MAX_SB_SQUARE];
-    int16_t r_ref[MAX_SB_SQUARE];
-    int16_t r_tst[MAX_SB_SQUARE];
-    uint8_t m[MAX_SB_SQUARE];
-
-    randomise(s);
-    randomise(m, 0, MAX_MASK_VALUE + 1);
-
-    const int w = 1 << randomise.uniform<uint32_t>(3, MAX_SB_SIZE_LOG2);
-    const int h = 1 << randomise.uniform<uint32_t>(3, MAX_SB_SIZE_LOG2);
-    const int N = w * h;
-
-    for (int j = 0 ; j < N ; j++) {
-      p0[j] = clamp(s[j] + randomise.uniform<int>(-16, 17), 0, UINT8_MAX);
-      p1[j] = clamp(s[j] + randomise.uniform<int>(-16, 17), 0, UINT8_MAX);
-    }
-    vpx_blend_mask6(p, w, p0, w, p1, w, m, w, h, w, 0, 0);
-
-    vpx_subtract_block(h, w, r0, w, s, w, p0, w);
-    vpx_subtract_block(h, w, r1, w, s, w, p1, w);
-
-    vpx_subtract_block(h, w, r_ref, w, s, w, p, w);
-    equiv_blend_residuals(r_tst, r0, r1, m, N);
-
-    ASSERT_TRUE(ArraysEqWithin(r_ref, r_tst, 0, N));
-
-    uint64_t ref_sse = vpx_sum_squares_i16(r_ref, N);
-    uint64_t tst_sse = equiv_sse_from_residuals(r0, r1, m, N);
-
-    ASSERT_EQ(ref_sse, tst_sse);
-  }
-}
-
-static uint64_t sse_from_residuals(const int16_t *r0,
-                                   const int16_t *r1,
-                                   const uint8_t *m,
-                                   int N) {
-  uint64_t acc = 0;
-  for (int i = 0 ; i < N ; i++) {
-    const int32_t m0 = m[i];
-    const int32_t m1 = MAX_MASK_VALUE - m0;
-    const int32_t r = m0 * r0[i] + m1 * r1[i];
-    acc += r * r;
-  }
-  return ROUND_POWER_OF_TWO(acc, 2 * WEDGE_WEIGHT_BITS);
-}
-
-TEST_F(WedgeUtilsSSEFuncTest, ResidualBlendingMethod) {
-  for (int i = 0 ; i < 1000 && !HasFatalFailure(); i++) {
-    int16_t r0[MAX_SB_SQUARE];
-    int16_t r1[MAX_SB_SQUARE];
-    int16_t d[MAX_SB_SQUARE];
-    uint8_t m[MAX_SB_SQUARE];
-
-    randomise(r1, 2 * INT8_MIN, 2 * INT8_MAX + 1);
-    randomise(d, 2 * INT8_MIN, 2 * INT8_MAX + 1);
-    randomise(m, 0, MAX_MASK_VALUE + 1);
-
-    const int N = 64 * randomise.uniform<uint32_t>(1, MAX_SB_SQUARE/64);
-
-    for (int j = 0 ; j < N ; j++)
-      r0[j] = r1[j] + d[j];
-
-    uint64_t ref_res, tst_res;
-
-    ref_res = sse_from_residuals(r0, r1, m, N);
-    tst_res = vp10_wedge_sse_from_residuals(r1, d, m, N);
-
-    ASSERT_EQ(ref_res, tst_res);
-  }
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// vp10_wedge_sse_from_residuals - optimizations
-//////////////////////////////////////////////////////////////////////////////
-
-typedef uint64_t (*FSSE)(const int16_t *r1,
-                         const int16_t *d,
-                         const uint8_t *m,
-                         int N);
-
-class WedgeUtilsSSEOptTest : public FunctionEquivalenceTest<FSSE> {
- protected:
-  void Common() {
-    const int N = 64 * randomise.uniform<uint32_t>(1, MAX_SB_SQUARE/64);
-
-    snapshot(r1);
-    snapshot(d);
-    snapshot(m);
-
-    uint64_t ref_res, tst_res;
-
-    ref_res = ref_func_(r1, d, m, N);
-    ASM_REGISTER_STATE_CHECK(tst_res = tst_func_(r1, d, m, N));
-
-    ASSERT_EQ(ref_res, tst_res);
-
-    ASSERT_TRUE(ArraysEq(snapshot.get(r1), r1));
-    ASSERT_TRUE(ArraysEq(snapshot.get(d), d));
-    ASSERT_TRUE(ArraysEq(snapshot.get(m), m));
-  }
-
-  Snapshot snapshot;
-  Randomise randomise;
-
-  DECLARE_ALIGNED(16, int16_t, r1[MAX_SB_SQUARE]);
-  DECLARE_ALIGNED(16, int16_t, d[MAX_SB_SQUARE]);
-  DECLARE_ALIGNED(16, uint8_t, m[MAX_SB_SQUARE]);
-};
-
-TEST_P(WedgeUtilsSSEOptTest, RandomValues) {
-  for (int i = 0 ; i < 10000 && !HasFatalFailure(); i++) {
-    randomise(r1, -int13_max, int13_max + 1);
-    randomise(d, -int13_max, int13_max + 1);
-    randomise(m, 0, 65);
-
-    Common();
-  }
-}
-
-TEST_P(WedgeUtilsSSEOptTest, ExtremeValues) {
-  for (int i = 0 ; i < 10000 && !HasFatalFailure(); i++) {
-    if (randomise.uniform<bool>())
-      arraySet(r1, int13_max);
-    else
-      arraySet(r1, -int13_max);
-
-    if (randomise.uniform<bool>())
-      arraySet(d, int13_max);
-    else
-      arraySet(d, -int13_max);
-
-    arraySet(m, MAX_MASK_VALUE);
-
-    Common();
-  }
-}
-
-#if HAVE_SSE2
-INSTANTIATE_TEST_CASE_P(
-    SSE2, WedgeUtilsSSEOptTest,
-    ::testing::Values(
-        make_tuple(&vp10_wedge_sse_from_residuals_c,
-                   &vp10_wedge_sse_from_residuals_sse2)
-    )
-);
-#endif  // HAVE_SSE2
-
-//////////////////////////////////////////////////////////////////////////////
-// vp10_wedge_sign_from_residuals
-//////////////////////////////////////////////////////////////////////////////
-
-typedef int (*FSign)(const int16_t *ds,
-                     const uint8_t *m,
-                     int N,
-                     int64_t limit);
-
-class WedgeUtilsSignOptTest : public FunctionEquivalenceTest<FSign> {
- protected:
-  static const int maxSize = 8196;  // Size limited by SIMD implementation.
-
-  void Common() {
-    const int maxN = VPXMIN(maxSize, MAX_SB_SQUARE);
-    const int N = 64 * randomise.uniform<uint32_t>(1, maxN/64);
-
-    int64_t limit;
-    limit = (int64_t)vpx_sum_squares_i16(r0, N);
-    limit -= (int64_t)vpx_sum_squares_i16(r1, N);
-    limit *= (1 << WEDGE_WEIGHT_BITS) / 2;
-
-    for (int i = 0 ; i < N ; i++)
-      ds[i] = clamp(r0[i]*r0[i] - r1[i]*r1[i], INT16_MIN, INT16_MAX);
-
-    snapshot(r0);
-    snapshot(r1);
-    snapshot(ds);
-    snapshot(m);
-
-    int ref_res, tst_res;
-
-    ref_res = ref_func_(ds, m, N, limit);
-    ASM_REGISTER_STATE_CHECK(tst_res = tst_func_(ds, m, N, limit));
-
-    ASSERT_EQ(ref_res, tst_res);
-
-    ASSERT_TRUE(ArraysEq(snapshot.get(r0), r0));
-    ASSERT_TRUE(ArraysEq(snapshot.get(r1), r1));
-    ASSERT_TRUE(ArraysEq(snapshot.get(ds), ds));
-    ASSERT_TRUE(ArraysEq(snapshot.get(m), m));
-  }
-
-  Snapshot snapshot;
-  Randomise randomise;
-
-  DECLARE_ALIGNED(16, int16_t, r0[MAX_SB_SQUARE]);
-  DECLARE_ALIGNED(16, int16_t, r1[MAX_SB_SQUARE]);
-  DECLARE_ALIGNED(16, int16_t, ds[MAX_SB_SQUARE]);
-  DECLARE_ALIGNED(16, uint8_t, m[MAX_SB_SQUARE]);
-};
-
-TEST_P(WedgeUtilsSignOptTest, RandomValues) {
-  for (int i = 0 ; i < 10000 && !HasFatalFailure(); i++) {
-    randomise(r0, -int13_max, int13_max+1);
-    randomise(r1, -int13_max, int13_max+1);
-    randomise(m, 0, MAX_MASK_VALUE + 1);
-
-    Common();
-  }
-}
-
-TEST_P(WedgeUtilsSignOptTest, ExtremeValues) {
-  for (int i = 0 ; i < 10000 && !HasFatalFailure(); i++) {
-    switch (randomise.uniform<int>(4)) {
-    case 0:
-      arraySet(r0, 0);
-      arraySet(r1, int13_max);
-      break;
-    case 1:
-      arraySet(r0, int13_max);
-      arraySet(r1, 0);
-      break;
-    case 2:
-      arraySet(r0, 0);
-      arraySet(r1, -int13_max);
-      break;
-    default:
-      arraySet(r0, -int13_max);
-      arraySet(r1, 0);
-      break;
-    }
-
-    arraySet(m, MAX_MASK_VALUE);
-
-    Common();
-  }
-}
-
-#if HAVE_SSE2
-INSTANTIATE_TEST_CASE_P(
-    SSE2, WedgeUtilsSignOptTest,
-    ::testing::Values(
-        make_tuple(&vp10_wedge_sign_from_residuals_c,
-                   &vp10_wedge_sign_from_residuals_sse2)
-    )
-);
-#endif  // HAVE_SSE2
-
-//////////////////////////////////////////////////////////////////////////////
-// vp10_wedge_compute_delta_squares
-//////////////////////////////////////////////////////////////////////////////
-
-typedef void (*FDS)(int16_t *d,
-                    const int16_t *a,
-                    const int16_t *b,
-                    int N);
-
-class WedgeUtilsDeltaSquaresOptTest : public FunctionEquivalenceTest<FDS> {
- protected:
-  void Common() {
-    const int N = 64 * randomise.uniform<uint32_t>(1, MAX_SB_SQUARE/64);
-
-    randomise(d_ref);
-    randomise(d_tst);
-
-    snapshot(a);
-    snapshot(b);
-
-    ref_func_(d_ref, a, b, N);
-    ASM_REGISTER_STATE_CHECK(tst_func_(d_tst, a, b, N));
-
-    ASSERT_TRUE(ArraysEqWithin(d_ref, d_tst, 0, N));
-
-    ASSERT_TRUE(ArraysEq(snapshot.get(a), a));
-    ASSERT_TRUE(ArraysEq(snapshot.get(b), b));
-  }
-
-  Snapshot snapshot;
-  Randomise randomise;
-
-  DECLARE_ALIGNED(16, int16_t, a[MAX_SB_SQUARE]);
-  DECLARE_ALIGNED(16, int16_t, b[MAX_SB_SQUARE]);
-  DECLARE_ALIGNED(16, int16_t, d_ref[MAX_SB_SQUARE]);
-  DECLARE_ALIGNED(16, int16_t, d_tst[MAX_SB_SQUARE]);
-};
-
-TEST_P(WedgeUtilsDeltaSquaresOptTest, RandomValues) {
-  for (int i = 0 ; i < 10000 && !HasFatalFailure(); i++) {
-    randomise(a);
-    randomise(b, -INT16_MAX, INT16_MAX + 1);
-
-    Common();
-  }
-}
-
-#if HAVE_SSE2
-INSTANTIATE_TEST_CASE_P(
-    SSE2, WedgeUtilsDeltaSquaresOptTest,
-    ::testing::Values(
-        make_tuple(&vp10_wedge_compute_delta_squares_c,
-                   &vp10_wedge_compute_delta_squares_sse2)
-    )
-);
-#endif  // HAVE_SSE2
-
-
-}  // namespace
diff --git a/test/vp9_end_to_end_test.cc b/test/vp9_end_to_end_test.cc
index 98e9e30..a32265e 100644
--- a/test/vp9_end_to_end_test.cc
+++ b/test/vp9_end_to_end_test.cc
@@ -32,9 +32,9 @@
 #if CONFIG_VP10_ENCODER && CONFIG_VP9_HIGHBITDEPTH
   { 36.0, 37.0, 37.0, 37.0, 37.0 },
   { 31.0, 36.0, 36.0, 36.0, 36.0 },
-  { 32.0, 35.0, 35.0, 35.0, 35.0 },
-  { 32.0, 34.0, 34.0, 34.0, 34.0 },
-  { 32.0, 33.0, 33.0, 33.0, 33.0 },
+  { 31.0, 35.0, 35.0, 35.0, 35.0 },
+  { 31.0, 34.0, 34.0, 34.0, 34.0 },
+  { 31.0, 33.0, 33.0, 33.0, 33.0 },
   { 31.0, 32.0, 32.0, 32.0, 32.0 },
   { 30.0, 31.0, 31.0, 31.0, 31.0 },
   { 29.0, 30.0, 30.0, 30.0, 30.0 },
diff --git a/vp10/common/blockd.h b/vp10/common/blockd.h
index 87e5d1c..5391d12 100644
--- a/vp10/common/blockd.h
+++ b/vp10/common/blockd.h
@@ -19,6 +19,7 @@
 #include "vpx_scale/yv12config.h"
 
 #include "vp10/common/common_data.h"
+#include "vp10/common/quant_common.h"
 #include "vp10/common/entropy.h"
 #include "vp10/common/entropymode.h"
 #include "vp10/common/mv.h"
@@ -215,6 +216,10 @@
 #if CONFIG_EXT_PARTITION_TYPES
   PARTITION_TYPE partition;
 #endif
+#if CONFIG_NEW_QUANT
+  int dq_off_index;
+  int send_dq_bit;
+#endif  // CONFIG_NEW_QUANT
 } MB_MODE_INFO;
 
 typedef struct MODE_INFO {
@@ -261,6 +266,9 @@
   ENTROPY_CONTEXT *above_context;
   ENTROPY_CONTEXT *left_context;
   int16_t seg_dequant[MAX_SEGMENTS][2];
+#if CONFIG_NEW_QUANT
+  dequant_val_type_nuq seg_dequant_nuq[MAX_SEGMENTS][COEF_BANDS];
+#endif
   uint8_t *color_index_map;
 
   // number of 4x4s in current block
@@ -270,6 +278,9 @@
 
   // encoder
   const int16_t *dequant;
+#if CONFIG_NEW_QUANT
+  const dequant_val_type_nuq* dequant_val_nuq;
+#endif  // CONFIG_NEW_QUANT
 } MACROBLOCKD_PLANE;
 
 #define BLOCK_OFFSET(x, i) ((x) + (i) * 16)
diff --git a/vp10/common/enums.h b/vp10/common/enums.h
index cdebc69..7ff4453 100644
--- a/vp10/common/enums.h
+++ b/vp10/common/enums.h
@@ -139,6 +139,8 @@
 
 #define MAX_TX_SIZE_LOG2  5
 #define MAX_TX_SIZE       (1 << MAX_TX_SIZE_LOG2)
+#define MIN_TX_SIZE_LOG2  2
+#define MIN_TX_SIZE       (1 << MIN_TX_SIZE_LOG2)
 #define MAX_TX_SQUARE     (MAX_TX_SIZE * MAX_TX_SIZE)
 
 // Number of maxium size transform blocks in the maximum size superblock
@@ -146,6 +148,8 @@
   ((MAX_SB_SIZE_LOG2 - MAX_TX_SIZE_LOG2) * 2)
 #define MAX_TX_BLOCKS_IN_MAX_SB (1 << MAX_TX_BLOCKS_IN_MAX_SB_LOG2)
 
+#define MAX_NUM_TXB  (1 << (MAX_SB_SIZE_LOG2 - MIN_TX_SIZE_LOG2))
+
 // frame transform mode
 typedef enum {
   ONLY_4X4            = 0,        // only 4x4 transform used
diff --git a/vp10/common/onyxc_int.h b/vp10/common/onyxc_int.h
index cbfa8b6..3ea4f3a 100644
--- a/vp10/common/onyxc_int.h
+++ b/vp10/common/onyxc_int.h
@@ -218,6 +218,10 @@
   int uv_ac_delta_q;
   int16_t y_dequant[MAX_SEGMENTS][2];
   int16_t uv_dequant[MAX_SEGMENTS][2];
+#if CONFIG_NEW_QUANT
+  dequant_val_type_nuq y_dequant_nuq[MAX_SEGMENTS][COEF_BANDS];
+  dequant_val_type_nuq uv_dequant_nuq[MAX_SEGMENTS][COEF_BANDS];
+#endif
 
   /* We allocate a MODE_INFO struct for each macroblock, together with
      an extra row on top and column on the left to simplify prediction. */
@@ -429,14 +433,21 @@
 static INLINE void vp10_init_macroblockd(VP10_COMMON *cm, MACROBLOCKD *xd,
                                         tran_low_t *dqcoeff) {
   int i;
-
   for (i = 0; i < MAX_MB_PLANE; ++i) {
     xd->plane[i].dqcoeff = dqcoeff;
     xd->above_context[i] = cm->above_context[i];
     if (xd->plane[i].plane_type == PLANE_TYPE_Y) {
       memcpy(xd->plane[i].seg_dequant, cm->y_dequant, sizeof(cm->y_dequant));
+#if CONFIG_NEW_QUANT
+      memcpy(xd->plane[i].seg_dequant_nuq, cm->y_dequant_nuq,
+             sizeof(cm->y_dequant_nuq));
+#endif
     } else {
       memcpy(xd->plane[i].seg_dequant, cm->uv_dequant, sizeof(cm->uv_dequant));
+#if CONFIG_NEW_QUANT
+      memcpy(xd->plane[i].seg_dequant_nuq, cm->uv_dequant_nuq,
+             sizeof(cm->uv_dequant_nuq));
+#endif
     }
     xd->fc = cm->fc;
   }
diff --git a/vp10/common/quant_common.c b/vp10/common/quant_common.c
index b1fb34d..f5886be 100644
--- a/vp10/common/quant_common.c
+++ b/vp10/common/quant_common.c
@@ -34,18 +34,18 @@
 
 // TODO(sarahparker) add multiple quantization profiles
 static const uint8_t nuq_knots[COEF_BANDS][NUQ_KNOTS] = {
-    {86, 122, 134},  // dc, band 0
+    {91, 133, 139},  // dc, band 0
     {78, 122, 134},  // band 1
-    {78, 122, 134},  // band 2
-    {84, 122, 133},  // band 3
-    {88, 122, 134},  // band 4
-    {88, 122, 134},  // band 5
+    {83, 127, 139},  // band 2
+    {84, 117, 128},  // band 3
+    {88, 117, 129},  // band 4
+    {93, 122, 134},  // band 5
 };
 
 // dequantization offsets
 static const uint8_t nuq_doff_lossless[COEF_BANDS] = {0, 0, 0, 0, 0, 0};
 
-static const uint8_t nuq_doff[COEF_BANDS] = {8, 15, 16, 22, 23, 24};
+static const uint8_t nuq_doff[COEF_BANDS] = {11, 12, 22, 18, 20, 21};
 
 static const uint8_t *get_nuq_knots(int lossless, int band) {
   if (lossless)
diff --git a/vp10/common/quant_common.h b/vp10/common/quant_common.h
index 5be0793..ebb82e8 100644
--- a/vp10/common/quant_common.h
+++ b/vp10/common/quant_common.h
@@ -31,6 +31,8 @@
 
 #if CONFIG_NEW_QUANT
 #define NUQ_KNOTS 3
+typedef tran_low_t dequant_val_type_nuq[NUQ_KNOTS + 1];
+typedef tran_low_t cuml_bins_type_nuq[NUQ_KNOTS];
 void get_dequant_val_nuq(int q, int lossless, int band,
                          tran_low_t *dq, tran_low_t *cumbins);
 tran_low_t dequant_abscoeff_nuq(int v, int q, const tran_low_t *dq);
diff --git a/vp10/common/reconinter.c b/vp10/common/reconinter.c
index a8278c4..083100f 100644
--- a/vp10/common/reconinter.c
+++ b/vp10/common/reconinter.c
@@ -2440,6 +2440,7 @@
                                                  int wedge_offset_x,
                                                  int wedge_offset_y,
 #endif  // CONFIG_SUPERTX
+                                                 int mi_x, int mi_y,
                                                  uint8_t *ext_dst0,
                                                  int ext_dst_stride0,
                                                  uint8_t *ext_dst1,
@@ -2453,6 +2454,8 @@
   (void) block;
   (void) bw;
   (void) bh;
+  (void) mi_x;
+  (void) mi_y;
 
   if (is_compound
       && is_interinter_wedge_used(mbmi->sb_type)
@@ -2516,9 +2519,12 @@
 void vp10_build_wedge_inter_predictor_from_buf(
     MACROBLOCKD *xd, BLOCK_SIZE bsize,
     int plane_from, int plane_to,
+    int mi_row, int mi_col,
     uint8_t *ext_dst0[3], int ext_dst_stride0[3],
     uint8_t *ext_dst1[3], int ext_dst_stride1[3]) {
   int plane;
+  const int mi_x = mi_col * MI_SIZE;
+  const int mi_y = mi_row * MI_SIZE;
   for (plane = plane_from; plane <= plane_to; ++plane) {
     const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize,
                                                         &xd->plane[plane]);
@@ -2537,6 +2543,7 @@
 #if CONFIG_SUPERTX
                                                0, 0,
 #endif
+                                               mi_x, mi_y,
                                                ext_dst0[plane],
                                                ext_dst_stride0[plane],
                                                ext_dst1[plane],
@@ -2547,6 +2554,7 @@
 #if CONFIG_SUPERTX
                                            0, 0,
 #endif
+                                           mi_x, mi_y,
                                            ext_dst0[plane],
                                            ext_dst_stride0[plane],
                                            ext_dst1[plane],
diff --git a/vp10/common/reconinter.h b/vp10/common/reconinter.h
index dad4962..e84e20e 100644
--- a/vp10/common/reconinter.h
+++ b/vp10/common/reconinter.h
@@ -646,6 +646,7 @@
 void vp10_build_wedge_inter_predictor_from_buf(
     MACROBLOCKD *xd, BLOCK_SIZE bsize,
     int plane_from, int plane_to,
+    int mi_row, int mi_col,
     uint8_t *ext_dst0[3], int ext_dst_stride0[3],
     uint8_t *ext_dst1[3], int ext_dst_stride1[3]);
 #endif  // CONFIG_EXT_INTER
diff --git a/vp10/common/restoration.h b/vp10/common/restoration.h
index 980fe72..8c0f143 100644
--- a/vp10/common/restoration.h
+++ b/vp10/common/restoration.h
@@ -34,13 +34,13 @@
 #define RESTORATION_FILT_BITS 7
 #define RESTORATION_FILT_STEP (1 << RESTORATION_FILT_BITS)
 
-#define WIENER_FILT_TAP0_MINV     3
+#define WIENER_FILT_TAP0_MINV     -5
 #define WIENER_FILT_TAP1_MINV     (-23)
-#define WIENER_FILT_TAP2_MINV     5
+#define WIENER_FILT_TAP2_MINV     -20
 
-#define WIENER_FILT_TAP0_BITS     2
-#define WIENER_FILT_TAP1_BITS     4
-#define WIENER_FILT_TAP2_BITS     5
+#define WIENER_FILT_TAP0_BITS     4
+#define WIENER_FILT_TAP1_BITS     5
+#define WIENER_FILT_TAP2_BITS     6
 
 #define WIENER_FILT_BITS \
   ((WIENER_FILT_TAP0_BITS + WIENER_FILT_TAP1_BITS + WIENER_FILT_TAP2_BITS) * 2)
diff --git a/vp10/common/vp10_rtcd_defs.pl b/vp10/common/vp10_rtcd_defs.pl
index d687380..b30953d 100644
--- a/vp10/common/vp10_rtcd_defs.pl
+++ b/vp10/common/vp10_rtcd_defs.pl
@@ -7,6 +7,7 @@
 #include "vpx/vpx_integer.h"
 #include "vp10/common/common.h"
 #include "vp10/common/enums.h"
+#include "vp10/common/quant_common.h"
 #include "vp10/common/vp10_txfm.h"
 
 struct macroblockd;
@@ -286,6 +287,20 @@
   }
 }
 
+if (vpx_config("CONFIG_NEW_QUANT") eq "yes") {
+  add_proto qw/void quantize_nuq/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, const int16_t *dequant_ptr, const cuml_bins_type_nuq *cuml_bins_ptr, const dequant_val_type_nuq *dequant_val, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const int16_t *scan, const uint8_t *band";
+  specialize qw/quantize_nuq/;
+
+  add_proto qw/void quantize_fp_nuq/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *quant_ptr, const int16_t *dequant_ptr, const cuml_bins_type_nuq *cuml_bins_ptr, const dequant_val_type_nuq *dequant_val, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const int16_t *scan, const uint8_t *band";
+  specialize qw/quantize_fp_nuq/;
+
+  add_proto qw/void quantize_32x32_nuq/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, const int16_t *dequant_ptr, const cuml_bins_type_nuq *cuml_bins_ptr, const dequant_val_type_nuq *dequant_val, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const int16_t *scan, const uint8_t *band";
+  specialize qw/quantize_32x32_nuq/;
+
+  add_proto qw/void quantize_32x32_fp_nuq/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *quant_ptr, const int16_t *dequant_ptr, const cuml_bins_type_nuq *cuml_bins_ptr, const dequant_val_type_nuq *dequant_val, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const int16_t *scan, const uint8_t *band";
+  specialize qw/quantize_32x32_fp_nuq/;
+}
+
 # High bitdepth functions
 if (vpx_config("CONFIG_VP9_HIGHBITDEPTH") eq "yes") {
   #
@@ -658,6 +673,19 @@
 if (vpx_config("CONFIG_VP9_HIGHBITDEPTH") eq "yes") {
 
   # ENCODEMB INVOKE
+  if (vpx_config("CONFIG_NEW_QUANT") eq "yes") {
+    add_proto qw/void highbd_quantize_nuq/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, const int16_t *dequant_ptr, const cuml_bins_type_nuq *cuml_bins_ptr, const dequant_val_type_nuq *dequant_val, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const int16_t *scan, const uint8_t *band";
+    specialize qw/highbd_quantize_nuq/;
+
+    add_proto qw/void highbd_quantize_fp_nuq/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *quant_ptr, const int16_t *dequant_ptr, const cuml_bins_type_nuq *cuml_bins_ptr, const dequant_val_type_nuq *dequant_val, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const int16_t *scan, const uint8_t *band";
+    specialize qw/highbd_quantize_fp_nuq/;
+
+    add_proto qw/void highbd_quantize_32x32_nuq/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, const int16_t *dequant_ptr, const cuml_bins_type_nuq *cuml_bins_ptr, const dequant_val_type_nuq *dequant_val, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const int16_t *scan, const uint8_t *band";
+    specialize qw/highbd_quantize_32x32_nuq/;
+
+    add_proto qw/void highbd_quantize_32x32_fp_nuq/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *quant_ptr, const int16_t *dequant_ptr, const cuml_bins_type_nuq *cuml_bins_ptr, const dequant_val_type_nuq *dequant_val, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const int16_t *scan, const uint8_t *band";
+    specialize qw/highbd_quantize_32x32_fp_nuq/;
+  }
 
   add_proto qw/int64_t vp10_highbd_block_error/, "const tran_low_t *coeff, const tran_low_t *dqcoeff, intptr_t block_size, int64_t *ssz, int bd";
   specialize qw/vp10_highbd_block_error sse2/;
@@ -690,15 +718,6 @@
 }
 # End vp10_high encoder functions
 
-if (vpx_config("CONFIG_EXT_INTER") eq "yes") {
-  add_proto qw/uint64_t vp10_wedge_sse_from_residuals/, "const int16_t *r1, const int16_t *d, const uint8_t *m, int N";
-  specialize qw/vp10_wedge_sse_from_residuals sse2/;
-  add_proto qw/int vp10_wedge_sign_from_residuals/, "const int16_t *ds, const uint8_t *m, int N, int64_t limit";
-  specialize qw/vp10_wedge_sign_from_residuals sse2/;
-  add_proto qw/void vp10_wedge_compute_delta_squares/, "int16_t *d, const int16_t *a, const int16_t *b, int N";
-  specialize qw/vp10_wedge_compute_delta_squares sse2/;
-}
-
 }
 # end encoder functions
 1;
diff --git a/vp10/decoder/decodeframe.c b/vp10/decoder/decodeframe.c
index 83d08b1..199891a 100644
--- a/vp10/decoder/decodeframe.c
+++ b/vp10/decoder/decodeframe.c
@@ -2046,6 +2046,9 @@
 
 static void setup_segmentation_dequant(VP10_COMMON *const cm) {
   // Build y/uv dequant values based on segmentation.
+#if CONFIG_NEW_QUANT
+  int b;
+#endif
   if (cm->seg.enabled) {
     int i;
     for (i = 0; i < MAX_SEGMENTS; ++i) {
@@ -2057,6 +2060,16 @@
                                           cm->bit_depth);
       cm->uv_dequant[i][1] = vp10_ac_quant(qindex, cm->uv_ac_delta_q,
                                           cm->bit_depth);
+#if CONFIG_NEW_QUANT
+      for (b = 0; b < COEF_BANDS; ++b) {
+        get_dequant_val_nuq(
+            cm->y_dequant[i][b != 0], qindex == 0, b,
+            cm->y_dequant_nuq[i][b], NULL);
+        get_dequant_val_nuq(
+            cm->uv_dequant[i][b != 0], qindex == 0, b,
+            cm->uv_dequant_nuq[i][b], NULL);
+      }
+#endif
     }
   } else {
     const int qindex = cm->base_qindex;
@@ -2068,6 +2081,16 @@
                                         cm->bit_depth);
     cm->uv_dequant[0][1] = vp10_ac_quant(qindex, cm->uv_ac_delta_q,
                                         cm->bit_depth);
+#if CONFIG_NEW_QUANT
+    for (b = 0; b < COEF_BANDS; ++b) {
+      get_dequant_val_nuq(
+          cm->y_dequant[0][b != 0], qindex == 0, b,
+          cm->y_dequant_nuq[0][b], NULL);
+      get_dequant_val_nuq(
+          cm->uv_dequant[0][b != 0], qindex == 0, b,
+          cm->uv_dequant_nuq[0][b], NULL);
+    }
+#endif
   }
 }
 
@@ -3057,7 +3080,6 @@
   RefCntBuffer *const frame_bufs = pool->frame_bufs;
   int i, mask, ref_index = 0;
   size_t sz;
-
 #if CONFIG_EXT_REFS
   cm->last3_frame_type = cm->last2_frame_type;
   cm->last2_frame_type = cm->last_frame_type;
diff --git a/vp10/decoder/detokenize.c b/vp10/decoder/detokenize.c
index 953af56..000b30b 100644
--- a/vp10/decoder/detokenize.c
+++ b/vp10/decoder/detokenize.c
@@ -49,6 +49,9 @@
                         PLANE_TYPE type,
                         tran_low_t *dqcoeff, TX_SIZE tx_size, TX_TYPE tx_type,
                         const int16_t *dq,
+#if CONFIG_NEW_QUANT
+                        dequant_val_type_nuq *dq_val,
+#endif  // CONFIG_NEW_QUANT
                         int ctx, const int16_t *scan, const int16_t *nb,
                         vp10_reader *r) {
   FRAME_COUNTS *counts = xd->counts;
@@ -66,6 +69,9 @@
   int dq_shift;
   int v, token;
   int16_t dqv = dq[0];
+#if CONFIG_NEW_QUANT
+  const tran_low_t *dqv_val = &dq_val[0][0];
+#endif  // CONFIG_NEW_QUANT
   const uint8_t *cat1_prob;
   const uint8_t *cat2_prob;
   const uint8_t *cat3_prob;
@@ -125,6 +131,10 @@
       break;
     }
 
+#if CONFIG_NEW_QUANT
+    dqv_val = &dq_val[band][0];
+#endif  // CONFIG_NEW_QUANT
+
     while (!vp10_read(r, prob[ZERO_CONTEXT_NODE])) {
       INCREMENT_COUNT(ZERO_TOKEN);
       dqv = dq[1];
@@ -135,6 +145,9 @@
       ctx = get_coef_context(nb, token_cache, c);
       band = *band_translate++;
       prob = coef_probs[band][ctx];
+#if CONFIG_NEW_QUANT
+      dqv_val = &dq_val[band][0];
+#endif  // CONFIG_NEW_QUANT
     }
 
     if (!vp10_read(r, prob[ONE_CONTEXT_NODE])) {
@@ -191,7 +204,13 @@
         }
       }
     }
+#if CONFIG_NEW_QUANT
+    v = dequant_abscoeff_nuq(val, dqv, dqv_val);
+    v = dq_shift ? ROUND_POWER_OF_TWO(v, dq_shift) : v;
+#else
     v = (val * dqv) >> dq_shift;
+#endif  // CONFIG_NEW_QUANT
+
 #if CONFIG_COEFFICIENT_RANGE_CHECKING
 #if CONFIG_VP9_HIGHBITDEPTH
     dqcoeff[scan[c]] = highbd_check_range((vp10_read_bit(r) ? -v : v),
@@ -224,6 +243,9 @@
                             tran_low_t *dqcoeff, TX_SIZE tx_size,
                             TX_TYPE tx_type,
                             const int16_t *dq,
+#if CONFIG_NEW_QUANT
+                            dequant_val_type_nuq *dq_val,
+#endif  // CONFIG_NEW_QUANT
                             int ctx, const int16_t *scan, const int16_t *nb,
                             struct AnsDecoder *const ans) {
   FRAME_COUNTS *counts = xd->counts;
@@ -245,6 +267,9 @@
   int dq_shift;
   int v, token;
   int16_t dqv = dq[0];
+#if CONFIG_NEW_QUANT
+  const tran_low_t *dqv_val = &dq_val[0][0];
+#endif  // CONFIG_NEW_QUANT
   const uint8_t *cat1_prob;
   const uint8_t *cat2_prob;
   const uint8_t *cat3_prob;
@@ -306,6 +331,10 @@
       }
     }
 
+#if CONFIG_NEW_QUANT
+    dqv_val = &dq_val[band][0];
+#endif  // CONFIG_NEW_QUANT
+
     cdf = &coef_cdfs[band][ctx];
     token = ZERO_TOKEN + rans_read(ans, *cdf);
     if (token == ZERO_TOKEN) {
@@ -359,7 +388,13 @@
 #endif
         } break;
       }
-      v = (val * dqv) >> dq_shift;
+#if CONFIG_NEW_QUANT
+    v = dequant_abscoeff_nuq(val, dqv, dqv_val);
+    v = dq_shift ? ROUND_POWER_OF_TWO(v, dq_shift) : v;
+#else
+    v = (val * dqv) >> dq_shift;
+#endif  // CONFIG_NEW_QUANT
+
 #if CONFIG_COEFFICIENT_RANGE_CHECKING
 #if CONFIG_VP9_HIGHBITDEPTH
       dqcoeff[scan[c]] =
@@ -474,11 +509,19 @@
 #if !CONFIG_ANS
   const int eob = decode_coefs(xd, pd->plane_type,
                                pd->dqcoeff, tx_size, tx_type,
-                               dequant, ctx, sc->scan, sc->neighbors, r);
+                               dequant,
+#if CONFIG_NEW_QUANT
+                               pd->seg_dequant_nuq[0],
+#endif  // CONFIG_NEW_QUANT
+                               ctx, sc->scan, sc->neighbors, r);
 #else
   const int eob = decode_coefs_ans(xd, pd->plane_type,
                                    pd->dqcoeff, tx_size, tx_type,
-                                   dequant, ctx, sc->scan, sc->neighbors, r);
+                                   dequant,
+#if CONFIG_NEW_QUANT
+                                   pd->seg_dequant_nuq[0],
+#endif  // CONFIG_NEW_QUANT
+                                   ctx, sc->scan, sc->neighbors, r);
 #endif  // !CONFIG_ANS
   dec_set_contexts(xd, pd, tx_size, eob > 0, x, y);
   return eob;
diff --git a/vp10/encoder/aq_cyclicrefresh.c b/vp10/encoder/aq_cyclicrefresh.c
index 057c057..71b0768 100644
--- a/vp10/encoder/aq_cyclicrefresh.c
+++ b/vp10/encoder/aq_cyclicrefresh.c
@@ -267,9 +267,17 @@
       // don't update the map for them. For cases where motion is non-zero or
       // the reference frame isn't the previous frame, the previous value in
       // the map for this spatial location is not entirely correct.
-      if (!is_inter_block(mbmi) || !skip)
+      if ((!is_inter_block(mbmi) || !skip) &&
+          mbmi->segment_id <= CR_SEGMENT_ID_BOOST2) {
         cr->last_coded_q_map[map_offset] = clamp(
             cm->base_qindex + cr->qindex_delta[mbmi->segment_id], 0, MAXQ);
+      } else if (is_inter_block(mbmi) && skip &&
+                 mbmi->segment_id <= CR_SEGMENT_ID_BOOST2) {
+        cr->last_coded_q_map[map_offset] =
+            VPXMIN(clamp(cm->base_qindex + cr->qindex_delta[mbmi->segment_id],
+                         0, MAXQ),
+                   cr->last_coded_q_map[map_offset]);
+      }
     }
 }
 
diff --git a/vp10/encoder/block.h b/vp10/encoder/block.h
index d4adf0d..6606e59 100644
--- a/vp10/encoder/block.h
+++ b/vp10/encoder/block.h
@@ -41,6 +41,9 @@
   int16_t *quant_shift;
   int16_t *zbin;
   int16_t *round;
+#if CONFIG_NEW_QUANT
+  cuml_bins_type_nuq *cuml_bins_nuq;
+#endif  // CONFIG_NEW_QUANT
 
   int64_t quant_thred[2];
 } MACROBLOCK_PLANE;
diff --git a/vp10/encoder/encodemb.c b/vp10/encoder/encodemb.c
index b9412cc..dfb72ea 100644
--- a/vp10/encoder/encodemb.c
+++ b/vp10/encoder/encodemb.c
@@ -107,6 +107,9 @@
   const int default_eob = 16 << (tx_size << 1);
   int mul;
   const int16_t *dequant_ptr = pd->dequant;
+#if CONFIG_NEW_QUANT
+  const dequant_val_type_nuq *dequant_val = pd->dequant_val_nuq;
+#endif  // CONFIG_NEW_QUANT
   const uint8_t *const band_translate = get_band_translate(tx_size);
   TX_TYPE tx_type = get_tx_type(type, xd, block, tx_size);
   const scan_order *const so =
@@ -121,6 +124,7 @@
   int16_t t0, t1;
   EXTRABIT e0;
   int best, band, pt, i, final_eob;
+  int shift = get_tx_scale(xd, tx_type, tx_size);
 #if CONFIG_VP9_HIGHBITDEPTH
   const int *cat6_high_cost = vp10_get_high_cost_table(xd->bd);
 #else
@@ -129,7 +133,7 @@
 
   assert((!type && !plane) || (type && plane));
   assert(eob <= default_eob);
-  mul = 1 << get_tx_scale(xd, tx_type, tx_size);
+  mul = 1 << shift;
 
   /* Now set up a Viterbi trellis to evaluate alternative roundings. */
   /* Initialize the sentinel node of the trellis. */
@@ -188,12 +192,23 @@
       rate0 = tokens[next][0].rate;
       rate1 = tokens[next][1].rate;
 
+#if CONFIG_NEW_QUANT
+      shortcut = (
+          (dequant_abscoeff_nuq(
+              abs(x), dequant_ptr[rc != 0],
+              dequant_val[band_translate[i]]) > abs(coeff[rc]) * mul) &&
+          (dequant_abscoeff_nuq(
+              abs(x) - 1, dequant_ptr[rc != 0],
+              dequant_val[band_translate[i]]) < abs(coeff[rc]) * mul));
+#else   // CONFIG_NEW_QUANT
+
       if ((abs(x) * dequant_ptr[rc != 0] > abs(coeff[rc]) * mul) &&
           (abs(x) * dequant_ptr[rc != 0] < abs(coeff[rc]) * mul +
                                                dequant_ptr[rc != 0]))
         shortcut = 1;
       else
         shortcut = 0;
+#endif   // CONFIG_NEW_QUANT
 
       if (shortcut) {
         sz = -(x < 0);
@@ -232,6 +247,16 @@
       base_bits = vp10_get_cost(t0, e0, cat6_high_cost);
 
       if (shortcut) {
+#if CONFIG_NEW_QUANT
+        dx = dequant_coeff_nuq(
+            x, dequant_ptr[rc != 0],
+            dequant_val[band_translate[i]]) - coeff[rc] * mul;
+#if CONFIG_VP9_HIGHBITDEPTH
+        if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+          dx >>= xd->bd - 8;
+        }
+#endif  // CONFIG_VP9_HIGHBITDEPTH
+#else   // CONFIG_NEW_QUANT
 #if CONFIG_VP9_HIGHBITDEPTH
         if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
           dx -= ((dequant_ptr[rc != 0] >> (xd->bd - 8)) + sz) ^ sz;
@@ -241,6 +266,7 @@
 #else
         dx -= (dequant_ptr[rc != 0] + sz) ^ sz;
 #endif  // CONFIG_VP9_HIGHBITDEPTH
+#endif  // CONFIG_NEW_QUANT
         d2 = dx * dx;
       }
       tokens[i][1].rate = base_bits + (best ? rate1 : rate0);
@@ -295,9 +321,15 @@
     if (x) {
       final_eob = i;
     }
-
     qcoeff[rc] = x;
+#if CONFIG_NEW_QUANT
+    dqcoeff[rc] = dequant_abscoeff_nuq(abs(x), dequant_ptr[rc != 0],
+                                       dequant_val[band_translate[i]]);
+    if (shift) dqcoeff[rc] = ROUND_POWER_OF_TWO(dqcoeff[rc], shift);
+    if (x < 0) dqcoeff[rc] = -dqcoeff[rc];
+#else
     dqcoeff[rc] = (x * dequant_ptr[rc != 0]) / mul;
+#endif  // CONFIG_NEW_QUANT
 
     next = tokens[i][best].next;
     best = best_index[i][best];
@@ -401,6 +433,469 @@
   }
 }
 
+#if CONFIG_NEW_QUANT
+void vp10_xform_quant_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
+                          int blk_col, BLOCK_SIZE plane_bsize,
+                          TX_SIZE tx_size) {
+  MACROBLOCKD *const xd = &x->e_mbd;
+  const struct macroblock_plane *const p = &x->plane[plane];
+  const struct macroblockd_plane *const pd = &xd->plane[plane];
+  PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
+  TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
+  const scan_order *const scan_order =
+      get_scan(tx_size, tx_type, is_inter_block(&xd->mi[0]->mbmi));
+  tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
+  tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
+  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
+  uint16_t *const eob = &p->eobs[block];
+  const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
+  const int16_t *src_diff;
+  const uint8_t* band = get_band_translate(tx_size);
+
+  FWD_TXFM_PARAM fwd_txfm_param;
+
+  fwd_txfm_param.tx_type = tx_type;
+  fwd_txfm_param.tx_size = tx_size;
+  fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[VP10_XFORM_QUANT_B];
+  fwd_txfm_param.rd_transform = x->use_lp32x32fdct;
+  fwd_txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
+
+  src_diff = &p->src_diff[4 * (blk_row * diff_stride + blk_col)];
+
+// TODO(sarahparker) add all of these new quant quantize functions
+// to quant_func_list, just trying to get this expr to work for now
+#if CONFIG_VP9_HIGHBITDEPTH
+  fwd_txfm_param.bd = xd->bd;
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    highbd_fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
+    switch (tx_size) {
+      case TX_32X32:
+        highbd_quantize_32x32_nuq(coeff, 1024, x->skip_block,
+                                  p->quant, p->quant_shift, pd->dequant,
+                                  (const cuml_bins_type_nuq *)
+                                      p->cuml_bins_nuq,
+                                  (const dequant_val_type_nuq *)
+                                      pd->dequant_val_nuq,
+                                  qcoeff, dqcoeff, eob,
+                                  scan_order->scan, band);
+        break;
+      case TX_16X16:
+        highbd_quantize_nuq(coeff, 256, x->skip_block,
+                            p->quant, p->quant_shift, pd->dequant,
+                            (const cuml_bins_type_nuq *)p->cuml_bins_nuq,
+                            (const dequant_val_type_nuq *)
+                                pd->dequant_val_nuq,
+                            qcoeff, dqcoeff, eob,
+                            scan_order->scan, band);
+        break;
+      case TX_8X8:
+        highbd_quantize_nuq(coeff, 64, x->skip_block,
+                            p->quant, p->quant_shift, pd->dequant,
+                            (const cuml_bins_type_nuq *)p->cuml_bins_nuq,
+                            (const dequant_val_type_nuq *)
+                                pd->dequant_val_nuq,
+                            qcoeff, dqcoeff, eob,
+                            scan_order->scan, band);
+        break;
+      case TX_4X4:
+        highbd_quantize_nuq(coeff, 16, x->skip_block,
+                            p->quant, p->quant_shift, pd->dequant,
+                            (const cuml_bins_type_nuq *)p->cuml_bins_nuq,
+                            (const dequant_val_type_nuq *)
+                                pd->dequant_val_nuq,
+                            qcoeff, dqcoeff, eob,
+                            scan_order->scan, band);
+        break;
+      default:
+        assert(0);
+    }
+    return;
+  }
+#endif  // CONFIG_VP9_HIGHBITDEPTH
+
+  fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
+  switch (tx_size) {
+    case TX_32X32:
+      quantize_32x32_nuq(coeff, 1024, x->skip_block,
+                         p->quant, p->quant_shift, pd->dequant,
+                         (const cuml_bins_type_nuq *)p->cuml_bins_nuq,
+                         (const dequant_val_type_nuq *)
+                         pd->dequant_val_nuq,
+                         qcoeff, dqcoeff, eob,
+                         scan_order->scan, band);
+      break;
+    case TX_16X16:
+      quantize_nuq(coeff, 256, x->skip_block,
+                   p->quant, p->quant_shift, pd->dequant,
+                   (const cuml_bins_type_nuq *)p->cuml_bins_nuq,
+                   (const dequant_val_type_nuq *)pd->dequant_val_nuq,
+                   qcoeff, dqcoeff, eob,
+                   scan_order->scan, band);
+      break;
+    case TX_8X8:
+      quantize_nuq(coeff, 64, x->skip_block,
+                   p->quant, p->quant_shift, pd->dequant,
+                   (const cuml_bins_type_nuq *)p->cuml_bins_nuq,
+                   (const dequant_val_type_nuq *)pd->dequant_val_nuq,
+                   qcoeff, dqcoeff, eob,
+                   scan_order->scan, band);
+      break;
+    case TX_4X4:
+      quantize_nuq(coeff, 16, x->skip_block,
+                   p->quant, p->quant_shift, pd->dequant,
+                   (const cuml_bins_type_nuq *)p->cuml_bins_nuq,
+                   (const dequant_val_type_nuq *)pd->dequant_val_nuq,
+                   qcoeff, dqcoeff, eob,
+                   scan_order->scan, band);
+      break;
+    default:
+      assert(0);
+      break;
+  }
+}
+
+void vp10_xform_quant_fp_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
+                             int blk_col, BLOCK_SIZE plane_bsize,
+                             TX_SIZE tx_size) {
+  MACROBLOCKD *const xd = &x->e_mbd;
+  const struct macroblock_plane *const p = &x->plane[plane];
+  const struct macroblockd_plane *const pd = &xd->plane[plane];
+  PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
+  TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
+  const scan_order *const scan_order =
+      get_scan(tx_size, tx_type, is_inter_block(&xd->mi[0]->mbmi));
+  tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
+  tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
+  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
+  uint16_t *const eob = &p->eobs[block];
+  const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
+  const int16_t *src_diff;
+  const uint8_t* band = get_band_translate(tx_size);
+
+  FWD_TXFM_PARAM fwd_txfm_param;
+
+  fwd_txfm_param.tx_type = tx_type;
+  fwd_txfm_param.tx_size = tx_size;
+  fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[VP10_XFORM_QUANT_FP];
+  fwd_txfm_param.rd_transform = x->use_lp32x32fdct;
+  fwd_txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
+
+  src_diff = &p->src_diff[4 * (blk_row * diff_stride + blk_col)];
+
+// TODO(sarahparker) add all of these new quant quantize functions
+// to quant_func_list, just trying to get this expr to work for now
+#if CONFIG_VP9_HIGHBITDEPTH
+  fwd_txfm_param.bd = xd->bd;
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    highbd_fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
+    switch (tx_size) {
+      case TX_32X32:
+        highbd_quantize_32x32_fp_nuq(coeff, 1024, x->skip_block,
+                                     p->quant_fp, pd->dequant,
+                                     (const cuml_bins_type_nuq *)
+                                         p->cuml_bins_nuq,
+                                     (const dequant_val_type_nuq *)
+                                         pd->dequant_val_nuq,
+                                     qcoeff, dqcoeff, eob,
+                                     scan_order->scan, band);
+        break;
+      case TX_16X16:
+        highbd_quantize_fp_nuq(coeff, 256, x->skip_block,
+                               p->quant_fp, pd->dequant,
+                               (const cuml_bins_type_nuq *)
+                                  p->cuml_bins_nuq,
+                               (const dequant_val_type_nuq *)
+                                   pd->dequant_val_nuq,
+                               qcoeff, dqcoeff, eob,
+                               scan_order->scan, band);
+        break;
+      case TX_8X8:
+        highbd_quantize_fp_nuq(coeff, 64, x->skip_block,
+                               p->quant_fp, pd->dequant,
+                               (const cuml_bins_type_nuq *)
+                                  p->cuml_bins_nuq,
+                               (const dequant_val_type_nuq *)
+                                   pd->dequant_val_nuq,
+                               qcoeff, dqcoeff, eob,
+                               scan_order->scan, band);
+        break;
+      case TX_4X4:
+        highbd_quantize_fp_nuq(coeff, 16, x->skip_block,
+                               p->quant_fp, pd->dequant,
+                               (const cuml_bins_type_nuq *)
+                                   p->cuml_bins_nuq,
+                               (const dequant_val_type_nuq *)
+                                   pd->dequant_val_nuq,
+                               qcoeff, dqcoeff, eob,
+                               scan_order->scan, band);
+        break;
+      default:
+        assert(0);
+    }
+    return;
+  }
+#endif  // CONFIG_VP9_HIGHBITDEPTH
+
+  fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
+  switch (tx_size) {
+    case TX_32X32:
+      quantize_32x32_fp_nuq(coeff, 1024, x->skip_block,
+                            p->quant_fp, pd->dequant,
+                            (const cuml_bins_type_nuq *)
+                                p->cuml_bins_nuq,
+                            (const dequant_val_type_nuq *)
+                                pd->dequant_val_nuq,
+                            qcoeff, dqcoeff, eob,
+                            scan_order->scan, band);
+      break;
+    case TX_16X16:
+      quantize_fp_nuq(coeff, 256, x->skip_block,
+                      p->quant_fp, pd->dequant,
+                      (const cuml_bins_type_nuq *)
+                          p->cuml_bins_nuq,
+                      (const dequant_val_type_nuq *)
+                          pd->dequant_val_nuq,
+                      qcoeff, dqcoeff, eob,
+                      scan_order->scan, band);
+      break;
+    case TX_8X8:
+      quantize_fp_nuq(coeff, 64, x->skip_block,
+                      p->quant_fp, pd->dequant,
+                      (const cuml_bins_type_nuq *)
+                          p->cuml_bins_nuq,
+                      (const dequant_val_type_nuq *)
+                          pd->dequant_val_nuq,
+                      qcoeff, dqcoeff, eob,
+                      scan_order->scan, band);
+      break;
+    case TX_4X4:
+      quantize_fp_nuq(coeff, 16, x->skip_block,
+                      p->quant_fp, pd->dequant,
+                      (const cuml_bins_type_nuq *)
+                          p->cuml_bins_nuq,
+                      (const dequant_val_type_nuq *)
+                          pd->dequant_val_nuq,
+                      qcoeff, dqcoeff, eob,
+                      scan_order->scan, band);
+      break;
+    default:
+      assert(0);
+      break;
+  }
+}
+
+void vp10_xform_quant_dc_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
+                             int blk_col, BLOCK_SIZE plane_bsize,
+                             TX_SIZE tx_size) {
+  MACROBLOCKD *const xd = &x->e_mbd;
+  const struct macroblock_plane *const p = &x->plane[plane];
+  const struct macroblockd_plane *const pd = &xd->plane[plane];
+  PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
+  TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
+  tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
+  tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
+  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
+  uint16_t *const eob = &p->eobs[block];
+  const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
+  const int16_t *src_diff;
+
+  FWD_TXFM_PARAM fwd_txfm_param;
+
+  fwd_txfm_param.tx_type = tx_type;
+  fwd_txfm_param.tx_size = tx_size;
+  fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[VP10_XFORM_QUANT_DC];
+  fwd_txfm_param.rd_transform = x->use_lp32x32fdct;
+  fwd_txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
+
+  src_diff = &p->src_diff[4 * (blk_row * diff_stride + blk_col)];
+
+// TODO(sarahparker) add all of these new quant quantize functions
+// to quant_func_list, just trying to get this expr to work for now
+#if CONFIG_VP9_HIGHBITDEPTH
+  fwd_txfm_param.bd = xd->bd;
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    highbd_fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
+    switch (tx_size) {
+      case TX_32X32:
+        highbd_quantize_dc_32x32_nuq(coeff, 1024, x->skip_block,
+                                     p->quant[0], p->quant_shift[0],
+                                     pd->dequant[0],
+                                     p->cuml_bins_nuq[0],
+                                     pd->dequant_val_nuq[0],
+                                     qcoeff, dqcoeff, eob);
+        break;
+      case TX_16X16:
+        highbd_quantize_dc_nuq(coeff, 256, x->skip_block,
+                               p->quant[0], p->quant_shift[0],
+                               pd->dequant[0],
+                               p->cuml_bins_nuq[0],
+                               pd->dequant_val_nuq[0],
+                               qcoeff, dqcoeff, eob);
+        break;
+      case TX_8X8:
+        highbd_quantize_dc_nuq(coeff, 64, x->skip_block,
+                               p->quant[0], p->quant_shift[0],
+                               pd->dequant[0],
+                               p->cuml_bins_nuq[0],
+                               pd->dequant_val_nuq[0],
+                               qcoeff, dqcoeff, eob);
+        break;
+      case TX_4X4:
+        highbd_quantize_dc_nuq(coeff, 16, x->skip_block,
+                               p->quant[0], p->quant_shift[0],
+                               pd->dequant[0],
+                               p->cuml_bins_nuq[0],
+                               pd->dequant_val_nuq[0],
+                               qcoeff, dqcoeff, eob);
+        break;
+      default:
+        assert(0);
+    }
+    return;
+  }
+#endif  // CONFIG_VP9_HIGHBITDEPTH
+
+  fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
+  switch (tx_size) {
+    case TX_32X32:
+      quantize_dc_32x32_nuq(coeff, 1024, x->skip_block,
+                            p->quant[0], p->quant_shift[0], pd->dequant[0],
+                            p->cuml_bins_nuq[0],
+                            pd->dequant_val_nuq[0],
+                            qcoeff, dqcoeff, eob);
+      break;
+    case TX_16X16:
+      quantize_dc_nuq(coeff, 256, x->skip_block,
+                      p->quant[0], p->quant_shift[0], pd->dequant[0],
+                      p->cuml_bins_nuq[0],
+                      pd->dequant_val_nuq[0],
+                      qcoeff, dqcoeff, eob);
+      break;
+    case TX_8X8:
+      quantize_dc_nuq(coeff, 64, x->skip_block,
+                      p->quant[0], p->quant_shift[0], pd->dequant[0],
+                      p->cuml_bins_nuq[0],
+                      pd->dequant_val_nuq[0],
+                      qcoeff, dqcoeff, eob);
+      break;
+    case TX_4X4:
+      quantize_dc_nuq(coeff, 16, x->skip_block,
+                      p->quant[0], p->quant_shift[0], pd->dequant[0],
+                      p->cuml_bins_nuq[0],
+                      pd->dequant_val_nuq[0],
+                      qcoeff, dqcoeff, eob);
+      break;
+    default:
+      assert(0);
+      break;
+  }
+}
+
+void vp10_xform_quant_dc_fp_nuq(MACROBLOCK *x, int plane, int block,
+                                int blk_row, int blk_col,
+                                BLOCK_SIZE plane_bsize, TX_SIZE tx_size) {
+  MACROBLOCKD *const xd = &x->e_mbd;
+  const struct macroblock_plane *const p = &x->plane[plane];
+  const struct macroblockd_plane *const pd = &xd->plane[plane];
+  PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
+  TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size);
+  tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
+  tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
+  tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
+  uint16_t *const eob = &p->eobs[block];
+  const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
+  const int16_t *src_diff;
+
+  FWD_TXFM_PARAM fwd_txfm_param;
+
+  fwd_txfm_param.tx_type = tx_type;
+  fwd_txfm_param.tx_size = tx_size;
+  fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[VP10_XFORM_QUANT_DC];
+  fwd_txfm_param.rd_transform = x->use_lp32x32fdct;
+  fwd_txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
+
+  src_diff = &p->src_diff[4 * (blk_row * diff_stride + blk_col)];
+
+// TODO(sarahparker) add all of these new quant quantize functions
+// to quant_func_list, just trying to get this expr to work for now
+#if CONFIG_VP9_HIGHBITDEPTH
+  fwd_txfm_param.bd = xd->bd;
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    highbd_fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
+    switch (tx_size) {
+      case TX_32X32:
+        highbd_quantize_dc_32x32_fp_nuq(coeff, 1024, x->skip_block,
+                                        p->quant_fp[0], pd->dequant[0],
+                                        p->cuml_bins_nuq[0],
+                                        pd->dequant_val_nuq[0],
+                                        qcoeff, dqcoeff, eob);
+        break;
+      case TX_16X16:
+        highbd_quantize_dc_fp_nuq(coeff, 256, x->skip_block,
+                                  p->quant_fp[0], pd->dequant[0],
+                                  p->cuml_bins_nuq[0],
+                                  pd->dequant_val_nuq[0],
+                                  qcoeff, dqcoeff, eob);
+        break;
+      case TX_8X8:
+        highbd_quantize_dc_fp_nuq(coeff, 64, x->skip_block,
+                                  p->quant_fp[0], pd->dequant[0],
+                                  p->cuml_bins_nuq[0],
+                                  pd->dequant_val_nuq[0],
+                                  qcoeff, dqcoeff, eob);
+        break;
+      case TX_4X4:
+        highbd_quantize_dc_fp_nuq(coeff, 16, x->skip_block,
+                                  p->quant_fp[0], pd->dequant[0],
+                                  p->cuml_bins_nuq[0],
+                                  pd->dequant_val_nuq[0],
+                                  qcoeff, dqcoeff, eob);
+        break;
+      default:
+        assert(0);
+    }
+    return;
+  }
+#endif  // CONFIG_VP9_HIGHBITDEPTH
+
+  fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
+  switch (tx_size) {
+    case TX_32X32:
+      quantize_dc_32x32_fp_nuq(coeff, 1024, x->skip_block,
+                               p->quant_fp[0], pd->dequant[0],
+                               p->cuml_bins_nuq[0],
+                               pd->dequant_val_nuq[0],
+                               qcoeff, dqcoeff, eob);
+      break;
+    case TX_16X16:
+      quantize_dc_fp_nuq(coeff, 256, x->skip_block,
+                         p->quant_fp[0], pd->dequant[0],
+                         p->cuml_bins_nuq[0],
+                         pd->dequant_val_nuq[0],
+                         qcoeff, dqcoeff, eob);
+
+      break;
+    case TX_8X8:
+      quantize_dc_fp_nuq(coeff, 64, x->skip_block,
+                         p->quant_fp[0], pd->dequant[0],
+                         p->cuml_bins_nuq[0],
+                         pd->dequant_val_nuq[0],
+                         qcoeff, dqcoeff, eob);
+      break;
+    case TX_4X4:
+      quantize_dc_fp_nuq(coeff, 16, x->skip_block,
+                         p->quant_fp[0], pd->dequant[0],
+                         p->cuml_bins_nuq[0],
+                         pd->dequant_val_nuq[0],
+                         qcoeff, dqcoeff, eob);
+      break;
+    default:
+      assert(0);
+      break;
+  }
+}
+#endif  // CONFIG_NEW_QUANT
+
 static void encode_block(int plane, int block, int blk_row, int blk_col,
                          BLOCK_SIZE plane_bsize,
                          TX_SIZE tx_size, void *arg) {
@@ -448,20 +943,35 @@
         *a = *l = 0;
         return;
       } else {
+#if CONFIG_NEW_QUANT
+        vp10_xform_quant_fp_nuq(x, plane, block, blk_row, blk_col, plane_bsize,
+                                tx_size);
+#else
         vp10_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize,
                          tx_size, VP10_XFORM_QUANT_FP);
+#endif
       }
     } else {
       if (max_txsize_lookup[plane_bsize] == tx_size) {
         int blk_index = (block >> (tx_size << 1));
         if (x->skip_txfm[plane][blk_index] == SKIP_TXFM_NONE) {
           // full forward transform and quantization
+#if CONFIG_NEW_QUANT
+          vp10_xform_quant_nuq(x, plane, block, blk_row, blk_col, plane_bsize,
+                               tx_size);
+#else
           vp10_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize,
                            tx_size, VP10_XFORM_QUANT_B);
+#endif  // CONFIG_NEW_QUANT
         } else if (x->skip_txfm[plane][blk_index] == SKIP_TXFM_AC_ONLY) {
           // fast path forward transform and quantization
+#if CONFIG_NEW_QUANT
+          vp10_xform_quant_dc_nuq(x, plane, block, blk_row, blk_col,
+                                  plane_bsize, tx_size);
+#else
           vp10_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize,
                            tx_size, VP10_XFORM_QUANT_DC);
+#endif  // CONFIG_NEW_QUANT
         } else {
           // skip forward transform
           p->eobs[block] = 0;
@@ -471,8 +981,13 @@
 #endif
         }
       } else {
+#if CONFIG_NEW_QUANT
+        vp10_xform_quant_nuq(x, plane, block, blk_row, blk_col, plane_bsize,
+                             tx_size);
+#else
         vp10_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize,
                          tx_size, VP10_XFORM_QUANT_B);
+#endif  // CONFIG_NEW_QUANT
       }
     }
   }
@@ -603,8 +1118,13 @@
   uint8_t *dst;
   dst = &pd->dst.buf[4 * blk_row * pd->dst.stride + 4 * blk_col];
 
+#if CONFIG_NEW_QUANT
+  vp10_xform_quant_nuq(x, plane, block, blk_row, blk_col, plane_bsize,
+                       tx_size);
+#else
   vp10_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize,
                    tx_size, VP10_XFORM_QUANT_B);
+#endif  // CONFIG_NEW_QUANT
 
   if (p->eobs[block] > 0) {
 #if CONFIG_VP9_HIGHBITDEPTH
@@ -733,7 +1253,6 @@
   uint16_t *eob = &p->eobs[block];
   const int src_stride = p->src.stride;
   const int dst_stride = pd->dst.stride;
-
   const int tx1d_size = get_tx1d_size(tx_size);
 
   INV_TXFM_PARAM inv_txfm_param;
@@ -758,8 +1277,13 @@
                      src_stride, dst, dst_stride);
 #endif  // CONFIG_VP9_HIGHBITDEPTH
 
+#if CONFIG_NEW_QUANT
+  vp10_xform_quant_nuq(x, plane, block, blk_row, blk_col, plane_bsize,
+                       tx_size);
+#else  // CONFIG_NEW_QUANT
   vp10_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                    VP10_XFORM_QUANT_B);
+#endif  // CONFIG_NEW_QUANT
 
   if (args->ctx != NULL) {
     struct optimize_ctx *const ctx = args->ctx;
diff --git a/vp10/encoder/encodemb.h b/vp10/encoder/encodemb.h
index cbe15aa..eae1db7 100644
--- a/vp10/encoder/encodemb.h
+++ b/vp10/encoder/encodemb.h
@@ -41,6 +41,20 @@
                       int blk_row, int blk_col,
                       BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
                       VP10_XFORM_QUANT xform_quant_idx);
+#if CONFIG_NEW_QUANT
+void vp10_xform_quant_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
+                          int blk_col, BLOCK_SIZE plane_bsize,
+                          TX_SIZE tx_size);
+void vp10_xform_quant_dc_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
+                             int blk_col, BLOCK_SIZE plane_bsize,
+                             TX_SIZE tx_size);
+void vp10_xform_quant_fp_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
+                             int blk_col, BLOCK_SIZE plane_bsize,
+                             TX_SIZE tx_size);
+void vp10_xform_quant_dc_fp_nuq(MACROBLOCK *x, int plane, int block,
+                                int blk_row, int blk_col,
+                                BLOCK_SIZE plane_bsize, TX_SIZE tx_size);
+#endif
 
 void vp10_subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
 
diff --git a/vp10/encoder/encoder.h b/vp10/encoder/encoder.h
index 7b7bd7d..4878c00 100644
--- a/vp10/encoder/encoder.h
+++ b/vp10/encoder/encoder.h
@@ -336,6 +336,12 @@
   MB_MODE_INFO_EXT *mbmi_ext_base;
   DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);   // 8: SIMD width
   DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);  // 8: SIMD width
+#if CONFIG_NEW_QUANT
+  DECLARE_ALIGNED(16, dequant_val_type_nuq,
+                  y_dequant_val_nuq[QINDEX_RANGE][COEF_BANDS]);
+  DECLARE_ALIGNED(16, dequant_val_type_nuq,
+                  uv_dequant_val_nuq[QINDEX_RANGE][COEF_BANDS]);
+#endif  // CONFIG_NEW_QUANT
   VP10_COMMON common;
   VP10EncoderConfig oxcf;
   struct lookahead_ctx    *lookahead;
diff --git a/vp10/encoder/pickrst.c b/vp10/encoder/pickrst.c
index 13f955d..4579eaa 100644
--- a/vp10/encoder/pickrst.c
+++ b/vp10/encoder/pickrst.c
@@ -76,7 +76,8 @@
   rsi.restoration_type = RESTORE_NONE;
   err = try_restoration_frame(sd, cpi, &rsi, partial_frame);
   bits = 0;
-  best_cost = RDCOST_DBL(x->rdmult, x->rddiv, (bits << 2), err);
+  best_cost = RDCOST_DBL(x->rdmult, x->rddiv,
+                         (bits << (VP9_PROB_COST_SHIFT - 6)), err);
   for (i = 0; i < restoration_levels; ++i) {
     rsi.restoration_type = RESTORE_BILATERAL;
     rsi.restoration_level = i;
@@ -85,7 +86,8 @@
     // when RDCOST is used.  However below we just scale both in the correct
     // ratios appropriately but not exactly by these values.
     bits = restoration_level_bits;
-    cost = RDCOST_DBL(x->rdmult, x->rddiv, (bits << 2), err);
+    cost = RDCOST_DBL(x->rdmult, x->rddiv,
+                      (bits << (VP9_PROB_COST_SHIFT - 6)), err);
     if (cost < best_cost) {
       restoration_best = i;
       best_cost = cost;
@@ -321,20 +323,12 @@
   return (i >= RESTORATION_HALFWIN1 ? RESTORATION_WIN - 1 - i : i);
 }
 
-static void normalize_copy(double *v, int n) {
-  double s = 0.0;
-  int i;
-  for (i = 0; i < n; ++i)
-    s += v[i];
-  s = 1.0 / s;
-  for (i = 0; i < n; ++i) v[i] *= s;
-}
-
 // Fix vector b, update vector a
 static void update_a_sep_sym(double **Mc, double **Hc, double *a, double *b) {
   int i, j;
   double S[RESTORATION_WIN];
   double A[RESTORATION_WIN], B[RESTORATION_WIN2];
+  int w, w2;
   memset(A, 0, sizeof(A));
   memset(B, 0, sizeof(B));
   for (i = 0; i < RESTORATION_WIN; i ++) {
@@ -344,7 +338,6 @@
       A[jj] += Mc[i][j] * b[i];
     }
   }
-
   for (i = 0; i < RESTORATION_WIN; i ++) {
     for (j = 0; j < RESTORATION_WIN; j ++) {
       int k, l;
@@ -358,12 +351,23 @@
         }
     }
   }
-  if (linsolve(RESTORATION_HALFWIN1, B, RESTORATION_HALFWIN1, A, S)) {
-    for (i = 0; i < RESTORATION_WIN; ++i) {
-      const int ii = wrap_index(i);
-      a[i] = S[ii];
+  // Normalization enforcement in the system of equations itself
+  w = RESTORATION_WIN;
+  w2 = (w >> 1) + 1;
+  for (i = 0; i < w2 - 1; ++i)
+    A[i] -= A[w2 - 1] * 2 + B[i * w2 + w2 - 1]
+              - 2 * B[(w2 - 1) * w2 + (w2 - 1)];
+  for (i = 0; i < w2 - 1; ++i)
+    for (j = 0; j < w2 - 1; ++j)
+      B[i * w2 + j] -= 2 * (B[i * w2 + (w2 - 1)] + B[(w2 - 1) * w2 + j] -
+                            2 * B[(w2 - 1) * w2 + (w2 - 1)]);
+  if (linsolve(w2 - 1, B, w2, A, S)) {
+    S[w2 - 1] = 1.0;
+    for (i = w2; i < w; ++i) {
+      S[i] = S[w - 1 - i];
+      S[w2 - 1] -= 2 * S[i];
     }
-    normalize_copy(a, RESTORATION_WIN);
+    memcpy(a, S, w * sizeof(*a));
   }
 }
 
@@ -372,6 +376,7 @@
   int i, j;
   double S[RESTORATION_WIN];
   double A[RESTORATION_WIN], B[RESTORATION_WIN2];
+  int w, w2;
   memset(A, 0, sizeof(A));
   memset(B, 0, sizeof(B));
   for (i = 0; i < RESTORATION_WIN; i ++) {
@@ -393,12 +398,23 @@
               a[k] * a[l];
     }
   }
-  if (linsolve(RESTORATION_HALFWIN1, B, RESTORATION_HALFWIN1, A, S)) {
-    for (i = 0; i < RESTORATION_WIN; ++i) {
-      const int ii = wrap_index(i);
-      b[i] = S[ii];
+  // Normalization enforcement in the system of equations itself
+  w = RESTORATION_WIN;
+  w2 = RESTORATION_HALFWIN1;
+  for (i = 0; i < w2 - 1; ++i)
+    A[i] -= A[w2 - 1] * 2 + B[i * w2 + w2 - 1]
+              - 2 * B[(w2 - 1) * w2 + (w2 - 1)];
+  for (i = 0; i < w2 - 1; ++i)
+    for (j = 0; j < w2 - 1; ++j)
+      B[i * w2 + j] -= 2 * (B[i * w2 + (w2 - 1)] + B[(w2 - 1) * w2 + j] -
+                            2 * B[(w2 - 1) * w2 + (w2 - 1)]);
+  if (linsolve(w2 - 1, B, w2, A, S)) {
+    S[w2 - 1] = 1.0;
+    for (i = w2; i < w; ++i) {
+      S[i] = S[w - 1 - i];
+      S[w2 - 1] -= 2 * S[i];
     }
-    normalize_copy(b, RESTORATION_WIN);
+    memcpy(b, S, w * sizeof(*b));
   }
 }
 
@@ -429,6 +445,46 @@
   return 1;
 }
 
+// Computes the function x'*A*x - x'*b for the learned filters, and compares
+// against identity filters; Final score is defined as the difference between
+// the function values
+  static double compute_score(double *M, double *H, int *vfilt, int *hfilt) {
+  double ab[RESTORATION_WIN * RESTORATION_WIN];
+  int i, k, l;
+  double P = 0, Q = 0;
+  double iP = 0, iQ = 0;
+  double Score, iScore;
+  int w;
+  double a[RESTORATION_WIN], b[RESTORATION_WIN];
+  w = RESTORATION_WIN;
+  a[RESTORATION_HALFWIN] = b[RESTORATION_HALFWIN] = 1.0;
+  for (i = 0; i < RESTORATION_HALFWIN; ++i) {
+    a[i] = a[RESTORATION_WIN - i - 1 ] =
+        (double) vfilt[i] / RESTORATION_FILT_STEP;
+    b[i] = b[RESTORATION_WIN - i - 1 ] =
+        (double) hfilt[i] / RESTORATION_FILT_STEP;
+    a[RESTORATION_HALFWIN] -= 2 * a[i];
+    b[RESTORATION_HALFWIN] -= 2 * b[i];
+  }
+  for (k = 0; k < w; ++k) {
+    for (l = 0; l < w; ++l) {
+      ab[k * w + l] = a[l] * b[k];
+    }
+  }
+  for (k = 0; k < w * w; ++k) {
+    P += ab[k] * M[k];
+    for (l = 0; l < w * w; ++l)
+      Q += ab[k] * H[k * w * w + l] * ab[l];
+  }
+  Score = Q - 2 * P;
+
+  iP = M[(w * w) >> 1];
+  iQ = H[((w * w) >> 1) * w * w + ((w * w) >> 1)];
+  iScore = iQ - 2 * iP;
+
+  return Score - iScore;
+}
+
 #define CLIP(x, lo, hi) ((x) < (lo) ? (lo) : (x) > (hi) ? (hi) : (x))
 #define RINT(x) ((x) < 0 ? (int)((x) - 0.5) : (int)((x) + 0.5))
 
@@ -463,6 +519,7 @@
   const int height = cm->height;
   const int src_stride = src->y_stride;
   const int dgd_stride = dgd->y_stride;
+  double score;
 
   assert(width == dgd->y_crop_width);
   assert(height == dgd->y_crop_height);
@@ -478,7 +535,8 @@
   rsi.restoration_type = RESTORE_NONE;
   err = try_restoration_frame(src, cpi, &rsi, partial_frame);
   bits = 0;
-  cost_norestore = RDCOST_DBL(x->rdmult, x->rddiv, (bits << 2), err);
+  cost_norestore = RDCOST_DBL(x->rdmult, x->rddiv,
+                              (bits << (VP9_PROB_COST_SHIFT - 6)), err);
 
 #if CONFIG_VP9_HIGHBITDEPTH
   if (cm->use_highbitdepth)
@@ -496,12 +554,27 @@
   quantize_sym_filter(vfilterd, vfilter);
   quantize_sym_filter(hfilterd, hfilter);
 
+  // Filter score computes the value of the function x'*A*x - x'*b for the
+  // learned filter and compares it against identity filer. If there is no
+  // reduction in the function, the filter is reverted back to identity
+  score = compute_score(M, H, vfilter, hfilter);
+  if (score > 0.0) {
+    int i;
+    for (i = 0; i < RESTORATION_HALFWIN; ++i)
+      vfilter[i] = hfilter[i] = 0;
+    rsi.restoration_type = RESTORE_NONE;
+    if (best_cost_ret) *best_cost_ret = cost_norestore;
+    vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
+    return 0;
+  }
+
   rsi.restoration_type = RESTORE_WIENER;
   memcpy(rsi.vfilter, vfilter, sizeof(rsi.vfilter));
   memcpy(rsi.hfilter, hfilter, sizeof(rsi.hfilter));
   err = try_restoration_frame(src, cpi, &rsi, partial_frame);
   bits = WIENER_FILT_BITS;
-  cost_wiener = RDCOST_DBL(x->rdmult, x->rddiv, (bits << 2), err);
+  cost_wiener = RDCOST_DBL(x->rdmult, x->rddiv,
+                           (bits << (VP9_PROB_COST_SHIFT - 6)), err);
 
   vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
 
@@ -597,7 +670,7 @@
         cm->rst_info.restoration_type = RESTORE_NONE;
     }
     // printf("[%d] Costs %g %g (%d) %g (%d)\n", cm->rst_info.restoration_type,
-    //        cost_norestore, cost_bilateral, lf->filter_level, cost_wiener,
-    //        wiener_success);
+    //         cost_norestore, cost_bilateral, lf->filter_level, cost_wiener,
+    //         wiener_success);
   }
 }
diff --git a/vp10/encoder/quantize.c b/vp10/encoder/quantize.c
index 2c61de5..2a8b33f 100644
--- a/vp10/encoder/quantize.c
+++ b/vp10/encoder/quantize.c
@@ -22,6 +22,405 @@
 #include "vp10/encoder/quantize.h"
 #include "vp10/encoder/rd.h"
 
+#if CONFIG_NEW_QUANT
+static INLINE int quantize_coeff_nuq(const tran_low_t coeffv,
+                                     const int16_t quant,
+                                     const int16_t quant_shift,
+                                     const int16_t dequant,
+                                     const tran_low_t *cuml_bins_ptr,
+                                     const tran_low_t *dequant_val,
+                                     tran_low_t *qcoeff_ptr,
+                                     tran_low_t *dqcoeff_ptr) {
+  const int coeff = coeffv;
+  const int coeff_sign = (coeff >> 31);
+  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+  int i, q;
+  int tmp = clamp(abs_coeff, INT16_MIN, INT16_MAX);
+  for (i = 0; i < NUQ_KNOTS; i++) {
+    if (tmp < cuml_bins_ptr[i]) {
+      q = i;
+      break;
+    }
+  }
+  if (i == NUQ_KNOTS) {
+    tmp -= cuml_bins_ptr[NUQ_KNOTS - 1];
+    q = NUQ_KNOTS + (((((tmp * quant) >> 16) + tmp) * quant_shift) >> 16);
+  }
+  if (q) {
+    *dqcoeff_ptr =
+        dequant_abscoeff_nuq(q, dequant, dequant_val);
+    *qcoeff_ptr  = (q ^ coeff_sign) - coeff_sign;
+    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
+  } else {
+    *qcoeff_ptr = 0;
+    *dqcoeff_ptr = 0;
+  }
+  return (q != 0);
+}
+
+static INLINE int quantize_coeff_bigtx_nuq(const tran_low_t coeffv,
+                                           const int16_t quant,
+                                           const int16_t quant_shift,
+                                           const int16_t dequant,
+                                           const tran_low_t *cuml_bins_ptr,
+                                           const tran_low_t *dequant_val,
+                                           tran_low_t *qcoeff_ptr,
+                                           tran_low_t *dqcoeff_ptr,
+                                           int logsizeby32) {
+  const int coeff = coeffv;
+  const int coeff_sign = (coeff >> 31);
+  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+  int i, q;
+  int tmp = clamp(abs_coeff, INT16_MIN, INT16_MAX);
+  for (i = 0; i < NUQ_KNOTS; i++) {
+    if (tmp < ROUND_POWER_OF_TWO(cuml_bins_ptr[i], 1 + logsizeby32)) {
+      q = i;
+      break;
+    }
+  }
+  if (i == NUQ_KNOTS) {
+    tmp -= ROUND_POWER_OF_TWO(cuml_bins_ptr[NUQ_KNOTS - 1], 1 + logsizeby32);
+    q = NUQ_KNOTS +
+        (((((tmp * quant) >> 16) + tmp) * quant_shift) >> (15 - logsizeby32));
+  }
+  if (q) {
+    *dqcoeff_ptr =
+         ROUND_POWER_OF_TWO(dequant_abscoeff_nuq(q, dequant, dequant_val),
+                            1 + logsizeby32);
+    // *dqcoeff_ptr = dequant_abscoeff_nuq(q, dequant, dequant_val) >>
+    // (1 + logsizeby32);
+    *qcoeff_ptr  = (q ^ coeff_sign) - coeff_sign;
+    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
+  } else {
+    *qcoeff_ptr = 0;
+    *dqcoeff_ptr = 0;
+  }
+  return (q != 0);
+}
+
+static INLINE int quantize_coeff_fp_nuq(const tran_low_t coeffv,
+                                        const int16_t quant,
+                                        const int16_t dequant,
+                                        const tran_low_t *cuml_bins_ptr,
+                                        const tran_low_t *dequant_val,
+                                        tran_low_t *qcoeff_ptr,
+                                        tran_low_t *dqcoeff_ptr) {
+  const int coeff = coeffv;
+  const int coeff_sign = (coeff >> 31);
+  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+  int i, q;
+  int tmp = clamp(abs_coeff, INT16_MIN, INT16_MAX);
+  for (i = 0; i < NUQ_KNOTS; i++) {
+    if (tmp < cuml_bins_ptr[i]) {
+      q = i;
+      break;
+    }
+  }
+  if (i == NUQ_KNOTS) {
+    q = NUQ_KNOTS +
+        ((((int64_t)tmp - cuml_bins_ptr[NUQ_KNOTS - 1]) * quant) >> 16);
+  }
+  if (q) {
+    *dqcoeff_ptr =
+        dequant_abscoeff_nuq(q, dequant, dequant_val);
+    *qcoeff_ptr  = (q ^ coeff_sign) - coeff_sign;
+    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
+  } else {
+    *qcoeff_ptr = 0;
+    *dqcoeff_ptr = 0;
+  }
+  return (q != 0);
+}
+
+static INLINE int quantize_coeff_bigtx_fp_nuq(const tran_low_t coeffv,
+                                              const int16_t quant,
+                                              const int16_t dequant,
+                                              const tran_low_t *cuml_bins_ptr,
+                                              const tran_low_t *dequant_val,
+                                              tran_low_t *qcoeff_ptr,
+                                              tran_low_t *dqcoeff_ptr,
+                                              int logsizeby32) {
+  const int coeff = coeffv;
+  const int coeff_sign = (coeff >> 31);
+  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+  int i, q;
+  int tmp = clamp(abs_coeff, INT16_MIN, INT16_MAX);
+  for (i = 0; i < NUQ_KNOTS; i++) {
+    if (tmp < ROUND_POWER_OF_TWO(cuml_bins_ptr[i], 1 + logsizeby32)) {
+      q = i;
+      break;
+    }
+  }
+  if (i == NUQ_KNOTS) {
+    q = NUQ_KNOTS +
+        ((((int64_t)tmp - ROUND_POWER_OF_TWO(cuml_bins_ptr[NUQ_KNOTS - 1],
+                                             1 + logsizeby32)) * quant) >>
+         (15 - logsizeby32));
+  }
+  if (q) {
+    *dqcoeff_ptr =
+        ROUND_POWER_OF_TWO(dequant_abscoeff_nuq(q, dequant, dequant_val),
+                           1 + logsizeby32);
+    // *dqcoeff_ptr = dequant_abscoeff_nuq(q, dequant, dequant_val) >>
+    // (1 + logsizeby32);
+    *qcoeff_ptr  = (q ^ coeff_sign) - coeff_sign;
+    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
+  } else {
+    *qcoeff_ptr = 0;
+    *dqcoeff_ptr = 0;
+  }
+  return (q != 0);
+}
+
+void quantize_dc_nuq(const tran_low_t *coeff_ptr,
+                     intptr_t n_coeffs,
+                     int skip_block,
+                     const int16_t quant,
+                     const int16_t quant_shift,
+                     const int16_t dequant,
+                     const tran_low_t *cuml_bins_ptr,
+                     const tran_low_t *dequant_val,
+                     tran_low_t *qcoeff_ptr,
+                     tran_low_t *dqcoeff_ptr,
+                     uint16_t *eob_ptr) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    const int rc = 0;
+    if (quantize_coeff_nuq(coeff_ptr[rc],
+                           quant,
+                           quant_shift,
+                           dequant,
+                           cuml_bins_ptr,
+                           dequant_val,
+                           qcoeff_ptr,
+                           dqcoeff_ptr))
+      eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+
+void quantize_dc_fp_nuq(const tran_low_t *coeff_ptr,
+                        intptr_t n_coeffs,
+                        int skip_block,
+                        const int16_t quant,
+                        const int16_t dequant,
+                        const tran_low_t *cuml_bins_ptr,
+                        const tran_low_t *dequant_val,
+                        tran_low_t *qcoeff_ptr,
+                        tran_low_t *dqcoeff_ptr,
+                        uint16_t *eob_ptr) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    const int rc = 0;
+    if (quantize_coeff_fp_nuq(coeff_ptr[rc],
+                              quant,
+                              dequant,
+                              cuml_bins_ptr,
+                              dequant_val,
+                              qcoeff_ptr,
+                              dqcoeff_ptr))
+      eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+
+void quantize_dc_32x32_nuq(const tran_low_t *coeff_ptr,
+                           intptr_t n_coeffs,
+                           int skip_block,
+                           const int16_t quant,
+                           const int16_t quant_shift,
+                           const int16_t dequant,
+                           const tran_low_t *cuml_bins_ptr,
+                           const tran_low_t *dequant_val,
+                           tran_low_t *qcoeff_ptr,
+                           tran_low_t *dqcoeff_ptr,
+                           uint16_t *eob_ptr) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    const int rc = 0;
+    if (quantize_coeff_bigtx_nuq(coeff_ptr[rc],
+                                 quant,
+                                 quant_shift,
+                                 dequant,
+                                 cuml_bins_ptr,
+                                 dequant_val,
+                                 qcoeff_ptr,
+                                 dqcoeff_ptr,
+                                 0))
+      eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+
+void quantize_dc_32x32_fp_nuq(const tran_low_t *coeff_ptr,
+                              intptr_t n_coeffs,
+                              int skip_block,
+                              const int16_t quant,
+                              const int16_t dequant,
+                              const tran_low_t *cuml_bins_ptr,
+                              const tran_low_t *dequant_val,
+                              tran_low_t *qcoeff_ptr,
+                              tran_low_t *dqcoeff_ptr,
+                              uint16_t *eob_ptr) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    const int rc = 0;
+    if (quantize_coeff_bigtx_fp_nuq(coeff_ptr[rc],
+                                    quant,
+                                    dequant,
+                                    cuml_bins_ptr,
+                                    dequant_val,
+                                    qcoeff_ptr,
+                                    dqcoeff_ptr,
+                                    0))
+      eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+
+void quantize_nuq_c(const tran_low_t *coeff_ptr,
+                    intptr_t n_coeffs,
+                    int skip_block,
+                    const int16_t *quant_ptr,
+                    const int16_t *quant_shift_ptr,
+                    const int16_t *dequant_ptr,
+                    const cuml_bins_type_nuq *cuml_bins_ptr,
+                    const dequant_val_type_nuq *dequant_val,
+                    tran_low_t *qcoeff_ptr,
+                    tran_low_t *dqcoeff_ptr,
+                    uint16_t *eob_ptr,
+                    const int16_t *scan,
+                    const uint8_t *band) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    int i;
+    for (i = 0; i < n_coeffs; i++) {
+      const int rc = scan[i];
+      if (quantize_coeff_nuq(coeff_ptr[rc],
+                             quant_ptr[rc != 0],
+                             quant_shift_ptr[rc != 0],
+                             dequant_ptr[rc != 0],
+                             cuml_bins_ptr[band[i]],
+                             dequant_val[band[i]],
+                             &qcoeff_ptr[rc],
+                             &dqcoeff_ptr[rc]))
+        eob = i;
+    }
+  }
+  *eob_ptr = eob + 1;
+}
+
+void quantize_fp_nuq_c(const tran_low_t *coeff_ptr,
+                       intptr_t n_coeffs,
+                       int skip_block,
+                       const int16_t *quant_ptr,
+                       const int16_t *dequant_ptr,
+                       const cuml_bins_type_nuq *cuml_bins_ptr,
+                       const dequant_val_type_nuq *dequant_val,
+                       tran_low_t *qcoeff_ptr,
+                       tran_low_t *dqcoeff_ptr,
+                       uint16_t *eob_ptr,
+                       const int16_t *scan,
+                       const uint8_t *band) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    int i;
+    for (i = 0; i < n_coeffs; i++) {
+      const int rc = scan[i];
+      if (quantize_coeff_fp_nuq(coeff_ptr[rc],
+                                quant_ptr[rc != 0],
+                                dequant_ptr[rc != 0],
+                                cuml_bins_ptr[band[i]],
+                                dequant_val[band[i]],
+                                &qcoeff_ptr[rc],
+                                &dqcoeff_ptr[rc]))
+        eob = i;
+    }
+  }
+  *eob_ptr = eob + 1;
+}
+
+void quantize_32x32_nuq_c(const tran_low_t *coeff_ptr,
+                          intptr_t n_coeffs,
+                          int skip_block,
+                          const int16_t *quant_ptr,
+                          const int16_t *quant_shift_ptr,
+                          const int16_t *dequant_ptr,
+                          const cuml_bins_type_nuq *cuml_bins_ptr,
+                          const dequant_val_type_nuq *dequant_val,
+                          tran_low_t *qcoeff_ptr,
+                          tran_low_t *dqcoeff_ptr,
+                          uint16_t *eob_ptr,
+                          const int16_t *scan,
+                          const uint8_t *band) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    int i;
+    for (i = 0; i < n_coeffs; i++) {
+      const int rc = scan[i];
+      if (quantize_coeff_bigtx_nuq(coeff_ptr[rc],
+                                   quant_ptr[rc != 0],
+                                   quant_shift_ptr[rc != 0],
+                                   dequant_ptr[rc != 0],
+                                   cuml_bins_ptr[band[i]],
+                                   dequant_val[band[i]],
+                                   &qcoeff_ptr[rc],
+                                   &dqcoeff_ptr[rc],
+                                   0))
+        eob = i;
+    }
+  }
+  *eob_ptr = eob + 1;
+}
+
+void quantize_32x32_fp_nuq_c(const tran_low_t *coeff_ptr,
+                             intptr_t n_coeffs,
+                             int skip_block,
+                             const int16_t *quant_ptr,
+                             const int16_t *dequant_ptr,
+                             const cuml_bins_type_nuq *cuml_bins_ptr,
+                             const dequant_val_type_nuq *dequant_val,
+                             tran_low_t *qcoeff_ptr,
+                             tran_low_t *dqcoeff_ptr,
+                             uint16_t *eob_ptr,
+                             const int16_t *scan,
+                             const uint8_t *band) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    int i;
+    for (i = 0; i < n_coeffs; i++) {
+      const int rc = scan[i];
+      if (quantize_coeff_bigtx_fp_nuq(coeff_ptr[rc],
+                                      quant_ptr[rc != 0],
+                                      dequant_ptr[rc != 0],
+                                      cuml_bins_ptr[band[i]],
+                                      dequant_val[band[i]],
+                                      &qcoeff_ptr[rc],
+                                      &dqcoeff_ptr[rc],
+                                      0))
+        eob = i;
+    }
+  }
+  *eob_ptr = eob + 1;
+}
+#endif  // CONFIG_NEW_QUANT
+
 void vp10_quantize_skip(intptr_t n_coeffs, tran_low_t *qcoeff_ptr,
                         tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) {
   memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
@@ -131,6 +530,403 @@
                          p->quant_fp[0], qcoeff_ptr, dqcoeff_ptr,
                          pd->dequant[0], eob_ptr, qparam->log_scale);
 }
+
+#if CONFIG_NEW_QUANT
+static INLINE int highbd_quantize_coeff_nuq(const tran_low_t coeffv,
+                                            const int16_t quant,
+                                            const int16_t quant_shift,
+                                            const int16_t dequant,
+                                            const tran_low_t *cuml_bins_ptr,
+                                            const tran_low_t *dequant_val,
+                                            tran_low_t *qcoeff_ptr,
+                                            tran_low_t *dqcoeff_ptr) {
+  const int coeff = coeffv;
+  const int coeff_sign = (coeff >> 31);
+  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+  int i, q;
+  int64_t tmp = clamp(abs_coeff, INT32_MIN, INT32_MAX);
+  for (i = 0; i < NUQ_KNOTS; i++) {
+    if (tmp < cuml_bins_ptr[i]) {
+      q = i;
+      break;
+    }
+  }
+  if (i == NUQ_KNOTS) {
+    tmp -= cuml_bins_ptr[NUQ_KNOTS - 1];
+    q = NUQ_KNOTS + (((((tmp * quant) >> 16) + tmp) * quant_shift) >> 16);
+  }
+  if (q) {
+    *dqcoeff_ptr =
+        dequant_abscoeff_nuq(q, dequant, dequant_val);
+    *qcoeff_ptr  = (q ^ coeff_sign) - coeff_sign;
+    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
+  } else {
+    *qcoeff_ptr = 0;
+    *dqcoeff_ptr = 0;
+  }
+  return (q != 0);
+}
+
+static INLINE int highbd_quantize_coeff_fp_nuq(const tran_low_t coeffv,
+                                               const int16_t quant,
+                                               const int16_t dequant,
+                                               const tran_low_t *cuml_bins_ptr,
+                                               const tran_low_t *dequant_val,
+                                               tran_low_t *qcoeff_ptr,
+                                               tran_low_t *dqcoeff_ptr) {
+  const int coeff = coeffv;
+  const int coeff_sign = (coeff >> 31);
+  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+  int i, q;
+  int64_t tmp = clamp(abs_coeff, INT32_MIN, INT32_MAX);
+  for (i = 0; i < NUQ_KNOTS; i++) {
+    if (tmp < cuml_bins_ptr[i]) {
+      q = i;
+      break;
+    }
+  }
+  if (i == NUQ_KNOTS) {
+    q = NUQ_KNOTS +
+        (((tmp - cuml_bins_ptr[NUQ_KNOTS - 1]) * quant) >> 16);
+  }
+  if (q) {
+    *dqcoeff_ptr =
+        dequant_abscoeff_nuq(q, dequant, dequant_val);
+    *qcoeff_ptr  = (q ^ coeff_sign) - coeff_sign;
+    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
+  } else {
+    *qcoeff_ptr = 0;
+    *dqcoeff_ptr = 0;
+  }
+  return (q != 0);
+}
+
+static INLINE int highbd_quantize_coeff_bigtx_fp_nuq(
+    const tran_low_t coeffv,
+    const int16_t quant,
+    const int16_t dequant,
+    const tran_low_t *cuml_bins_ptr,
+    const tran_low_t *dequant_val,
+    tran_low_t *qcoeff_ptr,
+    tran_low_t *dqcoeff_ptr,
+    int logsizeby32) {
+  const int coeff = coeffv;
+  const int coeff_sign = (coeff >> 31);
+  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+  int i, q;
+  int64_t tmp = clamp(abs_coeff, INT32_MIN, INT32_MAX);
+  for (i = 0; i < NUQ_KNOTS; i++) {
+    if (tmp < ROUND_POWER_OF_TWO(cuml_bins_ptr[i], 1 + logsizeby32)) {
+      q = i;
+      break;
+    }
+  }
+  if (i == NUQ_KNOTS) {
+    q = NUQ_KNOTS +
+        (((tmp - ROUND_POWER_OF_TWO(cuml_bins_ptr[NUQ_KNOTS - 1],
+                                    1 + logsizeby32)) * quant) >>
+         (15 - logsizeby32));
+  }
+  if (q) {
+    *dqcoeff_ptr =
+        ROUND_POWER_OF_TWO(dequant_abscoeff_nuq(q, dequant, dequant_val),
+                           1 + logsizeby32);
+    *qcoeff_ptr  = (q ^ coeff_sign) - coeff_sign;
+    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
+  } else {
+    *qcoeff_ptr = 0;
+    *dqcoeff_ptr = 0;
+  }
+  return (q != 0);
+}
+
+static INLINE int highbd_quantize_coeff_bigtx_nuq(const tran_low_t coeffv,
+                                                  const int16_t quant,
+                                                  const int16_t quant_shift,
+                                                  const int16_t dequant,
+                                                  const tran_low_t
+                                                        *cuml_bins_ptr,
+                                                  const tran_low_t *dequant_val,
+                                                  tran_low_t *qcoeff_ptr,
+                                                  tran_low_t *dqcoeff_ptr,
+                                                  int logsizeby32) {
+  const int coeff = coeffv;
+  const int coeff_sign = (coeff >> 31);
+  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+  int i, q;
+  int64_t tmp = clamp(abs_coeff, INT32_MIN, INT32_MAX);
+  for (i = 0; i < NUQ_KNOTS; i++) {
+    if (tmp < ROUND_POWER_OF_TWO(cuml_bins_ptr[i], 1 + logsizeby32)) {
+      q = i;
+      break;
+    }
+  }
+  if (i == NUQ_KNOTS) {
+    tmp -= ROUND_POWER_OF_TWO(cuml_bins_ptr[NUQ_KNOTS - 1], 1 + logsizeby32);
+    q = NUQ_KNOTS +
+        (((((tmp * quant) >> 16) + tmp) * quant_shift) >> (15 - logsizeby32));
+  }
+  if (q) {
+    *dqcoeff_ptr =
+        ROUND_POWER_OF_TWO(dequant_abscoeff_nuq(q, dequant, dequant_val),
+                           1 + logsizeby32);
+    *qcoeff_ptr  = (q ^ coeff_sign) - coeff_sign;
+    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
+  } else {
+    *qcoeff_ptr = 0;
+    *dqcoeff_ptr = 0;
+  }
+  return (q != 0);
+}
+
+void highbd_quantize_dc_nuq(const tran_low_t *coeff_ptr,
+                            intptr_t n_coeffs,
+                            int skip_block,
+                            const int16_t quant,
+                            const int16_t quant_shift,
+                            const int16_t dequant,
+                            const tran_low_t *cuml_bins_ptr,
+                            const tran_low_t *dequant_val,
+                            tran_low_t *qcoeff_ptr,
+                            tran_low_t *dqcoeff_ptr,
+                            uint16_t *eob_ptr) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    const int rc = 0;
+    if (highbd_quantize_coeff_nuq(coeff_ptr[rc],
+                                  quant,
+                                  quant_shift,
+                                  dequant,
+                                  cuml_bins_ptr,
+                                  dequant_val,
+                                  qcoeff_ptr,
+                                  dqcoeff_ptr))
+      eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+
+void highbd_quantize_dc_fp_nuq(const tran_low_t *coeff_ptr,
+                               intptr_t n_coeffs,
+                               int skip_block,
+                               const int16_t quant,
+                               const int16_t dequant,
+                               const tran_low_t *cuml_bins_ptr,
+                               const tran_low_t *dequant_val,
+                               tran_low_t *qcoeff_ptr,
+                               tran_low_t *dqcoeff_ptr,
+                               uint16_t *eob_ptr) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    const int rc = 0;
+    if (highbd_quantize_coeff_fp_nuq(coeff_ptr[rc],
+                                     quant,
+                                     dequant,
+                                     cuml_bins_ptr,
+                                     dequant_val,
+                                     qcoeff_ptr,
+                                     dqcoeff_ptr))
+      eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+
+void highbd_quantize_nuq_c(const tran_low_t *coeff_ptr,
+                           intptr_t n_coeffs,
+                           int skip_block,
+                           const int16_t *quant_ptr,
+                           const int16_t *quant_shift_ptr,
+                           const int16_t *dequant_ptr,
+                           const cuml_bins_type_nuq *cuml_bins_ptr,
+                           const dequant_val_type_nuq *dequant_val,
+                           tran_low_t *qcoeff_ptr,
+                           tran_low_t *dqcoeff_ptr,
+                           uint16_t *eob_ptr,
+                           const int16_t *scan,
+                           const uint8_t *band) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    int i;
+    for (i = 0; i < n_coeffs; i++) {
+      const int rc = scan[i];
+      if (highbd_quantize_coeff_nuq(coeff_ptr[rc],
+                                    quant_ptr[rc != 0],
+                                    quant_shift_ptr[rc != 0],
+                                    dequant_ptr[rc != 0],
+                                    cuml_bins_ptr[band[i]],
+                                    dequant_val[band[i]],
+                                    &qcoeff_ptr[rc],
+                                    &dqcoeff_ptr[rc]))
+        eob = i;
+    }
+  }
+  *eob_ptr = eob + 1;
+}
+
+void highbd_quantize_32x32_nuq_c(const tran_low_t *coeff_ptr,
+                                 intptr_t n_coeffs,
+                                 int skip_block,
+                                 const int16_t *quant_ptr,
+                                 const int16_t *quant_shift_ptr,
+                                 const int16_t *dequant_ptr,
+                                 const cuml_bins_type_nuq *cuml_bins_ptr,
+                                 const dequant_val_type_nuq *dequant_val,
+                                 tran_low_t *qcoeff_ptr,
+                                 tran_low_t *dqcoeff_ptr,
+                                 uint16_t *eob_ptr,
+                                 const int16_t *scan,
+                                 const uint8_t *band) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    int i;
+    for (i = 0; i < n_coeffs; i++) {
+      const int rc = scan[i];
+      if (highbd_quantize_coeff_bigtx_nuq(coeff_ptr[rc],
+                                          quant_ptr[rc != 0],
+                                          quant_shift_ptr[rc != 0],
+                                          dequant_ptr[rc != 0],
+                                          cuml_bins_ptr[band[i]],
+                                          dequant_val[band[i]],
+                                          &qcoeff_ptr[rc],
+                                          &dqcoeff_ptr[rc],
+                                          0))
+        eob = i;
+    }
+  }
+  *eob_ptr = eob + 1;
+}
+
+void highbd_quantize_32x32_fp_nuq_c(const tran_low_t *coeff_ptr,
+                                    intptr_t n_coeffs,
+                                    int skip_block,
+                                    const int16_t *quant_ptr,
+                                    const int16_t *dequant_ptr,
+                                    const cuml_bins_type_nuq *cuml_bins_ptr,
+                                    const dequant_val_type_nuq *dequant_val,
+                                    tran_low_t *qcoeff_ptr,
+                                    tran_low_t *dqcoeff_ptr,
+                                    uint16_t *eob_ptr,
+                                    const int16_t *scan,
+                                    const uint8_t *band) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    int i;
+    for (i = 0; i < n_coeffs; i++) {
+      const int rc = scan[i];
+      if (highbd_quantize_coeff_bigtx_fp_nuq(coeff_ptr[rc],
+                                             quant_ptr[rc != 0],
+                                             dequant_ptr[rc != 0],
+                                             cuml_bins_ptr[band[i]],
+                                             dequant_val[band[i]],
+                                             &qcoeff_ptr[rc],
+                                             &dqcoeff_ptr[rc],
+                                             0))
+        eob = i;
+    }
+  }
+  *eob_ptr = eob + 1;
+}
+
+void highbd_quantize_fp_nuq_c(const tran_low_t *coeff_ptr,
+                              intptr_t n_coeffs,
+                              int skip_block,
+                              const int16_t *quant_ptr,
+                              const int16_t *dequant_ptr,
+                              const cuml_bins_type_nuq *cuml_bins_ptr,
+                              const dequant_val_type_nuq *dequant_val,
+                              tran_low_t *qcoeff_ptr,
+                              tran_low_t *dqcoeff_ptr,
+                              uint16_t *eob_ptr,
+                              const int16_t *scan,
+                              const uint8_t *band) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    int i;
+    for (i = 0; i < n_coeffs; i++) {
+      const int rc = scan[i];
+      if (highbd_quantize_coeff_fp_nuq(coeff_ptr[rc],
+                                       quant_ptr[rc != 0],
+                                       dequant_ptr[rc != 0],
+                                       cuml_bins_ptr[band[i]],
+                                       dequant_val[band[i]],
+                                       &qcoeff_ptr[rc],
+                                       &dqcoeff_ptr[rc]))
+        eob = i;
+    }
+  }
+  *eob_ptr = eob + 1;
+}
+
+void highbd_quantize_dc_32x32_nuq(const tran_low_t *coeff_ptr,
+                                  intptr_t n_coeffs,
+                                  int skip_block,
+                                  const int16_t quant,
+                                  const int16_t quant_shift,
+                                  const int16_t dequant,
+                                  const tran_low_t *cuml_bins_ptr,
+                                  const tran_low_t *dequant_val,
+                                  tran_low_t *qcoeff_ptr,
+                                  tran_low_t *dqcoeff_ptr,
+                                  uint16_t *eob_ptr) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    const int rc = 0;
+    if (highbd_quantize_coeff_bigtx_nuq(coeff_ptr[rc],
+                                        quant,
+                                        quant_shift,
+                                        dequant,
+                                        cuml_bins_ptr,
+                                        dequant_val,
+                                        qcoeff_ptr,
+                                        dqcoeff_ptr,
+                                        0))
+      eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+
+void highbd_quantize_dc_32x32_fp_nuq(const tran_low_t *coeff_ptr,
+                                     intptr_t n_coeffs,
+                                     int skip_block,
+                                     const int16_t quant,
+                                     const int16_t dequant,
+                                     const tran_low_t *cuml_bins_ptr,
+                                     const tran_low_t *dequant_val,
+                                     tran_low_t *qcoeff_ptr,
+                                     tran_low_t *dqcoeff_ptr,
+                                     uint16_t *eob_ptr) {
+  int eob = -1;
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+  if (!skip_block) {
+    const int rc = 0;
+    if (highbd_quantize_coeff_bigtx_fp_nuq(coeff_ptr[rc],
+                                           quant,
+                                           dequant,
+                                           cuml_bins_ptr,
+                                           dequant_val,
+                                           qcoeff_ptr,
+                                           dqcoeff_ptr,
+                                           0))
+      eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+#endif  // CONFIG_NEW_QUANT
 #endif  // CONFIG_VP9_HIGHBITDEPTH
 
 void vp10_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
@@ -186,7 +982,7 @@
                               const int16_t *dequant_ptr,
                               uint16_t *eob_ptr,
                               const int16_t *scan,
-                              const int16_t *iscan, int log_scale) {
+                              const int16_t *iscan, const int log_scale) {
   int i;
   int eob = -1;
   const int scale = 1 << log_scale;
@@ -219,7 +1015,8 @@
   }
   *eob_ptr = eob + 1;
 }
-#endif
+
+#endif  // CONFIG_VP9_HIGHBITDEPTH
 
 // TODO(jingning) Refactor this file and combine functions with similar
 // operations.
@@ -272,7 +1069,7 @@
                               tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                               const int16_t *dequant_ptr,
                               uint16_t *eob_ptr, const int16_t *scan,
-                              const int16_t *iscan, int log_scale) {
+                              const int16_t *iscan, const int log_scale) {
   int i, non_zero_count = (int)n_coeffs, eob = -1;
   int zbins[2] = {zbin_ptr[0], zbin_ptr[1]};
   int round[2] = {round_ptr[0], round_ptr[1]};
@@ -452,6 +1249,20 @@
       cpi->uv_dequant[q][i] = quant;
     }
 
+#if CONFIG_NEW_QUANT
+    // TODO(sarahparker) do this for multiple profiles once they are added
+    for (i = 0; i < COEF_BANDS; i++) {
+      const int quant = cpi->y_dequant[q][i != 0];
+      const int uvquant = cpi->uv_dequant[q][i != 0];
+      get_dequant_val_nuq(quant, q == 0, i,
+                          cpi->y_dequant_val_nuq[q][i],
+                          quants->y_cuml_bins_nuq[q][i]);
+      get_dequant_val_nuq(uvquant, q == 0, i,
+                          cpi->uv_dequant_val_nuq[q][i],
+                          quants->uv_cuml_bins_nuq[q][i]);
+    }
+#endif  // CONFIG_NEW_QUANT
+
     for (i = 2; i < 8; i++) {  // 8: SIMD width
       quants->y_quant[q][i] = quants->y_quant[q][1];
       quants->y_quant_fp[q][i] = quants->y_quant_fp[q][1];
@@ -489,6 +1300,12 @@
   x->plane[0].zbin = quants->y_zbin[qindex];
   x->plane[0].round = quants->y_round[qindex];
   xd->plane[0].dequant = cpi->y_dequant[qindex];
+#if CONFIG_NEW_QUANT
+  x->plane[0].cuml_bins_nuq = quants->y_cuml_bins_nuq[qindex];
+  xd->plane[0].dequant_val_nuq = (const dequant_val_type_nuq*)
+                                 cpi->y_dequant_val_nuq[qindex];
+#endif  // CONFIG_NEW_QUANT
+
 
   x->plane[0].quant_thred[0] = x->plane[0].zbin[0] * x->plane[0].zbin[0];
   x->plane[0].quant_thred[1] = x->plane[0].zbin[1] * x->plane[0].zbin[1];
@@ -502,6 +1319,11 @@
     x->plane[i].zbin = quants->uv_zbin[qindex];
     x->plane[i].round = quants->uv_round[qindex];
     xd->plane[i].dequant = cpi->uv_dequant[qindex];
+#if CONFIG_NEW_QUANT
+    x->plane[i].cuml_bins_nuq = quants->uv_cuml_bins_nuq[qindex];
+    xd->plane[i].dequant_val_nuq = (const dequant_val_type_nuq*)
+                                   cpi->uv_dequant_val_nuq[qindex];
+#endif  // CONFIG_NEW_QUANT
 
     x->plane[i].quant_thred[0] = x->plane[i].zbin[0] * x->plane[i].zbin[0];
     x->plane[i].quant_thred[1] = x->plane[i].zbin[1] * x->plane[i].zbin[1];
diff --git a/vp10/encoder/quantize.h b/vp10/encoder/quantize.h
index 5e62eb2..dd10528 100644
--- a/vp10/encoder/quantize.h
+++ b/vp10/encoder/quantize.h
@@ -32,6 +32,14 @@
                                   const QUANT_PARAM *qparam);
 
 typedef struct {
+#if CONFIG_NEW_QUANT
+  DECLARE_ALIGNED(16, tran_low_t,
+                  y_cuml_bins_nuq[QINDEX_RANGE][COEF_BANDS]
+                               [NUQ_KNOTS]);
+  DECLARE_ALIGNED(16, tran_low_t,
+                  uv_cuml_bins_nuq[QINDEX_RANGE][COEF_BANDS]
+                                [NUQ_KNOTS]);
+#endif  // CONFIG_NEW_QUANT
   // 0: dc 1: ac 2-8: ac repeated to SIMD width
   DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE][8]);
   DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE][8]);
@@ -88,6 +96,52 @@
                              const MACROBLOCKD_PLANE *pd,
                              tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                              const scan_order *sc, const QUANT_PARAM *qparam);
+
+#if CONFIG_NEW_QUANT
+void quantize_dc_nuq(const tran_low_t *coeff_ptr,
+                     intptr_t n_coeffs,
+                     int skip_block,
+                     const int16_t quant,
+                     const int16_t quant_shift,
+                     const int16_t dequant,
+                     const tran_low_t *cuml_bins_ptr,
+                     const tran_low_t *dequant_val,
+                     tran_low_t *qcoeff_ptr,
+                     tran_low_t *dqcoeff_ptr,
+                     uint16_t *eob_ptr);
+void quantize_dc_32x32_nuq(const tran_low_t *coeff_ptr,
+                           intptr_t n_coeffs,
+                           int skip_block,
+                           const int16_t quant,
+                           const int16_t quant_shift,
+                           const int16_t dequant,
+                           const tran_low_t *cuml_bins_ptr,
+                           const tran_low_t *dequant_val,
+                           tran_low_t *qcoeff_ptr,
+                           tran_low_t *dqcoeff_ptr,
+                           uint16_t *eob_ptr);
+void quantize_dc_fp_nuq(const tran_low_t *coeff_ptr,
+                        intptr_t n_coeffs,
+                        int skip_block,
+                        const int16_t quant,
+                        const int16_t dequant,
+                        const tran_low_t *cuml_bins_ptr,
+                        const tran_low_t *dequant_val,
+                        tran_low_t *qcoeff_ptr,
+                        tran_low_t *dqcoeff_ptr,
+                        uint16_t *eob_ptr);
+void quantize_dc_32x32_fp_nuq(const tran_low_t *coeff_ptr,
+                              intptr_t n_coeffs,
+                              int skip_block,
+                              const int16_t quant,
+                              const int16_t dequant,
+                              const tran_low_t *cuml_bins_ptr,
+                              const tran_low_t *dequant_val,
+                              tran_low_t *qcoeff_ptr,
+                              tran_low_t *dqcoeff_ptr,
+                              uint16_t *eob_ptr);
+#endif  // CONFIG_NEW_QUANT
+
 #if CONFIG_VP9_HIGHBITDEPTH
 void vp10_highbd_quantize_fp_facade(
     const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
@@ -115,6 +169,51 @@
                             tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                             const int16_t dequant_ptr, uint16_t *eob_ptr,
                             const int log_scale);
+#if CONFIG_NEW_QUANT
+void highbd_quantize_dc_nuq(const tran_low_t *coeff_ptr,
+                            intptr_t n_coeffs,
+                            int skip_block,
+                            const int16_t quant,
+                            const int16_t quant_shift,
+                            const int16_t dequant,
+                            const tran_low_t *cuml_bins_ptr,
+                            const tran_low_t *dequant_val,
+                            tran_low_t *qcoeff_ptr,
+                            tran_low_t *dqcoeff_ptr,
+                            uint16_t *eob_ptr);
+void highbd_quantize_dc_32x32_nuq(const tran_low_t *coeff_ptr,
+                                  intptr_t n_coeffs,
+                                  int skip_block,
+                                  const int16_t quant,
+                                  const int16_t quant_shift,
+                                  const int16_t dequant,
+                                  const tran_low_t *cuml_bins_ptr,
+                                  const tran_low_t *dequant_val,
+                                  tran_low_t *qcoeff_ptr,
+                                  tran_low_t *dqcoeff_ptr,
+                                  uint16_t *eob_ptr);
+void highbd_quantize_dc_fp_nuq(const tran_low_t *coeff_ptr,
+                               intptr_t n_coeffs,
+                               int skip_block,
+                               const int16_t quant,
+                               const int16_t dequant,
+                               const tran_low_t *cuml_bins_ptr,
+                               const tran_low_t *dequant_val,
+                               tran_low_t *qcoeff_ptr,
+                               tran_low_t *dqcoeff_ptr,
+                               uint16_t *eob_ptr);
+void highbd_quantize_dc_32x32_fp_nuq(const tran_low_t *coeff_ptr,
+                                     intptr_t n_coeffs,
+                                     int skip_block,
+                                     const int16_t quant,
+                                     const int16_t dequant,
+                                     const tran_low_t *cuml_bins_ptr,
+                                     const tran_low_t *dequant_val,
+                                     tran_low_t *qcoeff_ptr,
+                                     tran_low_t *dqcoeff_ptr,
+                                     uint16_t *eob_ptr);
+
+#endif  // CONFIG_NEW_QUANT
 #endif  // CONFIG_VP9_HIGHBITDEPTH
 
 #ifdef __cplusplus
diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c
index a1b4fb7..640a409 100644
--- a/vp10/encoder/rdopt.c
+++ b/vp10/encoder/rdopt.c
@@ -1259,8 +1259,13 @@
     if (x->skip_txfm[plane][block >> (tx_size << 1)] ==
         SKIP_TXFM_NONE) {
       // full forward transform and quantization
+#if CONFIG_NEW_QUANT
+      vp10_xform_quant_nuq(x, plane, block, blk_row, blk_col,
+                           plane_bsize, tx_size);
+#else
       vp10_xform_quant(x, plane, block, blk_row, blk_col,
                        plane_bsize, tx_size, VP10_XFORM_QUANT_B);
+#endif  // CONFIG_NEW_QUANT
       dist_block(args->cpi, x, plane, block, blk_row, blk_col,
                  tx_size, &dist, &sse);
     } else if (x->skip_txfm[plane][block >> (tx_size << 1)] ==
@@ -1268,8 +1273,17 @@
       // compute DC coefficient
       tran_low_t *const coeff   = BLOCK_OFFSET(x->plane[plane].coeff, block);
       tran_low_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block);
+#if CONFIG_NEW_QUANT
+      if (x->quant_fp)
+        vp10_xform_quant_dc_fp_nuq(x, plane, block, blk_row, blk_col,
+                                   plane_bsize, tx_size);
+      else
+        vp10_xform_quant_dc_nuq(x, plane, block, blk_row, blk_col,
+                                plane_bsize, tx_size);
+#else
       vp10_xform_quant(x, plane, block, blk_row, blk_col,
                           plane_bsize, tx_size, VP10_XFORM_QUANT_DC);
+#endif  // CONFIG_NEW_QUANT
       sse  = x->bsse[plane][block >> (tx_size << 1)] << 4;
       dist = sse;
       if (x->plane[plane].eobs[block]) {
@@ -1295,8 +1309,17 @@
     }
   } else {
     // full forward transform and quantization
+#if CONFIG_NEW_QUANT
+    if (x->quant_fp)
+      vp10_xform_quant_fp_nuq(x, plane, block, blk_row, blk_col, plane_bsize,
+                              tx_size);
+    else
+      vp10_xform_quant_nuq(x, plane, block, blk_row, blk_col, plane_bsize,
+                           tx_size);
+#else
     vp10_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                      VP10_XFORM_QUANT_B);
+#endif  // CONFIG_NEW_QUANT
     dist_block(args->cpi, x, plane, block, blk_row, blk_col,
                tx_size, &dist, &sse);
   }
@@ -6535,8 +6558,8 @@
 static int estimate_wedge_sign(const VP10_COMP *cpi,
                                const MACROBLOCK *x,
                                const BLOCK_SIZE bsize,
-                               const uint8_t *pred0, int stride0,
-                               const uint8_t *pred1, int stride1) {
+                               uint8_t *pred0, int stride0,
+                               uint8_t *pred1, int stride1) {
   const struct macroblock_plane *const p = &x->plane[0];
   const uint8_t *src = p->src.buf;
   int src_stride = p->src.stride;
@@ -6702,195 +6725,6 @@
 }
 #endif
 
-#if CONFIG_EXT_INTER
-// Choose the best wedge index and sign
-static int64_t pick_wedge(const VP10_COMP *const cpi,
-                          const MACROBLOCK *const x,
-                          const BLOCK_SIZE bsize,
-                          const uint8_t *const p0,
-                          const uint8_t *const p1,
-                          int *const best_wedge_sign,
-                          int *const best_wedge_index) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const src = &x->plane[0].src;
-  const int bw = 4 * num_4x4_blocks_wide_lookup[bsize];
-  const int bh = 4 * num_4x4_blocks_high_lookup[bsize];
-  const int N = bw * bh;
-  int rate;
-  int64_t dist;
-  int64_t rd, best_rd = INT64_MAX;
-  int wedge_index;
-  int wedge_sign;
-  int wedge_types = (1 << get_wedge_bits_lookup(bsize));
-  const uint8_t *mask;
-  uint64_t sse;
-#if CONFIG_VP9_HIGHBITDEPTH
-  const int hbd = xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH;
-  const int bd_round = hbd ? (xd->bd - 8) * 2 : 0;
-#else
-  const int bd_round = 0;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  int16_t r0[MAX_SB_SQUARE];
-  int16_t r1[MAX_SB_SQUARE];
-  int16_t d10[MAX_SB_SQUARE];
-  int16_t ds[MAX_SB_SQUARE];
-
-  int64_t sign_limit;
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (hbd) {
-    vpx_highbd_subtract_block(bh, bw, r0, bw, src->buf, src->stride,
-                              CONVERT_TO_BYTEPTR(p0), bw, xd->bd);
-    vpx_highbd_subtract_block(bh, bw, r1, bw, src->buf, src->stride,
-                              CONVERT_TO_BYTEPTR(p1), bw, xd->bd);
-    vpx_highbd_subtract_block(bh, bw, d10, bw,
-                              CONVERT_TO_BYTEPTR(p1), bw,
-                              CONVERT_TO_BYTEPTR(p0), bw, xd->bd);
-  } else  // NOLINT
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  {
-    vpx_subtract_block(bh, bw, r0, bw, src->buf, src->stride, p0, bw);
-    vpx_subtract_block(bh, bw, r1, bw, src->buf, src->stride, p1, bw);
-    vpx_subtract_block(bh, bw, d10, bw, p1, bw, p0, bw);
-  }
-
-  sign_limit = ((int64_t)vpx_sum_squares_i16(r0, N)
-                - (int64_t)vpx_sum_squares_i16(r1, N))
-               * (1 << WEDGE_WEIGHT_BITS) / 2;
-
-  vp10_wedge_compute_delta_squares(ds, r0, r1, N);
-
-  for (wedge_index = 0; wedge_index < wedge_types; ++wedge_index) {
-    mask = vp10_get_soft_mask(wedge_index, 0, bsize, 0, 0);
-    wedge_sign = vp10_wedge_sign_from_residuals(ds, mask, N, sign_limit);
-
-    mask = vp10_get_soft_mask(wedge_index, wedge_sign, bsize, 0, 0);
-    sse = vp10_wedge_sse_from_residuals(r1, d10, mask, N);
-    sse = ROUNDZ_POWER_OF_TWO(sse, bd_round);
-
-    model_rd_from_sse(cpi, xd, bsize, 0, sse, &rate, &dist);
-    rd =  RDCOST(x->rdmult, x->rddiv, rate, dist);
-
-    if (rd < best_rd) {
-      *best_wedge_index = wedge_index;
-      *best_wedge_sign = wedge_sign;
-      best_rd = rd;
-    }
-  }
-
-  return best_rd;
-}
-
-// Choose the best wedge index the specified sign
-static int64_t pick_wedge_fixed_sign(const VP10_COMP *const cpi,
-                                     const MACROBLOCK *const x,
-                                     const BLOCK_SIZE bsize,
-                                     const uint8_t *const p0,
-                                     const uint8_t *const p1,
-                                     const int wedge_sign,
-                                     int *const best_wedge_index) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  const struct buf_2d *const src = &x->plane[0].src;
-  const int bw = 4 * num_4x4_blocks_wide_lookup[bsize];
-  const int bh = 4 * num_4x4_blocks_high_lookup[bsize];
-  const int N = bw * bh;
-  int rate;
-  int64_t dist;
-  int64_t rd, best_rd = INT64_MAX;
-  int wedge_index;
-  int wedge_types = (1 << get_wedge_bits_lookup(bsize));
-  const uint8_t *mask;
-  uint64_t sse;
-#if CONFIG_VP9_HIGHBITDEPTH
-  const int hbd = xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH;
-  const int bd_round = hbd ? (xd->bd - 8) * 2 : 0;
-#else
-  const int bd_round = 0;
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-
-  int16_t r1[MAX_SB_SQUARE];
-  int16_t d10[MAX_SB_SQUARE];
-
-#if CONFIG_VP9_HIGHBITDEPTH
-  if (hbd) {
-    vpx_highbd_subtract_block(bh, bw, r1, bw, src->buf, src->stride,
-                              CONVERT_TO_BYTEPTR(p1), bw, xd->bd);
-    vpx_highbd_subtract_block(bh, bw, d10, bw,
-                              CONVERT_TO_BYTEPTR(p1), bw,
-                              CONVERT_TO_BYTEPTR(p0), bw, xd->bd);
-  } else  // NOLINT
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  {
-    vpx_subtract_block(bh, bw, r1, bw, src->buf, src->stride, p1, bw);
-    vpx_subtract_block(bh, bw, d10, bw, p1, bw, p0, bw);
-  }
-
-  for (wedge_index = 0; wedge_index < wedge_types; ++wedge_index) {
-    mask = vp10_get_soft_mask(wedge_index, wedge_sign, bsize, 0, 0);
-    sse = vp10_wedge_sse_from_residuals(r1, d10, mask, N);
-    sse = ROUNDZ_POWER_OF_TWO(sse, bd_round);
-
-    model_rd_from_sse(cpi, xd, bsize, 0, sse, &rate, &dist);
-    rd =  RDCOST(x->rdmult, x->rddiv, rate, dist);
-
-    if (rd < best_rd) {
-      *best_wedge_index = wedge_index;
-      best_rd = rd;
-    }
-  }
-
-  return best_rd;
-}
-
-static int64_t pick_interinter_wedge(const VP10_COMP *const cpi,
-                                     const MACROBLOCK *const x,
-                                     const BLOCK_SIZE bsize,
-                                     const uint8_t *const p0,
-                                     const uint8_t *const p1) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
-  const int bw = 4 * num_4x4_blocks_wide_lookup[bsize];
-
-  int64_t rd;
-  int wedge_index = -1;
-  int wedge_sign = 0;
-
-  assert(is_interinter_wedge_used(bsize));
-
-  if (cpi->sf.fast_wedge_sign_estimate) {
-    wedge_sign = estimate_wedge_sign(cpi, x, bsize, p0, bw, p1, bw);
-    rd = pick_wedge_fixed_sign(cpi, x, bsize, p0, p1, wedge_sign, &wedge_index);
-  } else {
-    rd = pick_wedge(cpi, x, bsize, p0, p1, &wedge_sign, &wedge_index);
-  }
-
-  mbmi->interinter_wedge_sign = wedge_sign;
-  mbmi->interinter_wedge_index = wedge_index;
-  return rd;
-}
-
-static int64_t pick_interintra_wedge(const VP10_COMP *const cpi,
-                                     const MACROBLOCK *const x,
-                                     const BLOCK_SIZE bsize,
-                                     const uint8_t *const p0,
-                                     const uint8_t *const p1) {
-  const MACROBLOCKD *const xd = &x->e_mbd;
-  MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
-
-  int64_t rd;
-  int wedge_index = -1;
-
-  assert(is_interintra_wedge_used(bsize));
-
-  rd = pick_wedge_fixed_sign(cpi, x, bsize, p0, p1, 0, &wedge_index);
-
-  mbmi->interintra_wedge_sign = 0;
-  mbmi->interintra_wedge_index = wedge_index;
-  return rd;
-}
-#endif  // CONFIG_EXT_INTER
-
 static int64_t handle_inter_mode(VP10_COMP *cpi, MACROBLOCK *x,
                                  BLOCK_SIZE bsize,
                                  int *rate2, int64_t *distortion,
@@ -6930,7 +6764,6 @@
   int_mv cur_mv[2];
   int rate_mv = 0;
 #if CONFIG_EXT_INTER
-  const int bw = 4 * num_4x4_blocks_wide_lookup[bsize];
   int mv_idx = (this_mode == NEWFROMNEARMV) ? 1 : 0;
   int_mv single_newmv[MAX_REF_FRAMES];
   const unsigned int *const interintra_mode_cost =
@@ -6941,11 +6774,11 @@
 #endif
 #endif  // CONFIG_EXT_INTER
 #if CONFIG_VP9_HIGHBITDEPTH
-  DECLARE_ALIGNED(16, uint8_t, tmp_buf_[2 * MAX_MB_PLANE * MAX_SB_SQUARE]);
-#else
-  DECLARE_ALIGNED(16, uint8_t, tmp_buf_[MAX_MB_PLANE * MAX_SB_SQUARE]);
-#endif  // CONFIG_VP9_HIGHBITDEPTH
+  DECLARE_ALIGNED(16, uint16_t, tmp_buf16[MAX_MB_PLANE * MAX_SB_SQUARE]);
   uint8_t *tmp_buf;
+#else
+  DECLARE_ALIGNED(16, uint8_t, tmp_buf[MAX_MB_PLANE * MAX_SB_SQUARE]);
+#endif  // CONFIG_VP9_HIGHBITDEPTH
 
 #if CONFIG_OBMC
   int allow_obmc =
@@ -7019,11 +6852,12 @@
 #endif
 
 #if CONFIG_VP9_HIGHBITDEPTH
-  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
-    tmp_buf = CONVERT_TO_BYTEPTR(tmp_buf_);
-  else
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    tmp_buf = CONVERT_TO_BYTEPTR(tmp_buf16);
+  } else {
+    tmp_buf = (uint8_t *)tmp_buf16;
+  }
 #endif  // CONFIG_VP9_HIGHBITDEPTH
-    tmp_buf = tmp_buf_;
 
   if (is_comp_pred) {
     if (frame_mv[refs[0]].as_int == INVALID_MV ||
@@ -7436,10 +7270,13 @@
 #endif  // CONFIG_OBMC
 
   if (is_comp_pred && is_interinter_wedge_used(bsize)) {
+    int wedge_index, best_wedge_index = WEDGE_NONE;
+    int wedge_sign, best_wedge_sign = 0;
     int rate_sum, rs;
     int64_t dist_sum;
     int64_t best_rd_nowedge = INT64_MAX;
     int64_t best_rd_wedge = INT64_MAX;
+    int wedge_types;
     int tmp_skip_txfm_sb;
     int64_t tmp_skip_sse_sb;
 
@@ -7457,15 +7294,21 @@
     // Disbale wedge search if source variance is small
     if (x->source_variance > cpi->sf.disable_wedge_search_var_thresh &&
         best_rd_nowedge / 3 < ref_best_rd) {
-      uint8_t pred0[2 * MAX_SB_SQUARE];
-      uint8_t pred1[2 * MAX_SB_SQUARE];
-      uint8_t *preds0[1] = {pred0};
-      uint8_t *preds1[1] = {pred1};
-      int strides[1] = {bw};
+      uint8_t pred0[2 * MAX_SB_SQUARE * 3];
+      uint8_t pred1[2 * MAX_SB_SQUARE * 3];
+      uint8_t *preds0[3] = {pred0,
+        pred0 + 2 * MAX_SB_SQUARE,
+        pred0 + 4 * MAX_SB_SQUARE};
+      uint8_t *preds1[3] = {pred1,
+        pred1 + 2 * MAX_SB_SQUARE,
+        pred1 + 4 * MAX_SB_SQUARE};
+      int strides[3] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+      int est_wedge_sign;
 
       mbmi->use_wedge_interinter = 1;
       rs = vp10_cost_literal(get_interinter_wedge_bits(bsize)) +
           vp10_cost_bit(cm->fc->wedge_interinter_prob[bsize], 1);
+      wedge_types = (1 << get_wedge_bits_lookup(bsize));
 
       vp10_build_inter_predictors_for_planes_single_buf(
           xd, bsize, 0, 0,  mi_row, mi_col, 0, preds0, strides);
@@ -7473,8 +7316,49 @@
           xd, bsize, 0, 0, mi_row, mi_col, 1, preds1, strides);
 
       // Choose the best wedge
-      best_rd_wedge = pick_interinter_wedge(cpi, x, bsize, pred0, pred1);
-      best_rd_wedge += RDCOST(x->rdmult, x->rddiv, rs + rate_mv, 0);
+      if (cpi->sf.fast_wedge_sign_estimate) {
+        est_wedge_sign = estimate_wedge_sign(
+            cpi, x, bsize, pred0, MAX_SB_SIZE, pred1, MAX_SB_SIZE);
+        best_wedge_sign = mbmi->interinter_wedge_sign = est_wedge_sign;
+        for (wedge_index = 0; wedge_index < wedge_types; ++wedge_index) {
+          mbmi->interinter_wedge_index = wedge_index;
+          vp10_build_wedge_inter_predictor_from_buf(xd, bsize,
+                                                    0, 0, mi_row, mi_col,
+                                                    preds0, strides,
+                                                    preds1, strides);
+          model_rd_for_sb(cpi, bsize, x, xd, 0, 0,
+                          &rate_sum, &dist_sum,
+                          &tmp_skip_txfm_sb, &tmp_skip_sse_sb);
+          rd = RDCOST(x->rdmult, x->rddiv, rs + rate_mv + rate_sum, dist_sum);
+          if (rd < best_rd_wedge) {
+            best_wedge_index = wedge_index;
+            best_rd_wedge = rd;
+          }
+        }
+      } else {
+        for (wedge_index = 0; wedge_index < wedge_types; ++wedge_index) {
+          for (wedge_sign = 0; wedge_sign < 2; ++wedge_sign) {
+            mbmi->interinter_wedge_index = wedge_index;
+            mbmi->interinter_wedge_sign = wedge_sign;
+            vp10_build_wedge_inter_predictor_from_buf(xd, bsize,
+                                                      0, 0, mi_row, mi_col,
+                                                      preds0, strides,
+                                                      preds1, strides);
+            model_rd_for_sb(cpi, bsize, x, xd, 0, 0,
+                            &rate_sum, &dist_sum,
+                            &tmp_skip_txfm_sb, &tmp_skip_sse_sb);
+            rd = RDCOST(x->rdmult, x->rddiv,
+                        rs + rate_mv + rate_sum, dist_sum);
+            if (rd < best_rd_wedge) {
+              best_wedge_index = wedge_index;
+              best_wedge_sign = wedge_sign;
+              best_rd_wedge = rd;
+            }
+          }
+        }
+      }
+      mbmi->interinter_wedge_index = best_wedge_index;
+      mbmi->interinter_wedge_sign = best_wedge_sign;
 
       if (have_newmv_in_inter_mode(this_mode)) {
         int_mv tmp_mv[2];
@@ -7519,6 +7403,7 @@
           mbmi->mv[1].as_int = cur_mv[1].as_int;
           tmp_rate_mv = rate_mv;
           vp10_build_wedge_inter_predictor_from_buf(xd, bsize, 0, 0,
+                                                    mi_row, mi_col,
                                                     preds0, strides,
                                                     preds1, strides);
         }
@@ -7533,6 +7418,8 @@
 
         if (best_rd_wedge < best_rd_nowedge) {
           mbmi->use_wedge_interinter = 1;
+          mbmi->interinter_wedge_index = best_wedge_index;
+          mbmi->interinter_wedge_sign = best_wedge_sign;
           xd->mi[0]->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int;
           xd->mi[0]->bmi[0].as_mv[1].as_int = mbmi->mv[1].as_int;
           *rate2 += tmp_rate_mv - rate_mv;
@@ -7546,7 +7433,7 @@
         }
       } else {
         vp10_build_wedge_inter_predictor_from_buf(xd, bsize,
-                                                  0, 0,
+                                                  0, 0, mi_row, mi_col,
                                                   preds0, strides,
                                                   preds1, strides);
         vp10_subtract_plane(x, bsize, 0);
@@ -7558,6 +7445,8 @@
           best_rd_wedge = rd;
         if (best_rd_wedge < best_rd_nowedge) {
           mbmi->use_wedge_interinter = 1;
+          mbmi->interinter_wedge_index = best_wedge_index;
+          mbmi->interinter_wedge_sign = best_wedge_sign;
         } else {
           mbmi->use_wedge_interinter = 0;
         }
@@ -7580,11 +7469,13 @@
   }
 
   if (is_comp_interintra_pred) {
+    const int bw = 4 * num_4x4_blocks_wide_lookup[bsize];
     INTERINTRA_MODE best_interintra_mode = II_DC_PRED;
     int64_t best_interintra_rd = INT64_MAX;
     int rmode, rate_sum;
     int64_t dist_sum;
     int j;
+    int wedge_types, wedge_index, best_wedge_index = -1;
     int64_t best_interintra_rd_nowedge = INT64_MAX;
     int64_t best_interintra_rd_wedge = INT64_MAX;
     int rwedge;
@@ -7592,7 +7483,8 @@
     int tmp_rate_mv = 0;
     int tmp_skip_txfm_sb;
     int64_t tmp_skip_sse_sb;
-    DECLARE_ALIGNED(16, uint8_t, intrapred_[2 * MAX_SB_SQUARE]);
+    DECLARE_ALIGNED(16, uint8_t,
+                    intrapred_[2 * MAX_MB_PLANE * MAX_SB_SQUARE]);
     uint8_t *intrapred;
 
 #if CONFIG_VP9_HIGHBITDEPTH
@@ -7605,7 +7497,7 @@
     mbmi->ref_frame[1] = NONE;
     for (j = 0; j < MAX_MB_PLANE; j++) {
       xd->plane[j].dst.buf = tmp_buf + j * MAX_SB_SQUARE;
-      xd->plane[j].dst.stride = bw;
+      xd->plane[j].dst.stride = MAX_SB_SIZE;
     }
     vp10_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
     restore_dst_buf(xd, orig_dst, orig_dst_stride);
@@ -7616,9 +7508,9 @@
       mbmi->interintra_mode = (INTERINTRA_MODE)j;
       rmode = interintra_mode_cost[mbmi->interintra_mode];
       vp10_build_intra_predictors_for_interintra(
-          xd, bsize, 0, intrapred, bw);
-      vp10_combine_interintra(xd, bsize, 0, tmp_buf, bw,
-                              intrapred, bw);
+          xd, bsize, 0, intrapred, MAX_SB_SIZE);
+      vp10_combine_interintra(xd, bsize, 0, tmp_buf, MAX_SB_SIZE,
+                              intrapred, MAX_SB_SIZE);
       model_rd_for_sb(cpi, bsize, x, xd, 0, 0, &rate_sum, &dist_sum,
                       &tmp_skip_txfm_sb, &tmp_skip_sse_sb);
       rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate_mv + rate_sum, dist_sum);
@@ -7630,9 +7522,9 @@
     mbmi->interintra_mode = best_interintra_mode;
     rmode = interintra_mode_cost[mbmi->interintra_mode];
     vp10_build_intra_predictors_for_interintra(
-        xd, bsize, 0, intrapred, bw);
-    vp10_combine_interintra(xd, bsize, 0, tmp_buf, bw,
-                            intrapred, bw);
+        xd, bsize, 0, intrapred, MAX_SB_SIZE);
+    vp10_combine_interintra(xd, bsize, 0, tmp_buf, MAX_SB_SIZE,
+                            intrapred, MAX_SB_SIZE);
     vp10_subtract_plane(x, bsize, 0);
     rd = estimate_yrd_for_sb(cpi, bsize, x, &rate_sum, &dist_sum,
                              &tmp_skip_txfm_sb, &tmp_skip_sse_sb,
@@ -7655,20 +7547,32 @@
       // Disbale wedge search if source variance is small
       if (x->source_variance > cpi->sf.disable_wedge_search_var_thresh) {
         mbmi->use_wedge_interintra = 1;
-
+        wedge_types = (1 << get_wedge_bits_lookup(bsize));
         rwedge = vp10_cost_literal(get_interintra_wedge_bits(bsize)) +
             vp10_cost_bit(cm->fc->wedge_interintra_prob[bsize], 1);
-
-        best_interintra_rd_wedge = pick_interintra_wedge(cpi, x, bsize,
-                                                         intrapred_, tmp_buf_);
-
-        best_interintra_rd_wedge += RDCOST(x->rdmult, x->rddiv,
-                                           rmode + rate_mv + rwedge, 0);
+        for (wedge_index = 0; wedge_index < wedge_types; ++wedge_index) {
+          mbmi->interintra_wedge_index = wedge_index;
+          mbmi->interintra_wedge_sign = 0;
+          vp10_combine_interintra(xd, bsize, 0,
+                                  tmp_buf, MAX_SB_SIZE,
+                                  intrapred, MAX_SB_SIZE);
+          model_rd_for_sb(cpi, bsize, x, xd, 0, 0,
+                          &rate_sum, &dist_sum,
+                          &tmp_skip_txfm_sb, &tmp_skip_sse_sb);
+          rd = RDCOST(x->rdmult, x->rddiv,
+                      rmode + rate_mv + rwedge + rate_sum, dist_sum);
+          if (rd < best_interintra_rd_wedge) {
+            best_interintra_rd_wedge = rd;
+            best_wedge_index = wedge_index;
+          }
+        }
         // Refine motion vector.
-        if (have_newmv_in_inter_mode(this_mode)) {
+        if (have_newmv_in_inter_mode(this_mode) && best_wedge_index > -1) {
           // get negative of mask
           const uint8_t* mask = vp10_get_soft_mask(
-              mbmi->interintra_wedge_index, 1, bsize, 0, 0);
+              best_wedge_index, 1, bsize, 0, 0);
+          mbmi->interintra_wedge_index = best_wedge_index;
+          mbmi->interintra_wedge_sign = 0;
           do_masked_motion_search(cpi, x, mask, bw, bsize,
                                   mi_row, mi_col, &tmp_mv, &tmp_rate_mv,
                                   0, mv_idx);
@@ -7685,11 +7589,13 @@
             tmp_rate_mv = rate_mv;
           }
         } else {
+          mbmi->interintra_wedge_index = best_wedge_index;
+          mbmi->interintra_wedge_sign = 0;
           tmp_mv.as_int = cur_mv[0].as_int;
           tmp_rate_mv = rate_mv;
           vp10_combine_interintra(xd, bsize, 0,
-                                  tmp_buf, bw,
-                                  intrapred, bw);
+                                  tmp_buf, MAX_SB_SIZE,
+                                  intrapred, MAX_SB_SIZE);
         }
         // Evaluate closer to true rd
         vp10_subtract_plane(x, bsize, 0);
@@ -7702,6 +7608,8 @@
         best_interintra_rd_wedge = rd;
         if (best_interintra_rd_wedge < best_interintra_rd_nowedge) {
           mbmi->use_wedge_interintra = 1;
+          mbmi->interintra_wedge_index = best_wedge_index;
+          mbmi->interintra_wedge_sign = 0;
           best_interintra_rd = best_interintra_rd_wedge;
           mbmi->mv[0].as_int = tmp_mv.as_int;
           *rate2 += tmp_rate_mv - rate_mv;
diff --git a/vp10/encoder/speed_features.c b/vp10/encoder/speed_features.c
index 3f411b7..bd0cb81 100644
--- a/vp10/encoder/speed_features.c
+++ b/vp10/encoder/speed_features.c
@@ -239,7 +239,6 @@
 static void set_rt_speed_feature_framesize_dependent(VP10_COMP *cpi,
     SPEED_FEATURES *sf, int speed) {
   VP10_COMMON *const cm = &cpi->common;
-
   if (speed >= 1) {
     if (VPXMIN(cm->width, cm->height) >= 720) {
       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
@@ -309,6 +308,7 @@
     sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
   }
 
+
   if (speed >= 2) {
     sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
                                  FLAG_SKIP_INTRA_DIRMISMATCH |
diff --git a/vp10/encoder/wedge_utils.c b/vp10/encoder/wedge_utils.c
deleted file mode 100644
index d97008d..0000000
--- a/vp10/encoder/wedge_utils.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- *  Copyright (c) 2016 The WebM project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include <assert.h>
-
-#include "vpx/vpx_integer.h"
-
-#include "vpx_ports/mem.h"
-
-#include "vpx_dsp/vpx_dsp_common.h"
-
-#include "vp10/common/reconinter.h"
-
-#define MAX_MASK_VALUE  (1 << WEDGE_WEIGHT_BITS)
-
-/**
- * Computes SSE of a compound predictor constructed from 2 fundamental
- * predictors p0 and p1 using blending with mask.
- *
- * r1:  Residuals of p1.
- *      (source - p1)
- * d:   Difference of p1 and p0.
- *      (p1 - p0)
- * m:   The blending mask
- * N:   Number of pixels
- *
- * 'r1', 'd', and 'm' are contiguous.
- *
- * Computes:
- *  Sum((MAX_MASK_VALUE*r1 + mask*d)**2), which is equivalent to:
- *  Sum((mask*r0 + (MAX_MASK_VALUE-mask)*r1)**2),
- *    where r0 is (source - p0), and r1 is (source - p1), which is in turn
- *    is equivalent to:
- *  Sum((source*MAX_MASK_VALUE - (mask*p0 + (MAX_MASK_VALUE-mask)*p1))**2),
- *    which is the SSE of the residuals of the compound predictor scaled up by
- *    MAX_MASK_VALUE**2.
- *
- * Note that we clamp the partial term in the loop to 16 bits signed. This is
- * to facilitate equivalent SIMD implementation. It should have no effect if
- * residuals are within 16 - WEDGE_WEIGHT_BITS (=10) signed, which always
- * holds for 8 bit input, and on real input, it should hold practically always,
- * as residuals are expected to be small.
- */
-uint64_t vp10_wedge_sse_from_residuals_c(const int16_t *r1,
-                                         const int16_t *d,
-                                         const uint8_t *m,
-                                         int N) {
-  uint64_t csse = 0;
-  int i;
-  assert(N % 64 == 0);
-  for (i = 0 ; i < N ; i++) {
-    int32_t t = MAX_MASK_VALUE*r1[i] + m[i]*d[i];
-    t = clamp(t, INT16_MIN, INT16_MAX);
-    csse += t*t;
-  }
-  return ROUND_POWER_OF_TWO(csse, 2 * WEDGE_WEIGHT_BITS);
-}
-
-/**
- * Choose the mask sign for a compound predictor.
- *
- * ds:    Difference of the squares of the residuals.
- *        r0**2 - r1**2
- * m:     The blending mask
- * N:     Number of pixels
- * limit: Pre-computed threshold value.
- *        MAX_MASK_VALUE/2 * (sum(r0**2) - sum(r1**2))
- *
- * 'ds' and 'm' are contiguous.
- *
- * Returns true if the negated mask has lower SSE compared to the positive
- * mask. Computation is based on:
- *  Sum((mask*r0 + (MAX_MASK_VALUE-mask)*r1)**2)
- *                                     >
- *                                Sum(((MAX_MASK_VALUE-mask)*r0 + mask*r1)**2)
- *
- *  which can be simplified to:
- *
- *  Sum(mask*(r0**2 - r1**2)) > MAX_MASK_VALUE/2 * (sum(r0**2) - sum(r1**2))
- *
- *  The right hand side does not depend on the mask, and needs to be passed as
- *  the 'limit' parameter.
- *
- *  After pre-computing (r0**2 - r1**2), which is passed in as 'ds', the left
- *  hand side is simply a scalar product between an int16_t and uint8_t vector.
- *
- *  Note that for efficiency, ds is stored on 16 bits. Real input residuals
- *  being small, this should not cause a noticeable issue.
- */
-int vp10_wedge_sign_from_residuals_c(const int16_t *ds,
-                                     const uint8_t *m,
-                                     int N,
-                                     int64_t limit) {
-  int64_t acc = 0;
-
-  assert(N % 64 == 0);
-
-  do {
-    acc += *ds++ * *m++;
-  } while (--N);
-
-  return acc > limit;
-}
-
-/**
- * Compute the element-wise difference of the squares of 2 arrays.
- *
- * d: Difference of the squares of the inputs: a**2 - b**2
- * a: First input array
- * b: Second input array
- * N: Number of elements
- *
- * 'd', 'a', and 'b' are contiguous.
- *
- * The result is saturated to signed 16 bits.
- */
-void vp10_wedge_compute_delta_squares_c(int16_t *d,
-                                        const int16_t *a,
-                                        const int16_t *b,
-                                        int N) {
-  int i;
-
-  assert(N % 64 == 0);
-
-  for (i = 0 ; i < N ; i++)
-    d[i] = clamp(a[i]*a[i] - b[i]*b[i], INT16_MIN, INT16_MAX);
-}
-
diff --git a/vp10/encoder/x86/wedge_utils_sse2.c b/vp10/encoder/x86/wedge_utils_sse2.c
deleted file mode 100644
index b881d58..0000000
--- a/vp10/encoder/x86/wedge_utils_sse2.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- *  Copyright (c) 2016 The WebM project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include <assert.h>
-#include <immintrin.h>
-
-#include "vpx_dsp/x86/synonyms.h"
-
-#include "vpx/vpx_integer.h"
-
-#include "vp10/common/reconinter.h"
-
-#define MAX_MASK_VALUE  (1 << WEDGE_WEIGHT_BITS)
-
-/**
- * See vp10_wedge_sse_from_residuals_c
- */
-uint64_t vp10_wedge_sse_from_residuals_sse2(const int16_t *r1,
-                                            const int16_t *d,
-                                            const uint8_t *m,
-                                            int N) {
-  int n = -N;
-  int n8 = n + 8;
-
-  uint64_t csse;
-
-  const __m128i v_mask_max_w = _mm_set1_epi16(MAX_MASK_VALUE);
-  const __m128i v_zext_q = _mm_set_epi32(0, 0xffffffff, 0, 0xffffffff);
-
-  __m128i v_acc0_q = _mm_setzero_si128();
-
-  assert(N % 64 == 0);
-
-  r1 += N;
-  d += N;
-  m += N;
-
-  do {
-    const __m128i v_r0_w = xx_load_128(r1 + n);
-    const __m128i v_r1_w = xx_load_128(r1 + n8);
-    const __m128i v_d0_w = xx_load_128(d + n);
-    const __m128i v_d1_w = xx_load_128(d + n8);
-    const __m128i v_m01_b = xx_load_128(m + n);
-
-    const __m128i v_rd0l_w = _mm_unpacklo_epi16(v_d0_w, v_r0_w);
-    const __m128i v_rd0h_w = _mm_unpackhi_epi16(v_d0_w, v_r0_w);
-    const __m128i v_rd1l_w = _mm_unpacklo_epi16(v_d1_w, v_r1_w);
-    const __m128i v_rd1h_w = _mm_unpackhi_epi16(v_d1_w, v_r1_w);
-    const __m128i v_m0_w = _mm_unpacklo_epi8(v_m01_b, _mm_setzero_si128());
-    const __m128i v_m1_w = _mm_unpackhi_epi8(v_m01_b, _mm_setzero_si128());
-
-    const __m128i v_m0l_w = _mm_unpacklo_epi16(v_m0_w, v_mask_max_w);
-    const __m128i v_m0h_w = _mm_unpackhi_epi16(v_m0_w, v_mask_max_w);
-    const __m128i v_m1l_w = _mm_unpacklo_epi16(v_m1_w, v_mask_max_w);
-    const __m128i v_m1h_w = _mm_unpackhi_epi16(v_m1_w, v_mask_max_w);
-
-    const __m128i v_t0l_d = _mm_madd_epi16(v_rd0l_w, v_m0l_w);
-    const __m128i v_t0h_d = _mm_madd_epi16(v_rd0h_w, v_m0h_w);
-    const __m128i v_t1l_d = _mm_madd_epi16(v_rd1l_w, v_m1l_w);
-    const __m128i v_t1h_d = _mm_madd_epi16(v_rd1h_w, v_m1h_w);
-
-    const __m128i v_t0_w = _mm_packs_epi32(v_t0l_d, v_t0h_d);
-    const __m128i v_t1_w = _mm_packs_epi32(v_t1l_d, v_t1h_d);
-
-    const __m128i v_sq0_d = _mm_madd_epi16(v_t0_w, v_t0_w);
-    const __m128i v_sq1_d = _mm_madd_epi16(v_t1_w, v_t1_w);
-
-    const __m128i v_sum0_q = _mm_add_epi64(_mm_and_si128(v_sq0_d, v_zext_q),
-                                           _mm_srli_epi64(v_sq0_d, 32));
-    const __m128i v_sum1_q = _mm_add_epi64(_mm_and_si128(v_sq1_d, v_zext_q),
-                                           _mm_srli_epi64(v_sq1_d, 32));
-
-    v_acc0_q = _mm_add_epi64(v_acc0_q, v_sum0_q);
-    v_acc0_q = _mm_add_epi64(v_acc0_q, v_sum1_q);
-
-    n8 += 16;
-    n += 16;
-  } while (n);
-
-  v_acc0_q = _mm_add_epi64(v_acc0_q, _mm_srli_si128(v_acc0_q, 8));
-
-#if ARCH_X86_64
-  csse = (uint64_t)_mm_cvtsi128_si64(v_acc0_q);
-#else
-  xx_storel_64(&csse, v_acc0_q);
-#endif
-
-  return ROUND_POWER_OF_TWO(csse, 2 * WEDGE_WEIGHT_BITS);
-}
-
-/**
- * See vp10_wedge_sign_from_residuals_c
- */
-int vp10_wedge_sign_from_residuals_sse2(const int16_t *ds,
-                                        const uint8_t *m,
-                                        int N,
-                                        int64_t limit) {
-  int64_t acc;
-
-  __m128i v_sign_d;
-  __m128i v_acc0_d = _mm_setzero_si128();
-  __m128i v_acc1_d = _mm_setzero_si128();
-  __m128i v_acc_q;
-
-  // Input size limited to 8192 by the use of 32 bit accumulators and m
-  // being between [0, 64]. Overflow might happen at larger sizes,
-  // though it is practically impossible on real video input.
-  assert(N < 8192);
-  assert(N % 64 == 0);
-
-  do {
-    const __m128i v_m01_b = xx_load_128(m);
-    const __m128i v_m23_b = xx_load_128(m + 16);
-    const __m128i v_m45_b = xx_load_128(m + 32);
-    const __m128i v_m67_b = xx_load_128(m + 48);
-
-    const __m128i v_d0_w = xx_load_128(ds);
-    const __m128i v_d1_w = xx_load_128(ds + 8);
-    const __m128i v_d2_w = xx_load_128(ds + 16);
-    const __m128i v_d3_w = xx_load_128(ds + 24);
-    const __m128i v_d4_w = xx_load_128(ds + 32);
-    const __m128i v_d5_w = xx_load_128(ds + 40);
-    const __m128i v_d6_w = xx_load_128(ds + 48);
-    const __m128i v_d7_w = xx_load_128(ds + 56);
-
-    const __m128i v_m0_w = _mm_unpacklo_epi8(v_m01_b, _mm_setzero_si128());
-    const __m128i v_m1_w = _mm_unpackhi_epi8(v_m01_b, _mm_setzero_si128());
-    const __m128i v_m2_w = _mm_unpacklo_epi8(v_m23_b, _mm_setzero_si128());
-    const __m128i v_m3_w = _mm_unpackhi_epi8(v_m23_b, _mm_setzero_si128());
-    const __m128i v_m4_w = _mm_unpacklo_epi8(v_m45_b, _mm_setzero_si128());
-    const __m128i v_m5_w = _mm_unpackhi_epi8(v_m45_b, _mm_setzero_si128());
-    const __m128i v_m6_w = _mm_unpacklo_epi8(v_m67_b, _mm_setzero_si128());
-    const __m128i v_m7_w = _mm_unpackhi_epi8(v_m67_b, _mm_setzero_si128());
-
-    const __m128i v_p0_d = _mm_madd_epi16(v_d0_w, v_m0_w);
-    const __m128i v_p1_d = _mm_madd_epi16(v_d1_w, v_m1_w);
-    const __m128i v_p2_d = _mm_madd_epi16(v_d2_w, v_m2_w);
-    const __m128i v_p3_d = _mm_madd_epi16(v_d3_w, v_m3_w);
-    const __m128i v_p4_d = _mm_madd_epi16(v_d4_w, v_m4_w);
-    const __m128i v_p5_d = _mm_madd_epi16(v_d5_w, v_m5_w);
-    const __m128i v_p6_d = _mm_madd_epi16(v_d6_w, v_m6_w);
-    const __m128i v_p7_d = _mm_madd_epi16(v_d7_w, v_m7_w);
-
-    const __m128i v_p01_d = _mm_add_epi32(v_p0_d, v_p1_d);
-    const __m128i v_p23_d = _mm_add_epi32(v_p2_d, v_p3_d);
-    const __m128i v_p45_d = _mm_add_epi32(v_p4_d, v_p5_d);
-    const __m128i v_p67_d = _mm_add_epi32(v_p6_d, v_p7_d);
-
-    const __m128i v_p0123_d = _mm_add_epi32(v_p01_d, v_p23_d);
-    const __m128i v_p4567_d = _mm_add_epi32(v_p45_d, v_p67_d);
-
-    v_acc0_d = _mm_add_epi32(v_acc0_d, v_p0123_d);
-    v_acc1_d = _mm_add_epi32(v_acc1_d, v_p4567_d);
-
-    ds += 64;
-    m += 64;
-
-    N -= 64;
-  } while (N);
-
-  v_sign_d = _mm_cmplt_epi32(v_acc0_d, _mm_setzero_si128());
-  v_acc0_d = _mm_add_epi64(_mm_unpacklo_epi32(v_acc0_d, v_sign_d),
-                          _mm_unpackhi_epi32(v_acc0_d, v_sign_d));
-
-  v_sign_d = _mm_cmplt_epi32(v_acc1_d, _mm_setzero_si128());
-  v_acc1_d = _mm_add_epi64(_mm_unpacklo_epi32(v_acc1_d, v_sign_d),
-                          _mm_unpackhi_epi32(v_acc1_d, v_sign_d));
-
-  v_acc_q = _mm_add_epi64(v_acc0_d, v_acc1_d);
-
-  v_acc_q = _mm_add_epi64(v_acc_q, _mm_srli_si128(v_acc_q, 8));
-
-#if ARCH_X86_64
-  acc = (uint64_t)_mm_cvtsi128_si64(v_acc_q);
-#else
-  xx_storel_64(&acc, v_acc_q);
-#endif
-
-  return acc > limit;
-}
-
-// Negate under mask
-static INLINE __m128i negm_epi16(__m128i v_v_w, __m128i v_mask_w) {
-  return _mm_sub_epi16(_mm_xor_si128(v_v_w, v_mask_w), v_mask_w);
-}
-
-/**
- * vp10_wedge_compute_delta_squares_c
- */
-void vp10_wedge_compute_delta_squares_sse2(int16_t *d,
-                                          const int16_t *a,
-                                          const int16_t *b,
-                                          int N) {
-  const __m128i v_neg_w = _mm_set_epi16(0xffff, 0, 0xffff, 0,
-                                        0xffff, 0, 0xffff, 0);
-
-  assert(N % 64 == 0);
-
-  do {
-    const __m128i v_a0_w = xx_load_128(a);
-    const __m128i v_b0_w = xx_load_128(b);
-    const __m128i v_a1_w = xx_load_128(a + 8);
-    const __m128i v_b1_w = xx_load_128(b + 8);
-    const __m128i v_a2_w = xx_load_128(a + 16);
-    const __m128i v_b2_w = xx_load_128(b + 16);
-    const __m128i v_a3_w = xx_load_128(a + 24);
-    const __m128i v_b3_w = xx_load_128(b + 24);
-
-    const __m128i v_ab0l_w = _mm_unpacklo_epi16(v_a0_w, v_b0_w);
-    const __m128i v_ab0h_w = _mm_unpackhi_epi16(v_a0_w, v_b0_w);
-    const __m128i v_ab1l_w = _mm_unpacklo_epi16(v_a1_w, v_b1_w);
-    const __m128i v_ab1h_w = _mm_unpackhi_epi16(v_a1_w, v_b1_w);
-    const __m128i v_ab2l_w = _mm_unpacklo_epi16(v_a2_w, v_b2_w);
-    const __m128i v_ab2h_w = _mm_unpackhi_epi16(v_a2_w, v_b2_w);
-    const __m128i v_ab3l_w = _mm_unpacklo_epi16(v_a3_w, v_b3_w);
-    const __m128i v_ab3h_w = _mm_unpackhi_epi16(v_a3_w, v_b3_w);
-
-    // Negate top word of pairs
-    const __m128i v_abl0n_w = negm_epi16(v_ab0l_w, v_neg_w);
-    const __m128i v_abh0n_w = negm_epi16(v_ab0h_w, v_neg_w);
-    const __m128i v_abl1n_w = negm_epi16(v_ab1l_w, v_neg_w);
-    const __m128i v_abh1n_w = negm_epi16(v_ab1h_w, v_neg_w);
-    const __m128i v_abl2n_w = negm_epi16(v_ab2l_w, v_neg_w);
-    const __m128i v_abh2n_w = negm_epi16(v_ab2h_w, v_neg_w);
-    const __m128i v_abl3n_w = negm_epi16(v_ab3l_w, v_neg_w);
-    const __m128i v_abh3n_w = negm_epi16(v_ab3h_w, v_neg_w);
-
-    const __m128i v_r0l_w = _mm_madd_epi16(v_ab0l_w, v_abl0n_w);
-    const __m128i v_r0h_w = _mm_madd_epi16(v_ab0h_w, v_abh0n_w);
-    const __m128i v_r1l_w = _mm_madd_epi16(v_ab1l_w, v_abl1n_w);
-    const __m128i v_r1h_w = _mm_madd_epi16(v_ab1h_w, v_abh1n_w);
-    const __m128i v_r2l_w = _mm_madd_epi16(v_ab2l_w, v_abl2n_w);
-    const __m128i v_r2h_w = _mm_madd_epi16(v_ab2h_w, v_abh2n_w);
-    const __m128i v_r3l_w = _mm_madd_epi16(v_ab3l_w, v_abl3n_w);
-    const __m128i v_r3h_w = _mm_madd_epi16(v_ab3h_w, v_abh3n_w);
-
-    const __m128i v_r0_w = _mm_packs_epi32(v_r0l_w, v_r0h_w);
-    const __m128i v_r1_w = _mm_packs_epi32(v_r1l_w, v_r1h_w);
-    const __m128i v_r2_w = _mm_packs_epi32(v_r2l_w, v_r2h_w);
-    const __m128i v_r3_w = _mm_packs_epi32(v_r3l_w, v_r3h_w);
-
-    xx_store_128(d, v_r0_w);
-    xx_store_128(d + 8, v_r1_w);
-    xx_store_128(d + 16, v_r2_w);
-    xx_store_128(d + 24, v_r3_w);
-
-    a += 32;
-    b += 32;
-    d += 32;
-    N -= 32;
-  } while (N);
-}
-
diff --git a/vp10/vp10_common.mk b/vp10/vp10_common.mk
index 650b6f3..9bc0ce0 100644
--- a/vp10/vp10_common.mk
+++ b/vp10/vp10_common.mk
@@ -88,6 +88,10 @@
 VP10_COMMON_SRCS-$(HAVE_SSE2) += common/x86/mfqe_sse2.asm
 VP10_COMMON_SRCS-$(HAVE_SSE2) += common/x86/postproc_sse2.asm
 endif
+ifeq (yes,$(filter yes,$(CONFIG_GLOBAL_MOTION) $(CONFIG_WARPED_MOTION)))
+VP10_COMMON_SRCS-yes += common/warped_motion.h
+VP10_COMMON_SRCS-yes += common/warped_motion.c
+endif
 
 ifneq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
 VP10_COMMON_SRCS-$(HAVE_DSPR2)  += common/mips/dspr2/itrans4_dspr2.c
diff --git a/vp10/vp10cx.mk b/vp10/vp10cx.mk
index ea537fe..1aaac15 100644
--- a/vp10/vp10cx.mk
+++ b/vp10/vp10cx.mk
@@ -96,8 +96,6 @@
 VP10_CX_SRCS-yes += encoder/temporal_filter.h
 VP10_CX_SRCS-yes += encoder/mbgraph.c
 VP10_CX_SRCS-yes += encoder/mbgraph.h
-VP10_CX_SRCS-$(CONFIG_GLOBAL_MOTION) += common/warped_motion.h
-VP10_CX_SRCS-$(CONFIG_GLOBAL_MOTION) += common/warped_motion.c
 
 VP10_CX_SRCS-$(HAVE_SSE2) += encoder/x86/temporal_filter_apply_sse2.asm
 VP10_CX_SRCS-$(HAVE_SSE2) += encoder/x86/quantize_sse2.c
@@ -126,10 +124,6 @@
 ifeq ($(CONFIG_VP9_TEMPORAL_DENOISING),yes)
 VP10_CX_SRCS-$(HAVE_SSE2) += encoder/x86/denoiser_sse2.c
 endif
-ifeq ($(CONFIG_EXT_INTER),yes)
-VP10_CX_SRCS-yes += encoder/wedge_utils.c
-VP10_CX_SRCS-$(HAVE_SSE2) += encoder/x86/wedge_utils_sse2.c
-endif
 
 VP10_CX_SRCS-$(HAVE_AVX2) += encoder/x86/error_intrin_avx2.c