Coverage Report

Created: 2023-03-01 07:33

/src/spirv-tools/source/util/bit_vector.cpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2018 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "source/util/bit_vector.h"
16
17
#include <cassert>
18
#include <iostream>
19
20
namespace spvtools {
21
namespace utils {
22
23
0
void BitVector::ReportDensity(std::ostream& out) {
24
0
  uint32_t count = 0;
25
26
0
  for (BitContainer e : bits_) {
27
0
    while (e != 0) {
28
0
      if ((e & 1) != 0) {
29
0
        ++count;
30
0
      }
31
0
      e = e >> 1;
32
0
    }
33
0
  }
34
35
0
  out << "count=" << count
36
0
      << ", total size (bytes)=" << bits_.size() * sizeof(BitContainer)
37
0
      << ", bytes per element="
38
0
      << (double)(bits_.size() * sizeof(BitContainer)) / (double)(count);
39
0
}
40
41
1.02M
bool BitVector::Or(const BitVector& other) {
42
1.02M
  auto this_it = this->bits_.begin();
43
1.02M
  auto other_it = other.bits_.begin();
44
1.02M
  bool modified = false;
45
46
2.05M
  while (this_it != this->bits_.end() && other_it != other.bits_.end()) {
47
1.02M
    auto temp = *this_it | *other_it;
48
1.02M
    if (temp != *this_it) {
49
220k
      modified = true;
50
220k
      *this_it = temp;
51
220k
    }
52
1.02M
    ++this_it;
53
1.02M
    ++other_it;
54
1.02M
  }
55
56
1.02M
  if (other_it != other.bits_.end()) {
57
0
    modified = true;
58
0
    this->bits_.insert(this->bits_.end(), other_it, other.bits_.end());
59
0
  }
60
61
1.02M
  return modified;
62
1.02M
}
63
64
0
std::ostream& operator<<(std::ostream& out, const BitVector& bv) {
65
0
  out << "{";
66
0
  for (uint32_t i = 0; i < bv.bits_.size(); ++i) {
67
0
    BitVector::BitContainer b = bv.bits_[i];
68
0
    uint32_t j = 0;
69
0
    while (b != 0) {
70
0
      if (b & 1) {
71
0
        out << ' ' << i * BitVector::kBitContainerSize + j;
72
0
      }
73
0
      ++j;
74
0
      b = b >> 1;
75
0
    }
76
0
  }
77
0
  out << "}";
78
0
  return out;
79
0
}
80
81
}  // namespace utils
82
}  // namespace spvtools