/src/libvpx/vpx_dsp/sad.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2015 The WebM 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 <stdlib.h> |
12 | | |
13 | | #include "./vpx_config.h" |
14 | | #include "./vpx_dsp_rtcd.h" |
15 | | |
16 | | #include "vpx/vpx_integer.h" |
17 | | #include "vpx_ports/mem.h" |
18 | | |
19 | | /* Sum the difference between every corresponding element of the buffers. */ |
20 | | static INLINE unsigned int sad(const uint8_t *src_ptr, int src_stride, |
21 | | const uint8_t *ref_ptr, int ref_stride, |
22 | 20.0M | int width, int height) { |
23 | 20.0M | int y, x; |
24 | 20.0M | unsigned int sad = 0; |
25 | | |
26 | 60.0M | for (y = 0; y < height; y++) { |
27 | 253M | for (x = 0; x < width; x++) sad += abs(src_ptr[x] - ref_ptr[x]); |
28 | | |
29 | 40.0M | src_ptr += src_stride; |
30 | 40.0M | ref_ptr += ref_stride; |
31 | 40.0M | } |
32 | 20.0M | return sad; |
33 | 20.0M | } |
34 | | |
35 | | #if CONFIG_ENCODERS |
36 | | |
37 | | #define sadMxN(m, n) \ |
38 | | unsigned int vpx_sad##m##x##n##_c(const uint8_t *src_ptr, int src_stride, \ |
39 | 0 | const uint8_t *ref_ptr, int ref_stride) { \ |
40 | 0 | return sad(src_ptr, src_stride, ref_ptr, ref_stride, m, n); \ |
41 | 0 | } \ Unexecuted instantiation: vpx_sad64x64_c Unexecuted instantiation: vpx_sad32x32_c Unexecuted instantiation: vpx_sad16x16_c Unexecuted instantiation: vpx_sad64x32_c Unexecuted instantiation: vpx_sad32x64_c Unexecuted instantiation: vpx_sad32x16_c Unexecuted instantiation: vpx_sad16x32_c Unexecuted instantiation: vpx_sad16x8_c Unexecuted instantiation: vpx_sad8x16_c Unexecuted instantiation: vpx_sad8x8_c Unexecuted instantiation: vpx_sad8x4_c Unexecuted instantiation: vpx_sad4x8_c Unexecuted instantiation: vpx_sad4x4_c |
42 | | unsigned int vpx_sad##m##x##n##_avg_c( \ |
43 | | const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ |
44 | 0 | int ref_stride, const uint8_t *second_pred) { \ |
45 | 0 | DECLARE_ALIGNED(32, uint8_t, comp_pred[m * n]); \ |
46 | 0 | vpx_comp_avg_pred_c(comp_pred, second_pred, m, n, ref_ptr, ref_stride); \ |
47 | 0 | return sad(src_ptr, src_stride, comp_pred, m, m, n); \ |
48 | 0 | } \ Unexecuted instantiation: vpx_sad64x64_avg_c Unexecuted instantiation: vpx_sad32x32_avg_c Unexecuted instantiation: vpx_sad16x16_avg_c Unexecuted instantiation: vpx_sad64x32_avg_c Unexecuted instantiation: vpx_sad32x64_avg_c Unexecuted instantiation: vpx_sad32x16_avg_c Unexecuted instantiation: vpx_sad16x32_avg_c Unexecuted instantiation: vpx_sad16x8_avg_c Unexecuted instantiation: vpx_sad8x16_avg_c Unexecuted instantiation: vpx_sad8x8_avg_c Unexecuted instantiation: vpx_sad8x4_avg_c Unexecuted instantiation: vpx_sad4x8_avg_c Unexecuted instantiation: vpx_sad4x4_avg_c |
49 | | unsigned int vpx_sad_skip_##m##x##n##_c( \ |
50 | | const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ |
51 | 20.0M | int ref_stride) { \ |
52 | 20.0M | return 2 * sad(src_ptr, 2 * src_stride, ref_ptr, 2 * ref_stride, (m), \ |
53 | 20.0M | (n / 2)); \ |
54 | 20.0M | } Unexecuted instantiation: vpx_sad_skip_64x64_c Unexecuted instantiation: vpx_sad_skip_32x32_c Unexecuted instantiation: vpx_sad_skip_16x16_c Unexecuted instantiation: vpx_sad_skip_64x32_c Unexecuted instantiation: vpx_sad_skip_32x64_c Unexecuted instantiation: vpx_sad_skip_32x16_c Unexecuted instantiation: vpx_sad_skip_16x32_c Unexecuted instantiation: vpx_sad_skip_16x8_c Unexecuted instantiation: vpx_sad_skip_8x16_c Unexecuted instantiation: vpx_sad_skip_8x8_c Line | Count | Source | 51 | 6.68M | int ref_stride) { \ | 52 | 6.68M | return 2 * sad(src_ptr, 2 * src_stride, ref_ptr, 2 * ref_stride, (m), \ | 53 | 6.68M | (n / 2)); \ | 54 | 6.68M | } |
Unexecuted instantiation: vpx_sad_skip_4x8_c Line | Count | Source | 51 | 13.3M | int ref_stride) { \ | 52 | 13.3M | return 2 * sad(src_ptr, 2 * src_stride, ref_ptr, 2 * ref_stride, (m), \ | 53 | 13.3M | (n / 2)); \ | 54 | 13.3M | } |
|
55 | | |
56 | | // Compare |src_ptr| to 4 distinct references in |ref_array[4]| |
57 | | #define sadMxNx4D(m, n) \ |
58 | | void vpx_sad##m##x##n##x4d_c(const uint8_t *src_ptr, int src_stride, \ |
59 | | const uint8_t *const ref_array[4], \ |
60 | 0 | int ref_stride, uint32_t sad_array[4]) { \ |
61 | 0 | int i; \ |
62 | 0 | for (i = 0; i < 4; ++i) \ |
63 | 0 | sad_array[i] = \ |
64 | 0 | vpx_sad##m##x##n##_c(src_ptr, src_stride, ref_array[i], ref_stride); \ |
65 | 0 | } \ Unexecuted instantiation: vpx_sad64x64x4d_c Unexecuted instantiation: vpx_sad32x32x4d_c Unexecuted instantiation: vpx_sad16x16x4d_c Unexecuted instantiation: vpx_sad64x32x4d_c Unexecuted instantiation: vpx_sad32x64x4d_c Unexecuted instantiation: vpx_sad32x16x4d_c Unexecuted instantiation: vpx_sad16x32x4d_c Unexecuted instantiation: vpx_sad16x8x4d_c Unexecuted instantiation: vpx_sad8x16x4d_c Unexecuted instantiation: vpx_sad8x8x4d_c Unexecuted instantiation: vpx_sad8x4x4d_c Unexecuted instantiation: vpx_sad4x8x4d_c Unexecuted instantiation: vpx_sad4x4x4d_c |
66 | | void vpx_sad_skip_##m##x##n##x4d_c(const uint8_t *src_ptr, int src_stride, \ |
67 | | const uint8_t *const ref_array[4], \ |
68 | 0 | int ref_stride, uint32_t sad_array[4]) { \ |
69 | 0 | int i; \ |
70 | 0 | for (i = 0; i < 4; ++i) { \ |
71 | 0 | sad_array[i] = 2 * sad(src_ptr, 2 * src_stride, ref_array[i], \ |
72 | 0 | 2 * ref_stride, (m), (n / 2)); \ |
73 | 0 | } \ |
74 | 0 | } Unexecuted instantiation: vpx_sad_skip_64x64x4d_c Unexecuted instantiation: vpx_sad_skip_32x32x4d_c Unexecuted instantiation: vpx_sad_skip_16x16x4d_c Unexecuted instantiation: vpx_sad_skip_64x32x4d_c Unexecuted instantiation: vpx_sad_skip_32x64x4d_c Unexecuted instantiation: vpx_sad_skip_32x16x4d_c Unexecuted instantiation: vpx_sad_skip_16x32x4d_c Unexecuted instantiation: vpx_sad_skip_16x8x4d_c Unexecuted instantiation: vpx_sad_skip_8x16x4d_c Unexecuted instantiation: vpx_sad_skip_8x8x4d_c Unexecuted instantiation: vpx_sad_skip_8x4x4d_c Unexecuted instantiation: vpx_sad_skip_4x8x4d_c Unexecuted instantiation: vpx_sad_skip_4x4x4d_c |
75 | | #else // !CONFIG_ENCODERS |
76 | | #define sadMxN(m, n) \ |
77 | | unsigned int vpx_sad##m##x##n##_c(const uint8_t *src_ptr, int src_stride, \ |
78 | | const uint8_t *ref_ptr, int ref_stride) { \ |
79 | | return sad(src_ptr, src_stride, ref_ptr, ref_stride, m, n); \ |
80 | | } |
81 | | |
82 | | #define sadMxNx4D(m, n) |
83 | | #endif // CONFIG_ENCODERS |
84 | | |
85 | | /* clang-format off */ |
86 | | // 64x64 |
87 | | sadMxN(64, 64) |
88 | | sadMxNx4D(64, 64) |
89 | | |
90 | | // 32x32 |
91 | | sadMxN(32, 32) |
92 | | sadMxNx4D(32, 32) |
93 | | |
94 | | // 16x16 |
95 | | sadMxN(16, 16) |
96 | | sadMxNx4D(16, 16) |
97 | | |
98 | | #if CONFIG_ENCODERS |
99 | | // 64x32 |
100 | | sadMxN(64, 32) |
101 | | sadMxNx4D(64, 32) |
102 | | |
103 | | // 32x64 |
104 | | sadMxN(32, 64) |
105 | | sadMxNx4D(32, 64) |
106 | | |
107 | | // 32x16 |
108 | | sadMxN(32, 16) |
109 | | sadMxNx4D(32, 16) |
110 | | |
111 | | // 16x32 |
112 | | sadMxN(16, 32) |
113 | | sadMxNx4D(16, 32) |
114 | | |
115 | | // 16x8 |
116 | | sadMxN(16, 8) |
117 | | sadMxNx4D(16, 8) |
118 | | |
119 | | // 8x16 |
120 | | sadMxN(8, 16) |
121 | | sadMxNx4D(8, 16) |
122 | | |
123 | | // 8x8 |
124 | | sadMxN(8, 8) |
125 | | sadMxNx4D(8, 8) |
126 | | |
127 | | // 8x4 |
128 | | sadMxN(8, 4) |
129 | | sadMxNx4D(8, 4) |
130 | | |
131 | | // 4x8 |
132 | | sadMxN(4, 8) |
133 | | sadMxNx4D(4, 8) |
134 | | |
135 | | // 4x4 |
136 | | sadMxN(4, 4) |
137 | | sadMxNx4D(4, 4) |
138 | | #endif // CONFIG_ENCODERS |
139 | | /* clang-format on */ |
140 | | |
141 | | #if CONFIG_VP9_HIGHBITDEPTH && CONFIG_ENCODERS |
142 | | static INLINE |
143 | | unsigned int highbd_sad(const uint8_t *src8_ptr, int src_stride, |
144 | | const uint8_t *ref8_ptr, int ref_stride, int width, |
145 | 0 | int height) { |
146 | 0 | int y, x; |
147 | 0 | unsigned int sad = 0; |
148 | 0 | const uint16_t *src = CONVERT_TO_SHORTPTR(src8_ptr); |
149 | 0 | const uint16_t *ref_ptr = CONVERT_TO_SHORTPTR(ref8_ptr); |
150 | 0 | for (y = 0; y < height; y++) { |
151 | 0 | for (x = 0; x < width; x++) sad += abs(src[x] - ref_ptr[x]); |
152 | |
|
153 | 0 | src += src_stride; |
154 | 0 | ref_ptr += ref_stride; |
155 | 0 | } |
156 | 0 | return sad; |
157 | 0 | } |
158 | | |
159 | | static INLINE unsigned int highbd_sadb(const uint8_t *src8_ptr, int src_stride, |
160 | | const uint16_t *ref_ptr, int ref_stride, |
161 | 0 | int width, int height) { |
162 | 0 | int y, x; |
163 | 0 | unsigned int sad = 0; |
164 | 0 | const uint16_t *src = CONVERT_TO_SHORTPTR(src8_ptr); |
165 | 0 | for (y = 0; y < height; y++) { |
166 | 0 | for (x = 0; x < width; x++) sad += abs(src[x] - ref_ptr[x]); |
167 | |
|
168 | 0 | src += src_stride; |
169 | 0 | ref_ptr += ref_stride; |
170 | 0 | } |
171 | 0 | return sad; |
172 | 0 | } |
173 | | |
174 | | #define highbd_sadMxN(m, n) \ |
175 | | unsigned int vpx_highbd_sad##m##x##n##_c( \ |
176 | | const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ |
177 | 0 | int ref_stride) { \ |
178 | 0 | return highbd_sad(src_ptr, src_stride, ref_ptr, ref_stride, m, n); \ |
179 | 0 | } \ Unexecuted instantiation: vpx_highbd_sad64x64_c Unexecuted instantiation: vpx_highbd_sad64x32_c Unexecuted instantiation: vpx_highbd_sad32x64_c Unexecuted instantiation: vpx_highbd_sad32x32_c Unexecuted instantiation: vpx_highbd_sad32x16_c Unexecuted instantiation: vpx_highbd_sad16x32_c Unexecuted instantiation: vpx_highbd_sad16x16_c Unexecuted instantiation: vpx_highbd_sad16x8_c Unexecuted instantiation: vpx_highbd_sad8x16_c Unexecuted instantiation: vpx_highbd_sad8x8_c Unexecuted instantiation: vpx_highbd_sad8x4_c Unexecuted instantiation: vpx_highbd_sad4x8_c Unexecuted instantiation: vpx_highbd_sad4x4_c |
180 | | unsigned int vpx_highbd_sad##m##x##n##_avg_c( \ |
181 | | const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ |
182 | 0 | int ref_stride, const uint8_t *second_pred) { \ |
183 | 0 | DECLARE_ALIGNED(16, uint16_t, comp_pred[m * n]); \ |
184 | 0 | vpx_highbd_comp_avg_pred_c(comp_pred, CONVERT_TO_SHORTPTR(second_pred), m, \ |
185 | 0 | n, CONVERT_TO_SHORTPTR(ref_ptr), ref_stride); \ |
186 | 0 | return highbd_sadb(src_ptr, src_stride, comp_pred, m, m, n); \ |
187 | 0 | } \ Unexecuted instantiation: vpx_highbd_sad64x64_avg_c Unexecuted instantiation: vpx_highbd_sad64x32_avg_c Unexecuted instantiation: vpx_highbd_sad32x64_avg_c Unexecuted instantiation: vpx_highbd_sad32x32_avg_c Unexecuted instantiation: vpx_highbd_sad32x16_avg_c Unexecuted instantiation: vpx_highbd_sad16x32_avg_c Unexecuted instantiation: vpx_highbd_sad16x16_avg_c Unexecuted instantiation: vpx_highbd_sad16x8_avg_c Unexecuted instantiation: vpx_highbd_sad8x16_avg_c Unexecuted instantiation: vpx_highbd_sad8x8_avg_c Unexecuted instantiation: vpx_highbd_sad8x4_avg_c Unexecuted instantiation: vpx_highbd_sad4x8_avg_c Unexecuted instantiation: vpx_highbd_sad4x4_avg_c |
188 | | unsigned int vpx_highbd_sad_skip_##m##x##n##_c( \ |
189 | | const uint8_t *src, int src_stride, const uint8_t *ref, \ |
190 | 0 | int ref_stride) { \ |
191 | 0 | return 2 * \ |
192 | 0 | highbd_sad(src, 2 * src_stride, ref, 2 * ref_stride, (m), (n / 2)); \ |
193 | 0 | } Unexecuted instantiation: vpx_highbd_sad_skip_64x64_c Unexecuted instantiation: vpx_highbd_sad_skip_64x32_c Unexecuted instantiation: vpx_highbd_sad_skip_32x64_c Unexecuted instantiation: vpx_highbd_sad_skip_32x32_c Unexecuted instantiation: vpx_highbd_sad_skip_32x16_c Unexecuted instantiation: vpx_highbd_sad_skip_16x32_c Unexecuted instantiation: vpx_highbd_sad_skip_16x16_c Unexecuted instantiation: vpx_highbd_sad_skip_16x8_c Unexecuted instantiation: vpx_highbd_sad_skip_8x16_c Unexecuted instantiation: vpx_highbd_sad_skip_8x8_c Unexecuted instantiation: vpx_highbd_sad_skip_8x4_c Unexecuted instantiation: vpx_highbd_sad_skip_4x8_c Unexecuted instantiation: vpx_highbd_sad_skip_4x4_c |
194 | | |
195 | | #define highbd_sadMxNx4D(m, n) \ |
196 | | void vpx_highbd_sad##m##x##n##x4d_c(const uint8_t *src_ptr, int src_stride, \ |
197 | | const uint8_t *const ref_array[4], \ |
198 | 0 | int ref_stride, uint32_t sad_array[4]) { \ |
199 | 0 | int i; \ |
200 | 0 | for (i = 0; i < 4; ++i) { \ |
201 | 0 | sad_array[i] = vpx_highbd_sad##m##x##n##_c(src_ptr, src_stride, \ |
202 | 0 | ref_array[i], ref_stride); \ |
203 | 0 | } \ |
204 | 0 | } \ Unexecuted instantiation: vpx_highbd_sad64x64x4d_c Unexecuted instantiation: vpx_highbd_sad64x32x4d_c Unexecuted instantiation: vpx_highbd_sad32x64x4d_c Unexecuted instantiation: vpx_highbd_sad32x32x4d_c Unexecuted instantiation: vpx_highbd_sad32x16x4d_c Unexecuted instantiation: vpx_highbd_sad16x32x4d_c Unexecuted instantiation: vpx_highbd_sad16x16x4d_c Unexecuted instantiation: vpx_highbd_sad16x8x4d_c Unexecuted instantiation: vpx_highbd_sad8x16x4d_c Unexecuted instantiation: vpx_highbd_sad8x8x4d_c Unexecuted instantiation: vpx_highbd_sad8x4x4d_c Unexecuted instantiation: vpx_highbd_sad4x8x4d_c Unexecuted instantiation: vpx_highbd_sad4x4x4d_c |
205 | | void vpx_highbd_sad_skip_##m##x##n##x4d_c( \ |
206 | | const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \ |
207 | 0 | int ref_stride, uint32_t sad_array[4]) { \ |
208 | 0 | int i; \ |
209 | 0 | for (i = 0; i < 4; ++i) { \ |
210 | 0 | sad_array[i] = vpx_highbd_sad_skip_##m##x##n##_c( \ |
211 | 0 | src, src_stride, ref_array[i], ref_stride); \ |
212 | 0 | } \ |
213 | 0 | } Unexecuted instantiation: vpx_highbd_sad_skip_64x64x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_64x32x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_32x64x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_32x32x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_32x16x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_16x32x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_16x16x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_16x8x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_8x16x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_8x8x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_8x4x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_4x8x4d_c Unexecuted instantiation: vpx_highbd_sad_skip_4x4x4d_c |
214 | | |
215 | | /* clang-format off */ |
216 | | // 64x64 |
217 | | highbd_sadMxN(64, 64) |
218 | | highbd_sadMxNx4D(64, 64) |
219 | | |
220 | | // 64x32 |
221 | | highbd_sadMxN(64, 32) |
222 | | highbd_sadMxNx4D(64, 32) |
223 | | |
224 | | // 32x64 |
225 | | highbd_sadMxN(32, 64) |
226 | | highbd_sadMxNx4D(32, 64) |
227 | | |
228 | | // 32x32 |
229 | | highbd_sadMxN(32, 32) |
230 | | highbd_sadMxNx4D(32, 32) |
231 | | |
232 | | // 32x16 |
233 | | highbd_sadMxN(32, 16) |
234 | | highbd_sadMxNx4D(32, 16) |
235 | | |
236 | | // 16x32 |
237 | | highbd_sadMxN(16, 32) |
238 | | highbd_sadMxNx4D(16, 32) |
239 | | |
240 | | // 16x16 |
241 | | highbd_sadMxN(16, 16) |
242 | | highbd_sadMxNx4D(16, 16) |
243 | | |
244 | | // 16x8 |
245 | | highbd_sadMxN(16, 8) |
246 | | highbd_sadMxNx4D(16, 8) |
247 | | |
248 | | // 8x16 |
249 | | highbd_sadMxN(8, 16) |
250 | | highbd_sadMxNx4D(8, 16) |
251 | | |
252 | | // 8x8 |
253 | | highbd_sadMxN(8, 8) |
254 | | highbd_sadMxNx4D(8, 8) |
255 | | |
256 | | // 8x4 |
257 | | highbd_sadMxN(8, 4) |
258 | | highbd_sadMxNx4D(8, 4) |
259 | | |
260 | | // 4x8 |
261 | | highbd_sadMxN(4, 8) |
262 | | highbd_sadMxNx4D(4, 8) |
263 | | |
264 | | // 4x4 |
265 | | highbd_sadMxN(4, 4) |
266 | | highbd_sadMxNx4D(4, 4) |
267 | | /* clang-format on */ |
268 | | |
269 | | #endif // CONFIG_VP9_HIGHBITDEPTH && CONFIG_ENCODERS |