2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
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.
13 #include "./vpx_config.h"
14 #include "./vpx_dsp_rtcd.h"
16 #include "vpx/vpx_integer.h"
17 #include "vpx_ports/mem.h"
19 /* Sum the difference between every corresponding element of the buffers. */
20 static INLINE unsigned int sad(const uint8_t *a, int a_stride, const uint8_t *b,
21 int b_stride, int width, int height) {
25 for (y = 0; y < height; y++) {
26 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
34 #define sadMxN(m, n) \
35 unsigned int vpx_sad##m##x##n##_c(const uint8_t *src, int src_stride, \
36 const uint8_t *ref, int ref_stride) { \
37 return sad(src, src_stride, ref, ref_stride, m, n); \
39 unsigned int vpx_sad##m##x##n##_avg_c(const uint8_t *src, int src_stride, \
40 const uint8_t *ref, int ref_stride, \
41 const uint8_t *second_pred) { \
42 DECLARE_ALIGNED(16, uint8_t, comp_pred[m * n]); \
43 vpx_comp_avg_pred_c(comp_pred, second_pred, m, n, ref, ref_stride); \
44 return sad(src, src_stride, comp_pred, m, m, n); \
47 // depending on call sites, pass **ref_array to avoid & in subsequent call and
48 // de-dup with 4D below.
49 #define sadMxNxK(m, n, k) \
50 void vpx_sad##m##x##n##x##k##_c(const uint8_t *src, int src_stride, \
51 const uint8_t *ref_array, int ref_stride, \
52 uint32_t *sad_array) { \
54 for (i = 0; i < k; ++i) \
56 vpx_sad##m##x##n##_c(src, src_stride, &ref_array[i], ref_stride); \
59 // This appears to be equivalent to the above when k == 4 and refs is const
60 #define sadMxNx4D(m, n) \
61 void vpx_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \
62 const uint8_t *const ref_array[], \
63 int ref_stride, uint32_t *sad_array) { \
65 for (i = 0; i < 4; ++i) \
67 vpx_sad##m##x##n##_c(src, src_stride, ref_array[i], ref_stride); \
70 /* clang-format off */
132 /* clang-format on */
134 #if CONFIG_VP9_HIGHBITDEPTH
136 unsigned int highbd_sad(const uint8_t *a8, int a_stride, const uint8_t *b8,
137 int b_stride, int width, int height) {
139 unsigned int sad = 0;
140 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
141 const uint16_t *b = CONVERT_TO_SHORTPTR(b8);
142 for (y = 0; y < height; y++) {
143 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
151 static INLINE unsigned int highbd_sadb(const uint8_t *a8, int a_stride,
152 const uint16_t *b, int b_stride,
153 int width, int height) {
155 unsigned int sad = 0;
156 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
157 for (y = 0; y < height; y++) {
158 for (x = 0; x < width; x++) sad += abs(a[x] - b[x]);
166 #define highbd_sadMxN(m, n) \
167 unsigned int vpx_highbd_sad##m##x##n##_c(const uint8_t *src, int src_stride, \
168 const uint8_t *ref, \
170 return highbd_sad(src, src_stride, ref, ref_stride, m, n); \
172 unsigned int vpx_highbd_sad##m##x##n##_avg_c( \
173 const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
174 const uint8_t *second_pred) { \
175 DECLARE_ALIGNED(16, uint16_t, comp_pred[m * n]); \
176 vpx_highbd_comp_avg_pred_c(comp_pred, second_pred, m, n, ref, ref_stride); \
177 return highbd_sadb(src, src_stride, comp_pred, m, m, n); \
180 #define highbd_sadMxNx4D(m, n) \
181 void vpx_highbd_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \
182 const uint8_t *const ref_array[], \
183 int ref_stride, uint32_t *sad_array) { \
185 for (i = 0; i < 4; ++i) { \
186 sad_array[i] = vpx_highbd_sad##m##x##n##_c(src, src_stride, \
187 ref_array[i], ref_stride); \
191 /* clang-format off */
193 highbd_sadMxN(64, 64)
194 highbd_sadMxNx4D(64, 64)
197 highbd_sadMxN(64, 32)
198 highbd_sadMxNx4D(64, 32)
201 highbd_sadMxN(32, 64)
202 highbd_sadMxNx4D(32, 64)
205 highbd_sadMxN(32, 32)
206 highbd_sadMxNx4D(32, 32)
209 highbd_sadMxN(32, 16)
210 highbd_sadMxNx4D(32, 16)
213 highbd_sadMxN(16, 32)
214 highbd_sadMxNx4D(16, 32)
217 highbd_sadMxN(16, 16)
218 highbd_sadMxNx4D(16, 16)
222 highbd_sadMxNx4D(16, 8)
226 highbd_sadMxNx4D(8, 16)
230 highbd_sadMxNx4D(8, 8)
234 highbd_sadMxNx4D(8, 4)
238 highbd_sadMxNx4D(4, 8)
242 highbd_sadMxNx4D(4, 4)
243 /* clang-format on */
245 #endif // CONFIG_VP9_HIGHBITDEPTH