variance_mmx.c 10.6 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
6
 *  that can be found in the LICENSE file in the root of the source
 *  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.
John Koleszar's avatar
John Koleszar committed
9
10
 */

11
#include "vpx_config.h"
12
13
#include "vp9/encoder/variance.h"
#include "vp9/common/pragmas.h"
John Koleszar's avatar
John Koleszar committed
14
15
16
17
#include "vpx_ports/mem.h"

extern void filter_block1d_h6_mmx
(
John Koleszar's avatar
John Koleszar committed
18
19
20
21
22
23
24
  const unsigned char *src_ptr,
  unsigned short *output_ptr,
  unsigned int src_pixels_per_line,
  unsigned int pixel_step,
  unsigned int output_height,
  unsigned int output_width,
  short *vp7_filter
John Koleszar's avatar
John Koleszar committed
25
26
27
);
extern void filter_block1d_v6_mmx
(
John Koleszar's avatar
John Koleszar committed
28
29
30
31
32
33
34
  const short *src_ptr,
  unsigned char *output_ptr,
  unsigned int pixels_per_line,
  unsigned int pixel_step,
  unsigned int output_height,
  unsigned int output_width,
  short *vp7_filter
John Koleszar's avatar
John Koleszar committed
35
36
);

37
38
extern unsigned int vp9_get_mb_ss_mmx(const short *src_ptr);
extern unsigned int vp9_get8x8var_mmx
John Koleszar's avatar
John Koleszar committed
39
(
John Koleszar's avatar
John Koleszar committed
40
41
42
43
44
45
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *SSE,
  int *Sum
John Koleszar's avatar
John Koleszar committed
46
);
47
extern unsigned int vp9_get4x4var_mmx
John Koleszar's avatar
John Koleszar committed
48
(
John Koleszar's avatar
John Koleszar committed
49
50
51
52
53
54
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *SSE,
  int *Sum
John Koleszar's avatar
John Koleszar committed
55
);
56
extern void vp9_filter_block2d_bil4x4_var_mmx
John Koleszar's avatar
John Koleszar committed
57
(
John Koleszar's avatar
John Koleszar committed
58
59
60
61
62
63
64
65
  const unsigned char *ref_ptr,
  int ref_pixels_per_line,
  const unsigned char *src_ptr,
  int src_pixels_per_line,
  const short *HFilter,
  const short *VFilter,
  int *sum,
  unsigned int *sumsquared
John Koleszar's avatar
John Koleszar committed
66
);
67
extern void vp9_filter_block2d_bil_var_mmx
John Koleszar's avatar
John Koleszar committed
68
(
John Koleszar's avatar
John Koleszar committed
69
70
71
72
73
74
75
76
77
  const unsigned char *ref_ptr,
  int ref_pixels_per_line,
  const unsigned char *src_ptr,
  int src_pixels_per_line,
  unsigned int Height,
  const short *HFilter,
  const short *VFilter,
  int *sum,
  unsigned int *sumsquared
John Koleszar's avatar
John Koleszar committed
78
79
80
);


81
unsigned int vp9_variance4x4_mmx(
John Koleszar's avatar
John Koleszar committed
82
83
84
85
86
87
88
89
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
  unsigned int var;
  int avg;

90
  vp9_get4x4var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &var, &avg);
John Koleszar's avatar
John Koleszar committed
91
  *sse = var;
92
  return (var - (((unsigned int)avg * avg) >> 4));
John Koleszar's avatar
John Koleszar committed
93
94
95

}

96
unsigned int vp9_variance8x8_mmx(
John Koleszar's avatar
John Koleszar committed
97
98
99
100
101
102
103
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
  unsigned int var;
  int avg;
John Koleszar's avatar
John Koleszar committed
104

105
  vp9_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &var, &avg);
John Koleszar's avatar
John Koleszar committed
106
  *sse = var;
John Koleszar's avatar
John Koleszar committed
107

108
  return (var - (((unsigned int)avg * avg) >> 6));
John Koleszar's avatar
John Koleszar committed
109
110
111

}

112
unsigned int vp9_mse16x16_mmx(
John Koleszar's avatar
John Koleszar committed
113
114
115
116
117
118
119
120
121
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
  unsigned int sse0, sse1, sse2, sse3, var;
  int sum0, sum1, sum2, sum3;


122
123
124
125
  vp9_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0);
  vp9_get8x8var_mmx(src_ptr + 8, source_stride, ref_ptr + 8, recon_stride, &sse1, &sum1);
  vp9_get8x8var_mmx(src_ptr + 8 * source_stride, source_stride, ref_ptr + 8 * recon_stride, recon_stride, &sse2, &sum2);
  vp9_get8x8var_mmx(src_ptr + 8 * source_stride + 8, source_stride, ref_ptr + 8 * recon_stride + 8, recon_stride, &sse3, &sum3);
John Koleszar's avatar
John Koleszar committed
126
127
128
129

  var = sse0 + sse1 + sse2 + sse3;
  *sse = var;
  return var;
John Koleszar's avatar
John Koleszar committed
130
131
132
}


133
unsigned int vp9_variance16x16_mmx(
John Koleszar's avatar
John Koleszar committed
134
135
136
137
138
139
140
141
142
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
  unsigned int sse0, sse1, sse2, sse3, var;
  int sum0, sum1, sum2, sum3, avg;


143
144
145
146
  vp9_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0);
  vp9_get8x8var_mmx(src_ptr + 8, source_stride, ref_ptr + 8, recon_stride, &sse1, &sum1);
  vp9_get8x8var_mmx(src_ptr + 8 * source_stride, source_stride, ref_ptr + 8 * recon_stride, recon_stride, &sse2, &sum2);
  vp9_get8x8var_mmx(src_ptr + 8 * source_stride + 8, source_stride, ref_ptr + 8 * recon_stride + 8, recon_stride, &sse3, &sum3);
John Koleszar's avatar
John Koleszar committed
147
148
149
150

  var = sse0 + sse1 + sse2 + sse3;
  avg = sum0 + sum1 + sum2 + sum3;
  *sse = var;
151
  return (var - (((unsigned int)avg * avg) >> 8));
John Koleszar's avatar
John Koleszar committed
152
153
}

154
unsigned int vp9_variance16x8_mmx(
John Koleszar's avatar
John Koleszar committed
155
156
157
158
159
160
161
162
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
  unsigned int sse0, sse1, var;
  int sum0, sum1, avg;

163
164
  vp9_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0);
  vp9_get8x8var_mmx(src_ptr + 8, source_stride, ref_ptr + 8, recon_stride, &sse1, &sum1);
John Koleszar's avatar
John Koleszar committed
165
166
167
168

  var = sse0 + sse1;
  avg = sum0 + sum1;
  *sse = var;
169
  return (var - (((unsigned int)avg * avg) >> 7));
John Koleszar's avatar
John Koleszar committed
170
171
172
173

}


174
unsigned int vp9_variance8x16_mmx(
John Koleszar's avatar
John Koleszar committed
175
176
177
178
179
180
181
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
  unsigned int sse0, sse1, var;
  int sum0, sum1, avg;
John Koleszar's avatar
John Koleszar committed
182

183
184
  vp9_get8x8var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0);
  vp9_get8x8var_mmx(src_ptr + 8 * source_stride, source_stride, ref_ptr + 8 * recon_stride, recon_stride, &sse1, &sum1);
John Koleszar's avatar
John Koleszar committed
185

John Koleszar's avatar
John Koleszar committed
186
187
188
  var = sse0 + sse1;
  avg = sum0 + sum1;
  *sse = var;
John Koleszar's avatar
John Koleszar committed
189

190
  return (var - (((unsigned int)avg * avg) >> 7));
John Koleszar's avatar
John Koleszar committed
191
192
193
194
195
196
197
198
199
200

}




///////////////////////////////////////////////////////////////////////////
// the mmx function that does the bilinear filtering and var calculation //
// int one pass                                                          //
///////////////////////////////////////////////////////////////////////////
201
DECLARE_ALIGNED(16, const short, vp9_bilinear_filters_mmx[16][8]) = {
John Koleszar's avatar
John Koleszar committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  { 128, 128, 128, 128,  0,  0,  0,  0 },
  { 120, 120, 120, 120,  8,  8,  8,  8 },
  { 112, 112, 112, 112, 16, 16, 16, 16 },
  { 104, 104, 104, 104, 24, 24, 24, 24 },
  {  96, 96, 96, 96, 32, 32, 32, 32 },
  {  88, 88, 88, 88, 40, 40, 40, 40 },
  {  80, 80, 80, 80, 48, 48, 48, 48 },
  {  72, 72, 72, 72, 56, 56, 56, 56 },
  {  64, 64, 64, 64, 64, 64, 64, 64 },
  {  56, 56, 56, 56, 72, 72, 72, 72 },
  {  48, 48, 48, 48, 80, 80, 80, 80 },
  {  40, 40, 40, 40, 88, 88, 88, 88 },
  {  32, 32, 32, 32, 96, 96, 96, 96 },
  {  24, 24, 24, 24, 104, 104, 104, 104 },
  {  16, 16, 16, 16, 112, 112, 112, 112 },
  {   8,  8,  8,  8, 120, 120, 120, 120 }
218
};
John Koleszar's avatar
John Koleszar committed
219

220
unsigned int vp9_sub_pixel_variance4x4_mmx
John Koleszar's avatar
John Koleszar committed
221
(
John Koleszar's avatar
John Koleszar committed
222
223
224
225
226
227
228
  const unsigned char  *src_ptr,
  int  src_pixels_per_line,
  int  xoffset,
  int  yoffset,
  const unsigned char *dst_ptr,
  int dst_pixels_per_line,
  unsigned int *sse)
John Koleszar's avatar
John Koleszar committed
229
230

{
John Koleszar's avatar
John Koleszar committed
231
232
  int xsum;
  unsigned int xxsum;
233
  vp9_filter_block2d_bil4x4_var_mmx(
John Koleszar's avatar
John Koleszar committed
234
235
    src_ptr, src_pixels_per_line,
    dst_ptr, dst_pixels_per_line,
236
    vp9_bilinear_filters_mmx[xoffset], vp9_bilinear_filters_mmx[yoffset],
John Koleszar's avatar
John Koleszar committed
237
238
239
    &xsum, &xxsum
  );
  *sse = xxsum;
240
  return (xxsum - (((unsigned int)xsum * xsum) >> 4));
John Koleszar's avatar
John Koleszar committed
241
242
243
}


244
unsigned int vp9_sub_pixel_variance8x8_mmx
John Koleszar's avatar
John Koleszar committed
245
(
John Koleszar's avatar
John Koleszar committed
246
247
248
249
250
251
252
253
254
255
256
  const unsigned char  *src_ptr,
  int  src_pixels_per_line,
  int  xoffset,
  int  yoffset,
  const unsigned char *dst_ptr,
  int dst_pixels_per_line,
  unsigned int *sse
) {

  int xsum;
  unsigned int xxsum;
257
  vp9_filter_block2d_bil_var_mmx(
John Koleszar's avatar
John Koleszar committed
258
259
    src_ptr, src_pixels_per_line,
    dst_ptr, dst_pixels_per_line, 8,
260
    vp9_bilinear_filters_mmx[xoffset], vp9_bilinear_filters_mmx[yoffset],
John Koleszar's avatar
John Koleszar committed
261
262
263
    &xsum, &xxsum
  );
  *sse = xxsum;
264
  return (xxsum - (((unsigned int)xsum * xsum) >> 6));
John Koleszar's avatar
John Koleszar committed
265
266
}

267
unsigned int vp9_sub_pixel_variance16x16_mmx
John Koleszar's avatar
John Koleszar committed
268
(
John Koleszar's avatar
John Koleszar committed
269
270
271
272
273
274
275
276
277
278
279
280
  const unsigned char  *src_ptr,
  int  src_pixels_per_line,
  int  xoffset,
  int  yoffset,
  const unsigned char *dst_ptr,
  int dst_pixels_per_line,
  unsigned int *sse
) {

  int xsum0, xsum1;
  unsigned int xxsum0, xxsum1;

281
  vp9_filter_block2d_bil_var_mmx(
John Koleszar's avatar
John Koleszar committed
282
283
    src_ptr, src_pixels_per_line,
    dst_ptr, dst_pixels_per_line, 16,
284
    vp9_bilinear_filters_mmx[xoffset], vp9_bilinear_filters_mmx[yoffset],
John Koleszar's avatar
John Koleszar committed
285
286
287
    &xsum0, &xxsum0
  );

288
  vp9_filter_block2d_bil_var_mmx(
John Koleszar's avatar
John Koleszar committed
289
290
    src_ptr + 8, src_pixels_per_line,
    dst_ptr + 8, dst_pixels_per_line, 16,
291
    vp9_bilinear_filters_mmx[xoffset], vp9_bilinear_filters_mmx[yoffset],
John Koleszar's avatar
John Koleszar committed
292
293
294
295
296
297
298
    &xsum1, &xxsum1
  );

  xsum0 += xsum1;
  xxsum0 += xxsum1;

  *sse = xxsum0;
299
  return (xxsum0 - (((unsigned int)xsum0 * xsum0) >> 8));
John Koleszar's avatar
John Koleszar committed
300
301
302
303


}

304
unsigned int vp9_sub_pixel_mse16x16_mmx(
John Koleszar's avatar
John Koleszar committed
305
306
307
308
309
310
311
312
  const unsigned char  *src_ptr,
  int  src_pixels_per_line,
  int  xoffset,
  int  yoffset,
  const unsigned char *dst_ptr,
  int dst_pixels_per_line,
  unsigned int *sse
) {
313
  vp9_sub_pixel_variance16x16_mmx(src_ptr, src_pixels_per_line, xoffset, yoffset, dst_ptr, dst_pixels_per_line, sse);
John Koleszar's avatar
John Koleszar committed
314
  return *sse;
John Koleszar's avatar
John Koleszar committed
315
316
}

317
unsigned int vp9_sub_pixel_variance16x8_mmx
John Koleszar's avatar
John Koleszar committed
318
(
John Koleszar's avatar
John Koleszar committed
319
320
321
322
323
324
325
326
327
328
329
330
  const unsigned char  *src_ptr,
  int  src_pixels_per_line,
  int  xoffset,
  int  yoffset,
  const unsigned char *dst_ptr,
  int dst_pixels_per_line,
  unsigned int *sse
) {
  int xsum0, xsum1;
  unsigned int xxsum0, xxsum1;


331
  vp9_filter_block2d_bil_var_mmx(
John Koleszar's avatar
John Koleszar committed
332
333
    src_ptr, src_pixels_per_line,
    dst_ptr, dst_pixels_per_line, 8,
334
    vp9_bilinear_filters_mmx[xoffset], vp9_bilinear_filters_mmx[yoffset],
John Koleszar's avatar
John Koleszar committed
335
336
337
338
    &xsum0, &xxsum0
  );


339
  vp9_filter_block2d_bil_var_mmx(
John Koleszar's avatar
John Koleszar committed
340
341
    src_ptr + 8, src_pixels_per_line,
    dst_ptr + 8, dst_pixels_per_line, 8,
342
    vp9_bilinear_filters_mmx[xoffset], vp9_bilinear_filters_mmx[yoffset],
John Koleszar's avatar
John Koleszar committed
343
344
345
346
347
348
349
    &xsum1, &xxsum1
  );

  xsum0 += xsum1;
  xxsum0 += xxsum1;

  *sse = xxsum0;
350
  return (xxsum0 - (((unsigned int)xsum0 * xsum0) >> 7));
John Koleszar's avatar
John Koleszar committed
351
352
}

353
unsigned int vp9_sub_pixel_variance8x16_mmx
John Koleszar's avatar
John Koleszar committed
354
(
John Koleszar's avatar
John Koleszar committed
355
356
357
358
359
360
361
362
363
364
  const unsigned char  *src_ptr,
  int  src_pixels_per_line,
  int  xoffset,
  int  yoffset,
  const unsigned char *dst_ptr,
  int dst_pixels_per_line,
  unsigned int *sse
) {
  int xsum;
  unsigned int xxsum;
365
  vp9_filter_block2d_bil_var_mmx(
John Koleszar's avatar
John Koleszar committed
366
367
    src_ptr, src_pixels_per_line,
    dst_ptr, dst_pixels_per_line, 16,
368
    vp9_bilinear_filters_mmx[xoffset], vp9_bilinear_filters_mmx[yoffset],
John Koleszar's avatar
John Koleszar committed
369
370
371
    &xsum, &xxsum
  );
  *sse = xxsum;
372
  return (xxsum - (((unsigned int)xsum * xsum) >> 7));
John Koleszar's avatar
John Koleszar committed
373
}
374
375


376
unsigned int vp9_variance_halfpixvar16x16_h_mmx(
John Koleszar's avatar
John Koleszar committed
377
378
379
380
381
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
382
  return vp9_sub_pixel_variance16x16_mmx(src_ptr, source_stride, 8, 0,
John Koleszar's avatar
John Koleszar committed
383
                                         ref_ptr, recon_stride, sse);
384
385
386
}


387
unsigned int vp9_variance_halfpixvar16x16_v_mmx(
John Koleszar's avatar
John Koleszar committed
388
389
390
391
392
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
393
  return vp9_sub_pixel_variance16x16_mmx(src_ptr, source_stride, 0, 8,
John Koleszar's avatar
John Koleszar committed
394
                                         ref_ptr, recon_stride, sse);
395
396
397
}


398
unsigned int vp9_variance_halfpixvar16x16_hv_mmx(
John Koleszar's avatar
John Koleszar committed
399
400
401
402
403
  const unsigned char *src_ptr,
  int  source_stride,
  const unsigned char *ref_ptr,
  int  recon_stride,
  unsigned int *sse) {
404
  return vp9_sub_pixel_variance16x16_mmx(src_ptr, source_stride, 8, 8,
John Koleszar's avatar
John Koleszar committed
405
                                         ref_ptr, recon_stride, sse);
406
}