2
0

compare_neon.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2012 The LibYuv 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 "libyuv/basic_types.h"
  11. #include "libyuv/compare_row.h"
  12. #include "libyuv/row.h"
  13. #ifdef __cplusplus
  14. namespace libyuv {
  15. extern "C" {
  16. #endif
  17. #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__) && \
  18. !defined(__aarch64__)
  19. // 256 bits at a time
  20. // uses short accumulator which restricts count to 131 KB
  21. uint32_t HammingDistance_NEON(const uint8_t* src_a,
  22. const uint8_t* src_b,
  23. int count) {
  24. uint32_t diff;
  25. asm volatile(
  26. "vmov.u16 q4, #0 \n" // accumulator
  27. "1: \n"
  28. "vld1.8 {q0, q1}, [%0]! \n"
  29. "vld1.8 {q2, q3}, [%1]! \n"
  30. "veor.32 q0, q0, q2 \n"
  31. "veor.32 q1, q1, q3 \n"
  32. "vcnt.i8 q0, q0 \n"
  33. "vcnt.i8 q1, q1 \n"
  34. "subs %2, %2, #32 \n"
  35. "vadd.u8 q0, q0, q1 \n" // 16 byte counts
  36. "vpadal.u8 q4, q0 \n" // 8 shorts
  37. "bgt 1b \n"
  38. "vpaddl.u16 q0, q4 \n" // 4 ints
  39. "vpadd.u32 d0, d0, d1 \n"
  40. "vpadd.u32 d0, d0, d0 \n"
  41. "vmov.32 %3, d0[0] \n"
  42. : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(diff)
  43. :
  44. : "cc", "q0", "q1", "q2", "q3", "q4");
  45. return diff;
  46. }
  47. uint32_t SumSquareError_NEON(const uint8_t* src_a,
  48. const uint8_t* src_b,
  49. int count) {
  50. uint32_t sse;
  51. asm volatile(
  52. "vmov.u8 q8, #0 \n"
  53. "vmov.u8 q10, #0 \n"
  54. "vmov.u8 q9, #0 \n"
  55. "vmov.u8 q11, #0 \n"
  56. "1: \n"
  57. "vld1.8 {q0}, [%0]! \n"
  58. "vld1.8 {q1}, [%1]! \n"
  59. "subs %2, %2, #16 \n"
  60. "vsubl.u8 q2, d0, d2 \n"
  61. "vsubl.u8 q3, d1, d3 \n"
  62. "vmlal.s16 q8, d4, d4 \n"
  63. "vmlal.s16 q9, d6, d6 \n"
  64. "vmlal.s16 q10, d5, d5 \n"
  65. "vmlal.s16 q11, d7, d7 \n"
  66. "bgt 1b \n"
  67. "vadd.u32 q8, q8, q9 \n"
  68. "vadd.u32 q10, q10, q11 \n"
  69. "vadd.u32 q11, q8, q10 \n"
  70. "vpaddl.u32 q1, q11 \n"
  71. "vadd.u64 d0, d2, d3 \n"
  72. "vmov.32 %3, d0[0] \n"
  73. : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(sse)
  74. :
  75. : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11");
  76. return sse;
  77. }
  78. #endif // defined(__ARM_NEON__) && !defined(__aarch64__)
  79. #ifdef __cplusplus
  80. } // extern "C"
  81. } // namespace libyuv
  82. #endif