Merge "Refactor 1D transforms" into nextgenv2
diff --git a/test/borders_test.cc b/test/borders_test.cc
index 6592375..ff3812c 100644
--- a/test/borders_test.cc
+++ b/test/borders_test.cc
@@ -52,7 +52,7 @@
   // extend into the border and test the border condition.
   cfg_.g_lag_in_frames = 25;
   cfg_.rc_2pass_vbr_minsection_pct = 5;
-  cfg_.rc_2pass_vbr_minsection_pct = 2000;
+  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
   cfg_.rc_target_bitrate = 2000;
   cfg_.rc_max_quantizer = 10;
 
diff --git a/test/cpu_speed_test.cc b/test/cpu_speed_test.cc
index 8baa2f9..6a938a0 100644
--- a/test/cpu_speed_test.cc
+++ b/test/cpu_speed_test.cc
@@ -74,7 +74,7 @@
   // the encoder to producing lots of big partitions which will likely
   // extend into the border and test the border condition.
   cfg_.rc_2pass_vbr_minsection_pct = 5;
-  cfg_.rc_2pass_vbr_minsection_pct = 2000;
+  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
   cfg_.rc_target_bitrate = 400;
   cfg_.rc_max_quantizer = 0;
   cfg_.rc_min_quantizer = 0;
@@ -92,7 +92,7 @@
   ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
   cfg_.g_timebase = video.timebase();
   cfg_.rc_2pass_vbr_minsection_pct = 5;
-  cfg_.rc_2pass_vbr_minsection_pct = 2000;
+  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
   cfg_.rc_target_bitrate = 400;
   cfg_.rc_max_quantizer = 0;
   cfg_.rc_min_quantizer = 0;
@@ -109,7 +109,7 @@
   // the encoder to producing lots of big partitions which will likely
   // extend into the border and test the border condition.
   cfg_.rc_2pass_vbr_minsection_pct = 5;
-  cfg_.rc_2pass_vbr_minsection_pct = 2000;
+  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
   cfg_.rc_target_bitrate = 12000;
   cfg_.rc_max_quantizer = 10;
   cfg_.rc_min_quantizer = 0;
@@ -125,7 +125,7 @@
   // when passing in a very high min q.  This pushes the encoder to producing
   // lots of small partitions which might will test the other condition.
   cfg_.rc_2pass_vbr_minsection_pct = 5;
-  cfg_.rc_2pass_vbr_minsection_pct = 2000;
+  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
   cfg_.rc_target_bitrate = 200;
   cfg_.rc_min_quantizer = 40;
 
diff --git a/test/vp9_ethread_test.cc b/test/vp9_ethread_test.cc
index 29a653f..3445bf2 100644
--- a/test/vp9_ethread_test.cc
+++ b/test/vp9_ethread_test.cc
@@ -48,7 +48,7 @@
       cfg_.g_lag_in_frames = 3;
       cfg_.rc_end_usage = VPX_VBR;
       cfg_.rc_2pass_vbr_minsection_pct = 5;
-      cfg_.rc_2pass_vbr_minsection_pct = 2000;
+      cfg_.rc_2pass_vbr_maxsection_pct = 2000;
     } else {
       cfg_.g_lag_in_frames = 0;
       cfg_.rc_end_usage = VPX_CBR;
diff --git a/vp10/common/blockd.h b/vp10/common/blockd.h
index d5139f7..016fc75 100644
--- a/vp10/common/blockd.h
+++ b/vp10/common/blockd.h
@@ -380,7 +380,7 @@
 #if CONFIG_EXT_TX
 #define ALLOW_INTRA_EXT_TX       1
 // whether masked transforms are used for 32X32
-#define USE_MSKTX_FOR_32X32      1
+#define USE_MSKTX_FOR_32X32      0
 
 static const int num_ext_tx_set_inter[EXT_TX_SETS_INTER] = {
   1, 19, 12, 2
@@ -447,7 +447,7 @@
   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
   { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
   { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
-  { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
+  { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
 };
 
 static INLINE int get_ext_tx_types(TX_SIZE tx_size, BLOCK_SIZE bs,
diff --git a/vp10/common/common.h b/vp10/common/common.h
index 4abcbf6..54c7b89 100644
--- a/vp10/common/common.h
+++ b/vp10/common/common.h
@@ -33,12 +33,12 @@
 
 // Use this for variably-sized arrays.
 #define vp10_copy_array(dest, src, n) {       \
-    assert(sizeof(*dest) == sizeof(*src));   \
-    memcpy(dest, src, n * sizeof(*src)); \
+    assert(sizeof(*(dest)) == sizeof(*(src)));   \
+    memcpy(dest, src, n * sizeof(*(src))); \
   }
 
 #define vp10_zero(dest) memset(&(dest), 0, sizeof(dest))
-#define vp10_zero_array(dest, n) memset(dest, 0, n * sizeof(*dest))
+#define vp10_zero_array(dest, n) memset(dest, 0, n * sizeof(*(dest)))
 
 static INLINE int get_unsigned_bits(unsigned int num_values) {
   return num_values > 0 ? get_msb(num_values) + 1 : 0;
diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c
index c7a2702..6543b33 100644
--- a/vp10/encoder/rdopt.c
+++ b/vp10/encoder/rdopt.c
@@ -6075,28 +6075,6 @@
       !is_comp_interintra_pred &&
 #endif  // CONFIG_EXT_INTER
       is_obmc_allowed(mbmi);
-  int best_obmc_flag = 0;
-#if CONFIG_VP9_HIGHBITDEPTH
-  DECLARE_ALIGNED(16, uint16_t, tmp_buf1_16[MAX_MB_PLANE * CU_SIZE * CU_SIZE]);
-  DECLARE_ALIGNED(16, uint16_t, tmp_buf2_16[MAX_MB_PLANE * CU_SIZE * CU_SIZE]);
-  uint8_t *tmp_buf1, *tmp_buf2;
-  uint8_t *obmc_tmp_buf1[3];
-  uint8_t *obmc_tmp_buf2[3];
-#else
-  DECLARE_ALIGNED(16, uint8_t, tmp_buf1[MAX_MB_PLANE * CU_SIZE * CU_SIZE]);
-  DECLARE_ALIGNED(16, uint8_t, tmp_buf2[MAX_MB_PLANE * CU_SIZE * CU_SIZE]);
-  uint8_t *obmc_tmp_buf1[3] = {tmp_buf1, tmp_buf1 + CU_SIZE * CU_SIZE,
-    tmp_buf1 + CU_SIZE * CU_SIZE * 2};
-  uint8_t *obmc_tmp_buf2[3] = {tmp_buf2, tmp_buf2 + CU_SIZE * CU_SIZE,
-    tmp_buf2 + CU_SIZE * CU_SIZE * 2};
-#endif  // CONFIG_VP9_HIGHBITDEPTH
-  int obmc_tmp_stride[3] = {CU_SIZE, CU_SIZE, CU_SIZE};
-
-  uint8_t skip_txfm_bestfilter[2][MAX_MB_PLANE << 2] = {{0}, {0}};
-  int64_t bsse_bestfilter[2][MAX_MB_PLANE << 2] = {{0}, {0}};
-  int skip_txfm_sb_bestfilter[2] = {0};
-  int64_t skip_sse_sb_bestfilter[2] = {INT64_MAX};
-
   int rate2_nocoeff, best_rate2 = INT_MAX,
       best_skippable, best_xskip, best_disable_skip = 0;
 #if CONFIG_SUPERTX
@@ -6154,25 +6132,9 @@
 #if CONFIG_VP9_HIGHBITDEPTH
   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
     tmp_buf = CONVERT_TO_BYTEPTR(tmp_buf16);
-#if CONFIG_OBMC
-    tmp_buf1 = CONVERT_TO_BYTEPTR(tmp_buf1_16);
-    tmp_buf2 = CONVERT_TO_BYTEPTR(tmp_buf2_16);
-#endif  // CONFIG_OBMC
   } else {
     tmp_buf = (uint8_t *)tmp_buf16;
-#if CONFIG_OBMC
-    tmp_buf1 = (uint8_t *)tmp_buf1_16;
-    tmp_buf2 = (uint8_t *)tmp_buf2_16;
-#endif  // CONFIG_OBMC
   }
-#if CONFIG_OBMC
-  obmc_tmp_buf1[0] = tmp_buf1;
-  obmc_tmp_buf1[1] = tmp_buf1 + 4096;
-  obmc_tmp_buf1[2] = tmp_buf1 + 8192;
-  obmc_tmp_buf2[0] = tmp_buf2;
-  obmc_tmp_buf2[1] = tmp_buf2 + 4096;
-  obmc_tmp_buf2[2] = tmp_buf2 + 8192;
-#endif  // CONFIG_OBMC
 #endif  // CONFIG_VP9_HIGHBITDEPTH
 
   if (is_comp_pred) {
@@ -6436,15 +6398,6 @@
       int64_t rs_rd;
       int tmp_skip_sb = 0;
       int64_t tmp_skip_sse = INT64_MAX;
-#if CONFIG_OBMC
-      int obmc_flag = 0;
-      int tmp_skip_sb_obmc = 0;
-      int64_t tmp_skip_sse_obmc = INT64_MAX;
-      int64_t rdobmc = INT64_MAX;
-      uint8_t *obmc_tmp_buf[3];
-      uint8_t tmp_skip_txfm[MAX_MB_PLANE << 2] = {0};
-      int64_t tmp_bsse[MAX_MB_PLANE << 2] = {0};
-#endif  // CONFIG_OBMC
 
       mbmi->interp_filter = i;
       rs = vp10_get_switchable_rate(cpi, xd);
@@ -6457,21 +6410,11 @@
             VPXMIN(filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
         if (cm->interp_filter == SWITCHABLE)
           rd += rs_rd;
-#if CONFIG_OBMC
-        if (allow_obmc) {
-          obmc_flag = best_obmc_flag;
-          rd += RDCOST(x->rdmult, x->rddiv,
-                       cpi->obmc_cost[bsize][obmc_flag], 0);
-        }
-#endif  // CONFIG_OBMC
         *mask_filter = VPXMAX(*mask_filter, rd);
       } else {
         int rate_sum = 0;
         int64_t dist_sum = 0;
-#if CONFIG_OBMC
-        int rate_sum_obmc = 0;
-        int64_t dist_sum_obmc = 0;
-#endif  // CONFIG_OBMC
+
         if (i > 0 && cpi->sf.adaptive_interp_filter_search &&
             (cpi->sf.interp_filter_search_mask & (1 << i))) {
           rate_sum = INT_MAX;
@@ -6488,18 +6431,10 @@
              (cm->interp_filter == mbmi->interp_filter ||
               (i == 0 && intpel_mv && IsInterpolatingFilter(i))))) {
           restore_dst_buf(xd, orig_dst, orig_dst_stride);
-#if CONFIG_OBMC
-          for (j = 0; j < MAX_MB_PLANE; j++) {
-            obmc_tmp_buf[j] = obmc_tmp_buf1[j];
-          }
-#endif  // CONFIG_OBMC
         } else {
           for (j = 0; j < MAX_MB_PLANE; j++) {
             xd->plane[j].dst.buf = tmp_buf + j * 64 * 64;
             xd->plane[j].dst.stride = 64;
-#if CONFIG_OBMC
-            obmc_tmp_buf[j] = obmc_tmp_buf2[j];
-#endif  // CONFIG_OBMC
           }
         }
         vp10_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
@@ -6507,34 +6442,6 @@
                         &tmp_skip_sb, &tmp_skip_sse);
 
         rd = RDCOST(x->rdmult, x->rddiv, rate_sum, dist_sum);
-#if CONFIG_OBMC
-        if (allow_obmc) {
-          rd += RDCOST(x->rdmult, x->rddiv, cpi->obmc_cost[bsize][0], 0);
-          memcpy(tmp_skip_txfm, x->skip_txfm, sizeof(tmp_skip_txfm));
-          memcpy(tmp_bsse, x->bsse, sizeof(tmp_bsse));
-
-          vp10_build_obmc_inter_prediction(cm, xd, mi_row, mi_col, 1,
-                                           obmc_tmp_buf, obmc_tmp_stride,
-                                           dst_buf1, dst_stride1,
-                                           dst_buf2, dst_stride2);
-          for (j = 0; j < MAX_MB_PLANE; ++j) {
-            xd->plane[j].dst.buf = obmc_tmp_buf[j];
-            xd->plane[j].dst.stride = obmc_tmp_stride[j];
-          }
-          model_rd_for_sb(cpi, bsize, x, xd, &rate_sum_obmc, &dist_sum_obmc,
-                          &tmp_skip_sb_obmc, &tmp_skip_sse_obmc);
-          rdobmc = RDCOST(x->rdmult, x->rddiv,
-                          rate_sum_obmc + cpi->obmc_cost[bsize][1],
-                          dist_sum_obmc);
-
-          if ((double)rdobmc <= 0.99 * (double)rd) {
-            obmc_flag = 1;
-            rd = rdobmc;
-            rate_sum = rate_sum_obmc;
-            dist_sum = dist_sum_obmc;
-          }
-        }
-#endif  // CONFIG_OBMC
         filter_cache[i] = rd;
         filter_cache[SWITCHABLE_FILTERS] =
             VPXMIN(filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
@@ -6557,10 +6464,6 @@
       newbest = i == 0 || rd < best_rd;
 
       if (newbest) {
-#if CONFIG_OBMC
-        if (allow_obmc)
-          best_obmc_flag = obmc_flag;
-#endif  // CONFIG_OBMC
         best_rd = rd;
         best_filter = mbmi->interp_filter;
         if (cm->interp_filter == SWITCHABLE && i &&
@@ -6574,31 +6477,6 @@
         pred_exists = 1;
         tmp_rd = best_rd;
 
-#if CONFIG_OBMC
-        if (allow_obmc) {
-          skip_txfm_sb_bestfilter[0] = tmp_skip_sb;
-          skip_sse_sb_bestfilter[0] = tmp_skip_sse;
-          memcpy(skip_txfm_bestfilter[0], tmp_skip_txfm, sizeof(skip_txfm));
-          memcpy(bsse_bestfilter[0], tmp_bsse, sizeof(bsse));
-
-          skip_txfm_sb_bestfilter[1] = tmp_skip_sb_obmc;
-          skip_sse_sb_bestfilter[1] = tmp_skip_sse_obmc;
-          memcpy(skip_txfm_bestfilter[1], x->skip_txfm, sizeof(skip_txfm));
-          memcpy(bsse_bestfilter[1], x->bsse, sizeof(bsse));
-          if (best_obmc_flag) {
-            tmp_skip_sb = tmp_skip_sb_obmc;
-            tmp_skip_sse = tmp_skip_sse_obmc;
-          } else {
-            memcpy(x->skip_txfm, tmp_skip_txfm, sizeof(tmp_skip_txfm));
-            memcpy(x->bsse, tmp_bsse, sizeof(tmp_bsse));
-          }
-        } else {
-          skip_txfm_sb_bestfilter[0] = tmp_skip_sb;
-          skip_sse_sb_bestfilter[0] = tmp_skip_sse;
-          memcpy(skip_txfm_bestfilter[0], x->skip_txfm, sizeof(skip_txfm));
-          memcpy(bsse_bestfilter[0], x->bsse, sizeof(bsse));
-        }
-#endif  // CONFIG_OBMC
         skip_txfm_sb = tmp_skip_sb;
         skip_sse_sb = tmp_skip_sse;
         memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm));
@@ -6923,15 +6801,7 @@
 #endif  // CONFIG_EXT_INTERP
 #endif  // CONFIG_EXT_INTER
 
-#if CONFIG_OBMC
-  if (allow_obmc)
-    mbmi->obmc = best_obmc_flag;
-  else
-    mbmi->obmc = 0;
-#endif  // CONFIG_OBMC
-
   if (pred_exists) {
-#if !CONFIG_OBMC
     if (best_needs_copy) {
       // again temporarily set the buffers to local memory to prevent a memcpy
       for (i = 0; i < MAX_MB_PLANE; i++) {
@@ -6939,20 +6809,11 @@
         xd->plane[i].dst.stride = 64;
       }
     }
-#endif  // !CONFIG_OBMC
-    rd = tmp_rd + RDCOST(x->rdmult, x->rddiv, rs, 0);
-#if CONFIG_OBMC
-    if (allow_obmc)
-      rd += RDCOST(x->rdmult, x->rddiv,
-                   cpi->obmc_cost[bsize][mbmi->obmc], 0);
-#endif  // CONFIG_OBMC
+    rd = tmp_rd;
   } else {
     int tmp_rate;
     int64_t tmp_dist;
-#if CONFIG_OBMC
-    int64_t rdobmc = INT64_MAX;
-    restore_dst_buf(xd, orig_dst, orig_dst_stride);
-#endif  // CONFIG_OBMC
+
     // Handles the special case when a filter that is not in the
     // switchable list (ex. bilinear) is indicated at the frame level, or
     // skip condition holds.
@@ -6960,34 +6821,6 @@
     model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist,
                     &skip_txfm_sb, &skip_sse_sb);
     rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist);
-#if CONFIG_OBMC
-    skip_txfm_sb_bestfilter[0] = skip_txfm_sb;
-    skip_sse_sb_bestfilter[0] = skip_sse_sb;
-    memcpy(skip_txfm_bestfilter[0], x->skip_txfm, sizeof(skip_txfm));
-    memcpy(bsse_bestfilter[0], x->bsse, sizeof(bsse));
-    if (allow_obmc) {
-      rd += RDCOST(x->rdmult, x->rddiv, cpi->obmc_cost[bsize][0], 0);
-      vp10_build_obmc_inter_prediction(cm, xd, mi_row, mi_col, 1,
-                                       obmc_tmp_buf1, obmc_tmp_stride,
-                                       dst_buf1, dst_stride1,
-                                       dst_buf2, dst_stride2);
-      for (i = 0; i < MAX_MB_PLANE; ++i) {
-        xd->plane[i].dst.buf = obmc_tmp_buf1[i];
-        xd->plane[i].dst.stride = obmc_tmp_stride[i];
-      }
-      model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist,
-                      &skip_txfm_sb, &skip_sse_sb);
-      rdobmc = RDCOST(x->rdmult, x->rddiv,
-                      rs + tmp_rate + cpi->obmc_cost[bsize][1], tmp_dist);
-
-      skip_txfm_sb_bestfilter[1] = skip_txfm_sb;
-      skip_sse_sb_bestfilter[1] = skip_sse_sb;
-      memcpy(skip_txfm_bestfilter[1], x->skip_txfm, sizeof(skip_txfm));
-      memcpy(bsse_bestfilter[1], x->bsse, sizeof(bsse));
-      if ((double)rdobmc <= 0.99 * (double)rd)
-        rd = rdobmc;
-    }
-#endif  // CONFIG_OBMC
     memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm));
     memcpy(bsse, x->bsse, sizeof(bsse));
   }
@@ -7078,40 +6911,16 @@
 #if CONFIG_OBMC
   best_rd = INT64_MAX;
   for (mbmi->obmc = 0; mbmi->obmc <= allow_obmc; mbmi->obmc++) {
-    int64_t tmp_rd;
+    int64_t tmp_rd, tmp_dist;
+    int tmp_rate;
 
-    if (pred_exists) {
-      if (best_needs_copy) {
-        if (mbmi->obmc) {
-          for (i = 0; i < MAX_MB_PLANE; i++) {
-            xd->plane[i].dst.buf = obmc_tmp_buf2[i];
-            xd->plane[i].dst.stride = 64;
-          }
-        } else {
-          for (i = 0; i < MAX_MB_PLANE; i++) {
-            xd->plane[i].dst.buf = tmp_buf + i * 64 * 64;
-            xd->plane[i].dst.stride = 64;
-          }
-        }
-      } else {
-        if (mbmi->obmc) {
-          for (i = 0; i < MAX_MB_PLANE; i++) {
-            xd->plane[i].dst.buf = obmc_tmp_buf1[i];
-            xd->plane[i].dst.stride = 64;
-          }
-        } else {
-          restore_dst_buf(xd, orig_dst, orig_dst_stride);
-        }
-      }
-    } else {
-      if (mbmi->obmc) {
-        for (i = 0; i < MAX_MB_PLANE; i++) {
-          xd->plane[i].dst.buf = obmc_tmp_buf1[i];
-          xd->plane[i].dst.stride = 64;
-        }
-      } else {
-        restore_dst_buf(xd, orig_dst, orig_dst_stride);
-      }
+    if (mbmi->obmc) {
+      vp10_build_obmc_inter_prediction(cm, xd, mi_row, mi_col, 0,
+                                       NULL, NULL,
+                                       dst_buf1, dst_stride1,
+                                       dst_buf2, dst_stride2);
+      model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist,
+                      &skip_txfm_sb, &skip_sse_sb);
     }
 #if CONFIG_VP9_HIGHBITDEPTH
     if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
@@ -7126,11 +6935,6 @@
         vp10_get_sby_perpixel_variance(cpi, &xd->plane[0].dst, bsize);
 #endif  // CONFIG_VP9_HIGHBITDEPTH
 
-    skip_txfm_sb = skip_txfm_sb_bestfilter[mbmi->obmc];
-    skip_sse_sb = skip_sse_sb_bestfilter[mbmi->obmc];
-    memcpy(x->skip_txfm, skip_txfm_bestfilter[mbmi->obmc],
-           sizeof(skip_txfm));
-    memcpy(x->bsse, bsse_bestfilter[mbmi->obmc], sizeof(bsse));
     x->skip = 0;
 
     *rate2 = rate2_nocoeff;
@@ -7231,10 +7035,7 @@
 
     // The cost of skip bit needs to be added.
 #if CONFIG_OBMC
-    mbmi->skip = xd->lossless[mbmi->segment_id] ? 0 : 1;
-    if (xd->lossless[mbmi->segment_id])
-      *rate2 += vp10_cost_bit(vp10_get_skip_prob(cm, xd), 0);
-    else
+    mbmi->skip = 0;
 #endif  // CONFIG_OBMC
     *rate2 += vp10_cost_bit(vp10_get_skip_prob(cm, xd), 1);
 
diff --git a/vp8/common/common.h b/vp8/common/common.h
index e58a9cc..c42e875 100644
--- a/vp8/common/common.h
+++ b/vp8/common/common.h
@@ -32,13 +32,13 @@
 /* Use this for variably-sized arrays. */
 
 #define vp8_copy_array( Dest, Src, N) { \
-        assert( sizeof( *Dest) == sizeof( *Src)); \
-        memcpy( Dest, Src, N * sizeof( *Src)); \
+        assert( sizeof( *(Dest)) == sizeof( *(Src))); \
+        memcpy( Dest, Src, N * sizeof( *(Src))); \
     }
 
-#define vp8_zero( Dest)  memset( &Dest, 0, sizeof( Dest));
+#define vp8_zero( Dest)  memset( &(Dest), 0, sizeof( Dest));
 
-#define vp8_zero_array( Dest, N)  memset( Dest, 0, N * sizeof( *Dest));
+#define vp8_zero_array( Dest, N)  memset( Dest, 0, N * sizeof( *(Dest)));
 
 
 #ifdef __cplusplus
diff --git a/vp9/common/vp9_common.h b/vp9/common/vp9_common.h
index 76e7cd4..9d5dbc6 100644
--- a/vp9/common/vp9_common.h
+++ b/vp9/common/vp9_common.h
@@ -33,12 +33,12 @@
 
 // Use this for variably-sized arrays.
 #define vp9_copy_array(dest, src, n) {       \
-    assert(sizeof(*dest) == sizeof(*src));   \
-    memcpy(dest, src, n * sizeof(*src)); \
+    assert(sizeof(*(dest)) == sizeof(*(src)));   \
+    memcpy(dest, src, n * sizeof(*(src))); \
   }
 
 #define vp9_zero(dest) memset(&(dest), 0, sizeof(dest))
-#define vp9_zero_array(dest, n) memset(dest, 0, n * sizeof(*dest))
+#define vp9_zero_array(dest, n) memset(dest, 0, n * sizeof(*(dest)))
 
 static INLINE int get_unsigned_bits(unsigned int num_values) {
   return num_values > 0 ? get_msb(num_values) + 1 : 0;