• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "libyuv/basic_types.h"
12 
13 #include "libyuv/compare_row.h"
14 #include "libyuv/row.h"
15 
16 #ifdef __cplusplus
17 namespace libyuv {
18 extern "C" {
19 #endif
20 
21 #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
22 
23 // 256 bits at a time
24 // uses short accumulator which restricts count to 131 KB
HammingDistance_NEON(const uint8_t * src_a,const uint8_t * src_b,int count)25 uint32_t HammingDistance_NEON(const uint8_t* src_a,
26                               const uint8_t* src_b,
27                               int count) {
28   uint32_t diff;
29   asm volatile(
30       "movi       v4.8h, #0                      \n"
31 
32       "1:                                        \n"
33       "ld1        {v0.16b, v1.16b}, [%0], #32    \n"
34       "ld1        {v2.16b, v3.16b}, [%1], #32    \n"
35       "eor        v0.16b, v0.16b, v2.16b         \n"
36       "eor        v1.16b, v1.16b, v3.16b         \n"
37       "cnt        v0.16b, v0.16b                 \n"
38       "cnt        v1.16b, v1.16b                 \n"
39       "subs       %w2, %w2, #32                  \n"
40       "add        v0.16b, v0.16b, v1.16b         \n"
41       "uadalp     v4.8h, v0.16b                  \n"
42       "b.gt       1b                             \n"
43 
44       "uaddlv     s4, v4.8h                      \n"
45       "fmov       %w3, s4                        \n"
46       : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(diff)
47       :
48       : "cc", "v0", "v1", "v2", "v3", "v4");
49   return diff;
50 }
51 
SumSquareError_NEON(const uint8_t * src_a,const uint8_t * src_b,int count)52 uint32_t SumSquareError_NEON(const uint8_t* src_a,
53                              const uint8_t* src_b,
54                              int count) {
55   uint32_t sse;
56   asm volatile(
57       "eor        v16.16b, v16.16b, v16.16b      \n"
58       "eor        v18.16b, v18.16b, v18.16b      \n"
59       "eor        v17.16b, v17.16b, v17.16b      \n"
60       "eor        v19.16b, v19.16b, v19.16b      \n"
61 
62       "1:                                        \n"
63       "ld1        {v0.16b}, [%0], #16            \n"
64       "ld1        {v1.16b}, [%1], #16            \n"
65       "subs       %w2, %w2, #16                  \n"
66       "usubl      v2.8h, v0.8b, v1.8b            \n"
67       "usubl2     v3.8h, v0.16b, v1.16b          \n"
68       "smlal      v16.4s, v2.4h, v2.4h           \n"
69       "smlal      v17.4s, v3.4h, v3.4h           \n"
70       "smlal2     v18.4s, v2.8h, v2.8h           \n"
71       "smlal2     v19.4s, v3.8h, v3.8h           \n"
72       "b.gt       1b                             \n"
73 
74       "add        v16.4s, v16.4s, v17.4s         \n"
75       "add        v18.4s, v18.4s, v19.4s         \n"
76       "add        v19.4s, v16.4s, v18.4s         \n"
77       "addv       s0, v19.4s                     \n"
78       "fmov       %w3, s0                        \n"
79       : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(sse)
80       :
81       : "cc", "v0", "v1", "v2", "v3", "v16", "v17", "v18", "v19");
82   return sse;
83 }
84 
85 #endif  // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
86 
87 #ifdef __cplusplus
88 }  // extern "C"
89 }  // namespace libyuv
90 #endif
91