2 * Copyright (c) 2010 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.
12 #include "vp8/encoder/variance.h"
13 #include "vp8/common/pragmas.h"
14 #include "vpx_ports/mem.h"
16 extern void filter_block1d_h6_mmx
18 const unsigned char *src_ptr,
19 unsigned short *output_ptr,
20 unsigned int src_pixels_per_line,
21 unsigned int pixel_step,
22 unsigned int output_height,
23 unsigned int output_width,
26 extern void filter_block1d_v6_mmx
29 unsigned char *output_ptr,
30 unsigned int pixels_per_line,
31 unsigned int pixel_step,
32 unsigned int output_height,
33 unsigned int output_width,
37 extern unsigned int vp8_get_mb_ss_mmx(short *src_ptr);
38 extern unsigned int vp8_get8x8var_mmx
40 const unsigned char *src_ptr,
42 const unsigned char *ref_ptr,
47 extern unsigned int vp8_get4x4var_mmx
49 const unsigned char *src_ptr,
51 const unsigned char *ref_ptr,
56 extern void vp8_filter_block2d_bil4x4_var_mmx
58 const unsigned char *ref_ptr,
59 int ref_pixels_per_line,
60 const unsigned char *src_ptr,
61 int src_pixels_per_line,
65 unsigned int *sumsquared
67 extern void vp8_filter_block2d_bil_var_mmx
69 const unsigned char *ref_ptr,
70 int ref_pixels_per_line,
71 const unsigned char *src_ptr,
72 int src_pixels_per_line,
77 unsigned int *sumsquared
79 extern unsigned int vp8_get16x16pred_error_mmx
81 unsigned char *src_ptr,
83 unsigned char *ref_ptr,
88 unsigned int vp8_get16x16var_mmx(
89 const unsigned char *src_ptr,
91 const unsigned char *ref_ptr,
97 unsigned int sse0, sse1, sse2, sse3, var;
98 int sum0, sum1, sum2, sum3, avg;
101 vp8_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
102 vp8_get8x8var_mmx(src_ptr + 8, source_stride, ref_ptr + 8, recon_stride, &sse1, &sum1);
103 vp8_get8x8var_mmx(src_ptr + 8 * source_stride, source_stride, ref_ptr + 8 * recon_stride, recon_stride, &sse2, &sum2) ;
104 vp8_get8x8var_mmx(src_ptr + 8 * source_stride + 8, source_stride, ref_ptr + 8 * recon_stride + 8, recon_stride, &sse3, &sum3);
106 var = sse0 + sse1 + sse2 + sse3;
107 avg = sum0 + sum1 + sum2 + sum3;
111 return (var - ((avg * avg) >> 8));
119 unsigned int vp8_variance4x4_mmx(
120 const unsigned char *src_ptr,
122 const unsigned char *ref_ptr,
129 vp8_get4x4var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &var, &avg) ;
131 return (var - ((avg * avg) >> 4));
135 unsigned int vp8_variance8x8_mmx(
136 const unsigned char *src_ptr,
138 const unsigned char *ref_ptr,
145 vp8_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &var, &avg) ;
148 return (var - ((avg * avg) >> 6));
152 unsigned int vp8_mse16x16_mmx(
153 const unsigned char *src_ptr,
155 const unsigned char *ref_ptr,
159 unsigned int sse0, sse1, sse2, sse3, var;
160 int sum0, sum1, sum2, sum3;
163 vp8_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
164 vp8_get8x8var_mmx(src_ptr + 8, source_stride, ref_ptr + 8, recon_stride, &sse1, &sum1);
165 vp8_get8x8var_mmx(src_ptr + 8 * source_stride, source_stride, ref_ptr + 8 * recon_stride, recon_stride, &sse2, &sum2) ;
166 vp8_get8x8var_mmx(src_ptr + 8 * source_stride + 8, source_stride, ref_ptr + 8 * recon_stride + 8, recon_stride, &sse3, &sum3);
168 var = sse0 + sse1 + sse2 + sse3;
174 unsigned int vp8_variance16x16_mmx(
175 const unsigned char *src_ptr,
177 const unsigned char *ref_ptr,
181 unsigned int sse0, sse1, sse2, sse3, var;
182 int sum0, sum1, sum2, sum3, avg;
185 vp8_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
186 vp8_get8x8var_mmx(src_ptr + 8, source_stride, ref_ptr + 8, recon_stride, &sse1, &sum1);
187 vp8_get8x8var_mmx(src_ptr + 8 * source_stride, source_stride, ref_ptr + 8 * recon_stride, recon_stride, &sse2, &sum2) ;
188 vp8_get8x8var_mmx(src_ptr + 8 * source_stride + 8, source_stride, ref_ptr + 8 * recon_stride + 8, recon_stride, &sse3, &sum3);
190 var = sse0 + sse1 + sse2 + sse3;
191 avg = sum0 + sum1 + sum2 + sum3;
193 return (var - ((avg * avg) >> 8));
196 unsigned int vp8_variance16x8_mmx(
197 const unsigned char *src_ptr,
199 const unsigned char *ref_ptr,
203 unsigned int sse0, sse1, var;
206 vp8_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
207 vp8_get8x8var_mmx(src_ptr + 8, source_stride, ref_ptr + 8, recon_stride, &sse1, &sum1);
212 return (var - ((avg * avg) >> 7));
217 unsigned int vp8_variance8x16_mmx(
218 const unsigned char *src_ptr,
220 const unsigned char *ref_ptr,
224 unsigned int sse0, sse1, var;
227 vp8_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
228 vp8_get8x8var_mmx(src_ptr + 8 * source_stride, source_stride, ref_ptr + 8 * recon_stride, recon_stride, &sse1, &sum1) ;
234 return (var - ((avg * avg) >> 7));
241 ///////////////////////////////////////////////////////////////////////////
242 // the mmx function that does the bilinear filtering and var calculation //
244 ///////////////////////////////////////////////////////////////////////////
245 DECLARE_ALIGNED(16, const short, vp8_vp7_bilinear_filters_mmx[8][8]) =
247 { 128, 128, 128, 128, 0, 0, 0, 0 },
248 { 112, 112, 112, 112, 16, 16, 16, 16 },
249 { 96, 96, 96, 96, 32, 32, 32, 32 },
250 { 80, 80, 80, 80, 48, 48, 48, 48 },
251 { 64, 64, 64, 64, 64, 64, 64, 64 },
252 { 48, 48, 48, 48, 80, 80, 80, 80 },
253 { 32, 32, 32, 32, 96, 96, 96, 96 },
254 { 16, 16, 16, 16, 112, 112, 112, 112 }
257 unsigned int vp8_sub_pixel_variance4x4_mmx
259 const unsigned char *src_ptr,
260 int src_pixels_per_line,
263 const unsigned char *dst_ptr,
264 int dst_pixels_per_line,
270 vp8_filter_block2d_bil4x4_var_mmx(
271 src_ptr, src_pixels_per_line,
272 dst_ptr, dst_pixels_per_line,
273 vp8_vp7_bilinear_filters_mmx[xoffset], vp8_vp7_bilinear_filters_mmx[yoffset],
277 return (xxsum - ((xsum * xsum) >> 4));
281 unsigned int vp8_sub_pixel_variance8x8_mmx
283 const unsigned char *src_ptr,
284 int src_pixels_per_line,
287 const unsigned char *dst_ptr,
288 int dst_pixels_per_line,
295 vp8_filter_block2d_bil_var_mmx(
296 src_ptr, src_pixels_per_line,
297 dst_ptr, dst_pixels_per_line, 8,
298 vp8_vp7_bilinear_filters_mmx[xoffset], vp8_vp7_bilinear_filters_mmx[yoffset],
302 return (xxsum - ((xsum * xsum) >> 6));
305 unsigned int vp8_sub_pixel_variance16x16_mmx
307 const unsigned char *src_ptr,
308 int src_pixels_per_line,
311 const unsigned char *dst_ptr,
312 int dst_pixels_per_line,
318 unsigned int xxsum0, xxsum1;
321 vp8_filter_block2d_bil_var_mmx(
322 src_ptr, src_pixels_per_line,
323 dst_ptr, dst_pixels_per_line, 16,
324 vp8_vp7_bilinear_filters_mmx[xoffset], vp8_vp7_bilinear_filters_mmx[yoffset],
329 vp8_filter_block2d_bil_var_mmx(
330 src_ptr + 8, src_pixels_per_line,
331 dst_ptr + 8, dst_pixels_per_line, 16,
332 vp8_vp7_bilinear_filters_mmx[xoffset], vp8_vp7_bilinear_filters_mmx[yoffset],
340 return (xxsum0 - ((xsum0 * xsum0) >> 8));
345 unsigned int vp8_sub_pixel_mse16x16_mmx(
346 const unsigned char *src_ptr,
347 int src_pixels_per_line,
350 const unsigned char *dst_ptr,
351 int dst_pixels_per_line,
355 vp8_sub_pixel_variance16x16_mmx(src_ptr, src_pixels_per_line, xoffset, yoffset, dst_ptr, dst_pixels_per_line, sse);
359 unsigned int vp8_sub_pixel_variance16x8_mmx
361 const unsigned char *src_ptr,
362 int src_pixels_per_line,
365 const unsigned char *dst_ptr,
366 int dst_pixels_per_line,
371 unsigned int xxsum0, xxsum1;
374 vp8_filter_block2d_bil_var_mmx(
375 src_ptr, src_pixels_per_line,
376 dst_ptr, dst_pixels_per_line, 8,
377 vp8_vp7_bilinear_filters_mmx[xoffset], vp8_vp7_bilinear_filters_mmx[yoffset],
382 vp8_filter_block2d_bil_var_mmx(
383 src_ptr + 8, src_pixels_per_line,
384 dst_ptr + 8, dst_pixels_per_line, 8,
385 vp8_vp7_bilinear_filters_mmx[xoffset], vp8_vp7_bilinear_filters_mmx[yoffset],
393 return (xxsum0 - ((xsum0 * xsum0) >> 7));
396 unsigned int vp8_sub_pixel_variance8x16_mmx
398 const unsigned char *src_ptr,
399 int src_pixels_per_line,
402 const unsigned char *dst_ptr,
403 int dst_pixels_per_line,
409 vp8_filter_block2d_bil_var_mmx(
410 src_ptr, src_pixels_per_line,
411 dst_ptr, dst_pixels_per_line, 16,
412 vp8_vp7_bilinear_filters_mmx[xoffset], vp8_vp7_bilinear_filters_mmx[yoffset],
416 return (xxsum - ((xsum * xsum) >> 7));
420 unsigned int vp8_variance_halfpixvar16x16_h_mmx(
421 const unsigned char *src_ptr,
423 const unsigned char *ref_ptr,
427 return vp8_sub_pixel_variance16x16_mmx(src_ptr, source_stride, 4, 0,
428 ref_ptr, recon_stride, sse);
432 unsigned int vp8_variance_halfpixvar16x16_v_mmx(
433 const unsigned char *src_ptr,
435 const unsigned char *ref_ptr,
439 return vp8_sub_pixel_variance16x16_mmx(src_ptr, source_stride, 0, 4,
440 ref_ptr, recon_stride, sse);
444 unsigned int vp8_variance_halfpixvar16x16_hv_mmx(
445 const unsigned char *src_ptr,
447 const unsigned char *ref_ptr,
451 return vp8_sub_pixel_variance16x16_mmx(src_ptr, source_stride, 4, 4,
452 ref_ptr, recon_stride, sse);