0 LR ctx 3
diff --git a/apps/aomenc.c b/apps/aomenc.c
index a9f74b8..3768964 100644
--- a/apps/aomenc.c
+++ b/apps/aomenc.c
@@ -1645,6 +1645,9 @@
   fprintf(stdout,
           "Tool setting (Others)          : Palette (%d), "
           "ParityHiding (%d), "
+#if CONFIG_ADAPTIVE_HR
+          "AdaptiveHighRange (%d), "
+#endif  // CONFIG_ADAPTIVE_HR
 #if CONFIG_IBC_SR_EXT
           "IntraBCExt (%d), "
 #endif  // CONFIG_IBC_SR_EXT
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 68cf339..e873331 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -1459,6 +1459,7 @@
   tool_cfg->enable_short_refresh_frame_flags =
       extra_cfg->enable_short_refresh_frame_flags;
 #endif  // CONFIG_REFRESH_FLAG
+
   // Set Quantization related configuration.
   q_cfg->using_qm = extra_cfg->enable_qm;
   q_cfg->qm_minlevel = extra_cfg->qm_min;
diff --git a/av1/common/entropy.c b/av1/common/entropy.c
index f43adad..c607734 100644
--- a/av1/common/entropy.c
+++ b/av1/common/entropy.c
@@ -63,14 +63,18 @@
            av1_default_coeff_base_lf_multi_cdfs[index]);
   av1_copy(cm->fc->coeff_base_lf_eob_cdf,
            av1_default_coeff_base_lf_eob_multi_cdfs[index]);
+#if !CONFIG_ADAPTIVE_HR
   av1_copy(cm->fc->coeff_br_lf_cdf, av1_default_coeff_lps_lf_multi_cdfs[index]);
   av1_copy(cm->fc->coeff_br_cdf, av1_default_coeff_lps_multi_cdfs[index]);
+#endif  // !CONFIG_ADAPTIVE_HR
   av1_copy(cm->fc->coeff_base_cdf, av1_default_coeff_base_multi_cdfs[index]);
   av1_copy(cm->fc->idtx_sign_cdf, av1_default_idtx_sign_cdfs[index]);
   av1_copy(cm->fc->coeff_base_cdf_idtx,
            av1_default_coeff_base_multi_cdfs_idtx[index]);
+#if !CONFIG_ADAPTIVE_HR
   av1_copy(cm->fc->coeff_br_cdf_idtx,
            av1_default_coeff_lps_multi_cdfs_idtx[index]);
+#endif  // !CONFIG_ADAPTIVE_HR
   av1_copy(cm->fc->coeff_base_eob_cdf,
            av1_default_coeff_base_eob_multi_cdfs[index]);
   av1_copy(cm->fc->eob_flag_cdf16, av1_default_eob_multi16_cdfs[index]);
@@ -81,7 +85,9 @@
   av1_copy(cm->fc->eob_flag_cdf512, av1_default_eob_multi512_cdfs[index]);
   av1_copy(cm->fc->eob_flag_cdf1024, av1_default_eob_multi1024_cdfs[index]);
   av1_copy(cm->fc->coeff_base_ph_cdf, av1_default_coeff_base_ph_cdfs[index]);
+#if !CONFIG_ADAPTIVE_HR
   av1_copy(cm->fc->coeff_br_ph_cdf, av1_default_coeff_br_ph_cdfs[index]);
+#endif  // !CONFIG_ADAPTIVE_HR
   av1_copy(cm->fc->coeff_base_bob_cdf,
            av1_default_coeff_base_bob_multi_cdfs[index]);
 }
@@ -149,12 +155,16 @@
   RESET_CDF_COUNTER(fc->coeff_base_bob_cdf, 3);
   RESET_CDF_COUNTER(fc->coeff_base_lf_cdf, LF_BASE_SYMBOLS);
   RESET_CDF_COUNTER(fc->coeff_base_lf_eob_cdf, LF_BASE_SYMBOLS - 1);
+#if !CONFIG_ADAPTIVE_HR
   RESET_CDF_COUNTER(fc->coeff_br_lf_cdf, BR_CDF_SIZE);
+#endif  // !CONFIG_ADAPTIVE_HR
   RESET_CDF_COUNTER(fc->coeff_base_cdf, 4);
   RESET_CDF_COUNTER(fc->idtx_sign_cdf, 2);
   RESET_CDF_COUNTER(fc->coeff_base_cdf_idtx, 4);
+#if !CONFIG_ADAPTIVE_HR
   RESET_CDF_COUNTER(fc->coeff_br_cdf_idtx, BR_CDF_SIZE);
   RESET_CDF_COUNTER(fc->coeff_br_cdf, BR_CDF_SIZE);
+#endif  // !CONFIG_ADAPTIVE_HR
   RESET_CDF_COUNTER(fc->inter_single_mode_cdf, INTER_SINGLE_MODES);
 #if CONFIG_EXTENDED_WARP_PREDICTION
   RESET_CDF_COUNTER(fc->inter_warp_mode_cdf, 2);
@@ -436,6 +446,8 @@
   }
 
   RESET_CDF_COUNTER(fc->coeff_base_ph_cdf, NUM_BASE_LEVELS + 2);
+#if !CONFIG_ADAPTIVE_HR
   RESET_CDF_COUNTER(fc->coeff_br_ph_cdf, BR_CDF_SIZE);
+#endif  // !CONFIG_ADAPTIVE_HR
   RESET_CDF_COUNTER(fc->cctx_type_cdf, CCTX_TYPES);
 }
diff --git a/av1/common/entropy.h b/av1/common/entropy.h
index d84c233..0efcca2 100644
--- a/av1/common/entropy.h
+++ b/av1/common/entropy.h
@@ -83,7 +83,7 @@
 #define NUM_BASE_LEVELS 2
 
 #if CONFIG_ADAPTIVE_HR
-#define BR_NUM_ITERATIONS 1
+#define BR_NUM_ITERATIONS 0
 #else
 #define BR_NUM_ITERATIONS 4
 #endif  // CONFIG_ADAPTIVE_HR
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index 8536f22..d8497b4 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -199,18 +199,24 @@
                              [CDF_SIZE(4)];
   aom_cdf_prob idtx_sign_cdf[IDTX_SIGN_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob coeff_base_cdf_idtx[IDTX_SIG_COEF_CONTEXTS][CDF_SIZE(4)];
+#if !CONFIG_ADAPTIVE_HR
   aom_cdf_prob coeff_br_cdf_idtx[IDTX_LEVEL_CONTEXTS][CDF_SIZE(BR_CDF_SIZE)];
+#endif  // !CONFIG_ADAPTIVE_HR
   aom_cdf_prob coeff_base_lf_cdf[TX_SIZES][PLANE_TYPES][LF_SIG_COEF_CONTEXTS]
                                 [CDF_SIZE(LF_BASE_SYMBOLS)];
   aom_cdf_prob coeff_base_lf_eob_cdf[TX_SIZES][PLANE_TYPES]
                                     [SIG_COEF_CONTEXTS_EOB]
                                     [CDF_SIZE(LF_BASE_SYMBOLS - 1)];
+#if !CONFIG_ADAPTIVE_HR
   aom_cdf_prob coeff_br_lf_cdf[PLANE_TYPES][LF_LEVEL_CONTEXTS]
                               [CDF_SIZE(BR_CDF_SIZE)];
   aom_cdf_prob coeff_br_cdf[PLANE_TYPES][LEVEL_CONTEXTS][CDF_SIZE(BR_CDF_SIZE)];
+#endif // !CONFIG_ADAPTIVE_HR
   aom_cdf_prob coeff_base_ph_cdf[COEFF_BASE_PH_CONTEXTS]
                                 [CDF_SIZE(NUM_BASE_LEVELS + 2)];
+#if !CONFIG_ADAPTIVE_HR
   aom_cdf_prob coeff_br_ph_cdf[COEFF_BR_PH_CONTEXTS][CDF_SIZE(BR_CDF_SIZE)];
+#endif  // !CONFIG_ADAPTIVE_HR
 
   aom_cdf_prob inter_single_mode_cdf[INTER_SINGLE_MODE_CONTEXTS]
                                     [CDF_SIZE(INTER_SINGLE_MODES)];
diff --git a/av1/common/hr_coding.c b/av1/common/hr_coding.c
index 6fb9673..4279c6a 100644
--- a/av1/common/hr_coding.c
+++ b/av1/common/hr_coding.c
@@ -64,13 +64,13 @@
 
 #if CONFIG_ADAPTIVE_HR
 
-static int adaptive_table[] = { 10, 20, 40, 75, 135 };
+static const int adaptive_table[] = { 5, 10, 15, 35, 70, 135 };
+static const int table_size = sizeof(adaptive_table) / sizeof(int);
 
 static int get_adaptive_param(int ctx) {
-  const int table_size = sizeof(adaptive_table) / sizeof(int);
   int m = 0;
-  while (m < table_size && ctx >= adaptive_table[m]) ++m;
-  return m + 1;
+  while (m < table_size && ctx > adaptive_table[m]) ++m;
+  return m;
 }
 
 void write_truncated_rice(aom_writer *w, int level, int m, int k, int cmax) {
@@ -81,8 +81,7 @@
     write_exp_golomb(w, level - (cmax << m), k);
   } else {
     const int mask = (1 << m) - 1;
-    aom_write_literal(w, 0, q);
-    aom_write_literal(w, 1, 1);
+    aom_write_literal(w, 1, q + 1);
     aom_write_literal(w, level & mask, m);
   }
 }
diff --git a/av1/common/txb_common.h b/av1/common/txb_common.h
index c35cce4..92c2a16 100644
--- a/av1/common/txb_common.h
+++ b/av1/common/txb_common.h
@@ -270,12 +270,12 @@
   int mag;
   // Note: AOMMIN(level, 5) is useless for decoder since level < 5.
 
-  mag = clip_max5[levels[1]];                         // { 0, 1 }
-  mag += clip_max5[levels[(1 << bwl) + TX_PAD_HOR]];  // { 1, 0 }
+  mag = clip_max3[levels[1]];                         // { 0, 1 }
+  mag += clip_max3[levels[(1 << bwl) + TX_PAD_HOR]];  // { 1, 0 }
   if (tx_class == TX_CLASS_2D) {
-    mag += clip_max5[levels[(1 << bwl) + TX_PAD_HOR + 1]];          // { 1, 1 }
-    mag += clip_max5[levels[2]];                                    // { 0, 2 }
-    mag += clip_max5[levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)]];  // { 2, 0 }
+    mag += clip_max3[levels[(1 << bwl) + TX_PAD_HOR + 1]];          // { 1, 1 }
+    mag += clip_max3[levels[2]];                                    // { 0, 2 }
+    mag += clip_max3[levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)]];  // { 2, 0 }
   } else if (tx_class == TX_CLASS_VERT) {
     mag += clip_max3[levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)]];  // { 2, 0 }
     mag += clip_max3[levels[(3 << bwl) + (3 << TX_PAD_HOR_LOG2)]];  // { 3, 0 }
@@ -524,11 +524,11 @@
   int mag;
   // Note: AOMMIN(level, 3) is useless for decoder since level < 5.
   levels = levels + get_padded_idx(coeff_idx, bwl);
-  mag = AOMMIN(levels[1], 5);                                     // { 0, 1 }
-  mag += AOMMIN(levels[(1 << bwl) + TX_PAD_HOR], 5);              // { 1, 0 }
-  mag += AOMMIN(levels[(1 << bwl) + TX_PAD_HOR + 1], 5);          // { 1, 1 }
-  mag += AOMMIN(levels[2], 5);                                    // { 0, 2 }
-  mag += AOMMIN(levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)], 5);  // { 2, 0 }
+  mag = AOMMIN(levels[1], 3);                                     // { 0, 1 }
+  mag += AOMMIN(levels[(1 << bwl) + TX_PAD_HOR], 3);              // { 1, 0 }
+  mag += AOMMIN(levels[(1 << bwl) + TX_PAD_HOR + 1], 3);          // { 1, 1 }
+  mag += AOMMIN(levels[2], 3);                                    // { 0, 2 }
+  mag += AOMMIN(levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)], 3);  // { 2, 0 }
   int ctx = (mag + 1) >> 1;
   const int row = coeff_idx >> bwl;
   const int col = coeff_idx - (row << bwl);
diff --git a/av1/decoder/decodetxb.c b/av1/decoder/decodetxb.c
index 4c5edb2..19974d6 100644
--- a/av1/decoder/decodetxb.c
+++ b/av1/decoder/decodetxb.c
@@ -52,6 +52,8 @@
       const int coeff_ctx = get_lower_levels_ctx_lf_2d(levels, pos, bwl);
       level += aom_read_symbol(r, base_lf_cdf[coeff_ctx], LF_BASE_SYMBOLS,
                                ACCT_INFO("level", "base_lf_cdf"));
+
+#if !CONFIG_ADAPTIVE_HR
       if (level > LF_NUM_BASE_LEVELS) {
         const int br_ctx = get_br_lf_ctx_2d(levels, pos, bwl);
         aom_cdf_prob *cdf = br_lf_cdf[br_ctx];
@@ -62,6 +64,7 @@
           if (k < BR_CDF_SIZE - 1) break;
         }
       }
+#endif // !CONFIG_ADAPTIVE_HR
     } else {
       const int coeff_ctx = get_lower_levels_ctx_2d(levels, pos, bwl
 #if CONFIG_CHROMA_TX_COEFF_CODING
@@ -71,6 +74,8 @@
       );
       level += aom_read_symbol(r, base_cdf[coeff_ctx], 4,
                                ACCT_INFO("level", "base_cdf"));
+
+#if !CONFIG_ADAPTIVE_HR
       if (level > NUM_BASE_LEVELS) {
         const int br_ctx = get_br_ctx_2d(levels, pos, bwl);
         aom_cdf_prob *cdf = br_cdf[br_ctx];
@@ -81,6 +86,7 @@
           if (k < BR_CDF_SIZE - 1) break;
         }
       }
+#endif // !CONFIG_ADAPTIVE_HR
     }
     levels[get_padded_idx(pos, bwl)] = level;
   }
@@ -100,6 +106,8 @@
       const int coeff_ctx = get_lower_levels_lf_ctx(levels, pos, bwl, tx_class);
       level += aom_read_symbol(r, base_lf_cdf[coeff_ctx], LF_BASE_SYMBOLS,
                                ACCT_INFO("level", "base_lf_cdf"));
+
+#if !CONFIG_ADAPTIVE_HR
       if (level > LF_NUM_BASE_LEVELS) {
         const int br_ctx = get_br_lf_ctx(levels, pos, bwl, tx_class);
         aom_cdf_prob *cdf = br_lf_cdf[br_ctx];
@@ -110,6 +118,7 @@
           if (k < BR_CDF_SIZE - 1) break;
         }
       }
+#endif // !CONFIG_ADAPTIVE_HR
     } else {
       const int coeff_ctx = get_lower_levels_ctx(levels, pos, bwl, tx_class
 #if CONFIG_CHROMA_TX_COEFF_CODING
@@ -119,6 +128,8 @@
       );
       level += aom_read_symbol(r, base_cdf[coeff_ctx], 4,
                                ACCT_INFO("level", "base_cdf"));
+
+#if !CONFIG_ADAPTIVE_HR
       if (level > NUM_BASE_LEVELS) {
         const int br_ctx = get_br_ctx(levels, pos, bwl, tx_class);
         aom_cdf_prob *cdf = br_cdf[br_ctx];
@@ -129,6 +140,7 @@
           if (k < BR_CDF_SIZE - 1) break;
         }
       }
+#endif // !CONFIG_ADAPTIVE_HR
     }
     levels[get_padded_idx(pos, bwl)] = level;
   }
@@ -145,6 +157,8 @@
     const int nsymbs = 4;
     int level = aom_read_symbol(r, base_cdf[coeff_ctx], nsymbs,
                                 ACCT_INFO("level", "base_cdf"));
+
+#if !CONFIG_ADAPTIVE_HR
     if (level > NUM_BASE_LEVELS) {
       const int br_ctx = get_br_ctx_skip(levels, pos, bwl);
       aom_cdf_prob *cdf = br_cdf[br_ctx];
@@ -155,6 +169,7 @@
         if (k < BR_CDF_SIZE - 1) break;
       }
     }
+#endif // !CONFIG_ADAPTIVE_HR
     levels[get_padded_idx_left(pos, bwl)] = level;
   }
 }
@@ -417,7 +432,11 @@
     memset(levels_buf, 0, sizeof(*levels_buf) * TX_PAD_2D);
     memset(signs_buf, 0, sizeof(*signs_buf) * TX_PAD_2D);
     base_cdf_arr base_cdf = ec_ctx->coeff_base_cdf_idtx;
+#if !CONFIG_ADAPTIVE_HR
     br_cdf_arr br_cdf = ec_ctx->coeff_br_cdf_idtx;
+#else
+    br_cdf_arr br_cdf;
+#endif  // !CONFIG_ADAPTIVE_HR
     const int bob = av1_get_max_eob(tx_size) - bob_data->eob;
     {
       const int pos = scan[bob];
@@ -427,6 +446,8 @@
       int level = aom_read_symbol(r, cdf_bob, nsymbs_bob,
                                   ACCT_INFO("level", "cdf_bob")) +
                   1;
+
+#if !CONFIG_ADAPTIVE_HR
       if (level > NUM_BASE_LEVELS) {
         const int br_ctx = get_br_ctx_skip(levels, pos, bwl);
         aom_cdf_prob *cdf = br_cdf[br_ctx];
@@ -437,6 +458,7 @@
           if (k < BR_CDF_SIZE - 1) break;
         }
       }
+#endif  // !CONFIG_ADAPTIVE_HR
       levels[get_padded_idx_left(pos, bwl)] = level;
     }
     read_coeffs_forward_2d(r, bob + 1, eob_data->eob - 1, scan, bwl, levels,
@@ -505,6 +527,7 @@
   int ctx_idx = get_base_ctx_ph(levels, pos, bwl, tx_class);
   q_index = aom_read_symbol(r, base_cdf_ph[ctx_idx], 4, ACCT_INFO("q_index"));
 
+#if !CONFIG_ADAPTIVE_HR
   if (q_index > NUM_BASE_LEVELS) {
     ctx_idx = get_par_br_ctx(levels, pos, bwl, tx_class);
     aom_cdf_prob *cdf_br = br_cdf_ph[ctx_idx];
@@ -515,6 +538,8 @@
       if (k < BR_CDF_SIZE - 1) break;
     }
   }
+
+#endif  // !CONFIG_ADAPTIVE_HR
   assert(q_index <= MAX_BASE_BR_RANGE);
   uint8_t level = (q_index << 1) + parity;
   levels[get_padded_idx(pos, bwl)] = level;
@@ -611,6 +636,8 @@
       level += aom_read_symbol(r, cdf, LF_BASE_SYMBOLS - 1,
                                ACCT_INFO("level", "coeff_base_lf_eob_cdf")) +
                1;
+
+#if !CONFIG_ADAPTIVE_HR
       if (level > LF_NUM_BASE_LEVELS) {
         const int br_ctx = get_br_ctx_lf_eob(pos, tx_class);
         cdf = ec_ctx->coeff_br_lf_cdf[plane_type][br_ctx];
@@ -621,12 +648,15 @@
           if (k < BR_CDF_SIZE - 1) break;
         }
       }
+#endif  // !CONFIG_ADAPTIVE_HR
     } else {
       aom_cdf_prob *cdf =
           ec_ctx->coeff_base_eob_cdf[txs_ctx][plane_type][coeff_ctx];
       level +=
           aom_read_symbol(r, cdf, 3, ACCT_INFO("level", "coeff_base_eob_cdf")) +
           1;
+
+#if !CONFIG_ADAPTIVE_HR
       if (level > NUM_BASE_LEVELS) {
         const int br_ctx = 0; /* get_lf_ctx_eob */
         cdf = ec_ctx->coeff_br_cdf[plane_type][br_ctx];
@@ -637,6 +667,7 @@
           if (k < BR_CDF_SIZE - 1) break;
         }
       }
+#endif  // !CONFIG_ADAPTIVE_HR
     }
     levels[get_padded_idx(pos, bwl)] = level;
   }
@@ -648,9 +679,14 @@
   if (*eob > 1) {
     base_lf_cdf_arr base_lf_cdf =
         ec_ctx->coeff_base_lf_cdf[txs_ctx][plane_type];
-    br_cdf_arr br_lf_cdf = ec_ctx->coeff_br_lf_cdf[plane_type];
     base_cdf_arr base_cdf = ec_ctx->coeff_base_cdf[txs_ctx][plane_type];
+#if !CONFIG_ADAPTIVE_HR
+    br_cdf_arr br_lf_cdf = ec_ctx->coeff_br_lf_cdf[plane_type];
     br_cdf_arr br_cdf = ec_ctx->coeff_br_cdf[plane_type];
+#else
+    br_cdf_arr br_lf_cdf = NULL;
+    br_cdf_arr br_cdf = NULL;
+#endif  // !CONFIG_ADAPTIVE_HR
 
     if (tx_class == TX_CLASS_2D) {
       read_coeffs_reverse_2d(r, 1, *eob - 2, scan, bwl, levels, base_lf_cdf,
@@ -669,7 +705,13 @@
       }
       if (is_hidden) {
         read_coeff_hidden(r, tx_class, scan, bwl, levels, (sum_abs1 & 1),
-                          ec_ctx->coeff_base_ph_cdf, ec_ctx->coeff_br_ph_cdf);
+                          ec_ctx->coeff_base_ph_cdf
+#if !CONFIG_ADAPTIVE_HR
+                          , ec_ctx->coeff_br_ph_cdf
+#else
+                          , NULL
+#endif  // !CONFIG_ADAPTIVE_HR
+                          );
       } else {
         read_coeffs_reverse(r, tx_class, 0, 0, scan, bwl, levels, base_lf_cdf,
                             br_lf_cdf, plane, base_cdf, br_cdf);
@@ -691,7 +733,13 @@
       }
       if (is_hidden) {
         read_coeff_hidden(r, tx_class, scan, bwl, levels, (sum_abs1 & 1),
-                          ec_ctx->coeff_base_ph_cdf, ec_ctx->coeff_br_ph_cdf);
+                          ec_ctx->coeff_base_ph_cdf
+#if !CONFIG_ADAPTIVE_HR
+                          , ec_ctx->coeff_br_ph_cdf
+#else
+                          , NULL
+#endif  // !CONFIG_ADAPTIVE_HR
+                          );
       } else {
         read_coeffs_reverse(r, tx_class, 0, 0, scan, bwl, levels, base_lf_cdf,
                             br_lf_cdf, plane, base_cdf, br_cdf);
diff --git a/av1/encoder/encodeframe_utils.c b/av1/encoder/encodeframe_utils.c
index 5c1a663..87b88d2 100644
--- a/av1/encoder/encodeframe_utils.c
+++ b/av1/encoder/encodeframe_utils.c
@@ -1300,13 +1300,17 @@
               LF_BASE_SYMBOLS);
   AVERAGE_CDF(ctx_left->coeff_base_lf_eob_cdf, ctx_tr->coeff_base_lf_eob_cdf,
               LF_BASE_SYMBOLS - 1);
+#if !CONFIG_ADAPTIVE_HR
   AVERAGE_CDF(ctx_left->coeff_br_lf_cdf, ctx_tr->coeff_br_lf_cdf, BR_CDF_SIZE);
+#endif  // !CONFIG_ADAPTIVE_HR
   AVERAGE_CDF(ctx_left->coeff_base_cdf, ctx_tr->coeff_base_cdf, 4);
   AVERAGE_CDF(ctx_left->idtx_sign_cdf, ctx_tr->idtx_sign_cdf, 2);
   AVERAGE_CDF(ctx_left->coeff_base_cdf_idtx, ctx_tr->coeff_base_cdf_idtx, 4);
+#if !CONFIG_ADAPTIVE_HR
   AVERAGE_CDF(ctx_left->coeff_br_cdf_idtx, ctx_tr->coeff_br_cdf_idtx,
               BR_CDF_SIZE);
   AVERAGE_CDF(ctx_left->coeff_br_cdf, ctx_tr->coeff_br_cdf, BR_CDF_SIZE);
+#endif  // !CONFIG_ADAPTIVE_HR
   AVERAGE_CDF(ctx_left->inter_single_mode_cdf, ctx_tr->inter_single_mode_cdf,
               INTER_SINGLE_MODES);
 
@@ -1631,7 +1635,9 @@
   }
 
   AVERAGE_CDF(ctx_left->coeff_base_ph_cdf, ctx_tr->coeff_base_ph_cdf, 4);
+#if !CONFIG_ADAPTIVE_HR
   AVERAGE_CDF(ctx_left->coeff_br_ph_cdf, ctx_tr->coeff_br_ph_cdf, 4);
+#endif  // !CONFIG_ADAPTIVE_HR
   AVERAGE_CDF(ctx_left->cctx_type_cdf, ctx_tr->cctx_type_cdf, CCTX_TYPES);
 }
 
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c
index b7a2ce8..653fbea 100644
--- a/av1/encoder/encodetxb.c
+++ b/av1/encoder/encodetxb.c
@@ -771,6 +771,8 @@
       aom_write_symbol(w, AOMMIN(level, 3),
                        ec_ctx->coeff_base_cdf_idtx[coeff_ctx], 4);
     }
+
+#if !CONFIG_ADAPTIVE_HR
     if (level > NUM_BASE_LEVELS) {
       // level is above 1.
       const int base_range = level - 1 - NUM_BASE_LEVELS;
@@ -782,6 +784,7 @@
         if (k < BR_CDF_SIZE - 1) break;
       }
     }
+#endif // !CONFIG_ADAPTIVE_HR
   }
   // Loop to code all signs, bypass levels in the transform block
   for (int c = eob - 1; c >= 0; --c) {
@@ -817,6 +820,7 @@
   int ctx_id = get_base_ctx_ph(levels, pos, bwl, tx_class);
   aom_write_symbol(w, AOMMIN(q_index, 3), base_cdf_ph[ctx_id], 4);
 
+#if !CONFIG_ADAPTIVE_HR
   if (q_index > NUM_BASE_LEVELS) {
     ctx_id = get_par_br_ctx(levels, pos, bwl, tx_class);
     aom_cdf_prob *cdf_br = br_cdf_ph[ctx_id];
@@ -827,6 +831,7 @@
       if (k < BR_CDF_SIZE - 1) break;
     }
   }
+#endif  // !CONFIG_ADAPTIVE_HR
 }
 
 void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *const x,
@@ -895,7 +900,6 @@
                           plane);
 
   const int bwl = get_txb_bwl(tx_size);
-
   bool enable_parity_hiding = cm->features.allow_parity_hiding &&
                               !xd->lossless[xd->mi[0]->segment_id] &&
                               plane == PLANE_TYPE_Y &&
@@ -939,6 +943,7 @@
     const int row = pos >> bwl;
     const int col = pos - (row << bwl);
     int limits = get_lf_limits(row, col, tx_class, plane);
+#if !CONFIG_ADAPTIVE_HR
     if (limits) {
       if (level > LF_NUM_BASE_LEVELS) {
         const int base_range =
@@ -963,6 +968,7 @@
         }
       }
     }
+#endif // !CONFIG_ADAPTIVE_HR
   }
 
   int num_nz = 0;
@@ -979,7 +985,13 @@
     const tran_low_t v = tcoeff[pos];
     const tran_low_t level = abs(v);
     write_coeff_hidden(w, tx_class, scan, bwl, levels, level,
-                       ec_ctx->coeff_base_ph_cdf, ec_ctx->coeff_br_ph_cdf);
+                       ec_ctx->coeff_base_ph_cdf
+#if !CONFIG_ADAPTIVE_HR
+                       , ec_ctx->coeff_br_ph_cdf
+                       #else
+                       , NULL
+                       #endif  // !CONFIG_ADAPTIVE_HR
+                       );
   } else {
     const int c = 0;
     const int pos = scan[c];
@@ -1020,6 +1032,7 @@
     const int row = pos >> bwl;
     const int col = pos - (row << bwl);
     int limits = get_lf_limits(row, col, tx_class, plane);
+#if !CONFIG_ADAPTIVE_HR
     if (limits) {
       if (level > LF_NUM_BASE_LEVELS) {
         const int base_range =
@@ -1044,6 +1057,7 @@
         }
       }
     }
+#endif // !CONFIG_ADAPTIVE_HR
   }
 
 #if DEBUG_EXTQUANT
@@ -2100,7 +2114,12 @@
                                      int32_t *tmp_sign
 #endif  // CONFIG_CONTEXT_DERIVATION
                                      ,
-                                     int plane) {
+                                     int plane
+#if CONFIG_ADAPTIVE_HR
+                                     ,
+                                     const uint8_t *levels
+#endif  // CONFIG_ADAPTIVE_HR
+) {
   int cost = 0;
   const int row = ci >> bwl;
   const int col = ci - (row << bwl);
@@ -2557,7 +2576,12 @@
                                           tmp_sign
 #endif  // CONFIG_CONTEXT_DERIVATION
                                           ,
-                                          plane);
+                                          plane
+#if CONFIG_ADAPTIVE_HR
+                                          ,
+                                          levels
+#endif  // CONFIG_ADAPTIVE_HR
+                       );
     int64_t dist_new_eob = dist;
     int64_t rd_new_eob = RDCOST(rdmult, rate_coeff_eob, dist_new_eob);
     int rateeobup = rate_coeff_eob;
@@ -2572,7 +2596,12 @@
                                             tmp_sign
 #endif  // CONFIG_CONTEXT_DERIVATION
                                             ,
-                                            plane);
+                                            plane
+#if CONFIG_ADAPTIVE_HR
+                                            ,
+                                            levels
+#endif  // CONFIG_ADAPTIVE_HR
+                         );
       const int64_t dist_new_eob_low = dist_low;
       const int64_t rd_new_eob_low =
           RDCOST(rdmult, rate_coeff_eob_low, dist_new_eob_low);
@@ -3091,7 +3120,12 @@
                            xd->tmp_sign
 #endif  // CONFIG_CONTEXT_DERIVATION
                            ,
-                           plane);
+                           plane
+#if CONFIG_ADAPTIVE_HR
+                           ,
+                           levels
+#endif  // CONFIG_ADAPTIVE_HR
+        );
     const tran_low_t tqc = tcoeff[ci];
     const tran_low_t dqc = dqcoeff[ci];
     const int64_t dist = get_coeff_dist(tqc, dqc, shift);
@@ -3122,8 +3156,7 @@
   for (; si >= 1; --si) {
     update_coeff_simple(&accu_rate, si, eob, tx_class, bwl, rdmult, shift,
                         dequant, scan, txb_costs, tcoeff, qcoeff, dqcoeff,
-                        levels, iqmatrix, coef_info, enable_parity_hiding,
-                        plane);
+                        levels, iqmatrix, coef_info, enable_parity_hiding, plane);
   }
 
   // DC position
@@ -3480,6 +3513,7 @@
               ->coeff_base_multi_skip[cdf_idx][coeff_ctx][AOMMIN(level, 3)];
       }
 #endif
+#if !CONFIG_ADAPTIVE_HR
       if (level > NUM_BASE_LEVELS) {
         const int base_range = level - 1 - NUM_BASE_LEVELS;
         const int br_ctx = get_br_ctx_skip(levels, pos, bwl);
@@ -3500,6 +3534,7 @@
           if (k < BR_CDF_SIZE - 1) break;
         }
       }
+#endif  // !CONFIG_ADAPTIVE_HR
     }
     for (int c = eob - 1; c >= 0; --c) {
       const int pos = scan[c];
@@ -3540,6 +3575,7 @@
   ++td->counts->coeff_base_ph_multi[cdf_idx][coeff_ctx][AOMMIN(level, 3)];
 #endif  // CONFIG_ENTROPY_STATS
 
+#if !CONFIG_ADAPTIVE_HR
   if (q_index > NUM_BASE_LEVELS) {
     int br_ctx = get_par_br_ctx(levels, pos, bwl, tx_class);
     aom_cdf_prob *cdf_br = br_cdf_ph[br_ctx];
@@ -3559,6 +3595,7 @@
       if (k < BR_CDF_SIZE - 1) break;
     }
   }
+#endif  // !CONFIG_ADAPTIVE_HR
 }
 void av1_update_and_record_txb_context(int plane, int block, int blk_row,
                                        int blk_col, BLOCK_SIZE plane_bsize,
@@ -3796,6 +3833,7 @@
       const int row = pos >> bwl;
       const int col = pos - (row << bwl);
       int limits = get_lf_limits(row, col, tx_class, plane);
+#if !CONFIG_ADAPTIVE_HR
       if (limits) {
         if (level > LF_NUM_BASE_LEVELS) {
           const int base_range = level - 1 - LF_NUM_BASE_LEVELS;
@@ -3842,6 +3880,7 @@
           }
         }
       }
+#endif  // !CONFIG_ADAPTIVE_HR
     }
 
     bool is_hidden = false;
@@ -3856,7 +3895,11 @@
         const int level = abs(qcoeff[scan[0]]);
         update_coeff_ctx_hiden(tx_class, scan, bwl, levels, level,
                                ec_ctx->coeff_base_ph_cdf,
+#if !CONFIG_ADAPTIVE_HR
                                ec_ctx->coeff_br_ph_cdf
+#else
+                               NULL
+#endif  // !CONFIG_ADAPTIVE_HR
 #if CONFIG_ENTROPY_STATS
                                ,
                                td, cdf_idx
@@ -3932,6 +3975,7 @@
       const int row = pos >> bwl;
       const int col = pos - (row << bwl);
       int limits = get_lf_limits(row, col, tx_class, plane);
+#if !CONFIG_ADAPTIVE_HR
       if (limits) {
         if (level > LF_NUM_BASE_LEVELS) {
           const int base_range = level - 1 - LF_NUM_BASE_LEVELS;
@@ -3978,6 +4022,7 @@
           }
         }
       }
+#endif  // !CONFIG_ADAPTIVE_HR
     }
 
     // Update the context needed to code the DC sign (if applicable)
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 218b323..e3f114e 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -1105,8 +1105,11 @@
         int br_lf_rate[BR_CDF_SIZE];
         int prev_cost_lf = 0;
         int i, j;
+
+#if !CONFIG_ADAPTIVE_HR
         av1_cost_tokens_from_cdf(br_lf_rate, fc->coeff_br_lf_cdf[plane][ctx],
                                  NULL);
+#endif  // !CONFIG_ADAPTIVE_HR
         for (i = 0; i < COEFF_BASE_RANGE; i += BR_CDF_SIZE - 1) {
           for (j = 0; j < BR_CDF_SIZE - 1; j++) {
             pcost->lps_lf_cost[ctx][i + j] = prev_cost_lf + br_lf_rate[j];
@@ -1127,7 +1130,9 @@
         int br_rate[BR_CDF_SIZE];
         int prev_cost = 0;
         int i, j;
+#if !CONFIG_ADAPTIVE_HR
         av1_cost_tokens_from_cdf(br_rate, fc->coeff_br_cdf[plane][ctx], NULL);
+#endif  // !CONFIG_ADAPTIVE_HR
         // printf("br_rate: ");
         // for(j = 0; j < BR_CDF_SIZE; j++)
         //  printf("%4d ", br_rate[j]);
@@ -1178,7 +1183,9 @@
       int br_rate_skip[BR_CDF_SIZE];
       int prev_cost_skip = 0;
       int i, j;
+#if !CONFIG_ADAPTIVE_HR
       av1_cost_tokens_from_cdf(br_rate_skip, fc->coeff_br_cdf_idtx[ctx], NULL);
+#endif  // !CONFIG_ADAPTIVE_HR
       for (i = 0; i < COEFF_BASE_RANGE; i += BR_CDF_SIZE - 1) {
         for (j = 0; j < BR_CDF_SIZE - 1; j++) {
           pcost->lps_cost_skip[ctx][i + j] = prev_cost_skip + br_rate_skip[j];
@@ -1209,7 +1216,9 @@
     int br_ph_rate[BR_CDF_SIZE];
     int prev_cost = 0;
     int i, j;
+#if !CONFIG_ADAPTIVE_HR
     av1_cost_tokens_from_cdf(br_ph_rate, fc->coeff_br_ph_cdf[ctx], NULL);
+#endif  // !CONFIG_ADAPTIVE_HR
     for (i = 0; i < COEFF_BASE_RANGE; i += BR_CDF_SIZE - 1) {
       for (j = 0; j < BR_CDF_SIZE - 1; j++) {
         pcost->lps_ph_cost[ctx][i + j] = prev_cost + br_ph_rate[j];
diff --git a/tools/aom_entropy_optimizer.c b/tools/aom_entropy_optimizer.c
index 4a37aaf..7b7bf2c 100644
--- a/tools/aom_entropy_optimizer.c
+++ b/tools/aom_entropy_optimizer.c
@@ -1901,6 +1901,7 @@
                      "BASE_PH_CONTEXTS][CDF_SIZE(NUM_BASE_LEVELS + 2)]",
                      1, &total_count, 0, mem_wanted, "Coefficients");
 
+#if !CONFIG_ADAPTIVE_HR
   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
   cts_each_dim[1] = COEFF_BR_PH_CONTEXTS;
   cts_each_dim[2] = BR_CDF_SIZE;
@@ -1910,6 +1911,7 @@
                      "av1_default_coeff_br_ph_cdfs[TOKEN_CDF_Q_CTXS][COEFF_BR_"
                      "PH_CONTEXTS][CDF_SIZE(BR_CDF_SIZE)]",
                      1, &total_count, 0, mem_wanted, "Coefficients");
+#endif  // !CONFIG_ADAPTIVE_HR
 
   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
   cts_each_dim[1] = TX_SIZES;
@@ -1936,6 +1938,7 @@
       "[CDF_SIZE(LF_BASE_SYMBOLS - 1)]",
       1, &total_count, 0, mem_wanted, "Coefficients");
 
+#if !CONFIG_ADAPTIVE_HR
   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
   cts_each_dim[1] = PLANE_TYPES;
   cts_each_dim[2] = LF_LEVEL_CONTEXTS;
@@ -1959,6 +1962,7 @@
                      "[PLANE_TYPES][LEVEL_CONTEXTS]"
                      "[CDF_SIZE(BR_CDF_SIZE)]",
                      1, &total_count, 0, mem_wanted, "Coefficients");
+#endif  // !CONFIG_ADAPTIVE_HR
 
   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
   cts_each_dim[1] = TX_SIZES;
@@ -1972,6 +1976,7 @@
       "[CDF_SIZE(NUM_BASE_LEVELS + 2)]",
       1, &total_count, 0, mem_wanted, "Coefficients");
 
+#if !CONFIG_ADAPTIVE_HR
   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
   cts_each_dim[1] = IDTX_LEVEL_CONTEXTS;
   cts_each_dim[2] = BR_CDF_SIZE;
@@ -1982,6 +1987,8 @@
                      "[TOKEN_CDF_Q_CTXS][IDTX_LEVEL_CONTEXTS]"
                      "[CDF_SIZE(BR_CDF_SIZE)]",
                      1, &total_count, 0, mem_wanted, "Coefficients");
+#endif  // !CONFIG_ADAPTIVE_HR
+
   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
   cts_each_dim[1] = IDTX_SIG_COEF_CONTEXTS;
   cts_each_dim[2] = NUM_BASE_LEVELS + 2;