Merge "Handling frame references and scale factors in one for loop." into experimental
diff --git a/configure b/configure
index 5c015b3..a799be0 100755
--- a/configure
+++ b/configure
@@ -247,7 +247,6 @@
     loop_dering
     scatterscan
     oneshotq
-    sbsegment
     multiple_arf
     code_zerogroup
     sb8x8
diff --git a/vp9/common/vp9_blockd.c b/vp9/common/vp9_blockd.c
index 6a68f6e..d06e1b2 100644
--- a/vp9/common/vp9_blockd.c
+++ b/vp9/common/vp9_blockd.c
@@ -60,7 +60,6 @@
 
 #define S(x) x + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT)
 
-#if CONFIG_SBSEGMENT
 const uint8_t vp9_block2left_sb16x32[TX_SIZE_MAX_MB][48] = {
   { 0, 0, 0, 0,
     1, 1, 1, 1,
@@ -190,7 +189,6 @@
     0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0 },
 };
-#endif
 
 const uint8_t vp9_block2left_sb[TX_SIZE_MAX_SB][96] = {
   { 0, 0, 0, 0, 0, 0, 0, 0,
@@ -312,7 +310,6 @@
 #define T(x) x + 2 * (sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT))
 #define U(x) x + 3 * (sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT))
 
-#if CONFIG_SBSEGMENT
 const uint8_t vp9_block2left_sb32x64[TX_SIZE_MAX_SB][192] = {
   { 0, 0, 0, 0, 0, 0, 0, 0,
     1, 1, 1, 1, 1, 1, 1, 1,
@@ -656,7 +653,6 @@
     T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0),
     T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0) },
 };
-#endif
 
 const uint8_t vp9_block2left_sb64[TX_SIZE_MAX_SB][384] = {
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h
index 1e55bed..b03e354 100644
--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -202,18 +202,12 @@
 
 static INLINE int mb_width_log2(BLOCK_SIZE_TYPE sb_type) {
   switch (sb_type) {
-#if CONFIG_SBSEGMENT
-    case BLOCK_SIZE_SB16X32:
-#endif
-    case BLOCK_SIZE_MB16X16: return 0;
-#if CONFIG_SBSEGMENT
+    case BLOCK_SIZE_MB16X16:
+    case BLOCK_SIZE_SB16X32: return 0;
     case BLOCK_SIZE_SB32X16:
     case BLOCK_SIZE_SB32X64:
-#endif
     case BLOCK_SIZE_SB32X32: return 1;
-#if CONFIG_SBSEGMENT
     case BLOCK_SIZE_SB64X32:
-#endif
     case BLOCK_SIZE_SB64X64: return 2;
     default: assert(0);
   }
@@ -221,18 +215,12 @@
 
 static INLINE int mb_height_log2(BLOCK_SIZE_TYPE sb_type) {
   switch (sb_type) {
-#if CONFIG_SBSEGMENT
-    case BLOCK_SIZE_SB32X16:
-#endif
-    case BLOCK_SIZE_MB16X16: return 0;
-#if CONFIG_SBSEGMENT
+    case BLOCK_SIZE_MB16X16:
+    case BLOCK_SIZE_SB32X16: return 0;
     case BLOCK_SIZE_SB16X32:
     case BLOCK_SIZE_SB64X32:
-#endif
     case BLOCK_SIZE_SB32X32: return 1;
-#if CONFIG_SBSEGMENT
     case BLOCK_SIZE_SB32X64:
-#endif
     case BLOCK_SIZE_SB64X64: return 2;
     default: assert(0);
   }
@@ -431,12 +419,11 @@
   /* Inverse transform function pointers. */
   void (*inv_txm4x4_1)(int16_t *input, int16_t *output, int pitch);
   void (*inv_txm4x4)(int16_t *input, int16_t *output, int pitch);
-  void (*itxm_add)(int16_t *input, const int16_t *dq, uint8_t *dest,
-    int stride, int eob);
-  void (*itxm_add_y_block)(int16_t *q, const int16_t *dq,
-    uint8_t *dst, int stride, struct macroblockd *xd);
-  void (*itxm_add_uv_block)(int16_t *q, const int16_t *dq,
-    uint8_t *dst, int stride, uint16_t *eobs);
+  void (*itxm_add)(int16_t *input, uint8_t *dest, int stride, int eob);
+  void (*itxm_add_y_block)(int16_t *q, uint8_t *dst, int stride,
+    struct macroblockd *xd);
+  void (*itxm_add_uv_block)(int16_t *q, uint8_t *dst, int stride,
+    uint16_t *eobs);
 
   struct subpix_fn_table  subpix;
 
@@ -470,7 +457,6 @@
       xd->left_seg_context[i] = ~(0xf << boffset);
     for (i = 0; i < bs; i++)
       xd->above_seg_context[i] = ~(0xf << boffset);
-#if CONFIG_SBSEGMENT
   } else if ((bwl == bsl) && (bhl < bsl)) {
     for (i = 0; i < bs; i++)
       xd->left_seg_context[i] = ~(0xe << boffset);
@@ -481,7 +467,6 @@
       xd->left_seg_context[i] = ~(0xf << boffset);
     for (i = 0; i < bs; i++)
       xd->above_seg_context[i] = ~(0xe << boffset);
-#endif
   } else if ((bwl < bsl) && (bhl < bsl)) {
     for (i = 0; i < bs; i++)
       xd->left_seg_context[i] = ~(0xe << boffset);
@@ -571,7 +556,6 @@
 extern const uint8_t vp9_block2above_sb[TX_SIZE_MAX_SB][96];
 extern const uint8_t vp9_block2left_sb64[TX_SIZE_MAX_SB][384];
 extern const uint8_t vp9_block2above_sb64[TX_SIZE_MAX_SB][384];
-#if CONFIG_SBSEGMENT
 extern const uint8_t vp9_block2left_sb16x32[TX_SIZE_MAX_MB][48];
 extern const uint8_t vp9_block2above_sb16x32[TX_SIZE_MAX_MB][48];
 extern const uint8_t vp9_block2left_sb32x16[TX_SIZE_MAX_MB][48];
@@ -580,7 +564,6 @@
 extern const uint8_t vp9_block2above_sb32x64[TX_SIZE_MAX_SB][192];
 extern const uint8_t vp9_block2left_sb64x32[TX_SIZE_MAX_SB][192];
 extern const uint8_t vp9_block2above_sb64x32[TX_SIZE_MAX_SB][192];
-#endif
 
 #define USE_ADST_FOR_I16X16_8X8   1
 #define USE_ADST_FOR_I16X16_4X4   1
@@ -786,10 +769,8 @@
   switch (mbmi->sb_type) {
     case BLOCK_SIZE_SB64X64:
       return size;
-#if CONFIG_SBSEGMENT
     case BLOCK_SIZE_SB64X32:
     case BLOCK_SIZE_SB32X64:
-#endif
     case BLOCK_SIZE_SB32X32:
       if (size == TX_32X32)
         return TX_16X16;
diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c
index fc93c99..626c7d4 100644
--- a/vp9/common/vp9_entropymode.c
+++ b/vp9/common/vp9_entropymode.c
@@ -151,7 +151,6 @@
 
 const vp9_prob vp9_mbsplit_probs [VP9_NUMMBSPLITS - 1] = { 110, 111, 150};
 
-#if CONFIG_SBSEGMENT
 const vp9_prob vp9_partition_probs[NUM_PARTITION_CONTEXTS]
                                   [PARTITION_TYPES - 1] = {
   {202, 162, 107},
@@ -163,13 +162,6 @@
   {67,  208,  22},
   {4,   17,   5},
 };
-#else
-const vp9_prob vp9_partition_probs[NUM_PARTITION_CONTEXTS]
-                                  [PARTITION_TYPES - 1] = {
-  {200}, {200}, {200}, {200},
-  {200}, {200}, {200}, {200},
-};
-#endif
 
 /* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */
 
@@ -303,17 +295,11 @@
   -ZERO4X4, -NEW4X4
 };
 
-#if CONFIG_SBSEGMENT
 const vp9_tree_index vp9_partition_tree[6] = {
   -PARTITION_NONE, 2,
   -PARTITION_HORZ, 4,
   -PARTITION_VERT, -PARTITION_SPLIT
 };
-#else
-const vp9_tree_index vp9_partition_tree[2] = {
-  -PARTITION_NONE, -PARTITION_SPLIT
-};
-#endif
 
 struct vp9_token vp9_bmode_encodings[VP9_NKF_BINTRAMODES];
 struct vp9_token vp9_kf_bmode_encodings[VP9_KF_BINTRAMODES];
diff --git a/vp9/common/vp9_enums.h b/vp9/common/vp9_enums.h
index d9a6721..23ed3e1 100644
--- a/vp9/common/vp9_enums.h
+++ b/vp9/common/vp9_enums.h
@@ -16,30 +16,22 @@
 typedef enum BLOCK_SIZE_TYPE {
 #if CONFIG_SB8X8
   BLOCK_SIZE_SB8X8,
-#if CONFIG_SBSEGMENT
   BLOCK_SIZE_SB8X16,
   BLOCK_SIZE_SB16X8,
 #endif
-#endif
   BLOCK_SIZE_MB16X16,
-#if CONFIG_SBSEGMENT
   BLOCK_SIZE_SB16X32,
   BLOCK_SIZE_SB32X16,
-#endif
   BLOCK_SIZE_SB32X32,
-#if CONFIG_SBSEGMENT
   BLOCK_SIZE_SB32X64,
   BLOCK_SIZE_SB64X32,
-#endif
   BLOCK_SIZE_SB64X64,
 } BLOCK_SIZE_TYPE;
 
 typedef enum PARTITION_TYPE {
   PARTITION_NONE,
-#if CONFIG_SBSEGMENT
   PARTITION_HORZ,
   PARTITION_VERT,
-#endif
   PARTITION_SPLIT,
   PARTITION_TYPES
 } PARTITION_TYPE;
diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h
index 730021a..839d5a8 100644
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -343,24 +343,18 @@
   return (cm->mb_cols + 3) & ~3;
 }
 
-// TODO(debargha): merge the two functions
-static void set_mb_row(VP9_COMMON *cm, MACROBLOCKD *xd,
-                       int mb_row, int block_size) {
+static void set_mb_row_col(VP9_COMMON *cm, MACROBLOCKD *xd,
+                       int mb_row, int bh,
+                       int mb_col, int bw) {
   xd->mb_to_top_edge    = -((mb_row * 16) << 3);
-  xd->mb_to_bottom_edge = ((cm->mb_rows - block_size - mb_row) * 16) << 3;
+  xd->mb_to_bottom_edge = ((cm->mb_rows - bh - mb_row) * 16) << 3;
+  xd->mb_to_left_edge   = -((mb_col * 16) << 3);
+  xd->mb_to_right_edge  = ((cm->mb_cols - bw - mb_col) * 16) << 3;
 
   // Are edges available for intra prediction?
   xd->up_available    = (mb_row != 0);
-}
-
-static void set_mb_col(VP9_COMMON *cm, MACROBLOCKD *xd,
-                       int mb_col, int block_size) {
-  xd->mb_to_left_edge   = -((mb_col * 16) << 3);
-  xd->mb_to_right_edge  = ((cm->mb_cols - block_size - mb_col) * 16) << 3;
-
-  // Are edges available for intra prediction?
   xd->left_available  = (mb_col > cm->cur_tile_mb_col_start);
-  xd->right_available = (mb_col + block_size < cm->cur_tile_mb_col_end);
+  xd->right_available = (mb_col + bw < cm->cur_tile_mb_col_end);
 }
 
 static int get_mb_row(const MACROBLOCKD *xd) {
diff --git a/vp9/common/vp9_pred_common.c b/vp9/common/vp9_pred_common.c
index 6376bcd..c12920c 100644
--- a/vp9/common/vp9_pred_common.c
+++ b/vp9/common/vp9_pred_common.c
@@ -66,7 +66,7 @@
                     VP9_SWITCHABLE_FILTERS;
 
       // above
-      const int above_in_image = above_mi->mbmi.mb_in_image;
+      const int above_in_image = xd->up_available && above_mi->mbmi.mb_in_image;
       const int above_mv_pred = above_mi->mbmi.mode >= NEARESTMV &&
                                 above_mi->mbmi.mode <= SPLITMV;
       const int above_interp = above_in_image && above_mv_pred ?
diff --git a/vp9/common/vp9_reconintra.c b/vp9/common/vp9_reconintra.c
index 4e786b0..23fc552 100644
--- a/vp9/common/vp9_reconintra.c
+++ b/vp9/common/vp9_reconintra.c
@@ -310,7 +310,6 @@
         ypred_ptr += y_stride;
       }
       break;
-#if CONFIG_SBSEGMENT
     case D45_PRED:
     case D135_PRED:
     case D117_PRED:
@@ -319,7 +318,6 @@
     case D63_PRED:
       if (bw == bh) {
         switch (mode) {
-#endif
           case D45_PRED:
             d45_predictor(ypred_ptr, y_stride, bw, bh,  yabove_row, yleft_col);
             break;
@@ -338,7 +336,6 @@
           case D63_PRED:
             d63_predictor(ypred_ptr, y_stride, bw, bh,  yabove_row, yleft_col);
             break;
-#if CONFIG_SBSEGMENT
           default:
             assert(0);
         }
@@ -398,7 +395,6 @@
           memcpy(ypred_ptr + y_stride * i, pred + i * 64, bw);
       }
       break;
-#endif
     default:
       break;
   }
diff --git a/vp9/common/vp9_rtcd_defs.sh b/vp9/common/vp9_rtcd_defs.sh
index 61a2de4..d909f87 100644
--- a/vp9/common/vp9_rtcd_defs.sh
+++ b/vp9/common/vp9_rtcd_defs.sh
@@ -27,26 +27,26 @@
 #
 # Dequant
 #
-prototype void vp9_dequant_idct_add_y_block_8x8 "int16_t *q, const int16_t *dq, uint8_t *dst, int stride, struct macroblockd *xd"
-specialize vp9_dequant_idct_add_y_block_8x8
+prototype void vp9_idct_add_y_block_8x8 "int16_t *q, uint8_t *dst, int stride, struct macroblockd *xd"
+specialize vp9_idct_add_y_block_8x8
 
-prototype void vp9_dequant_idct_add_16x16 "int16_t *input, const int16_t *dq, uint8_t *dest, int stride, int eob"
-specialize vp9_dequant_idct_add_16x16
+prototype void vp9_idct_add_16x16 "int16_t *input, uint8_t *dest, int stride, int eob"
+specialize vp9_idct_add_16x16
 
-prototype void vp9_dequant_idct_add_8x8 "int16_t *input, const int16_t *dq, uint8_t *dest, int stride, int eob"
-specialize vp9_dequant_idct_add_8x8
+prototype void vp9_idct_add_8x8 "int16_t *input, uint8_t *dest, int stride, int eob"
+specialize vp9_idct_add_8x8
 
-prototype void vp9_dequant_idct_add "int16_t *input, const int16_t *dq, uint8_t *dest, int stride, int eob"
-specialize vp9_dequant_idct_add
+prototype void vp9_idct_add "int16_t *input, uint8_t *dest, int stride, int eob"
+specialize vp9_idct_add
 
-prototype void vp9_dequant_idct_add_y_block "int16_t *q, const int16_t *dq, uint8_t *dst, int stride, struct macroblockd *xd"
-specialize vp9_dequant_idct_add_y_block
+prototype void vp9_idct_add_y_block "int16_t *q, uint8_t *dst, int stride, struct macroblockd *xd"
+specialize vp9_idct_add_y_block
 
-prototype void vp9_dequant_idct_add_uv_block "int16_t *q, const int16_t *dq, uint8_t *dst, int stride, uint16_t *eobs"
-specialize vp9_dequant_idct_add_uv_block
+prototype void vp9_idct_add_uv_block "int16_t *q, uint8_t *dst, int stride, uint16_t *eobs"
+specialize vp9_idct_add_uv_block
 
-prototype void vp9_dequant_idct_add_32x32 "int16_t *q, const int16_t *dq, uint8_t *dst, int stride, int eob"
-specialize vp9_dequant_idct_add_32x32
+prototype void vp9_idct_add_32x32 "int16_t *q, uint8_t *dst, int stride, int eob"
+specialize vp9_idct_add_32x32
 
 #
 # RECON
@@ -306,8 +306,6 @@
 # variance
 [ $arch = "x86_64" ] && mmx_x86_64=mmx && sse2_x86_64=sse2
 
-if [ "$CONFIG_SBSEGMENT" = "yes" ]; then
-
 prototype unsigned int vp9_variance32x16 "const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse"
 specialize vp9_variance32x16
 
@@ -320,8 +318,6 @@
 prototype unsigned int vp9_variance32x64 "const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse"
 specialize vp9_variance32x64
 
-fi
-
 prototype unsigned int vp9_variance32x32 "const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse"
 specialize vp9_variance32x32
 
@@ -356,8 +352,6 @@
 prototype unsigned int vp9_sub_pixel_variance64x64 "const uint8_t *src_ptr, int source_stride, int xoffset, int  yoffset, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse"
 specialize vp9_sub_pixel_variance64x64 sse2
 
-if [ "$CONFIG_SBSEGMENT" = "yes" ]; then
-
 prototype unsigned int vp9_sub_pixel_variance32x64 "const uint8_t *src_ptr, int source_stride, int xoffset, int  yoffset, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse"
 specialize vp9_sub_pixel_variance32x64
 
@@ -370,8 +364,6 @@
 prototype unsigned int vp9_sub_pixel_variance16x32 "const uint8_t *src_ptr, int source_stride, int xoffset, int  yoffset, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse"
 specialize vp9_sub_pixel_variance16x32
 
-fi
-
 prototype unsigned int vp9_sub_pixel_variance32x32 "const uint8_t *src_ptr, int source_stride, int xoffset, int  yoffset, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse"
 specialize vp9_sub_pixel_variance32x32 sse2
 
@@ -398,8 +390,6 @@
 prototype unsigned int vp9_sad64x64 "const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, int  ref_stride, unsigned int max_sad"
 specialize vp9_sad64x64 sse2
 
-if [ "$CONFIG_SBSEGMENT" = "yes" ]; then
-
 prototype unsigned int vp9_sad32x64 "const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int max_sad"
 specialize vp9_sad32x64 sse2
 
@@ -412,8 +402,6 @@
 prototype unsigned int vp9_sad16x32 "const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int max_sad"
 specialize vp9_sad16x32 sse2
 
-fi
-
 prototype unsigned int vp9_sad32x32 "const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, int  ref_stride, unsigned int max_sad"
 specialize vp9_sad32x32 sse2
 
@@ -507,8 +495,6 @@
 prototype void vp9_sad64x64x4d "const uint8_t *src_ptr, int  src_stride, const uint8_t* const ref_ptr[], int  ref_stride, unsigned int *sad_array"
 specialize vp9_sad64x64x4d sse2
 
-if [ "$CONFIG_SBSEGMENT" = "yes" ]; then
-
 prototype void vp9_sad32x64x4d "const uint8_t *src_ptr, int  src_stride, const uint8_t* const ref_ptr[], int  ref_stride, unsigned int *sad_array"
 specialize vp9_sad32x64x4d sse2
 
@@ -521,8 +507,6 @@
 prototype void vp9_sad16x32x4d "const uint8_t *src_ptr, int  src_stride, const uint8_t* const ref_ptr[], int  ref_stride, unsigned int *sad_array"
 specialize vp9_sad16x32x4d sse2
 
-fi
-
 prototype void vp9_sad32x32x4d "const uint8_t *src_ptr, int  src_stride, const uint8_t* const ref_ptr[], int  ref_stride, unsigned int *sad_array"
 specialize vp9_sad32x32x4d sse2
 
diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c
index a073352..65e81b9 100644
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -620,8 +620,7 @@
   // Distance of Mb to the various image edges.
   // These specified to 8th pel as they are always compared to MV values
   // that are in 1/8th pel units
-  set_mb_row(cm, xd, mb_row, bh);
-  set_mb_col(cm, xd, mb_col, bw);
+  set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw);
 
   mb_to_top_edge = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
   mb_to_bottom_edge = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index d5bfe64..c196dd5 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -216,32 +216,29 @@
     assert(qindex == 0);
     mb->inv_txm4x4_1      = vp9_short_iwalsh4x4_1;
     mb->inv_txm4x4        = vp9_short_iwalsh4x4;
-    mb->itxm_add          = vp9_dequant_idct_add_lossless_c;
-    mb->itxm_add_y_block  = vp9_dequant_idct_add_y_block_lossless_c;
-    mb->itxm_add_uv_block = vp9_dequant_idct_add_uv_block_lossless_c;
+    mb->itxm_add          = vp9_idct_add_lossless_c;
+    mb->itxm_add_y_block  = vp9_idct_add_y_block_lossless_c;
+    mb->itxm_add_uv_block = vp9_idct_add_uv_block_lossless_c;
   } else {
     mb->inv_txm4x4_1      = vp9_short_idct4x4_1;
     mb->inv_txm4x4        = vp9_short_idct4x4;
-    mb->itxm_add          = vp9_dequant_idct_add;
-    mb->itxm_add_y_block  = vp9_dequant_idct_add_y_block;
-    mb->itxm_add_uv_block = vp9_dequant_idct_add_uv_block;
+    mb->itxm_add          = vp9_idct_add;
+    mb->itxm_add_y_block  = vp9_idct_add_y_block;
+    mb->itxm_add_uv_block = vp9_idct_add_uv_block;
   }
 }
 
 static void decode_16x16(MACROBLOCKD *xd) {
   const TX_TYPE tx_type = get_tx_type_16x16(xd, 0);
 
-  vp9_dequant_iht_add_16x16_c(tx_type, xd->plane[0].qcoeff,
-                              xd->block[0].dequant, xd->plane[0].dst.buf,
-                              xd->plane[0].dst.stride, xd->plane[0].eobs[0]);
+  vp9_iht_add_16x16_c(tx_type, xd->plane[0].qcoeff, xd->plane[0].dst.buf,
+                      xd->plane[0].dst.stride, xd->plane[0].eobs[0]);
 
-  vp9_dequant_idct_add_8x8(xd->plane[1].qcoeff, xd->block[16].dequant,
-                           xd->plane[1].dst.buf, xd->plane[1].dst.stride,
-                           xd->plane[1].eobs[0]);
+  vp9_idct_add_8x8(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
+                   xd->plane[1].dst.stride, xd->plane[1].eobs[0]);
 
-  vp9_dequant_idct_add_8x8(xd->plane[2].qcoeff, xd->block[20].dequant,
-                           xd->plane[2].dst.buf, xd->plane[1].dst.stride,
-                           xd->plane[2].eobs[0]);
+  vp9_idct_add_8x8(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
+                   xd->plane[1].dst.stride, xd->plane[2].eobs[0]);
 }
 
 static void decode_8x8(MACROBLOCKD *xd) {
@@ -255,7 +252,6 @@
       int ib = vp9_i8x8_block[i];
       int idx = (ib & 0x02) ? (ib + 2) : ib;
       int16_t *q  = BLOCK_OFFSET(xd->plane[0].qcoeff, idx, 16);
-      int16_t *dq = xd->block[0].dequant;
       uint8_t *dst = *(xd->block[ib].base_dst) + xd->block[ib].dst;
       int stride = xd->plane[0].dst.stride;
       if (mode == I8X8_PRED) {
@@ -264,13 +260,11 @@
         vp9_intra8x8_predict(xd, b, i8x8mode, dst, stride);
       }
       tx_type = get_tx_type_8x8(xd, ib);
-      vp9_dequant_iht_add_8x8_c(tx_type, q, dq, dst, stride,
-                                xd->plane[0].eobs[idx]);
+      vp9_iht_add_8x8_c(tx_type, q, dst, stride, xd->plane[0].eobs[idx]);
     }
   } else {
-    vp9_dequant_idct_add_y_block_8x8(xd->plane[0].qcoeff,
-                                     xd->block[0].dequant, xd->plane[0].dst.buf,
-                                     xd->plane[0].dst.stride, xd);
+    vp9_idct_add_y_block_8x8(xd->plane[0].qcoeff, xd->plane[0].dst.buf,
+                             xd->plane[0].dst.stride, xd);
   }
 
   // chroma
@@ -285,29 +279,27 @@
       vp9_intra_uv4x4_predict(xd, b, i8x8mode, *(b->base_dst) + b->dst,
                               b->dst_stride);
       xd->itxm_add(BLOCK_OFFSET(xd->plane[1].qcoeff, i, 16),
-                   b->dequant, *(b->base_dst) + b->dst, b->dst_stride,
+                   *(b->base_dst) + b->dst, b->dst_stride,
                    xd->plane[1].eobs[i]);
 
       b = &xd->block[20 + i];
       vp9_intra_uv4x4_predict(xd, b, i8x8mode, *(b->base_dst) + b->dst,
                               b->dst_stride);
       xd->itxm_add(BLOCK_OFFSET(xd->plane[2].qcoeff, i, 16),
-                   b->dequant, *(b->base_dst) + b->dst, b->dst_stride,
+                   *(b->base_dst) + b->dst, b->dst_stride,
                    xd->plane[2].eobs[i]);
     }
   } else if (mode == SPLITMV) {
-    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->block[16].dequant,
-         xd->plane[1].dst.buf, xd->plane[1].dst.stride, xd->plane[1].eobs);
-    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->block[16].dequant,
-         xd->plane[2].dst.buf, xd->plane[1].dst.stride, xd->plane[2].eobs);
+    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
+        xd->plane[1].dst.stride, xd->plane[1].eobs);
+    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
+        xd->plane[1].dst.stride, xd->plane[2].eobs);
   } else {
-    vp9_dequant_idct_add_8x8(xd->plane[1].qcoeff, xd->block[16].dequant,
-                             xd->plane[1].dst.buf, xd->plane[1].dst.stride,
-                             xd->plane[1].eobs[0]);
+    vp9_idct_add_8x8(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
+                     xd->plane[1].dst.stride, xd->plane[1].eobs[0]);
 
-    vp9_dequant_idct_add_8x8(xd->plane[2].qcoeff, xd->block[16].dequant,
-                             xd->plane[2].dst.buf, xd->plane[1].dst.stride,
-                             xd->plane[2].eobs[0]);
+    vp9_idct_add_8x8(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
+                     xd->plane[1].dst.stride, xd->plane[2].eobs[0]);
   }
 }
 
@@ -315,13 +307,10 @@
   BLOCKD *const b = &xd->block[idx];
   struct macroblockd_plane *const y = &xd->plane[0];
   if (tx_type != DCT_DCT) {
-    vp9_dequant_iht_add_c(tx_type,
-                          BLOCK_OFFSET(y->qcoeff, idx, 16),
-                          b->dequant, *(b->base_dst) + b->dst,
-                          b->dst_stride, y->eobs[idx]);
+    vp9_iht_add_c(tx_type, BLOCK_OFFSET(y->qcoeff, idx, 16),
+                  *(b->base_dst) + b->dst, b->dst_stride, y->eobs[idx]);
   } else {
-    xd->itxm_add(BLOCK_OFFSET(y->qcoeff, idx, 16),
-                 b->dequant, *(b->base_dst) + b->dst,
+    xd->itxm_add(BLOCK_OFFSET(y->qcoeff, idx, 16), *(b->base_dst) + b->dst,
                  b->dst_stride, y->eobs[idx]);
   }
 }
@@ -348,13 +337,13 @@
       vp9_intra_uv4x4_predict(xd, b, i8x8mode, *(b->base_dst) + b->dst,
                               b->dst_stride);
       xd->itxm_add(BLOCK_OFFSET(xd->plane[1].qcoeff, i, 16),
-                   b->dequant, *(b->base_dst) + b->dst, b->dst_stride,
+                   *(b->base_dst) + b->dst, b->dst_stride,
                    xd->plane[1].eobs[i]);
       b = &xd->block[20 + i];
       vp9_intra_uv4x4_predict(xd, b, i8x8mode, *(b->base_dst) + b->dst,
                               b->dst_stride);
       xd->itxm_add(BLOCK_OFFSET(xd->plane[2].qcoeff, i, 16),
-                   b->dequant, *(b->base_dst) + b->dst, b->dst_stride,
+                   *(b->base_dst) + b->dst, b->dst_stride,
                    xd->plane[2].eobs[i]);
     }
   } else if (mode == I4X4_PRED) {
@@ -365,7 +354,7 @@
       xd->mode_info_context->bmi[i].as_mode.context = b->bmi.as_mode.context =
           vp9_find_bpred_context(xd, b);
       if (!xd->mode_info_context->mbmi.mb_skip_coeff)
-        vp9_decode_coefs_4x4(pbi, xd, r, PLANE_TYPE_Y_WITH_DC, i);
+        vp9_decode_coefs_4x4(pbi, xd, r, PLANE_TYPE_Y_WITH_DC, i, b->dequant);
 #endif
       vp9_intra4x4_predict(xd, b, b_mode, *(b->base_dst) + b->dst,
                            b->dst_stride);
@@ -374,32 +363,29 @@
     }
 #if CONFIG_NEWBINTRAMODES
     if (!xd->mode_info_context->mbmi.mb_skip_coeff)
-      vp9_decode_mb_tokens_4x4_uv(pbi, xd, r);
+      vp9_decode_mb_tokens_4x4_uv(pbi, xd, r, xd->block[16].dequant);
 #endif
     vp9_build_intra_predictors_sbuv_s(xd, BLOCK_SIZE_MB16X16);
-    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->block[16].dequant,
-         xd->plane[1].dst.buf, xd->plane[1].dst.stride, xd->plane[1].eobs);
-    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->block[16].dequant,
-         xd->plane[2].dst.buf, xd->plane[1].dst.stride, xd->plane[2].eobs);
+    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
+        xd->plane[1].dst.stride, xd->plane[1].eobs);
+    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
+        xd->plane[1].dst.stride, xd->plane[2].eobs);
   } else if (mode == SPLITMV || get_tx_type_4x4(xd, 0) == DCT_DCT) {
-    xd->itxm_add_y_block(xd->plane[0].qcoeff,
-                          xd->block[0].dequant,
-                          xd->plane[0].dst.buf, xd->plane[0].dst.stride, xd);
-    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->block[16].dequant,
-         xd->plane[1].dst.buf, xd->plane[1].dst.stride, xd->plane[1].eobs);
-    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->block[16].dequant,
-         xd->plane[2].dst.buf, xd->plane[1].dst.stride, xd->plane[2].eobs);
+    xd->itxm_add_y_block(xd->plane[0].qcoeff, xd->plane[0].dst.buf,
+        xd->plane[0].dst.stride, xd);
+    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
+        xd->plane[1].dst.stride, xd->plane[1].eobs);
+    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
+        xd->plane[1].dst.stride, xd->plane[2].eobs);
   } else {
     for (i = 0; i < 16; i++) {
       tx_type = get_tx_type_4x4(xd, i);
       dequant_add_y(xd, tx_type, i);
     }
-    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->block[16].dequant,
-                          xd->plane[1].dst.buf, xd->plane[1].dst.stride,
-                          xd->plane[1].eobs);
-    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->block[16].dequant,
-                          xd->plane[2].dst.buf, xd->plane[1].dst.stride,
-                          xd->plane[2].eobs);
+    xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->plane[1].dst.buf,
+                          xd->plane[1].dst.stride, xd->plane[1].eobs);
+    xd->itxm_add_uv_block(xd->plane[2].qcoeff, xd->plane[2].dst.buf,
+                          xd->plane[1].dst.stride, xd->plane[2].eobs);
   }
 }
 
@@ -413,11 +399,10 @@
     const int x_idx = n & (bw - 1);
     const int y_idx = n >> bwl;
     const int y_offset = (y_idx * 32) * mb->plane[0].dst.stride + (x_idx * 32);
-    vp9_dequant_idct_add_32x32(BLOCK_OFFSET(mb->plane[0].qcoeff, n, 1024),
-                               mb->block[0].dequant ,
-                               mb->plane[0].dst.buf + y_offset,
-                               mb->plane[0].dst.stride,
-                               mb->plane[0].eobs[n * 64]);
+    vp9_idct_add_32x32(BLOCK_OFFSET(mb->plane[0].qcoeff, n, 1024),
+                       mb->plane[0].dst.buf + y_offset,
+                       mb->plane[0].dst.stride,
+                       mb->plane[0].eobs[n * 64]);
   }
 }
 
@@ -431,16 +416,14 @@
      const int y_idx = n >> (bwl - 1);
      const int uv_offset = (y_idx * 32) * mb->plane[1].dst.stride +
          (x_idx * 32);
-     vp9_dequant_idct_add_32x32(BLOCK_OFFSET(mb->plane[1].qcoeff, n, 1024),
-                                mb->block[16].dequant,
-                                mb->plane[1].dst.buf + uv_offset,
-                                mb->plane[1].dst.stride,
-                                mb->plane[1].eobs[n * 64]);
-     vp9_dequant_idct_add_32x32(BLOCK_OFFSET(mb->plane[2].qcoeff, n, 1024),
-                                mb->block[20].dequant,
-                                mb->plane[2].dst.buf + uv_offset,
-                                mb->plane[1].dst.stride,
-                                mb->plane[2].eobs[n * 64]);
+     vp9_idct_add_32x32(BLOCK_OFFSET(mb->plane[1].qcoeff, n, 1024),
+                        mb->plane[1].dst.buf + uv_offset,
+                        mb->plane[1].dst.stride,
+                        mb->plane[1].eobs[n * 64]);
+     vp9_idct_add_32x32(BLOCK_OFFSET(mb->plane[2].qcoeff, n, 1024),
+                        mb->plane[2].dst.buf + uv_offset,
+                        mb->plane[1].dst.stride,
+                        mb->plane[2].eobs[n * 64]);
   }
 }
 
@@ -456,12 +439,9 @@
     const int y_offset = (y_idx * 16) * mb->plane[0].dst.stride + (x_idx * 16);
     const TX_TYPE tx_type = get_tx_type_16x16(mb,
                                 (y_idx * (4 * bw) + x_idx) * 4);
-    vp9_dequant_iht_add_16x16_c(tx_type,
-                                BLOCK_OFFSET(mb->plane[0].qcoeff, n, 256),
-                                mb->block[0].dequant,
-                                mb->plane[0].dst.buf + y_offset,
-                                mb->plane[0].dst.stride,
-                                mb->plane[0].eobs[n * 16]);
+    vp9_iht_add_16x16_c(tx_type, BLOCK_OFFSET(mb->plane[0].qcoeff, n, 256),
+                        mb->plane[0].dst.buf + y_offset,
+                        mb->plane[0].dst.stride, mb->plane[0].eobs[n * 16]);
   }
 }
 
@@ -477,16 +457,12 @@
     const int x_idx = n & (bw - 1);
     const int y_idx = n >> (bwl - 1);
     const int uv_offset = (y_idx * 16) * mb->plane[1].dst.stride + (x_idx * 16);
-    vp9_dequant_idct_add_16x16(BLOCK_OFFSET(mb->plane[1].qcoeff, n, 256),
-                               mb->block[16].dequant,
-                               mb->plane[1].dst.buf + uv_offset,
-                               mb->plane[1].dst.stride,
-                               mb->plane[1].eobs[n * 16]);
-    vp9_dequant_idct_add_16x16(BLOCK_OFFSET(mb->plane[2].qcoeff, n, 256),
-                               mb->block[20].dequant,
-                               mb->plane[2].dst.buf + uv_offset,
-                               mb->plane[1].dst.stride,
-                               mb->plane[2].eobs[n * 16]);
+    vp9_idct_add_16x16(BLOCK_OFFSET(mb->plane[1].qcoeff, n, 256),
+                       mb->plane[1].dst.buf + uv_offset,
+                       mb->plane[1].dst.stride, mb->plane[1].eobs[n * 16]);
+    vp9_idct_add_16x16(BLOCK_OFFSET(mb->plane[2].qcoeff, n, 256),
+                       mb->plane[2].dst.buf + uv_offset,
+                       mb->plane[1].dst.stride, mb->plane[2].eobs[n * 16]);
   }
 }
 
@@ -504,12 +480,9 @@
     const TX_TYPE tx_type = get_tx_type_8x8(xd,
                                             (y_idx * (2 * bw) + x_idx) * 2);
 
-    vp9_dequant_iht_add_8x8_c(tx_type,
-                              BLOCK_OFFSET(xd->plane[0].qcoeff, n, 64),
-                              xd->block[0].dequant,
-                              xd->plane[0].dst.buf + y_offset,
-                              xd->plane[0].dst.stride,
-                              xd->plane[0].eobs[n * 4]);
+    vp9_iht_add_8x8_c(tx_type, BLOCK_OFFSET(xd->plane[0].qcoeff, n, 64),
+                      xd->plane[0].dst.buf + y_offset, xd->plane[0].dst.stride,
+                      xd->plane[0].eobs[n * 4]);
   }
 }
 
@@ -524,16 +497,12 @@
     const int x_idx = n & (bw - 1);
     const int y_idx = n >> (bwl - 1);
     const int uv_offset = (y_idx * 8) * xd->plane[1].dst.stride + (x_idx * 8);
-    vp9_dequant_idct_add_8x8(BLOCK_OFFSET(xd->plane[1].qcoeff, n, 64),
-                             xd->block[16].dequant,
-                             xd->plane[1].dst.buf + uv_offset,
-                             xd->plane[1].dst.stride,
-                             xd->plane[1].eobs[n * 4]);
-    vp9_dequant_idct_add_8x8(BLOCK_OFFSET(xd->plane[2].qcoeff, n, 64),
-                             xd->block[20].dequant,
-                             xd->plane[2].dst.buf + uv_offset,
-                             xd->plane[1].dst.stride,
-                             xd->plane[2].eobs[n * 4]);
+    vp9_idct_add_8x8(BLOCK_OFFSET(xd->plane[1].qcoeff, n, 64),
+                     xd->plane[1].dst.buf + uv_offset, xd->plane[1].dst.stride,
+                     xd->plane[1].eobs[n * 4]);
+    vp9_idct_add_8x8(BLOCK_OFFSET(xd->plane[2].qcoeff, n, 64),
+                     xd->plane[2].dst.buf + uv_offset, xd->plane[1].dst.stride,
+                     xd->plane[2].eobs[n * 4]);
   }
 }
 
@@ -550,15 +519,12 @@
     const TX_TYPE tx_type = get_tx_type_4x4(xd, n);
     if (tx_type == DCT_DCT) {
       xd->itxm_add(BLOCK_OFFSET(xd->plane[0].qcoeff, n, 16),
-                   xd->block[0].dequant,
                    xd->plane[0].dst.buf + y_offset, xd->plane[0].dst.stride,
                    xd->plane[0].eobs[n]);
     } else {
-      vp9_dequant_iht_add_c(tx_type,
-                            BLOCK_OFFSET(xd->plane[0].qcoeff, n, 16),
-                            xd->block[0].dequant,
-                            xd->plane[0].dst.buf + y_offset,
-                            xd->plane[0].dst.stride, xd->plane[0].eobs[n]);
+      vp9_iht_add_c(tx_type, BLOCK_OFFSET(xd->plane[0].qcoeff, n, 16),
+                    xd->plane[0].dst.buf + y_offset, xd->plane[0].dst.stride,
+                    xd->plane[0].eobs[n]);
     }
   }
 }
@@ -574,11 +540,9 @@
     const int y_idx = n >> (bwl - 1);
     const int uv_offset = (y_idx * 4) * xd->plane[1].dst.stride + (x_idx * 4);
     xd->itxm_add(BLOCK_OFFSET(xd->plane[1].qcoeff, n, 16),
-        xd->block[16].dequant,
         xd->plane[1].dst.buf + uv_offset, xd->plane[1].dst.stride,
         xd->plane[1].eobs[n]);
     xd->itxm_add(BLOCK_OFFSET(xd->plane[2].qcoeff, n, 16),
-        xd->block[20].dequant,
         xd->plane[2].dst.buf + uv_offset, xd->plane[1].dst.stride,
         xd->plane[2].eobs[n]);
   }
@@ -632,7 +596,7 @@
       mb_init_dequantizer(pbi, xd);
 
     // dequantization and idct
-    eobtotal = vp9_decode_tokens(pbi, xd, r, bsize);
+    eobtotal = vp9_decode_tokens(pbi, xd, r, bsize, xd->block[0].dequant);
     if (eobtotal == 0) {  // skip loopfilter
       for (n = 0; n < bw * bh; n++) {
         const int x_idx = n & (bw - 1), y_idx = n >> bwl;
@@ -706,7 +670,8 @@
 #if CONFIG_NEWBINTRAMODES
     if (mode != I4X4_PRED)
 #endif
-      eobtotal = vp9_decode_tokens(pbi, xd, r, BLOCK_SIZE_MB16X16);
+      eobtotal = vp9_decode_tokens(pbi, xd, r, BLOCK_SIZE_MB16X16,
+                                   xd->block[0].dequant);
     }
   }
 
@@ -801,8 +766,7 @@
 
   // Distance of Mb to the various image edges. These are specified to 8th pel
   // as they are always compared to values that are in 1/8th pel units
-  set_mb_row(cm, xd, mb_row, bh);
-  set_mb_col(cm, xd, mb_col, bw);
+  set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw);
 
   xd->plane[0].dst.buf = dst_fb->y_buffer + recon_yoffset;
   xd->plane[1].dst.buf = dst_fb->u_buffer + recon_uvoffset;
@@ -882,7 +846,6 @@
       subsize = bsize;
       decode_modes_b(pbi, mb_row, mb_col, r, subsize);
       break;
-#if CONFIG_SBSEGMENT
     case PARTITION_HORZ:
       subsize = (bsize == BLOCK_SIZE_SB64X64) ? BLOCK_SIZE_SB64X32 :
                                                 BLOCK_SIZE_SB32X16;
@@ -897,7 +860,6 @@
       if ((mb_col + bs) < pc->mb_cols)
         decode_modes_b(pbi, mb_row, mb_col + bs, r, subsize);
       break;
-#endif
     case PARTITION_SPLIT:
       subsize = (bsize == BLOCK_SIZE_SB64X64) ? BLOCK_SIZE_SB32X32 :
                                                 BLOCK_SIZE_MB16X16;
diff --git a/vp9/decoder/vp9_dequantize.c b/vp9/decoder/vp9_dequantize.c
deleted file mode 100644
index 0930201..0000000
--- a/vp9/decoder/vp9_dequantize.c
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-
-#include "vp9_rtcd.h"
-#include "vp9/decoder/vp9_dequantize.h"
-#include "vpx_mem/vpx_mem.h"
-#include "vp9/decoder/vp9_onyxd_int.h"
-#include "vp9/common/vp9_common.h"
-
-
-static void add_residual(const int16_t *diff, uint8_t *dest, int stride,
-                         int width, int height) {
-  int r, c;
-
-  for (r = 0; r < height; r++) {
-    for (c = 0; c < width; c++)
-      dest[c] = clip_pixel(diff[c] + dest[c]);
-
-    dest += stride;
-    diff += width;
-  }
-}
-
-void vp9_add_residual_4x4_c(const int16_t *diff, uint8_t *dest, int stride) {
-  add_residual(diff, dest, stride, 4, 4);
-}
-
-void vp9_add_residual_8x8_c(const int16_t *diff, uint8_t *dest, int stride) {
-  add_residual(diff, dest, stride, 8, 8);
-}
-
-void vp9_add_residual_16x16_c(const int16_t *diff, uint8_t *dest, int stride) {
-  add_residual(diff, dest, stride, 16, 16);
-}
-
-void vp9_add_residual_32x32_c(const int16_t *diff,uint8_t *dest, int stride) {
-  add_residual(diff, dest, stride, 32, 32);
-}
-
-static void add_constant_residual(const int16_t diff, uint8_t *dest, int stride,
-                                  int width, int height) {
-  int r, c;
-
-  for (r = 0; r < height; r++) {
-    for (c = 0; c < width; c++)
-      dest[c] = clip_pixel(diff + dest[c]);
-
-    dest += stride;
-  }
-}
-
-void vp9_add_constant_residual_8x8_c(const int16_t diff, uint8_t *dest,
-                                     int stride) {
-  add_constant_residual(diff, dest, stride, 8, 8);
-}
-
-void vp9_add_constant_residual_16x16_c(const int16_t diff, uint8_t *dest,
-                                       int stride) {
-  add_constant_residual(diff, dest, stride, 16, 16);
-}
-
-void vp9_add_constant_residual_32x32_c(const int16_t diff,  uint8_t *dest,
-                                       int stride) {
-  add_constant_residual(diff, dest, stride, 32, 32);
-}
-
-void vp9_dequant_iht_add_c(TX_TYPE tx_type, int16_t *input,
-                           const int16_t *dq,
-                           uint8_t *dest, int stride, int eob) {
-
-  if (tx_type == DCT_DCT) {
-    vp9_dequant_idct_add(input, dq, dest, stride, eob);
-  } else {
-    int i;
-    DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
-
-    for (i = 0; i < 16; i++)
-      input[i] *= dq[i];
-
-    vp9_short_iht4x4(input, output, 4, tx_type);
-    vpx_memset(input, 0, 32);
-    vp9_add_residual_4x4(output, dest, stride);
-  }
-}
-
-void vp9_dequant_iht_add_8x8_c(TX_TYPE tx_type, int16_t *input,
-                               const int16_t *dq, uint8_t *dest,
-                               int stride, int eob) {
-  if (tx_type == DCT_DCT) {
-    vp9_dequant_idct_add_8x8(input, dq, dest, stride, eob);
-  } else {
-    if (eob > 0) {
-      int i;
-      DECLARE_ALIGNED_ARRAY(16, int16_t, output, 64);
-
-      input[0] *= dq[0];
-      for (i = 1; i < 64; i++)
-        input[i] *= dq[1];
-
-      vp9_short_iht8x8(input, output, 8, tx_type);
-      vpx_memset(input, 0, 128);
-      vp9_add_residual_8x8(output, dest, stride);
-    }
-  }
-}
-
-void vp9_dequant_idct_add_c(int16_t *input, const int16_t *dq, uint8_t *dest,
-                            int stride, int eob) {
-  int i;
-  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
-
-  if (eob > 1) {
-    for (i = 0; i < 16; i++)
-      input[i] *= dq[i];
-
-    // the idct halves ( >> 1) the pitch
-    vp9_short_idct4x4(input, output, 4 << 1);
-    vpx_memset(input, 0, 32);
-    vp9_add_residual_4x4(output, dest, stride);
-  } else {
-    vp9_dc_only_idct_add(input[0]*dq[0], dest, dest, stride, stride);
-    ((int *)input)[0] = 0;
-  }
-}
-
-void vp9_dequant_dc_idct_add_c(int16_t *input, const int16_t *dq, uint8_t *dest,
-                               int stride, int dc) {
-  int i;
-  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
-
-  input[0] = dc;
-
-  for (i = 1; i < 16; i++)
-    input[i] *= dq[i];
-
-  // the idct halves ( >> 1) the pitch
-  vp9_short_idct4x4(input, output, 4 << 1);
-  vpx_memset(input, 0, 32);
-  vp9_add_residual_4x4(output, dest, stride);
-}
-
-void vp9_dequant_idct_add_lossless_c(int16_t *input, const int16_t *dq,
-                                     uint8_t *dest, int stride, int eob) {
-  int i;
-  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
-
-  if (eob > 1) {
-    for (i = 0; i < 16; i++)
-      input[i] *= dq[i];
-
-    vp9_short_iwalsh4x4_c(input, output, 4 << 1);
-    vpx_memset(input, 0, 32);
-    vp9_add_residual_4x4(output, dest, stride);
-  } else {
-    vp9_dc_only_inv_walsh_add(input[0]*dq[0], dest, dest, stride, stride);
-    ((int *)input)[0] = 0;
-  }
-}
-
-void vp9_dequant_dc_idct_add_lossless_c(int16_t *input, const int16_t *dq,
-                                        uint8_t *dest, int stride, int dc) {
-  int i;
-  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
-
-  input[0] = dc;
-
-  for (i = 1; i < 16; i++)
-    input[i] *= dq[i];
-
-  vp9_short_iwalsh4x4_c(input, output, 4 << 1);
-  vpx_memset(input, 0, 32);
-  vp9_add_residual_4x4(output, dest, stride);
-}
-
-void vp9_dequant_idct_add_8x8_c(int16_t *input, const int16_t *dq,
-                                uint8_t *dest, int stride, int eob) {
-  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 64);
-
-  // If dc is 1, then input[0] is the reconstructed value, do not need
-  // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
-  input[0] *= dq[0];
-
-  // The calculation can be simplified if there are not many non-zero dct
-  // coefficients. Use eobs to decide what to do.
-  // TODO(yunqingwang): "eobs = 1" case is also handled in vp9_short_idct8x8_c.
-  // Combine that with code here.
-  if (eob) {
-    if (eob == 1) {
-      // DC only DCT coefficient
-      int16_t in = input[0];
-      int16_t out;
-
-      // Note: the idct1 will need to be modified accordingly whenever
-      // vp9_short_idct8x8_c() is modified.
-      vp9_short_idct1_8x8_c(&in, &out);
-      input[0] = 0;
-
-      vp9_add_constant_residual_8x8(out, dest, stride);
-#if !CONFIG_SCATTERSCAN
-    } else if (eob <= 10) {
-      input[1] *= dq[1];
-      input[2] *= dq[1];
-      input[3] *= dq[1];
-      input[8] *= dq[1];
-      input[9] *= dq[1];
-      input[10] *= dq[1];
-      input[16] *= dq[1];
-      input[17] *= dq[1];
-      input[24] *= dq[1];
-
-      vp9_short_idct10_8x8(input, output, 16);
-
-      input[0] = input[1] = input[2] = input[3] = 0;
-      input[8] = input[9] = input[10] = 0;
-      input[16] = input[17] = 0;
-      input[24] = 0;
-
-      vp9_add_residual_8x8(output, dest, stride);
-#endif
-    } else {
-      int i;
-
-      // recover quantizer for 4 4x4 blocks
-      for (i = 1; i < 64; i++)
-        input[i] *= dq[1];
-
-      // the idct halves ( >> 1) the pitch
-      vp9_short_idct8x8(input, output, 8 << 1);
-      vpx_memset(input, 0, 128);
-      vp9_add_residual_8x8(output, dest, stride);
-    }
-  }
-}
-
-void vp9_dequant_iht_add_16x16_c(TX_TYPE tx_type, int16_t *input,
-                                 const int16_t *dq,
-                                 uint8_t *dest, int stride,
-                                 int eob) {
-  if (tx_type == DCT_DCT) {
-    vp9_dequant_idct_add_16x16(input, dq, dest, stride, eob);
-  } else {
-    DECLARE_ALIGNED_ARRAY(16, int16_t, output, 256);
-
-    if (eob > 0) {
-      int i;
-
-      input[0] *= dq[0];
-      for (i = 1; i < 256; i++)
-        input[i] *= dq[1];
-
-      vp9_short_iht16x16(input, output, 16, tx_type);
-      vpx_memset(input, 0, 512);
-      vp9_add_residual_16x16(output, dest, stride);
-    }
-  }
-}
-
-void vp9_dequant_idct_add_16x16_c(int16_t *input, const int16_t *dq,
-                                  uint8_t *dest, int stride, int eob) {
-  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 256);
-
-  /* The calculation can be simplified if there are not many non-zero dct
-   * coefficients. Use eobs to separate different cases. */
-  if (eob) {
-    if (eob == 1) {
-      /* DC only DCT coefficient. */
-      int16_t in = input[0] * dq[0];
-      int16_t out;
-      /* Note: the idct1 will need to be modified accordingly whenever
-       * vp9_short_idct16x16() is modified. */
-      vp9_short_idct1_16x16_c(&in, &out);
-      input[0] = 0;
-
-      vp9_add_constant_residual_16x16(out, dest, stride);
-#if !CONFIG_SCATTERSCAN
-    } else if (eob <= 10) {
-      input[0] *= dq[0];
-
-      input[1] *= dq[1];
-      input[2] *= dq[1];
-      input[3] *= dq[1];
-      input[16] *= dq[1];
-      input[17] *= dq[1];
-      input[18] *= dq[1];
-      input[32] *= dq[1];
-      input[33] *= dq[1];
-      input[48] *= dq[1];
-
-      // the idct halves ( >> 1) the pitch
-      vp9_short_idct10_16x16(input, output, 32);
-
-      input[0] = input[1] = input[2] = input[3] = 0;
-      input[16] = input[17] = input[18] = 0;
-      input[32] = input[33] = 0;
-      input[48] = 0;
-
-      vp9_add_residual_16x16(output, dest, stride);
-#endif
-    } else {
-      int i;
-
-      input[0] *= dq[0];
-
-      // recover quantizer for 4 4x4 blocks
-      for (i = 1; i < 256; i++)
-        input[i] *= dq[1];
-
-      // the idct halves ( >> 1) the pitch
-      vp9_short_idct16x16(input, output, 16 << 1);
-      vpx_memset(input, 0, 512);
-      vp9_add_residual_16x16(output, dest, stride);
-    }
-  }
-}
-
-void vp9_dequant_idct_add_32x32_c(int16_t *input, const int16_t *dq,
-                                  uint8_t *dest, int stride, int eob) {
-  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 1024);
-
-  if (eob) {
-    input[0] = input[0] * dq[0] / 2;
-    if (eob == 1) {
-      vp9_short_idct1_32x32(input, output);
-      vp9_add_constant_residual_32x32(output[0], dest, stride);
-      input[0] = 0;
-#if !CONFIG_SCATTERSCAN
-    } else if (eob <= 10) {
-      input[1] = input[1] * dq[1] / 2;
-      input[2] = input[2] * dq[1] / 2;
-      input[3] = input[3] * dq[1] / 2;
-      input[32] = input[32] * dq[1] / 2;
-      input[33] = input[33] * dq[1] / 2;
-      input[34] = input[34] * dq[1] / 2;
-      input[64] = input[64] * dq[1] / 2;
-      input[65] = input[65] * dq[1] / 2;
-      input[96] = input[96] * dq[1] / 2;
-
-      // the idct halves ( >> 1) the pitch
-      vp9_short_idct10_32x32(input, output, 64);
-
-      input[0] = input[1] = input[2] = input[3] = 0;
-      input[32] = input[33] = input[34] = 0;
-      input[64] = input[65] = 0;
-      input[96] = 0;
-
-      vp9_add_residual_32x32(output, dest, stride);
-#endif
-    } else {
-      int i;
-      for (i = 1; i < 1024; i++)
-        input[i] = input[i] * dq[1] / 2;
-      vp9_short_idct32x32(input, output, 64);
-      vpx_memset(input, 0, 2048);
-      vp9_add_residual_32x32(output, dest, stride);
-    }
-  }
-}
diff --git a/vp9/decoder/vp9_dequantize.h b/vp9/decoder/vp9_dequantize.h
deleted file mode 100644
index a635a3b..0000000
--- a/vp9/decoder/vp9_dequantize.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-
-#ifndef VP9_DECODER_VP9_DEQUANTIZE_H_
-#define VP9_DECODER_VP9_DEQUANTIZE_H_
-
-#include "vp9/common/vp9_blockd.h"
-
-
-void vp9_dequant_idct_add_lossless_c(int16_t *input, const int16_t *dq,
-                                     unsigned char *dest, int stride, int eob);
-
-void vp9_dequant_dc_idct_add_lossless_c(int16_t *input, const int16_t *dq,
-                                        unsigned char *output, int stride,
-                                        int dc);
-
-void vp9_dequant_dc_idct_add_y_block_lossless_c(int16_t *q,
-                                                const int16_t *dq,
-                                                unsigned char *pre,
-                                                unsigned char *dst,
-                                                int stride,
-                                                const int16_t *dc);
-
-void vp9_dequant_idct_add_y_block_lossless_c(int16_t *q, const int16_t *dq,
-                                             unsigned char *dst, int stride,
-                                             struct macroblockd *xd);
-
-void vp9_dequant_idct_add_uv_block_lossless_c(int16_t *q, const int16_t *dq,
-                                              unsigned char *dst,
-                                              int stride,
-                                              uint16_t *eobs);
-
-void vp9_dequant_iht_add_c(TX_TYPE tx_type, int16_t *input, const int16_t *dq,
-                           unsigned char *dest, int stride, int eob);
-
-void vp9_dequant_iht_add_8x8_c(TX_TYPE tx_type, int16_t *input,
-                               const int16_t *dq,  unsigned char *dest,
-                               int stride, int eob);
-
-void vp9_dequant_iht_add_16x16_c(TX_TYPE tx_type, int16_t *input,
-                                 const int16_t *dq, unsigned char *dest,
-                                 int stride, int eob);
-
-#endif  // VP9_DECODER_VP9_DEQUANTIZE_H_
diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c
index 02ee7c3..fc47225 100644
--- a/vp9/decoder/vp9_detokenize.c
+++ b/vp9/decoder/vp9_detokenize.c
@@ -85,7 +85,7 @@
 
 #define WRITE_COEF_CONTINUE(val, token)                  \
   {                                                      \
-    qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(r, val); \
+    qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(r, val) * dq[c > 0]; \
     INCREMENT_COUNT(token);                              \
     c++;                                                 \
     continue;                                            \
@@ -106,7 +106,7 @@
 static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
                         vp9_reader *r, int block_idx,
                         PLANE_TYPE type, int seg_eob, int16_t *qcoeff_ptr,
-                        TX_SIZE txfm_size) {
+                        TX_SIZE txfm_size, const int16_t *dq) {
   ENTROPY_CONTEXT* const A0 = (ENTROPY_CONTEXT *) xd->above_context;
   ENTROPY_CONTEXT* const L0 = (ENTROPY_CONTEXT *) xd->left_context;
   int aidx, lidx;
@@ -136,25 +136,21 @@
   if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB64X64) {
     aidx = vp9_block2above_sb64[txfm_size][block_idx];
     lidx = vp9_block2left_sb64[txfm_size][block_idx];
-#if CONFIG_SBSEGMENT
   } else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB64X32) {
     aidx = vp9_block2above_sb64x32[txfm_size][block_idx];
     lidx = vp9_block2left_sb64x32[txfm_size][block_idx];
   } else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB32X64) {
     aidx = vp9_block2above_sb32x64[txfm_size][block_idx];
     lidx = vp9_block2left_sb32x64[txfm_size][block_idx];
-#endif
   } else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB32X32) {
     aidx = vp9_block2above_sb[txfm_size][block_idx];
     lidx = vp9_block2left_sb[txfm_size][block_idx];
-#if CONFIG_SBSEGMENT
   } else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB32X16) {
     aidx = vp9_block2above_sb32x16[txfm_size][block_idx];
     lidx = vp9_block2left_sb32x16[txfm_size][block_idx];
   } else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB16X32) {
     aidx = vp9_block2above_sb16x32[txfm_size][block_idx];
     lidx = vp9_block2left_sb16x32[txfm_size][block_idx];
-#endif
   } else {
     aidx = vp9_block2above[txfm_size][block_idx];
     lidx = vp9_block2left[txfm_size][block_idx];
@@ -425,6 +421,7 @@
   MACROBLOCKD *xd;
   vp9_reader *r;
   int *eobtotal;
+  const int16_t *dq;
 };
 static void decode_block(int plane, int block,
                          BLOCK_SIZE_TYPE bsize,
@@ -444,7 +441,7 @@
   const int eob = decode_coefs(arg->pbi, arg->xd, arg->r, old_block_idx,
                                arg->xd->plane[plane].plane_type, seg_eob,
                                BLOCK_OFFSET(qcoeff_base, block, 16),
-                               ss_tx_size);
+                               ss_tx_size, arg->dq);
 
   arg->xd->plane[plane].eobs[block] = eob;
   arg->eobtotal[0] += eob;
@@ -453,9 +450,10 @@
 int vp9_decode_tokens(VP9D_COMP* const pbi,
                          MACROBLOCKD* const xd,
                          vp9_reader *r,
-                         BLOCK_SIZE_TYPE bsize) {
+                         BLOCK_SIZE_TYPE bsize,
+                         const int16_t *dq) {
   int eobtotal = 0;
-  struct decode_block_args args = {pbi, xd, r, &eobtotal};
+  struct decode_block_args args = {pbi, xd, r, &eobtotal, dq};
   foreach_transformed_block(xd, bsize, decode_block, &args);
   return eobtotal;
 }
@@ -463,10 +461,12 @@
 #if CONFIG_NEWBINTRAMODES
 static int decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd,
                             vp9_reader *r,
-                            PLANE_TYPE type, int i, int seg_eob) {
+                            PLANE_TYPE type, int i, int seg_eob,
+                            const int16_t *dq) {
   const struct plane_block_idx pb_idx = plane_block_idx(16, i);
   const int c = decode_coefs(dx, xd, r, i, type, seg_eob,
-      BLOCK_OFFSET(xd->plane[pb_idx.plane].qcoeff, pb_idx.block, 16), TX_4X4);
+      BLOCK_OFFSET(xd->plane[pb_idx.plane].qcoeff, pb_idx.block, 16), TX_4X4,
+      dq);
   xd->plane[pb_idx.plane].eobs[pb_idx.block] = c;
   return c;
 }
@@ -474,30 +474,31 @@
 static int decode_mb_tokens_4x4_uv(VP9D_COMP* const dx,
                                    MACROBLOCKD* const xd,
                                    vp9_reader *r,
-                                   int seg_eob) {
+                                   int seg_eob,
+                                   const int16_t *dq) {
   int i, eobtotal = 0;
 
   // chroma blocks
   for (i = 16; i < 24; i++)
-    eobtotal += decode_coefs_4x4(dx, xd, r, PLANE_TYPE_UV, i, seg_eob);
+    eobtotal += decode_coefs_4x4(dx, xd, r, PLANE_TYPE_UV, i, seg_eob, dq);
 
   return eobtotal;
 }
 
 int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx,
                                 MACROBLOCKD* const xd,
-                                vp9_reader *r) {
+                                vp9_reader *r, const int16_t *dq) {
   const int segment_id = xd->mode_info_context->mbmi.segment_id;
   const int seg_eob = get_eob(xd, segment_id, 16);
 
-  return decode_mb_tokens_4x4_uv(dx, xd, r, seg_eob);
+  return decode_mb_tokens_4x4_uv(dx, xd, r, seg_eob, dq);
 }
 
 int vp9_decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd,
                          vp9_reader *r,
-                         PLANE_TYPE type, int i) {
+                         PLANE_TYPE type, int i, const int16_t *dq) {
   const int segment_id = xd->mode_info_context->mbmi.segment_id;
   const int seg_eob = get_eob(xd, segment_id, 16);
-  return decode_coefs_4x4(dx, xd, r, type, i, seg_eob);
+  return decode_coefs_4x4(dx, xd, r, type, i, seg_eob, dq);
 }
 #endif
diff --git a/vp9/decoder/vp9_detokenize.h b/vp9/decoder/vp9_detokenize.h
index 74352a3..65c7200 100644
--- a/vp9/decoder/vp9_detokenize.h
+++ b/vp9/decoder/vp9_detokenize.h
@@ -17,14 +17,15 @@
 int vp9_decode_tokens(VP9D_COMP* const pbi,
                       MACROBLOCKD* const xd,
                       vp9_reader *r,
-                      BLOCK_SIZE_TYPE bsize);
+                      BLOCK_SIZE_TYPE bsize,
+                      const int16_t *dq);
 
-int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx, MACROBLOCKD* const xd,
-                                vp9_reader *r);
 #if CONFIG_NEWBINTRAMODES
+int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx, MACROBLOCKD* const xd,
+                                vp9_reader *r, const int16_t *dq);
 int vp9_decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd,
                          vp9_reader *r,
-                         PLANE_TYPE type, int i);
+                         PLANE_TYPE type, int i, const int16_t *dq);
 #endif
 
 #endif  // VP9_DECODER_VP9_DETOKENIZE_H_
diff --git a/vp9/decoder/vp9_idct_blk.c b/vp9/decoder/vp9_idct_blk.c
index 7dd503b..73c1c4d 100644
--- a/vp9/decoder/vp9_idct_blk.c
+++ b/vp9/decoder/vp9_idct_blk.c
@@ -10,15 +10,15 @@
 
 #include "vp9_rtcd.h"
 #include "vp9/common/vp9_blockd.h"
-#include "vp9/decoder/vp9_dequantize.h"
+#include "vp9/decoder/vp9_idct_blk.h"
 
-void vp9_dequant_idct_add_y_block_c(int16_t *q, const int16_t *dq,
-                                    uint8_t *dst, int stride, MACROBLOCKD *xd) {
+void vp9_idct_add_y_block_c(int16_t *q, uint8_t *dst, int stride,
+                            MACROBLOCKD *xd) {
   int i, j;
 
   for (i = 0; i < 4; i++) {
     for (j = 0; j < 4; j++) {
-      vp9_dequant_idct_add(q, dq, dst, stride, xd->plane[0].eobs[i * 4  + j]);
+      vp9_idct_add(q, dst, stride, xd->plane[0].eobs[i * 4  + j]);
       q   += 16;
       dst += 4;
     }
@@ -27,13 +27,13 @@
   }
 }
 
-void vp9_dequant_idct_add_uv_block_c(int16_t *q, const int16_t *dq,
-                                     uint8_t *dst, int stride, uint16_t *eobs) {
+void vp9_idct_add_uv_block_c(int16_t *q, uint8_t *dst, int stride,
+                             uint16_t *eobs) {
   int i, j;
 
   for (i = 0; i < 2; i++) {
     for (j = 0; j < 2; j++) {
-      vp9_dequant_idct_add(q, dq, dst, stride, eobs[i * 2 + j]);
+      vp9_idct_add(q, dst, stride, eobs[i * 2 + j]);
       q   += 16;
       dst += 4;
     }
@@ -42,29 +42,25 @@
   }
 }
 
-void vp9_dequant_idct_add_y_block_8x8_c(int16_t *q, const int16_t *dq,
-                                        uint8_t *dst, int stride,
-                                        MACROBLOCKD *xd) {
+void vp9_idct_add_y_block_8x8_c(int16_t *q, uint8_t *dst, int stride,
+                                MACROBLOCKD *xd) {
   uint8_t *origdest = dst;
 
-  vp9_dequant_idct_add_8x8_c(q, dq, dst, stride, xd->plane[0].eobs[0]);
-  vp9_dequant_idct_add_8x8_c(&q[64], dq, origdest + 8, stride,
-                             xd->plane[0].eobs[4]);
-  vp9_dequant_idct_add_8x8_c(&q[128], dq, origdest + 8 * stride, stride,
-                             xd->plane[0].eobs[8]);
-  vp9_dequant_idct_add_8x8_c(&q[192], dq, origdest + 8 * stride + 8, stride,
-                             xd->plane[0].eobs[12]);
+  vp9_idct_add_8x8_c(q, dst, stride, xd->plane[0].eobs[0]);
+  vp9_idct_add_8x8_c(&q[64], origdest + 8, stride, xd->plane[0].eobs[4]);
+  vp9_idct_add_8x8_c(&q[128], origdest + 8 * stride, stride,
+                     xd->plane[0].eobs[8]);
+  vp9_idct_add_8x8_c(&q[192], origdest + 8 * stride + 8, stride,
+                     xd->plane[0].eobs[12]);
 }
 
-void vp9_dequant_idct_add_y_block_lossless_c(int16_t *q, const int16_t *dq,
-                                             uint8_t *dst, int stride,
-                                             MACROBLOCKD *xd) {
+void vp9_idct_add_y_block_lossless_c(int16_t *q, uint8_t *dst, int stride,
+                                     MACROBLOCKD *xd) {
   int i, j;
 
   for (i = 0; i < 4; i++) {
     for (j = 0; j < 4; j++) {
-      vp9_dequant_idct_add_lossless_c(q, dq, dst, stride,
-                                      xd->plane[0].eobs[i * 4 + j]);
+      vp9_idct_add_lossless_c(q, dst, stride, xd->plane[0].eobs[i * 4 + j]);
       q   += 16;
       dst += 4;
     }
@@ -73,14 +69,13 @@
   }
 }
 
-void vp9_dequant_idct_add_uv_block_lossless_c(int16_t *q, const int16_t *dq,
-                                              uint8_t *dst, int stride,
-                                              uint16_t *eobs) {
+void vp9_idct_add_uv_block_lossless_c(int16_t *q, uint8_t *dst, int stride,
+                                      uint16_t *eobs) {
   int i, j;
 
   for (i = 0; i < 2; i++) {
     for (j = 0; j < 2; j++) {
-      vp9_dequant_idct_add_lossless_c(q, dq, dst, stride, eobs[i * 2 + j]);
+      vp9_idct_add_lossless_c(q, dst, stride, eobs[i * 2 + j]);
       q   += 16;
       dst += 4;
     }
@@ -89,3 +84,273 @@
   }
 }
 
+static void add_residual(const int16_t *diff, uint8_t *dest, int stride,
+                         int width, int height) {
+  int r, c;
+
+  for (r = 0; r < height; r++) {
+    for (c = 0; c < width; c++)
+      dest[c] = clip_pixel(diff[c] + dest[c]);
+
+    dest += stride;
+    diff += width;
+  }
+}
+
+void vp9_add_residual_4x4_c(const int16_t *diff, uint8_t *dest, int stride) {
+  add_residual(diff, dest, stride, 4, 4);
+}
+
+void vp9_add_residual_8x8_c(const int16_t *diff, uint8_t *dest, int stride) {
+  add_residual(diff, dest, stride, 8, 8);
+}
+
+void vp9_add_residual_16x16_c(const int16_t *diff, uint8_t *dest, int stride) {
+  add_residual(diff, dest, stride, 16, 16);
+}
+
+void vp9_add_residual_32x32_c(const int16_t *diff, uint8_t *dest, int stride) {
+  add_residual(diff, dest, stride, 32, 32);
+}
+
+static void add_constant_residual(const int16_t diff, uint8_t *dest, int stride,
+                                  int width, int height) {
+  int r, c;
+
+  for (r = 0; r < height; r++) {
+    for (c = 0; c < width; c++)
+      dest[c] = clip_pixel(diff + dest[c]);
+
+    dest += stride;
+  }
+}
+
+void vp9_add_constant_residual_8x8_c(const int16_t diff, uint8_t *dest,
+                                     int stride) {
+  add_constant_residual(diff, dest, stride, 8, 8);
+}
+
+void vp9_add_constant_residual_16x16_c(const int16_t diff, uint8_t *dest,
+                                       int stride) {
+  add_constant_residual(diff, dest, stride, 16, 16);
+}
+
+void vp9_add_constant_residual_32x32_c(const int16_t diff,  uint8_t *dest,
+                                       int stride) {
+  add_constant_residual(diff, dest, stride, 32, 32);
+}
+
+void vp9_iht_add_c(TX_TYPE tx_type, int16_t *input, uint8_t *dest, int stride,
+                   int eob) {
+  if (tx_type == DCT_DCT) {
+    vp9_idct_add(input, dest, stride, eob);
+  } else {
+    DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
+
+    vp9_short_iht4x4(input, output, 4, tx_type);
+    vpx_memset(input, 0, 32);
+    vp9_add_residual_4x4(output, dest, stride);
+  }
+}
+
+void vp9_iht_add_8x8_c(TX_TYPE tx_type, int16_t *input, uint8_t *dest,
+                       int stride, int eob) {
+  if (tx_type == DCT_DCT) {
+    vp9_idct_add_8x8(input, dest, stride, eob);
+  } else {
+    if (eob > 0) {
+      DECLARE_ALIGNED_ARRAY(16, int16_t, output, 64);
+
+      vp9_short_iht8x8(input, output, 8, tx_type);
+      vpx_memset(input, 0, 128);
+      vp9_add_residual_8x8(output, dest, stride);
+    }
+  }
+}
+
+void vp9_idct_add_c(int16_t *input, uint8_t *dest, int stride, int eob) {
+  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
+
+  if (eob > 1) {
+    // the idct halves ( >> 1) the pitch
+    vp9_short_idct4x4(input, output, 4 << 1);
+    vpx_memset(input, 0, 32);
+    vp9_add_residual_4x4(output, dest, stride);
+  } else {
+    vp9_dc_only_idct_add(input[0], dest, dest, stride, stride);
+    ((int *)input)[0] = 0;
+  }
+}
+
+void vp9_dc_idct_add_c(int16_t *input, uint8_t *dest, int stride, int dc) {
+  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
+
+  input[0] = dc;
+
+  // the idct halves ( >> 1) the pitch
+  vp9_short_idct4x4(input, output, 4 << 1);
+  vpx_memset(input, 0, 32);
+  vp9_add_residual_4x4(output, dest, stride);
+}
+
+void vp9_idct_add_lossless_c(int16_t *input, uint8_t *dest, int stride,
+                             int eob) {
+  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
+
+  if (eob > 1) {
+    vp9_short_iwalsh4x4_c(input, output, 4 << 1);
+    vpx_memset(input, 0, 32);
+    vp9_add_residual_4x4(output, dest, stride);
+  } else {
+    vp9_dc_only_inv_walsh_add(input[0], dest, dest, stride, stride);
+    ((int *)input)[0] = 0;
+  }
+}
+
+void vp9_dc_idct_add_lossless_c(int16_t *input, uint8_t *dest,
+                                int stride, int dc) {
+  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16);
+
+  input[0] = dc;
+  vp9_short_iwalsh4x4_c(input, output, 4 << 1);
+  vpx_memset(input, 0, 32);
+  vp9_add_residual_4x4(output, dest, stride);
+}
+
+void vp9_idct_add_8x8_c(int16_t *input, uint8_t *dest, int stride, int eob) {
+  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 64);
+
+  // If dc is 1, then input[0] is the reconstructed value, do not need
+  // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1.
+
+  // The calculation can be simplified if there are not many non-zero dct
+  // coefficients. Use eobs to decide what to do.
+  // TODO(yunqingwang): "eobs = 1" case is also handled in vp9_short_idct8x8_c.
+  // Combine that with code here.
+  if (eob) {
+    if (eob == 1) {
+      // DC only DCT coefficient
+      int16_t in = input[0];
+      int16_t out;
+
+      // Note: the idct1 will need to be modified accordingly whenever
+      // vp9_short_idct8x8_c() is modified.
+      vp9_short_idct1_8x8_c(&in, &out);
+      input[0] = 0;
+
+      vp9_add_constant_residual_8x8(out, dest, stride);
+#if !CONFIG_SCATTERSCAN
+    } else if (eob <= 10) {
+      vp9_short_idct10_8x8(input, output, 16);
+
+      input[0] = input[1] = input[2] = input[3] = 0;
+      input[8] = input[9] = input[10] = 0;
+      input[16] = input[17] = 0;
+      input[24] = 0;
+
+      vp9_add_residual_8x8(output, dest, stride);
+#endif
+    } else {
+      // the idct halves ( >> 1) the pitch
+      vp9_short_idct8x8(input, output, 8 << 1);
+      vpx_memset(input, 0, 128);
+      vp9_add_residual_8x8(output, dest, stride);
+    }
+  }
+}
+
+void vp9_iht_add_16x16_c(TX_TYPE tx_type, int16_t *input, uint8_t *dest,
+                         int stride, int eob) {
+  if (tx_type == DCT_DCT) {
+    vp9_idct_add_16x16(input, dest, stride, eob);
+  } else {
+    DECLARE_ALIGNED_ARRAY(16, int16_t, output, 256);
+
+    if (eob > 0) {
+      vp9_short_iht16x16(input, output, 16, tx_type);
+      vpx_memset(input, 0, 512);
+      vp9_add_residual_16x16(output, dest, stride);
+    }
+  }
+}
+
+void vp9_idct_add_16x16_c(int16_t *input, uint8_t *dest, int stride, int eob) {
+  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 256);
+
+  /* The calculation can be simplified if there are not many non-zero dct
+   * coefficients. Use eobs to separate different cases. */
+  if (eob) {
+    if (eob == 1) {
+      /* DC only DCT coefficient. */
+      int16_t in = input[0];
+      int16_t out;
+      /* Note: the idct1 will need to be modified accordingly whenever
+       * vp9_short_idct16x16() is modified. */
+      vp9_short_idct1_16x16_c(&in, &out);
+      input[0] = 0;
+
+      vp9_add_constant_residual_16x16(out, dest, stride);
+#if !CONFIG_SCATTERSCAN
+    } else if (eob <= 10) {
+      // the idct halves ( >> 1) the pitch
+      vp9_short_idct10_16x16(input, output, 32);
+
+      input[0] = input[1] = input[2] = input[3] = 0;
+      input[16] = input[17] = input[18] = 0;
+      input[32] = input[33] = 0;
+      input[48] = 0;
+
+      vp9_add_residual_16x16(output, dest, stride);
+#endif
+    } else {
+      // the idct halves ( >> 1) the pitch
+      vp9_short_idct16x16(input, output, 16 << 1);
+      vpx_memset(input, 0, 512);
+      vp9_add_residual_16x16(output, dest, stride);
+    }
+  }
+}
+
+void vp9_idct_add_32x32_c(int16_t *input, uint8_t *dest, int stride, int eob) {
+  DECLARE_ALIGNED_ARRAY(16, int16_t, output, 1024);
+
+  if (eob) {
+    input[0] = input[0] / 2;
+    if (eob == 1) {
+      vp9_short_idct1_32x32(input, output);
+      vp9_add_constant_residual_32x32(output[0], dest, stride);
+      input[0] = 0;
+#if !CONFIG_SCATTERSCAN
+    } else if (eob <= 10) {
+      input[1] = input[1] / 2;
+      input[2] = input[2] / 2;
+      input[3] = input[3] / 2;
+      input[32] = input[32] / 2;
+      input[33] = input[33] / 2;
+      input[34] = input[34] / 2;
+      input[64] = input[64] / 2;
+      input[65] = input[65] / 2;
+      input[96] = input[96] / 2;
+
+      // the idct halves ( >> 1) the pitch
+      vp9_short_idct10_32x32(input, output, 64);
+
+      input[0] = input[1] = input[2] = input[3] = 0;
+      input[32] = input[33] = input[34] = 0;
+      input[64] = input[65] = 0;
+      input[96] = 0;
+
+      vp9_add_residual_32x32(output, dest, stride);
+#endif
+    } else {
+      int i;
+      for (i = 1; i < 1024; i++)
+        input[i] = input[i] / 2;
+
+      vp9_short_idct32x32(input, output, 64);
+      vpx_memset(input, 0, 2048);
+      vp9_add_residual_32x32(output, dest, stride);
+    }
+  }
+}
+
diff --git a/vp9/decoder/vp9_idct_blk.h b/vp9/decoder/vp9_idct_blk.h
new file mode 100644
index 0000000..ab4c042
--- /dev/null
+++ b/vp9/decoder/vp9_idct_blk.h
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+
+#ifndef VP9_DECODER_VP9_IDCT_BLK_H_
+#define VP9_DECODER_VP9_IDCT_BLK_H_
+
+#include "vp9/common/vp9_blockd.h"
+
+
+void vp9_idct_add_lossless_c(int16_t *input, unsigned char *dest, int stride,
+                             int eob);
+
+void vp9_dc_idct_add_lossless_c(int16_t *input, unsigned char *output,
+                                int stride, int dc);
+
+void vp9_dc_idct_add_y_block_lossless_c(int16_t *q, unsigned char *pre,
+                                        unsigned char *dst, int stride,
+                                        const int16_t *dc);
+
+void vp9_idct_add_y_block_lossless_c(int16_t *q, unsigned char *dst, int stride,
+                                     struct macroblockd *xd);
+
+void vp9_idct_add_uv_block_lossless_c(int16_t *q, unsigned char *dst,
+                                      int stride, uint16_t *eobs);
+
+void vp9_iht_add_c(TX_TYPE tx_type, int16_t *input, unsigned char *dest,
+                   int stride, int eob);
+
+void vp9_iht_add_8x8_c(TX_TYPE tx_type, int16_t *input, unsigned char *dest,
+                       int stride, int eob);
+
+void vp9_iht_add_16x16_c(TX_TYPE tx_type, int16_t *input, unsigned char *dest,
+                         int stride, int eob);
+
+#endif  // VP9_DECODER_VP9_IDCT_BLK_H_
diff --git a/vp9/decoder/vp9_onyxd_int.h b/vp9/decoder/vp9_onyxd_int.h
index da40bd1..a7d444e 100644
--- a/vp9/decoder/vp9_onyxd_int.h
+++ b/vp9/decoder/vp9_onyxd_int.h
@@ -14,7 +14,7 @@
 #include "vp9/decoder/vp9_onyxd.h"
 #include "vp9/decoder/vp9_treereader.h"
 #include "vp9/common/vp9_onyxc_int.h"
-#include "vp9/decoder/vp9_dequantize.h"
+#include "vp9/decoder/vp9_idct_blk.h"
 
 // #define DEC_DEBUG
 
diff --git a/vp9/decoder/x86/vp9_idct_blk_sse2.c b/vp9/decoder/x86/vp9_idct_blk_sse2.c
index badd97f..ece5803 100644
--- a/vp9/decoder/x86/vp9_idct_blk_sse2.c
+++ b/vp9/decoder/x86/vp9_idct_blk_sse2.c
@@ -10,7 +10,6 @@
 
 #include "./vpx_config.h"
 #include "vp9/common/vp9_blockd.h"
-#include "vp9/decoder/vp9_dequantize.h"
 
 void vp9_idct_dequant_dc_0_2x_sse2(short *q, const short *dq,
                                    unsigned char *pre, unsigned char *dst,
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index 978fdcd..62ee0bb 100644
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -710,8 +710,7 @@
   // These specified to 8th pel as they are always compared to MV
   // values that are in 1/8th pel units
 
-  set_mb_row(pc, xd, mb_row, bh);
-  set_mb_col(pc, xd, mb_col, bw);
+  set_mb_row_col(pc, xd, mb_row, bh, mb_col, bw);
 
 #ifdef ENTROPY_STATS
   active_section = 9;
@@ -1151,8 +1150,9 @@
   MACROBLOCKD *const xd = &cpi->mb.e_mbd;
 
   xd->mode_info_context = m;
-  set_mb_row(&cpi->common, xd, mb_row, 1 << mb_height_log2(m->mbmi.sb_type));
-  set_mb_col(&cpi->common, xd, mb_col, 1 << mb_width_log2(m->mbmi.sb_type));
+  set_mb_row_col(&cpi->common, xd, mb_row,
+                 1 << mb_height_log2(m->mbmi.sb_type),
+                 mb_col, 1 << mb_width_log2(m->mbmi.sb_type));
   if (cm->frame_type == KEY_FRAME) {
     write_mb_modes_kf(cpi, m, bc,
                       cm->mb_rows - mb_row, cm->mb_cols - mb_col);
@@ -1179,9 +1179,7 @@
   MACROBLOCKD *xd = &cpi->mb.e_mbd;
   const int mis = cm->mode_info_stride;
   int bwl, bhl;
-#if CONFIG_SBSEGMENT
   int bw, bh;
-#endif
   int bsl = mb_width_log2(bsize), bs = (1 << bsl) / 2;
   int n;
   PARTITION_TYPE partition;
@@ -1192,20 +1190,16 @@
 
   bwl = mb_width_log2(m->mbmi.sb_type);
   bhl = mb_height_log2(m->mbmi.sb_type);
-#if CONFIG_SBSEGMENT
   bw = 1 << bwl;
   bh = 1 << bhl;
-#endif
 
   // parse the partition type
   if ((bwl == bsl) && (bhl == bsl))
     partition = PARTITION_NONE;
-#if CONFIG_SBSEGMENT
   else if ((bwl == bsl) && (bhl < bsl))
     partition = PARTITION_HORZ;
   else if ((bwl < bsl) && (bhl == bsl))
     partition = PARTITION_VERT;
-#endif
   else if ((bwl < bsl) && (bhl < bsl))
     partition = PARTITION_SPLIT;
   else
@@ -1226,7 +1220,6 @@
       subsize = bsize;
       write_modes_b(cpi, m, bc, tok, tok_end, mb_row, mb_col);
       break;
-#if CONFIG_SBSEGMENT
     case PARTITION_HORZ:
       subsize = (bsize == BLOCK_SIZE_SB64X64) ? BLOCK_SIZE_SB64X32 :
                                                 BLOCK_SIZE_SB32X16;
@@ -1241,7 +1234,6 @@
       if ((mb_col + bw) < cm->mb_cols)
         write_modes_b(cpi, m + bw, bc, tok, tok_end, mb_row, mb_col + bw);
       break;
-#endif
     case PARTITION_SPLIT:
       // TODO(jingning): support recursive partitioning down to 16x16 as for
       // now. need to merge in 16x8, 8x16, 8x8, and smaller partitions.
diff --git a/vp9/encoder/vp9_block.h b/vp9/encoder/vp9_block.h
index eede4cb..ea632b5 100644
--- a/vp9/encoder/vp9_block.h
+++ b/vp9/encoder/vp9_block.h
@@ -152,16 +152,12 @@
   // Structure to hold context for each of the 4 MBs within a SB:
   // when encoded as 4 independent MBs:
   PICK_MODE_CONTEXT mb_context[4][4];
-#if CONFIG_SBSEGMENT
   PICK_MODE_CONTEXT sb32x16_context[4][2];
   PICK_MODE_CONTEXT sb16x32_context[4][2];
-#endif
   // when 4 MBs share coding parameters:
   PICK_MODE_CONTEXT sb32_context[4];
-#if CONFIG_SBSEGMENT
   PICK_MODE_CONTEXT sb32x64_context[2];
   PICK_MODE_CONTEXT sb64x32_context[2];
-#endif
   PICK_MODE_CONTEXT sb64_context;
   int partition_cost[NUM_PARTITION_CONTEXTS][PARTITION_TYPES];
 
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
index 5bc1644..65e6b18 100644
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -579,8 +579,7 @@
 
   // Set up distance of MB to edge of frame in 1/8th pel units
   assert(!(mb_col & (bw - 1)) && !(mb_row & (bh - 1)));
-  set_mb_row(cm, xd, mb_row, bh);
-  set_mb_col(cm, xd, mb_col, bw);
+  set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw);
 
   /* set up source buffers */
   setup_pred_block(&x->src, cpi->Source, mb_row, mb_col, NULL, NULL);
@@ -773,7 +772,6 @@
       (*tp)->token = EOSB_TOKEN;
       (*tp)++;
     }
-#if CONFIG_SBSEGMENT
   } else if (is_sb == BLOCK_SIZE_SB16X32) {
     int i;
 
@@ -810,7 +808,6 @@
         (*tp)++;
       }
     }
-#endif
   } else {
     int i;
     if (output_enabled)
@@ -881,9 +878,7 @@
 
     (*tp)->token = EOSB_TOKEN;
     (*tp)++;
-
     cpi->partition_count[pl][PARTITION_NONE]++;
-#if CONFIG_SBSEGMENT
   } else if (is_sb[0] == BLOCK_SIZE_SB32X64) {
     int i;
 
@@ -912,7 +907,6 @@
       (*tp)->token = EOSB_TOKEN;
       (*tp)++;
     }
-#endif
   } else {
     int i;
     cpi->partition_count[pl][PARTITION_SPLIT]++;
@@ -1021,7 +1015,6 @@
         sb64_skip += splitmodes_used;
       }
 
-#if CONFIG_SBSEGMENT
       // check 32x16
       if (mb_col + x_idx + 1 < cm->mb_cols) {
         int r, d;
@@ -1103,7 +1096,6 @@
         vpx_memcpy(cm->left_context + y_idx, l2, sizeof(l2));
         vpx_memcpy(cm->above_context + mb_col + x_idx, a2, sizeof(a2));
       }
-#endif
 
       if (!sb32_skip && !(mb_col + x_idx + 1 >= cm->mb_cols ||
                           mb_row + y_idx + 1 >= cm->mb_rows)) {
@@ -1155,7 +1147,6 @@
     pl = partition_plane_context(xd, BLOCK_SIZE_SB64X64);
     sb64_rate += x->partition_cost[pl][PARTITION_SPLIT];
 
-#if CONFIG_SBSEGMENT
     // check 64x32
     if (mb_col + 3 < cm->mb_cols && !(cm->mb_rows & 1)) {
       int r, d;
@@ -1235,7 +1226,6 @@
       vpx_memcpy(cm->left_context, l, sizeof(l));
       vpx_memcpy(cm->above_context + mb_col, a, sizeof(a));
     }
-#endif
 
     if (!sb64_skip && !(mb_col + 3 >= cm->mb_cols ||
                         mb_row + 3 >= cm->mb_rows)) {
@@ -1545,7 +1535,6 @@
         reset_skip_txfm_size_sb(cpi, mi, mis, txfm_max,
                                 cm->mb_rows - mb_row, cm->mb_cols - mb_col,
                                 BLOCK_SIZE_SB64X64);
-#if CONFIG_SBSEGMENT
       } else if (mi->mbmi.sb_type == BLOCK_SIZE_SB64X32) {
         reset_skip_txfm_size_sb(cpi, mi, mis, txfm_max,
                                 cm->mb_rows - mb_row, cm->mb_cols - mb_col,
@@ -1564,7 +1553,6 @@
                                   cm->mb_rows - mb_row,
                                   cm->mb_cols - mb_col - 2,
                                   BLOCK_SIZE_SB32X64);
-#endif
       } else {
         int i;
 
@@ -1581,7 +1569,6 @@
                                     cm->mb_rows - mb_row - y_idx_sb,
                                     cm->mb_cols - mb_col - x_idx_sb,
                                     BLOCK_SIZE_SB32X32);
-#if CONFIG_SBSEGMENT
           } else if (sb_mi->mbmi.sb_type == BLOCK_SIZE_SB32X16) {
             reset_skip_txfm_size_sb(cpi, sb_mi, mis, txfm_max,
                                     cm->mb_rows - mb_row - y_idx_sb,
@@ -1602,7 +1589,6 @@
                                       cm->mb_rows - mb_row - y_idx_sb,
                                       cm->mb_cols - mb_col - x_idx_sb - 1,
                                       BLOCK_SIZE_SB16X32);
-#endif
           } else {
             int m;
 
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c
index e441107..6e61250 100644
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -524,15 +524,15 @@
     x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16)
                     + (VP9BORDERINPIXELS - 16);
 
-    set_mb_row(cm, xd, mb_row, 1 << mb_height_log2(BLOCK_SIZE_MB16X16));
-
     // for each macroblock col in image
     for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) {
       int this_error;
       int gf_motion_error = INT_MAX;
       int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row);
 
-      set_mb_col(cm, xd, mb_col, 1 << mb_height_log2(BLOCK_SIZE_MB16X16));
+      set_mb_row_col(cm, xd,
+                     mb_row, 1 << mb_height_log2(BLOCK_SIZE_MB16X16),
+                     mb_col, 1 << mb_height_log2(BLOCK_SIZE_MB16X16));
       xd->plane[0].dst.buf = new_yv12->y_buffer + recon_yoffset;
       xd->plane[1].dst.buf = new_yv12->u_buffer + recon_uvoffset;
       xd->plane[2].dst.buf = new_yv12->v_buffer + recon_uvoffset;
diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index c2c587e..9d693a0 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -1631,7 +1631,6 @@
     cpi->fn_ptr[BT].sdx8f          = SDX8F; \
     cpi->fn_ptr[BT].sdx4df         = SDX4DF;
 
-#if CONFIG_SBSEGMENT
   BFP(BLOCK_32X16, vp9_sad32x16, vp9_variance32x16, vp9_sub_pixel_variance32x16,
       NULL, NULL,
       NULL, NULL, NULL,
@@ -1651,7 +1650,6 @@
       NULL, NULL,
       NULL, NULL, NULL,
       vp9_sad32x64x4d)
-#endif
 
   BFP(BLOCK_32X32, vp9_sad32x32, vp9_variance32x32, vp9_sub_pixel_variance32x32,
       vp9_variance_halfpixvar32x32_h, vp9_variance_halfpixvar32x32_v,
diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h
index 4fff233..a01c7d1 100644
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -280,12 +280,10 @@
   BLOCK_16X16,
   BLOCK_MAX_SEGMENTS,
   BLOCK_32X32 = BLOCK_MAX_SEGMENTS,
-#if CONFIG_SBSEGMENT
   BLOCK_32X16,
   BLOCK_16X32,
   BLOCK_64X32,
   BLOCK_32X64,
-#endif
   BLOCK_64X64,
   BLOCK_MAX_SB_SEGMENTS,
 };
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index f846cf3..c448ce5 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -2779,15 +2779,11 @@
 static enum BlockSize y_to_uv_block_size(enum BlockSize bs) {
   switch (bs) {
     case BLOCK_64X64: return BLOCK_32X32;
-#if CONFIG_SBSEGMENT
     case BLOCK_64X32: return BLOCK_32X16;
     case BLOCK_32X64: return BLOCK_16X32;
-#endif
     case BLOCK_32X32: return BLOCK_16X16;
-#if CONFIG_SBSEGMENT
     case BLOCK_32X16: return BLOCK_16X8;
     case BLOCK_16X32: return BLOCK_8X16;
-#endif
     case BLOCK_16X16: return BLOCK_8X8;
     default:
       assert(0);
@@ -2798,15 +2794,11 @@
 static enum BlockSize y_bsizet_to_block_size(BLOCK_SIZE_TYPE bs) {
   switch (bs) {
     case BLOCK_SIZE_SB64X64: return BLOCK_64X64;
-#if CONFIG_SBSEGMENT
     case BLOCK_SIZE_SB64X32: return BLOCK_64X32;
     case BLOCK_SIZE_SB32X64: return BLOCK_32X64;
-#endif
     case BLOCK_SIZE_SB32X32: return BLOCK_32X32;
-#if CONFIG_SBSEGMENT
     case BLOCK_SIZE_SB32X16: return BLOCK_32X16;
     case BLOCK_SIZE_SB16X32: return BLOCK_16X32;
-#endif
     case BLOCK_SIZE_MB16X16: return BLOCK_16X16;
     default:
       assert(0);
diff --git a/vp9/encoder/vp9_sad_c.c b/vp9/encoder/vp9_sad_c.c
index dbadaea..fa47f81 100644
--- a/vp9/encoder/vp9_sad_c.c
+++ b/vp9/encoder/vp9_sad_c.c
@@ -23,7 +23,6 @@
   return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 64, 64);
 }
 
-#if CONFIG_SBSEGMENT
 unsigned int vp9_sad64x32_c(const uint8_t *src_ptr,
                             int  src_stride,
                             const uint8_t *ref_ptr,
@@ -69,7 +68,6 @@
   sad_array[3] = vp9_sad32x64(src_ptr, src_stride,
                               ref_ptr[3], ref_stride, 0x7fffffff);
 }
-#endif
 
 unsigned int vp9_sad32x32_c(const uint8_t *src_ptr,
                             int  src_stride,
@@ -79,7 +77,6 @@
   return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 32, 32);
 }
 
-#if CONFIG_SBSEGMENT
 unsigned int vp9_sad32x16_c(const uint8_t *src_ptr,
                             int   src_stride,
                             const uint8_t *ref_ptr,
@@ -125,7 +122,6 @@
   sad_array[3] = vp9_sad16x32(src_ptr, src_stride,
                               ref_ptr[3], ref_stride, 0x7fffffff);
 }
-#endif
 
 unsigned int vp9_sad16x16_c(const uint8_t *src_ptr,
                             int  src_stride,
diff --git a/vp9/encoder/vp9_segmentation.c b/vp9/encoder/vp9_segmentation.c
index 56484e6..c243458 100644
--- a/vp9/encoder/vp9_segmentation.c
+++ b/vp9/encoder/vp9_segmentation.c
@@ -133,8 +133,7 @@
   const int segment_id = mi->mbmi.segment_id;
 
   xd->mode_info_context = mi;
-  set_mb_row(cm, xd, mb_row, bh);
-  set_mb_col(cm, xd, mb_col, bw);
+  set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw);
 
   // Count the number of hits on each segment with no prediction
   no_pred_segcounts[segment_id]++;
@@ -205,7 +204,6 @@
         if (mi->mbmi.sb_type == BLOCK_SIZE_SB64X64) {
           count_segs(cpi, mi, no_pred_segcounts, temporal_predictor_count,
                      t_unpred_seg_counts, 4, 4, mb_row, mb_col);
-#if CONFIG_SBSEGMENT
         } else if (mi->mbmi.sb_type == BLOCK_SIZE_SB64X32) {
           count_segs(cpi, mi, no_pred_segcounts, temporal_predictor_count,
                      t_unpred_seg_counts, 4, 2, mb_row, mb_col);
@@ -219,7 +217,6 @@
           if (mb_col + 2 != cm->mb_cols)
             count_segs(cpi, mi + 2, no_pred_segcounts, temporal_predictor_count,
                        t_unpred_seg_counts, 2, 4, mb_row, mb_col + 2);
-#endif
         } else {
           for (i = 0; i < 4; i++) {
             int x_idx = (i & 1) << 1, y_idx = i & 2;
@@ -234,7 +231,6 @@
               count_segs(cpi, sb_mi, no_pred_segcounts,
                          temporal_predictor_count, t_unpred_seg_counts, 2, 2,
                          mb_row + y_idx, mb_col + x_idx);
-#if CONFIG_SBSEGMENT
             } else if (sb_mi->mbmi.sb_type == BLOCK_SIZE_SB32X16) {
               count_segs(cpi, sb_mi, no_pred_segcounts,
                          temporal_predictor_count,
@@ -255,7 +251,6 @@
                            temporal_predictor_count,
                            t_unpred_seg_counts, 1, 2,
                            mb_row + y_idx, mb_col + x_idx + 1);
-#endif
             } else {
               int j;
 
diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c
index 6f2cbbf..0edf126 100644
--- a/vp9/encoder/vp9_tokenize.c
+++ b/vp9/encoder/vp9_tokenize.c
@@ -147,7 +147,6 @@
     l2 = l1 + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
     a3 = a2 + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
     l3 = l2 + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
-#if CONFIG_SBSEGMENT
   } else if (sb_type == BLOCK_SIZE_SB32X64) {
     a = (ENTROPY_CONTEXT *)xd->above_context +
                                           vp9_block2above_sb32x64[tx_size][ib];
@@ -164,14 +163,12 @@
     a1 = a + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
     l1 = l + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
     a2 = a3 = l2 = l3 = NULL;
-#endif
   } else if (sb_type == BLOCK_SIZE_SB32X32) {
     a = (ENTROPY_CONTEXT *)xd->above_context + vp9_block2above_sb[tx_size][ib];
     l = (ENTROPY_CONTEXT *)xd->left_context + vp9_block2left_sb[tx_size][ib];
     a1 = a + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
     l1 = l + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
     a2 = a3 = l2 = l3 = NULL;
-#if CONFIG_SBSEGMENT
   } else if (sb_type == BLOCK_SIZE_SB16X32) {
     a = (ENTROPY_CONTEXT *)xd->above_context +
                                           vp9_block2above_sb16x32[tx_size][ib];
@@ -188,7 +185,6 @@
     a1 = a + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
     l1 = l + sizeof(ENTROPY_CONTEXT_PLANES) / sizeof(ENTROPY_CONTEXT);
     a1 = l1 = a2 = l2 = a3 = l3 = NULL;
-#endif
   } else {
     assert(sb_type == BLOCK_SIZE_MB16X16);
     a = (ENTROPY_CONTEXT *)xd->above_context + vp9_block2above[tx_size][ib];
diff --git a/vp9/encoder/vp9_variance_c.c b/vp9/encoder/vp9_variance_c.c
index fb66f4f..f7916b4 100644
--- a/vp9/encoder/vp9_variance_c.c
+++ b/vp9/encoder/vp9_variance_c.c
@@ -24,7 +24,6 @@
   return sum;
 }
 
-#if CONFIG_SBSEGMENT
 unsigned int vp9_variance64x32_c(const uint8_t *src_ptr,
                                  int  source_stride,
                                  const uint8_t *ref_ptr,
@@ -160,7 +159,6 @@
 
   return vp9_variance16x32_c(temp2, 32, dst_ptr, dst_pixels_per_line, sse);
 }
-#endif
 
 unsigned int vp9_variance64x64_c(const uint8_t *src_ptr,
                                  int  source_stride,
diff --git a/vp9/vp9dx.mk b/vp9/vp9dx.mk
index 239ae30..69b2997 100644
--- a/vp9/vp9dx.mk
+++ b/vp9/vp9dx.mk
@@ -22,17 +22,16 @@
 VP9_DX_SRCS-yes += decoder/vp9_decodemv.c
 VP9_DX_SRCS-yes += decoder/vp9_decodframe.c
 VP9_DX_SRCS-yes += decoder/vp9_decodframe.h
-VP9_DX_SRCS-yes += decoder/vp9_dequantize.c
 VP9_DX_SRCS-yes += decoder/vp9_detokenize.c
 VP9_DX_SRCS-yes += decoder/vp9_dboolhuff.h
 VP9_DX_SRCS-yes += decoder/vp9_decodemv.h
-VP9_DX_SRCS-yes += decoder/vp9_dequantize.h
 VP9_DX_SRCS-yes += decoder/vp9_detokenize.h
 VP9_DX_SRCS-yes += decoder/vp9_onyxd.h
 VP9_DX_SRCS-yes += decoder/vp9_onyxd_int.h
 VP9_DX_SRCS-yes += decoder/vp9_treereader.h
 VP9_DX_SRCS-yes += decoder/vp9_onyxd_if.c
 VP9_DX_SRCS-yes += decoder/vp9_idct_blk.c
+VP9_DX_SRCS-yes += decoder/vp9_idct_blk.h
 
 VP9_DX_SRCS-yes := $(filter-out $(VP9_DX_SRCS_REMOVE-yes),$(VP9_DX_SRCS-yes))