subpel_variance_neon.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <arm_neon.h>
  11. #include "./vpx_dsp_rtcd.h"
  12. #include "./vpx_config.h"
  13. #include "vpx/vpx_integer.h"
  14. #include "vpx_dsp/variance.h"
  15. #include "vpx_dsp/arm/mem_neon.h"
  16. static const uint8_t bilinear_filters[8][2] = {
  17. { 128, 0 }, { 112, 16 }, { 96, 32 }, { 80, 48 },
  18. { 64, 64 }, { 48, 80 }, { 32, 96 }, { 16, 112 },
  19. };
  20. // Process a block exactly 4 wide and a multiple of 2 high.
  21. static void var_filter_block2d_bil_w4(const uint8_t *src_ptr,
  22. uint8_t *output_ptr,
  23. unsigned int src_pixels_per_line,
  24. int pixel_step,
  25. unsigned int output_height,
  26. const uint8_t *filter) {
  27. const uint8x8_t f0 = vdup_n_u8(filter[0]);
  28. const uint8x8_t f1 = vdup_n_u8(filter[1]);
  29. unsigned int i;
  30. for (i = 0; i < output_height; i += 2) {
  31. const uint8x8_t src_0 = load_unaligned_u8(src_ptr, src_pixels_per_line);
  32. const uint8x8_t src_1 =
  33. load_unaligned_u8(src_ptr + pixel_step, src_pixels_per_line);
  34. const uint16x8_t a = vmull_u8(src_0, f0);
  35. const uint16x8_t b = vmlal_u8(a, src_1, f1);
  36. const uint8x8_t out = vrshrn_n_u16(b, FILTER_BITS);
  37. vst1_u8(output_ptr, out);
  38. src_ptr += 2 * src_pixels_per_line;
  39. output_ptr += 8;
  40. }
  41. }
  42. // Process a block exactly 8 wide and any height.
  43. static void var_filter_block2d_bil_w8(const uint8_t *src_ptr,
  44. uint8_t *output_ptr,
  45. unsigned int src_pixels_per_line,
  46. int pixel_step,
  47. unsigned int output_height,
  48. const uint8_t *filter) {
  49. const uint8x8_t f0 = vdup_n_u8(filter[0]);
  50. const uint8x8_t f1 = vdup_n_u8(filter[1]);
  51. unsigned int i;
  52. for (i = 0; i < output_height; ++i) {
  53. const uint8x8_t src_0 = vld1_u8(&src_ptr[0]);
  54. const uint8x8_t src_1 = vld1_u8(&src_ptr[pixel_step]);
  55. const uint16x8_t a = vmull_u8(src_0, f0);
  56. const uint16x8_t b = vmlal_u8(a, src_1, f1);
  57. const uint8x8_t out = vrshrn_n_u16(b, FILTER_BITS);
  58. vst1_u8(output_ptr, out);
  59. src_ptr += src_pixels_per_line;
  60. output_ptr += 8;
  61. }
  62. }
  63. // Process a block which is a mutiple of 16 wide and any height.
  64. static void var_filter_block2d_bil_w16(const uint8_t *src_ptr,
  65. uint8_t *output_ptr,
  66. unsigned int src_pixels_per_line,
  67. int pixel_step,
  68. unsigned int output_height,
  69. unsigned int output_width,
  70. const uint8_t *filter) {
  71. const uint8x8_t f0 = vdup_n_u8(filter[0]);
  72. const uint8x8_t f1 = vdup_n_u8(filter[1]);
  73. unsigned int i, j;
  74. for (i = 0; i < output_height; ++i) {
  75. for (j = 0; j < output_width; j += 16) {
  76. const uint8x16_t src_0 = vld1q_u8(&src_ptr[j]);
  77. const uint8x16_t src_1 = vld1q_u8(&src_ptr[j + pixel_step]);
  78. const uint16x8_t a = vmull_u8(vget_low_u8(src_0), f0);
  79. const uint16x8_t b = vmlal_u8(a, vget_low_u8(src_1), f1);
  80. const uint8x8_t out_lo = vrshrn_n_u16(b, FILTER_BITS);
  81. const uint16x8_t c = vmull_u8(vget_high_u8(src_0), f0);
  82. const uint16x8_t d = vmlal_u8(c, vget_high_u8(src_1), f1);
  83. const uint8x8_t out_hi = vrshrn_n_u16(d, FILTER_BITS);
  84. vst1q_u8(output_ptr + j, vcombine_u8(out_lo, out_hi));
  85. }
  86. src_ptr += src_pixels_per_line;
  87. output_ptr += output_width;
  88. }
  89. }
  90. // 4xM filter writes an extra row to fdata because it processes two rows at a
  91. // time.
  92. #define sub_pixel_varianceNxM(n, m) \
  93. uint32_t vpx_sub_pixel_variance##n##x##m##_neon( \
  94. const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, \
  95. const uint8_t *ref_ptr, int ref_stride, uint32_t *sse) { \
  96. uint8_t temp0[n * (m + (n == 4 ? 2 : 1))]; \
  97. uint8_t temp1[n * m]; \
  98. \
  99. if (n == 4) { \
  100. var_filter_block2d_bil_w4(src_ptr, temp0, src_stride, 1, (m + 2), \
  101. bilinear_filters[x_offset]); \
  102. var_filter_block2d_bil_w4(temp0, temp1, n, n, m, \
  103. bilinear_filters[y_offset]); \
  104. } else if (n == 8) { \
  105. var_filter_block2d_bil_w8(src_ptr, temp0, src_stride, 1, (m + 1), \
  106. bilinear_filters[x_offset]); \
  107. var_filter_block2d_bil_w8(temp0, temp1, n, n, m, \
  108. bilinear_filters[y_offset]); \
  109. } else { \
  110. var_filter_block2d_bil_w16(src_ptr, temp0, src_stride, 1, (m + 1), n, \
  111. bilinear_filters[x_offset]); \
  112. var_filter_block2d_bil_w16(temp0, temp1, n, n, m, n, \
  113. bilinear_filters[y_offset]); \
  114. } \
  115. return vpx_variance##n##x##m(temp1, n, ref_ptr, ref_stride, sse); \
  116. }
  117. sub_pixel_varianceNxM(4, 4);
  118. sub_pixel_varianceNxM(4, 8);
  119. sub_pixel_varianceNxM(8, 4);
  120. sub_pixel_varianceNxM(8, 8);
  121. sub_pixel_varianceNxM(8, 16);
  122. sub_pixel_varianceNxM(16, 8);
  123. sub_pixel_varianceNxM(16, 16);
  124. sub_pixel_varianceNxM(16, 32);
  125. sub_pixel_varianceNxM(32, 16);
  126. sub_pixel_varianceNxM(32, 32);
  127. sub_pixel_varianceNxM(32, 64);
  128. sub_pixel_varianceNxM(64, 32);
  129. sub_pixel_varianceNxM(64, 64);
  130. // 4xM filter writes an extra row to fdata because it processes two rows at a
  131. // time.
  132. #define sub_pixel_avg_varianceNxM(n, m) \
  133. uint32_t vpx_sub_pixel_avg_variance##n##x##m##_neon( \
  134. const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, \
  135. const uint8_t *ref_ptr, int ref_stride, uint32_t *sse, \
  136. const uint8_t *second_pred) { \
  137. uint8_t temp0[n * (m + (n == 4 ? 2 : 1))]; \
  138. uint8_t temp1[n * m]; \
  139. \
  140. if (n == 4) { \
  141. var_filter_block2d_bil_w4(src_ptr, temp0, src_stride, 1, (m + 2), \
  142. bilinear_filters[x_offset]); \
  143. var_filter_block2d_bil_w4(temp0, temp1, n, n, m, \
  144. bilinear_filters[y_offset]); \
  145. } else if (n == 8) { \
  146. var_filter_block2d_bil_w8(src_ptr, temp0, src_stride, 1, (m + 1), \
  147. bilinear_filters[x_offset]); \
  148. var_filter_block2d_bil_w8(temp0, temp1, n, n, m, \
  149. bilinear_filters[y_offset]); \
  150. } else { \
  151. var_filter_block2d_bil_w16(src_ptr, temp0, src_stride, 1, (m + 1), n, \
  152. bilinear_filters[x_offset]); \
  153. var_filter_block2d_bil_w16(temp0, temp1, n, n, m, n, \
  154. bilinear_filters[y_offset]); \
  155. } \
  156. \
  157. vpx_comp_avg_pred(temp0, second_pred, n, m, temp1, n); \
  158. \
  159. return vpx_variance##n##x##m(temp0, n, ref_ptr, ref_stride, sse); \
  160. }
  161. sub_pixel_avg_varianceNxM(4, 4);
  162. sub_pixel_avg_varianceNxM(4, 8);
  163. sub_pixel_avg_varianceNxM(8, 4);
  164. sub_pixel_avg_varianceNxM(8, 8);
  165. sub_pixel_avg_varianceNxM(8, 16);
  166. sub_pixel_avg_varianceNxM(16, 8);
  167. sub_pixel_avg_varianceNxM(16, 16);
  168. sub_pixel_avg_varianceNxM(16, 32);
  169. sub_pixel_avg_varianceNxM(32, 16);
  170. sub_pixel_avg_varianceNxM(32, 32);
  171. sub_pixel_avg_varianceNxM(32, 64);
  172. sub_pixel_avg_varianceNxM(64, 32);
  173. sub_pixel_avg_varianceNxM(64, 64);