2
0

compare_neon64.cc 3.2 KB

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