Merge "Use defines for inline and __builtin_prefetch"
diff --git a/test/byte_alignment_test.cc b/test/byte_alignment_test.cc
new file mode 100644
index 0000000..aa4b78b
--- /dev/null
+++ b/test/byte_alignment_test.cc
@@ -0,0 +1,189 @@
+/*
+ *  Copyright (c) 2014 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 <string>
+
+#include "./vpx_config.h"
+#include "test/codec_factory.h"
+#include "test/decode_test_driver.h"
+#include "test/md5_helper.h"
+#include "test/util.h"
+#if CONFIG_WEBM_IO
+#include "test/webm_video_source.h"
+#endif
+
+namespace {
+
+const int kLegacyByteAlignment = 0;
+const int kLegacyYPlaneByteAlignment = 32;
+const int kNumPlanesToCheck = 3;
+const char kVP9TestFile[] = "vp90-2-02-size-lf-1920x1080.webm";
+const char kVP9Md5File[] = "vp90-2-02-size-lf-1920x1080.webm.md5";
+
+#if CONFIG_WEBM_IO
+
+struct ByteAlignmentTestParam {
+  int byte_alignment;
+  vpx_codec_err_t expected_value;
+  bool decode_remaining;
+};
+
+const ByteAlignmentTestParam kBaTestParams[] = {
+  {kLegacyByteAlignment, VPX_CODEC_OK, true},
+  {32, VPX_CODEC_OK, true},
+  {64, VPX_CODEC_OK, true},
+  {128, VPX_CODEC_OK, true},
+  {256, VPX_CODEC_OK, true},
+  {512, VPX_CODEC_OK, true},
+  {1024, VPX_CODEC_OK, true},
+  {1, VPX_CODEC_INVALID_PARAM, false},
+  {-2, VPX_CODEC_INVALID_PARAM, false},
+  {4, VPX_CODEC_INVALID_PARAM, false},
+  {16, VPX_CODEC_INVALID_PARAM, false},
+  {255, VPX_CODEC_INVALID_PARAM, false},
+  {2048, VPX_CODEC_INVALID_PARAM, false},
+};
+
+// Class for testing byte alignment of reference buffers.
+class ByteAlignmentTest
+    : public ::testing::TestWithParam<ByteAlignmentTestParam> {
+ protected:
+  ByteAlignmentTest()
+      : video_(NULL),
+        decoder_(NULL),
+        md5_file_(NULL) {}
+
+  virtual void SetUp() {
+    video_ = new libvpx_test::WebMVideoSource(kVP9TestFile);
+    ASSERT_TRUE(video_ != NULL);
+    video_->Init();
+    video_->Begin();
+
+    const vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
+    decoder_ = new libvpx_test::VP9Decoder(cfg, 0);
+    ASSERT_TRUE(decoder_ != NULL);
+
+    OpenMd5File(kVP9Md5File);
+  }
+
+  virtual void TearDown() {
+    if (md5_file_ != NULL)
+      fclose(md5_file_);
+
+    delete decoder_;
+    delete video_;
+  }
+
+  void SetByteAlignment(int byte_alignment, vpx_codec_err_t expected_value) {
+    decoder_->Control(VP9_SET_BYTE_ALIGNMENT, byte_alignment, expected_value);
+  }
+
+  vpx_codec_err_t DecodeOneFrame(int byte_alignment_to_check) {
+    const vpx_codec_err_t res =
+        decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
+    CheckDecodedFrames(byte_alignment_to_check);
+    if (res == VPX_CODEC_OK)
+      video_->Next();
+    return res;
+  }
+
+  vpx_codec_err_t DecodeRemainingFrames(int byte_alignment_to_check) {
+    for (; video_->cxdata() != NULL; video_->Next()) {
+      const vpx_codec_err_t res =
+          decoder_->DecodeFrame(video_->cxdata(), video_->frame_size());
+      if (res != VPX_CODEC_OK)
+        return res;
+      CheckDecodedFrames(byte_alignment_to_check);
+    }
+    return VPX_CODEC_OK;
+  }
+
+ private:
+  // Check if |data| is aligned to |byte_alignment_to_check|.
+  // |byte_alignment_to_check| must be a power of 2.
+  void CheckByteAlignment(const uint8_t *data, int byte_alignment_to_check) {
+    ASSERT_EQ(0u, reinterpret_cast<size_t>(data) % byte_alignment_to_check);
+  }
+
+  // Iterate through the planes of the decoded frames and check for
+  // alignment based off |byte_alignment_to_check|.
+  void CheckDecodedFrames(int byte_alignment_to_check) {
+    libvpx_test::DxDataIterator dec_iter = decoder_->GetDxData();
+    const vpx_image_t *img;
+
+    // Get decompressed data
+    while ((img = dec_iter.Next()) != NULL) {
+      if (byte_alignment_to_check == kLegacyByteAlignment) {
+        CheckByteAlignment(img->planes[0], kLegacyYPlaneByteAlignment);
+      } else {
+        for (int i = 0; i < kNumPlanesToCheck; ++i) {
+          CheckByteAlignment(img->planes[i], byte_alignment_to_check);
+        }
+      }
+      CheckMd5(*img);
+    }
+  }
+
+  // TODO(fgalligan): Move the MD5 testing code into another class.
+  void OpenMd5File(const std::string &md5_file_name_) {
+    md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
+    ASSERT_TRUE(md5_file_ != NULL) << "MD5 file open failed. Filename: "
+        << md5_file_name_;
+  }
+
+  void CheckMd5(const vpx_image_t &img) {
+    ASSERT_TRUE(md5_file_ != NULL);
+    char expected_md5[33];
+    char junk[128];
+
+    // Read correct md5 checksums.
+    const int res = fscanf(md5_file_, "%s  %s", expected_md5, junk);
+    ASSERT_NE(EOF, res) << "Read md5 data failed";
+    expected_md5[32] = '\0';
+
+    ::libvpx_test::MD5 md5_res;
+    md5_res.Add(&img);
+    const char *const actual_md5 = md5_res.Get();
+
+    // Check md5 match.
+    ASSERT_STREQ(expected_md5, actual_md5) << "MD5 checksums don't match";
+  }
+
+  libvpx_test::WebMVideoSource *video_;
+  libvpx_test::VP9Decoder *decoder_;
+  FILE *md5_file_;
+};
+
+TEST_F(ByteAlignmentTest, SwitchByteAlignment) {
+  const int num_elements = 14;
+  const int byte_alignments[] = { 0, 32, 64, 128, 256, 512, 1024,
+                                  0, 1024, 32, 512, 64, 256, 128 };
+
+  for (int i = 0; i < num_elements; ++i) {
+    SetByteAlignment(byte_alignments[i], VPX_CODEC_OK);
+    ASSERT_EQ(VPX_CODEC_OK, DecodeOneFrame(byte_alignments[i]));
+  }
+  SetByteAlignment(byte_alignments[0], VPX_CODEC_OK);
+  ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames(byte_alignments[0]));
+}
+
+TEST_P(ByteAlignmentTest, TestAlignment) {
+  const ByteAlignmentTestParam t = GetParam();
+  SetByteAlignment(t.byte_alignment, t.expected_value);
+  if (t.decode_remaining)
+    ASSERT_EQ(VPX_CODEC_OK, DecodeRemainingFrames(t.byte_alignment));
+}
+
+INSTANTIATE_TEST_CASE_P(Alignments, ByteAlignmentTest,
+                        ::testing::ValuesIn(kBaTestParams));
+
+#endif  // CONFIG_WEBM_IO
+
+}  // namespace
diff --git a/test/decode_test_driver.h b/test/decode_test_driver.h
index 232428e..f566c53 100644
--- a/test/decode_test_driver.h
+++ b/test/decode_test_driver.h
@@ -72,9 +72,7 @@
   }
 
   void Control(int ctrl_id, int arg) {
-    InitOnce();
-    const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
-    ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
+    Control(ctrl_id, arg, VPX_CODEC_OK);
   }
 
   void Control(int ctrl_id, const void *arg) {
@@ -83,6 +81,12 @@
     ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
   }
 
+  void Control(int ctrl_id, int arg, vpx_codec_err_t expected_value) {
+    InitOnce();
+    const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
+    ASSERT_EQ(expected_value, res) << DecodeError();
+  }
+
   const char* DecodeError() {
     const char *detail = vpx_codec_error_detail(&decoder_);
     return detail ? detail : vpx_codec_error(&decoder_);
diff --git a/test/test.mk b/test/test.mk
index 6e935de..bd65759 100644
--- a/test/test.mk
+++ b/test/test.mk
@@ -31,6 +31,7 @@
 LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += cq_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += keyframe_test.cc
 
+LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += byte_alignment_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += external_frame_buffer_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += invalid_file_test.cc
 LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += user_priv_test.cc
diff --git a/vp8/common/loopfilter.c b/vp8/common/loopfilter.c
index 7a07e76..da2275e 100644
--- a/vp8/common/loopfilter.c
+++ b/vp8/common/loopfilter.c
@@ -261,6 +261,7 @@
     int mb_col;
     int filter_level;
     loop_filter_info_n *lfi_n = &cm->lf_info;
+    (void)post_uvstride;
 
     for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
     {
diff --git a/vp8/common/postproc.c b/vp8/common/postproc.c
index 277f371..b112663 100644
--- a/vp8/common/postproc.c
+++ b/vp8/common/postproc.c
@@ -518,6 +518,7 @@
                            unsigned int Width, unsigned int Height, int Pitch)
 {
     unsigned int i, j;
+    (void)bothclamp;
 
     for (i = 0; i < Height; i++)
     {
diff --git a/vp8/decoder/decodeframe.c b/vp8/decoder/decodeframe.c
index e7cf0d9..ab03c90 100644
--- a/vp8/decoder/decodeframe.c
+++ b/vp8/decoder/decodeframe.c
@@ -101,6 +101,8 @@
     int i;
 #if CONFIG_ERROR_CONCEALMENT
     int corruption_detected = 0;
+#else
+    (void)mb_idx;
 #endif
 
     if (xd->mode_info_context->mbmi.mb_skip_coeff)
diff --git a/vp8/decoder/decodemv.c b/vp8/decoder/decodemv.c
index 35a22c7..1d155e7 100644
--- a/vp8/decoder/decodemv.c
+++ b/vp8/decoder/decodemv.c
@@ -591,6 +591,8 @@
 static void decode_mb_mode_mvs(VP8D_COMP *pbi, MODE_INFO *mi,
                                MB_MODE_INFO *mbmi)
 {
+    (void)mbmi;
+
     /* Read the Macroblock segmentation map if it is being updated explicitly
      * this frame (reset to 0 above by default)
      * By default on a key frame reset all MBs to segment 0
diff --git a/vp8/decoder/onyxd_if.c b/vp8/decoder/onyxd_if.c
index 1d763b6..3ec5327 100644
--- a/vp8/decoder/onyxd_if.c
+++ b/vp8/decoder/onyxd_if.c
@@ -87,6 +87,7 @@
     pbi->ec_enabled = oxcf->error_concealment;
     pbi->overlaps = NULL;
 #else
+    (void)oxcf;
     pbi->ec_enabled = 0;
 #endif
     /* Error concealment is activated after a key frame has been
@@ -303,6 +304,8 @@
 {
     VP8_COMMON *cm = &pbi->common;
     int retcode = -1;
+    (void)size;
+    (void)source;
 
     pbi->common.error.error_code = VPX_CODEC_OK;
 
@@ -407,6 +410,7 @@
 #if CONFIG_POSTPROC
     ret = vp8_post_proc_frame(&pbi->common, sd, flags);
 #else
+    (void)flags;
 
     if (pbi->common.frame_to_show)
     {
diff --git a/vp8/decoder/threading.c b/vp8/decoder/threading.c
index fe290cf..dfc7570 100644
--- a/vp8/decoder/threading.c
+++ b/vp8/decoder/threading.c
@@ -96,6 +96,8 @@
     int i;
 #if CONFIG_ERROR_CONCEALMENT
     int corruption_detected = 0;
+#else
+    (void)mb_idx;
 #endif
 
     if (xd->mode_info_context->mbmi.mb_skip_coeff)
diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c
index 70632c0..62d5d2d 100644
--- a/vp8/encoder/encodeframe.c
+++ b/vp8/encoder/encodeframe.c
@@ -82,6 +82,7 @@
 {
     unsigned int act;
     unsigned int sse;
+    (void)cpi;
     /* TODO: This could also be done over smaller areas (8x8), but that would
      *  require extensive changes elsewhere, as lambda is assumed to be fixed
      *  over an entire MB in most of the code.
@@ -1149,6 +1150,8 @@
         while (++b < 16);
     }
 
+#else
+    (void)cpi;
 #endif
 
     ++x->ymode_count[m];
diff --git a/vp8/encoder/firstpass.c b/vp8/encoder/firstpass.c
index 98e5a71..85767ef 100644
--- a/vp8/encoder/firstpass.c
+++ b/vp8/encoder/firstpass.c
@@ -132,6 +132,7 @@
                          FIRSTPASS_STATS            *stats)
 {
     struct vpx_codec_cx_pkt pkt;
+    (void)cpi;
     pkt.kind = VPX_CODEC_STATS_PKT;
     pkt.data.twopass_stats.buf = stats;
     pkt.data.twopass_stats.sz = sizeof(FIRSTPASS_STATS);
@@ -418,6 +419,7 @@
     int raw_stride = raw_buffer->y_stride;
     unsigned char *ref_ptr;
     int ref_stride = x->e_mbd.pre.y_stride;
+    (void)cpi;
 
     /* Set up pointers for this macro block raw buffer */
     raw_ptr = (unsigned char *)(raw_buffer->y_buffer + recon_yoffset
@@ -1409,6 +1411,7 @@
 
 void vp8_end_second_pass(VP8_COMP *cpi)
 {
+  (void)cpi;
 }
 
 /* This function gives and estimate of how badly we believe the prediction
@@ -1419,6 +1422,7 @@
     double prediction_decay_rate;
     double motion_decay;
     double motion_pct = next_frame->pcnt_motion;
+    (void)cpi;
 
     /* Initial basis is the % mbs inter coded */
     prediction_decay_rate = next_frame->pcnt_inter;
@@ -1547,6 +1551,7 @@
     double this_frame_mvr_ratio;
     double this_frame_mvc_ratio;
     double motion_pct;
+    (void)cpi;
 
     /* Accumulate motion stats. */
     motion_pct = this_frame->pcnt_motion;
diff --git a/vp8/encoder/mcomp.c b/vp8/encoder/mcomp.c
index 545f2c8..237c8eb 100644
--- a/vp8/encoder/mcomp.c
+++ b/vp8/encoder/mcomp.c
@@ -888,6 +888,8 @@
     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
 
+    (void)mvcost;
+
     /* adjust ref_mv to make sure it is within MV range */
     vp8_clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
     br = ref_mv->as_mv.row;
@@ -911,6 +913,8 @@
     else if (search_param >= 1) hex_range = 63;
 
     dia_range = 8;
+#else
+    (void)search_param;
 #endif
 
     /* hex search */
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index b046456..41b3066 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -5831,6 +5831,7 @@
         cpi->common.show_frame_mi = cpi->common.mi;
         ret = vp8_post_proc_frame(&cpi->common, dest, flags);
 #else
+        (void)flags;
 
         if (cpi->common.frame_to_show)
         {
diff --git a/vp8/encoder/pickinter.c b/vp8/encoder/pickinter.c
index 9eb6932..fc026aa 100644
--- a/vp8/encoder/pickinter.c
+++ b/vp8/encoder/pickinter.c
@@ -180,6 +180,7 @@
     (void) ref_mv;
     (void) error_per_bit;
     (void) vfp;
+    (void) mb;
     (void) mvcost;
     (void) distortion;
     (void) sse;
diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c
index 2f6f5d0..29da926 100644
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -837,6 +837,9 @@
 static int rd_inter16x16_uv(VP8_COMP *cpi, MACROBLOCK *x, int *rate,
                             int *distortion, int fullpixel)
 {
+    (void)cpi;
+    (void)fullpixel;
+
     vp8_build_inter16x16_predictors_mbuv(&x->e_mbd);
     vp8_subtract_mbuv(x->src_diff,
         x->src.u_buffer, x->src.v_buffer, x->src.uv_stride,
@@ -854,6 +857,9 @@
 static int rd_inter4x4_uv(VP8_COMP *cpi, MACROBLOCK *x, int *rate,
                           int *distortion, int fullpixel)
 {
+    (void)cpi;
+    (void)fullpixel;
+
     vp8_build_inter4x4_predictors_mbuv(&x->e_mbd);
     vp8_subtract_mbuv(x->src_diff,
         x->src.u_buffer, x->src.v_buffer, x->src.uv_stride,
diff --git a/vp8/encoder/temporal_filter.c b/vp8/encoder/temporal_filter.c
index 4dc0d95..04501ac 100644
--- a/vp8/encoder/temporal_filter.c
+++ b/vp8/encoder/temporal_filter.c
@@ -163,6 +163,8 @@
     int pre = d->offset;
     int pre_stride = x->e_mbd.pre.y_stride;
 
+    (void)error_thresh;
+
     best_ref_mv1.as_int = 0;
     best_ref_mv1_full.as_mv.col = best_ref_mv1.as_mv.col >>3;
     best_ref_mv1_full.as_mv.row = best_ref_mv1.as_mv.row >>3;
diff --git a/vp8/vp8_cx_iface.c b/vp8/vp8_cx_iface.c
index 3426f59..f81f078 100644
--- a/vp8/vp8_cx_iface.c
+++ b/vp8/vp8_cx_iface.c
@@ -384,6 +384,8 @@
         oxcf->mr_down_sampling_factor.den = mr_cfg->mr_down_sampling_factor.den;
         oxcf->mr_low_res_mode_info        = mr_cfg->mr_low_res_mode_info;
     }
+#else
+    (void)mr_cfg;
 #endif
 
     oxcf->cpu_used               = vp8_cfg.cpu_used;
@@ -628,6 +630,9 @@
         *mem_loc = (void *)shared_mem_loc;
         res = VPX_CODEC_OK;
     }
+#else
+    (void)cfg;
+    (void)mem_loc;
 #endif
     return res;
 }
diff --git a/vp8/vp8_dx_iface.c b/vp8/vp8_dx_iface.c
index 352ed7b..6810644 100644
--- a/vp8/vp8_dx_iface.c
+++ b/vp8/vp8_dx_iface.c
@@ -74,6 +74,7 @@
      * known)
      */
     (void)si;
+    (void)flags;
     return sizeof(vpx_codec_alg_priv_t);
 }
 
@@ -647,6 +648,8 @@
         return VPX_CODEC_INVALID_PARAM;
 
 #else
+    (void)ctx;
+    (void)args;
     return VPX_CODEC_INCAPABLE;
 #endif
 }
diff --git a/vp9/common/arm/neon/vp9_reconintra_neon.c b/vp9/common/arm/neon/vp9_reconintra_neon.c
new file mode 100644
index 0000000..d0beaa7
--- /dev/null
+++ b/vp9/common/arm/neon/vp9_reconintra_neon.c
@@ -0,0 +1,473 @@
+/*
+ *  Copyright (c) 2014 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 <stddef.h>
+#include <arm_neon.h>
+
+void vp9_v_predictor_4x4_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int i;
+    uint32x2_t d0u32 = vdup_n_u32(0);
+    (void)left;
+
+    d0u32 = vld1_lane_u32((const uint32_t *)above, d0u32, 0);
+    for (i = 0; i < 4; i++, dst += y_stride)
+        vst1_lane_u32((uint32_t *)dst, d0u32, 0);
+    return;
+}
+
+void vp9_v_predictor_8x8_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int i;
+    uint8x8_t d0u8 = vdup_n_u8(0);
+    (void)left;
+
+    d0u8 = vld1_u8(above);
+    for (i = 0; i < 8; i++, dst += y_stride)
+        vst1_u8(dst, d0u8);
+    return;
+}
+
+void vp9_v_predictor_16x16_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int i;
+    uint8x16_t q0u8 = vdupq_n_u8(0);
+    (void)left;
+
+    q0u8 = vld1q_u8(above);
+    for (i = 0; i < 16; i++, dst += y_stride)
+        vst1q_u8(dst, q0u8);
+    return;
+}
+
+void vp9_v_predictor_32x32_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int i;
+    uint8x16_t q0u8 = vdupq_n_u8(0);
+    uint8x16_t q1u8 = vdupq_n_u8(0);
+    (void)left;
+
+    q0u8 = vld1q_u8(above);
+    q1u8 = vld1q_u8(above + 16);
+    for (i = 0; i < 32; i++, dst += y_stride) {
+        vst1q_u8(dst, q0u8);
+        vst1q_u8(dst + 16, q1u8);
+    }
+    return;
+}
+
+void vp9_h_predictor_4x4_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    uint8x8_t d0u8 = vdup_n_u8(0);
+    uint32x2_t d1u32 = vdup_n_u32(0);
+    (void)above;
+
+    d1u32 = vld1_lane_u32((const uint32_t *)left, d1u32, 0);
+
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u32(d1u32), 0);
+    vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d0u8), 0);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u32(d1u32), 1);
+    vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d0u8), 0);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u32(d1u32), 2);
+    vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d0u8), 0);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u32(d1u32), 3);
+    vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d0u8), 0);
+    return;
+}
+
+void vp9_h_predictor_8x8_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    uint8x8_t d0u8 = vdup_n_u8(0);
+    uint64x1_t d1u64 = vdup_n_u64(0);
+    (void)above;
+
+    d1u64 = vld1_u64((const uint64_t *)left);
+
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u64(d1u64), 0);
+    vst1_u8(dst, d0u8);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u64(d1u64), 1);
+    vst1_u8(dst, d0u8);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u64(d1u64), 2);
+    vst1_u8(dst, d0u8);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u64(d1u64), 3);
+    vst1_u8(dst, d0u8);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u64(d1u64), 4);
+    vst1_u8(dst, d0u8);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u64(d1u64), 5);
+    vst1_u8(dst, d0u8);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u64(d1u64), 6);
+    vst1_u8(dst, d0u8);
+    dst += y_stride;
+    d0u8 = vdup_lane_u8(vreinterpret_u8_u64(d1u64), 7);
+    vst1_u8(dst, d0u8);
+    return;
+}
+
+void vp9_h_predictor_16x16_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int j;
+    uint8x8_t d2u8 = vdup_n_u8(0);
+    uint8x16_t q0u8 = vdupq_n_u8(0);
+    uint8x16_t q1u8 = vdupq_n_u8(0);
+    (void)above;
+
+    q1u8 = vld1q_u8(left);
+    d2u8 = vget_low_u8(q1u8);
+    for (j = 0; j < 2; j++, d2u8 = vget_high_u8(q1u8)) {
+        q0u8 = vdupq_lane_u8(d2u8, 0);
+        vst1q_u8(dst, q0u8);
+        dst += y_stride;
+        q0u8 = vdupq_lane_u8(d2u8, 1);
+        vst1q_u8(dst, q0u8);
+        dst += y_stride;
+        q0u8 = vdupq_lane_u8(d2u8, 2);
+        vst1q_u8(dst, q0u8);
+        dst += y_stride;
+        q0u8 = vdupq_lane_u8(d2u8, 3);
+        vst1q_u8(dst, q0u8);
+        dst += y_stride;
+        q0u8 = vdupq_lane_u8(d2u8, 4);
+        vst1q_u8(dst, q0u8);
+        dst += y_stride;
+        q0u8 = vdupq_lane_u8(d2u8, 5);
+        vst1q_u8(dst, q0u8);
+        dst += y_stride;
+        q0u8 = vdupq_lane_u8(d2u8, 6);
+        vst1q_u8(dst, q0u8);
+        dst += y_stride;
+        q0u8 = vdupq_lane_u8(d2u8, 7);
+        vst1q_u8(dst, q0u8);
+        dst += y_stride;
+    }
+    return;
+}
+
+void vp9_h_predictor_32x32_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int j, k;
+    uint8x8_t d2u8 = vdup_n_u8(0);
+    uint8x16_t q0u8 = vdupq_n_u8(0);
+    uint8x16_t q1u8 = vdupq_n_u8(0);
+    (void)above;
+
+    for (k = 0; k < 2; k++, left += 16) {
+        q1u8 = vld1q_u8(left);
+        d2u8 = vget_low_u8(q1u8);
+        for (j = 0; j < 2; j++, d2u8 = vget_high_u8(q1u8)) {
+            q0u8 = vdupq_lane_u8(d2u8, 0);
+            vst1q_u8(dst, q0u8);
+            vst1q_u8(dst + 16, q0u8);
+            dst += y_stride;
+            q0u8 = vdupq_lane_u8(d2u8, 1);
+            vst1q_u8(dst, q0u8);
+            vst1q_u8(dst + 16, q0u8);
+            dst += y_stride;
+            q0u8 = vdupq_lane_u8(d2u8, 2);
+            vst1q_u8(dst, q0u8);
+            vst1q_u8(dst + 16, q0u8);
+            dst += y_stride;
+            q0u8 = vdupq_lane_u8(d2u8, 3);
+            vst1q_u8(dst, q0u8);
+            vst1q_u8(dst + 16, q0u8);
+            dst += y_stride;
+            q0u8 = vdupq_lane_u8(d2u8, 4);
+            vst1q_u8(dst, q0u8);
+            vst1q_u8(dst + 16, q0u8);
+            dst += y_stride;
+            q0u8 = vdupq_lane_u8(d2u8, 5);
+            vst1q_u8(dst, q0u8);
+            vst1q_u8(dst + 16, q0u8);
+            dst += y_stride;
+            q0u8 = vdupq_lane_u8(d2u8, 6);
+            vst1q_u8(dst, q0u8);
+            vst1q_u8(dst + 16, q0u8);
+            dst += y_stride;
+            q0u8 = vdupq_lane_u8(d2u8, 7);
+            vst1q_u8(dst, q0u8);
+            vst1q_u8(dst + 16, q0u8);
+            dst += y_stride;
+        }
+    }
+    return;
+}
+
+void vp9_tm_predictor_4x4_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int i;
+    uint16x8_t q1u16, q3u16;
+    int16x8_t q1s16;
+    uint8x8_t d0u8 = vdup_n_u8(0);
+    uint32x2_t d2u32 = vdup_n_u32(0);
+
+    d0u8 = vdup_n_u8(above[-1]);
+    d2u32 = vld1_lane_u32((const uint32_t *)above, d2u32, 0);
+    q3u16 = vsubl_u8(vreinterpret_u8_u32(d2u32), d0u8);
+    for (i = 0; i < 4; i++, dst += y_stride) {
+        q1u16 = vdupq_n_u16((uint16_t)left[i]);
+        q1s16 = vaddq_s16(vreinterpretq_s16_u16(q1u16),
+                          vreinterpretq_s16_u16(q3u16));
+        d0u8 = vqmovun_s16(q1s16);
+        vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d0u8), 0);
+    }
+    return;
+}
+
+void vp9_tm_predictor_8x8_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int j;
+    uint16x8_t q0u16, q3u16, q10u16;
+    int16x8_t q0s16;
+    uint16x4_t d20u16;
+    uint8x8_t d0u8, d2u8, d30u8;
+
+    d0u8 = vdup_n_u8(above[-1]);
+    d30u8 = vld1_u8(left);
+    d2u8 = vld1_u8(above);
+    q10u16 = vmovl_u8(d30u8);
+    q3u16 = vsubl_u8(d2u8, d0u8);
+    d20u16 = vget_low_u16(q10u16);
+    for (j = 0; j < 2; j++, d20u16 = vget_high_u16(q10u16)) {
+        q0u16 = vdupq_lane_u16(d20u16, 0);
+        q0s16 = vaddq_s16(vreinterpretq_s16_u16(q3u16),
+                          vreinterpretq_s16_u16(q0u16));
+        d0u8 = vqmovun_s16(q0s16);
+        vst1_u64((uint64_t *)dst, vreinterpret_u64_u8(d0u8));
+        dst += y_stride;
+        q0u16 = vdupq_lane_u16(d20u16, 1);
+        q0s16 = vaddq_s16(vreinterpretq_s16_u16(q3u16),
+                          vreinterpretq_s16_u16(q0u16));
+        d0u8 = vqmovun_s16(q0s16);
+        vst1_u64((uint64_t *)dst, vreinterpret_u64_u8(d0u8));
+        dst += y_stride;
+        q0u16 = vdupq_lane_u16(d20u16, 2);
+        q0s16 = vaddq_s16(vreinterpretq_s16_u16(q3u16),
+                          vreinterpretq_s16_u16(q0u16));
+        d0u8 = vqmovun_s16(q0s16);
+        vst1_u64((uint64_t *)dst, vreinterpret_u64_u8(d0u8));
+        dst += y_stride;
+        q0u16 = vdupq_lane_u16(d20u16, 3);
+        q0s16 = vaddq_s16(vreinterpretq_s16_u16(q3u16),
+                          vreinterpretq_s16_u16(q0u16));
+        d0u8 = vqmovun_s16(q0s16);
+        vst1_u64((uint64_t *)dst, vreinterpret_u64_u8(d0u8));
+        dst += y_stride;
+    }
+    return;
+}
+
+void vp9_tm_predictor_16x16_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int j, k;
+    uint16x8_t q0u16, q2u16, q3u16, q8u16, q10u16;
+    uint8x16_t q0u8, q1u8;
+    int16x8_t q0s16, q1s16, q8s16, q11s16;
+    uint16x4_t d20u16;
+    uint8x8_t d2u8, d3u8, d18u8, d22u8, d23u8;
+
+    q0u8 = vdupq_n_u8(above[-1]);
+    q1u8 = vld1q_u8(above);
+    q2u16 = vsubl_u8(vget_low_u8(q1u8), vget_low_u8(q0u8));
+    q3u16 = vsubl_u8(vget_high_u8(q1u8), vget_high_u8(q0u8));
+    for (k = 0; k < 2; k++, left += 8) {
+        d18u8 = vld1_u8(left);
+        q10u16 = vmovl_u8(d18u8);
+        d20u16 = vget_low_u16(q10u16);
+        for (j = 0; j < 2; j++, d20u16 = vget_high_u16(q10u16)) {
+            q0u16 = vdupq_lane_u16(d20u16, 0);
+            q8u16 = vdupq_lane_u16(d20u16, 1);
+            q1s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                              vreinterpretq_s16_u16(q2u16));
+            q0s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                              vreinterpretq_s16_u16(q3u16));
+            q11s16 = vaddq_s16(vreinterpretq_s16_u16(q8u16),
+                              vreinterpretq_s16_u16(q2u16));
+            q8s16 = vaddq_s16(vreinterpretq_s16_u16(q8u16),
+                              vreinterpretq_s16_u16(q3u16));
+            d2u8 = vqmovun_s16(q1s16);
+            d3u8 = vqmovun_s16(q0s16);
+            d22u8 = vqmovun_s16(q11s16);
+            d23u8 = vqmovun_s16(q8s16);
+            vst1_u64((uint64_t *)dst, vreinterpret_u64_u8(d2u8));
+            vst1_u64((uint64_t *)(dst + 8), vreinterpret_u64_u8(d3u8));
+            dst += y_stride;
+            vst1_u64((uint64_t *)dst, vreinterpret_u64_u8(d22u8));
+            vst1_u64((uint64_t *)(dst + 8), vreinterpret_u64_u8(d23u8));
+            dst += y_stride;
+
+            q0u16 = vdupq_lane_u16(d20u16, 2);
+            q8u16 = vdupq_lane_u16(d20u16, 3);
+            q1s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                              vreinterpretq_s16_u16(q2u16));
+            q0s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                              vreinterpretq_s16_u16(q3u16));
+            q11s16 = vaddq_s16(vreinterpretq_s16_u16(q8u16),
+                              vreinterpretq_s16_u16(q2u16));
+            q8s16 = vaddq_s16(vreinterpretq_s16_u16(q8u16),
+                              vreinterpretq_s16_u16(q3u16));
+            d2u8 = vqmovun_s16(q1s16);
+            d3u8 = vqmovun_s16(q0s16);
+            d22u8 = vqmovun_s16(q11s16);
+            d23u8 = vqmovun_s16(q8s16);
+            vst1_u64((uint64_t *)dst, vreinterpret_u64_u8(d2u8));
+            vst1_u64((uint64_t *)(dst + 8), vreinterpret_u64_u8(d3u8));
+            dst += y_stride;
+            vst1_u64((uint64_t *)dst, vreinterpret_u64_u8(d22u8));
+            vst1_u64((uint64_t *)(dst + 8), vreinterpret_u64_u8(d23u8));
+            dst += y_stride;
+        }
+    }
+    return;
+}
+
+void vp9_tm_predictor_32x32_neon(
+        uint8_t *dst,
+        ptrdiff_t y_stride,
+        const uint8_t *above,
+        const uint8_t *left) {
+    int j, k;
+    uint16x8_t q0u16, q3u16, q8u16, q9u16, q10u16, q11u16;
+    uint8x16_t q0u8, q1u8, q2u8;
+    int16x8_t q12s16, q13s16, q14s16, q15s16;
+    uint16x4_t d6u16;
+    uint8x8_t d0u8, d1u8, d2u8, d3u8, d26u8;
+
+    q0u8 = vdupq_n_u8(above[-1]);
+    q1u8 = vld1q_u8(above);
+    q2u8 = vld1q_u8(above + 16);
+    q8u16 = vsubl_u8(vget_low_u8(q1u8), vget_low_u8(q0u8));
+    q9u16 = vsubl_u8(vget_high_u8(q1u8), vget_high_u8(q0u8));
+    q10u16 = vsubl_u8(vget_low_u8(q2u8), vget_low_u8(q0u8));
+    q11u16 = vsubl_u8(vget_high_u8(q2u8), vget_high_u8(q0u8));
+    for (k = 0; k < 4; k++, left += 8) {
+        d26u8 = vld1_u8(left);
+        q3u16 = vmovl_u8(d26u8);
+        d6u16 = vget_low_u16(q3u16);
+        for (j = 0; j < 2; j++, d6u16 = vget_high_u16(q3u16)) {
+            q0u16 = vdupq_lane_u16(d6u16, 0);
+            q12s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q8u16));
+            q13s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q9u16));
+            q14s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q10u16));
+            q15s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q11u16));
+            d0u8 = vqmovun_s16(q12s16);
+            d1u8 = vqmovun_s16(q13s16);
+            d2u8 = vqmovun_s16(q14s16);
+            d3u8 = vqmovun_s16(q15s16);
+            q0u8 = vcombine_u8(d0u8, d1u8);
+            q1u8 = vcombine_u8(d2u8, d3u8);
+            vst1q_u64((uint64_t *)dst, vreinterpretq_u64_u8(q0u8));
+            vst1q_u64((uint64_t *)(dst + 16), vreinterpretq_u64_u8(q1u8));
+            dst += y_stride;
+
+            q0u16 = vdupq_lane_u16(d6u16, 1);
+            q12s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q8u16));
+            q13s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q9u16));
+            q14s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q10u16));
+            q15s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q11u16));
+            d0u8 = vqmovun_s16(q12s16);
+            d1u8 = vqmovun_s16(q13s16);
+            d2u8 = vqmovun_s16(q14s16);
+            d3u8 = vqmovun_s16(q15s16);
+            q0u8 = vcombine_u8(d0u8, d1u8);
+            q1u8 = vcombine_u8(d2u8, d3u8);
+            vst1q_u64((uint64_t *)dst, vreinterpretq_u64_u8(q0u8));
+            vst1q_u64((uint64_t *)(dst + 16), vreinterpretq_u64_u8(q1u8));
+            dst += y_stride;
+
+            q0u16 = vdupq_lane_u16(d6u16, 2);
+            q12s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q8u16));
+            q13s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q9u16));
+            q14s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q10u16));
+            q15s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q11u16));
+            d0u8 = vqmovun_s16(q12s16);
+            d1u8 = vqmovun_s16(q13s16);
+            d2u8 = vqmovun_s16(q14s16);
+            d3u8 = vqmovun_s16(q15s16);
+            q0u8 = vcombine_u8(d0u8, d1u8);
+            q1u8 = vcombine_u8(d2u8, d3u8);
+            vst1q_u64((uint64_t *)dst, vreinterpretq_u64_u8(q0u8));
+            vst1q_u64((uint64_t *)(dst + 16), vreinterpretq_u64_u8(q1u8));
+            dst += y_stride;
+
+            q0u16 = vdupq_lane_u16(d6u16, 3);
+            q12s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q8u16));
+            q13s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q9u16));
+            q14s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q10u16));
+            q15s16 = vaddq_s16(vreinterpretq_s16_u16(q0u16),
+                               vreinterpretq_s16_u16(q11u16));
+            d0u8 = vqmovun_s16(q12s16);
+            d1u8 = vqmovun_s16(q13s16);
+            d2u8 = vqmovun_s16(q14s16);
+            d3u8 = vqmovun_s16(q15s16);
+            q0u8 = vcombine_u8(d0u8, d1u8);
+            q1u8 = vcombine_u8(d2u8, d3u8);
+            vst1q_u64((uint64_t *)dst, vreinterpretq_u64_u8(q0u8));
+            vst1q_u64((uint64_t *)(dst + 16), vreinterpretq_u64_u8(q1u8));
+            dst += y_stride;
+        }
+    }
+    return;
+}
diff --git a/vp9/common/arm/neon/vp9_reconintra_neon.asm b/vp9/common/arm/neon/vp9_reconintra_neon_asm.asm
similarity index 100%
rename from vp9/common/arm/neon/vp9_reconintra_neon.asm
rename to vp9/common/arm/neon/vp9_reconintra_neon_asm.asm
diff --git a/vp9/common/vp9_alloccommon.c b/vp9/common/vp9_alloccommon.c
index cad5750..2f75af5 100644
--- a/vp9/common/vp9_alloccommon.c
+++ b/vp9/common/vp9_alloccommon.c
@@ -112,7 +112,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                cm->use_highbitdepth,
 #endif
-                               VP9_ENC_BORDER_IN_PIXELS) < 0)
+                               VP9_ENC_BORDER_IN_PIXELS,
+                               cm->byte_alignment) < 0)
       goto fail;
     if (cm->frame_bufs[i].mvs == NULL) {
       cm->frame_bufs[i].mvs =
@@ -133,7 +134,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                              cm->use_highbitdepth,
 #endif
-                             VP9_ENC_BORDER_IN_PIXELS) < 0)
+                             VP9_ENC_BORDER_IN_PIXELS,
+                             cm->byte_alignment) < 0)
     goto fail;
 #endif
 
diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h
index c166590..bba24e0 100644
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -208,6 +208,7 @@
   int frame_parallel_decoding_mode;
 
   int log2_tile_cols, log2_tile_rows;
+  int byte_alignment;
 
   // Private data associated with the frame buffer callbacks.
   void *cb_priv;
diff --git a/vp9/common/vp9_postproc.c b/vp9/common/vp9_postproc.c
index 6b31675..90b9898 100644
--- a/vp9/common/vp9_postproc.c
+++ b/vp9/common/vp9_postproc.c
@@ -677,7 +677,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                  cm->use_highbitdepth,
 #endif  // CONFIG_VP9_HIGHBITDEPTH
-                                 VP9_ENC_BORDER_IN_PIXELS) < 0) {
+                                 VP9_ENC_BORDER_IN_PIXELS,
+                                 cm->byte_alignment) < 0) {
         vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
                            "Failed to allocate MFQE framebuffer");
       }
@@ -694,7 +695,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                cm->use_highbitdepth,
 #endif
-                               VP9_DEC_BORDER_IN_PIXELS, NULL, NULL, NULL) < 0)
+                               VP9_DEC_BORDER_IN_PIXELS, cm->byte_alignment,
+                               NULL, NULL, NULL) < 0)
     vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
                        "Failed to allocate post-processing buffer");
 
diff --git a/vp9/common/vp9_rtcd_defs.pl b/vp9/common/vp9_rtcd_defs.pl
index 11c0d81..ef68d74 100644
--- a/vp9/common/vp9_rtcd_defs.pl
+++ b/vp9/common/vp9_rtcd_defs.pl
@@ -66,8 +66,7 @@
 specialize qw/vp9_d63_predictor_4x4/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_h_predictor_4x4/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_h_predictor_4x4 neon_asm dspr2/, "$ssse3_x86inc";
-$vp9_h_predictor_4x4_neon_asm=vp9_h_predictor_4x4_neon;
+specialize qw/vp9_h_predictor_4x4 neon dspr2/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_d117_predictor_4x4/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
 specialize qw/vp9_d117_predictor_4x4/;
@@ -79,12 +78,10 @@
 specialize qw/vp9_d153_predictor_4x4/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_v_predictor_4x4/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_v_predictor_4x4 neon_asm/, "$sse_x86inc";
-$vp9_v_predictor_4x4_neon_asm=vp9_v_predictor_4x4_neon;
+specialize qw/vp9_v_predictor_4x4 neon/, "$sse_x86inc";
 
 add_proto qw/void vp9_tm_predictor_4x4/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_tm_predictor_4x4 neon_asm dspr2/, "$sse_x86inc";
-$vp9_tm_predictor_4x4_neon_asm=vp9_tm_predictor_4x4_neon;
+specialize qw/vp9_tm_predictor_4x4 neon dspr2/, "$sse_x86inc";
 
 add_proto qw/void vp9_dc_predictor_4x4/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
 specialize qw/vp9_dc_predictor_4x4 dspr2/, "$sse_x86inc";
@@ -108,8 +105,7 @@
 specialize qw/vp9_d63_predictor_8x8/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_h_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_h_predictor_8x8 neon_asm dspr2/, "$ssse3_x86inc";
-$vp9_h_predictor_8x8_neon_asm=vp9_h_predictor_8x8_neon;
+specialize qw/vp9_h_predictor_8x8 neon dspr2/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_d117_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
 specialize qw/vp9_d117_predictor_8x8/;
@@ -121,12 +117,10 @@
 specialize qw/vp9_d153_predictor_8x8/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_v_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_v_predictor_8x8 neon_asm/, "$sse_x86inc";
-$vp9_v_predictor_8x8_neon_asm=vp9_v_predictor_8x8_neon;
+specialize qw/vp9_v_predictor_8x8 neon/, "$sse_x86inc";
 
 add_proto qw/void vp9_tm_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_tm_predictor_8x8 neon_asm dspr2/, "$sse2_x86inc";
-$vp9_tm_predictor_8x8_neon_asm=vp9_tm_predictor_8x8_neon;
+specialize qw/vp9_tm_predictor_8x8 neon dspr2/, "$sse2_x86inc";
 
 add_proto qw/void vp9_dc_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
 specialize qw/vp9_dc_predictor_8x8 dspr2/, "$sse_x86inc";
@@ -150,8 +144,7 @@
 specialize qw/vp9_d63_predictor_16x16/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_h_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_h_predictor_16x16 neon_asm dspr2/, "$ssse3_x86inc";
-$vp9_h_predictor_16x16_neon_asm=vp9_h_predictor_16x16_neon;
+specialize qw/vp9_h_predictor_16x16 neon dspr2/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_d117_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
 specialize qw/vp9_d117_predictor_16x16/;
@@ -163,12 +156,10 @@
 specialize qw/vp9_d153_predictor_16x16/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_v_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_v_predictor_16x16 neon_asm/, "$sse2_x86inc";
-$vp9_v_predictor_16x16_neon_asm=vp9_v_predictor_16x16_neon;
+specialize qw/vp9_v_predictor_16x16 neon/, "$sse2_x86inc";
 
 add_proto qw/void vp9_tm_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_tm_predictor_16x16 neon_asm/, "$sse2_x86inc";
-$vp9_tm_predictor_16x16_neon_asm=vp9_tm_predictor_16x16_neon;
+specialize qw/vp9_tm_predictor_16x16 neon/, "$sse2_x86inc";
 
 add_proto qw/void vp9_dc_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
 specialize qw/vp9_dc_predictor_16x16 dspr2/, "$sse2_x86inc";
@@ -192,8 +183,7 @@
 specialize qw/vp9_d63_predictor_32x32/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_h_predictor_32x32/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_h_predictor_32x32 neon_asm/, "$ssse3_x86inc";
-$vp9_h_predictor_32x32_neon_asm=vp9_h_predictor_32x32_neon;
+specialize qw/vp9_h_predictor_32x32 neon/, "$ssse3_x86inc";
 
 add_proto qw/void vp9_d117_predictor_32x32/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
 specialize qw/vp9_d117_predictor_32x32/;
@@ -205,12 +195,10 @@
 specialize qw/vp9_d153_predictor_32x32/;
 
 add_proto qw/void vp9_v_predictor_32x32/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_v_predictor_32x32 neon_asm/, "$sse2_x86inc";
-$vp9_v_predictor_32x32_neon_asm=vp9_v_predictor_32x32_neon;
+specialize qw/vp9_v_predictor_32x32 neon/, "$sse2_x86inc";
 
 add_proto qw/void vp9_tm_predictor_32x32/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
-specialize qw/vp9_tm_predictor_32x32 neon_asm/, "$sse2_x86_64";
-$vp9_tm_predictor_32x32_neon_asm=vp9_tm_predictor_32x32_neon;
+specialize qw/vp9_tm_predictor_32x32 neon/, "$sse2_x86_64";
 
 add_proto qw/void vp9_dc_predictor_32x32/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left";
 specialize qw/vp9_dc_predictor_32x32/, "$sse2_x86inc";
diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c
index 5bf44d7..9677173 100644
--- a/vp9/decoder/vp9_decodeframe.c
+++ b/vp9/decoder/vp9_decodeframe.c
@@ -719,6 +719,7 @@
           cm->use_highbitdepth,
 #endif
           VP9_DEC_BORDER_IN_PIXELS,
+          cm->byte_alignment,
           &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb,
           cm->cb_priv)) {
     vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
@@ -793,6 +794,7 @@
           cm->use_highbitdepth,
 #endif
           VP9_DEC_BORDER_IN_PIXELS,
+          cm->byte_alignment,
           &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb,
           cm->cb_priv)) {
     vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
diff --git a/vp9/encoder/vp9_denoiser.c b/vp9/encoder/vp9_denoiser.c
index 4deeed2..56ec6b3 100644
--- a/vp9/encoder/vp9_denoiser.c
+++ b/vp9/encoder/vp9_denoiser.c
@@ -425,6 +425,7 @@
 #endif
                        int border) {
   int i, fail;
+  const int legacy_byte_alignment = 0;
   assert(denoiser != NULL);
 
   for (i = 0; i < MAX_REF_FRAMES; ++i) {
@@ -433,7 +434,7 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                   use_highbitdepth,
 #endif
-                                  border);
+                                  border, legacy_byte_alignment);
     if (fail) {
       vp9_denoiser_free(denoiser);
       return 1;
@@ -448,7 +449,7 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                 use_highbitdepth,
 #endif
-                                border);
+                                border, legacy_byte_alignment);
   if (fail) {
     vp9_denoiser_free(denoiser);
     return 1;
diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c
index aaa6b23..a7f34a2 100644
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -491,7 +491,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                cm->use_highbitdepth,
 #endif
-                               VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
+                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                               NULL, NULL, NULL))
     vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
                        "Failed to allocate altref buffer");
 }
@@ -511,7 +512,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                cm->use_highbitdepth,
 #endif
-                               VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
+                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                               NULL, NULL, NULL))
     vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
                        "Failed to allocate last frame buffer");
 
@@ -521,7 +523,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                cm->use_highbitdepth,
 #endif
-                               VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
+                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                               NULL, NULL, NULL))
     vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
                        "Failed to allocate scaled source buffer");
 
@@ -531,7 +534,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                cm->use_highbitdepth,
 #endif
-                               VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
+                               VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                               NULL, NULL, NULL))
     vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
                        "Failed to allocate scaled last source buffer");
 }
@@ -567,7 +571,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                  cm->use_highbitdepth,
 #endif
-                                 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
+                                 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                                 NULL, NULL, NULL))
       vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
                          "Failed to reallocate alt_ref_buffer");
   }
@@ -2473,7 +2478,8 @@
                                  cm->width, cm->height,
                                  cm->subsampling_x, cm->subsampling_y,
                                  cm->use_highbitdepth,
-                                 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL);
+                                 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                                 NULL, NULL, NULL);
         scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf,
                                (int)cm->bit_depth);
 #else
@@ -2482,7 +2488,8 @@
         vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf,
                                  cm->width, cm->height,
                                  cm->subsampling_x, cm->subsampling_y,
-                                 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL);
+                                 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                                 NULL, NULL, NULL);
         scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf);
 #endif  // CONFIG_VP9_HIGHBITDEPTH
         cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
@@ -2721,7 +2728,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                            cm->use_highbitdepth,
 #endif
-                           VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL);
+                           VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                           NULL, NULL, NULL);
 
   alloc_util_frame_buffers(cpi);
   init_motion_estimation(cpi);
diff --git a/vp9/encoder/vp9_lookahead.c b/vp9/encoder/vp9_lookahead.c
index 823e7a1..708072e 100644
--- a/vp9/encoder/vp9_lookahead.c
+++ b/vp9/encoder/vp9_lookahead.c
@@ -65,6 +65,7 @@
   // Allocate the lookahead structures
   ctx = calloc(1, sizeof(*ctx));
   if (ctx) {
+    const int legacy_byte_alignment = 0;
     unsigned int i;
     ctx->max_sz = depth;
     ctx->buf = calloc(depth, sizeof(*ctx->buf));
@@ -76,7 +77,8 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                  use_highbitdepth,
 #endif
-                                 VP9_ENC_BORDER_IN_PIXELS))
+                                 VP9_ENC_BORDER_IN_PIXELS,
+                                 legacy_byte_alignment))
         goto bail;
   }
   return ctx;
diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c
index db5650c..e0892fe 100644
--- a/vp9/encoder/vp9_pickmode.c
+++ b/vp9/encoder/vp9_pickmode.c
@@ -872,7 +872,6 @@
       const PREDICTION_MODE this_mode = intra_mode_list[i];
       if (!((1 << this_mode) & cpi->sf.intra_y_mode_mask[intra_tx_size]))
         continue;
-      skip_txfm = x->skip_txfm[0];
       args.mode = this_mode;
       args.rate = 0;
       args.dist = 0;
@@ -893,11 +892,14 @@
         mbmi->ref_frame[0] = INTRA_FRAME;
         mbmi->uv_mode = this_mode;
         mbmi->mv[0].as_int = INVALID_MV;
-      } else {
-        x->skip_txfm[0] = best_mode_skip_txfm;
-        mbmi->tx_size = best_tx_size;
       }
     }
+
+    // Reset mb_mode_info to the best inter mode.
+    if (mbmi->ref_frame[0] != INTRA_FRAME) {
+      x->skip_txfm[0] = best_mode_skip_txfm;
+      mbmi->tx_size = best_tx_size;
+    }
   }
 
   pd->dst = orig_dst;
diff --git a/vp9/encoder/vp9_svc_layercontext.c b/vp9/encoder/vp9_svc_layercontext.c
index 184322f..31e93be 100644
--- a/vp9/encoder/vp9_svc_layercontext.c
+++ b/vp9/encoder/vp9_svc_layercontext.c
@@ -39,7 +39,9 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                  cpi->common.use_highbitdepth,
 #endif
-                                 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
+                                 VP9_ENC_BORDER_IN_PIXELS,
+                                 cpi->common.byte_alignment,
+                                 NULL, NULL, NULL))
         vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
                            "Failed to allocate empty frame for multiple frame "
                            "contexts");
diff --git a/vp9/encoder/vp9_temporal_filter.c b/vp9/encoder/vp9_temporal_filter.c
index a4051f0..424cc08 100644
--- a/vp9/encoder/vp9_temporal_filter.c
+++ b/vp9/encoder/vp9_temporal_filter.c
@@ -710,8 +710,9 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                                        cm->use_highbitdepth,
 #endif
-                                       VP9_ENC_BORDER_IN_PIXELS, NULL, NULL,
-                                       NULL)) {
+                                       VP9_ENC_BORDER_IN_PIXELS,
+                                       cm->byte_alignment,
+                                       NULL, NULL, NULL)) {
             vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
                                "Failed to reallocate alt_ref_buffer");
           }
diff --git a/vp9/vp9_common.mk b/vp9/vp9_common.mk
index c7a2bfe..ab18a76 100644
--- a/vp9/vp9_common.mk
+++ b/vp9/vp9_common.mk
@@ -136,7 +136,6 @@
 VP9_COMMON_SRCS-$(HAVE_NEON_ASM) += common/arm/neon/vp9_loopfilter_16_neon_asm$(ASM)
 VP9_COMMON_SRCS-$(HAVE_NEON_ASM) += common/arm/neon/vp9_mb_lpf_neon$(ASM)
 VP9_COMMON_SRCS-$(HAVE_NEON_ASM) += common/arm/neon/vp9_save_reg_neon$(ASM)
-VP9_COMMON_SRCS-$(HAVE_NEON_ASM) += common/arm/neon/vp9_reconintra_neon$(ASM)
 
 VP9_COMMON_SRCS-$(HAVE_NEON) += common/arm/neon/vp9_iht4x4_add_neon.c
 VP9_COMMON_SRCS-$(HAVE_NEON) += common/arm/neon/vp9_iht8x8_add_neon.c
@@ -160,6 +159,7 @@
 VP9_COMMON_SRCS-yes += common/arm/neon/vp9_idct8x8_add_neon_asm$(ASM)
 VP9_COMMON_SRCS-yes += common/arm/neon/vp9_loopfilter_neon_asm$(ASM)
 VP9_COMMON_SRCS-yes += common/arm/neon/vp9_loopfilter_16_neon.c
+VP9_COMMON_SRCS-yes += common/arm/neon/vp9_reconintra_neon_asm$(ASM)
 else
 ifeq ($(HAVE_NEON), yes)
 VP9_COMMON_SRCS-yes += common/arm/neon/vp9_avg_neon.c
@@ -178,6 +178,7 @@
 VP9_COMMON_SRCS-yes += common/arm/neon/vp9_idct8x8_add_neon.c
 VP9_COMMON_SRCS-yes += common/arm/neon/vp9_loopfilter_neon.c
 VP9_COMMON_SRCS-yes += common/arm/neon/vp9_loopfilter_16_neon.c
+VP9_COMMON_SRCS-yes += common/arm/neon/vp9_reconintra_neon.c
 endif  # HAVE_NEON
 endif  # HAVE_NEON_ASM
 
diff --git a/vp9/vp9_dx_iface.c b/vp9/vp9_dx_iface.c
index 8095140..43bf35f 100644
--- a/vp9/vp9_dx_iface.c
+++ b/vp9/vp9_dx_iface.c
@@ -44,6 +44,7 @@
   int                     flushed;
   int                     invert_tile_order;
   int                     frame_parallel_decode;  // frame-based threading.
+  int                     byte_alignment;
 
   // External frame buffer info to save for VP9 common.
   void *ext_priv;  // Private data associated with the external frame buffers.
@@ -219,6 +220,7 @@
   VP9_COMMON *const cm = &ctx->pbi->common;
 
   cm->new_fb_idx = -1;
+  cm->byte_alignment = ctx->byte_alignment;
 
   if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
     cm->get_fb_cb = ctx->get_ext_fb_cb;
@@ -617,6 +619,27 @@
   return VPX_CODEC_OK;
 }
 
+static vpx_codec_err_t ctrl_set_byte_alignment(vpx_codec_alg_priv_t *ctx,
+                                               va_list args) {
+  const int legacy_byte_alignment = 0;
+  const int min_byte_alignment = 32;
+  const int max_byte_alignment = 1024;
+  const int byte_alignment = va_arg(args, int);
+
+  if (byte_alignment != legacy_byte_alignment &&
+      (byte_alignment < min_byte_alignment ||
+       byte_alignment > max_byte_alignment ||
+       (byte_alignment & (byte_alignment - 1)) != 0))
+    return VPX_CODEC_INVALID_PARAM;
+
+  ctx->byte_alignment = byte_alignment;
+  if (ctx->pbi != NULL) {
+    VP9_COMMON *const cm = &ctx->pbi->common;
+    cm->byte_alignment = byte_alignment;
+  }
+  return VPX_CODEC_OK;
+}
+
 static vpx_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
   {VP8_COPY_REFERENCE,            ctrl_copy_reference},
 
@@ -629,6 +652,7 @@
   {VP8_SET_DBG_DISPLAY_MV,        ctrl_set_dbg_options},
   {VP9_INVERT_TILE_DECODE_ORDER,  ctrl_set_invert_tile_order},
   {VPXD_SET_DECRYPTOR,            ctrl_set_decryptor},
+  {VP9_SET_BYTE_ALIGNMENT,        ctrl_set_byte_alignment},
 
   // Getters
   {VP8D_GET_LAST_REF_UPDATES,     ctrl_get_last_ref_updates},
diff --git a/vpx/exports_enc b/vpx/exports_enc
index 8885920..e4707ba 100644
--- a/vpx/exports_enc
+++ b/vpx/exports_enc
@@ -1,5 +1,6 @@
 text vpx_codec_enc_config_default
 text vpx_codec_enc_config_set
+text vpx_codec_enc_init_multi_ver
 text vpx_codec_enc_init_ver
 text vpx_codec_encode
 text vpx_codec_get_cx_data
diff --git a/vpx/vp8dx.h b/vpx/vp8dx.h
index 379b306..5cc25cd 100644
--- a/vpx/vp8dx.h
+++ b/vpx/vp8dx.h
@@ -78,6 +78,13 @@
   /** control function to get the bit depth of the stream. */
   VP9D_GET_BIT_DEPTH,
 
+  /** control function to set the byte alignment of the planes in the reference
+   * buffers. Valid values are power of 2, from 32 to 1024. A value of 0 sets
+   * legacy alignment. I.e. Y plane is aligned to 32 bytes, U plane directly
+   * follows Y plane, and V plane directly follows U plane. Default value is 0.
+   */
+  VP9_SET_BYTE_ALIGNMENT,
+
   /** For testing. */
   VP9_INVERT_TILE_DECODE_ORDER,
 
diff --git a/vpx_scale/generic/yv12config.c b/vpx_scale/generic/yv12config.c
index 00a8c16..ff49ffb 100644
--- a/vpx_scale/generic/yv12config.c
+++ b/vpx_scale/generic/yv12config.c
@@ -143,22 +143,25 @@
                              int use_highbitdepth,
 #endif
                              int border,
+                             int byte_alignment,
                              vpx_codec_frame_buffer_t *fb,
                              vpx_get_frame_buffer_cb_fn_t cb,
                              void *cb_priv) {
   if (ybf) {
+    const int vp9_byte_align = (byte_alignment == 0) ? 1 : byte_alignment;
     const int aligned_width = (width + 7) & ~7;
     const int aligned_height = (height + 7) & ~7;
     const int y_stride = ((aligned_width + 2 * border) + 31) & ~31;
     const uint64_t yplane_size = (aligned_height + 2 * border) *
-                                 (uint64_t)y_stride;
+                                 (uint64_t)y_stride + byte_alignment;
     const int uv_width = aligned_width >> ss_x;
     const int uv_height = aligned_height >> ss_y;
     const int uv_stride = y_stride >> ss_x;
     const int uv_border_w = border >> ss_x;
     const int uv_border_h = border >> ss_y;
     const uint64_t uvplane_size = (uv_height + 2 * uv_border_h) *
-                                  (uint64_t)uv_stride;
+                                  (uint64_t)uv_stride + byte_alignment;
+
 #if CONFIG_ALPHA
     const int alpha_width = aligned_width;
     const int alpha_height = aligned_height;
@@ -166,7 +169,7 @@
     const int alpha_border_w = border;
     const int alpha_border_h = border;
     const uint64_t alpha_plane_size = (alpha_height + 2 * alpha_border_h) *
-                                      (uint64_t)alpha_stride;
+                                      (uint64_t)alpha_stride + byte_alignment;
 #if CONFIG_VP9_HIGHBITDEPTH
     const uint64_t frame_size = (1 + use_highbitdepth) *
         (yplane_size + 2 * uvplane_size + alpha_plane_size);
@@ -182,6 +185,9 @@
     const uint64_t frame_size = yplane_size + 2 * uvplane_size;
 #endif  // CONFIG_VP9_HIGHBITDEPTH
 #endif  // CONFIG_ALPHA
+
+    uint8_t *buf = NULL;
+
     if (cb != NULL) {
       const int align_addr_extra_size = 31;
       const uint64_t external_frame_size = frame_size + align_addr_extra_size;
@@ -244,38 +250,33 @@
     ybf->subsampling_x = ss_x;
     ybf->subsampling_y = ss_y;
 
+    buf = ybf->buffer_alloc;
 #if CONFIG_VP9_HIGHBITDEPTH
     if (use_highbitdepth) {
       // Store uint16 addresses when using 16bit framebuffers
-      uint8_t *p = CONVERT_TO_BYTEPTR(ybf->buffer_alloc);
-      ybf->y_buffer = p + (border * y_stride) + border;
-      ybf->u_buffer = p + yplane_size +
-          (uv_border_h * uv_stride) + uv_border_w;
-      ybf->v_buffer = p + yplane_size + uvplane_size +
-          (uv_border_h * uv_stride) + uv_border_w;
+      buf = CONVERT_TO_BYTEPTR(ybf->buffer_alloc);
       ybf->flags = YV12_FLAG_HIGHBITDEPTH;
     } else {
-      ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border;
-      ybf->u_buffer = ybf->buffer_alloc + yplane_size +
-          (uv_border_h * uv_stride) + uv_border_w;
-      ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size +
-          (uv_border_h * uv_stride) + uv_border_w;
       ybf->flags = 0;
     }
-#else
-    ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border;
-    ybf->u_buffer = ybf->buffer_alloc + yplane_size +
-                    (uv_border_h * uv_stride) + uv_border_w;
-    ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size +
-                    (uv_border_h * uv_stride) + uv_border_w;
 #endif  // CONFIG_VP9_HIGHBITDEPTH
 
+    ybf->y_buffer = (uint8_t *)yv12_align_addr(
+        buf + (border * y_stride) + border, vp9_byte_align);
+    ybf->u_buffer = (uint8_t *)yv12_align_addr(
+        buf + yplane_size + (uv_border_h * uv_stride) + uv_border_w,
+        vp9_byte_align);
+    ybf->v_buffer = (uint8_t *)yv12_align_addr(
+        buf + yplane_size + uvplane_size + (uv_border_h * uv_stride) +
+        uv_border_w, vp9_byte_align);
+
 #if CONFIG_ALPHA
     ybf->alpha_width = alpha_width;
     ybf->alpha_height = alpha_height;
     ybf->alpha_stride = alpha_stride;
-    ybf->alpha_buffer = ybf->buffer_alloc + yplane_size + 2 * uvplane_size +
-                        (alpha_border_h * alpha_stride) + alpha_border_w;
+    ybf->alpha_buffer = (uint8_t *)yv12_align_addr(
+        buf + yplane_size + 2 * uvplane_size +
+        (alpha_border_h * alpha_stride) + alpha_border_w, vp9_byte_align);
 #endif
     ybf->corrupted = 0; /* assume not corrupted by errors */
     return 0;
@@ -289,14 +290,15 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                            int use_highbitdepth,
 #endif
-                           int border) {
+                           int border,
+                           int byte_alignment) {
   if (ybf) {
     vp9_free_frame_buffer(ybf);
     return vp9_realloc_frame_buffer(ybf, width, height, ss_x, ss_y,
 #if CONFIG_VP9_HIGHBITDEPTH
                                     use_highbitdepth,
 #endif
-                                    border, NULL, NULL, NULL);
+                                    border, byte_alignment, NULL, NULL, NULL);
   }
   return -2;
 }
diff --git a/vpx_scale/yv12config.h b/vpx_scale/yv12config.h
index b9f13fd..f04dee1 100644
--- a/vpx_scale/yv12config.h
+++ b/vpx_scale/yv12config.h
@@ -73,9 +73,10 @@
 #if CONFIG_VP9_HIGHBITDEPTH
                            int use_highbitdepth,
 #endif
-                           int border);
+                           int border, int byte_alignment);
 
-// Updates the yv12 buffer config with the frame buffer. If cb is not
+// Updates the yv12 buffer config with the frame buffer. |byte_alignment| must
+// be a power of 2, from 32 to 1024. 0 sets legacy alignment. If cb is not
 // NULL, then libvpx is using the frame buffer callbacks to handle memory.
 // If cb is not NULL, libvpx will call cb with minimum size in bytes needed
 // to decode the current frame. If cb is NULL, libvpx will allocate memory
@@ -87,6 +88,7 @@
                              int use_highbitdepth,
 #endif
                              int border,
+                             int byte_alignment,
                              vpx_codec_frame_buffer_t *fb,
                              vpx_get_frame_buffer_cb_fn_t cb,
                              void *cb_priv);
diff --git a/vpxenc.c b/vpxenc.c
index cbf142a..ebdbb07 100644
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -1197,6 +1197,7 @@
 static void validate_stream_config(const struct stream_state *stream,
                                    const struct VpxEncoderConfig *global) {
   const struct stream_state *streami;
+  (void)global;
 
   if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
     fatal("Stream %d: Specify stream dimensions with --width (-w) "