compare_neon64.cc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(__aarch64__)
  18. // 256 bits at a time
  19. // uses short accumulator which restricts count to 131 KB
  20. uint32 HammingDistance_NEON(const uint8* src_a, const uint8* src_b, int count) {
  21. uint32 diff;
  22. asm volatile(
  23. "movi v4.8h, #0 \n"
  24. "1: \n"
  25. "ld1 {v0.16b, v1.16b}, [%0], #32 \n"
  26. "ld1 {v2.16b, v3.16b}, [%1], #32 \n"
  27. "eor v0.16b, v0.16b, v2.16b \n"
  28. "eor v1.16b, v1.16b, v3.16b \n"
  29. "cnt v0.16b, v0.16b \n"
  30. "cnt v1.16b, v1.16b \n"
  31. "subs %w2, %w2, #32 \n"
  32. "add v0.16b, v0.16b, v1.16b \n"
  33. "uadalp v4.8h, v0.16b \n"
  34. "b.gt 1b \n"
  35. "uaddlv s4, v4.8h \n"
  36. "fmov %w3, s4 \n"
  37. : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(diff)
  38. :
  39. : "cc", "v0", "v1", "v2", "v3", "v4");
  40. return diff;
  41. }
  42. uint32 SumSquareError_NEON(const uint8* src_a, const uint8* src_b, int count) {
  43. uint32 sse;
  44. asm volatile(
  45. "eor v16.16b, v16.16b, v16.16b \n"
  46. "eor v18.16b, v18.16b, v18.16b \n"
  47. "eor v17.16b, v17.16b, v17.16b \n"
  48. "eor v19.16b, v19.16b, v19.16b \n"
  49. "1: \n"
  50. "ld1 {v0.16b}, [%0], #16 \n"
  51. "ld1 {v1.16b}, [%1], #16 \n"
  52. "subs %w2, %w2, #16 \n"
  53. "usubl v2.8h, v0.8b, v1.8b \n"
  54. "usubl2 v3.8h, v0.16b, v1.16b \n"
  55. "smlal v16.4s, v2.4h, v2.4h \n"
  56. "smlal v17.4s, v3.4h, v3.4h \n"
  57. "smlal2 v18.4s, v2.8h, v2.8h \n"
  58. "smlal2 v19.4s, v3.8h, v3.8h \n"
  59. "b.gt 1b \n"
  60. "add v16.4s, v16.4s, v17.4s \n"
  61. "add v18.4s, v18.4s, v19.4s \n"
  62. "add v19.4s, v16.4s, v18.4s \n"
  63. "addv s0, v19.4s \n"
  64. "fmov %w3, s0 \n"
  65. : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(sse)
  66. :
  67. : "cc", "v0", "v1", "v2", "v3", "v16", "v17", "v18", "v19");
  68. return sse;
  69. }
  70. #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
  71. #ifdef __cplusplus
  72. } // extern "C"
  73. } // namespace libyuv
  74. #endif