blob: ede4c583b3ec570c48828067d0724a9499e0e734 [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
Tom Finegan60e653d2018-05-22 11:34:58 -070014#include "config/aom_config.h"
Tom Finegan44702c82018-05-22 13:00:39 -070015#include "config/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
Kyle Siefringef6e2df2018-04-10 14:51:35 -040064// Calculate sad against 4 reference locations and store each in sad_array
Yaowu Xuc27fc142016-08-22 16:08:15 -070065#define sadMxNx4D(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -070066 void aom_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -070067 const uint8_t *const ref_array[], \
68 int ref_stride, uint32_t *sad_array) { \
69 int i; \
70 for (i = 0; i < 4; ++i) \
71 sad_array[i] = \
Yaowu Xuf883b422016-08-30 14:01:10 -070072 aom_sad##m##x##n##_c(src, src_stride, ref_array[i], ref_stride); \
Yaowu Xuc27fc142016-08-22 16:08:15 -070073 }
74
75/* clang-format off */
Yaowu Xuc27fc142016-08-22 16:08:15 -070076// 128x128
77sadMxN(128, 128)
Yaowu Xuc27fc142016-08-22 16:08:15 -070078sadMxNx4D(128, 128)
79
80// 128x64
81sadMxN(128, 64)
82sadMxNx4D(128, 64)
83
84// 64x128
85sadMxN(64, 128)
86sadMxNx4D(64, 128)
Yaowu Xuc27fc142016-08-22 16:08:15 -070087
88// 64x64
89sadMxN(64, 64)
Yaowu Xuc27fc142016-08-22 16:08:15 -070090sadMxNx4D(64, 64)
91
92// 64x32
93sadMxN(64, 32)
94sadMxNx4D(64, 32)
95
96// 32x64
97sadMxN(32, 64)
98sadMxNx4D(32, 64)
99
100// 32x32
101sadMxN(32, 32)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700102sadMxNx4D(32, 32)
103
104// 32x16
105sadMxN(32, 16)
106sadMxNx4D(32, 16)
107
108// 16x32
109sadMxN(16, 32)
110sadMxNx4D(16, 32)
111
112// 16x16
113sadMxN(16, 16)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114sadMxNx4D(16, 16)
115
116// 16x8
117sadMxN(16, 8)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700118sadMxNx4D(16, 8)
119
120// 8x16
121sadMxN(8, 16)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700122sadMxNx4D(8, 16)
123
124// 8x8
125sadMxN(8, 8)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700126sadMxNx4D(8, 8)
127
128// 8x4
129sadMxN(8, 4)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700130sadMxNx4D(8, 4)
131
132// 4x8
133sadMxN(4, 8)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700134sadMxNx4D(4, 8)
135
136// 4x4
137sadMxN(4, 4)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700138sadMxNx4D(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100139
Cheng Chend0179a62017-11-16 17:02:53 -0800140sadMxh(128);
Cheng Chend0179a62017-11-16 17:02:53 -0800141sadMxh(64);
142sadMxh(32);
143sadMxh(16);
144sadMxh(8);
145sadMxh(4);
Cheng Chend0179a62017-11-16 17:02:53 -0800146
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100147sadMxN(4, 16)
148sadMxNx4D(4, 16)
149sadMxN(16, 4)
150sadMxNx4D(16, 4)
151sadMxN(8, 32)
152sadMxNx4D(8, 32)
153sadMxN(32, 8)
154sadMxNx4D(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100155sadMxN(16, 64)
156sadMxNx4D(16, 64)
157sadMxN(64, 16)
158sadMxNx4D(64, 16)
Tom Finegan9a7278f2018-05-25 10:20:55 -0700159
Yaowu Xud3e7c682017-12-21 14:08:25 -0800160 /* clang-format on */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700161
Yaowu Xud3e7c682017-12-21 14:08:25 -0800162 static INLINE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700163 unsigned int highbd_sad(const uint8_t *a8, int a_stride, const uint8_t *b8,
164 int b_stride, int width, int height) {
165 int y, x;
166 unsigned int sad = 0;
167 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
168 const uint16_t *b = CONVERT_TO_SHORTPTR(b8);
169 for (y = 0; y < height; y++) {
170 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
171
172 a += a_stride;
173 b += b_stride;
174 }
175 return sad;
176}
177
178static INLINE unsigned int highbd_sadb(const uint8_t *a8, int a_stride,
179 const uint16_t *b, int b_stride,
180 int width, int height) {
181 int y, x;
182 unsigned int sad = 0;
183 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
184 for (y = 0; y < height; y++) {
185 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
186
187 a += a_stride;
188 b += b_stride;
189 }
190 return sad;
191}
192
Cheng Chenbf3d4962017-11-01 14:48:52 -0700193#define highbd_sadMxN(m, n) \
194 unsigned int aom_highbd_sad##m##x##n##_c(const uint8_t *src, int src_stride, \
195 const uint8_t *ref, \
196 int ref_stride) { \
197 return highbd_sad(src, src_stride, ref, ref_stride, m, n); \
198 } \
199 unsigned int aom_highbd_sad##m##x##n##_avg_c( \
200 const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
201 const uint8_t *second_pred) { \
202 uint16_t comp_pred[m * n]; \
203 aom_highbd_comp_avg_pred(comp_pred, second_pred, m, n, ref, ref_stride); \
204 return highbd_sadb(src, src_stride, comp_pred, m, m, n); \
205 } \
206 unsigned int aom_highbd_jnt_sad##m##x##n##_avg_c( \
207 const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
208 const uint8_t *second_pred, const JNT_COMP_PARAMS *jcp_param) { \
209 uint16_t comp_pred[m * n]; \
210 aom_highbd_jnt_comp_avg_pred(comp_pred, second_pred, m, n, ref, \
211 ref_stride, jcp_param); \
212 return highbd_sadb(src, src_stride, comp_pred, m, m, n); \
213 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700214
Yaowu Xuc27fc142016-08-22 16:08:15 -0700215#define highbd_sadMxNx4D(m, n) \
Yaowu Xuf883b422016-08-30 14:01:10 -0700216 void aom_highbd_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700217 const uint8_t *const ref_array[], \
218 int ref_stride, uint32_t *sad_array) { \
219 int i; \
220 for (i = 0; i < 4; ++i) { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700221 sad_array[i] = aom_highbd_sad##m##x##n##_c(src, src_stride, \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700222 ref_array[i], ref_stride); \
223 } \
224 }
225
226/* clang-format off */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700227// 128x128
228highbd_sadMxN(128, 128)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700229highbd_sadMxNx4D(128, 128)
230
231// 128x64
232highbd_sadMxN(128, 64)
233highbd_sadMxNx4D(128, 64)
234
235// 64x128
236highbd_sadMxN(64, 128)
237highbd_sadMxNx4D(64, 128)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700238
239// 64x64
240highbd_sadMxN(64, 64)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700241highbd_sadMxNx4D(64, 64)
242
243// 64x32
244highbd_sadMxN(64, 32)
245highbd_sadMxNx4D(64, 32)
246
247// 32x64
248highbd_sadMxN(32, 64)
249highbd_sadMxNx4D(32, 64)
250
251// 32x32
252highbd_sadMxN(32, 32)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700253highbd_sadMxNx4D(32, 32)
254
255// 32x16
256highbd_sadMxN(32, 16)
257highbd_sadMxNx4D(32, 16)
258
259// 16x32
260highbd_sadMxN(16, 32)
261highbd_sadMxNx4D(16, 32)
262
263// 16x16
264highbd_sadMxN(16, 16)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700265highbd_sadMxNx4D(16, 16)
266
267// 16x8
268highbd_sadMxN(16, 8)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700269highbd_sadMxNx4D(16, 8)
270
271// 8x16
272highbd_sadMxN(8, 16)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700273highbd_sadMxNx4D(8, 16)
274
275// 8x8
276highbd_sadMxN(8, 8)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700277highbd_sadMxNx4D(8, 8)
278
279// 8x4
280highbd_sadMxN(8, 4)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700281highbd_sadMxNx4D(8, 4)
282
283// 4x8
284highbd_sadMxN(4, 8)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285highbd_sadMxNx4D(4, 8)
286
287// 4x4
288highbd_sadMxN(4, 4)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700289highbd_sadMxNx4D(4, 4)
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100290
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100291highbd_sadMxN(4, 16)
292highbd_sadMxNx4D(4, 16)
293highbd_sadMxN(16, 4)
294highbd_sadMxNx4D(16, 4)
295highbd_sadMxN(8, 32)
296highbd_sadMxNx4D(8, 32)
297highbd_sadMxN(32, 8)
298highbd_sadMxNx4D(32, 8)
Rupert Swarbrick72678572017-08-02 12:05:26 +0100299highbd_sadMxN(16, 64)
300highbd_sadMxNx4D(16, 64)
301highbd_sadMxN(64, 16)
302highbd_sadMxNx4D(64, 16)
Yaowu Xud3e7c682017-12-21 14:08:25 -0800303 /* clang-format on */