compare_neon.cc 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 HammingDistance_NEON(const uint8* src_a, const uint8* src_b, int count) {
  22. uint32 diff;
  23. asm volatile(
  24. "vmov.u16 q4, #0 \n" // accumulator
  25. "1: \n"
  26. "vld1.8 {q0, q1}, [%0]! \n"
  27. "vld1.8 {q2, q3}, [%1]! \n"
  28. "veor.32 q0, q0, q2 \n"
  29. "veor.32 q1, q1, q3 \n"
  30. "vcnt.i8 q0, q0 \n"
  31. "vcnt.i8 q1, q1 \n"
  32. "subs %2, %2, #32 \n"
  33. "vadd.u8 q0, q0, q1 \n" // 16 byte counts
  34. "vpadal.u8 q4, q0 \n" // 8 shorts
  35. "bgt 1b \n"
  36. "vpaddl.u16 q0, q4 \n" // 4 ints
  37. "vpadd.u32 d0, d0, d1 \n"
  38. "vpadd.u32 d0, d0, d0 \n"
  39. "vmov.32 %3, d0[0] \n"
  40. : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(diff)
  41. :
  42. : "cc", "q0", "q1", "q2", "q3", "q4");
  43. return diff;
  44. }
  45. uint32 SumSquareError_NEON(const uint8* src_a, const uint8* src_b, int count) {
  46. uint32 sse;
  47. asm volatile(
  48. "vmov.u8 q8, #0 \n"
  49. "vmov.u8 q10, #0 \n"
  50. "vmov.u8 q9, #0 \n"
  51. "vmov.u8 q11, #0 \n"
  52. "1: \n"
  53. "vld1.8 {q0}, [%0]! \n"
  54. "vld1.8 {q1}, [%1]! \n"
  55. "subs %2, %2, #16 \n"
  56. "vsubl.u8 q2, d0, d2 \n"
  57. "vsubl.u8 q3, d1, d3 \n"
  58. "vmlal.s16 q8, d4, d4 \n"
  59. "vmlal.s16 q9, d6, d6 \n"
  60. "vmlal.s16 q10, d5, d5 \n"
  61. "vmlal.s16 q11, d7, d7 \n"
  62. "bgt 1b \n"
  63. "vadd.u32 q8, q8, q9 \n"
  64. "vadd.u32 q10, q10, q11 \n"
  65. "vadd.u32 q11, q8, q10 \n"
  66. "vpaddl.u32 q1, q11 \n"
  67. "vadd.u64 d0, d2, d3 \n"
  68. "vmov.32 %3, d0[0] \n"
  69. : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(sse)
  70. :
  71. : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11");
  72. return sse;
  73. }
  74. #endif // defined(__ARM_NEON__) && !defined(__aarch64__)
  75. #ifdef __cplusplus
  76. } // extern "C"
  77. } // namespace libyuv
  78. #endif