variance_sse2.c 14 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"
John Koleszar's avatar
John Koleszar committed
12 13
#include "vp8/encoder/variance.h"
#include "vp8/common/pragmas.h"
John Koleszar's avatar
John Koleszar committed
14 15
#include "vpx_ports/mem.h"

16 17 18 19
extern void filter_block1d_h6_mmx(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);
extern void filter_block1d_v6_mmx(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);
extern void filter_block1d8_h6_sse2(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);
extern void filter_block1d8_v6_sse2(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
20 21 22

extern void vp8_filter_block2d_bil4x4_var_mmx
(
23
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
24
    int ref_pixels_per_line,
25
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
26 27 28 29 30 31 32 33 34
    int src_pixels_per_line,
    const short *HFilter,
    const short *VFilter,
    int *sum,
    unsigned int *sumsquared
);

extern unsigned int vp8_get4x4var_mmx
(
35
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
36
    int  source_stride,
37
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
38 39 40 41 42 43 44
    int  recon_stride,
    unsigned int *SSE,
    int *Sum
);

unsigned int vp8_get_mb_ss_sse2
(
45
    const short *src_ptr
John Koleszar's avatar
John Koleszar committed
46 47 48
);
unsigned int vp8_get16x16var_sse2
(
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 57
);
unsigned int vp8_get8x8var_sse2
(
58 59 60 61 62 63
    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
64 65 66
);
void vp8_filter_block2d_bil_var_sse2
(
67
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
68
    int ref_pixels_per_line,
69
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
70 71
    int src_pixels_per_line,
    unsigned int Height,
72 73
    int  xoffset,
    int  yoffset,
John Koleszar's avatar
John Koleszar committed
74 75 76
    int *sum,
    unsigned int *sumsquared
);
77 78 79 80 81 82 83 84 85 86
void vp8_half_horiz_vert_variance8x_h_sse2
(
    const unsigned char *ref_ptr,
    int ref_pixels_per_line,
    const unsigned char *src_ptr,
    int src_pixels_per_line,
    unsigned int Height,
    int *sum,
    unsigned int *sumsquared
);
John Koleszar's avatar
John Koleszar committed
87 88
void vp8_half_horiz_vert_variance16x_h_sse2
(
89
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
90
    int ref_pixels_per_line,
91
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
92 93 94 95 96
    int src_pixels_per_line,
    unsigned int Height,
    int *sum,
    unsigned int *sumsquared
);
97 98 99 100 101 102 103 104 105 106
void vp8_half_horiz_variance8x_h_sse2
(
    const unsigned char *ref_ptr,
    int ref_pixels_per_line,
    const unsigned char *src_ptr,
    int src_pixels_per_line,
    unsigned int Height,
    int *sum,
    unsigned int *sumsquared
);
John Koleszar's avatar
John Koleszar committed
107 108
void vp8_half_horiz_variance16x_h_sse2
(
109
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
110
    int ref_pixels_per_line,
111
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
112 113 114 115 116
    int src_pixels_per_line,
    unsigned int Height,
    int *sum,
    unsigned int *sumsquared
);
117 118 119 120 121 122 123 124 125 126
void vp8_half_vert_variance8x_h_sse2
(
    const unsigned char *ref_ptr,
    int ref_pixels_per_line,
    const unsigned char *src_ptr,
    int src_pixels_per_line,
    unsigned int Height,
    int *sum,
    unsigned int *sumsquared
);
John Koleszar's avatar
John Koleszar committed
127 128
void vp8_half_vert_variance16x_h_sse2
(
129
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
130
    int ref_pixels_per_line,
131
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
132 133 134 135 136 137 138 139 140
    int src_pixels_per_line,
    unsigned int Height,
    int *sum,
    unsigned int *sumsquared
);

DECLARE_ALIGNED(16, extern short, vp8_vp7_bilinear_filters_mmx[8][8]);

unsigned int vp8_variance4x4_wmt(
141
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
142
    int  source_stride,
143
    const unsigned char *ref_ptr,
144 145
    int  recon_stride,
    unsigned int *sse)
John Koleszar's avatar
John Koleszar committed
146 147 148 149 150
{
    unsigned int var;
    int avg;

    vp8_get4x4var_mmx(src_ptr, source_stride, ref_ptr, recon_stride, &var, &avg) ;
151
    *sse = var;
John Koleszar's avatar
John Koleszar committed
152 153 154 155 156 157
    return (var - ((avg * avg) >> 4));

}

unsigned int vp8_variance8x8_wmt
(
158
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
159
    int  source_stride,
160
    const unsigned char *ref_ptr,
161 162
    int  recon_stride,
    unsigned int *sse)
John Koleszar's avatar
John Koleszar committed
163 164 165 166 167
{
    unsigned int var;
    int avg;

    vp8_get8x8var_sse2(src_ptr, source_stride, ref_ptr, recon_stride, &var, &avg) ;
168
    *sse = var;
John Koleszar's avatar
John Koleszar committed
169 170 171 172 173 174 175
    return (var - ((avg * avg) >> 6));

}


unsigned int vp8_variance16x16_wmt
(
176
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
177
    int  source_stride,
178
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
179 180 181 182 183 184 185 186 187 188 189 190
    int  recon_stride,
    unsigned int *sse)
{
    unsigned int sse0;
    int sum0;


    vp8_get16x16var_sse2(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
    *sse = sse0;
    return (sse0 - ((sum0 * sum0) >> 8));
}
unsigned int vp8_mse16x16_wmt(
191
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
192
    int  source_stride,
193
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    int  recon_stride,
    unsigned int *sse)
{

    unsigned int sse0;
    int sum0;
    vp8_get16x16var_sse2(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
    *sse = sse0;
    return sse0;

}


unsigned int vp8_variance16x8_wmt
(
209
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
210
    int  source_stride,
211
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
    int  recon_stride,
    unsigned int *sse)
{
    unsigned int sse0, sse1, var;
    int sum0, sum1, avg;

    vp8_get8x8var_sse2(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
    vp8_get8x8var_sse2(src_ptr + 8, source_stride, ref_ptr + 8, recon_stride, &sse1, &sum1);

    var = sse0 + sse1;
    avg = sum0 + sum1;
    *sse = var;
    return (var - ((avg * avg) >> 7));

}

unsigned int vp8_variance8x16_wmt
(
230
    const unsigned char *src_ptr,
John Koleszar's avatar
John Koleszar committed
231
    int  source_stride,
232
    const unsigned char *ref_ptr,
John Koleszar's avatar
John Koleszar committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    int  recon_stride,
    unsigned int *sse)
{
    unsigned int sse0, sse1, var;
    int sum0, sum1, avg;

    vp8_get8x8var_sse2(src_ptr, source_stride, ref_ptr, recon_stride, &sse0, &sum0) ;
    vp8_get8x8var_sse2(src_ptr + 8 * source_stride, source_stride, ref_ptr + 8 * recon_stride, recon_stride, &sse1, &sum1) ;

    var = sse0 + sse1;
    avg = sum0 + sum1;
    *sse = var;
    return (var - ((avg * avg) >> 7));

}

unsigned int vp8_sub_pixel_variance4x4_wmt
(
251
    const unsigned char  *src_ptr,
John Koleszar's avatar
John Koleszar committed
252 253 254
    int  src_pixels_per_line,
    int  xoffset,
    int  yoffset,
255
    const unsigned char *dst_ptr,
John Koleszar's avatar
John Koleszar committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    int dst_pixels_per_line,
    unsigned int *sse
)
{
    int xsum;
    unsigned int xxsum;
    vp8_filter_block2d_bil4x4_var_mmx(
        src_ptr, src_pixels_per_line,
        dst_ptr, dst_pixels_per_line,
        vp8_vp7_bilinear_filters_mmx[xoffset], vp8_vp7_bilinear_filters_mmx[yoffset],
        &xsum, &xxsum
    );
    *sse = xxsum;
    return (xxsum - ((xsum * xsum) >> 4));
}


unsigned int vp8_sub_pixel_variance8x8_wmt
(
275
    const unsigned char  *src_ptr,
John Koleszar's avatar
John Koleszar committed
276 277 278
    int  src_pixels_per_line,
    int  xoffset,
    int  yoffset,
279
    const unsigned char *dst_ptr,
John Koleszar's avatar
John Koleszar committed
280 281 282 283 284 285
    int dst_pixels_per_line,
    unsigned int *sse
)
{
    int xsum;
    unsigned int xxsum;
286 287 288

    if (xoffset == 4 && yoffset == 0)
    {
289
        vp8_half_horiz_variance8x_h_sse2(
290 291 292 293 294 295
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 8,
            &xsum, &xxsum);
    }
    else if (xoffset == 0 && yoffset == 4)
    {
296
        vp8_half_vert_variance8x_h_sse2(
297 298 299 300 301 302
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 8,
            &xsum, &xxsum);
    }
    else if (xoffset == 4 && yoffset == 4)
    {
303
        vp8_half_horiz_vert_variance8x_h_sse2(
304 305 306 307 308 309 310 311 312 313 314 315
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 8,
            &xsum, &xxsum);
    }
    else
    {
        vp8_filter_block2d_bil_var_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 8,
            xoffset, yoffset,
            &xsum, &xxsum);
    }
John Koleszar's avatar
John Koleszar committed
316 317 318 319 320 321 322

    *sse = xxsum;
    return (xxsum - ((xsum * xsum) >> 6));
}

unsigned int vp8_sub_pixel_variance16x16_wmt
(
323
    const unsigned char  *src_ptr,
John Koleszar's avatar
John Koleszar committed
324 325 326
    int  src_pixels_per_line,
    int  xoffset,
    int  yoffset,
327
    const unsigned char *dst_ptr,
John Koleszar's avatar
John Koleszar committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
    int dst_pixels_per_line,
    unsigned int *sse
)
{
    int xsum0, xsum1;
    unsigned int xxsum0, xxsum1;


    // note we could avoid these if statements if the calling function
    // just called the appropriate functions inside.
    if (xoffset == 4 && yoffset == 0)
    {
        vp8_half_horiz_variance16x_h_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 16,
            &xsum0, &xxsum0);
    }
    else if (xoffset == 0 && yoffset == 4)
    {
        vp8_half_vert_variance16x_h_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 16,
            &xsum0, &xxsum0);
    }
    else if (xoffset == 4 && yoffset == 4)
    {
        vp8_half_horiz_vert_variance16x_h_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 16,
            &xsum0, &xxsum0);
    }
    else
    {
        vp8_filter_block2d_bil_var_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 16,
364
            xoffset, yoffset,
John Koleszar's avatar
John Koleszar committed
365 366 367 368 369 370
            &xsum0, &xxsum0
        );

        vp8_filter_block2d_bil_var_sse2(
            src_ptr + 8, src_pixels_per_line,
            dst_ptr + 8, dst_pixels_per_line, 16,
371
            xoffset, yoffset,
John Koleszar's avatar
John Koleszar committed
372 373
            &xsum1, &xxsum1
        );
374 375
        xsum0 += xsum1;
        xxsum0 += xxsum1;
John Koleszar's avatar
John Koleszar committed
376 377 378 379 380 381 382
    }

    *sse = xxsum0;
    return (xxsum0 - ((xsum0 * xsum0) >> 8));
}

unsigned int vp8_sub_pixel_mse16x16_wmt(
383
    const unsigned char  *src_ptr,
John Koleszar's avatar
John Koleszar committed
384 385 386
    int  src_pixels_per_line,
    int  xoffset,
    int  yoffset,
387
    const unsigned char *dst_ptr,
John Koleszar's avatar
John Koleszar committed
388 389 390 391 392 393 394 395 396 397
    int dst_pixels_per_line,
    unsigned int *sse
)
{
    vp8_sub_pixel_variance16x16_wmt(src_ptr, src_pixels_per_line, xoffset, yoffset, dst_ptr, dst_pixels_per_line, sse);
    return *sse;
}

unsigned int vp8_sub_pixel_variance16x8_wmt
(
398
    const unsigned char  *src_ptr,
John Koleszar's avatar
John Koleszar committed
399 400 401
    int  src_pixels_per_line,
    int  xoffset,
    int  yoffset,
402
    const unsigned char *dst_ptr,
John Koleszar's avatar
John Koleszar committed
403 404 405 406 407 408 409 410
    int dst_pixels_per_line,
    unsigned int *sse

)
{
    int xsum0, xsum1;
    unsigned int xxsum0, xxsum1;

411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
    if (xoffset == 4 && yoffset == 0)
    {
        vp8_half_horiz_variance16x_h_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 8,
            &xsum0, &xxsum0);
    }
    else if (xoffset == 0 && yoffset == 4)
    {
        vp8_half_vert_variance16x_h_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 8,
            &xsum0, &xxsum0);
    }
    else if (xoffset == 4 && yoffset == 4)
    {
        vp8_half_horiz_vert_variance16x_h_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 8,
            &xsum0, &xxsum0);
    }
    else
    {
        vp8_filter_block2d_bil_var_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 8,
            xoffset, yoffset,
            &xsum0, &xxsum0);
John Koleszar's avatar
John Koleszar committed
439

440 441 442 443 444
        vp8_filter_block2d_bil_var_sse2(
            src_ptr + 8, src_pixels_per_line,
            dst_ptr + 8, dst_pixels_per_line, 8,
            xoffset, yoffset,
            &xsum1, &xxsum1);
445 446
        xsum0 += xsum1;
        xxsum0 += xxsum1;
447
    }
John Koleszar's avatar
John Koleszar committed
448 449 450 451 452 453 454

    *sse = xxsum0;
    return (xxsum0 - ((xsum0 * xsum0) >> 7));
}

unsigned int vp8_sub_pixel_variance8x16_wmt
(
455
    const unsigned char  *src_ptr,
John Koleszar's avatar
John Koleszar committed
456 457 458
    int  src_pixels_per_line,
    int  xoffset,
    int  yoffset,
459
    const unsigned char *dst_ptr,
John Koleszar's avatar
John Koleszar committed
460 461 462 463 464 465
    int dst_pixels_per_line,
    unsigned int *sse
)
{
    int xsum;
    unsigned int xxsum;
466 467 468

    if (xoffset == 4 && yoffset == 0)
    {
469
        vp8_half_horiz_variance8x_h_sse2(
470 471 472 473 474 475
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 16,
            &xsum, &xxsum);
    }
    else if (xoffset == 0 && yoffset == 4)
    {
476
        vp8_half_vert_variance8x_h_sse2(
477 478 479 480 481 482
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 16,
            &xsum, &xxsum);
    }
    else if (xoffset == 4 && yoffset == 4)
    {
483
        vp8_half_horiz_vert_variance8x_h_sse2(
484 485 486 487 488 489 490 491 492 493 494 495
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 16,
            &xsum, &xxsum);
    }
    else
    {
        vp8_filter_block2d_bil_var_sse2(
            src_ptr, src_pixels_per_line,
            dst_ptr, dst_pixels_per_line, 16,
            xoffset, yoffset,
            &xsum, &xxsum);
    }
John Koleszar's avatar
John Koleszar committed
496 497 498 499 500

    *sse = xxsum;
    return (xxsum - ((xsum * xsum) >> 7));
}

501 502 503 504 505 506 507 508

unsigned int vp8_variance_halfpixvar16x16_h_wmt(
    const unsigned char *src_ptr,
    int  src_pixels_per_line,
    const unsigned char *dst_ptr,
    int  dst_pixels_per_line,
    unsigned int *sse)
{
509 510
    int xsum0;
    unsigned int xxsum0;
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528

    vp8_half_horiz_variance16x_h_sse2(
        src_ptr, src_pixels_per_line,
        dst_ptr, dst_pixels_per_line, 16,
        &xsum0, &xxsum0);

    *sse = xxsum0;
    return (xxsum0 - ((xsum0 * xsum0) >> 8));
}


unsigned int vp8_variance_halfpixvar16x16_v_wmt(
    const unsigned char *src_ptr,
    int  src_pixels_per_line,
    const unsigned char *dst_ptr,
    int  dst_pixels_per_line,
    unsigned int *sse)
{
529 530
    int xsum0;
    unsigned int xxsum0;
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
    vp8_half_vert_variance16x_h_sse2(
        src_ptr, src_pixels_per_line,
        dst_ptr, dst_pixels_per_line, 16,
        &xsum0, &xxsum0);

    *sse = xxsum0;
    return (xxsum0 - ((xsum0 * xsum0) >> 8));
}


unsigned int vp8_variance_halfpixvar16x16_hv_wmt(
    const unsigned char *src_ptr,
    int  src_pixels_per_line,
    const unsigned char *dst_ptr,
    int  dst_pixels_per_line,
    unsigned int *sse)
{
548 549
    int xsum0;
    unsigned int xxsum0;
550 551 552 553 554 555 556 557 558

    vp8_half_horiz_vert_variance16x_h_sse2(
        src_ptr, src_pixels_per_line,
        dst_ptr, dst_pixels_per_line, 16,
        &xsum0, &xxsum0);

    *sse = xxsum0;
    return (xxsum0 - ((xsum0 * xsum0) >> 8));
}