Harmonize quantizers for new-quant and regular

Change-Id: Ia8ccf6f270c06d14ecd37882860ce6a5a50434e5
diff --git a/av1/decoder/detokenize.c b/av1/decoder/detokenize.c
index 024006c..c42b95e 100644
--- a/av1/decoder/detokenize.c
+++ b/av1/decoder/detokenize.c
@@ -52,6 +52,9 @@
 #if CONFIG_AOM_QM
 static int decode_coefs(MACROBLOCKD *xd, 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,
                         int16_t *max_scan_line, aom_reader *r,
                         const qm_val_t *iqm[2][TX_SIZES])
@@ -63,7 +66,7 @@
 #endif  // CONFIG_NEW_QUANT
                         int ctx, const int16_t *scan, const int16_t *nb,
                         int16_t *max_scan_line, aom_reader *r)
-#endif
+#endif  // CONFIG_AOM_QM
 {
   FRAME_COUNTS *counts = xd->counts;
   FRAME_CONTEXT *const fc = xd->fc;
@@ -71,7 +74,7 @@
   const int ref = is_inter_block(&xd->mi[0]->mbmi);
 #if CONFIG_AOM_QM
   const qm_val_t *iqmatrix = iqm[!ref][tx_size];
-#endif
+#endif  // CONFIG_AOM_QM
   int band, c = 0;
   const int tx_size_ctx = txsize_sqr_map[tx_size];
   aom_prob(*coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] =
@@ -99,6 +102,9 @@
   const uint8_t *cat5_prob;
   const uint8_t *cat6_prob;
   (void)tx_type;
+#if CONFIG_AOM_QM
+  (void)iqmatrix;
+#endif  // CONFIG_AOM_QM
 
   if (counts) {
     coef_counts = counts->coef[tx_size_ctx][type][ref];
@@ -345,9 +351,12 @@
 #endif  //  CONFIG_NEW_QUANT
 
 #if CONFIG_AOM_QM
-  const int eob = decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size,
-                               tx_type, dequant, ctx, sc->scan, sc->neighbors,
-                               max_scan_line, r, pd->seg_iqmatrix[seg_id]);
+  const int eob = decode_coefs(
+      xd, pd->plane_type, pd->dqcoeff, tx_size, tx_type, dequant,
+#if CONFIG_NEW_QUANT
+      pd->seg_dequant_nuq[seg_id][dq],
+#endif  // CONFIG_NEW_QUANT
+      ctx, sc->scan, sc->neighbors, max_scan_line, r, pd->seg_iqmatrix[seg_id]);
 #else
   const int eob =
       decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size, tx_type, dequant,
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index 6916463..03a0ef9 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -96,15 +96,15 @@
   const int16_t *const scan = scan_order->scan;
   const int16_t *const nb = scan_order->neighbors;
   int dqv;
+  const int shift = get_tx_scale(tx_size);
 #if CONFIG_AOM_QM
   int seg_id = xd->mi[0]->mbmi.segment_id;
   const qm_val_t *iqmatrix = pd->seg_iqmatrix[seg_id][!ref][tx_size];
 #endif
-  const int shift = get_tx_scale(tx_size);
 #if CONFIG_NEW_QUANT
   int dq = get_dq_profile_from_ctx(mb->qindex, ctx, ref, plane_type);
   const dequant_val_type_nuq *dequant_val = pd->dequant_val_nuq[dq];
-#else
+#elif !CONFIG_AOM_QM
   const int dq_step[2] = { dequant_ptr[0] >> shift, dequant_ptr[1] >> shift };
 #endif  // CONFIG_NEW_QUANT
   int next = eob, sz = 0;
@@ -417,38 +417,55 @@
 typedef enum QUANT_FUNC {
   QUANT_FUNC_LOWBD = 0,
   QUANT_FUNC_HIGHBD = 1,
-  QUANT_FUNC_LAST = 2
+  QUANT_FUNC_TYPES = 2
 } QUANT_FUNC;
 
-static AV1_QUANT_FACADE quant_func_list[AV1_XFORM_QUANT_LAST][QUANT_FUNC_LAST] =
-    { { av1_quantize_fp_facade, av1_highbd_quantize_fp_facade },
+static AV1_QUANT_FACADE
+    quant_func_list[AV1_XFORM_QUANT_TYPES][QUANT_FUNC_TYPES] = {
+      { av1_quantize_fp_facade, av1_highbd_quantize_fp_facade },
       { av1_quantize_b_facade, av1_highbd_quantize_b_facade },
       { av1_quantize_dc_facade, av1_highbd_quantize_dc_facade },
-      { NULL, NULL } };
+#if CONFIG_NEW_QUANT
+      { av1_quantize_fp_nuq_facade, av1_highbd_quantize_fp_nuq_facade },
+      { av1_quantize_b_nuq_facade, av1_highbd_quantize_b_nuq_facade },
+      { av1_quantize_dc_nuq_facade, av1_highbd_quantize_dc_nuq_facade },
+#endif  // CONFIG_NEW_QUANT
+      { NULL, NULL }
+    };
 
 #elif !CONFIG_PVQ
 
 typedef enum QUANT_FUNC {
   QUANT_FUNC_LOWBD = 0,
-  QUANT_FUNC_LAST = 1
+  QUANT_FUNC_TYPES = 1
 } QUANT_FUNC;
 
-static AV1_QUANT_FACADE quant_func_list[AV1_XFORM_QUANT_LAST]
-                                       [QUANT_FUNC_LAST] = {
+static AV1_QUANT_FACADE quant_func_list[AV1_XFORM_QUANT_TYPES]
+                                       [QUANT_FUNC_TYPES] = {
                                          { av1_quantize_fp_facade },
                                          { av1_quantize_b_facade },
                                          { av1_quantize_dc_facade },
+#if CONFIG_NEW_QUANT
+                                         { av1_quantize_fp_nuq_facade },
+                                         { av1_quantize_b_nuq_facade },
+                                         { av1_quantize_dc_nuq_facade },
+#endif  // CONFIG_NEW_QUANT
                                          { NULL }
                                        };
 #endif
 
-static FWD_TXFM_OPT fwd_txfm_opt_list[AV1_XFORM_QUANT_LAST] = {
-  FWD_TXFM_OPT_NORMAL, FWD_TXFM_OPT_NORMAL, FWD_TXFM_OPT_DC, FWD_TXFM_OPT_NORMAL
+static FWD_TXFM_OPT fwd_txfm_opt_list[AV1_XFORM_QUANT_TYPES] = {
+  FWD_TXFM_OPT_NORMAL, FWD_TXFM_OPT_NORMAL, FWD_TXFM_OPT_DC,
+#if CONFIG_NEW_QUANT
+  FWD_TXFM_OPT_NORMAL, FWD_TXFM_OPT_NORMAL, FWD_TXFM_OPT_DC,
+#endif  // CONFIG_NEW_QUANT
+  FWD_TXFM_OPT_NORMAL
 };
 
 void av1_xform_quant(const AV1_COMMON *cm, MACROBLOCK *x, int plane, int block,
                      int blk_row, int blk_col, BLOCK_SIZE plane_bsize,
-                     TX_SIZE tx_size, AV1_XFORM_QUANT xform_quant_idx) {
+                     TX_SIZE tx_size, int ctx,
+                     AV1_XFORM_QUANT xform_quant_idx) {
   MACROBLOCKD *const xd = &x->e_mbd;
 #if !CONFIG_PVQ
   const struct macroblock_plane *const p = &x->plane[plane];
@@ -481,6 +498,14 @@
 
   src_diff = &p->src_diff[4 * (blk_row * diff_stride + blk_col)];
   qparam.log_scale = get_tx_scale(tx_size);
+#if CONFIG_NEW_QUANT
+  qparam.tx_size = tx_size;
+  qparam.dq = get_dq_profile_from_ctx(x->qindex, ctx, is_inter, plane_type);
+#endif  // CONFIG_NEW_QUANT
+#if CONFIG_AOM_QM
+  qparam.qmatrix = qmatrix;
+  qparam.iqmatrix = iqmatrix;
+#endif  // CONFIG_AOM_QM
 #else
   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
   tran_low_t *ref_coeff = BLOCK_OFFSET(pd->pvq_ref_coeff, block);
@@ -516,6 +541,7 @@
       pred[diff_stride * j + i] = dst[dst_stride * j + i];
     }
 #endif
+  (void)ctx;
 
   fwd_txfm_param.tx_type = tx_type;
   fwd_txfm_param.tx_size = tx_size;
@@ -530,12 +556,7 @@
     if (xform_quant_idx != AV1_XFORM_QUANT_SKIP_QUANT) {
       if (LIKELY(!x->skip_block)) {
         quant_func_list[xform_quant_idx][QUANT_FUNC_HIGHBD](
-            coeff, tx2d_size, p, qcoeff, pd, dqcoeff, eob, scan_order, &qparam
-#if CONFIG_AOM_QM
-            ,
-            qmatrix, iqmatrix
-#endif  // CONFIG_AOM_QM
-            );
+            coeff, tx2d_size, p, qcoeff, pd, dqcoeff, eob, scan_order, &qparam);
       } else {
         av1_quantize_skip(tx2d_size, qcoeff, dqcoeff, eob);
       }
@@ -549,12 +570,7 @@
   if (xform_quant_idx != AV1_XFORM_QUANT_SKIP_QUANT) {
     if (LIKELY(!x->skip_block)) {
       quant_func_list[xform_quant_idx][QUANT_FUNC_LOWBD](
-          coeff, tx2d_size, p, qcoeff, pd, dqcoeff, eob, scan_order, &qparam
-#if CONFIG_AOM_QM
-          ,
-          qmatrix, iqmatrix
-#endif  // CONFIG_AOM_QM
-          );
+          coeff, tx2d_size, p, qcoeff, pd, dqcoeff, eob, scan_order, &qparam);
     } else {
       av1_quantize_skip(tx2d_size, qcoeff, dqcoeff, eob);
     }
@@ -586,368 +602,6 @@
 #endif  // #if !CONFIG_PVQ
 }
 
-#if CONFIG_NEW_QUANT
-// TODO(debargha, sarah): Unify these functions with the ones above
-void av1_xform_quant_nuq(const AV1_COMMON *cm, MACROBLOCK *x, int plane,
-                         int block, int blk_row, int blk_col,
-                         BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int ctx) {
-  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 int is_inter = is_inter_block(&xd->mi[0]->mbmi);
-  const SCAN_ORDER *const scan_order = get_scan(cm, tx_size, tx_type, is_inter);
-  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);
-  int dq = get_dq_profile_from_ctx(x->qindex, ctx, is_inter, plane_type);
-  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;
-
-  assert((x->qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
-
-  fwd_txfm_param.tx_type = tx_type;
-  fwd_txfm_param.tx_size = tx_size;
-  fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[AV1_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_AOM_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 (get_tx_scale(tx_size)) {
-#if CONFIG_TX64X64
-      case 2:
-        highbd_quantize_64x64_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant, p->quant_shift,
-            pd->dequant, (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-            (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff,
-            dqcoeff, eob, scan_order->scan, band);
-        break;
-#endif  // CONFIG_TX64X64
-      case 1:
-        highbd_quantize_32x32_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant, p->quant_shift,
-            pd->dequant, (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-            (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff,
-            dqcoeff, eob, scan_order->scan, band);
-        break;
-      default:
-        highbd_quantize_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant, p->quant_shift,
-            pd->dequant, (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-            (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff,
-            dqcoeff, eob, scan_order->scan, band);
-        break;
-    }
-    return;
-  }
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-
-  fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
-  switch (get_tx_scale(tx_size)) {
-#if CONFIG_TX64X64
-    case 2:
-      quantize_64x64_nuq(coeff, tx_size_2d[tx_size], x->skip_block, p->quant,
-                         p->quant_shift, pd->dequant,
-                         (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-                         (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
-                         qcoeff, dqcoeff, eob, scan_order->scan, band);
-      break;
-#endif  // CONFIG_TX64X64
-    case 1:
-      quantize_32x32_nuq(coeff, tx_size_2d[tx_size], x->skip_block, p->quant,
-                         p->quant_shift, pd->dequant,
-                         (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-                         (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
-                         qcoeff, dqcoeff, eob, scan_order->scan, band);
-      break;
-    default:
-      quantize_nuq(coeff, tx_size_2d[tx_size], x->skip_block, p->quant,
-                   p->quant_shift, pd->dequant,
-                   (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-                   (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
-                   qcoeff, dqcoeff, eob, scan_order->scan, band);
-      break;
-  }
-}
-
-void av1_xform_quant_fp_nuq(const AV1_COMMON *cm, MACROBLOCK *x, int plane,
-                            int block, int blk_row, int blk_col,
-                            BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int ctx) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  const struct macroblock_plane *const p = &x->plane[plane];
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
-  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(cm, tx_size, tx_type, is_inter);
-  int dq = get_dq_profile_from_ctx(x->qindex, ctx, is_inter, plane_type);
-  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;
-
-  assert((x->qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
-
-  fwd_txfm_param.tx_type = tx_type;
-  fwd_txfm_param.tx_size = tx_size;
-  fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[AV1_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_AOM_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 (get_tx_scale(tx_size)) {
-#if CONFIG_TX64X64
-      case 2:
-        highbd_quantize_64x64_fp_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp, pd->dequant,
-            (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-            (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff,
-            dqcoeff, eob, scan_order->scan, band);
-        break;
-#endif  // CONFIG_TX64X64
-      case 1:
-        highbd_quantize_32x32_fp_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp, pd->dequant,
-            (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-            (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff,
-            dqcoeff, eob, scan_order->scan, band);
-        break;
-      default:
-        highbd_quantize_fp_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp, pd->dequant,
-            (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-            (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff,
-            dqcoeff, eob, scan_order->scan, band);
-    }
-    return;
-  }
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-
-  fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
-  switch (get_tx_scale(tx_size)) {
-#if CONFIG_TX64X64
-    case 2:
-      quantize_64x64_fp_nuq(
-          coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp, pd->dequant,
-          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff,
-          dqcoeff, eob, scan_order->scan, band);
-      break;
-#endif  // CONFIG_TX64X64
-    case 1:
-      quantize_32x32_fp_nuq(
-          coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp, pd->dequant,
-          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff,
-          dqcoeff, eob, scan_order->scan, band);
-      break;
-    default:
-      quantize_fp_nuq(coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp,
-                      pd->dequant,
-                      (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
-                      (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
-                      qcoeff, dqcoeff, eob, scan_order->scan, band);
-      break;
-  }
-}
-
-void av1_xform_quant_dc_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
-                            int blk_col, BLOCK_SIZE plane_bsize,
-                            TX_SIZE tx_size, int ctx) {
-  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;
-  const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
-  int dq = get_dq_profile_from_ctx(x->qindex, ctx, is_inter, plane_type);
-
-  FWD_TXFM_PARAM fwd_txfm_param;
-
-  assert((x->qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
-
-  fwd_txfm_param.tx_type = tx_type;
-  fwd_txfm_param.tx_size = tx_size;
-  fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[AV1_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_AOM_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 (get_tx_scale(tx_size)) {
-#if CONFIG_TX64X64
-      case 2:
-        highbd_quantize_dc_64x64_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant[0],
-            p->quant_shift[0], pd->dequant[0], p->cuml_bins_nuq[dq][0],
-            pd->dequant_val_nuq[dq][0], qcoeff, dqcoeff, eob);
-        break;
-#endif  // CONFIG_TX64X64
-      case 1:
-        highbd_quantize_dc_32x32_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant[0],
-            p->quant_shift[0], pd->dequant[0], p->cuml_bins_nuq[dq][0],
-            pd->dequant_val_nuq[dq][0], qcoeff, dqcoeff, eob);
-        break;
-      default:
-        highbd_quantize_dc_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant[0],
-            p->quant_shift[0], pd->dequant[0], p->cuml_bins_nuq[dq][0],
-            pd->dequant_val_nuq[dq][0], qcoeff, dqcoeff, eob);
-        break;
-    }
-    return;
-  }
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-
-  fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
-  switch (get_tx_scale(tx_size)) {
-#if CONFIG_TX64X64
-    case 2:
-      quantize_dc_64x64_nuq(coeff, tx_size_2d[tx_size], x->skip_block,
-                            p->quant[0], p->quant_shift[0], pd->dequant[0],
-                            p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-                            qcoeff, dqcoeff, eob);
-      break;
-#endif  // CONFIG_TX64X64
-    case 1:
-      quantize_dc_32x32_nuq(coeff, tx_size_2d[tx_size], x->skip_block,
-                            p->quant[0], p->quant_shift[0], pd->dequant[0],
-                            p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-                            qcoeff, dqcoeff, eob);
-      break;
-    default:
-      quantize_dc_nuq(coeff, tx_size_2d[tx_size], x->skip_block, p->quant[0],
-                      p->quant_shift[0], pd->dequant[0],
-                      p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-                      qcoeff, dqcoeff, eob);
-      break;
-  }
-}
-
-void av1_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, int ctx) {
-  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;
-  const int is_inter = is_inter_block(&xd->mi[0]->mbmi);
-  int dq = get_dq_profile_from_ctx(x->qindex, ctx, is_inter, plane_type);
-
-  FWD_TXFM_PARAM fwd_txfm_param;
-
-  assert((x->qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
-
-  fwd_txfm_param.tx_type = tx_type;
-  fwd_txfm_param.tx_size = tx_size;
-  fwd_txfm_param.fwd_txfm_opt = fwd_txfm_opt_list[AV1_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_AOM_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 (get_tx_scale(tx_size)) {
-#if CONFIG_TX64X64
-      case 2:
-        highbd_quantize_dc_64x64_fp_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp[0],
-            pd->dequant[0], p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-            qcoeff, dqcoeff, eob);
-        break;
-#endif  // CONFIG_TX64X64
-      case 1:
-        highbd_quantize_dc_32x32_fp_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp[0],
-            pd->dequant[0], p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-            qcoeff, dqcoeff, eob);
-        break;
-      default:
-        highbd_quantize_dc_fp_nuq(
-            coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp[0],
-            pd->dequant[0], p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-            qcoeff, dqcoeff, eob);
-        break;
-    }
-    return;
-  }
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-
-  fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param);
-  switch (get_tx_scale(tx_size)) {
-#if CONFIG_TX64X64
-    case 2:
-      quantize_dc_64x64_fp_nuq(
-          coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp[0],
-          pd->dequant[0], p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-          qcoeff, dqcoeff, eob);
-      break;
-#endif  // CONFIG_TX64X64
-    case 1:
-      quantize_dc_32x32_fp_nuq(
-          coeff, tx_size_2d[tx_size], x->skip_block, p->quant_fp[0],
-          pd->dequant[0], p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-          qcoeff, dqcoeff, eob);
-      break;
-    default:
-      quantize_dc_fp_nuq(coeff, tx_size_2d[tx_size], x->skip_block,
-                         p->quant_fp[0], pd->dequant[0],
-                         p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0],
-                         qcoeff, dqcoeff, eob);
-      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) {
   struct encode_b_args *const args = arg;
@@ -987,11 +641,11 @@
   {
 #endif
 #if CONFIG_NEW_QUANT
-    av1_xform_quant_fp_nuq(cm, x, plane, block, blk_row, blk_col, plane_bsize,
-                           tx_size, ctx);
+    av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
+                    ctx, AV1_XFORM_QUANT_FP_NUQ);
 #else
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
-                    AV1_XFORM_QUANT_FP);
+                    ctx, AV1_XFORM_QUANT_FP);
 #endif  // CONFIG_NEW_QUANT
   }
 #if CONFIG_VAR_TX
@@ -1113,18 +767,15 @@
   struct macroblockd_plane *const pd = &xd->plane[plane];
   tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
   uint8_t *dst;
-#if CONFIG_NEW_QUANT
-  int ctx;
-#endif  // CONFIG_NEW_QUANT
+  int ctx = 0;
   dst = &pd->dst.buf[4 * blk_row * pd->dst.stride + 4 * blk_col];
 
 #if CONFIG_NEW_QUANT
-  ctx = 0;
-  av1_xform_quant_fp_nuq(cm, x, plane, block, blk_row, blk_col, plane_bsize,
-                         tx_size, ctx);
+  av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
+                  ctx, AV1_XFORM_QUANT_B_NUQ);
 #else
   av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
-                  AV1_XFORM_QUANT_B);
+                  ctx, AV1_XFORM_QUANT_B);
 #endif  // CONFIG_NEW_QUANT
 #if !CONFIG_PVQ
   if (p->eobs[block] > 0) {
@@ -1274,7 +925,7 @@
   const int tx1d_width = tx_size_wide[tx_size];
   const int tx1d_height = tx_size_high[tx_size];
   ENTROPY_CONTEXT *a = NULL, *l = NULL;
-  int ctx;
+  int ctx = 0;
   INV_TXFM_PARAM inv_txfm_param;
 #if CONFIG_PVQ
   int tx_blk_size;
@@ -1309,11 +960,11 @@
 
   if (args->enable_optimize_b) {
 #if CONFIG_NEW_QUANT
-    av1_xform_quant_fp_nuq(cm, x, plane, block, blk_row, blk_col, plane_bsize,
-                           tx_size, ctx);
+    av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
+                    ctx, AV1_XFORM_QUANT_FP_NUQ);
 #else   // CONFIG_NEW_QUANT
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
-                    AV1_XFORM_QUANT_FP);
+                    ctx, AV1_XFORM_QUANT_FP);
 #endif  // CONFIG_NEW_QUANT
     if (p->eobs[block]) {
       *a = *l = av1_optimize_b(cm, x, plane, block, tx_size, ctx) > 0;
@@ -1321,8 +972,13 @@
       *a = *l = 0;
     }
   } else {
+#if CONFIG_NEW_QUANT
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
-                    AV1_XFORM_QUANT_B);
+                    ctx, AV1_XFORM_QUANT_B_NUQ);
+#else   // CONFIG_NEW_QUANT
+    av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
+                    ctx, AV1_XFORM_QUANT_B);
+#endif  // CONFIG_NEW_QUANT
     *a = *l = p->eobs[block] > 0;
   }
 
@@ -1346,10 +1002,14 @@
     *(args->skip) = 0;
   }
 #else  // #if !CONFIG_PVQ
-  (void)ctx;
 
+#if CONFIG_NEW_QUANT
   av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
-                  AV1_XFORM_QUANT_FP);
+                  ctx, AV1_XFORM_QUANT_FP_NUQ);
+#else
+  av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
+                  ctx, AV1_XFORM_QUANT_FP);
+#endif  // CONFIG_NEW_QUANT
 
   *a = *l = !x->pvq_skip[plane];
 
diff --git a/av1/encoder/encodemb.h b/av1/encoder/encodemb.h
index 2f2b93b..99810066 100644
--- a/av1/encoder/encodemb.h
+++ b/av1/encoder/encodemb.h
@@ -39,8 +39,13 @@
   AV1_XFORM_QUANT_FP = 0,
   AV1_XFORM_QUANT_B = 1,
   AV1_XFORM_QUANT_DC = 2,
-  AV1_XFORM_QUANT_SKIP_QUANT = 3,
-  AV1_XFORM_QUANT_LAST = 4
+#if CONFIG_NEW_QUANT
+  AV1_XFORM_QUANT_FP_NUQ = 3,
+  AV1_XFORM_QUANT_B_NUQ = 4,
+  AV1_XFORM_QUANT_DC_NUQ = 5,
+#endif  // CONFIG_NEW_QUANT
+  AV1_XFORM_QUANT_SKIP_QUANT,
+  AV1_XFORM_QUANT_TYPES,
 } AV1_XFORM_QUANT;
 
 void av1_encode_sb(AV1_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE bsize);
@@ -50,21 +55,7 @@
 void av1_encode_sby_pass1(AV1_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE bsize);
 void av1_xform_quant(const AV1_COMMON *cm, MACROBLOCK *x, int plane, int block,
                      int blk_row, int blk_col, BLOCK_SIZE plane_bsize,
-                     TX_SIZE tx_size, AV1_XFORM_QUANT xform_quant_idx);
-#if CONFIG_NEW_QUANT
-void av1_xform_quant_nuq(const AV1_COMMON *cm, MACROBLOCK *x, int plane,
-                         int block, int blk_row, int blk_col,
-                         BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int ctx);
-void av1_xform_quant_dc_nuq(MACROBLOCK *x, int plane, int block, int blk_row,
-                            int blk_col, BLOCK_SIZE plane_bsize,
-                            TX_SIZE tx_size, int ctx);
-void av1_xform_quant_fp_nuq(const AV1_COMMON *cm, MACROBLOCK *x, int plane,
-                            int block, int blk_row, int blk_col,
-                            BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int ctx);
-void av1_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, int ctx);
-#endif
+                     TX_SIZE tx_size, int ctx, AV1_XFORM_QUANT xform_quant_idx);
 
 int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int block,
                    TX_SIZE tx_size, int ctx);
diff --git a/av1/encoder/quantize.c b/av1/encoder/quantize.c
index da01642..975ab94 100644
--- a/av1/encoder/quantize.c
+++ b/av1/encoder/quantize.c
@@ -442,14 +442,13 @@
                             const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                             const MACROBLOCKD_PLANE *pd,
                             tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
-                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-                            ,
-                            const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-                            ) {
+                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam) {
   // obsolete skip_block
   const int skip_block = 0;
+#if CONFIG_AOM_QM
+  const qm_val_t *qm_ptr = qparam->qmatrix;
+  const qm_val_t *iqm_ptr = qparam->iqmatrix;
+#endif  // CONFIG_AOM_QM
 
   switch (qparam->log_scale) {
     case 0:
@@ -494,14 +493,13 @@
                            const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                            const MACROBLOCKD_PLANE *pd, tran_low_t *dqcoeff_ptr,
                            uint16_t *eob_ptr, const SCAN_ORDER *sc,
-                           const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-                           ,
-                           const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-                           ) {
+                           const QUANT_PARAM *qparam) {
   // obsolete skip_block
   const int skip_block = 0;
+#if CONFIG_AOM_QM
+  const qm_val_t *qm_ptr = qparam->qmatrix;
+  const qm_val_t *iqm_ptr = qparam->iqmatrix;
+#endif  // CONFIG_AOM_QM
 
   switch (qparam->log_scale) {
     case 0:
@@ -544,14 +542,14 @@
                             const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                             const MACROBLOCKD_PLANE *pd,
                             tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
-                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-                            ,
-                            const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-                            ) {
+                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam) {
   // obsolete skip_block
   const int skip_block = 0;
+#if CONFIG_AOM_QM
+  const qm_val_t *qm_ptr = qparam->qmatrix;
+  const qm_val_t *iqm_ptr = qparam->iqmatrix;
+#endif  // CONFIG_AOM_QM
+
   (void)sc;
 
   switch (qparam->log_scale) {
@@ -588,19 +586,138 @@
   }
 }
 
-#if CONFIG_AOM_HIGHBITDEPTH
-void av1_highbd_quantize_fp_facade(
-    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
-    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
-    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
-    const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-    ,
-    const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-    ) {
+#if CONFIG_NEW_QUANT
+void av1_quantize_b_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
+                               const MACROBLOCK_PLANE *p,
+                               tran_low_t *qcoeff_ptr,
+                               const MACROBLOCKD_PLANE *pd,
+                               tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                               const SCAN_ORDER *sc,
+                               const QUANT_PARAM *qparam) {
   // obsolete skip_block
   const int skip_block = 0;
+  const uint8_t *band = get_band_translate(qparam->tx_size);
+  int dq = qparam->dq;
+
+  switch (qparam->log_scale) {
+    case 0:
+      quantize_nuq(coeff_ptr, n_coeffs, skip_block, p->quant, p->quant_shift,
+                   pd->dequant,
+                   (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+                   (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
+                   qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+    case 1:
+      quantize_32x32_nuq(coeff_ptr, n_coeffs, skip_block, p->quant,
+                         p->quant_shift, pd->dequant,
+                         (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+                         (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
+                         qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+#if CONFIG_TX64X64
+    case 2:
+      quantize_64x64_nuq(coeff_ptr, n_coeffs, skip_block, p->quant,
+                         p->quant_shift, pd->dequant,
+                         (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+                         (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
+                         qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+#endif  // CONFIG_TX64X64
+    default: assert(0);
+  }
+}
+
+void av1_quantize_fp_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
+                                const MACROBLOCK_PLANE *p,
+                                tran_low_t *qcoeff_ptr,
+                                const MACROBLOCKD_PLANE *pd,
+                                tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                const SCAN_ORDER *sc,
+                                const QUANT_PARAM *qparam) {
+  // obsolete skip_block
+  const int skip_block = 0;
+  const uint8_t *band = get_band_translate(qparam->tx_size);
+  int dq = qparam->dq;
+
+  switch (qparam->log_scale) {
+    case 0:
+      quantize_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
+                      (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+                      (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
+                      qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+    case 1:
+      quantize_32x32_fp_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
+          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+#if CONFIG_TX64X64
+    case 2:
+      quantize_64x64_fp_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
+          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+#endif  // CONFIG_TX64X64
+    default: assert(0);
+  }
+}
+
+void av1_quantize_dc_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
+                                const MACROBLOCK_PLANE *p,
+                                tran_low_t *qcoeff_ptr,
+                                const MACROBLOCKD_PLANE *pd,
+                                tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                const SCAN_ORDER *sc,
+                                const QUANT_PARAM *qparam) {
+  // obsolete skip_block
+  const int skip_block = 0;
+  int dq = qparam->dq;
+  (void)sc;
+
+  switch (qparam->log_scale) {
+    case 0:
+      quantize_dc_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp[0],
+                         pd->dequant[0], p->cuml_bins_nuq[dq][0],
+                         pd->dequant_val_nuq[dq][0], qcoeff_ptr, dqcoeff_ptr,
+                         eob_ptr);
+      break;
+    case 1:
+      quantize_dc_32x32_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp[0],
+                               pd->dequant[0], p->cuml_bins_nuq[dq][0],
+                               pd->dequant_val_nuq[dq][0], qcoeff_ptr,
+                               dqcoeff_ptr, eob_ptr);
+      break;
+#if CONFIG_TX64X64
+    case 2:
+      quantize_dc_64x64_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp[0],
+                               pd->dequant[0], p->cuml_bins_nuq[dq][0],
+                               pd->dequant_val_nuq[dq][0], qcoeff_ptr,
+                               dqcoeff_ptr, eob_ptr);
+      break;
+#endif  // CONFIG_TX64X64
+    default: assert(0);
+  }
+}
+#endif  // CONFIG_NEW_QUANT
+
+#if CONFIG_AOM_HIGHBITDEPTH
+void av1_highbd_quantize_fp_facade(const tran_low_t *coeff_ptr,
+                                   intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+                                   tran_low_t *qcoeff_ptr,
+                                   const MACROBLOCKD_PLANE *pd,
+                                   tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                   const SCAN_ORDER *sc,
+                                   const QUANT_PARAM *qparam) {
+  // obsolete skip_block
+  const int skip_block = 0;
+#if CONFIG_AOM_QM
+  const qm_val_t *qm_ptr = qparam->qmatrix;
+  const qm_val_t *iqm_ptr = qparam->iqmatrix;
+#endif  // CONFIG_AOM_QM
 
   av1_highbd_quantize_fp(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round_fp,
                          p->quant_fp, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
@@ -611,18 +728,19 @@
                          qparam->log_scale);
 }
 
-void av1_highbd_quantize_b_facade(
-    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
-    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
-    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
-    const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-    ,
-    const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-    ) {
+void av1_highbd_quantize_b_facade(const tran_low_t *coeff_ptr,
+                                  intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+                                  tran_low_t *qcoeff_ptr,
+                                  const MACROBLOCKD_PLANE *pd,
+                                  tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                  const SCAN_ORDER *sc,
+                                  const QUANT_PARAM *qparam) {
   // obsolete skip_block
   const int skip_block = 0;
+#if CONFIG_AOM_QM
+  const qm_val_t *qm_ptr = qparam->qmatrix;
+  const qm_val_t *iqm_ptr = qparam->iqmatrix;
+#endif  // CONFIG_AOM_QM
 
   av1_highbd_quantize_b(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round,
                         p->quant, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
@@ -633,28 +751,60 @@
                         qparam->log_scale);
 }
 
-void av1_highbd_quantize_dc_facade(
-    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
-    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
-    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
-    const QUANT_PARAM *qparam
+#if CONFIG_AOM_HIGHBITDEPTH
+static INLINE void highbd_quantize_dc(
+    const tran_low_t *coeff_ptr, int n_coeffs, int skip_block,
+    const int16_t *round_ptr, const int16_t quant, tran_low_t *qcoeff_ptr,
+    tran_low_t *dqcoeff_ptr, const int16_t dequant_ptr, uint16_t *eob_ptr,
 #if CONFIG_AOM_QM
-    ,
-    const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
+    const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr,
 #endif
-    ) {
+    const int log_scale) {
+  int eob = -1;
+
+  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
+  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
+#if CONFIG_AOM_QM
+  (void)qm_ptr;
+  (void)iqm_ptr;
+#endif
+  if (!skip_block) {
+    const int coeff = coeff_ptr[0];
+    const int coeff_sign = (coeff >> 31);
+    const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
+    const int64_t tmp = abs_coeff + round_ptr[0];
+    const uint32_t abs_qcoeff = (uint32_t)((tmp * quant) >> (16 - log_scale));
+    qcoeff_ptr[0] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
+    dqcoeff_ptr[0] = qcoeff_ptr[0] * dequant_ptr / (1 << log_scale);
+    if (abs_qcoeff) eob = 0;
+  }
+  *eob_ptr = eob + 1;
+}
+#endif  // CONFIG_AOM_HIGHBITDEPTH
+
+void av1_highbd_quantize_dc_facade(const tran_low_t *coeff_ptr,
+                                   intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+                                   tran_low_t *qcoeff_ptr,
+                                   const MACROBLOCKD_PLANE *pd,
+                                   tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                   const SCAN_ORDER *sc,
+                                   const QUANT_PARAM *qparam) {
   // obsolete skip_block
   const int skip_block = 0;
+#if CONFIG_AOM_QM
+  const qm_val_t *qm_ptr = qparam->qmatrix;
+  const qm_val_t *iqm_ptr = qparam->iqmatrix;
+#endif  // CONFIG_AOM_QM
 
   (void)sc;
 
-  av1_highbd_quantize_dc(coeff_ptr, (int)n_coeffs, skip_block, p->round,
-                         p->quant_fp[0], qcoeff_ptr, dqcoeff_ptr,
-                         pd->dequant[0], eob_ptr,
+  highbd_quantize_dc(coeff_ptr, (int)n_coeffs, skip_block, p->round,
+                     p->quant_fp[0], qcoeff_ptr, dqcoeff_ptr, pd->dequant[0],
+                     eob_ptr,
 #if CONFIG_AOM_QM
-                         qm_ptr, iqm_ptr,
+                     qm_ptr, iqm_ptr,
 #endif
-                         qparam->log_scale);
+                     qparam->log_scale);
 }
 
 #if CONFIG_NEW_QUANT
@@ -1057,6 +1207,117 @@
   *eob_ptr = eob + 1;
 }
 #endif  // CONFIG_TX64X64
+
+void av1_highbd_quantize_b_nuq_facade(
+    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
+    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
+    const QUANT_PARAM *qparam) {
+  // obsolete skip_block
+  const int skip_block = 0;
+  const uint8_t *band = get_band_translate(qparam->tx_size);
+  const int dq = qparam->dq;
+
+  switch (qparam->log_scale) {
+    case 0:
+      highbd_quantize_nuq(coeff_ptr, n_coeffs, skip_block, p->quant,
+                          p->quant_shift, pd->dequant,
+                          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+                          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
+                          qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+    case 1:
+      highbd_quantize_32x32_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant, p->quant_shift,
+          pd->dequant, (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+#if CONFIG_TX64X64
+    case 2:
+      highbd_quantize_64x64_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant, p->quant_shift,
+          pd->dequant, (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+#endif  // CONFIG_TX64X64
+    default: assert(0);
+  }
+}
+
+void av1_highbd_quantize_fp_nuq_facade(
+    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
+    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
+    const QUANT_PARAM *qparam) {
+  // obsolete skip_block
+  const int skip_block = 0;
+  const uint8_t *band = get_band_translate(qparam->tx_size);
+  const int dq = qparam->dq;
+
+  switch (qparam->log_scale) {
+    case 0:
+      highbd_quantize_fp_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
+          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+    case 1:
+      highbd_quantize_32x32_fp_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
+          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+#if CONFIG_TX64X64
+    case 2:
+      highbd_quantize_64x64_fp_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
+          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
+          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr, sc->scan, band);
+      break;
+#endif  // CONFIG_TX64X64
+    default: assert(0);
+  }
+}
+
+void av1_highbd_quantize_dc_nuq_facade(
+    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
+    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
+    const QUANT_PARAM *qparam) {
+  // obsolete skip_block
+  const int skip_block = 0;
+  const int dq = qparam->dq;
+  (void)sc;
+
+  switch (qparam->log_scale) {
+    case 0:
+      highbd_quantize_dc_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp[0],
+                                pd->dequant[0], p->cuml_bins_nuq[dq][0],
+                                pd->dequant_val_nuq[dq][0], qcoeff_ptr,
+                                dqcoeff_ptr, eob_ptr);
+      break;
+    case 1:
+      highbd_quantize_dc_32x32_fp_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant_fp[0], pd->dequant[0],
+          p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr);
+      break;
+#if CONFIG_TX64X64
+    case 2:
+      highbd_quantize_dc_64x64_fp_nuq(
+          coeff_ptr, n_coeffs, skip_block, p->quant_fp[0], pd->dequant[0],
+          p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0], qcoeff_ptr,
+          dqcoeff_ptr, eob_ptr);
+      break;
+#endif  // CONFIG_TX64X64
+    default: assert(0);
+  }
+}
 #endif  // CONFIG_NEW_QUANT
 #endif  // CONFIG_AOM_HIGHBITDEPTH
 
@@ -1476,38 +1737,6 @@
 }
 #endif
 
-#if CONFIG_AOM_HIGHBITDEPTH
-void av1_highbd_quantize_dc(const tran_low_t *coeff_ptr, int n_coeffs,
-                            int skip_block, const int16_t *round_ptr,
-                            const int16_t quant, tran_low_t *qcoeff_ptr,
-                            tran_low_t *dqcoeff_ptr, const int16_t dequant_ptr,
-                            uint16_t *eob_ptr,
-#if CONFIG_AOM_QM
-                            const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr,
-#endif
-                            const int log_scale) {
-  int eob = -1;
-
-  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
-  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
-#if CONFIG_AOM_QM
-  (void)qm_ptr;
-  (void)iqm_ptr;
-#endif
-  if (!skip_block) {
-    const int coeff = coeff_ptr[0];
-    const int coeff_sign = (coeff >> 31);
-    const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
-    const int64_t tmp = abs_coeff + round_ptr[0];
-    const uint32_t abs_qcoeff = (uint32_t)((tmp * quant) >> (16 - log_scale));
-    qcoeff_ptr[0] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
-    dqcoeff_ptr[0] = qcoeff_ptr[0] * dequant_ptr / (1 << log_scale);
-    if (abs_qcoeff) eob = 0;
-  }
-  *eob_ptr = eob + 1;
-}
-#endif
-
 static void invert_quant(int16_t *quant, int16_t *shift, int d) {
   uint32_t t;
   int l, m;
diff --git a/av1/encoder/quantize.h b/av1/encoder/quantize.h
index b13af5a..92ba3e7 100644
--- a/av1/encoder/quantize.h
+++ b/av1/encoder/quantize.h
@@ -21,19 +21,25 @@
 extern "C" {
 #endif
 
-typedef struct QUANT_PARAM { int log_scale; } QUANT_PARAM;
+typedef struct QUANT_PARAM {
+  int log_scale;
+#if CONFIG_NEW_QUANT
+  TX_SIZE tx_size;
+  int dq;
+#endif  // CONFIG_NEW_QUANT
+#if CONFIG_AOM_QM
+  const qm_val_t *qmatrix;
+  const qm_val_t *iqmatrix;
+#endif  // CONFIG_AOM_QM
+} QUANT_PARAM;
 
 typedef void (*AV1_QUANT_FACADE)(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                                  const MACROBLOCK_PLANE *p,
                                  tran_low_t *qcoeff_ptr,
                                  const MACROBLOCKD_PLANE *pd,
                                  tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
-                                 const SCAN_ORDER *sc, const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-                                 ,
-                                 const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-                                 );
+                                 const SCAN_ORDER *sc,
+                                 const QUANT_PARAM *qparam);
 
 typedef struct {
 #if CONFIG_NEW_QUANT
@@ -84,163 +90,88 @@
                             const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                             const MACROBLOCKD_PLANE *pd,
                             tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
-                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-                            ,
-                            const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-                            );
+                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam);
 
 void av1_quantize_b_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                            const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                            const MACROBLOCKD_PLANE *pd, tran_low_t *dqcoeff_ptr,
                            uint16_t *eob_ptr, const SCAN_ORDER *sc,
-                           const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-                           ,
-                           const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-                           );
+                           const QUANT_PARAM *qparam);
 
 void av1_quantize_dc_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                             const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                             const MACROBLOCKD_PLANE *pd,
                             tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
-                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-                            ,
-                            const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-                            );
+                            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);
-#if CONFIG_TX64X64
-void quantize_dc_64x64_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);
-#endif  // CONFIG_TX64X64
-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);
-#if CONFIG_TX64X64
-void quantize_dc_64x64_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_TX64X64
+void av1_quantize_fp_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
+                                const MACROBLOCK_PLANE *p,
+                                tran_low_t *qcoeff_ptr,
+                                const MACROBLOCKD_PLANE *pd,
+                                tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                const SCAN_ORDER *sc,
+                                const QUANT_PARAM *qparam);
+
+void av1_quantize_b_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
+                               const MACROBLOCK_PLANE *p,
+                               tran_low_t *qcoeff_ptr,
+                               const MACROBLOCKD_PLANE *pd,
+                               tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                               const SCAN_ORDER *sc, const QUANT_PARAM *qparam);
+
+void av1_quantize_dc_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
+                                const MACROBLOCK_PLANE *p,
+                                tran_low_t *qcoeff_ptr,
+                                const MACROBLOCKD_PLANE *pd,
+                                tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                const SCAN_ORDER *sc,
+                                const QUANT_PARAM *qparam);
 #endif  // CONFIG_NEW_QUANT
 
 #if CONFIG_AOM_HIGHBITDEPTH
-void av1_highbd_quantize_fp_facade(
-    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
-    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
-    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
-    const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-    ,
-    const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-    );
+void av1_highbd_quantize_fp_facade(const tran_low_t *coeff_ptr,
+                                   intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+                                   tran_low_t *qcoeff_ptr,
+                                   const MACROBLOCKD_PLANE *pd,
+                                   tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                   const SCAN_ORDER *sc,
+                                   const QUANT_PARAM *qparam);
 
-void av1_highbd_quantize_b_facade(
-    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
-    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
-    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
-    const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-    ,
-    const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-    );
+void av1_highbd_quantize_b_facade(const tran_low_t *coeff_ptr,
+                                  intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+                                  tran_low_t *qcoeff_ptr,
+                                  const MACROBLOCKD_PLANE *pd,
+                                  tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                  const SCAN_ORDER *sc,
+                                  const QUANT_PARAM *qparam);
 
-void av1_highbd_quantize_dc_facade(
-    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
-    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
-    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
-    const QUANT_PARAM *qparam
-#if CONFIG_AOM_QM
-    ,
-    const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
-#endif
-    );
+void av1_highbd_quantize_dc_facade(const tran_low_t *coeff_ptr,
+                                   intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+                                   tran_low_t *qcoeff_ptr,
+                                   const MACROBLOCKD_PLANE *pd,
+                                   tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
+                                   const SCAN_ORDER *sc,
+                                   const QUANT_PARAM *qparam);
 
-void av1_highbd_quantize_dc(const tran_low_t *coeff_ptr, int n_coeffs,
-                            int skip_block, const int16_t *round_ptr,
-                            const int16_t quant, tran_low_t *qcoeff_ptr,
-                            tran_low_t *dqcoeff_ptr, const int16_t dequant_ptr,
-                            uint16_t *eob_ptr,
-#if CONFIG_AOM_QM
-                            const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr,
-#endif
-                            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);
-#if CONFIG_TX64X64
-void highbd_quantize_dc_64x64_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);
-#endif  // CONFIG_TX64X64
-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);
-#if CONFIG_TX64X64
-void highbd_quantize_dc_64x64_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_TX64X64
+void av1_highbd_quantize_fp_nuq_facade(
+    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
+    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
+    const QUANT_PARAM *qparam);
+
+void av1_highbd_quantize_b_nuq_facade(
+    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
+    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
+    const QUANT_PARAM *qparam);
+
+void av1_highbd_quantize_dc_nuq_facade(
+    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
+    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
+    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
+    const QUANT_PARAM *qparam);
 #endif  // CONFIG_NEW_QUANT
 #endif  // CONFIG_AOM_HIGHBITDEPTH
 
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index b97797c..ab37ec8 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -1222,11 +1222,11 @@
   } else {
 // full forward transform and quantization
 #if CONFIG_NEW_QUANT
-    av1_xform_quant_fp_nuq(cm, x, plane, block, blk_row, blk_col, plane_bsize,
-                           tx_size, coeff_ctx);
+    av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
+                    coeff_ctx, AV1_XFORM_QUANT_FP_NUQ);
 #else
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
-                    AV1_XFORM_QUANT_FP);
+                    coeff_ctx, AV1_XFORM_QUANT_FP);
 #endif  // CONFIG_NEW_QUANT
 #if !CONFIG_PVQ
     if (x->plane[plane].eobs[block])
@@ -2065,11 +2065,11 @@
             const int coeff_ctx =
                 combine_entropy_contexts(*(tempa + idx), *(templ + idy));
 #if CONFIG_NEW_QUANT
-            av1_xform_quant_fp_nuq(cm, x, 0, block, row + idy, col + idx,
-                                   BLOCK_8X8, TX_4X4, coeff_ctx);
+            av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
+                            TX_4X4, coeff_ctx, AV1_XFORM_QUANT_FP_NUQ);
 #else
             av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
-                            TX_4X4, AV1_XFORM_QUANT_FP);
+                            TX_4X4, coeff_ctx, AV1_XFORM_QUANT_FP);
 #endif  // CONFIG_NEW_QUANT
             ratey += av1_cost_coeffs(cm, x, 0, block, coeff_ctx, TX_4X4,
                                      scan_order->scan, scan_order->neighbors,
@@ -2090,11 +2090,11 @@
             const int coeff_ctx =
                 combine_entropy_contexts(*(tempa + idx), *(templ + idy));
 #if CONFIG_NEW_QUANT
-            av1_xform_quant_fp_nuq(cm, x, 0, block, row + idy, col + idx,
-                                   BLOCK_8X8, TX_4X4, coeff_ctx);
+            av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
+                            TX_4X4, coeff_ctx, AV1_XFORM_QUANT_FP_NUQ);
 #else
             av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
-                            TX_4X4, AV1_XFORM_QUANT_FP);
+                            TX_4X4, coeff_ctx, AV1_XFORM_QUANT_FP);
 #endif  // CONFIG_NEW_QUANT
             av1_optimize_b(cm, x, 0, block, TX_4X4, coeff_ctx);
             ratey += av1_cost_coeffs(cm, x, 0, block, coeff_ctx, TX_4X4,
@@ -2229,11 +2229,11 @@
           const int coeff_ctx =
               combine_entropy_contexts(*(tempa + idx), *(templ + idy));
 #if CONFIG_NEW_QUANT
-          av1_xform_quant_fp_nuq(cm, x, 0, block, row + idy, col + idx,
-                                 BLOCK_8X8, TX_4X4, coeff_ctx);
+          av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
+                          TX_4X4, coeff_ctx, AV1_XFORM_QUANT_B_NUQ);
 #else
           av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
-                          TX_4X4, AV1_XFORM_QUANT_B);
+                          TX_4X4, coeff_ctx, AV1_XFORM_QUANT_B);
 #endif  // CONFIG_NEW_QUANT
           ratey += av1_cost_coeffs(cm, x, 0, block, coeff_ctx, TX_4X4,
                                    scan_order->scan, scan_order->neighbors,
@@ -2268,11 +2268,11 @@
           const int coeff_ctx =
               combine_entropy_contexts(*(tempa + idx), *(templ + idy));
 #if CONFIG_NEW_QUANT
-          av1_xform_quant_fp_nuq(cm, x, 0, block, row + idy, col + idx,
-                                 BLOCK_8X8, TX_4X4, coeff_ctx);
+          av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
+                          TX_4X4, coeff_ctx, AV1_XFORM_QUANT_FP_NUQ);
 #else
           av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
-                          TX_4X4, AV1_XFORM_QUANT_FP);
+                          TX_4X4, coeff_ctx, AV1_XFORM_QUANT_FP);
 #endif  // CONFIG_NEW_QUANT
           av1_optimize_b(cm, x, 0, block, TX_4X4, coeff_ctx);
           ratey += av1_cost_coeffs(cm, x, 0, block, coeff_ctx, TX_4X4,
@@ -3137,11 +3137,11 @@
   max_blocks_wide >>= tx_size_wide_log2[0];
 
 #if CONFIG_NEW_QUANT
-  av1_xform_quant_fp_nuq(cm, x, plane, block, blk_row, blk_col, plane_bsize,
-                         tx_size, coeff_ctx);
+  av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
+                  coeff_ctx, AV1_XFORM_QUANT_FP_NUQ);
 #else
   av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
-                  AV1_XFORM_QUANT_FP);
+                  coeff_ctx, AV1_XFORM_QUANT_FP);
 #endif  // CONFIG_NEW_QUANT
 
   // TODO(yushin) : If PVQ is enabled, this should not be called.
@@ -4590,11 +4590,11 @@
 #if !CONFIG_PVQ
       coeff_ctx = combine_entropy_contexts(*(ta + (k & 1)), *(tl + (k >> 1)));
 #if CONFIG_NEW_QUANT
-      av1_xform_quant_fp_nuq(cm, x, 0, block, idy + (i >> 1), idx + (i & 0x01),
-                             BLOCK_8X8, tx_size, coeff_ctx);
+      av1_xform_quant(cm, x, 0, block, idy + (i >> 1), idx + (i & 0x01),
+                      BLOCK_8X8, tx_size, coeff_ctx, AV1_XFORM_QUANT_FP_NUQ);
 #else
       av1_xform_quant(cm, x, 0, block, idy + (i >> 1), idx + (i & 0x01),
-                      BLOCK_8X8, tx_size, AV1_XFORM_QUANT_FP);
+                      BLOCK_8X8, tx_size, coeff_ctx, AV1_XFORM_QUANT_FP);
 #endif  // CONFIG_NEW_QUANT
       if (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0)
         av1_optimize_b(cm, x, 0, block, tx_size, coeff_ctx);