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