Remove experimental flag of LV_MAP

This experiment has been adopted, we can simplify the code
by dropping the associated preprocessor conditionals.

Change-Id: Ic3438799335c6cd05f170302f49bd47e1f705c24
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 5b8dee0..050f8c0 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -42,9 +42,7 @@
 #include "av1/encoder/bitstream.h"
 #include "av1/encoder/cost.h"
 #include "av1/encoder/encodemv.h"
-#if CONFIG_LV_MAP
 #include "av1/encoder/encodetxb.h"
-#endif  // CONFIG_LV_MAP
 #include "av1/encoder/mcomp.h"
 #include "av1/encoder/palette.h"
 #include "av1/encoder/segmentation.h"
@@ -385,79 +383,6 @@
   *tp = p;
 }
 
-#if !CONFIG_LV_MAP
-static INLINE void write_coeff_extra(const aom_cdf_prob *const *cdf, int val,
-                                     int n, aom_writer *w) {
-  // Code the extra bits from LSB to MSB in groups of 4
-  int i = 0;
-  int count = 0;
-  while (count < n) {
-    const int size = AOMMIN(n - count, 4);
-    const int mask = (1 << size) - 1;
-    aom_write_cdf(w, val & mask, cdf[i++], 1 << size);
-    val >>= size;
-    count += size;
-  }
-}
-
-static void pack_mb_tokens(aom_writer *w, const TOKENEXTRA **tp,
-                           const TOKENEXTRA *const stop,
-                           aom_bit_depth_t bit_depth, const TX_SIZE tx_size,
-                           TOKEN_STATS *token_stats) {
-  const TOKENEXTRA *p = *tp;
-  int count = 0;
-  const int seg_eob = av1_get_max_eob(tx_size);
-
-  while (p < stop && p->token != EOSB_TOKEN) {
-    const int token = p->token;
-    const int8_t eob_val = p->eob_val;
-    if (token == BLOCK_Z_TOKEN) {
-      aom_write_symbol(w, 0, *p->head_cdf, HEAD_TOKENS + 1);
-      p++;
-      break;
-      continue;
-    }
-
-    const av1_extra_bit *const extra_bits = &av1_extra_bits[token];
-    if (eob_val == LAST_EOB) {
-      // Just code a flag indicating whether the value is >1 or 1.
-      aom_write_bit(w, token != ONE_TOKEN);
-    } else {
-      int comb_symb = 2 * AOMMIN(token, TWO_TOKEN) - eob_val + p->first_val;
-      aom_write_symbol(w, comb_symb, *p->head_cdf, HEAD_TOKENS + p->first_val);
-    }
-    if (token > ONE_TOKEN) {
-      aom_write_symbol(w, token - TWO_TOKEN, *p->tail_cdf, TAIL_TOKENS);
-    }
-
-    if (extra_bits->base_val) {
-      const int bit_string = p->extra;
-      const int bit_string_length = extra_bits->len;  // Length of extra bits to
-      const int is_cat6 = (extra_bits->base_val == CAT6_MIN_VAL);
-      // be written excluding
-      // the sign bit.
-      int skip_bits = is_cat6 ? CAT6_BIT_SIZE - av1_get_cat6_extrabits_size(
-                                                    tx_size, bit_depth)
-                              : 0;
-
-      assert(!(bit_string >> (bit_string_length - skip_bits + 1)));
-      if (bit_string_length > 0)
-        write_coeff_extra(extra_bits->cdf, bit_string >> 1,
-                          bit_string_length - skip_bits, w);
-
-      aom_write_bit_record(w, bit_string & 1, token_stats);
-    }
-    ++p;
-
-    ++count;
-    if (eob_val == EARLY_EOB || count == seg_eob) break;
-  }
-
-  *tp = p;
-}
-#endif  // !CONFIG_LV_MAP
-
-#if CONFIG_LV_MAP
 static void pack_txb_tokens(aom_writer *w, AV1_COMMON *cm, MACROBLOCK *const x,
                             const TOKENEXTRA **tp,
                             const TOKENEXTRA *const tok_end, MACROBLOCKD *xd,
@@ -513,56 +438,6 @@
     }
   }
 }
-#else  // CONFIG_LV_MAP
-static void pack_txb_tokens(aom_writer *w, const TOKENEXTRA **tp,
-                            const TOKENEXTRA *const tok_end, MACROBLOCKD *xd,
-                            MB_MODE_INFO *mbmi, int plane,
-                            BLOCK_SIZE plane_bsize, aom_bit_depth_t bit_depth,
-                            int block, int blk_row, int blk_col,
-                            TX_SIZE tx_size, TOKEN_STATS *token_stats) {
-  const struct macroblockd_plane *const pd = &xd->plane[plane];
-  const int tx_row = blk_row >> (1 - pd->subsampling_y);
-  const int tx_col = blk_col >> (1 - pd->subsampling_x);
-  const int max_blocks_high = max_block_high(xd, plane_bsize, plane);
-  const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane);
-
-  if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
-
-  const TX_SIZE plane_tx_size =
-      plane ? av1_get_uv_tx_size(mbmi, pd->subsampling_x, pd->subsampling_y)
-            : mbmi->inter_tx_size[tx_row][tx_col];
-
-  if (tx_size == plane_tx_size || plane) {
-    TOKEN_STATS tmp_token_stats;
-    init_token_stats(&tmp_token_stats);
-    pack_mb_tokens(w, tp, tok_end, bit_depth, tx_size, &tmp_token_stats);
-#if CONFIG_RD_DEBUG
-    token_stats->txb_coeff_cost_map[blk_row][blk_col] = tmp_token_stats.cost;
-    token_stats->cost += tmp_token_stats.cost;
-#endif
-  } else {
-    const TX_SIZE sub_txs = sub_tx_size_map[1][tx_size];
-    const int bsw = tx_size_wide_unit[sub_txs];
-    const int bsh = tx_size_high_unit[sub_txs];
-
-    assert(bsw > 0 && bsh > 0);
-
-    for (int r = 0; r < tx_size_high_unit[tx_size]; r += bsh) {
-      for (int c = 0; c < tx_size_wide_unit[tx_size]; c += bsw) {
-        const int offsetr = blk_row + r;
-        const int offsetc = blk_col + c;
-        const int step = bsh * bsw;
-
-        if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue;
-
-        pack_txb_tokens(w, tp, tok_end, xd, mbmi, plane, plane_bsize, bit_depth,
-                        block, offsetr, offsetc, sub_txs, token_stats);
-        block += step;
-      }
-    }
-  }
-}
-#endif  // CONFIG_LV_MAP
 
 #if CONFIG_SPATIAL_SEGMENTATION
 static int neg_interleave(int x, int ref, int max) {
@@ -1875,12 +1750,9 @@
        blk_row += bkh) {
     for (blk_col = col >> pd->subsampling_x; blk_col < unit_width;
          blk_col += bkw) {
-      pack_txb_tokens(w,
-#if CONFIG_LV_MAP
-                      cm, x,
-#endif
-                      tok, tok_end, xd, mbmi, plane, plane_bsize, cm->bit_depth,
-                      *block, blk_row, blk_col, max_tx_size, token_stats);
+      pack_txb_tokens(w, cm, x, tok, tok_end, xd, mbmi, plane, plane_bsize,
+                      cm->bit_depth, *block, blk_row, blk_col, max_tx_size,
+                      token_stats);
       *block += step;
     }
   }
@@ -1899,10 +1771,8 @@
   int plane;
   int bh, bw;
   MACROBLOCK *const x = &cpi->td.mb;
-#if CONFIG_LV_MAP
   (void)tok;
   (void)tok_end;
-#endif
   xd->mi = cm->mi_grid_visible + mi_offset;
 
   assert(mbmi->sb_type <= cm->seq_params.sb_size ||
@@ -1934,17 +1804,10 @@
                                &cols);
       assert(*tok < tok_end);
       pack_map_tokens(w, tok, palette_size_plane, rows * cols);
-#if !CONFIG_LV_MAP
-      assert(*tok < tok_end + mbmi->skip);
-#endif  // !CONFIG_LV_MAP
     }
   }
 
   if (!mbmi->skip) {
-#if !CONFIG_LV_MAP
-    assert(*tok < tok_end);
-#endif
-
     if (!is_inter_block(mbmi))
       av1_write_coeffs_mb(cm, x, mi_row, mi_col, w, mbmi->sb_type);
 
@@ -1975,9 +1838,6 @@
             const struct macroblockd_plane *const pd = &xd->plane[plane];
             if (!is_chroma_reference(mi_row, mi_col, mbmi->sb_type,
                                      pd->subsampling_x, pd->subsampling_y)) {
-#if !CONFIG_LV_MAP
-              (*tok)++;
-#endif  // !CONFIG_LV_MAP
               continue;
             }
             write_inter_txb_coeff(cm, x, mbmi, w, tok, tok_end, &token_stats,
@@ -3071,9 +2931,6 @@
 
         aom_start_encode(&mode_bc, dst + total_size);
         write_modes(cpi, &tile_info, &mode_bc, &tok, tok_end);
-#if !CONFIG_LV_MAP
-        assert(tok == tok_end);
-#endif  // !CONFIG_LV_MAP
         aom_stop_encode(&mode_bc);
         tile_size = mode_bc.pos;
         assert(tile_size > 0);
@@ -4878,9 +4735,6 @@
 
         aom_start_encode(&mode_bc, dst + total_size);
         write_modes(cpi, &tile_info, &mode_bc, &tok, tok_end);
-#if !CONFIG_LV_MAP
-        assert(tok == tok_end);
-#endif  // !CONFIG_LV_MAP
         aom_stop_encode(&mode_bc);
         tile_size = mode_bc.pos;
         assert(tile_size > 0);
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 7c890b8..3cbb8ad 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -35,9 +35,7 @@
   tran_low_t *qcoeff;
   tran_low_t *coeff;
   uint16_t *eobs;
-#if CONFIG_LV_MAP
   uint8_t *txb_entropy_ctx;
-#endif
   struct buf_2d src;
 
   // Quantizer setings
@@ -56,7 +54,6 @@
 typedef int av1_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][COEFF_CONTEXTS]
                           [TAIL_TOKENS];
 
-#if CONFIG_LV_MAP
 typedef struct {
   int txb_skip_cost[TXB_SKIP_CONTEXTS][2];
   int base_eob_cost[SIG_COEF_CONTEXTS_EOB][3];
@@ -78,18 +75,15 @@
   int dc_sign_ctx[MAX_MB_PLANE]
                  [MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)];
 } CB_COEFF_BUFFER;
-#endif
 
 typedef struct {
   int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
   int16_t mode_context[MODE_CTX_REF_FRAMES];
-#if CONFIG_LV_MAP
   // TODO(angiebird): Reduce the buffer size according to sb_type
   tran_low_t *tcoeff[MAX_MB_PLANE];
   uint16_t *eobs[MAX_MB_PLANE];
   uint8_t *txb_skip_ctx[MAX_MB_PLANE];
   int *dc_sign_ctx[MAX_MB_PLANE];
-#endif
   uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
   CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
   int16_t compound_mode_context[MODE_CTX_REF_FRAMES];
@@ -133,15 +127,11 @@
   int64_t sse;
   int rate;
   uint16_t eob;
-#if CONFIG_LV_MAP
 #if CONFIG_TXK_SEL
   TX_TYPE tx_type;
 #endif
   uint16_t entropy_context;
   uint8_t txb_entropy_ctx;
-#else
-  uint8_t entropy_context;
-#endif
   uint8_t valid;
   uint8_t fast;  // This is not being used now.
 } TX_SIZE_RD_INFO;
@@ -267,11 +257,9 @@
   int skip_mode_index;
 #endif  // CONFIG_EXT_SKIP
 
-#if CONFIG_LV_MAP
   LV_MAP_COEFF_COST coeff_costs[TX_SIZES][PLANE_TYPES];
   LV_MAP_EOB_COST eob_costs[7][2];
   uint16_t cb_offset;
-#endif
 
   av1_coeff_cost token_head_costs[TX_SIZES];
   av1_coeff_cost token_tail_costs[TX_SIZES];
diff --git a/av1/encoder/context_tree.c b/av1/encoder/context_tree.c
index c6a9606..32231d4 100644
--- a/av1/encoder/context_tree.c
+++ b/av1/encoder/context_tree.c
@@ -36,11 +36,9 @@
                     aom_memalign(32, num_pix * sizeof(*ctx->dqcoeff[i])));
     CHECK_MEM_ERROR(cm, ctx->eobs[i],
                     aom_memalign(32, num_blk * sizeof(*ctx->eobs[i])));
-#if CONFIG_LV_MAP
     CHECK_MEM_ERROR(
         cm, ctx->txb_entropy_ctx[i],
         aom_memalign(32, num_blk * sizeof(*ctx->txb_entropy_ctx[i])));
-#endif
   }
 
   if (num_pix <= MAX_PALETTE_SQUARE) {
@@ -65,10 +63,8 @@
     ctx->dqcoeff[i] = 0;
     aom_free(ctx->eobs[i]);
     ctx->eobs[i] = 0;
-#if CONFIG_LV_MAP
     aom_free(ctx->txb_entropy_ctx[i]);
     ctx->txb_entropy_ctx[i] = 0;
-#endif
   }
 
   for (i = 0; i < 2; ++i) {
diff --git a/av1/encoder/context_tree.h b/av1/encoder/context_tree.h
index c99a9c3..8c01175 100644
--- a/av1/encoder/context_tree.h
+++ b/av1/encoder/context_tree.h
@@ -45,9 +45,7 @@
   tran_low_t *qcoeff[MAX_MB_PLANE];
   tran_low_t *dqcoeff[MAX_MB_PLANE];
   uint16_t *eobs[MAX_MB_PLANE];
-#if CONFIG_LV_MAP
   uint8_t *txb_entropy_ctx[MAX_MB_PLANE];
-#endif
 
   int num_4x4_blk;
   int skip;
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 189a1dd..e5f8df2 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -51,9 +51,7 @@
 #include "av1/encoder/encodeframe.h"
 #include "av1/encoder/encodemb.h"
 #include "av1/encoder/encodemv.h"
-#if CONFIG_LV_MAP
 #include "av1/encoder/encodetxb.h"
-#endif
 #include "av1/encoder/ethread.h"
 #include "av1/encoder/extend.h"
 #include "av1/encoder/rd.h"
@@ -505,9 +503,7 @@
     p[i].qcoeff = ctx->qcoeff[i];
     pd[i].dqcoeff = ctx->dqcoeff[i];
     p[i].eobs = ctx->eobs[i];
-#if CONFIG_LV_MAP
     p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i];
-#endif  // CONFIG_LV_MAP
   }
   for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i];
   // Restore the coding context of the MB to that that was in place
@@ -669,9 +665,7 @@
     p[i].qcoeff = ctx->qcoeff[i];
     pd[i].dqcoeff = ctx->dqcoeff[i];
     p[i].eobs = ctx->eobs[i];
-#if CONFIG_LV_MAP
     p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i];
-#endif
   }
 
   for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i];
@@ -1501,17 +1495,13 @@
 #endif
   update_state(cpi, tile_data, td, ctx, mi_row, mi_col, bsize, dry_run);
 
-#if CONFIG_LV_MAP
   av1_set_coeff_buffer(cpi, x, mi_row, mi_col);
-#endif
 
   encode_superblock(cpi, tile_data, td, tp, dry_run, mi_row, mi_col, bsize,
                     rate);
 
-#if CONFIG_LV_MAP
   if (dry_run == 0)
     x->cb_offset += block_size_wide[bsize] * block_size_high[bsize];
-#endif
 
   if (!dry_run) {
 #if CONFIG_EXT_DELTA_Q
@@ -2716,9 +2706,6 @@
 #endif  // CONFIG_DIST_8X8
 
   if (bsize == cm->seq_params.sb_size) {
-#if !CONFIG_LV_MAP
-    assert(tp_orig < *tp || (tp_orig == *tp && xd->mi[0]->mbmi.skip));
-#endif
     assert(best_rdc.rate < INT_MAX);
     assert(best_rdc.dist < INT64_MAX);
   } else {
@@ -3565,9 +3552,7 @@
   if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX &&
       pc_tree->index != 3) {
     if (bsize == cm->seq_params.sb_size) {
-#if CONFIG_LV_MAP
       x->cb_offset = 0;
-#endif
 
       encode_sb(cpi, td, tile_data, tp, mi_row, mi_col, OUTPUT_ENABLED, bsize,
                 pc_tree, NULL);
@@ -3586,9 +3571,6 @@
 #endif  // CONFIG_DIST_8X8
 
   if (bsize == cm->seq_params.sb_size) {
-#if !CONFIG_LV_MAP
-    assert(tp_orig < *tp || (tp_orig == *tp && xd->mi[0]->mbmi.skip));
-#endif
     assert(best_rdc.rate < INT_MAX);
     assert(best_rdc.dist < INT64_MAX);
   } else {
@@ -3644,14 +3626,7 @@
     PC_TREE *const pc_root =
         td->pc_root[cm->seq_params.mib_size_log2 - MIN_MIB_SIZE_LOG2];
 
-#if CONFIG_LV_MAP
     av1_fill_coeff_costs(&td->mb, xd->tile_ctx, num_planes);
-#else
-    av1_fill_token_costs_from_cdf(x->token_head_costs,
-                                  x->e_mbd.tile_ctx->coef_head_cdfs);
-    av1_fill_token_costs_from_cdf(x->token_tail_costs,
-                                  x->e_mbd.tile_ctx->coef_tail_cdfs);
-#endif
     av1_fill_mode_rates(cm, x, xd->tile_ctx);
 
     if (sf->adaptive_pred_interp_filter) {
@@ -4969,13 +4944,8 @@
     }
 
     mbmi->min_tx_size = mbmi->tx_size;
-#if CONFIG_LV_MAP
     av1_update_txb_context(cpi, td, dry_run, bsize, rate, mi_row, mi_col,
                            tile_data->allow_update_cdf);
-#else   // CONFIG_LV_MAP
-    av1_tokenize_sb(cpi, td, t, dry_run, bsize, rate, mi_row, mi_col,
-                    tile_data->allow_update_cdf);
-#endif  // CONFIG_LV_MAP
   } else {
     int ref;
     const int is_compound = has_second_ref(mbmi);
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index 7bb3044..e0fac35 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -29,9 +29,7 @@
 
 #include "av1/encoder/av1_quantize.h"
 #include "av1/encoder/encodemb.h"
-#if CONFIG_LV_MAP
 #include "av1/encoder/encodetxb.h"
-#endif
 #include "av1/encoder/hybrid_fwd_txfm.h"
 #include "av1/encoder/rd.h"
 #include "av1/encoder/rdopt.h"
@@ -100,272 +98,6 @@
                  pd->dst.buf, pd->dst.stride);
 }
 
-#if !CONFIG_LV_MAP
-// Shifting negative values is undefined behaviour in C99,
-// and could mislead the optimizer, who might assume the shifted is positive.
-// This also avoids ubsan warnings.
-// In practise, this gets inlined by the optimizer to a single instruction.
-static INLINE int signed_shift_right(int x, int shift) {
-  if (x >= 0)
-    return x >> shift;
-  else
-    return -((-x) >> shift);
-}
-
-// These numbers are empirically obtained.
-static const int plane_rd_mult[REF_TYPES][PLANE_TYPES] = {
-  { 10, 7 },
-  { 8, 5 },
-};
-
-static int optimize_b_greedy(const AV1_COMMON *cm, MACROBLOCK *mb, int plane,
-                             int blk_row, int blk_col, int block,
-                             TX_SIZE tx_size, int ctx, int fast_mode) {
-  MACROBLOCKD *const xd = &mb->e_mbd;
-  struct macroblock_plane *const p = &mb->plane[plane];
-  struct macroblockd_plane *const pd = &xd->plane[plane];
-  const PLANE_TYPE plane_type = pd->plane_type;
-  const int eob = p->eobs[block];
-  assert(mb->qindex > 0);
-  assert((!plane_type && !plane) || (plane_type && plane));
-  assert(eob <= av1_get_max_eob(tx_size));
-  const int ref = is_inter_block(&xd->mi[0]->mbmi);
-  const 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);
-  const int16_t *const dequant_ptr = p->dequant_QTX;
-  const uint8_t *const band_translate = get_band_translate(tx_size);
-  const TX_TYPE tx_type = av1_get_tx_type(plane_type, xd, blk_row, blk_col,
-                                          tx_size, cm->reduced_tx_set_used);
-  const SCAN_ORDER *const scan_order =
-      get_scan(cm, tx_size, tx_type, &xd->mi[0]->mbmi);
-  const int16_t *const scan = scan_order->scan;
-  const int16_t *const nb = scan_order->neighbors;
-  const int shift = av1_get_tx_scale(tx_size);
-#if CONFIG_AOM_QM
-  int seg_id = xd->mi[0]->mbmi.segment_id;
-  const TX_SIZE qm_tx_size = av1_get_adjusted_tx_size(tx_size);
-  // Use a flat matrix (i.e. no weighting) for 1D and Identity transforms
-  const qm_val_t *iqmatrix =
-      IS_2D_TRANSFORM(tx_type)
-          ? pd->seg_iqmatrix[seg_id][qm_tx_size]
-          : cm->giqmatrix[NUM_QM_LEVELS - 1][0][qm_tx_size];
-#endif  // CONFIG_AOM_QM
-  int64_t rd_cost0, rd_cost1;
-  int16_t t0, t1;
-  int i, final_eob = 0;
-  const int cat6_bits = av1_get_cat6_extrabits_size(tx_size, xd->bd);
-  int(*head_token_costs)[COEFF_CONTEXTS][TAIL_TOKENS] =
-      mb->token_head_costs[get_txsize_entropy_ctx(tx_size)][plane_type][ref];
-  int(*tail_token_costs)[COEFF_CONTEXTS][TAIL_TOKENS] =
-      mb->token_tail_costs[get_txsize_entropy_ctx(tx_size)][plane_type][ref];
-
-  const int64_t rdmult = (mb->rdmult * plane_rd_mult[ref][plane_type]) >> 1;
-  int64_t rate0, rate1;
-  int64_t eob_cost0, eob_cost1;
-  tran_low_t before_best_eob_qc = 0;
-  tran_low_t before_best_eob_dqc = 0;
-
-  uint8_t token_cache[MAX_TX_SQUARE];
-
-  // TODO(debargha): Implement a fast mode. For now just skip.
-  if (fast_mode) return eob;
-
-  for (i = 0; i < eob; i++) {
-    const int rc = scan[i];
-    token_cache[rc] = av1_pt_energy_class[av1_get_token(qcoeff[rc])];
-  }
-
-  /* Record the r-d cost */
-  int64_t accu_rate = 0;
-  // Initialized to the worst possible error for the largest transform size.
-  // This ensures that it never goes negative.
-  int64_t accu_error = ((int64_t)1) << 50;
-  rate0 = head_token_costs[0][ctx][0];
-  int64_t best_block_rd_cost = RDCOST(rdmult, rate0, accu_error);
-
-  // int64_t best_block_rd_cost_all0 = best_block_rd_cost;
-  const int seg_eob =
-      av1_get_tx_eob(&cm->seg, xd->mi[0]->mbmi.segment_id, tx_size);
-  for (i = 0; i < eob; i++) {
-    const int rc = scan[i];
-    const int x = qcoeff[rc];
-    const int sz = -(x < 0);
-    const int band_cur = band_translate[i];
-    const int ctx_cur = (i == 0) ? ctx : get_coef_context(nb, token_cache, i);
-    const int8_t eob_val =
-        (i + 1 == eob) ? (i + 1 == seg_eob ? LAST_EOB : EARLY_EOB) : NO_EOB;
-    const int is_first = (i == 0);
-
-    if (x == 0) {
-      // no need to search when x == 0
-      accu_rate += av1_get_coeff_token_cost(
-          ZERO_TOKEN, eob_val, is_first, head_token_costs[band_cur][ctx_cur],
-          tail_token_costs[band_cur][ctx_cur]);
-      // accu_error does not change when x==0
-    } else {
-      /*  Computing distortion
-       */
-      // compute the distortion for the first candidate
-      // and the distortion for quantizing to 0.
-      int dx0 = abs(coeff[rc]) * (1 << shift);
-      dx0 >>= xd->bd - 8;
-
-      const int64_t d0 = (int64_t)dx0 * dx0;
-      const int x_a = x - 2 * sz - 1;
-      int dqv = dequant_ptr[rc != 0];
-#if CONFIG_AOM_QM
-      if (iqmatrix != NULL) {
-        const qm_val_t iwt = iqmatrix[rc];
-        dqv = ((iwt * (int)dqv) + (1 << (AOM_QM_BITS - 1))) >> AOM_QM_BITS;
-      }
-#endif  // CONFIG_AOM_QM
-
-      int dx = (dqcoeff[rc] - coeff[rc]) * (1 << shift);
-      dx = signed_shift_right(dx, xd->bd - 8);
-      const int64_t d2 = (int64_t)dx * dx;
-
-      /* compute the distortion for the second candidate
-       * x_a = x - 2 * sz + 1;
-       */
-      int64_t d2_a;
-      if (x_a != 0) {
-        dx -= ((dqv >> (xd->bd - 8)) + sz) ^ sz;
-        d2_a = (int64_t)dx * dx;
-      } else {
-        d2_a = d0;
-      }
-
-      // Computing RD cost
-      int64_t base_bits;
-      // rate cost of x
-      base_bits = av1_get_token_cost(x, &t0, cat6_bits);
-      rate0 = base_bits +
-              av1_get_coeff_token_cost(t0, eob_val, is_first,
-                                       head_token_costs[band_cur][ctx_cur],
-                                       tail_token_costs[band_cur][ctx_cur]);
-      // rate cost of x_a
-      base_bits = av1_get_token_cost(x_a, &t1, cat6_bits);
-      if (t1 == ZERO_TOKEN && eob_val) {
-        rate1 = base_bits;
-      } else {
-        rate1 = base_bits +
-                av1_get_coeff_token_cost(t1, eob_val, is_first,
-                                         head_token_costs[band_cur][ctx_cur],
-                                         tail_token_costs[band_cur][ctx_cur]);
-      }
-
-      int64_t next_bits0 = 0, next_bits1 = 0;
-      if (i < eob - 1) {
-        int ctx_next;
-        const int band_next = band_translate[i + 1];
-        const int token_next = av1_get_token(qcoeff[scan[i + 1]]);
-        const int8_t eob_val_next =
-            (i + 2 == eob) ? (i + 2 == seg_eob ? LAST_EOB : EARLY_EOB) : NO_EOB;
-
-        token_cache[rc] = av1_pt_energy_class[t0];
-        ctx_next = get_coef_context(nb, token_cache, i + 1);
-        next_bits0 = av1_get_coeff_token_cost(
-            token_next, eob_val_next, 0, head_token_costs[band_next][ctx_next],
-            tail_token_costs[band_next][ctx_next]);
-
-        token_cache[rc] = av1_pt_energy_class[t1];
-        ctx_next = get_coef_context(nb, token_cache, i + 1);
-        next_bits1 = av1_get_coeff_token_cost(
-            token_next, eob_val_next, 0, head_token_costs[band_next][ctx_next],
-            tail_token_costs[band_next][ctx_next]);
-      }
-
-      rd_cost0 = RDCOST(rdmult, (rate0 + next_bits0), d2);
-      rd_cost1 = RDCOST(rdmult, (rate1 + next_bits1), d2_a);
-      const int best_x = (rd_cost1 < rd_cost0);
-
-      const int eob_v = (i + 1 == seg_eob) ? LAST_EOB : EARLY_EOB;
-      int64_t next_eob_bits0, next_eob_bits1;
-      int best_eob_x;
-      next_eob_bits0 = av1_get_coeff_token_cost(
-          t0, eob_v, is_first, head_token_costs[band_cur][ctx_cur],
-          tail_token_costs[band_cur][ctx_cur]);
-      eob_cost0 =
-          RDCOST(rdmult, (accu_rate + next_eob_bits0), (accu_error + d2 - d0));
-      eob_cost1 = eob_cost0;
-      if (x_a != 0) {
-        next_eob_bits1 = av1_get_coeff_token_cost(
-            t1, eob_v, is_first, head_token_costs[band_cur][ctx_cur],
-            tail_token_costs[band_cur][ctx_cur]);
-        eob_cost1 = RDCOST(rdmult, (accu_rate + next_eob_bits1),
-                           (accu_error + d2_a - d0));
-        best_eob_x = (eob_cost1 < eob_cost0);
-      } else {
-        best_eob_x = 0;
-      }
-
-      const int dqc = dqcoeff[rc];
-      int dqc_a = 0;
-      if (best_x || best_eob_x) {
-        if (x_a != 0) {
-          if (x_a < 0)
-            dqc_a = -((-x_a * dqv) >> shift);
-          else
-            dqc_a = (x_a * dqv) >> shift;
-        } else {
-          dqc_a = 0;
-        }
-      }
-
-      // record the better quantized value
-      if (best_x) {
-        assert(d2_a <= d0);
-        qcoeff[rc] = x_a;
-        dqcoeff[rc] = dqc_a;
-        accu_rate += rate1;
-        accu_error += d2_a - d0;
-        token_cache[rc] = av1_pt_energy_class[t1];
-      } else {
-        assert(d2 <= d0);
-        accu_rate += rate0;
-        accu_error += d2 - d0;
-        token_cache[rc] = av1_pt_energy_class[t0];
-      }
-      assert(accu_error >= 0);
-
-      // determine whether to move the eob position to i+1
-      const int use_a = (x_a != 0) && (best_eob_x);
-      const int64_t best_eob_cost_i = use_a ? eob_cost1 : eob_cost0;
-      if (best_eob_cost_i < best_block_rd_cost) {
-        best_block_rd_cost = best_eob_cost_i;
-        final_eob = i + 1;
-        if (use_a) {
-          before_best_eob_qc = x_a;
-          before_best_eob_dqc = dqc_a;
-        } else {
-          before_best_eob_qc = x;
-          before_best_eob_dqc = dqc;
-        }
-      }
-    }  // if (x==0)
-  }    // for (i)
-
-  assert(final_eob <= eob);
-  if (final_eob > 0) {
-    assert(before_best_eob_qc != 0);
-    i = final_eob - 1;
-    int rc = scan[i];
-    qcoeff[rc] = before_best_eob_qc;
-    dqcoeff[rc] = before_best_eob_dqc;
-  }
-
-  for (i = final_eob; i < eob; i++) {
-    int rc = scan[i];
-    qcoeff[rc] = 0;
-    dqcoeff[rc] = 0;
-  }
-
-  p->eobs[block] = final_eob;
-  return final_eob;
-}
-#endif  // !CONFIG_LV_MAP
-
 int av1_optimize_b(const struct AV1_COMP *cpi, MACROBLOCK *mb, int plane,
                    int blk_row, int blk_col, int block, BLOCK_SIZE plane_bsize,
                    TX_SIZE tx_size, const ENTROPY_CONTEXT *a,
@@ -376,20 +108,10 @@
   if (eob == 0 || !mb->optimize || xd->lossless[xd->mi[0]->mbmi.segment_id])
     return eob;
 
-#if !CONFIG_LV_MAP
-  (void)plane_bsize;
-  (void)blk_row;
-  (void)blk_col;
-  int ctx = get_entropy_context(tx_size, a, l);
-  const AV1_COMMON *const cm = &cpi->common;
-  return optimize_b_greedy(cm, mb, plane, blk_row, blk_col, block, tx_size, ctx,
-                           fast_mode);
-#else   // !CONFIG_LV_MAP
   TXB_CTX txb_ctx;
   get_txb_ctx(plane_bsize, tx_size, plane, a, l, &txb_ctx);
   return av1_optimize_txb(cpi, mb, plane, blk_row, blk_col, block, tx_size,
                           &txb_ctx, fast_mode, rate_cost);
-#endif  // !CONFIG_LV_MAP
 }
 
 typedef enum QUANT_FUNC {
@@ -471,10 +193,8 @@
       av1_quantize_skip(n_coeffs, qcoeff, dqcoeff, eob);
     }
   }
-#if CONFIG_LV_MAP
   p->txb_entropy_ctx[block] =
       (uint8_t)av1_get_txb_entropy_context(qcoeff, scan_order, *eob);
-#endif  // CONFIG_LV_MAP
   return;
 }
 
@@ -510,7 +230,7 @@
       av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize,
                       tx_size, AV1_XFORM_QUANT_FP);
       av1_optimize_b(args->cpi, x, plane, blk_row, blk_col, block, plane_bsize,
-                     tx_size, a, l, CONFIG_LV_MAP, &dummy_rate_cost);
+                     tx_size, a, l, 1, &dummy_rate_cost);
     } else {
       av1_xform_quant(
           cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
@@ -518,9 +238,7 @@
     }
   } else {
     p->eobs[block] = 0;
-#if CONFIG_LV_MAP
     p->txb_entropy_ctx[block] = 0;
-#endif
   }
 
   av1_set_txb_context(x, plane, block, tx_size, a, l);
@@ -770,11 +488,7 @@
   (void)tx_size;
   struct macroblock_plane *p = &x->plane[plane];
 
-#if !CONFIG_LV_MAP
-  *a = *l = p->eobs[block] > 0;
-#else   // !CONFIG_LV_MAP
   *a = *l = p->txb_entropy_ctx[block];
-#endif  // !CONFIG_LV_MAP
 
   int i;
   for (i = 0; i < tx_size_wide_unit[tx_size]; ++i) a[i] = a[0];
@@ -844,7 +558,7 @@
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                     AV1_XFORM_QUANT_FP);
     av1_optimize_b(args->cpi, x, plane, blk_row, blk_col, block, plane_bsize,
-                   tx_size, a, l, CONFIG_LV_MAP, &dummy_rate_cost);
+                   tx_size, a, l, 1, &dummy_rate_cost);
 
 #if CONFIG_TXK_SEL
     if (plane == 0 && p->eobs[block] == 0) {
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index f0c3600..a45916c 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -35,9 +35,7 @@
 #include "av1/encoder/encodeframe.h"
 #include "av1/encoder/encodemv.h"
 #include "av1/encoder/encoder.h"
-#if CONFIG_LV_MAP
 #include "av1/encoder/encodetxb.h"
-#endif
 #include "av1/encoder/ethread.h"
 #include "av1/encoder/firstpass.h"
 #if CONFIG_HASH_ME
@@ -550,9 +548,7 @@
 #endif
 
   av1_free_ref_frame_buffers(cm->buffer_pool);
-#if CONFIG_LV_MAP
   av1_free_txb_buf(cpi);
-#endif
   av1_free_context_buffers(cm);
 
   aom_free_frame_buffer(&cpi->last_frame_uf);
@@ -842,9 +838,7 @@
 
   av1_alloc_context_buffers(cm, cm->width, cm->height);
 
-#if CONFIG_LV_MAP
   av1_alloc_txb_buf(cpi);
-#endif
 
   alloc_context_buffers_ext(cpi);
 
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index d2c391e..4f5dc9a 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -402,9 +402,7 @@
   QUANTS quants;
   ThreadData td;
   MB_MODE_INFO_EXT *mbmi_ext_base;
-#if CONFIG_LV_MAP
   CB_COEFF_BUFFER *coeff_buffer_base;
-#endif
   Dequants dequants;
   AV1_COMMON common;
   AV1EncoderConfig oxcf;
@@ -609,9 +607,7 @@
   int arf_pos_in_gf[MAX_EXT_ARFS + 1];
   int arf_pos_for_ovrly[MAX_EXT_ARFS + 1];
   int global_motion_search_done;
-#if CONFIG_LV_MAP
   tran_low_t *tcoeff_buf[MAX_MB_PLANE];
-#endif
 
   int extra_arf_allowed;
   int bwd_ref_allowed;
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index f605ed0..8c65d06 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -27,9 +27,7 @@
 #include "av1/common/entropymv.h"
 #include "av1/common/quant_common.h"
 #include "av1/common/reconinter.h"  // av1_setup_dst_planes()
-#if CONFIG_LV_MAP
 #include "av1/common/txb_common.h"
-#endif
 #include "av1/encoder/aq_variance.h"
 #include "av1/encoder/av1_quantize.h"
 #include "av1/encoder/block.h"
@@ -578,15 +576,11 @@
     p[i].qcoeff = ctx->qcoeff[i];
     pd[i].dqcoeff = ctx->dqcoeff[i];
     p[i].eobs = ctx->eobs[i];
-#if CONFIG_LV_MAP
     p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i];
-#endif
   }
 
   av1_init_mv_probs(cm);
-#if CONFIG_LV_MAP
   av1_init_lv_map(cm);
-#endif
   av1_initialize_rd_consts(cpi);
 
   // Tiling is ignored in the first pass.
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 4a13638..2f40dbb 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -36,9 +36,7 @@
 #include "av1/encoder/encodemb.h"
 #include "av1/encoder/encodemv.h"
 #include "av1/encoder/encoder.h"
-#if CONFIG_LV_MAP
 #include "av1/encoder/encodetxb.h"
-#endif
 #include "av1/encoder/mcomp.h"
 #include "av1/encoder/ratectrl.h"
 #include "av1/encoder/rd.h"
@@ -473,7 +471,6 @@
   x->nmvjointcost = x->nmv_vec_cost[nmv_ctx];
 }
 
-#if CONFIG_LV_MAP
 void av1_fill_coeff_costs(MACROBLOCK *x, FRAME_CONTEXT *fc,
                           const int num_planes) {
   const int nplanes = AOMMIN(num_planes, PLANE_TYPES);
@@ -553,7 +550,6 @@
     }
   }
 }
-#endif  // CONFIG_LV_MAP
 
 void av1_fill_token_costs_from_cdf(av1_coeff_cost *cost,
                                    coeff_cdf_model (*cdf)[PLANE_TYPES]) {
@@ -733,11 +729,9 @@
   const ENTROPY_CONTEXT *const above = pd->above_context;
   const ENTROPY_CONTEXT *const left = pd->left_context;
 
-#if CONFIG_LV_MAP
   memcpy(t_above, above, sizeof(ENTROPY_CONTEXT) * num_4x4_w);
   memcpy(t_left, left, sizeof(ENTROPY_CONTEXT) * num_4x4_h);
   return;
-#endif  // CONFIG_LV_MAP
 
   int i;
 
diff --git a/av1/encoder/rd.h b/av1/encoder/rd.h
index 44f2f1b..3cfcc96 100644
--- a/av1/encoder/rd.h
+++ b/av1/encoder/rd.h
@@ -461,10 +461,8 @@
 void av1_fill_mode_rates(AV1_COMMON *const cm, MACROBLOCK *x,
                          FRAME_CONTEXT *fc);
 
-#if CONFIG_LV_MAP
 void av1_fill_coeff_costs(MACROBLOCK *x, FRAME_CONTEXT *fc,
                           const int num_planes);
-#endif
 
 void av1_fill_token_costs_from_cdf(av1_coeff_cost *cost,
                                    coeff_cdf_model (*cdf)[PLANE_TYPES]);
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 0acf70b..de24d61 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -38,9 +38,7 @@
 #include "av1/common/reconintra.h"
 #include "av1/common/scan.h"
 #include "av1/common/seg_common.h"
-#if CONFIG_LV_MAP
 #include "av1/common/txb_common.h"
-#endif
 #include "av1/common/warped_motion.h"
 
 #include "av1/encoder/aq_variance.h"
@@ -49,9 +47,7 @@
 #include "av1/encoder/encodemb.h"
 #include "av1/encoder/encodemv.h"
 #include "av1/encoder/encoder.h"
-#if CONFIG_LV_MAP
 #include "av1/encoder/encodetxb.h"
-#endif
 #include "av1/encoder/hybrid_fwd_txfm.h"
 #include "av1/encoder/mcomp.h"
 #include "av1/encoder/palette.h"
@@ -2089,7 +2085,7 @@
 #endif
         RDCOST(x->rdmult, 0, tmp_dist) + args->this_rd < args->best_rd) {
       av1_optimize_b(cpi, x, plane, blk_row, blk_col, block, plane_bsize,
-                     tx_size, a, l, CONFIG_LV_MAP, &rate_cost);
+                     tx_size, a, l, 1, &rate_cost);
 
       const int eob = x->plane[plane].eobs[block];
       if (!eob)
@@ -3792,15 +3788,9 @@
 
   assert(tx_size < TX_SIZES_ALL);
 
-#if CONFIG_LV_MAP
   TXB_CTX txb_ctx;
   get_txb_ctx(plane_bsize, tx_size, plane, a, l, &txb_ctx);
   uint16_t cur_joint_ctx = (txb_ctx.dc_sign_ctx << 8) + txb_ctx.txb_skip_ctx;
-#else
-  const int coeff_ctx = get_entropy_context(tx_size, a, l);
-  const int coeff_ctx_one_byte = combine_entropy_contexts(*a, *l);
-  const uint8_t cur_joint_ctx = (coeff_ctx << 2) + coeff_ctx_one_byte;
-#endif
 
   // Note: tmp below is pixel distortion, not TX domain
   tmp = pixel_diff_dist(x, plane, diff, diff_stride, blk_row, blk_col,
@@ -3826,9 +3816,7 @@
     rd_stats->rate += rd_info_array[tx_type].rate;
     rd_stats->skip &= rd_info_array[tx_type].eob == 0;
     p->eobs[block] = rd_info_array[tx_type].eob;
-#if CONFIG_LV_MAP
     p->txb_entropy_ctx[block] = rd_info_array[tx_type].txb_entropy_ctx;
-#endif
     return;
   }
 
@@ -3951,9 +3939,7 @@
     rd_info_array[tx_type].dist = cur_dist;
     rd_info_array[tx_type].rate = cur_rate;
     rd_info_array[tx_type].eob = eob;
-#if CONFIG_LV_MAP
     rd_info_array[tx_type].txb_entropy_ctx = p->txb_entropy_ctx[block];
-#endif
   }
 
   rd_stats->dist += cur_dist;
@@ -4008,19 +3994,12 @@
 
   // TX no split
   {
-#if CONFIG_LV_MAP
     const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
     TXB_CTX txb_ctx;
     get_txb_ctx(plane_bsize, tx_size, plane, pta, ptl, &txb_ctx);
 
     const int zero_blk_rate = x->coeff_costs[txs_ctx][get_plane_type(plane)]
                                   .txb_skip_cost[txb_ctx.txb_skip_ctx][1];
-#else
-    const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size);
-    const int coeff_ctx = get_entropy_context(tx_size, pta, ptl);
-    const int zero_blk_rate =
-        x->token_head_costs[tx_size_ctx][pd->plane_type][1][0][coeff_ctx][0];
-#endif
 
     rd_stats->ref_rdcost = ref_best_rd;
     rd_stats->zero_rate = zero_blk_rate;
@@ -4056,11 +4035,7 @@
     if (tx_size > TX_4X4 && depth < MAX_VARTX_DEPTH)
       rd_stats->rate += x->txfm_partition_cost[ctx][0];
     this_rd = RDCOST(x->rdmult, rd_stats->rate, rd_stats->dist);
-#if CONFIG_LV_MAP
     tmp_eob = p->txb_entropy_ctx[block];
-#else
-    tmp_eob = p->eobs[block];
-#endif
 
 #if CONFIG_TXK_SEL
     const int txk_idx = (blk_row << MAX_MIB_SIZE_LOG2) + blk_col;
@@ -4225,11 +4200,7 @@
   if (this_rd < sum_rd) {
     const TX_SIZE tx_size_selected = tx_size;
 
-#if CONFIG_LV_MAP
     p->txb_entropy_ctx[block] = tmp_eob;
-#else
-    p->eobs[block] = tmp_eob;
-#endif
 
     av1_set_txb_context(x, plane, block, tx_size_selected, pta, ptl);
 
@@ -4434,19 +4405,12 @@
   if (tx_size == plane_tx_size || plane) {
     ENTROPY_CONTEXT *ta = above_ctx + blk_col;
     ENTROPY_CONTEXT *tl = left_ctx + blk_row;
-#if CONFIG_LV_MAP
     const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
     TXB_CTX txb_ctx;
     get_txb_ctx(plane_bsize, tx_size, plane, ta, tl, &txb_ctx);
 
     const int zero_blk_rate = x->coeff_costs[txs_ctx][get_plane_type(plane)]
                                   .txb_skip_cost[txb_ctx.txb_skip_ctx][1];
-#else
-    const int coeff_ctx = get_entropy_context(tx_size, ta, tl);
-    const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size);
-    const int zero_blk_rate =
-        x->token_head_costs[tx_size_ctx][pd->plane_type][1][0][coeff_ctx][0];
-#endif  // CONFIG_LV_MAP
     rd_stats->zero_rate = zero_blk_rate;
     rd_stats->ref_rdcost = ref_best_rd;
     av1_tx_block_rd_b(cpi, x, tx_size, blk_row, blk_col, plane, block,
@@ -4460,12 +4424,10 @@
       rd_stats->skip = 1;
       x->blk_skip[plane][blk_row * mi_width + blk_col] = 1;
       x->plane[plane].eobs[block] = 0;
-#if CONFIG_LV_MAP
       x->plane[plane].txb_entropy_ctx[block] = 0;
 #if CONFIG_TXK_SEL
       update_txk_array(mbmi->txk_type, blk_row, blk_col, tx_size, DCT_DCT);
 #endif
-#endif  // CONFIG_LV_MAP
     } else {
       rd_stats->skip = 0;
       x->blk_skip[plane][blk_row * mi_width + blk_col] = 0;
@@ -4906,16 +4868,11 @@
   ENTROPY_CONTEXT ctxa[2 * MAX_MIB_SIZE];
   ENTROPY_CONTEXT ctxl[2 * MAX_MIB_SIZE];
   av1_get_entropy_contexts(bsize, 0, &xd->plane[0], ctxa, ctxl);
-#if CONFIG_LV_MAP
   TXB_CTX txb_ctx;
   // Because plane is 0, plane_bsize equal to bsize
   get_txb_ctx(bsize, tx_size, 0, ctxa, ctxl, &txb_ctx);
   int rate = x->coeff_costs[tx_size_ctx][PLANE_TYPE_Y]
                  .txb_skip_cost[txb_ctx.txb_skip_ctx][1];
-#else
-  int coeff_ctx = get_entropy_context(tx_size, ctxa, ctxl);
-  int rate = x->token_head_costs[tx_size_ctx][PLANE_TYPE_Y][1][0][coeff_ctx][0];
-#endif
   if (tx_size > TX_4X4) {
     int ctx = txfm_partition_context(
         xd->above_txfm_context, xd->left_txfm_context, mbmi->sb_type, tx_size);
diff --git a/av1/encoder/rdopt.h b/av1/encoder/rdopt.h
index a53d193..a31d396 100644
--- a/av1/encoder/rdopt.h
+++ b/av1/encoder/rdopt.h
@@ -13,16 +13,12 @@
 #define AV1_ENCODER_RDOPT_H_
 
 #include "av1/common/blockd.h"
-#if CONFIG_LV_MAP
 #include "av1/common/txb_common.h"
-#endif
 
 #include "av1/encoder/block.h"
 #include "av1/encoder/context_tree.h"
 #include "av1/encoder/encoder.h"
-#if CONFIG_LV_MAP
 #include "av1/encoder/encodetxb.h"
-#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -82,130 +78,6 @@
                      int bsh, int visible_w, int visible_h, int qindex);
 #endif
 
-#if !CONFIG_LV_MAP
-DECLARE_ALIGNED(16, const uint16_t, band_count_table[TX_SIZES_ALL][8]);
-
-const uint16_t band_count_table[TX_SIZES_ALL][8] = {
-  { 1, 2, 3, 4, 3, 16 - 13, 0 },    { 1, 2, 3, 4, 11, 64 - 21, 0 },
-  { 1, 2, 3, 4, 11, 256 - 21, 0 },  { 1, 2, 3, 4, 11, 1024 - 21, 0 },
-  { 1, 2, 3, 4, 11, 4096 - 21, 0 }, { 1, 2, 3, 4, 8, 32 - 18, 0 },
-  { 1, 2, 3, 4, 8, 32 - 18, 0 },    { 1, 2, 3, 4, 11, 128 - 21, 0 },
-  { 1, 2, 3, 4, 11, 128 - 21, 0 },  { 1, 2, 3, 4, 11, 512 - 21, 0 },
-  { 1, 2, 3, 4, 11, 512 - 21, 0 },  { 1, 2, 3, 4, 11, 2048 - 21, 0 },
-  { 1, 2, 3, 4, 11, 2048 - 21, 0 }, { 1, 2, 3, 4, 11, 64 - 21, 0 },
-  { 1, 2, 3, 4, 11, 64 - 21, 0 },   { 1, 2, 3, 4, 11, 256 - 21, 0 },
-  { 1, 2, 3, 4, 11, 256 - 21, 0 },  { 1, 2, 3, 4, 11, 1024 - 21, 0 },
-  { 1, 2, 3, 4, 11, 1024 - 21, 0 },
-};
-
-static INLINE int cost_coeffs(const AV1_COMMON *const cm, MACROBLOCK *x,
-                              int plane, int block, TX_SIZE tx_size,
-                              const SCAN_ORDER *scan_order,
-                              const ENTROPY_CONTEXT *a,
-                              const ENTROPY_CONTEXT *l,
-                              int use_fast_coef_costing) {
-  MACROBLOCKD *const xd = &x->e_mbd;
-  MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
-  const struct macroblock_plane *p = &x->plane[plane];
-  const struct macroblockd_plane *pd = &xd->plane[plane];
-  const PLANE_TYPE type = pd->plane_type;
-  const uint16_t *band_count = &band_count_table[tx_size][1];
-  const int eob = p->eobs[block];
-  const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
-  const TX_SIZE tx_size_ctx = get_txsize_entropy_ctx(tx_size);
-  uint8_t token_cache[MAX_TX_SQUARE];
-  int pt = combine_entropy_contexts(*a, *l);
-  int c, cost;
-  const int16_t *scan = scan_order->scan;
-  const int16_t *nb = scan_order->neighbors;
-  const int ref = is_inter_block(mbmi);
-  int(*head_token_costs)[COEFF_CONTEXTS][TAIL_TOKENS] =
-      x->token_head_costs[tx_size_ctx][type][ref];
-  int(*tail_token_costs)[COEFF_CONTEXTS][TAIL_TOKENS] =
-      x->token_tail_costs[tx_size_ctx][type][ref];
-  const int seg_eob = av1_get_tx_eob(&cm->seg, mbmi->segment_id, tx_size);
-  int8_t eob_val;
-  const int cat6_bits = av1_get_cat6_extrabits_size(tx_size, xd->bd);
-  (void)cm;
-
-  if (eob == 0) {
-    // block zero
-    cost = (*head_token_costs)[pt][0];
-  } else {
-    if (use_fast_coef_costing) {
-      int band_left = *band_count++;
-
-      // dc token
-      int v = qcoeff[0];
-      int16_t prev_t;
-      cost = av1_get_token_cost(v, &prev_t, cat6_bits);
-      eob_val = (eob == 1) ? EARLY_EOB : NO_EOB;
-      cost += av1_get_coeff_token_cost(
-          prev_t, eob_val, 1, (*head_token_costs)[pt], (*tail_token_costs)[pt]);
-
-      token_cache[0] = av1_pt_energy_class[prev_t];
-      ++head_token_costs;
-      ++tail_token_costs;
-
-      // ac tokens
-      for (c = 1; c < eob; c++) {
-        const int rc = scan[c];
-        int16_t t;
-
-        v = qcoeff[rc];
-        cost += av1_get_token_cost(v, &t, cat6_bits);
-        eob_val =
-            (c + 1 == eob) ? (c + 1 == seg_eob ? LAST_EOB : EARLY_EOB) : NO_EOB;
-        cost += av1_get_coeff_token_cost(t, eob_val, 0,
-                                         (*head_token_costs)[!prev_t],
-                                         (*tail_token_costs)[!prev_t]);
-        prev_t = t;
-        if (!--band_left) {
-          band_left = *band_count++;
-          ++head_token_costs;
-          ++tail_token_costs;
-        }
-      }
-    } else {  // !use_fast_coef_costing
-      int band_left = *band_count++;
-
-      // dc token
-      int v = qcoeff[0];
-      int16_t tok;
-      cost = av1_get_token_cost(v, &tok, cat6_bits);
-      eob_val = (eob == 1) ? EARLY_EOB : NO_EOB;
-      cost += av1_get_coeff_token_cost(tok, eob_val, 1, (*head_token_costs)[pt],
-                                       (*tail_token_costs)[pt]);
-
-      token_cache[0] = av1_pt_energy_class[tok];
-      ++head_token_costs;
-      ++tail_token_costs;
-
-      // ac tokens
-      for (c = 1; c < eob; c++) {
-        const int rc = scan[c];
-
-        v = qcoeff[rc];
-        cost += av1_get_token_cost(v, &tok, cat6_bits);
-        pt = get_coef_context(nb, token_cache, c);
-        eob_val =
-            (c + 1 == eob) ? (c + 1 == seg_eob ? LAST_EOB : EARLY_EOB) : NO_EOB;
-        cost += av1_get_coeff_token_cost(
-            tok, eob_val, 0, (*head_token_costs)[pt], (*tail_token_costs)[pt]);
-        token_cache[rc] = av1_pt_energy_class[tok];
-        if (!--band_left) {
-          band_left = *band_count++;
-          ++head_token_costs;
-          ++tail_token_costs;
-        }
-      }
-    }
-  }
-
-  return cost;
-}
-#endif  // !CONFIG_LV_MAP
-
 static INLINE int av1_cost_coeffs(const struct AV1_COMP *const cpi,
                                   MACROBLOCK *x, int plane, int blk_row,
                                   int blk_col, int block, TX_SIZE tx_size,
@@ -218,12 +90,6 @@
   aom_usec_timer_start(&timer);
 #endif
   const AV1_COMMON *const cm = &cpi->common;
-#if !CONFIG_LV_MAP
-  (void)blk_row;
-  (void)blk_col;
-  int cost = cost_coeffs(cm, x, plane, block, tx_size, scan_order, a, l,
-                         use_fast_coef_costing);
-#else   // !CONFIG_LV_MAP
   (void)scan_order;
   (void)use_fast_coef_costing;
   const MACROBLOCKD *xd = &x->e_mbd;
@@ -245,7 +111,6 @@
         &x->coeff_costs[txs_ctx][plane_type];
     cost = coeff_costs->txb_skip_cost[txb_ctx.txb_skip_ctx][1];
   }
-#endif  // !CONFIG_LV_MAP
 #if TXCOEFF_COST_TIMER
   AV1_COMMON *tmp_cm = (AV1_COMMON *)&cpi->common;
   aom_usec_timer_mark(&timer);
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 1a246d5..3075a07 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -154,10 +154,10 @@
 #if CONFIG_DUAL_FILTER
     sf->use_fast_interpolation_filter_search = 1;
 #endif  // CONFIG_DUAL_FILTER
-#if 0   // CONFIG_HASH_ME && CONFIG_LV_MAP
+#if 0   // CONFIG_HASH_ME
     // TODO(mfo): Activate feature once it gives positive results.
     sf->use_hash_based_trellis = 1;
-#endif  // CONFIG_HASH_ME && CONFIG_LV_MAP
+#endif  // CONFIG_HASH_ME
     sf->tx_type_search.skip_tx_search = 1;
   }
 
diff --git a/av1/encoder/tokenize.c b/av1/encoder/tokenize.c
index ff6bcd4..f41449d 100644
--- a/av1/encoder/tokenize.c
+++ b/av1/encoder/tokenize.c
@@ -23,9 +23,7 @@
 
 #include "av1/encoder/cost.h"
 #include "av1/encoder/encoder.h"
-#if CONFIG_LV_MAP
 #include "av1/encoder/encodetxb.h"
-#endif
 #include "av1/encoder/rdopt.h"
 #include "av1/encoder/tokenize.h"
 
@@ -498,7 +496,6 @@
 
   if (tx_size == plane_tx_size || plane) {
     plane_bsize = get_plane_block_size(mbmi->sb_type, pd);
-#if CONFIG_LV_MAP
     if (!dry_run) {
       av1_update_and_record_txb_context(plane, block, blk_row, blk_col,
                                         plane_bsize, tx_size, arg);
@@ -509,15 +506,6 @@
       printf("DRY_RUN_COSTCOEFFS is not supported yet\n");
       assert(0);
     }
-#else
-    if (!dry_run)
-      tokenize_b(plane, block, blk_row, blk_col, plane_bsize, tx_size, arg);
-    else if (dry_run == DRY_RUN_NORMAL)
-      set_entropy_context_b(plane, block, blk_row, blk_col, plane_bsize,
-                            tx_size, arg);
-    else if (dry_run == DRY_RUN_COSTCOEFFS)
-      cost_coeffs_b(plane, block, blk_row, blk_col, plane_bsize, tx_size, arg);
-#endif
   } else {
     // Half the block size in transform block unit.
     const TX_SIZE sub_txs = sub_tx_size_map[1][tx_size];
@@ -551,37 +539,19 @@
   MACROBLOCK *const x = &td->mb;
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
-#if CONFIG_LV_MAP
   (void)t;
-#else
-  TOKENEXTRA *t_backup = *t;
-#endif
   struct tokenize_b_args arg = { cpi, td, t, 0, allow_update_cdf };
   if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return;
 
   if (mbmi->skip) {
     av1_reset_skip_context(xd, mi_row, mi_col, bsize, num_planes);
-#if !CONFIG_LV_MAP
-    if (dry_run) *t = t_backup;
-#endif
     return;
   }
 
-#if !CONFIG_LV_MAP
-  else
-    *t = t_backup;
-#endif
-
   for (int plane = 0; plane < num_planes; ++plane) {
     if (!is_chroma_reference(mi_row, mi_col, bsize,
                              xd->plane[plane].subsampling_x,
                              xd->plane[plane].subsampling_y)) {
-#if !CONFIG_LV_MAP
-      if (!dry_run) {
-        (*t)->token = EOSB_TOKEN;
-        (*t)++;
-      }
-#endif
       continue;
     }
     const struct macroblockd_plane *const pd = &xd->plane[plane];
@@ -622,12 +592,6 @@
         }
       }
     }
-#if !CONFIG_LV_MAP
-    if (!dry_run) {
-      (*t)->token = EOSB_TOKEN;
-      (*t)++;
-    }
-#endif
   }
   if (rate) *rate += arg.this_rate;
 }