Merge "Special handle on DC only inverse 8x8 2D-DCT"
diff --git a/vp9/common/arm/neon/vp9_short_idct8x8_add_neon.asm b/vp9/common/arm/neon/vp9_short_idct8x8_add_neon.asm
index 8e4aada..f829665 100644
--- a/vp9/common/arm/neon/vp9_short_idct8x8_add_neon.asm
+++ b/vp9/common/arm/neon/vp9_short_idct8x8_add_neon.asm
@@ -22,8 +22,8 @@
     MACRO
     IDCT8x8_1D
     ; stage 1
-    vdup.16         d0, r3;                   ; duplicate cospi_28_64
-    vdup.16         d1, r4;                   ; duplicate cospi_4_64
+    vdup.16         d0, r3                    ; duplicate cospi_28_64
+    vdup.16         d1, r4                    ; duplicate cospi_4_64
 
     ; input[1] * cospi_28_64
     vmull.s16       q2, d18, d0
@@ -57,8 +57,8 @@
     vqrshrn.s32     d14, q2, #14              ; >> 14
     vqrshrn.s32     d15, q3, #14              ; >> 14
 
-    vdup.16         d0, r5;                   ; duplicate cospi_12_64
-    vdup.16         d1, r6;                   ; duplicate cospi_20_64
+    vdup.16         d0, r5                    ; duplicate cospi_12_64
+    vdup.16         d1, r6                    ; duplicate cospi_20_64
 
     ; input[5] * cospi_12_64
     vmull.s16       q2, d26, d0
@@ -93,7 +93,7 @@
     vqrshrn.s32     d13, q1, #14              ; >> 14
 
     ; stage 2 & stage 3 - even half
-    vdup.16         d0, r7;                   ; duplicate cospi_16_64
+    vdup.16         d0, r7                    ; duplicate cospi_16_64
 
     ; input[0] * cospi_16_64
     vmull.s16       q2, d16, d0
@@ -128,8 +128,8 @@
     vqrshrn.s32     d23, q3, #14              ; >> 14
 
     ; input[1] * cospi_24_64 - input[3] * cospi_8_64
-    vdup.16         d0, r8;                   ; duplicate cospi_24_64
-    vdup.16         d1, r9;                   ; duplicate cospi_8_64
+    vdup.16         d0, r8                    ; duplicate cospi_24_64
+    vdup.16         d1, r9                    ; duplicate cospi_8_64
 
     ; input[1] * cospi_24_64
     vmull.s16       q2, d20, d0
@@ -176,7 +176,7 @@
     vadd.s16        q7, q7, q6                ; step2[7] = step1[6] + step1[7]
 
     ; stage 3 -odd half
-    vdup.16         d16, r7;                   ; duplicate cospi_16_64
+    vdup.16         d16, r7                   ; duplicate cospi_16_64
 
     ; step2[6] * cospi_16_64
     vmull.s16       q9, d28, d16
@@ -211,14 +211,14 @@
     vqrshrn.s32     d13, q10, #14             ; >> 14
 
     ; stage 4
-    vadd.s16        q8, q0, q7;               ; output[0] = step1[0] + step1[7];
-    vadd.s16        q9, q1, q6;               ; output[1] = step1[1] + step1[6];
-    vadd.s16        q10, q2, q5;              ; output[2] = step1[2] + step1[5];
-    vadd.s16        q11, q3, q4;              ; output[3] = step1[3] + step1[4];
-    vsub.s16        q12, q3, q4;              ; output[4] = step1[3] - step1[4];
-    vsub.s16        q13, q2, q5;              ; output[5] = step1[2] - step1[5];
-    vsub.s16        q14, q1, q6;              ; output[6] = step1[1] - step1[6];
-    vsub.s16        q15, q0, q7;              ; output[7] = step1[0] - step1[7];
+    vadd.s16        q8, q0, q7                ; output[0] = step1[0] + step1[7];
+    vadd.s16        q9, q1, q6                ; output[1] = step1[1] + step1[6];
+    vadd.s16        q10, q2, q5               ; output[2] = step1[2] + step1[5];
+    vadd.s16        q11, q3, q4               ; output[3] = step1[3] + step1[4];
+    vsub.s16        q12, q3, q4               ; output[4] = step1[3] - step1[4];
+    vsub.s16        q13, q2, q5               ; output[5] = step1[2] - step1[5];
+    vsub.s16        q14, q1, q6               ; output[6] = step1[1] - step1[6];
+    vsub.s16        q15, q0, q7               ; output[7] = step1[0] - step1[7];
     MEND
 
     ; Transpose a 8x8 16bit data matrix. Datas are loaded in q8-q15.
@@ -310,14 +310,14 @@
     mov             r0, r1
 
     ; load destination data
-    vld1.u8         {d0}, [r1], r2
-    vld1.u8         {d1}, [r1], r2
-    vld1.s16        {d2}, [r1], r2
-    vld1.s16        {d3}, [r1], r2
-    vld1.s16        {d4}, [r1], r2
-    vld1.s16        {d5}, [r1], r2
-    vld1.s16        {d6}, [r1], r2
-    vld1.s16        {d7}, [r1]
+    vld1.64         {d0}, [r1], r2
+    vld1.64         {d1}, [r1], r2
+    vld1.64         {d2}, [r1], r2
+    vld1.64         {d3}, [r1], r2
+    vld1.64         {d4}, [r1], r2
+    vld1.64         {d5}, [r1], r2
+    vld1.64         {d6}, [r1], r2
+    vld1.64         {d7}, [r1]
 
     ; ROUND_POWER_OF_TWO(temp_out[j], 5) + dest[j * dest_stride + i]
     vaddw.u8        q8, q8, d0
diff --git a/vp9/common/vp9_entropy.c b/vp9/common/vp9_entropy.c
index 6c2b6e5..9d46a96 100644
--- a/vp9/common/vp9_entropy.c
+++ b/vp9/common/vp9_entropy.c
@@ -437,14 +437,10 @@
 #include "vp9/common/vp9_default_coef_probs.h"
 
 void vp9_default_coef_probs(VP9_COMMON *pc) {
-  vpx_memcpy(pc->fc.coef_probs[TX_4X4], default_coef_probs_4x4,
-             sizeof(pc->fc.coef_probs[TX_4X4]));
-  vpx_memcpy(pc->fc.coef_probs[TX_8X8], default_coef_probs_8x8,
-             sizeof(pc->fc.coef_probs[TX_8X8]));
-  vpx_memcpy(pc->fc.coef_probs[TX_16X16], default_coef_probs_16x16,
-             sizeof(pc->fc.coef_probs[TX_16X16]));
-  vpx_memcpy(pc->fc.coef_probs[TX_32X32], default_coef_probs_32x32,
-             sizeof(pc->fc.coef_probs[TX_32X32]));
+  vp9_copy(pc->fc.coef_probs[TX_4X4], default_coef_probs_4x4);
+  vp9_copy(pc->fc.coef_probs[TX_8X8], default_coef_probs_8x8);
+  vp9_copy(pc->fc.coef_probs[TX_16X16], default_coef_probs_16x16);
+  vp9_copy(pc->fc.coef_probs[TX_32X32], default_coef_probs_32x32);
 }
 
 // Neighborhood 5-tuples for various scans and blocksizes,
diff --git a/vp9/common/vp9_entropy.h b/vp9/common/vp9_entropy.h
index 4ea727f..b2a941b 100644
--- a/vp9/common/vp9_entropy.h
+++ b/vp9/common/vp9_entropy.h
@@ -80,7 +80,6 @@
    coefficient band (and since zigzag positions 0, 1, and 2 are in
    distinct bands). */
 
-/*# define DC_TOKEN_CONTEXTS        3*/ /* 00, 0!0, !0!0 */
 #define PREV_COEF_CONTEXTS          6
 
 // #define ENTROPY_STATS
diff --git a/vp9/common/vp9_entropymode.h b/vp9/common/vp9_entropymode.h
index 1094e82..f000b96 100644
--- a/vp9/common/vp9_entropymode.h
+++ b/vp9/common/vp9_entropymode.h
@@ -61,8 +61,6 @@
 
 void vp9_entropy_mode_init();
 
-int vp9_mv_cont(const int_mv *l, const int_mv *a);
-
 void vp9_setup_past_independence(struct VP9Common *cm, MACROBLOCKD *xd);
 
 void vp9_init_mbmode_probs(struct VP9Common *x);
diff --git a/vp9/common/vp9_entropymv.c b/vp9/common/vp9_entropymv.c
index f819d68..4080f8c 100644
--- a/vp9/common/vp9_entropymv.c
+++ b/vp9/common/vp9_entropymv.c
@@ -16,7 +16,7 @@
 #define MV_MAX_UPDATE_FACTOR 128
 
 /* Integer pel reference mv threshold for use of high-precision 1/8 mv */
-#define COMPANDED_MVREF_THRESH    8
+#define COMPANDED_MVREF_THRESH 8
 
 const vp9_tree_index vp9_mv_joint_tree[2 * MV_JOINTS - 2] = {
   -MV_JOINT_ZERO, 2,
@@ -169,8 +169,8 @@
     ++counts->comps[1].mvcount[MV_MAX + mv->col];
 }
 
-static void adapt_prob(vp9_prob *dest, vp9_prob prep, unsigned int ct[2]) {
-  *dest = merge_probs2(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR);
+static vp9_prob adapt_prob(vp9_prob prep, const unsigned int ct[2]) {
+  return merge_probs2(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR);
 }
 
 void vp9_counts_process(nmv_context_counts *nmv_count, int usehp) {
@@ -192,11 +192,8 @@
   const unsigned int right = tree[i + 1] <= 0
           ? num_events[-tree[i + 1]]
           : adapt_probs(tree[i + 1], tree, this_probs, last_probs, num_events);
-
   const unsigned int ct[2] = { left, right };
-
-  this_probs[i >> 1] = merge_probs2(last_probs[i >> 1], ct,
-                                    MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR);
+  this_probs[i >> 1] = adapt_prob(last_probs[i >> 1], ct);
   return left + right;
 }
 
@@ -215,31 +212,27 @@
   adapt_probs(0, vp9_mv_joint_tree, ctx->joints, pre_ctx->joints, cts->joints);
 
   for (i = 0; i < 2; ++i) {
-    adapt_prob(&ctx->comps[i].sign, pre_ctx->comps[i].sign, cts->comps[i].sign);
+    ctx->comps[i].sign = adapt_prob(pre_ctx->comps[i].sign, cts->comps[i].sign);
     adapt_probs(0, vp9_mv_class_tree, ctx->comps[i].classes,
                 pre_ctx->comps[i].classes, cts->comps[i].classes);
     adapt_probs(0, vp9_mv_class0_tree, ctx->comps[i].class0,
                 pre_ctx->comps[i].class0, cts->comps[i].class0);
 
     for (j = 0; j < MV_OFFSET_BITS; ++j)
-      adapt_prob(&ctx->comps[i].bits[j], pre_ctx->comps[i].bits[j],
-                 cts->comps[i].bits[j]);
-  }
+        ctx->comps[i].bits[j] = adapt_prob(pre_ctx->comps[i].bits[j],
+                                           cts->comps[i].bits[j]);
 
-  for (i = 0; i < 2; ++i) {
     for (j = 0; j < CLASS0_SIZE; ++j)
       adapt_probs(0, vp9_mv_fp_tree, ctx->comps[i].class0_fp[j],
                   pre_ctx->comps[i].class0_fp[j], cts->comps[i].class0_fp[j]);
 
     adapt_probs(0, vp9_mv_fp_tree, ctx->comps[i].fp, pre_ctx->comps[i].fp,
                 cts->comps[i].fp);
-  }
 
-  if (usehp) {
-    for (i = 0; i < 2; ++i) {
-      adapt_prob(&ctx->comps[i].class0_hp, pre_ctx->comps[i].class0_hp,
-                 cts->comps[i].class0_hp);
-      adapt_prob(&ctx->comps[i].hp, pre_ctx->comps[i].hp, cts->comps[i].hp);
+    if (usehp) {
+      ctx->comps[i].class0_hp = adapt_prob(pre_ctx->comps[i].class0_hp,
+                                           cts->comps[i].class0_hp);
+      ctx->comps[i].hp = adapt_prob(pre_ctx->comps[i].hp, cts->comps[i].hp);
     }
   }
 }
diff --git a/vp9/common/vp9_extend.c b/vp9/common/vp9_extend.c
index 95ec590..d8496c4 100644
--- a/vp9/common/vp9_extend.c
+++ b/vp9/common/vp9_extend.c
@@ -8,9 +8,11 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "vp9/common/vp9_extend.h"
 #include "vpx_mem/vpx_mem.h"
 
+#include "vp9/common/vp9_common.h"
+#include "vp9/common/vp9_extend.h"
+
 static void copy_and_extend_plane(const uint8_t *src, int src_pitch,
                                   uint8_t *dst, int dst_pitch,
                                   int w, int h,
@@ -107,14 +109,14 @@
   const int src_y_offset = srcy * src->y_stride + srcx;
   const int dst_y_offset = srcy * dst->y_stride + srcx;
 
-  const int et_uv = (et_y + 1) >> 1;
-  const int el_uv = (el_y + 1) >> 1;
-  const int eb_uv = (eb_y + 1) >> 1;
-  const int er_uv = (er_y + 1) >> 1;
+  const int et_uv = ROUND_POWER_OF_TWO(et_y, 1);
+  const int el_uv = ROUND_POWER_OF_TWO(el_y, 1);
+  const int eb_uv = ROUND_POWER_OF_TWO(eb_y, 1);
+  const int er_uv = ROUND_POWER_OF_TWO(er_y, 1);
   const int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1);
   const int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1);
-  const int srch_uv = (srch + 1) >> 1;
-  const int srcw_uv = (srcw + 1) >> 1;
+  const int srch_uv = ROUND_POWER_OF_TWO(srch, 1);
+  const int srcw_uv = ROUND_POWER_OF_TWO(srcw, 1);
 
   copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride,
                         dst->y_buffer + dst_y_offset, dst->y_stride,
diff --git a/vp9/common/vp9_reconinter.c b/vp9/common/vp9_reconinter.c
index 63e5646..2e42fd0 100644
--- a/vp9/common/vp9_reconinter.c
+++ b/vp9/common/vp9_reconinter.c
@@ -400,7 +400,7 @@
   const int ref = cm->active_ref_idx[i];
   struct scale_factors *const sf = &cm->active_ref_scale[i];
   if (ref >= NUM_YV12_BUFFERS) {
-    memset(sf, 0, sizeof(*sf));
+    vp9_zero(*sf);
   } else {
     YV12_BUFFER_CONFIG *const fb = &cm->yv12_fb[ref];
     vp9_setup_scale_factors_for_frame(sf,
diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c
index 24e0fd4..8dbc1cd 100644
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -380,8 +380,8 @@
   return vp9_switchable_interp[index];
 }
 
-static void read_intra_block_modes(VP9D_COMP *pbi, MODE_INFO *mi,
-                                   vp9_reader *r) {
+static void read_intra_block_part(VP9D_COMP *pbi, MODE_INFO *mi,
+                                  vp9_reader *r) {
   VP9_COMMON *const cm = &pbi->common;
   MB_MODE_INFO *const mbmi = &mi->mbmi;
   const BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type;
@@ -433,183 +433,191 @@
   return ref;
 }
 
-static void read_inter_mode_info(VP9D_COMP *pbi, MODE_INFO *mi,
-                                 int mi_row, int mi_col, vp9_reader *r) {
+static void read_inter_block_part(VP9D_COMP *pbi, MODE_INFO *mi,
+                                  vp9_reader *r) {
   VP9_COMMON *const cm = &pbi->common;
   MACROBLOCKD *const xd = &pbi->mb;
   nmv_context *const nmvc = &cm->fc.nmvc;
   MB_MODE_INFO *const mbmi = &mi->mbmi;
-
   int_mv *const mv0 = &mbmi->mv[0];
   int_mv *const mv1 = &mbmi->mv[1];
-  const BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type;
+  const BLOCK_SIZE_TYPE bsize = mbmi->sb_type;
   const int bw = 1 << b_width_log2(bsize);
   const int bh = 1 << b_height_log2(bsize);
 
-  int idx, idy;
+  int_mv nearest, nearby, best_mv;
+  int_mv nearest_second, nearby_second, best_mv_second;
+  vp9_prob *mv_ref_p;
+  MV_REFERENCE_FRAME ref0, ref1;
+
+  read_ref_frame(pbi, r, mbmi->segment_id, mbmi->ref_frame);
+  ref0 = mbmi->ref_frame[0];
+  ref1 = mbmi->ref_frame[1];
+
+  vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context,
+                   ref0, mbmi->ref_mvs[ref0], cm->ref_frame_sign_bias);
+
+  mv_ref_p = cm->fc.inter_mode_probs[mbmi->mb_mode_context[ref0]];
+
+  if (vp9_segfeature_active(&xd->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
+    mbmi->mode = ZEROMV;
+  } else if (bsize >= BLOCK_SIZE_SB8X8) {
+    mbmi->mode = read_inter_mode(r, mv_ref_p);
+    vp9_accum_mv_refs(cm, mbmi->mode, mbmi->mb_mode_context[ref0]);
+  }
+  mbmi->uv_mode = DC_PRED;
+
+  // nearest, nearby
+  if (bsize < BLOCK_SIZE_SB8X8 || mbmi->mode != ZEROMV) {
+    vp9_find_best_ref_mvs(xd, mbmi->ref_mvs[ref0], &nearest, &nearby);
+    best_mv.as_int = mbmi->ref_mvs[ref0][0].as_int;
+  }
+
+  mbmi->interp_filter = cm->mcomp_filter_type == SWITCHABLE
+                            ? read_switchable_filter_type(pbi, r)
+                            : cm->mcomp_filter_type;
+
+  if (ref1 > INTRA_FRAME) {
+    vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context,
+                     ref1, mbmi->ref_mvs[ref1], cm->ref_frame_sign_bias);
+
+    if (bsize < BLOCK_SIZE_SB8X8 || mbmi->mode != ZEROMV) {
+      vp9_find_best_ref_mvs(xd, mbmi->ref_mvs[ref1],
+                            &nearest_second, &nearby_second);
+      best_mv_second.as_int = mbmi->ref_mvs[ref1][0].as_int;
+    }
+  }
+
+
+  if (mbmi->sb_type < BLOCK_SIZE_SB8X8) {
+    int idx, idy;
+    for (idy = 0; idy < 2; idy += bh) {
+      for (idx = 0; idx < 2; idx += bw) {
+        int_mv blockmv, secondmv;
+        const int j = idy * 2 + idx;
+        const int blockmode = read_inter_mode(r, mv_ref_p);
+
+        vp9_accum_mv_refs(cm, blockmode, mbmi->mb_mode_context[ref0]);
+        if (blockmode == NEARESTMV || blockmode == NEARMV) {
+          vp9_append_sub8x8_mvs_for_idx(cm, xd, &nearest, &nearby, j, 0);
+          if (ref1 > 0)
+            vp9_append_sub8x8_mvs_for_idx(cm, xd,  &nearest_second,
+                                         &nearby_second, j, 1);
+        }
+
+        switch (blockmode) {
+          case NEWMV:
+            read_mv(r, &blockmv.as_mv, &best_mv.as_mv, nmvc,
+                    &cm->counts.mv, xd->allow_high_precision_mv);
+
+            if (ref1 > 0)
+              read_mv(r, &secondmv.as_mv, &best_mv_second.as_mv, nmvc,
+                      &cm->counts.mv, xd->allow_high_precision_mv);
+            break;
+          case NEARESTMV:
+            blockmv.as_int = nearest.as_int;
+            if (ref1 > 0)
+              secondmv.as_int = nearest_second.as_int;
+            break;
+          case NEARMV:
+            blockmv.as_int = nearby.as_int;
+            if (ref1 > 0)
+              secondmv.as_int = nearby_second.as_int;
+            break;
+          case ZEROMV:
+            blockmv.as_int = 0;
+            if (ref1 > 0)
+              secondmv.as_int = 0;
+            break;
+          default:
+            assert(!"Invalid inter mode value");
+        }
+        mi->bmi[j].as_mv[0].as_int = blockmv.as_int;
+        if (ref1 > 0)
+          mi->bmi[j].as_mv[1].as_int = secondmv.as_int;
+
+        if (bh == 2)
+          mi->bmi[j + 2] = mi->bmi[j];
+        if (bw == 2)
+          mi->bmi[j + 1] = mi->bmi[j];
+        mi->mbmi.mode = blockmode;
+      }
+    }
+
+    mv0->as_int = mi->bmi[3].as_mv[0].as_int;
+    mv1->as_int = mi->bmi[3].as_mv[1].as_int;
+  } else {
+    const int mb_to_top_edge = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
+    const int mb_to_bottom_edge = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
+    const int mb_to_left_edge = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
+    const int mb_to_right_edge = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
+
+    switch (mbmi->mode) {
+      case NEARMV:
+        // Clip "next_nearest" so that it does not extend to far out of image
+        assign_and_clamp_mv(mv0, &nearby, mb_to_left_edge,
+                                          mb_to_right_edge,
+                                          mb_to_top_edge,
+                                          mb_to_bottom_edge);
+        if (ref1 > 0)
+          assign_and_clamp_mv(mv1, &nearby_second, mb_to_left_edge,
+                                                   mb_to_right_edge,
+                                                   mb_to_top_edge,
+                                                   mb_to_bottom_edge);
+        break;
+
+      case NEARESTMV:
+        // Clip "next_nearest" so that it does not extend to far out of image
+        assign_and_clamp_mv(mv0, &nearest, mb_to_left_edge,
+                                           mb_to_right_edge,
+                                           mb_to_top_edge,
+                                           mb_to_bottom_edge);
+        if (ref1 > 0)
+          assign_and_clamp_mv(mv1, &nearest_second, mb_to_left_edge,
+                                                    mb_to_right_edge,
+                                                    mb_to_top_edge,
+                                                    mb_to_bottom_edge);
+        break;
+
+      case ZEROMV:
+        mv0->as_int = 0;
+        if (ref1 > 0)
+          mv1->as_int = 0;
+        break;
+
+      case NEWMV:
+        read_mv(r, &mv0->as_mv, &best_mv.as_mv, nmvc, &cm->counts.mv,
+                xd->allow_high_precision_mv);
+        if (ref1 > 0)
+          read_mv(r, &mv1->as_mv, &best_mv_second.as_mv, nmvc,
+                  &cm->counts.mv, xd->allow_high_precision_mv);
+        break;
+      default:
+        assert(!"Invalid inter mode value");
+    }
+  }
+}
+
+static void read_inter_mode_info(VP9D_COMP *pbi, MODE_INFO *mi,
+                                 int mi_row, int mi_col, vp9_reader *r) {
+  VP9_COMMON *const cm = &pbi->common;
+  MB_MODE_INFO *const mbmi = &mi->mbmi;
+  int intra_block;
 
   mbmi->segment_id = read_inter_segment_id(pbi, mi_row, mi_col, r);
   mbmi->mb_skip_coeff = read_skip_coeff(pbi, mbmi->segment_id, r);
   mbmi->ref_frame[0] = read_reference_frame(pbi, mbmi->segment_id, r);
   mbmi->ref_frame[1] = NONE;
-  mbmi->txfm_size = read_tx_size(pbi, cm->tx_mode, bsize,
-     (!mbmi->mb_skip_coeff || mbmi->ref_frame[0] == INTRA_FRAME), r);
+  intra_block = mbmi->ref_frame[0] == INTRA_FRAME;
+  mbmi->txfm_size = read_tx_size(pbi, cm->tx_mode, mbmi->sb_type,
+                                 !mbmi->mb_skip_coeff || intra_block, r);
+  mbmi->mv[0].as_int = 0;
+  mbmi->mv[1].as_int = 0;
 
-  if (mbmi->ref_frame[0] != INTRA_FRAME) {
-    int_mv nearest, nearby, best_mv;
-    int_mv nearest_second, nearby_second, best_mv_second;
-    vp9_prob *mv_ref_p;
-    MV_REFERENCE_FRAME ref0, ref1;
-
-    read_ref_frame(pbi, r, mbmi->segment_id, mbmi->ref_frame);
-    ref0 = mbmi->ref_frame[0];
-    ref1 = mbmi->ref_frame[1];
-
-    vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context,
-                     ref0, mbmi->ref_mvs[ref0], cm->ref_frame_sign_bias);
-
-    mv_ref_p = cm->fc.inter_mode_probs[mbmi->mb_mode_context[ref0]];
-
-    if (vp9_segfeature_active(&xd->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
-      mbmi->mode = ZEROMV;
-    } else if (bsize >= BLOCK_SIZE_SB8X8) {
-      mbmi->mode = read_inter_mode(r, mv_ref_p);
-      vp9_accum_mv_refs(cm, mbmi->mode, mbmi->mb_mode_context[ref0]);
-    }
-    mbmi->uv_mode = DC_PRED;
-
-    // nearest, nearby
-    if (bsize < BLOCK_SIZE_SB8X8 || mbmi->mode != ZEROMV) {
-      vp9_find_best_ref_mvs(xd, mbmi->ref_mvs[ref0], &nearest, &nearby);
-      best_mv.as_int = mbmi->ref_mvs[ref0][0].as_int;
-    }
-
-    mbmi->interp_filter = cm->mcomp_filter_type == SWITCHABLE
-                              ? read_switchable_filter_type(pbi, r)
-                              : cm->mcomp_filter_type;
-
-    if (ref1 > INTRA_FRAME) {
-      vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context,
-                       ref1, mbmi->ref_mvs[ref1], cm->ref_frame_sign_bias);
-
-      if (bsize < BLOCK_SIZE_SB8X8 || mbmi->mode != ZEROMV) {
-        vp9_find_best_ref_mvs(xd, mbmi->ref_mvs[ref1],
-                              &nearest_second, &nearby_second);
-        best_mv_second.as_int = mbmi->ref_mvs[ref1][0].as_int;
-      }
-    }
-
-
-    if (mbmi->sb_type < BLOCK_SIZE_SB8X8) {
-      for (idy = 0; idy < 2; idy += bh) {
-        for (idx = 0; idx < 2; idx += bw) {
-          int_mv blockmv, secondmv;
-          const int j = idy * 2 + idx;
-          const int blockmode = read_inter_mode(r, mv_ref_p);
-
-          vp9_accum_mv_refs(cm, blockmode, mbmi->mb_mode_context[ref0]);
-          if (blockmode == NEARESTMV || blockmode == NEARMV) {
-            vp9_append_sub8x8_mvs_for_idx(cm, xd, &nearest, &nearby, j, 0);
-            if (ref1 > 0)
-              vp9_append_sub8x8_mvs_for_idx(cm, xd,  &nearest_second,
-                                            &nearby_second, j, 1);
-          }
-
-          switch (blockmode) {
-            case NEWMV:
-              read_mv(r, &blockmv.as_mv, &best_mv.as_mv, nmvc,
-                      &cm->counts.mv, xd->allow_high_precision_mv);
-
-              if (ref1 > 0)
-                read_mv(r, &secondmv.as_mv, &best_mv_second.as_mv, nmvc,
-                        &cm->counts.mv, xd->allow_high_precision_mv);
-              break;
-            case NEARESTMV:
-              blockmv.as_int = nearest.as_int;
-              if (ref1 > 0)
-                secondmv.as_int = nearest_second.as_int;
-              break;
-            case NEARMV:
-              blockmv.as_int = nearby.as_int;
-              if (ref1 > 0)
-                secondmv.as_int = nearby_second.as_int;
-              break;
-            case ZEROMV:
-              blockmv.as_int = 0;
-              if (ref1 > 0)
-                secondmv.as_int = 0;
-              break;
-            default:
-              assert(!"Invalid inter mode value");
-          }
-          mi->bmi[j].as_mv[0].as_int = blockmv.as_int;
-          if (ref1 > 0)
-            mi->bmi[j].as_mv[1].as_int = secondmv.as_int;
-
-          if (bh == 2)
-            mi->bmi[j + 2] = mi->bmi[j];
-          if (bw == 2)
-            mi->bmi[j + 1] = mi->bmi[j];
-          mi->mbmi.mode = blockmode;
-        }
-      }
-
-      mv0->as_int = mi->bmi[3].as_mv[0].as_int;
-      mv1->as_int = mi->bmi[3].as_mv[1].as_int;
-    } else {
-      const int mb_to_top_edge = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
-      const int mb_to_bottom_edge = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
-      const int mb_to_left_edge = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
-      const int mb_to_right_edge = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
-
-      switch (mbmi->mode) {
-        case NEARMV:
-          // Clip "next_nearest" so that it does not extend to far out of image
-          assign_and_clamp_mv(mv0, &nearby, mb_to_left_edge,
-                                            mb_to_right_edge,
-                                            mb_to_top_edge,
-                                            mb_to_bottom_edge);
-          if (ref1 > 0)
-            assign_and_clamp_mv(mv1, &nearby_second, mb_to_left_edge,
-                                                     mb_to_right_edge,
-                                                     mb_to_top_edge,
-                                                     mb_to_bottom_edge);
-          break;
-
-        case NEARESTMV:
-          // Clip "next_nearest" so that it does not extend to far out of image
-          assign_and_clamp_mv(mv0, &nearest, mb_to_left_edge,
-                                             mb_to_right_edge,
-                                             mb_to_top_edge,
-                                             mb_to_bottom_edge);
-          if (ref1 > 0)
-            assign_and_clamp_mv(mv1, &nearest_second, mb_to_left_edge,
-                                                      mb_to_right_edge,
-                                                      mb_to_top_edge,
-                                                      mb_to_bottom_edge);
-          break;
-
-        case ZEROMV:
-          mv0->as_int = 0;
-          if (ref1 > 0)
-            mv1->as_int = 0;
-          break;
-
-        case NEWMV:
-          read_mv(r, &mv0->as_mv, &best_mv.as_mv, nmvc, &cm->counts.mv,
-                  xd->allow_high_precision_mv);
-          if (ref1 > 0)
-            read_mv(r, &mv1->as_mv, &best_mv_second.as_mv, nmvc,
-                    &cm->counts.mv, xd->allow_high_precision_mv);
-          break;
-        default:
-          assert(!"Invalid inter mode value");
-      }
-    }
-  } else {
-    mv0->as_int = 0;  // required for left and above block mv
-    read_intra_block_modes(pbi, mi, r);
-  }
+  if (intra_block)
+    read_intra_block_part(pbi, mi, r);
+  else
+    read_inter_block_part(pbi, mi, r);
 }
 
 static void read_comp_pred(VP9_COMMON *cm, vp9_reader *r) {
diff --git a/vp9/decoder/vp9_decodemv.h b/vp9/decoder/vp9_decodemv.h
index 4073d9e..462d2e3 100644
--- a/vp9/decoder/vp9_decodemv.h
+++ b/vp9/decoder/vp9_decodemv.h
@@ -12,6 +12,7 @@
 #define VP9_DECODER_VP9_DECODEMV_H_
 
 #include "vp9/decoder/vp9_onyxd_int.h"
+#include "vp9/decoder/vp9_dboolhuff.h"
 
 void vp9_prepare_read_mode_info(VP9D_COMP* pbi, vp9_reader *r);
 
diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index f5086d6..93fecf2 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -31,8 +31,10 @@
 #include "vp9/decoder/vp9_detokenize.h"
 #include "vp9/decoder/vp9_decodemv.h"
 #include "vp9/decoder/vp9_dsubexp.h"
+#include "vp9/decoder/vp9_idct_blk.h"
 #include "vp9/decoder/vp9_onyxd_int.h"
 #include "vp9/decoder/vp9_read_bit_buffer.h"
+#include "vp9/decoder/vp9_treereader.h"
 
 static int read_be32(const uint8_t *p) {
   return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c
index 01c1db0..b393aa0 100644
--- a/vp9/decoder/vp9_detokenize.c
+++ b/vp9/decoder/vp9_detokenize.c
@@ -15,8 +15,10 @@
 #include "vp9/common/vp9_common.h"
 #include "vp9/common/vp9_seg_common.h"
 
+#include "vp9/decoder/vp9_dboolhuff.h"
 #include "vp9/decoder/vp9_detokenize.h"
 #include "vp9/decoder/vp9_onyxd_int.h"
+#include "vp9/decoder/vp9_treereader.h"
 
 #define EOB_CONTEXT_NODE            0
 #define ZERO_CONTEXT_NODE           1
@@ -93,27 +95,18 @@
   FRAME_CONTEXT *const fc = &cm->fc;
   FRAME_COUNTS *const counts = &cm->counts;
   ENTROPY_CONTEXT above_ec, left_ec;
-  int pt, c = 0;
-  int band;
-  vp9_prob (*coef_probs)[PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES];
-  vp9_prob coef_probs_full[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES];
-  uint8_t load_map[COEF_BANDS][PREV_COEF_CONTEXTS] = {
-    {0, 0, 0, 0, 0, 0},
-    {0, 0, 0, 0, 0, 0},
-    {0, 0, 0, 0, 0, 0},
-    {0, 0, 0, 0, 0, 0},
-    {0, 0, 0, 0, 0, 0},
-    {0, 0, 0, 0, 0, 0},
-  };
-
-  vp9_prob *prob;
-  vp9_coeff_count_model *coef_counts;
   const int ref = xd->mode_info_context->mbmi.ref_frame[0] != INTRA_FRAME;
+  int band, pt, c = 0;
+  vp9_prob (*coef_probs)[PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES] =
+      fc->coef_probs[txfm_size][type][ref];
+  vp9_prob coef_probs_full[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES];
+  uint8_t load_map[COEF_BANDS][PREV_COEF_CONTEXTS] = { { 0 } };
+  vp9_prob *prob;
+  vp9_coeff_count_model *coef_counts = counts->coef[txfm_size];
   const int16_t *scan, *nb;
   uint8_t token_cache[1024];
   const uint8_t * band_translate;
-  coef_probs  = fc->coef_probs[txfm_size][type][ref];
-  coef_counts = counts->coef[txfm_size];
+
   switch (txfm_size) {
     default:
     case TX_4X4: {
diff --git a/vp9/decoder/vp9_detokenize.h b/vp9/decoder/vp9_detokenize.h
index d46b596..f98fe8d 100644
--- a/vp9/decoder/vp9_detokenize.h
+++ b/vp9/decoder/vp9_detokenize.h
@@ -13,6 +13,7 @@
 #define VP9_DECODER_VP9_DETOKENIZE_H_
 
 #include "vp9/decoder/vp9_onyxd_int.h"
+#include "vp9/decoder/vp9_dboolhuff.h"
 
 int vp9_decode_tokens(VP9D_COMP* pbi, vp9_reader *r, BLOCK_SIZE_TYPE bsize);
 
diff --git a/vp9/decoder/vp9_onyxd_if.c b/vp9/decoder/vp9_onyxd_if.c
index cb72920..aefb56f 100644
--- a/vp9/decoder/vp9_onyxd_if.c
+++ b/vp9/decoder/vp9_onyxd_if.c
@@ -8,9 +8,9 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-
-#include <stdio.h>
 #include <assert.h>
+#include <limits.h>
+#include <stdio.h>
 
 #include "vp9/common/vp9_onyxc_int.h"
 #if CONFIG_POSTPROC
@@ -114,7 +114,7 @@
   if (!pbi)
     return NULL;
 
-  vpx_memset(pbi, 0, sizeof(VP9D_COMP));
+  vp9_zero(*pbi);
 
   if (setjmp(pbi->common.error.jmp)) {
     pbi->common.error.setjmp = 0;
diff --git a/vp9/decoder/vp9_onyxd_int.h b/vp9/decoder/vp9_onyxd_int.h
index 4760066..607d14c 100644
--- a/vp9/decoder/vp9_onyxd_int.h
+++ b/vp9/decoder/vp9_onyxd_int.h
@@ -15,9 +15,7 @@
 
 #include "vp9/common/vp9_onyxc_int.h"
 
-#include "vp9/decoder/vp9_idct_blk.h"
 #include "vp9/decoder/vp9_onyxd.h"
-#include "vp9/decoder/vp9_treereader.h"
 
 typedef struct VP9Decompressor {
   DECLARE_ALIGNED(16, MACROBLOCKD, mb);
diff --git a/vp9/decoder/vp9_treereader.h b/vp9/decoder/vp9_treereader.h
index 4535688..710cc4c 100644
--- a/vp9/decoder/vp9_treereader.h
+++ b/vp9/decoder/vp9_treereader.h
@@ -15,7 +15,6 @@
 #include "vp9/common/vp9_treecoder.h"
 #include "vp9/decoder/vp9_dboolhuff.h"
 
-#define vp9_read_prob(r) ((vp9_prob)vp9_read_literal(r, 8))
 #define vp9_read_and_apply_sign(r, value) (vp9_read_bit(r) ? -(value) : (value))
 
 // Intent of tree data structure is to make decoding trivial.
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
index 4823c4b..ab3f47e 100644
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -1069,8 +1069,7 @@
   int dp;
   int pixels_wide = 64, pixels_high = 64;
 
-  vpx_memset(&vt, 0, sizeof(vt));
-
+  vp9_zero(vt);
   set_offsets(cpi, mi_row, mi_col, BLOCK_SIZE_SB64X64);
 
   if (xd->mb_to_right_edge < 0)
@@ -1429,6 +1428,56 @@
   *dist = chosen_dist;
 }
 
+static BLOCK_SIZE_TYPE min_partition_size[BLOCK_SIZE_TYPES] =
+  { BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, BLOCK_4X4,
+    BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, BLOCK_8X8,
+    BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16 };
+static BLOCK_SIZE_TYPE max_partition_size[BLOCK_SIZE_TYPES] =
+  { BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16,
+    BLOCK_32X32, BLOCK_32X32, BLOCK_32X32, BLOCK_64X64,
+    BLOCK_64X64, BLOCK_64X64, BLOCK_64X64, BLOCK_64X64, BLOCK_64X64 };
+
+
+// Look at neighbouring blocks and set a min and max partition size based on
+// what they chose.
+static void rd_auto_partition_range(VP9_COMP *cpi,
+                                    BLOCK_SIZE_TYPE * min_block_size,
+                                    BLOCK_SIZE_TYPE * max_block_size) {
+  MACROBLOCKD *const xd = &cpi->mb.e_mbd;
+  const MODE_INFO *const mi = xd->mode_info_context;
+  const MB_MODE_INFO *const above_mbmi = &mi[-xd->mode_info_stride].mbmi;
+  const MB_MODE_INFO *const left_mbmi = &mi[-1].mbmi;
+  const int left_in_image = xd->left_available && left_mbmi->mb_in_image;
+  const int above_in_image = xd->up_available && above_mbmi->mb_in_image;
+
+  // Frequency check
+  if (cpi->sf.auto_min_max_partition_count <= 0) {
+    cpi->sf.auto_min_max_partition_count =
+      cpi->sf.auto_min_max_partition_interval;
+    *min_block_size = BLOCK_4X4;
+    *max_block_size = BLOCK_64X64;
+    return;
+  } else {
+    --cpi->sf.auto_min_max_partition_count;
+  }
+
+  // Check for edge cases
+  if (!left_in_image && !above_in_image) {
+    *min_block_size = BLOCK_4X4;
+    *max_block_size = BLOCK_64X64;
+  } else if (!left_in_image) {
+    *min_block_size = min_partition_size[above_mbmi->sb_type];
+    *max_block_size = max_partition_size[above_mbmi->sb_type];
+  } else if (!above_in_image) {
+    *min_block_size = min_partition_size[left_mbmi->sb_type];
+    *max_block_size = max_partition_size[left_mbmi->sb_type];
+  } else {
+    *min_block_size =
+      min_partition_size[MIN(left_mbmi->sb_type, above_mbmi->sb_type)];
+    *max_block_size =
+      max_partition_size[MAX(left_mbmi->sb_type, above_mbmi->sb_type)];
+  }
+}
 
 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are
 // unlikely to be selected depending on previously rate-distortion optimization
@@ -1462,8 +1511,8 @@
   save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize);
 
   // PARTITION_SPLIT
-  if (!cpi->sf.use_partitions_greater_than ||
-      bsize > cpi->sf.greater_than_block_size) {
+  if (!cpi->sf.auto_min_max_partition_size ||
+      bsize >= cpi->sf.min_partition_size) {
     if (bsize > BLOCK_SIZE_SB8X8) {
       int r4 = 0;
       int64_t d4 = 0, sum_rd = 0;
@@ -1604,8 +1653,8 @@
     }
   }
 
-  if (!cpi->sf.use_partitions_less_than ||
-      bsize <= cpi->sf.less_than_block_size) {
+  if (!cpi->sf.use_max_partition_size ||
+      bsize <= cpi->sf.max_partition_size) {
     int larger_is_better = 0;
     // PARTITION_NONE
     if ((mi_row + (ms >> 1) < cm->mi_rows) &&
@@ -1876,6 +1925,12 @@
             || cpi->common.show_frame == 0
             || cpi->common.frame_type == KEY_FRAME
             || cpi->is_src_frame_alt_ref) {
+          // If required set upper and lower partition size limits
+          if (cpi->sf.auto_min_max_partition_size) {
+            rd_auto_partition_range(cpi,
+                                    &cpi->sf.min_partition_size,
+                                    &cpi->sf.max_partition_size);
+          }
           rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64,
                             &dummy_rate, &dummy_dist, 1, INT64_MAX);
         } else {
@@ -1885,6 +1940,13 @@
         }
       }
     } else {
+      // If required set upper and lower partition size limits
+      if (cpi->sf.auto_min_max_partition_size) {
+        rd_auto_partition_range(cpi,
+                                &cpi->sf.min_partition_size,
+                                &cpi->sf.max_partition_size);
+      }
+
       rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64,
                         &dummy_rate, &dummy_dist, 1, INT64_MAX);
     }
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c
index ec2e361..ff336d7 100644
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -2139,8 +2139,7 @@
       adjust_active_maxq(cpi->active_worst_quality, tmp_q);
   }
 #endif
-
-  vpx_memset(&this_frame, 0, sizeof(FIRSTPASS_STATS));
+  vp9_zero(this_frame);
   if (EOF == input_stats(cpi, &this_frame))
     return;
 
@@ -2318,7 +2317,7 @@
   double kf_group_coded_err = 0.0;
   double recent_loop_decay[8] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
 
-  vpx_memset(&next_frame, 0, sizeof(next_frame)); // assure clean
+  vp9_zero(next_frame);
 
   vp9_clear_system_state();  // __asm emms;
   start_position = cpi->twopass.stats_in;
diff --git a/vp9/encoder/vp9_mbgraph.c b/vp9/encoder/vp9_mbgraph.c
index 7d6db07..c6736fe 100644
--- a/vp9/encoder/vp9_mbgraph.c
+++ b/vp9/encoder/vp9_mbgraph.c
@@ -248,8 +248,7 @@
   int_mv arf_top_mv, gld_top_mv;
   MODE_INFO mi_local;
 
-  // Make sure the mi context starts in a consistent state.
-  memset(&mi_local, 0, sizeof(mi_local));
+  vp9_zero(mi_local);
 
   // Set up limit values for motion vectors to prevent them extending outside the UMV borders
   arf_top_mv.as_int = 0;
diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index fc19bd9..969e581 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -731,10 +731,13 @@
   sf->use_one_partition_size_always = 0;
   sf->less_rectangular_check = 0;
   sf->use_square_partition_only = 0;
-  sf->use_partitions_less_than = 0;
-  sf->less_than_block_size = BLOCK_SIZE_MB16X16;
-  sf->use_partitions_greater_than = 0;
-  sf->greater_than_block_size = BLOCK_SIZE_SB8X8;
+  sf->auto_min_max_partition_size = 0;
+  sf->auto_min_max_partition_interval = 0;
+  sf->auto_min_max_partition_count = 0;
+  sf->use_max_partition_size = 0;
+  sf->max_partition_size = BLOCK_64X64;
+  sf->use_min_partition_size = 0;
+  sf->min_partition_size = BLOCK_4X4;
   sf->adjust_partitioning_from_last_frame = 0;
   sf->last_partitioning_redo_frequency = 4;
   sf->disable_splitmv = 0;
@@ -788,10 +791,15 @@
         sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH |
                                      FLAG_SKIP_INTRA_BESTINTER |
                                      FLAG_SKIP_COMP_BESTINTRA;
-        sf->last_chroma_intra_mode = H_PRED;
+        sf->use_uv_intra_rd_estimate = 1;
         sf->use_rd_breakout = 1;
         sf->skip_encode_sb = 1;
         sf->auto_mv_step_size = 1;
+
+        sf->auto_min_max_partition_size = 1;
+        sf->use_max_partition_size = 1;
+        sf->use_min_partition_size = 1;
+        sf->auto_min_max_partition_interval = 1;
       }
       if (speed == 2) {
         sf->adjust_thresholds_by_speed = 1;
@@ -812,9 +820,9 @@
                                      FLAG_SKIP_COMP_BESTINTRA |
                                      FLAG_SKIP_COMP_REFMISMATCH;
         sf->last_chroma_intra_mode = DC_PRED;
+        sf->use_uv_intra_rd_estimate = 1;
         sf->use_rd_breakout = 1;
         sf->skip_encode_sb = 1;
-        sf->use_uv_intra_rd_estimate = 1;
         sf->using_small_partition_info = 1;
         sf->disable_splitmv =
             (MIN(cpi->common.width, cpi->common.height) >= 720)? 1 : 0;
@@ -862,14 +870,14 @@
       if (speed == 2) {
         sf->first_step = 0;
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_SB8X8;
-        sf->use_partitions_less_than = 1;
-        sf->less_than_block_size = BLOCK_SIZE_MB16X16;
+        sf->use_max_partition_size = 1;
+        sf->max_partition_size = BLOCK_SIZE_MB16X16;
       }
       if (speed == 3) {
         sf->first_step = 0;
         sf->comp_inter_joint_search_thresh = BLOCK_SIZE_SB8X8;
-        sf->use_partitions_greater_than = 1;
-        sf->greater_than_block_size = BLOCK_SIZE_SB8X8;
+        sf->use_min_partition_size = 1;
+        sf->min_partition_size = BLOCK_SIZE_SB8X8;
       }
       */
 
@@ -1383,7 +1391,7 @@
 
   cm = &cpi->common;
 
-  vpx_memset(cpi, 0, sizeof(VP9_COMP));
+  vp9_zero(*cpi);
 
   if (setjmp(cm->error.jmp)) {
     VP9_PTR ptr = ctx.ptr;
@@ -2818,7 +2826,7 @@
   }
 #endif
   loop_count = 0;
-  vpx_memset(cpi->rd_tx_select_threshes, 0, sizeof(cpi->rd_tx_select_threshes));
+  vp9_zero(cpi->rd_tx_select_threshes);
 
   if (cm->frame_type != KEY_FRAME) {
     /* TODO: Decide this more intelligently */
diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h
index 0798927..dc5e564 100644
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -258,10 +258,13 @@
   int unused_mode_skip_lvl;
   int reference_masking;
   BLOCK_SIZE_TYPE always_this_block_size;
-  int use_partitions_greater_than;
-  BLOCK_SIZE_TYPE greater_than_block_size;
-  int use_partitions_less_than;
-  BLOCK_SIZE_TYPE less_than_block_size;
+  int auto_min_max_partition_size;
+  int auto_min_max_partition_interval;
+  int auto_min_max_partition_count;
+  int use_min_partition_size;
+  BLOCK_SIZE_TYPE min_partition_size;
+  int use_max_partition_size;
+  BLOCK_SIZE_TYPE max_partition_size;
   int adjust_partitioning_from_last_frame;
   int last_partitioning_redo_frequency;
   int disable_splitmv;
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index 619f3e4..7fb3d7f 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -2204,7 +2204,7 @@
   MB_MODE_INFO *mbmi = &mi->mbmi;
   int mode_idx;
 
-  vpx_memset(bsi, 0, sizeof(*bsi));
+  vp9_zero(*bsi);
 
   bsi->segment_rd = best_rd;
   bsi->ref_mv = best_ref_mv;