blob: 6b8ca669bebfce768bb3b07c93a31d7d5ab4aece [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include <stdlib.h>
13
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "./aom_config.h"
15#include "./aom_dsp_rtcd.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070016
Yaowu Xuf883b422016-08-30 14:01:10 -070017#include "aom/aom_integer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070018#include "aom_ports/mem.h"
David Barkerc155e012017-05-11 13:54:54 +010019#include "aom_dsp/blend.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070020
21/* Sum the difference between every corresponding element of the buffers. */
22static INLINE unsigned int sad(const uint8_t *a, int a_stride, const uint8_t *b,
23 int b_stride, int width, int height) {
24 int y, x;
25 unsigned int sad = 0;
26
27 for (y = 0; y < height; y++) {
28 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
29
30 a += a_stride;
31 b += b_stride;
32 }
33 return sad;
34}
35
36#define sadMxN(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -070037 unsigned int aom_sad##m##x##n##_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -070038 const uint8_t *ref, int ref_stride) { \
39 return sad(src, src_stride, ref, ref_stride, m, n); \
40 } \
Yaowu Xuf883b422016-08-30 14:01:10 -070041 unsigned int aom_sad##m##x##n##_avg_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -070042 const uint8_t *ref, int ref_stride, \
43 const uint8_t *second_pred) { \
44 uint8_t comp_pred[m * n]; \
Yaowu Xuf883b422016-08-30 14:01:10 -070045 aom_comp_avg_pred_c(comp_pred, second_pred, m, n, ref, ref_stride); \
Yaowu Xuc27fc142016-08-22 16:08:15 -070046 return sad(src, src_stride, comp_pred, m, m, n); \
47 }
48
49// depending on call sites, pass **ref_array to avoid & in subsequent call and
50// de-dup with 4D below.
51#define sadMxNxK(m, n, k) \
Yaowu Xuf883b422016-08-30 14:01:10 -070052 void aom_sad##m##x##n##x##k##_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -070053 const uint8_t *ref_array, int ref_stride, \
54 uint32_t *sad_array) { \
55 int i; \
56 for (i = 0; i < k; ++i) \
57 sad_array[i] = \
Yaowu Xuf883b422016-08-30 14:01:10 -070058 aom_sad##m##x##n##_c(src, src_stride, &ref_array[i], ref_stride); \
Yaowu Xuc27fc142016-08-22 16:08:15 -070059 }
60
61// This appears to be equivalent to the above when k == 4 and refs is const
62#define sadMxNx4D(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -070063 void aom_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -070064 const uint8_t *const ref_array[], \
65 int ref_stride, uint32_t *sad_array) { \
66 int i; \
67 for (i = 0; i < 4; ++i) \
68 sad_array[i] = \
Yaowu Xuf883b422016-08-30 14:01:10 -070069 aom_sad##m##x##n##_c(src, src_stride, ref_array[i], ref_stride); \
Yaowu Xuc27fc142016-08-22 16:08:15 -070070 }
71
72/* clang-format off */
Yaowu Xuf883b422016-08-30 14:01:10 -070073#if CONFIG_AV1 && CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -070074// 128x128
75sadMxN(128, 128)
76sadMxNxK(128, 128, 3)
77sadMxNxK(128, 128, 8)
78sadMxNx4D(128, 128)
79
80// 128x64
81sadMxN(128, 64)
82sadMxNx4D(128, 64)
83
84// 64x128
85sadMxN(64, 128)
86sadMxNx4D(64, 128)
Yaowu Xuf883b422016-08-30 14:01:10 -070087#endif // CONFIG_AV1 && CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -070088
89// 64x64
90sadMxN(64, 64)
91sadMxNxK(64, 64, 3)
92sadMxNxK(64, 64, 8)
93sadMxNx4D(64, 64)
94
95// 64x32
96sadMxN(64, 32)
97sadMxNx4D(64, 32)
98
99// 32x64
100sadMxN(32, 64)
101sadMxNx4D(32, 64)
102
103// 32x32
104sadMxN(32, 32)
105sadMxNxK(32, 32, 3)
106sadMxNxK(32, 32, 8)
107sadMxNx4D(32, 32)
108
109// 32x16
110sadMxN(32, 16)
111sadMxNx4D(32, 16)
112
113// 16x32
114sadMxN(16, 32)
115sadMxNx4D(16, 32)
116
117// 16x16
118sadMxN(16, 16)
119sadMxNxK(16, 16, 3)
120sadMxNxK(16, 16, 8)
121sadMxNx4D(16, 16)
122
123// 16x8
124sadMxN(16, 8)
125sadMxNxK(16, 8, 3)
126sadMxNxK(16, 8, 8)
127sadMxNx4D(16, 8)
128
129// 8x16
130sadMxN(8, 16)
131sadMxNxK(8, 16, 3)
132sadMxNxK(8, 16, 8)
133sadMxNx4D(8, 16)
134
135// 8x8
136sadMxN(8, 8)
137sadMxNxK(8, 8, 3)
138sadMxNxK(8, 8, 8)
139sadMxNx4D(8, 8)
140
141// 8x4
142sadMxN(8, 4)
143sadMxNxK(8, 4, 8)
144sadMxNx4D(8, 4)
145
146// 4x8
147sadMxN(4, 8)
148sadMxNxK(4, 8, 8)
149sadMxNx4D(4, 8)
150
151// 4x4
152sadMxN(4, 4)
153sadMxNxK(4, 4, 3)
154sadMxNxK(4, 4, 8)
155sadMxNx4D(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100156
157#if CONFIG_AV1 && CONFIG_EXT_PARTITION_TYPES
158sadMxN(4, 16)
159sadMxNx4D(4, 16)
160sadMxN(16, 4)
161sadMxNx4D(16, 4)
162sadMxN(8, 32)
163sadMxNx4D(8, 32)
164sadMxN(32, 8)
165sadMxNx4D(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100166sadMxN(16, 64)
167sadMxNx4D(16, 64)
168sadMxN(64, 16)
169sadMxNx4D(64, 16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100170sadMxN(32, 128)
171sadMxNx4D(32, 128)
172sadMxN(128, 32)
173sadMxNx4D(128, 32)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100174#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700175/* clang-format on */
176
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200177#if CONFIG_HIGHBITDEPTH
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100178 static INLINE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700179 unsigned int highbd_sad(const uint8_t *a8, int a_stride, const uint8_t *b8,
180 int b_stride, int width, int height) {
181 int y, x;
182 unsigned int sad = 0;
183 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
184 const uint16_t *b = CONVERT_TO_SHORTPTR(b8);
185 for (y = 0; y < height; y++) {
186 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
187
188 a += a_stride;
189 b += b_stride;
190 }
191 return sad;
192}
193
194static INLINE unsigned int highbd_sadb(const uint8_t *a8, int a_stride,
195 const uint16_t *b, int b_stride,
196 int width, int height) {
197 int y, x;
198 unsigned int sad = 0;
199 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
200 for (y = 0; y < height; y++) {
201 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
202
203 a += a_stride;
204 b += b_stride;
205 }
206 return sad;
207}
208
209#define highbd_sadMxN(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -0700210 unsigned int aom_highbd_sad##m##x##n##_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700211 const uint8_t *ref, \
212 int ref_stride) { \
213 return highbd_sad(src, src_stride, ref, ref_stride, m, n); \
214 } \
Yaowu Xuf883b422016-08-30 14:01:10 -0700215 unsigned int aom_highbd_sad##m##x##n##_avg_c( \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700216 const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
217 const uint8_t *second_pred) { \
218 uint16_t comp_pred[m * n]; \
Yaowu Xuf883b422016-08-30 14:01:10 -0700219 aom_highbd_comp_avg_pred_c(comp_pred, second_pred, m, n, ref, ref_stride); \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700220 return highbd_sadb(src, src_stride, comp_pred, m, m, n); \
221 }
222
223#define highbd_sadMxNxK(m, n, k) \
Yaowu Xuf883b422016-08-30 14:01:10 -0700224 void aom_highbd_sad##m##x##n##x##k##_c( \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700225 const uint8_t *src, int src_stride, const uint8_t *ref_array, \
226 int ref_stride, uint32_t *sad_array) { \
227 int i; \
228 for (i = 0; i < k; ++i) { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700229 sad_array[i] = aom_highbd_sad##m##x##n##_c(src, src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700230 &ref_array[i], ref_stride); \
231 } \
232 }
233
234#define highbd_sadMxNx4D(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -0700235 void aom_highbd_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700236 const uint8_t *const ref_array[], \
237 int ref_stride, uint32_t *sad_array) { \
238 int i; \
239 for (i = 0; i < 4; ++i) { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700240 sad_array[i] = aom_highbd_sad##m##x##n##_c(src, src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700241 ref_array[i], ref_stride); \
242 } \
243 }
244
245/* clang-format off */
Yaowu Xuf883b422016-08-30 14:01:10 -0700246#if CONFIG_AV1 && CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700247// 128x128
248highbd_sadMxN(128, 128)
249highbd_sadMxNxK(128, 128, 3)
250highbd_sadMxNxK(128, 128, 8)
251highbd_sadMxNx4D(128, 128)
252
253// 128x64
254highbd_sadMxN(128, 64)
255highbd_sadMxNx4D(128, 64)
256
257// 64x128
258highbd_sadMxN(64, 128)
259highbd_sadMxNx4D(64, 128)
Yaowu Xuf883b422016-08-30 14:01:10 -0700260#endif // CONFIG_AV1 && CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700261
262// 64x64
263highbd_sadMxN(64, 64)
264highbd_sadMxNxK(64, 64, 3)
265highbd_sadMxNxK(64, 64, 8)
266highbd_sadMxNx4D(64, 64)
267
268// 64x32
269highbd_sadMxN(64, 32)
270highbd_sadMxNx4D(64, 32)
271
272// 32x64
273highbd_sadMxN(32, 64)
274highbd_sadMxNx4D(32, 64)
275
276// 32x32
277highbd_sadMxN(32, 32)
278highbd_sadMxNxK(32, 32, 3)
279highbd_sadMxNxK(32, 32, 8)
280highbd_sadMxNx4D(32, 32)
281
282// 32x16
283highbd_sadMxN(32, 16)
284highbd_sadMxNx4D(32, 16)
285
286// 16x32
287highbd_sadMxN(16, 32)
288highbd_sadMxNx4D(16, 32)
289
290// 16x16
291highbd_sadMxN(16, 16)
292highbd_sadMxNxK(16, 16, 3)
293highbd_sadMxNxK(16, 16, 8)
294highbd_sadMxNx4D(16, 16)
295
296// 16x8
297highbd_sadMxN(16, 8)
298highbd_sadMxNxK(16, 8, 3)
299highbd_sadMxNxK(16, 8, 8)
300highbd_sadMxNx4D(16, 8)
301
302// 8x16
303highbd_sadMxN(8, 16)
304highbd_sadMxNxK(8, 16, 3)
305highbd_sadMxNxK(8, 16, 8)
306highbd_sadMxNx4D(8, 16)
307
308// 8x8
309highbd_sadMxN(8, 8)
310highbd_sadMxNxK(8, 8, 3)
311highbd_sadMxNxK(8, 8, 8)
312highbd_sadMxNx4D(8, 8)
313
314// 8x4
315highbd_sadMxN(8, 4)
316highbd_sadMxNxK(8, 4, 8)
317highbd_sadMxNx4D(8, 4)
318
319// 4x8
320highbd_sadMxN(4, 8)
321highbd_sadMxNxK(4, 8, 8)
322highbd_sadMxNx4D(4, 8)
323
324// 4x4
325highbd_sadMxN(4, 4)
326highbd_sadMxNxK(4, 4, 3)
327highbd_sadMxNxK(4, 4, 8)
328highbd_sadMxNx4D(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100329
330#if CONFIG_AV1 && CONFIG_EXT_PARTITION_TYPES
331highbd_sadMxN(4, 16)
332highbd_sadMxNx4D(4, 16)
333highbd_sadMxN(16, 4)
334highbd_sadMxNx4D(16, 4)
335highbd_sadMxN(8, 32)
336highbd_sadMxNx4D(8, 32)
337highbd_sadMxN(32, 8)
338highbd_sadMxNx4D(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100339highbd_sadMxN(16, 64)
340highbd_sadMxNx4D(16, 64)
341highbd_sadMxN(64, 16)
342highbd_sadMxNx4D(64, 16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100343highbd_sadMxN(32, 128)
344highbd_sadMxNx4D(32, 128)
345highbd_sadMxN(128, 32)
346highbd_sadMxNx4D(128, 32)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100347#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700348/* clang-format on */
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200349#endif // CONFIG_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -0700350
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +0200351#if CONFIG_AV1
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100352 static INLINE
David Barkerf19f35f2017-05-22 16:33:22 +0100353 unsigned int masked_sad(const uint8_t *src, int src_stride,
354 const uint8_t *a, int a_stride, const uint8_t *b,
355 int b_stride, const uint8_t *m, int m_stride,
356 int width, int height) {
David Barkerc155e012017-05-11 13:54:54 +0100357 int y, x;
358 unsigned int sad = 0;
359
360 for (y = 0; y < height; y++) {
361 for (x = 0; x < width; x++) {
362 const uint8_t pred = AOM_BLEND_A64(m[x], a[x], b[x]);
363 sad += abs(pred - src[x]);
364 }
365
366 src += src_stride;
367 a += a_stride;
368 b += b_stride;
369 m += m_stride;
370 }
371 sad = (sad + 31) >> 6;
372
373 return sad;
374}
375
David Barkerf19f35f2017-05-22 16:33:22 +0100376#define MASKSADMxN(m, n) \
377 unsigned int aom_masked_sad##m##x##n##_c( \
378 const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
379 const uint8_t *second_pred, const uint8_t *msk, int msk_stride, \
380 int invert_mask) { \
381 if (!invert_mask) \
382 return masked_sad(src, src_stride, ref, ref_stride, second_pred, m, msk, \
383 msk_stride, m, n); \
384 else \
385 return masked_sad(src, src_stride, second_pred, m, ref, ref_stride, msk, \
386 msk_stride, m, n); \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700387 }
388
389/* clang-format off */
390#if CONFIG_EXT_PARTITION
391MASKSADMxN(128, 128)
392MASKSADMxN(128, 64)
393MASKSADMxN(64, 128)
394#endif // CONFIG_EXT_PARTITION
395MASKSADMxN(64, 64)
396MASKSADMxN(64, 32)
397MASKSADMxN(32, 64)
398MASKSADMxN(32, 32)
399MASKSADMxN(32, 16)
400MASKSADMxN(16, 32)
401MASKSADMxN(16, 16)
402MASKSADMxN(16, 8)
403MASKSADMxN(8, 16)
404MASKSADMxN(8, 8)
405MASKSADMxN(8, 4)
406MASKSADMxN(4, 8)
407MASKSADMxN(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100408
409#if CONFIG_EXT_PARTITION_TYPES
410MASKSADMxN(4, 16)
411MASKSADMxN(16, 4)
412MASKSADMxN(8, 32)
413MASKSADMxN(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100414MASKSADMxN(16, 64)
415MASKSADMxN(64, 16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100416MASKSADMxN(32, 128)
417MASKSADMxN(128, 32)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100418#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700419/* clang-format on */
420
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200421#if CONFIG_HIGHBITDEPTH
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100422 static INLINE
David Barkerf19f35f2017-05-22 16:33:22 +0100423 unsigned int highbd_masked_sad(const uint8_t *src8, int src_stride,
424 const uint8_t *a8, int a_stride,
425 const uint8_t *b8, int b_stride,
426 const uint8_t *m, int m_stride, int width,
427 int height) {
David Barkerc155e012017-05-11 13:54:54 +0100428 int y, x;
429 unsigned int sad = 0;
430 const uint16_t *src = CONVERT_TO_SHORTPTR(src8);
431 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
432 const uint16_t *b = CONVERT_TO_SHORTPTR(b8);
433
434 for (y = 0; y < height; y++) {
435 for (x = 0; x < width; x++) {
436 const uint16_t pred = AOM_BLEND_A64(m[x], a[x], b[x]);
437 sad += abs(pred - src[x]);
438 }
439
440 src += src_stride;
441 a += a_stride;
442 b += b_stride;
443 m += m_stride;
444 }
445 sad = (sad + 31) >> 6;
446
447 return sad;
448}
449
David Barkerf19f35f2017-05-22 16:33:22 +0100450#define HIGHBD_MASKSADMXN(m, n) \
451 unsigned int aom_highbd_masked_sad##m##x##n##_c( \
452 const uint8_t *src8, int src_stride, const uint8_t *ref8, \
453 int ref_stride, const uint8_t *second_pred8, const uint8_t *msk, \
454 int msk_stride, int invert_mask) { \
455 if (!invert_mask) \
456 return highbd_masked_sad(src8, src_stride, ref8, ref_stride, \
457 second_pred8, m, msk, msk_stride, m, n); \
458 else \
459 return highbd_masked_sad(src8, src_stride, second_pred8, m, ref8, \
460 ref_stride, msk, msk_stride, m, n); \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700461 }
462
463#if CONFIG_EXT_PARTITION
464HIGHBD_MASKSADMXN(128, 128)
465HIGHBD_MASKSADMXN(128, 64)
466HIGHBD_MASKSADMXN(64, 128)
467#endif // CONFIG_EXT_PARTITION
468HIGHBD_MASKSADMXN(64, 64)
469HIGHBD_MASKSADMXN(64, 32)
470HIGHBD_MASKSADMXN(32, 64)
471HIGHBD_MASKSADMXN(32, 32)
472HIGHBD_MASKSADMXN(32, 16)
473HIGHBD_MASKSADMXN(16, 32)
474HIGHBD_MASKSADMXN(16, 16)
475HIGHBD_MASKSADMXN(16, 8)
476HIGHBD_MASKSADMXN(8, 16)
477HIGHBD_MASKSADMXN(8, 8)
478HIGHBD_MASKSADMXN(8, 4)
479HIGHBD_MASKSADMXN(4, 8)
480HIGHBD_MASKSADMXN(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100481
482#if CONFIG_AV1 && CONFIG_EXT_PARTITION_TYPES
483HIGHBD_MASKSADMXN(4, 16)
484HIGHBD_MASKSADMXN(16, 4)
485HIGHBD_MASKSADMXN(8, 32)
486HIGHBD_MASKSADMXN(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100487HIGHBD_MASKSADMXN(16, 64)
488HIGHBD_MASKSADMXN(64, 16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100489HIGHBD_MASKSADMXN(32, 128)
490HIGHBD_MASKSADMXN(128, 32)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100491#endif
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200492#endif // CONFIG_HIGHBITDEPTH
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +0200493#endif // CONFIG_AV1
Yaowu Xuc27fc142016-08-22 16:08:15 -0700494
Yue Chencb60b182016-10-13 15:18:22 -0700495#if CONFIG_AV1 && CONFIG_MOTION_VAR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700496// pre: predictor being evaluated
497// wsrc: target weighted prediction (has been *4096 to keep precision)
498// mask: 2d weights (scaled by 4096)
499static INLINE unsigned int obmc_sad(const uint8_t *pre, int pre_stride,
500 const int32_t *wsrc, const int32_t *mask,
501 int width, int height) {
502 int y, x;
503 unsigned int sad = 0;
504
505 for (y = 0; y < height; y++) {
506 for (x = 0; x < width; x++)
507 sad += ROUND_POWER_OF_TWO(abs(wsrc[x] - pre[x] * mask[x]), 12);
508
509 pre += pre_stride;
510 wsrc += width;
511 mask += width;
512 }
513
514 return sad;
515}
516
517#define OBMCSADMxN(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -0700518 unsigned int aom_obmc_sad##m##x##n##_c(const uint8_t *ref, int ref_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700519 const int32_t *wsrc, \
520 const int32_t *mask) { \
521 return obmc_sad(ref, ref_stride, wsrc, mask, m, n); \
522 }
523
524/* clang-format off */
525#if CONFIG_EXT_PARTITION
526OBMCSADMxN(128, 128)
527OBMCSADMxN(128, 64)
528OBMCSADMxN(64, 128)
529#endif // CONFIG_EXT_PARTITION
530OBMCSADMxN(64, 64)
531OBMCSADMxN(64, 32)
532OBMCSADMxN(32, 64)
533OBMCSADMxN(32, 32)
534OBMCSADMxN(32, 16)
535OBMCSADMxN(16, 32)
536OBMCSADMxN(16, 16)
537OBMCSADMxN(16, 8)
538OBMCSADMxN(8, 16)
539OBMCSADMxN(8, 8)
540OBMCSADMxN(8, 4)
541OBMCSADMxN(4, 8)
542OBMCSADMxN(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100543
544#if CONFIG_AV1 && CONFIG_EXT_PARTITION_TYPES
545OBMCSADMxN(4, 16)
546OBMCSADMxN(16, 4)
547OBMCSADMxN(8, 32)
548OBMCSADMxN(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100549OBMCSADMxN(16, 64)
550OBMCSADMxN(64, 16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100551OBMCSADMxN(32, 128)
552OBMCSADMxN(128, 32)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100553#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700554/* clang-format on */
555
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200556#if CONFIG_HIGHBITDEPTH
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100557 static INLINE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700558 unsigned int highbd_obmc_sad(const uint8_t *pre8, int pre_stride,
559 const int32_t *wsrc, const int32_t *mask,
560 int width, int height) {
561 int y, x;
562 unsigned int sad = 0;
563 const uint16_t *pre = CONVERT_TO_SHORTPTR(pre8);
564
565 for (y = 0; y < height; y++) {
566 for (x = 0; x < width; x++)
567 sad += ROUND_POWER_OF_TWO(abs(wsrc[x] - pre[x] * mask[x]), 12);
568
569 pre += pre_stride;
570 wsrc += width;
571 mask += width;
572 }
573
574 return sad;
575}
576
577#define HIGHBD_OBMCSADMXN(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -0700578 unsigned int aom_highbd_obmc_sad##m##x##n##_c( \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700579 const uint8_t *ref, int ref_stride, const int32_t *wsrc, \
580 const int32_t *mask) { \
581 return highbd_obmc_sad(ref, ref_stride, wsrc, mask, m, n); \
582 }
583
584/* clang-format off */
585#if CONFIG_EXT_PARTITION
586HIGHBD_OBMCSADMXN(128, 128)
587HIGHBD_OBMCSADMXN(128, 64)
588HIGHBD_OBMCSADMXN(64, 128)
589#endif // CONFIG_EXT_PARTITION
590HIGHBD_OBMCSADMXN(64, 64)
591HIGHBD_OBMCSADMXN(64, 32)
592HIGHBD_OBMCSADMXN(32, 64)
593HIGHBD_OBMCSADMXN(32, 32)
594HIGHBD_OBMCSADMXN(32, 16)
595HIGHBD_OBMCSADMXN(16, 32)
596HIGHBD_OBMCSADMXN(16, 16)
597HIGHBD_OBMCSADMXN(16, 8)
598HIGHBD_OBMCSADMXN(8, 16)
599HIGHBD_OBMCSADMXN(8, 8)
600HIGHBD_OBMCSADMXN(8, 4)
601HIGHBD_OBMCSADMXN(4, 8)
602HIGHBD_OBMCSADMXN(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100603
604#if CONFIG_AV1 && CONFIG_EXT_PARTITION_TYPES
605HIGHBD_OBMCSADMXN(4, 16)
606HIGHBD_OBMCSADMXN(16, 4)
607HIGHBD_OBMCSADMXN(8, 32)
608HIGHBD_OBMCSADMXN(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100609HIGHBD_OBMCSADMXN(16, 64)
610HIGHBD_OBMCSADMXN(64, 16)
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100611HIGHBD_OBMCSADMXN(32, 128)
612HIGHBD_OBMCSADMXN(128, 32)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100613#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700614/* clang-format on */
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200615#endif // CONFIG_HIGHBITDEPTH
Yue Chencb60b182016-10-13 15:18:22 -0700616#endif // CONFIG_AV1 && CONFIG_MOTION_VAR