blob: 47b657c3bc16f3a0c11f915af39e83d142dd7942 [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
Cheng Chend0179a62017-11-16 17:02:53 -080036#define sadMxh(m) \
37 unsigned int aom_sad##m##xh_c(const uint8_t *a, int a_stride, \
38 const uint8_t *b, int b_stride, int width, \
39 int height) { \
40 return sad(a, a_stride, b, b_stride, width, height); \
41 }
42
Cheng Chenf78632e2017-10-20 15:30:51 -070043#define sadMxN(m, n) \
44 unsigned int aom_sad##m##x##n##_c(const uint8_t *src, int src_stride, \
45 const uint8_t *ref, int ref_stride) { \
46 return sad(src, src_stride, ref, ref_stride, m, n); \
47 } \
48 unsigned int aom_sad##m##x##n##_avg_c(const uint8_t *src, int src_stride, \
49 const uint8_t *ref, int ref_stride, \
50 const uint8_t *second_pred) { \
51 uint8_t comp_pred[m * n]; \
52 aom_comp_avg_pred(comp_pred, second_pred, m, n, ref, ref_stride); \
53 return sad(src, src_stride, comp_pred, m, m, n); \
54 } \
55 unsigned int aom_jnt_sad##m##x##n##_avg_c( \
56 const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
57 const uint8_t *second_pred, const JNT_COMP_PARAMS *jcp_param) { \
58 uint8_t comp_pred[m * n]; \
Cheng Chend0179a62017-11-16 17:02:53 -080059 aom_jnt_comp_avg_pred_c(comp_pred, second_pred, m, n, ref, ref_stride, \
60 jcp_param); \
Cheng Chenf78632e2017-10-20 15:30:51 -070061 return sad(src, src_stride, comp_pred, m, m, n); \
62 }
Yaowu Xuc27fc142016-08-22 16:08:15 -070063
64// depending on call sites, pass **ref_array to avoid & in subsequent call and
65// de-dup with 4D below.
66#define sadMxNxK(m, n, k) \
Yaowu Xuf883b422016-08-30 14:01:10 -070067 void aom_sad##m##x##n##x##k##_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -070068 const uint8_t *ref_array, int ref_stride, \
69 uint32_t *sad_array) { \
70 int i; \
71 for (i = 0; i < k; ++i) \
72 sad_array[i] = \
Yaowu Xuf883b422016-08-30 14:01:10 -070073 aom_sad##m##x##n##_c(src, src_stride, &ref_array[i], ref_stride); \
Yaowu Xuc27fc142016-08-22 16:08:15 -070074 }
75
76// This appears to be equivalent to the above when k == 4 and refs is const
77#define sadMxNx4D(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -070078 void aom_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -070079 const uint8_t *const ref_array[], \
80 int ref_stride, uint32_t *sad_array) { \
81 int i; \
82 for (i = 0; i < 4; ++i) \
83 sad_array[i] = \
Yaowu Xuf883b422016-08-30 14:01:10 -070084 aom_sad##m##x##n##_c(src, src_stride, ref_array[i], ref_stride); \
Yaowu Xuc27fc142016-08-22 16:08:15 -070085 }
86
87/* clang-format off */
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -080088#if CONFIG_AV1
Yaowu Xuc27fc142016-08-22 16:08:15 -070089// 128x128
90sadMxN(128, 128)
91sadMxNxK(128, 128, 3)
92sadMxNxK(128, 128, 8)
93sadMxNx4D(128, 128)
94
95// 128x64
96sadMxN(128, 64)
97sadMxNx4D(128, 64)
98
99// 64x128
100sadMxN(64, 128)
101sadMxNx4D(64, 128)
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800102#endif // CONFIG_AV1
Yaowu Xuc27fc142016-08-22 16:08:15 -0700103
104// 64x64
105sadMxN(64, 64)
106sadMxNxK(64, 64, 3)
107sadMxNxK(64, 64, 8)
108sadMxNx4D(64, 64)
109
110// 64x32
111sadMxN(64, 32)
112sadMxNx4D(64, 32)
113
114// 32x64
115sadMxN(32, 64)
116sadMxNx4D(32, 64)
117
118// 32x32
119sadMxN(32, 32)
120sadMxNxK(32, 32, 3)
121sadMxNxK(32, 32, 8)
122sadMxNx4D(32, 32)
123
124// 32x16
125sadMxN(32, 16)
126sadMxNx4D(32, 16)
127
128// 16x32
129sadMxN(16, 32)
130sadMxNx4D(16, 32)
131
132// 16x16
133sadMxN(16, 16)
134sadMxNxK(16, 16, 3)
135sadMxNxK(16, 16, 8)
136sadMxNx4D(16, 16)
137
138// 16x8
139sadMxN(16, 8)
140sadMxNxK(16, 8, 3)
141sadMxNxK(16, 8, 8)
142sadMxNx4D(16, 8)
143
144// 8x16
145sadMxN(8, 16)
146sadMxNxK(8, 16, 3)
147sadMxNxK(8, 16, 8)
148sadMxNx4D(8, 16)
149
150// 8x8
151sadMxN(8, 8)
152sadMxNxK(8, 8, 3)
153sadMxNxK(8, 8, 8)
154sadMxNx4D(8, 8)
155
156// 8x4
157sadMxN(8, 4)
158sadMxNxK(8, 4, 8)
159sadMxNx4D(8, 4)
160
161// 4x8
162sadMxN(4, 8)
163sadMxNxK(4, 8, 8)
164sadMxNx4D(4, 8)
165
166// 4x4
167sadMxN(4, 4)
168sadMxNxK(4, 4, 3)
169sadMxNxK(4, 4, 8)
170sadMxNx4D(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100171
Cheng Chend0179a62017-11-16 17:02:53 -0800172sadMxh(128);
Cheng Chend0179a62017-11-16 17:02:53 -0800173sadMxh(64);
174sadMxh(32);
175sadMxh(16);
176sadMxh(8);
177sadMxh(4);
Cheng Chend0179a62017-11-16 17:02:53 -0800178
Debargha Mukherjee16870852018-02-28 10:00:17 -0800179#if CONFIG_AV1
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100180sadMxN(4, 16)
181sadMxNx4D(4, 16)
182sadMxN(16, 4)
183sadMxNx4D(16, 4)
184sadMxN(8, 32)
185sadMxNx4D(8, 32)
186sadMxN(32, 8)
187sadMxNx4D(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100188sadMxN(16, 64)
189sadMxNx4D(16, 64)
190sadMxN(64, 16)
191sadMxNx4D(64, 16)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100192#endif
Yaowu Xud3e7c682017-12-21 14:08:25 -0800193 /* clang-format on */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700194
Yaowu Xud3e7c682017-12-21 14:08:25 -0800195 static INLINE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700196 unsigned int highbd_sad(const uint8_t *a8, int a_stride, const uint8_t *b8,
197 int b_stride, int width, int height) {
198 int y, x;
199 unsigned int sad = 0;
200 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
201 const uint16_t *b = CONVERT_TO_SHORTPTR(b8);
202 for (y = 0; y < height; y++) {
203 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
204
205 a += a_stride;
206 b += b_stride;
207 }
208 return sad;
209}
210
211static INLINE unsigned int highbd_sadb(const uint8_t *a8, int a_stride,
212 const uint16_t *b, int b_stride,
213 int width, int height) {
214 int y, x;
215 unsigned int sad = 0;
216 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
217 for (y = 0; y < height; y++) {
218 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
219
220 a += a_stride;
221 b += b_stride;
222 }
223 return sad;
224}
225
Cheng Chenbf3d4962017-11-01 14:48:52 -0700226#define highbd_sadMxN(m, n) \
227 unsigned int aom_highbd_sad##m##x##n##_c(const uint8_t *src, int src_stride, \
228 const uint8_t *ref, \
229 int ref_stride) { \
230 return highbd_sad(src, src_stride, ref, ref_stride, m, n); \
231 } \
232 unsigned int aom_highbd_sad##m##x##n##_avg_c( \
233 const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
234 const uint8_t *second_pred) { \
235 uint16_t comp_pred[m * n]; \
236 aom_highbd_comp_avg_pred(comp_pred, second_pred, m, n, ref, ref_stride); \
237 return highbd_sadb(src, src_stride, comp_pred, m, m, n); \
238 } \
239 unsigned int aom_highbd_jnt_sad##m##x##n##_avg_c( \
240 const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
241 const uint8_t *second_pred, const JNT_COMP_PARAMS *jcp_param) { \
242 uint16_t comp_pred[m * n]; \
243 aom_highbd_jnt_comp_avg_pred(comp_pred, second_pred, m, n, ref, \
244 ref_stride, jcp_param); \
245 return highbd_sadb(src, src_stride, comp_pred, m, m, n); \
246 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700247
248#define highbd_sadMxNxK(m, n, k) \
Yaowu Xuf883b422016-08-30 14:01:10 -0700249 void aom_highbd_sad##m##x##n##x##k##_c( \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700250 const uint8_t *src, int src_stride, const uint8_t *ref_array, \
251 int ref_stride, uint32_t *sad_array) { \
252 int i; \
253 for (i = 0; i < k; ++i) { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700254 sad_array[i] = aom_highbd_sad##m##x##n##_c(src, src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700255 &ref_array[i], ref_stride); \
256 } \
257 }
258
259#define highbd_sadMxNx4D(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -0700260 void aom_highbd_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700261 const uint8_t *const ref_array[], \
262 int ref_stride, uint32_t *sad_array) { \
263 int i; \
264 for (i = 0; i < 4; ++i) { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700265 sad_array[i] = aom_highbd_sad##m##x##n##_c(src, src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700266 ref_array[i], ref_stride); \
267 } \
268 }
269
270/* clang-format off */
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800271#if CONFIG_AV1
Yaowu Xuc27fc142016-08-22 16:08:15 -0700272// 128x128
273highbd_sadMxN(128, 128)
274highbd_sadMxNxK(128, 128, 3)
275highbd_sadMxNxK(128, 128, 8)
276highbd_sadMxNx4D(128, 128)
277
278// 128x64
279highbd_sadMxN(128, 64)
280highbd_sadMxNx4D(128, 64)
281
282// 64x128
283highbd_sadMxN(64, 128)
284highbd_sadMxNx4D(64, 128)
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800285#endif // CONFIG_AV1
Yaowu Xuc27fc142016-08-22 16:08:15 -0700286
287// 64x64
288highbd_sadMxN(64, 64)
289highbd_sadMxNxK(64, 64, 3)
290highbd_sadMxNxK(64, 64, 8)
291highbd_sadMxNx4D(64, 64)
292
293// 64x32
294highbd_sadMxN(64, 32)
295highbd_sadMxNx4D(64, 32)
296
297// 32x64
298highbd_sadMxN(32, 64)
299highbd_sadMxNx4D(32, 64)
300
301// 32x32
302highbd_sadMxN(32, 32)
303highbd_sadMxNxK(32, 32, 3)
304highbd_sadMxNxK(32, 32, 8)
305highbd_sadMxNx4D(32, 32)
306
307// 32x16
308highbd_sadMxN(32, 16)
309highbd_sadMxNx4D(32, 16)
310
311// 16x32
312highbd_sadMxN(16, 32)
313highbd_sadMxNx4D(16, 32)
314
315// 16x16
316highbd_sadMxN(16, 16)
317highbd_sadMxNxK(16, 16, 3)
318highbd_sadMxNxK(16, 16, 8)
319highbd_sadMxNx4D(16, 16)
320
321// 16x8
322highbd_sadMxN(16, 8)
323highbd_sadMxNxK(16, 8, 3)
324highbd_sadMxNxK(16, 8, 8)
325highbd_sadMxNx4D(16, 8)
326
327// 8x16
328highbd_sadMxN(8, 16)
329highbd_sadMxNxK(8, 16, 3)
330highbd_sadMxNxK(8, 16, 8)
331highbd_sadMxNx4D(8, 16)
332
333// 8x8
334highbd_sadMxN(8, 8)
335highbd_sadMxNxK(8, 8, 3)
336highbd_sadMxNxK(8, 8, 8)
337highbd_sadMxNx4D(8, 8)
338
339// 8x4
340highbd_sadMxN(8, 4)
341highbd_sadMxNxK(8, 4, 8)
342highbd_sadMxNx4D(8, 4)
343
344// 4x8
345highbd_sadMxN(4, 8)
346highbd_sadMxNxK(4, 8, 8)
347highbd_sadMxNx4D(4, 8)
348
349// 4x4
350highbd_sadMxN(4, 4)
351highbd_sadMxNxK(4, 4, 3)
352highbd_sadMxNxK(4, 4, 8)
353highbd_sadMxNx4D(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100354
Debargha Mukherjee16870852018-02-28 10:00:17 -0800355#if CONFIG_AV1
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100356highbd_sadMxN(4, 16)
357highbd_sadMxNx4D(4, 16)
358highbd_sadMxN(16, 4)
359highbd_sadMxNx4D(16, 4)
360highbd_sadMxN(8, 32)
361highbd_sadMxNx4D(8, 32)
362highbd_sadMxN(32, 8)
363highbd_sadMxNx4D(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100364highbd_sadMxN(16, 64)
365highbd_sadMxNx4D(16, 64)
366highbd_sadMxN(64, 16)
367highbd_sadMxNx4D(64, 16)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100368#endif
Yaowu Xud3e7c682017-12-21 14:08:25 -0800369 /* clang-format on */