1 /*
2 * Copyright (c) 2010 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 "./vp9_rtcd.h"
14 #include "./vpx_config.h"
15
16 #include "vpx/vpx_integer.h"
17 #include "vp9/encoder/vp9_variance.h"
18
sad(const uint8_t * a,int a_stride,const uint8_t * b,int b_stride,int width,int height)19 static INLINE unsigned int sad(const uint8_t *a, int a_stride,
20 const uint8_t *b, int b_stride,
21 int width, int height) {
22 int y, x;
23 unsigned int sad = 0;
24
25 for (y = 0; y < height; y++) {
26 for (x = 0; x < width; x++)
27 sad += abs(a[x] - b[x]);
28
29 a += a_stride;
30 b += b_stride;
31 }
32
33 return sad;
34 }
35
36 #define sad_mxn_func(m, n) \
37 unsigned int vp9_sad##m##x##n##_c(const uint8_t *src_ptr, int src_stride, \
38 const uint8_t *ref_ptr, int ref_stride, \
39 unsigned int max_sad) { \
40 return sad(src_ptr, src_stride, ref_ptr, ref_stride, m, n); \
41 } \
42 unsigned int vp9_sad##m##x##n##_avg_c(const uint8_t *src_ptr, int src_stride, \
43 const uint8_t *ref_ptr, int ref_stride, \
44 const uint8_t *second_pred, \
45 unsigned int max_sad) { \
46 uint8_t comp_pred[m * n]; \
47 vp9_comp_avg_pred(comp_pred, second_pred, m, n, ref_ptr, ref_stride); \
48 return sad(src_ptr, src_stride, comp_pred, m, m, n); \
49 }
50
51 sad_mxn_func(64, 64)
52 sad_mxn_func(64, 32)
53 sad_mxn_func(32, 64)
54 sad_mxn_func(32, 32)
55 sad_mxn_func(32, 16)
56 sad_mxn_func(16, 32)
57 sad_mxn_func(16, 16)
58 sad_mxn_func(16, 8)
59 sad_mxn_func(8, 16)
60 sad_mxn_func(8, 8)
61 sad_mxn_func(8, 4)
62 sad_mxn_func(4, 8)
63 sad_mxn_func(4, 4)
64
vp9_sad64x32x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)65 void vp9_sad64x32x4d_c(const uint8_t *src_ptr, int src_stride,
66 const uint8_t* const ref_ptr[], int ref_stride,
67 unsigned int *sad_array) {
68 int i;
69 for (i = 0; i < 4; ++i)
70 sad_array[i] = vp9_sad64x32(src_ptr, src_stride, ref_ptr[i], ref_stride,
71 0x7fffffff);
72 }
73
vp9_sad32x64x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)74 void vp9_sad32x64x4d_c(const uint8_t *src_ptr, int src_stride,
75 const uint8_t* const ref_ptr[], int ref_stride,
76 unsigned int *sad_array) {
77 int i;
78 for (i = 0; i < 4; ++i)
79 sad_array[i] = vp9_sad32x64(src_ptr, src_stride, ref_ptr[i], ref_stride,
80 0x7fffffff);
81 }
82
vp9_sad32x16x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)83 void vp9_sad32x16x4d_c(const uint8_t *src_ptr, int src_stride,
84 const uint8_t* const ref_ptr[], int ref_stride,
85 unsigned int *sad_array) {
86 int i;
87 for (i = 0; i < 4; ++i)
88 sad_array[i] = vp9_sad32x16(src_ptr, src_stride, ref_ptr[i], ref_stride,
89 0x7fffffff);
90 }
91
vp9_sad16x32x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)92 void vp9_sad16x32x4d_c(const uint8_t *src_ptr, int src_stride,
93 const uint8_t* const ref_ptr[], int ref_stride,
94 unsigned int *sad_array) {
95 int i;
96 for (i = 0; i < 4; ++i)
97 sad_array[i] = vp9_sad16x32(src_ptr, src_stride, ref_ptr[i], ref_stride,
98 0x7fffffff);
99 }
100
vp9_sad64x64x3_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)101 void vp9_sad64x64x3_c(const uint8_t *src_ptr, int src_stride,
102 const uint8_t *ref_ptr, int ref_stride,
103 unsigned int *sad_array) {
104 int i;
105 for (i = 0; i < 3; ++i)
106 sad_array[i] = vp9_sad64x64(src_ptr, src_stride, ref_ptr + i, ref_stride,
107 0x7fffffff);
108 }
109
vp9_sad32x32x3_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)110 void vp9_sad32x32x3_c(const uint8_t *src_ptr, int src_stride,
111 const uint8_t *ref_ptr, int ref_stride,
112 unsigned int *sad_array) {
113 int i;
114 for (i = 0; i < 3; ++i)
115 sad_array[i] = vp9_sad32x32(src_ptr, src_stride, ref_ptr + i, ref_stride,
116 0x7fffffff);
117 }
118
vp9_sad64x64x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)119 void vp9_sad64x64x8_c(const uint8_t *src_ptr, int src_stride,
120 const uint8_t *ref_ptr, int ref_stride,
121 unsigned int *sad_array) {
122 int i;
123 for (i = 0; i < 8; ++i)
124 sad_array[i] = vp9_sad64x64(src_ptr, src_stride, ref_ptr + i, ref_stride,
125 0x7fffffff);
126 }
127
vp9_sad32x32x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)128 void vp9_sad32x32x8_c(const uint8_t *src_ptr, int src_stride,
129 const uint8_t *ref_ptr, int ref_stride,
130 unsigned int *sad_array) {
131 int i;
132 for (i = 0; i < 8; ++i)
133 sad_array[i] = vp9_sad32x32(src_ptr, src_stride, ref_ptr + i, ref_stride,
134 0x7fffffff);
135 }
136
vp9_sad16x16x3_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)137 void vp9_sad16x16x3_c(const uint8_t *src_ptr, int src_stride,
138 const uint8_t *ref_ptr, int ref_stride,
139 unsigned int *sad_array) {
140 int i;
141 for (i = 0; i < 3; ++i)
142 sad_array[i] = vp9_sad16x16(src_ptr, src_stride, ref_ptr + i, ref_stride,
143 0x7fffffff);
144 }
145
vp9_sad16x16x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,uint32_t * sad_array)146 void vp9_sad16x16x8_c(const uint8_t *src_ptr, int src_stride,
147 const uint8_t *ref_ptr, int ref_stride,
148 uint32_t *sad_array) {
149 int i;
150 for (i = 0; i < 8; ++i)
151 sad_array[i] = vp9_sad16x16(src_ptr, src_stride, ref_ptr + i, ref_stride,
152 0x7fffffff);
153 }
154
vp9_sad16x8x3_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)155 void vp9_sad16x8x3_c(const uint8_t *src_ptr, int src_stride,
156 const uint8_t *ref_ptr, int ref_stride,
157 unsigned int *sad_array) {
158 int i;
159 for (i = 0; i < 3; ++i)
160 sad_array[i] = vp9_sad16x8(src_ptr, src_stride, ref_ptr + i, ref_stride,
161 0x7fffffff);
162 }
163
vp9_sad16x8x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,uint32_t * sad_array)164 void vp9_sad16x8x8_c(const uint8_t *src_ptr, int src_stride,
165 const uint8_t *ref_ptr, int ref_stride,
166 uint32_t *sad_array) {
167 int i;
168 for (i = 0; i < 8; ++i)
169 sad_array[i] = vp9_sad16x8(src_ptr, src_stride, ref_ptr + i, ref_stride,
170 0x7fffffff);
171 }
172
vp9_sad8x8x3_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)173 void vp9_sad8x8x3_c(const uint8_t *src_ptr, int src_stride,
174 const uint8_t *ref_ptr, int ref_stride,
175 unsigned int *sad_array) {
176 int i;
177 for (i = 0; i < 3; ++i)
178 sad_array[i] = vp9_sad8x8(src_ptr, src_stride, ref_ptr + i, ref_stride,
179 0x7fffffff);
180 }
181
vp9_sad8x8x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,uint32_t * sad_array)182 void vp9_sad8x8x8_c(const uint8_t *src_ptr, int src_stride,
183 const uint8_t *ref_ptr, int ref_stride,
184 uint32_t *sad_array) {
185 int i;
186 for (i = 0; i < 8; ++i)
187 sad_array[i] = vp9_sad8x8(src_ptr, src_stride, ref_ptr + i, ref_stride,
188 0x7fffffff);
189 }
190
vp9_sad8x16x3_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)191 void vp9_sad8x16x3_c(const uint8_t *src_ptr, int src_stride,
192 const uint8_t *ref_ptr, int ref_stride,
193 unsigned int *sad_array) {
194 int i;
195 for (i = 0; i < 3; ++i)
196 sad_array[i] = vp9_sad8x16(src_ptr, src_stride, ref_ptr + i, ref_stride,
197 0x7fffffff);
198 }
199
vp9_sad8x16x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,uint32_t * sad_array)200 void vp9_sad8x16x8_c(const uint8_t *src_ptr, int src_stride,
201 const uint8_t *ref_ptr, int ref_stride,
202 uint32_t *sad_array) {
203 int i;
204 for (i = 0; i < 8; ++i)
205 sad_array[i] = vp9_sad8x16(src_ptr, src_stride, ref_ptr + i, ref_stride,
206 0x7fffffff);
207 }
208
vp9_sad4x4x3_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,unsigned int * sad_array)209 void vp9_sad4x4x3_c(const uint8_t *src_ptr, int src_stride,
210 const uint8_t *ref_ptr, int ref_stride,
211 unsigned int *sad_array) {
212 int i;
213 for (i = 0; i < 3; ++i)
214 sad_array[i] = vp9_sad4x4(src_ptr, src_stride, ref_ptr + i, ref_stride,
215 0x7fffffff);
216 }
217
vp9_sad4x4x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,uint32_t * sad_array)218 void vp9_sad4x4x8_c(const uint8_t *src_ptr, int src_stride,
219 const uint8_t *ref_ptr, int ref_stride,
220 uint32_t *sad_array) {
221 int i;
222 for (i = 0; i < 8; ++i)
223 sad_array[i] = vp9_sad4x4(src_ptr, src_stride, ref_ptr + i, ref_stride,
224 0x7fffffff);
225 }
226
vp9_sad64x64x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)227 void vp9_sad64x64x4d_c(const uint8_t *src_ptr, int src_stride,
228 const uint8_t* const ref_ptr[], int ref_stride,
229 unsigned int *sad_array) {
230 int i;
231 for (i = 0; i < 4; ++i)
232 sad_array[i] = vp9_sad64x64(src_ptr, src_stride, ref_ptr[i], ref_stride,
233 0x7fffffff);
234 }
235
vp9_sad32x32x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)236 void vp9_sad32x32x4d_c(const uint8_t *src_ptr, int src_stride,
237 const uint8_t* const ref_ptr[], int ref_stride,
238 unsigned int *sad_array) {
239 int i;
240 for (i = 0; i < 4; ++i)
241 sad_array[i] = vp9_sad32x32(src_ptr, src_stride, ref_ptr[i], ref_stride,
242 0x7fffffff);
243 }
244
vp9_sad16x16x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)245 void vp9_sad16x16x4d_c(const uint8_t *src_ptr, int src_stride,
246 const uint8_t* const ref_ptr[], int ref_stride,
247 unsigned int *sad_array) {
248 int i;
249 for (i = 0; i < 4; ++i)
250 sad_array[i] = vp9_sad16x16(src_ptr, src_stride, ref_ptr[i], ref_stride,
251 0x7fffffff);
252 }
253
vp9_sad16x8x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)254 void vp9_sad16x8x4d_c(const uint8_t *src_ptr, int src_stride,
255 const uint8_t* const ref_ptr[], int ref_stride,
256 unsigned int *sad_array) {
257 int i;
258 for (i = 0; i < 4; ++i)
259 sad_array[i] = vp9_sad16x8(src_ptr, src_stride, ref_ptr[i], ref_stride,
260 0x7fffffff);
261 }
262
vp9_sad8x8x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)263 void vp9_sad8x8x4d_c(const uint8_t *src_ptr, int src_stride,
264 const uint8_t* const ref_ptr[], int ref_stride,
265 unsigned int *sad_array) {
266 int i;
267 for (i = 0; i < 4; ++i)
268 sad_array[i] = vp9_sad8x8(src_ptr, src_stride, ref_ptr[i], ref_stride,
269 0x7fffffff);
270 }
271
vp9_sad8x16x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)272 void vp9_sad8x16x4d_c(const uint8_t *src_ptr, int src_stride,
273 const uint8_t* const ref_ptr[], int ref_stride,
274 unsigned int *sad_array) {
275 int i;
276 for (i = 0; i < 4; ++i)
277 sad_array[i] = vp9_sad8x16(src_ptr, src_stride, ref_ptr[i], ref_stride,
278 0x7fffffff);
279 }
280
vp9_sad8x4x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)281 void vp9_sad8x4x4d_c(const uint8_t *src_ptr, int src_stride,
282 const uint8_t* const ref_ptr[], int ref_stride,
283 unsigned int *sad_array) {
284 int i;
285 for (i = 0; i < 4; ++i)
286 sad_array[i] = vp9_sad8x4(src_ptr, src_stride, ref_ptr[i], ref_stride,
287 0x7fffffff);
288 }
289
vp9_sad8x4x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,uint32_t * sad_array)290 void vp9_sad8x4x8_c(const uint8_t *src_ptr, int src_stride,
291 const uint8_t *ref_ptr, int ref_stride,
292 uint32_t *sad_array) {
293 int i;
294 for (i = 0; i < 8; ++i)
295 sad_array[i] = vp9_sad8x4(src_ptr, src_stride, ref_ptr + i, ref_stride,
296 0x7fffffff);
297 }
298
vp9_sad4x8x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)299 void vp9_sad4x8x4d_c(const uint8_t *src_ptr, int src_stride,
300 const uint8_t* const ref_ptr[], int ref_stride,
301 unsigned int *sad_array) {
302 int i;
303 for (i = 0; i < 4; ++i)
304 sad_array[i] = vp9_sad4x8(src_ptr, src_stride, ref_ptr[i], ref_stride,
305 0x7fffffff);
306 }
307
vp9_sad4x8x8_c(const uint8_t * src_ptr,int src_stride,const uint8_t * ref_ptr,int ref_stride,uint32_t * sad_array)308 void vp9_sad4x8x8_c(const uint8_t *src_ptr, int src_stride,
309 const uint8_t *ref_ptr, int ref_stride,
310 uint32_t *sad_array) {
311 int i;
312 for (i = 0; i < 8; ++i)
313 sad_array[i] = vp9_sad4x8(src_ptr, src_stride, ref_ptr + i, ref_stride,
314 0x7fffffff);
315 }
316
vp9_sad4x4x4d_c(const uint8_t * src_ptr,int src_stride,const uint8_t * const ref_ptr[],int ref_stride,unsigned int * sad_array)317 void vp9_sad4x4x4d_c(const uint8_t *src_ptr, int src_stride,
318 const uint8_t* const ref_ptr[], int ref_stride,
319 unsigned int *sad_array) {
320 int i;
321 for (i = 0; i < 4; ++i)
322 sad_array[i] = vp9_sad4x4(src_ptr, src_stride, ref_ptr[i], ref_stride,
323 0x7fffffff);
324 }
325