vp9_variance_neon.c 6.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 *  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 <arm_neon.h>
#include "./vp9_rtcd.h"
Johann's avatar
Johann committed
13
#include "./vpx_dsp_rtcd.h"
14
#include "./vpx_config.h"
15 16 17 18 19 20

#include "vpx_ports/mem.h"
#include "vpx/vpx_integer.h"

#include "vp9/common/vp9_filter.h"

21
static const uint8_t bilinear_filters[8][2] = {
Johann's avatar
Johann committed
22 23 24 25 26 27 28 29 30
  { 128,   0, },
  { 112,  16, },
  {  96,  32, },
  {  80,  48, },
  {  64,  64, },
  {  48,  80, },
  {  32,  96, },
  {  16, 112, },
};
31

32 33 34 35 36 37
static void var_filter_block2d_bil_w8(const uint8_t *src_ptr,
                                      uint8_t *output_ptr,
                                      unsigned int src_pixels_per_line,
                                      int pixel_step,
                                      unsigned int output_height,
                                      unsigned int output_width,
Johann's avatar
Johann committed
38 39 40
                                      const uint8_t *vp9_filter) {
  const uint8x8_t f0 = vmov_n_u8(vp9_filter[0]);
  const uint8x8_t f1 = vmov_n_u8(vp9_filter[1]);
41 42 43 44 45 46 47 48 49 50 51 52 53 54
  unsigned int i;
  for (i = 0; i < output_height; ++i) {
    const uint8x8_t src_0 = vld1_u8(&src_ptr[0]);
    const uint8x8_t src_1 = vld1_u8(&src_ptr[pixel_step]);
    const uint16x8_t a = vmull_u8(src_0, f0);
    const uint16x8_t b = vmlal_u8(a, src_1, f1);
    const uint8x8_t out = vrshrn_n_u16(b, FILTER_BITS);
    vst1_u8(&output_ptr[0], out);
    // Next row...
    src_ptr += src_pixels_per_line;
    output_ptr += output_width;
  }
}

55 56 57 58 59 60
static void var_filter_block2d_bil_w16(const uint8_t *src_ptr,
                                       uint8_t *output_ptr,
                                       unsigned int src_pixels_per_line,
                                       int pixel_step,
                                       unsigned int output_height,
                                       unsigned int output_width,
Johann's avatar
Johann committed
61 62 63
                                       const uint8_t *vp9_filter) {
  const uint8x8_t f0 = vmov_n_u8(vp9_filter[0]);
  const uint8x8_t f1 = vmov_n_u8(vp9_filter[1]);
64
  unsigned int i, j;
65
  for (i = 0; i < output_height; ++i) {
66 67 68 69 70 71 72 73 74 75 76
    for (j = 0; j < output_width; j += 16) {
      const uint8x16_t src_0 = vld1q_u8(&src_ptr[j]);
      const uint8x16_t src_1 = vld1q_u8(&src_ptr[j + pixel_step]);
      const uint16x8_t a = vmull_u8(vget_low_u8(src_0), f0);
      const uint16x8_t b = vmlal_u8(a, vget_low_u8(src_1), f1);
      const uint8x8_t out_lo = vrshrn_n_u16(b, FILTER_BITS);
      const uint16x8_t c = vmull_u8(vget_high_u8(src_0), f0);
      const uint16x8_t d = vmlal_u8(c, vget_high_u8(src_1), f1);
      const uint8x8_t out_hi = vrshrn_n_u16(d, FILTER_BITS);
      vst1q_u8(&output_ptr[j], vcombine_u8(out_lo, out_hi));
    }
77 78 79 80 81 82
    // Next row...
    src_ptr += src_pixels_per_line;
    output_ptr += output_width;
  }
}

83 84 85 86 87 88 89
unsigned int vp9_sub_pixel_variance8x8_neon(const uint8_t *src,
                                            int src_stride,
                                            int xoffset,
                                            int yoffset,
                                            const uint8_t *dst,
                                            int dst_stride,
                                            unsigned int *sse) {
90 91
  DECLARE_ALIGNED(16, uint8_t, temp2[8 * 8]);
  DECLARE_ALIGNED(16, uint8_t, fdata3[9 * 8]);
92

93 94
  var_filter_block2d_bil_w8(src, fdata3, src_stride, 1,
                            9, 8,
Johann's avatar
Johann committed
95
                            bilinear_filters[xoffset]);
96
  var_filter_block2d_bil_w8(fdata3, temp2, 8, 8, 8,
Johann's avatar
Johann committed
97
                            8, bilinear_filters[yoffset]);
Johann's avatar
Johann committed
98
  return vpx_variance8x8_neon(temp2, 8, dst, dst_stride, sse);
99 100
}

101 102 103 104 105 106 107
unsigned int vp9_sub_pixel_variance16x16_neon(const uint8_t *src,
                                              int src_stride,
                                              int xoffset,
                                              int yoffset,
                                              const uint8_t *dst,
                                              int dst_stride,
                                              unsigned int *sse) {
108 109
  DECLARE_ALIGNED(16, uint8_t, temp2[16 * 16]);
  DECLARE_ALIGNED(16, uint8_t, fdata3[17 * 16]);
110

111 112
  var_filter_block2d_bil_w16(src, fdata3, src_stride, 1,
                             17, 16,
Johann's avatar
Johann committed
113
                             bilinear_filters[xoffset]);
114
  var_filter_block2d_bil_w16(fdata3, temp2, 16, 16, 16,
Johann's avatar
Johann committed
115
                             16, bilinear_filters[yoffset]);
Johann's avatar
Johann committed
116
  return vpx_variance16x16_neon(temp2, 16, dst, dst_stride, sse);
117 118
}

119 120 121 122 123 124 125
unsigned int vp9_sub_pixel_variance32x32_neon(const uint8_t *src,
                                              int src_stride,
                                              int xoffset,
                                              int yoffset,
                                              const uint8_t *dst,
                                              int dst_stride,
                                              unsigned int *sse) {
126 127
  DECLARE_ALIGNED(16, uint8_t, temp2[32 * 32]);
  DECLARE_ALIGNED(16, uint8_t, fdata3[33 * 32]);
128

129 130
  var_filter_block2d_bil_w16(src, fdata3, src_stride, 1,
                             33, 32,
Johann's avatar
Johann committed
131
                             bilinear_filters[xoffset]);
132
  var_filter_block2d_bil_w16(fdata3, temp2, 32, 32, 32,
Johann's avatar
Johann committed
133
                             32, bilinear_filters[yoffset]);
Johann's avatar
Johann committed
134
  return vpx_variance32x32_neon(temp2, 32, dst, dst_stride, sse);
135
}
136 137 138 139 140 141 142 143

unsigned int vp9_sub_pixel_variance64x64_neon(const uint8_t *src,
                                              int src_stride,
                                              int xoffset,
                                              int yoffset,
                                              const uint8_t *dst,
                                              int dst_stride,
                                              unsigned int *sse) {
144 145
  DECLARE_ALIGNED(16, uint8_t, temp2[64 * 64]);
  DECLARE_ALIGNED(16, uint8_t, fdata3[65 * 64]);
146

147 148
  var_filter_block2d_bil_w16(src, fdata3, src_stride, 1,
                             65, 64,
Johann's avatar
Johann committed
149
                             bilinear_filters[xoffset]);
150
  var_filter_block2d_bil_w16(fdata3, temp2, 64, 64, 64,
Johann's avatar
Johann committed
151
                             64, bilinear_filters[yoffset]);
Johann's avatar
Johann committed
152
  return vpx_variance64x64_neon(temp2, 64, dst, dst_stride, sse);
153
}