sum_squares_neon.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2018 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 <assert.h>
  12. #include "./vpx_dsp_rtcd.h"
  13. uint64_t vpx_sum_squares_2d_i16_neon(const int16_t *src, int stride, int size) {
  14. uint64x1_t s2;
  15. if (size == 4) {
  16. int16x4_t s[4];
  17. int32x4_t s0;
  18. uint32x2_t s1;
  19. s[0] = vld1_s16(src + 0 * stride);
  20. s[1] = vld1_s16(src + 1 * stride);
  21. s[2] = vld1_s16(src + 2 * stride);
  22. s[3] = vld1_s16(src + 3 * stride);
  23. s0 = vmull_s16(s[0], s[0]);
  24. s0 = vmlal_s16(s0, s[1], s[1]);
  25. s0 = vmlal_s16(s0, s[2], s[2]);
  26. s0 = vmlal_s16(s0, s[3], s[3]);
  27. s1 = vpadd_u32(vget_low_u32(vreinterpretq_u32_s32(s0)),
  28. vget_high_u32(vreinterpretq_u32_s32(s0)));
  29. s2 = vpaddl_u32(s1);
  30. } else {
  31. int r = size;
  32. uint64x2_t s1 = vdupq_n_u64(0);
  33. do {
  34. int c = size;
  35. int32x4_t s0 = vdupq_n_s32(0);
  36. const int16_t *src_t = src;
  37. do {
  38. int16x8_t s[8];
  39. s[0] = vld1q_s16(src_t + 0 * stride);
  40. s[1] = vld1q_s16(src_t + 1 * stride);
  41. s[2] = vld1q_s16(src_t + 2 * stride);
  42. s[3] = vld1q_s16(src_t + 3 * stride);
  43. s[4] = vld1q_s16(src_t + 4 * stride);
  44. s[5] = vld1q_s16(src_t + 5 * stride);
  45. s[6] = vld1q_s16(src_t + 6 * stride);
  46. s[7] = vld1q_s16(src_t + 7 * stride);
  47. s0 = vmlal_s16(s0, vget_low_s16(s[0]), vget_low_s16(s[0]));
  48. s0 = vmlal_s16(s0, vget_low_s16(s[1]), vget_low_s16(s[1]));
  49. s0 = vmlal_s16(s0, vget_low_s16(s[2]), vget_low_s16(s[2]));
  50. s0 = vmlal_s16(s0, vget_low_s16(s[3]), vget_low_s16(s[3]));
  51. s0 = vmlal_s16(s0, vget_low_s16(s[4]), vget_low_s16(s[4]));
  52. s0 = vmlal_s16(s0, vget_low_s16(s[5]), vget_low_s16(s[5]));
  53. s0 = vmlal_s16(s0, vget_low_s16(s[6]), vget_low_s16(s[6]));
  54. s0 = vmlal_s16(s0, vget_low_s16(s[7]), vget_low_s16(s[7]));
  55. s0 = vmlal_s16(s0, vget_high_s16(s[0]), vget_high_s16(s[0]));
  56. s0 = vmlal_s16(s0, vget_high_s16(s[1]), vget_high_s16(s[1]));
  57. s0 = vmlal_s16(s0, vget_high_s16(s[2]), vget_high_s16(s[2]));
  58. s0 = vmlal_s16(s0, vget_high_s16(s[3]), vget_high_s16(s[3]));
  59. s0 = vmlal_s16(s0, vget_high_s16(s[4]), vget_high_s16(s[4]));
  60. s0 = vmlal_s16(s0, vget_high_s16(s[5]), vget_high_s16(s[5]));
  61. s0 = vmlal_s16(s0, vget_high_s16(s[6]), vget_high_s16(s[6]));
  62. s0 = vmlal_s16(s0, vget_high_s16(s[7]), vget_high_s16(s[7]));
  63. src_t += 8;
  64. c -= 8;
  65. } while (c);
  66. s1 = vaddw_u32(s1, vget_low_u32(vreinterpretq_u32_s32(s0)));
  67. s1 = vaddw_u32(s1, vget_high_u32(vreinterpretq_u32_s32(s0)));
  68. src += 8 * stride;
  69. r -= 8;
  70. } while (r);
  71. s2 = vadd_u64(vget_low_u64(s1), vget_high_u64(s1));
  72. }
  73. return vget_lane_u64(s2, 0);
  74. }