11b362b15af34006e6a11974088a46d42b903418eJohann/*
21b362b15af34006e6a11974088a46d42b903418eJohann *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
31b362b15af34006e6a11974088a46d42b903418eJohann *
41b362b15af34006e6a11974088a46d42b903418eJohann *  Use of this source code is governed by a BSD-style license
51b362b15af34006e6a11974088a46d42b903418eJohann *  that can be found in the LICENSE file in the root of the source
61b362b15af34006e6a11974088a46d42b903418eJohann *  tree. An additional intellectual property rights grant can be found
71b362b15af34006e6a11974088a46d42b903418eJohann *  in the file PATENTS.  All contributing project authors may
81b362b15af34006e6a11974088a46d42b903418eJohann *  be found in the AUTHORS file in the root of the source tree.
91b362b15af34006e6a11974088a46d42b903418eJohann */
101b362b15af34006e6a11974088a46d42b903418eJohann
111b362b15af34006e6a11974088a46d42b903418eJohann#include <limits.h>
12da49e34c1fb5e99681f4ad99c21d9cfd83eddb96Vignesh Venkatasubramanian#include <string.h>
13da49e34c1fb5e99681f4ad99c21d9cfd83eddb96Vignesh Venkatasubramanian
141b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx_config.h"
15ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "vp8_rtcd.h"
161b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx/vpx_integer.h"
171b362b15af34006e6a11974088a46d42b903418eJohann#include "blockd.h"
181b362b15af34006e6a11974088a46d42b903418eJohann#include "reconinter.h"
191b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_RUNTIME_CPU_DETECT
201b362b15af34006e6a11974088a46d42b903418eJohann#include "onyxc_int.h"
211b362b15af34006e6a11974088a46d42b903418eJohann#endif
221b362b15af34006e6a11974088a46d42b903418eJohann
237bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_copy_mem16x16_c(unsigned char *src, int src_stride, unsigned char *dst,
247bc9febe8749e98a3812a0dc4380ceae75c29450Johann                         int dst_stride) {
257bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int r;
261b362b15af34006e6a11974088a46d42b903418eJohann
277bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (r = 0; r < 16; ++r) {
287bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(dst, src, 16);
291b362b15af34006e6a11974088a46d42b903418eJohann
307bc9febe8749e98a3812a0dc4380ceae75c29450Johann    src += src_stride;
317bc9febe8749e98a3812a0dc4380ceae75c29450Johann    dst += dst_stride;
327bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
331b362b15af34006e6a11974088a46d42b903418eJohann}
341b362b15af34006e6a11974088a46d42b903418eJohann
357bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_copy_mem8x8_c(unsigned char *src, int src_stride, unsigned char *dst,
367bc9febe8749e98a3812a0dc4380ceae75c29450Johann                       int dst_stride) {
377bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int r;
38da49e34c1fb5e99681f4ad99c21d9cfd83eddb96Vignesh Venkatasubramanian
397bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (r = 0; r < 8; ++r) {
407bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(dst, src, 8);
411b362b15af34006e6a11974088a46d42b903418eJohann
427bc9febe8749e98a3812a0dc4380ceae75c29450Johann    src += src_stride;
437bc9febe8749e98a3812a0dc4380ceae75c29450Johann    dst += dst_stride;
447bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
451b362b15af34006e6a11974088a46d42b903418eJohann}
461b362b15af34006e6a11974088a46d42b903418eJohann
477bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_copy_mem8x4_c(unsigned char *src, int src_stride, unsigned char *dst,
487bc9febe8749e98a3812a0dc4380ceae75c29450Johann                       int dst_stride) {
497bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int r;
50da49e34c1fb5e99681f4ad99c21d9cfd83eddb96Vignesh Venkatasubramanian
517bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (r = 0; r < 4; ++r) {
527bc9febe8749e98a3812a0dc4380ceae75c29450Johann    memcpy(dst, src, 8);
531b362b15af34006e6a11974088a46d42b903418eJohann
547bc9febe8749e98a3812a0dc4380ceae75c29450Johann    src += src_stride;
557bc9febe8749e98a3812a0dc4380ceae75c29450Johann    dst += dst_stride;
567bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
571b362b15af34006e6a11974088a46d42b903418eJohann}
581b362b15af34006e6a11974088a46d42b903418eJohann
597bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_build_inter_predictors_b(BLOCKD *d, int pitch, unsigned char *base_pre,
607bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                  int pre_stride, vp8_subpix_fn_t sppf) {
617bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int r;
627bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *pred_ptr = d->predictor;
637bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *ptr;
647bc9febe8749e98a3812a0dc4380ceae75c29450Johann  ptr = base_pre + d->offset + (d->bmi.mv.as_mv.row >> 3) * pre_stride +
657bc9febe8749e98a3812a0dc4380ceae75c29450Johann        (d->bmi.mv.as_mv.col >> 3);
667bc9febe8749e98a3812a0dc4380ceae75c29450Johann
677bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (d->bmi.mv.as_mv.row & 7 || d->bmi.mv.as_mv.col & 7) {
687bc9febe8749e98a3812a0dc4380ceae75c29450Johann    sppf(ptr, pre_stride, d->bmi.mv.as_mv.col & 7, d->bmi.mv.as_mv.row & 7,
697bc9febe8749e98a3812a0dc4380ceae75c29450Johann         pred_ptr, pitch);
707bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
717bc9febe8749e98a3812a0dc4380ceae75c29450Johann    for (r = 0; r < 4; ++r) {
727bc9febe8749e98a3812a0dc4380ceae75c29450Johann      pred_ptr[0] = ptr[0];
737bc9febe8749e98a3812a0dc4380ceae75c29450Johann      pred_ptr[1] = ptr[1];
747bc9febe8749e98a3812a0dc4380ceae75c29450Johann      pred_ptr[2] = ptr[2];
757bc9febe8749e98a3812a0dc4380ceae75c29450Johann      pred_ptr[3] = ptr[3];
767bc9febe8749e98a3812a0dc4380ceae75c29450Johann      pred_ptr += pitch;
777bc9febe8749e98a3812a0dc4380ceae75c29450Johann      ptr += pre_stride;
781b362b15af34006e6a11974088a46d42b903418eJohann    }
797bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
801b362b15af34006e6a11974088a46d42b903418eJohann}
811b362b15af34006e6a11974088a46d42b903418eJohann
827bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic void build_inter_predictors4b(MACROBLOCKD *x, BLOCKD *d,
837bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                     unsigned char *dst, int dst_stride,
847bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                     unsigned char *base_pre, int pre_stride) {
857bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *ptr;
867bc9febe8749e98a3812a0dc4380ceae75c29450Johann  ptr = base_pre + d->offset + (d->bmi.mv.as_mv.row >> 3) * pre_stride +
877bc9febe8749e98a3812a0dc4380ceae75c29450Johann        (d->bmi.mv.as_mv.col >> 3);
887bc9febe8749e98a3812a0dc4380ceae75c29450Johann
897bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (d->bmi.mv.as_mv.row & 7 || d->bmi.mv.as_mv.col & 7) {
907bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->subpixel_predict8x8(ptr, pre_stride, d->bmi.mv.as_mv.col & 7,
917bc9febe8749e98a3812a0dc4380ceae75c29450Johann                           d->bmi.mv.as_mv.row & 7, dst, dst_stride);
927bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
937bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_copy_mem8x8(ptr, pre_stride, dst, dst_stride);
947bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
951b362b15af34006e6a11974088a46d42b903418eJohann}
961b362b15af34006e6a11974088a46d42b903418eJohann
977bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic void build_inter_predictors2b(MACROBLOCKD *x, BLOCKD *d,
987bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                     unsigned char *dst, int dst_stride,
997bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                     unsigned char *base_pre, int pre_stride) {
1007bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *ptr;
1017bc9febe8749e98a3812a0dc4380ceae75c29450Johann  ptr = base_pre + d->offset + (d->bmi.mv.as_mv.row >> 3) * pre_stride +
1027bc9febe8749e98a3812a0dc4380ceae75c29450Johann        (d->bmi.mv.as_mv.col >> 3);
1037bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1047bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (d->bmi.mv.as_mv.row & 7 || d->bmi.mv.as_mv.col & 7) {
1057bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->subpixel_predict8x4(ptr, pre_stride, d->bmi.mv.as_mv.col & 7,
1067bc9febe8749e98a3812a0dc4380ceae75c29450Johann                           d->bmi.mv.as_mv.row & 7, dst, dst_stride);
1077bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
1087bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_copy_mem8x4(ptr, pre_stride, dst, dst_stride);
1097bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
1101b362b15af34006e6a11974088a46d42b903418eJohann}
1111b362b15af34006e6a11974088a46d42b903418eJohann
1127bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic void build_inter_predictors_b(BLOCKD *d, unsigned char *dst,
1137bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                     int dst_stride, unsigned char *base_pre,
1147bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                     int pre_stride, vp8_subpix_fn_t sppf) {
1157bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int r;
1167bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *ptr;
1177bc9febe8749e98a3812a0dc4380ceae75c29450Johann  ptr = base_pre + d->offset + (d->bmi.mv.as_mv.row >> 3) * pre_stride +
1187bc9febe8749e98a3812a0dc4380ceae75c29450Johann        (d->bmi.mv.as_mv.col >> 3);
1197bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1207bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (d->bmi.mv.as_mv.row & 7 || d->bmi.mv.as_mv.col & 7) {
1217bc9febe8749e98a3812a0dc4380ceae75c29450Johann    sppf(ptr, pre_stride, d->bmi.mv.as_mv.col & 7, d->bmi.mv.as_mv.row & 7, dst,
1227bc9febe8749e98a3812a0dc4380ceae75c29450Johann         dst_stride);
1237bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
1247bc9febe8749e98a3812a0dc4380ceae75c29450Johann    for (r = 0; r < 4; ++r) {
1257bc9febe8749e98a3812a0dc4380ceae75c29450Johann      dst[0] = ptr[0];
1267bc9febe8749e98a3812a0dc4380ceae75c29450Johann      dst[1] = ptr[1];
1277bc9febe8749e98a3812a0dc4380ceae75c29450Johann      dst[2] = ptr[2];
1287bc9febe8749e98a3812a0dc4380ceae75c29450Johann      dst[3] = ptr[3];
1297bc9febe8749e98a3812a0dc4380ceae75c29450Johann      dst += dst_stride;
1307bc9febe8749e98a3812a0dc4380ceae75c29450Johann      ptr += pre_stride;
1311b362b15af34006e6a11974088a46d42b903418eJohann    }
1327bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
1331b362b15af34006e6a11974088a46d42b903418eJohann}
1341b362b15af34006e6a11974088a46d42b903418eJohann
1351b362b15af34006e6a11974088a46d42b903418eJohann/*encoder only*/
1367bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_build_inter16x16_predictors_mbuv(MACROBLOCKD *x) {
1377bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *uptr, *vptr;
1387bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *upred_ptr = &x->predictor[256];
1397bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *vpred_ptr = &x->predictor[320];
1407bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1417bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int mv_row = x->mode_info_context->mbmi.mv.as_mv.row;
1427bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int mv_col = x->mode_info_context->mbmi.mv.as_mv.col;
1437bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int offset;
1447bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int pre_stride = x->pre.uv_stride;
1457bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1467bc9febe8749e98a3812a0dc4380ceae75c29450Johann  /* calc uv motion vectors */
1477bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv_row += 1 | (mv_row >> (sizeof(int) * CHAR_BIT - 1));
1487bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv_col += 1 | (mv_col >> (sizeof(int) * CHAR_BIT - 1));
1497bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv_row /= 2;
1507bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv_col /= 2;
1517bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv_row &= x->fullpixel_mask;
1527bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv_col &= x->fullpixel_mask;
1537bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1547bc9febe8749e98a3812a0dc4380ceae75c29450Johann  offset = (mv_row >> 3) * pre_stride + (mv_col >> 3);
1557bc9febe8749e98a3812a0dc4380ceae75c29450Johann  uptr = x->pre.u_buffer + offset;
1567bc9febe8749e98a3812a0dc4380ceae75c29450Johann  vptr = x->pre.v_buffer + offset;
1577bc9febe8749e98a3812a0dc4380ceae75c29450Johann
1587bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if ((mv_row | mv_col) & 7) {
1597bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->subpixel_predict8x8(uptr, pre_stride, mv_col & 7, mv_row & 7, upred_ptr,
1607bc9febe8749e98a3812a0dc4380ceae75c29450Johann                           8);
1617bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->subpixel_predict8x8(vptr, pre_stride, mv_col & 7, mv_row & 7, vpred_ptr,
1627bc9febe8749e98a3812a0dc4380ceae75c29450Johann                           8);
1637bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
1647bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_copy_mem8x8(uptr, pre_stride, upred_ptr, 8);
1657bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_copy_mem8x8(vptr, pre_stride, vpred_ptr, 8);
1667bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
1671b362b15af34006e6a11974088a46d42b903418eJohann}
1681b362b15af34006e6a11974088a46d42b903418eJohann
1691b362b15af34006e6a11974088a46d42b903418eJohann/*encoder only*/
1707bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_build_inter4x4_predictors_mbuv(MACROBLOCKD *x) {
1717bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int i, j;
1727bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int pre_stride = x->pre.uv_stride;
1737bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *base_pre;
1741b362b15af34006e6a11974088a46d42b903418eJohann
1757bc9febe8749e98a3812a0dc4380ceae75c29450Johann  /* build uv mvs */
1767bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (i = 0; i < 2; ++i) {
1777bc9febe8749e98a3812a0dc4380ceae75c29450Johann    for (j = 0; j < 2; ++j) {
1787bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int yoffset = i * 8 + j * 2;
1797bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int uoffset = 16 + i * 2 + j;
1807bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int voffset = 20 + i * 2 + j;
1811b362b15af34006e6a11974088a46d42b903418eJohann
1827bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int temp;
1831b362b15af34006e6a11974088a46d42b903418eJohann
1847bc9febe8749e98a3812a0dc4380ceae75c29450Johann      temp = x->block[yoffset].bmi.mv.as_mv.row +
1857bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->block[yoffset + 1].bmi.mv.as_mv.row +
1867bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->block[yoffset + 4].bmi.mv.as_mv.row +
1877bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->block[yoffset + 5].bmi.mv.as_mv.row;
1881b362b15af34006e6a11974088a46d42b903418eJohann
1897bc9febe8749e98a3812a0dc4380ceae75c29450Johann      temp += 4 + ((temp >> (sizeof(temp) * CHAR_BIT - 1)) * 8);
1901b362b15af34006e6a11974088a46d42b903418eJohann
1917bc9febe8749e98a3812a0dc4380ceae75c29450Johann      x->block[uoffset].bmi.mv.as_mv.row = (temp / 8) & x->fullpixel_mask;
1921b362b15af34006e6a11974088a46d42b903418eJohann
1937bc9febe8749e98a3812a0dc4380ceae75c29450Johann      temp = x->block[yoffset].bmi.mv.as_mv.col +
1947bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->block[yoffset + 1].bmi.mv.as_mv.col +
1957bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->block[yoffset + 4].bmi.mv.as_mv.col +
1967bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->block[yoffset + 5].bmi.mv.as_mv.col;
1971b362b15af34006e6a11974088a46d42b903418eJohann
1987bc9febe8749e98a3812a0dc4380ceae75c29450Johann      temp += 4 + ((temp >> (sizeof(temp) * CHAR_BIT - 1)) * 8);
1991b362b15af34006e6a11974088a46d42b903418eJohann
2007bc9febe8749e98a3812a0dc4380ceae75c29450Johann      x->block[uoffset].bmi.mv.as_mv.col = (temp / 8) & x->fullpixel_mask;
2011b362b15af34006e6a11974088a46d42b903418eJohann
2027bc9febe8749e98a3812a0dc4380ceae75c29450Johann      x->block[voffset].bmi.mv.as_int = x->block[uoffset].bmi.mv.as_int;
2031b362b15af34006e6a11974088a46d42b903418eJohann    }
2047bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
2057bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2067bc9febe8749e98a3812a0dc4380ceae75c29450Johann  base_pre = x->pre.u_buffer;
2077bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (i = 16; i < 20; i += 2) {
2087bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *d0 = &x->block[i];
2097bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *d1 = &x->block[i + 1];
2107bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2117bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (d0->bmi.mv.as_int == d1->bmi.mv.as_int) {
2127bc9febe8749e98a3812a0dc4380ceae75c29450Johann      build_inter_predictors2b(x, d0, d0->predictor, 8, base_pre, pre_stride);
2137bc9febe8749e98a3812a0dc4380ceae75c29450Johann    } else {
2147bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vp8_build_inter_predictors_b(d0, 8, base_pre, pre_stride,
2157bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                   x->subpixel_predict);
2167bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vp8_build_inter_predictors_b(d1, 8, base_pre, pre_stride,
2177bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                   x->subpixel_predict);
2181b362b15af34006e6a11974088a46d42b903418eJohann    }
2197bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
2207bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2217bc9febe8749e98a3812a0dc4380ceae75c29450Johann  base_pre = x->pre.v_buffer;
2227bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (i = 20; i < 24; i += 2) {
2237bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *d0 = &x->block[i];
2247bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *d1 = &x->block[i + 1];
2257bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2267bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (d0->bmi.mv.as_int == d1->bmi.mv.as_int) {
2277bc9febe8749e98a3812a0dc4380ceae75c29450Johann      build_inter_predictors2b(x, d0, d0->predictor, 8, base_pre, pre_stride);
2287bc9febe8749e98a3812a0dc4380ceae75c29450Johann    } else {
2297bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vp8_build_inter_predictors_b(d0, 8, base_pre, pre_stride,
2307bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                   x->subpixel_predict);
2317bc9febe8749e98a3812a0dc4380ceae75c29450Johann      vp8_build_inter_predictors_b(d1, 8, base_pre, pre_stride,
2327bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                   x->subpixel_predict);
2331b362b15af34006e6a11974088a46d42b903418eJohann    }
2347bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
2351b362b15af34006e6a11974088a46d42b903418eJohann}
2361b362b15af34006e6a11974088a46d42b903418eJohann
2371b362b15af34006e6a11974088a46d42b903418eJohann/*encoder only*/
2387bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_build_inter16x16_predictors_mby(MACROBLOCKD *x, unsigned char *dst_y,
2397bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                         int dst_ystride) {
2407bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *ptr_base;
2417bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *ptr;
2427bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int mv_row = x->mode_info_context->mbmi.mv.as_mv.row;
2437bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int mv_col = x->mode_info_context->mbmi.mv.as_mv.col;
2447bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int pre_stride = x->pre.y_stride;
2457bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2467bc9febe8749e98a3812a0dc4380ceae75c29450Johann  ptr_base = x->pre.y_buffer;
2477bc9febe8749e98a3812a0dc4380ceae75c29450Johann  ptr = ptr_base + (mv_row >> 3) * pre_stride + (mv_col >> 3);
2487bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2497bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if ((mv_row | mv_col) & 7) {
2507bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->subpixel_predict16x16(ptr, pre_stride, mv_col & 7, mv_row & 7, dst_y,
2517bc9febe8749e98a3812a0dc4380ceae75c29450Johann                             dst_ystride);
2527bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
2537bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_copy_mem16x16(ptr, pre_stride, dst_y, dst_ystride);
2547bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
2551b362b15af34006e6a11974088a46d42b903418eJohann}
2561b362b15af34006e6a11974088a46d42b903418eJohann
2577bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic void clamp_mv_to_umv_border(MV *mv, const MACROBLOCKD *xd) {
2587bc9febe8749e98a3812a0dc4380ceae75c29450Johann  /* If the MV points so far into the UMV border that no visible pixels
2597bc9febe8749e98a3812a0dc4380ceae75c29450Johann   * are used for reconstruction, the subpel part of the MV can be
2607bc9febe8749e98a3812a0dc4380ceae75c29450Johann   * discarded and the MV limited to 16 pixels with equivalent results.
2617bc9febe8749e98a3812a0dc4380ceae75c29450Johann   *
2627bc9febe8749e98a3812a0dc4380ceae75c29450Johann   * This limit kicks in at 19 pixels for the top and left edges, for
2637bc9febe8749e98a3812a0dc4380ceae75c29450Johann   * the 16 pixels plus 3 taps right of the central pixel when subpel
2647bc9febe8749e98a3812a0dc4380ceae75c29450Johann   * filtering. The bottom and right edges use 16 pixels plus 2 pixels
2657bc9febe8749e98a3812a0dc4380ceae75c29450Johann   * left of the central pixel when filtering.
2667bc9febe8749e98a3812a0dc4380ceae75c29450Johann   */
2677bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (mv->col < (xd->mb_to_left_edge - (19 << 3))) {
2687bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mv->col = xd->mb_to_left_edge - (16 << 3);
2697bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else if (mv->col > xd->mb_to_right_edge + (18 << 3)) {
2707bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mv->col = xd->mb_to_right_edge + (16 << 3);
2717bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
2727bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2737bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (mv->row < (xd->mb_to_top_edge - (19 << 3))) {
2747bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mv->row = xd->mb_to_top_edge - (16 << 3);
2757bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else if (mv->row > xd->mb_to_bottom_edge + (18 << 3)) {
2767bc9febe8749e98a3812a0dc4380ceae75c29450Johann    mv->row = xd->mb_to_bottom_edge + (16 << 3);
2777bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
2781b362b15af34006e6a11974088a46d42b903418eJohann}
2791b362b15af34006e6a11974088a46d42b903418eJohann
2801b362b15af34006e6a11974088a46d42b903418eJohann/* A version of the above function for chroma block MVs.*/
2817bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic void clamp_uvmv_to_umv_border(MV *mv, const MACROBLOCKD *xd) {
2827bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv->col = (2 * mv->col < (xd->mb_to_left_edge - (19 << 3)))
2837bc9febe8749e98a3812a0dc4380ceae75c29450Johann                ? (xd->mb_to_left_edge - (16 << 3)) >> 1
2847bc9febe8749e98a3812a0dc4380ceae75c29450Johann                : mv->col;
2857bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv->col = (2 * mv->col > xd->mb_to_right_edge + (18 << 3))
2867bc9febe8749e98a3812a0dc4380ceae75c29450Johann                ? (xd->mb_to_right_edge + (16 << 3)) >> 1
2877bc9febe8749e98a3812a0dc4380ceae75c29450Johann                : mv->col;
2887bc9febe8749e98a3812a0dc4380ceae75c29450Johann
2897bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv->row = (2 * mv->row < (xd->mb_to_top_edge - (19 << 3)))
2907bc9febe8749e98a3812a0dc4380ceae75c29450Johann                ? (xd->mb_to_top_edge - (16 << 3)) >> 1
2917bc9febe8749e98a3812a0dc4380ceae75c29450Johann                : mv->row;
2927bc9febe8749e98a3812a0dc4380ceae75c29450Johann  mv->row = (2 * mv->row > xd->mb_to_bottom_edge + (18 << 3))
2937bc9febe8749e98a3812a0dc4380ceae75c29450Johann                ? (xd->mb_to_bottom_edge + (16 << 3)) >> 1
2947bc9febe8749e98a3812a0dc4380ceae75c29450Johann                : mv->row;
2951b362b15af34006e6a11974088a46d42b903418eJohann}
2961b362b15af34006e6a11974088a46d42b903418eJohann
2977bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_build_inter16x16_predictors_mb(MACROBLOCKD *x, unsigned char *dst_y,
2981b362b15af34006e6a11974088a46d42b903418eJohann                                        unsigned char *dst_u,
2997bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                        unsigned char *dst_v, int dst_ystride,
3007bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                        int dst_uvstride) {
3017bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int offset;
3027bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *ptr;
3037bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *uptr, *vptr;
3047bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3057bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int_mv _16x16mv;
3067bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3077bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *ptr_base = x->pre.y_buffer;
3087bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int pre_stride = x->pre.y_stride;
3097bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3107bc9febe8749e98a3812a0dc4380ceae75c29450Johann  _16x16mv.as_int = x->mode_info_context->mbmi.mv.as_int;
3117bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3127bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (x->mode_info_context->mbmi.need_to_clamp_mvs) {
3137bc9febe8749e98a3812a0dc4380ceae75c29450Johann    clamp_mv_to_umv_border(&_16x16mv.as_mv, x);
3147bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
3157bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3167bc9febe8749e98a3812a0dc4380ceae75c29450Johann  ptr = ptr_base + (_16x16mv.as_mv.row >> 3) * pre_stride +
3177bc9febe8749e98a3812a0dc4380ceae75c29450Johann        (_16x16mv.as_mv.col >> 3);
3187bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3197bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (_16x16mv.as_int & 0x00070007) {
3207bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->subpixel_predict16x16(ptr, pre_stride, _16x16mv.as_mv.col & 7,
3217bc9febe8749e98a3812a0dc4380ceae75c29450Johann                             _16x16mv.as_mv.row & 7, dst_y, dst_ystride);
3227bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
3237bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_copy_mem16x16(ptr, pre_stride, dst_y, dst_ystride);
3247bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
3257bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3267bc9febe8749e98a3812a0dc4380ceae75c29450Johann  /* calc uv motion vectors */
3277bc9febe8749e98a3812a0dc4380ceae75c29450Johann  _16x16mv.as_mv.row +=
3287bc9febe8749e98a3812a0dc4380ceae75c29450Johann      1 | (_16x16mv.as_mv.row >> (sizeof(int) * CHAR_BIT - 1));
3297bc9febe8749e98a3812a0dc4380ceae75c29450Johann  _16x16mv.as_mv.col +=
3307bc9febe8749e98a3812a0dc4380ceae75c29450Johann      1 | (_16x16mv.as_mv.col >> (sizeof(int) * CHAR_BIT - 1));
3317bc9febe8749e98a3812a0dc4380ceae75c29450Johann  _16x16mv.as_mv.row /= 2;
3327bc9febe8749e98a3812a0dc4380ceae75c29450Johann  _16x16mv.as_mv.col /= 2;
3337bc9febe8749e98a3812a0dc4380ceae75c29450Johann  _16x16mv.as_mv.row &= x->fullpixel_mask;
3347bc9febe8749e98a3812a0dc4380ceae75c29450Johann  _16x16mv.as_mv.col &= x->fullpixel_mask;
3357bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3367bc9febe8749e98a3812a0dc4380ceae75c29450Johann  pre_stride >>= 1;
3377bc9febe8749e98a3812a0dc4380ceae75c29450Johann  offset = (_16x16mv.as_mv.row >> 3) * pre_stride + (_16x16mv.as_mv.col >> 3);
3387bc9febe8749e98a3812a0dc4380ceae75c29450Johann  uptr = x->pre.u_buffer + offset;
3397bc9febe8749e98a3812a0dc4380ceae75c29450Johann  vptr = x->pre.v_buffer + offset;
3407bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3417bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (_16x16mv.as_int & 0x00070007) {
3427bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->subpixel_predict8x8(uptr, pre_stride, _16x16mv.as_mv.col & 7,
3437bc9febe8749e98a3812a0dc4380ceae75c29450Johann                           _16x16mv.as_mv.row & 7, dst_u, dst_uvstride);
3447bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->subpixel_predict8x8(vptr, pre_stride, _16x16mv.as_mv.col & 7,
3457bc9febe8749e98a3812a0dc4380ceae75c29450Johann                           _16x16mv.as_mv.row & 7, dst_v, dst_uvstride);
3467bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
3477bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_copy_mem8x8(uptr, pre_stride, dst_u, dst_uvstride);
3487bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_copy_mem8x8(vptr, pre_stride, dst_v, dst_uvstride);
3497bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
3501b362b15af34006e6a11974088a46d42b903418eJohann}
3511b362b15af34006e6a11974088a46d42b903418eJohann
3527bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic void build_inter4x4_predictors_mb(MACROBLOCKD *x) {
3537bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int i;
3547bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *base_dst = x->dst.y_buffer;
3557bc9febe8749e98a3812a0dc4380ceae75c29450Johann  unsigned char *base_pre = x->pre.y_buffer;
3567bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3577bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (x->mode_info_context->mbmi.partitioning < 3) {
3587bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *b;
3597bc9febe8749e98a3812a0dc4380ceae75c29450Johann    int dst_stride = x->dst.y_stride;
3607bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3617bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->block[0].bmi = x->mode_info_context->bmi[0];
3627bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->block[2].bmi = x->mode_info_context->bmi[2];
3637bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->block[8].bmi = x->mode_info_context->bmi[8];
3647bc9febe8749e98a3812a0dc4380ceae75c29450Johann    x->block[10].bmi = x->mode_info_context->bmi[10];
3657bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (x->mode_info_context->mbmi.need_to_clamp_mvs) {
3667bc9febe8749e98a3812a0dc4380ceae75c29450Johann      clamp_mv_to_umv_border(&x->block[0].bmi.mv.as_mv, x);
3677bc9febe8749e98a3812a0dc4380ceae75c29450Johann      clamp_mv_to_umv_border(&x->block[2].bmi.mv.as_mv, x);
3687bc9febe8749e98a3812a0dc4380ceae75c29450Johann      clamp_mv_to_umv_border(&x->block[8].bmi.mv.as_mv, x);
3697bc9febe8749e98a3812a0dc4380ceae75c29450Johann      clamp_mv_to_umv_border(&x->block[10].bmi.mv.as_mv, x);
3701b362b15af34006e6a11974088a46d42b903418eJohann    }
3711b362b15af34006e6a11974088a46d42b903418eJohann
3727bc9febe8749e98a3812a0dc4380ceae75c29450Johann    b = &x->block[0];
3737bc9febe8749e98a3812a0dc4380ceae75c29450Johann    build_inter_predictors4b(x, b, base_dst + b->offset, dst_stride, base_pre,
3747bc9febe8749e98a3812a0dc4380ceae75c29450Johann                             dst_stride);
3757bc9febe8749e98a3812a0dc4380ceae75c29450Johann    b = &x->block[2];
3767bc9febe8749e98a3812a0dc4380ceae75c29450Johann    build_inter_predictors4b(x, b, base_dst + b->offset, dst_stride, base_pre,
3777bc9febe8749e98a3812a0dc4380ceae75c29450Johann                             dst_stride);
3787bc9febe8749e98a3812a0dc4380ceae75c29450Johann    b = &x->block[8];
3797bc9febe8749e98a3812a0dc4380ceae75c29450Johann    build_inter_predictors4b(x, b, base_dst + b->offset, dst_stride, base_pre,
3807bc9febe8749e98a3812a0dc4380ceae75c29450Johann                             dst_stride);
3817bc9febe8749e98a3812a0dc4380ceae75c29450Johann    b = &x->block[10];
3827bc9febe8749e98a3812a0dc4380ceae75c29450Johann    build_inter_predictors4b(x, b, base_dst + b->offset, dst_stride, base_pre,
3837bc9febe8749e98a3812a0dc4380ceae75c29450Johann                             dst_stride);
3847bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
3857bc9febe8749e98a3812a0dc4380ceae75c29450Johann    for (i = 0; i < 16; i += 2) {
3867bc9febe8749e98a3812a0dc4380ceae75c29450Johann      BLOCKD *d0 = &x->block[i];
3877bc9febe8749e98a3812a0dc4380ceae75c29450Johann      BLOCKD *d1 = &x->block[i + 1];
3887bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int dst_stride = x->dst.y_stride;
3897bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3907bc9febe8749e98a3812a0dc4380ceae75c29450Johann      x->block[i + 0].bmi = x->mode_info_context->bmi[i + 0];
3917bc9febe8749e98a3812a0dc4380ceae75c29450Johann      x->block[i + 1].bmi = x->mode_info_context->bmi[i + 1];
3927bc9febe8749e98a3812a0dc4380ceae75c29450Johann      if (x->mode_info_context->mbmi.need_to_clamp_mvs) {
3937bc9febe8749e98a3812a0dc4380ceae75c29450Johann        clamp_mv_to_umv_border(&x->block[i + 0].bmi.mv.as_mv, x);
3947bc9febe8749e98a3812a0dc4380ceae75c29450Johann        clamp_mv_to_umv_border(&x->block[i + 1].bmi.mv.as_mv, x);
3957bc9febe8749e98a3812a0dc4380ceae75c29450Johann      }
3967bc9febe8749e98a3812a0dc4380ceae75c29450Johann
3977bc9febe8749e98a3812a0dc4380ceae75c29450Johann      if (d0->bmi.mv.as_int == d1->bmi.mv.as_int) {
3987bc9febe8749e98a3812a0dc4380ceae75c29450Johann        build_inter_predictors2b(x, d0, base_dst + d0->offset, dst_stride,
3997bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                 base_pre, dst_stride);
4007bc9febe8749e98a3812a0dc4380ceae75c29450Johann      } else {
4017bc9febe8749e98a3812a0dc4380ceae75c29450Johann        build_inter_predictors_b(d0, base_dst + d0->offset, dst_stride,
4027bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                 base_pre, dst_stride, x->subpixel_predict);
4037bc9febe8749e98a3812a0dc4380ceae75c29450Johann        build_inter_predictors_b(d1, base_dst + d1->offset, dst_stride,
4047bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                 base_pre, dst_stride, x->subpixel_predict);
4057bc9febe8749e98a3812a0dc4380ceae75c29450Johann      }
4061b362b15af34006e6a11974088a46d42b903418eJohann    }
4077bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
4087bc9febe8749e98a3812a0dc4380ceae75c29450Johann  base_dst = x->dst.u_buffer;
4097bc9febe8749e98a3812a0dc4380ceae75c29450Johann  base_pre = x->pre.u_buffer;
4107bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (i = 16; i < 20; i += 2) {
4117bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *d0 = &x->block[i];
4127bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *d1 = &x->block[i + 1];
4137bc9febe8749e98a3812a0dc4380ceae75c29450Johann    int dst_stride = x->dst.uv_stride;
4147bc9febe8749e98a3812a0dc4380ceae75c29450Johann
4157bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /* Note: uv mvs already clamped in build_4x4uvmvs() */
4167bc9febe8749e98a3812a0dc4380ceae75c29450Johann
4177bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (d0->bmi.mv.as_int == d1->bmi.mv.as_int) {
4187bc9febe8749e98a3812a0dc4380ceae75c29450Johann      build_inter_predictors2b(x, d0, base_dst + d0->offset, dst_stride,
4197bc9febe8749e98a3812a0dc4380ceae75c29450Johann                               base_pre, dst_stride);
4207bc9febe8749e98a3812a0dc4380ceae75c29450Johann    } else {
4217bc9febe8749e98a3812a0dc4380ceae75c29450Johann      build_inter_predictors_b(d0, base_dst + d0->offset, dst_stride, base_pre,
4227bc9febe8749e98a3812a0dc4380ceae75c29450Johann                               dst_stride, x->subpixel_predict);
4237bc9febe8749e98a3812a0dc4380ceae75c29450Johann      build_inter_predictors_b(d1, base_dst + d1->offset, dst_stride, base_pre,
4247bc9febe8749e98a3812a0dc4380ceae75c29450Johann                               dst_stride, x->subpixel_predict);
4251b362b15af34006e6a11974088a46d42b903418eJohann    }
4267bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
4277bc9febe8749e98a3812a0dc4380ceae75c29450Johann
4287bc9febe8749e98a3812a0dc4380ceae75c29450Johann  base_dst = x->dst.v_buffer;
4297bc9febe8749e98a3812a0dc4380ceae75c29450Johann  base_pre = x->pre.v_buffer;
4307bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (i = 20; i < 24; i += 2) {
4317bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *d0 = &x->block[i];
4327bc9febe8749e98a3812a0dc4380ceae75c29450Johann    BLOCKD *d1 = &x->block[i + 1];
4337bc9febe8749e98a3812a0dc4380ceae75c29450Johann    int dst_stride = x->dst.uv_stride;
4347bc9febe8749e98a3812a0dc4380ceae75c29450Johann
4357bc9febe8749e98a3812a0dc4380ceae75c29450Johann    /* Note: uv mvs already clamped in build_4x4uvmvs() */
4367bc9febe8749e98a3812a0dc4380ceae75c29450Johann
4377bc9febe8749e98a3812a0dc4380ceae75c29450Johann    if (d0->bmi.mv.as_int == d1->bmi.mv.as_int) {
4387bc9febe8749e98a3812a0dc4380ceae75c29450Johann      build_inter_predictors2b(x, d0, base_dst + d0->offset, dst_stride,
4397bc9febe8749e98a3812a0dc4380ceae75c29450Johann                               base_pre, dst_stride);
4407bc9febe8749e98a3812a0dc4380ceae75c29450Johann    } else {
4417bc9febe8749e98a3812a0dc4380ceae75c29450Johann      build_inter_predictors_b(d0, base_dst + d0->offset, dst_stride, base_pre,
4427bc9febe8749e98a3812a0dc4380ceae75c29450Johann                               dst_stride, x->subpixel_predict);
4437bc9febe8749e98a3812a0dc4380ceae75c29450Johann      build_inter_predictors_b(d1, base_dst + d1->offset, dst_stride, base_pre,
4447bc9febe8749e98a3812a0dc4380ceae75c29450Johann                               dst_stride, x->subpixel_predict);
4451b362b15af34006e6a11974088a46d42b903418eJohann    }
4467bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
4471b362b15af34006e6a11974088a46d42b903418eJohann}
4481b362b15af34006e6a11974088a46d42b903418eJohann
4497bc9febe8749e98a3812a0dc4380ceae75c29450Johannstatic void build_4x4uvmvs(MACROBLOCKD *x) {
4507bc9febe8749e98a3812a0dc4380ceae75c29450Johann  int i, j;
4511b362b15af34006e6a11974088a46d42b903418eJohann
4527bc9febe8749e98a3812a0dc4380ceae75c29450Johann  for (i = 0; i < 2; ++i) {
4537bc9febe8749e98a3812a0dc4380ceae75c29450Johann    for (j = 0; j < 2; ++j) {
4547bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int yoffset = i * 8 + j * 2;
4557bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int uoffset = 16 + i * 2 + j;
4567bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int voffset = 20 + i * 2 + j;
4571b362b15af34006e6a11974088a46d42b903418eJohann
4587bc9febe8749e98a3812a0dc4380ceae75c29450Johann      int temp;
4591b362b15af34006e6a11974088a46d42b903418eJohann
4607bc9febe8749e98a3812a0dc4380ceae75c29450Johann      temp = x->mode_info_context->bmi[yoffset + 0].mv.as_mv.row +
4617bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->mode_info_context->bmi[yoffset + 1].mv.as_mv.row +
4627bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->mode_info_context->bmi[yoffset + 4].mv.as_mv.row +
4637bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->mode_info_context->bmi[yoffset + 5].mv.as_mv.row;
4641b362b15af34006e6a11974088a46d42b903418eJohann
4657bc9febe8749e98a3812a0dc4380ceae75c29450Johann      temp += 4 + ((temp >> (sizeof(temp) * CHAR_BIT - 1)) * 8);
4661b362b15af34006e6a11974088a46d42b903418eJohann
4677bc9febe8749e98a3812a0dc4380ceae75c29450Johann      x->block[uoffset].bmi.mv.as_mv.row = (temp / 8) & x->fullpixel_mask;
4681b362b15af34006e6a11974088a46d42b903418eJohann
4697bc9febe8749e98a3812a0dc4380ceae75c29450Johann      temp = x->mode_info_context->bmi[yoffset + 0].mv.as_mv.col +
4707bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->mode_info_context->bmi[yoffset + 1].mv.as_mv.col +
4717bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->mode_info_context->bmi[yoffset + 4].mv.as_mv.col +
4727bc9febe8749e98a3812a0dc4380ceae75c29450Johann             x->mode_info_context->bmi[yoffset + 5].mv.as_mv.col;
4731b362b15af34006e6a11974088a46d42b903418eJohann
4747bc9febe8749e98a3812a0dc4380ceae75c29450Johann      temp += 4 + ((temp >> (sizeof(temp) * CHAR_BIT - 1)) * 8);
4751b362b15af34006e6a11974088a46d42b903418eJohann
4767bc9febe8749e98a3812a0dc4380ceae75c29450Johann      x->block[uoffset].bmi.mv.as_mv.col = (temp / 8) & x->fullpixel_mask;
4771b362b15af34006e6a11974088a46d42b903418eJohann
4787bc9febe8749e98a3812a0dc4380ceae75c29450Johann      if (x->mode_info_context->mbmi.need_to_clamp_mvs) {
4797bc9febe8749e98a3812a0dc4380ceae75c29450Johann        clamp_uvmv_to_umv_border(&x->block[uoffset].bmi.mv.as_mv, x);
4807bc9febe8749e98a3812a0dc4380ceae75c29450Johann      }
4811b362b15af34006e6a11974088a46d42b903418eJohann
4827bc9febe8749e98a3812a0dc4380ceae75c29450Johann      x->block[voffset].bmi.mv.as_int = x->block[uoffset].bmi.mv.as_int;
4831b362b15af34006e6a11974088a46d42b903418eJohann    }
4847bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
4851b362b15af34006e6a11974088a46d42b903418eJohann}
4861b362b15af34006e6a11974088a46d42b903418eJohann
4877bc9febe8749e98a3812a0dc4380ceae75c29450Johannvoid vp8_build_inter_predictors_mb(MACROBLOCKD *xd) {
4887bc9febe8749e98a3812a0dc4380ceae75c29450Johann  if (xd->mode_info_context->mbmi.mode != SPLITMV) {
4897bc9febe8749e98a3812a0dc4380ceae75c29450Johann    vp8_build_inter16x16_predictors_mb(xd, xd->dst.y_buffer, xd->dst.u_buffer,
4907bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                       xd->dst.v_buffer, xd->dst.y_stride,
4917bc9febe8749e98a3812a0dc4380ceae75c29450Johann                                       xd->dst.uv_stride);
4927bc9febe8749e98a3812a0dc4380ceae75c29450Johann  } else {
4937bc9febe8749e98a3812a0dc4380ceae75c29450Johann    build_4x4uvmvs(xd);
4947bc9febe8749e98a3812a0dc4380ceae75c29450Johann    build_inter4x4_predictors_mb(xd);
4957bc9febe8749e98a3812a0dc4380ceae75c29450Johann  }
4961b362b15af34006e6a11974088a46d42b903418eJohann}
497