compare_neon64.cc 3.5 KB

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