vpx_convolve_avg_neon.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/vpx_integer.h"
  13. void vpx_convolve_avg_neon(const uint8_t *src, ptrdiff_t src_stride,
  14. uint8_t *dst, ptrdiff_t dst_stride,
  15. const InterpKernel *filter, int x0_q4, int x_step_q4,
  16. int y0_q4, int y_step_q4, int w, int h) {
  17. (void)filter;
  18. (void)x0_q4;
  19. (void)x_step_q4;
  20. (void)y0_q4;
  21. (void)y_step_q4;
  22. if (w < 8) { // avg4
  23. uint8x8_t s0, s1;
  24. uint8x8_t dd0 = vdup_n_u8(0);
  25. uint32x2x2_t s01;
  26. do {
  27. s0 = vld1_u8(src);
  28. src += src_stride;
  29. s1 = vld1_u8(src);
  30. src += src_stride;
  31. s01 = vzip_u32(vreinterpret_u32_u8(s0), vreinterpret_u32_u8(s1));
  32. dd0 = vreinterpret_u8_u32(
  33. vld1_lane_u32((const uint32_t *)dst, vreinterpret_u32_u8(dd0), 0));
  34. dd0 = vreinterpret_u8_u32(vld1_lane_u32(
  35. (const uint32_t *)(dst + dst_stride), vreinterpret_u32_u8(dd0), 1));
  36. dd0 = vrhadd_u8(vreinterpret_u8_u32(s01.val[0]), dd0);
  37. vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(dd0), 0);
  38. dst += dst_stride;
  39. vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(dd0), 1);
  40. dst += dst_stride;
  41. h -= 2;
  42. } while (h > 0);
  43. } else if (w == 8) { // avg8
  44. uint8x8_t s0, s1, d0, d1;
  45. uint8x16_t s01, d01;
  46. do {
  47. s0 = vld1_u8(src);
  48. src += src_stride;
  49. s1 = vld1_u8(src);
  50. src += src_stride;
  51. d0 = vld1_u8(dst);
  52. d1 = vld1_u8(dst + dst_stride);
  53. s01 = vcombine_u8(s0, s1);
  54. d01 = vcombine_u8(d0, d1);
  55. d01 = vrhaddq_u8(s01, d01);
  56. vst1_u8(dst, vget_low_u8(d01));
  57. dst += dst_stride;
  58. vst1_u8(dst, vget_high_u8(d01));
  59. dst += dst_stride;
  60. h -= 2;
  61. } while (h > 0);
  62. } else if (w < 32) { // avg16
  63. uint8x16_t s0, s1, d0, d1;
  64. do {
  65. s0 = vld1q_u8(src);
  66. src += src_stride;
  67. s1 = vld1q_u8(src);
  68. src += src_stride;
  69. d0 = vld1q_u8(dst);
  70. d1 = vld1q_u8(dst + dst_stride);
  71. d0 = vrhaddq_u8(s0, d0);
  72. d1 = vrhaddq_u8(s1, d1);
  73. vst1q_u8(dst, d0);
  74. dst += dst_stride;
  75. vst1q_u8(dst, d1);
  76. dst += dst_stride;
  77. h -= 2;
  78. } while (h > 0);
  79. } else if (w == 32) { // avg32
  80. uint8x16_t s0, s1, s2, s3, d0, d1, d2, d3;
  81. do {
  82. s0 = vld1q_u8(src);
  83. s1 = vld1q_u8(src + 16);
  84. src += src_stride;
  85. s2 = vld1q_u8(src);
  86. s3 = vld1q_u8(src + 16);
  87. src += src_stride;
  88. d0 = vld1q_u8(dst);
  89. d1 = vld1q_u8(dst + 16);
  90. d2 = vld1q_u8(dst + dst_stride);
  91. d3 = vld1q_u8(dst + dst_stride + 16);
  92. d0 = vrhaddq_u8(s0, d0);
  93. d1 = vrhaddq_u8(s1, d1);
  94. d2 = vrhaddq_u8(s2, d2);
  95. d3 = vrhaddq_u8(s3, d3);
  96. vst1q_u8(dst, d0);
  97. vst1q_u8(dst + 16, d1);
  98. dst += dst_stride;
  99. vst1q_u8(dst, d2);
  100. vst1q_u8(dst + 16, d3);
  101. dst += dst_stride;
  102. h -= 2;
  103. } while (h > 0);
  104. } else { // avg64
  105. uint8x16_t s0, s1, s2, s3, d0, d1, d2, d3;
  106. do {
  107. s0 = vld1q_u8(src);
  108. s1 = vld1q_u8(src + 16);
  109. s2 = vld1q_u8(src + 32);
  110. s3 = vld1q_u8(src + 48);
  111. src += src_stride;
  112. d0 = vld1q_u8(dst);
  113. d1 = vld1q_u8(dst + 16);
  114. d2 = vld1q_u8(dst + 32);
  115. d3 = vld1q_u8(dst + 48);
  116. d0 = vrhaddq_u8(s0, d0);
  117. d1 = vrhaddq_u8(s1, d1);
  118. d2 = vrhaddq_u8(s2, d2);
  119. d3 = vrhaddq_u8(s3, d3);
  120. vst1q_u8(dst, d0);
  121. vst1q_u8(dst + 16, d1);
  122. vst1q_u8(dst + 32, d2);
  123. vst1q_u8(dst + 48, d3);
  124. dst += dst_stride;
  125. } while (--h);
  126. }
  127. }