Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/media/libyuv/libyuv/source/compare_common.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *  Copyright 2012 The LibYuv 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 "libyuv/basic_types.h"
12
13
#include "libyuv/compare_row.h"
14
15
#ifdef __cplusplus
16
namespace libyuv {
17
extern "C" {
18
#endif
19
20
#if ORIGINAL_OPT
21
uint32_t HammingDistance_C1(const uint8_t* src_a,
22
                            const uint8_t* src_b,
23
                            int count) {
24
  uint32_t diff = 0u;
25
26
  int i;
27
  for (i = 0; i < count; ++i) {
28
    int x = src_a[i] ^ src_b[i];
29
    if (x & 1)
30
      ++diff;
31
    if (x & 2)
32
      ++diff;
33
    if (x & 4)
34
      ++diff;
35
    if (x & 8)
36
      ++diff;
37
    if (x & 16)
38
      ++diff;
39
    if (x & 32)
40
      ++diff;
41
    if (x & 64)
42
      ++diff;
43
    if (x & 128)
44
      ++diff;
45
  }
46
  return diff;
47
}
48
#endif
49
50
// Hakmem method for hamming distance.
51
uint32_t HammingDistance_C(const uint8_t* src_a,
52
                           const uint8_t* src_b,
53
0
                           int count) {
54
0
  uint32_t diff = 0u;
55
0
56
0
  int i;
57
0
  for (i = 0; i < count - 3; i += 4) {
58
0
    uint32_t x = *((uint32_t*)src_a) ^ *((uint32_t*)src_b);  // NOLINT
59
0
    uint32_t u = x - ((x >> 1) & 0x55555555);
60
0
    u = ((u >> 2) & 0x33333333) + (u & 0x33333333);
61
0
    diff += ((((u + (u >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24);
62
0
    src_a += 4;
63
0
    src_b += 4;
64
0
  }
65
0
66
0
  for (; i < count; ++i) {
67
0
    uint32_t x = *src_a ^ *src_b;
68
0
    uint32_t u = x - ((x >> 1) & 0x55);
69
0
    u = ((u >> 2) & 0x33) + (u & 0x33);
70
0
    diff += (u + (u >> 4)) & 0x0f;
71
0
    src_a += 1;
72
0
    src_b += 1;
73
0
  }
74
0
75
0
  return diff;
76
0
}
77
78
uint32_t SumSquareError_C(const uint8_t* src_a,
79
                          const uint8_t* src_b,
80
0
                          int count) {
81
0
  uint32_t sse = 0u;
82
0
  int i;
83
0
  for (i = 0; i < count; ++i) {
84
0
    int diff = src_a[i] - src_b[i];
85
0
    sse += (uint32_t)(diff * diff);
86
0
  }
87
0
  return sse;
88
0
}
89
90
// hash seed of 5381 recommended.
91
// Internal C version of HashDjb2 with int sized count for efficiency.
92
0
uint32_t HashDjb2_C(const uint8_t* src, int count, uint32_t seed) {
93
0
  uint32_t hash = seed;
94
0
  int i;
95
0
  for (i = 0; i < count; ++i) {
96
0
    hash += (hash << 5) + src[i];
97
0
  }
98
0
  return hash;
99
0
}
100
101
#ifdef __cplusplus
102
}  // extern "C"
103
}  // namespace libyuv
104
#endif