Blender V5.0
bit_span.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_bit_span.hh"
10#include "BLI_bit_span_ops.hh"
11
12#include <ostream>
13
14namespace blender::bits {
15
17{
18 if (bit_range_.is_empty()) {
19 return;
20 }
22 {
23 BitInt &first_int = *int_containing_bit(data_, bit_range_.start());
24 const BitInt first_int_mask = mask_range_bits(ranges.prefix.start() & BitIndexMask,
25 ranges.prefix.size());
26 first_int |= first_int_mask;
27 }
28 {
29 BitInt *start = int_containing_bit(data_, ranges.aligned.start());
30 const int64_t ints_to_fill = ranges.aligned.size() / BitsPerInt;
31 constexpr BitInt fill_value = BitInt(-1);
32 initialized_fill_n(start, ints_to_fill, fill_value);
33 }
34 {
35 BitInt &last_int = *int_containing_bit(data_, bit_range_.one_after_last() - 1);
36 const BitInt last_int_mask = mask_first_n_bits(ranges.suffix.size());
37 last_int |= last_int_mask;
38 }
39}
40
42{
43 if (bit_range_.is_empty()) {
44 return;
45 }
47 {
48 BitInt &first_int = *int_containing_bit(data_, bit_range_.start());
49 const BitInt first_int_mask = mask_range_bits(ranges.prefix.start() & BitIndexMask,
50 ranges.prefix.size());
51 first_int &= ~first_int_mask;
52 }
53 {
54 BitInt *start = int_containing_bit(data_, ranges.aligned.start());
55 const int64_t ints_to_fill = ranges.aligned.size() / BitsPerInt;
56 constexpr BitInt fill_value = 0;
57 initialized_fill_n(start, ints_to_fill, fill_value);
58 }
59 {
60 BitInt &last_int = *int_containing_bit(data_, bit_range_.one_after_last() - 1);
61 const BitInt last_int_mask = mask_first_n_bits(ranges.suffix.size());
62 last_int &= ~last_int_mask;
63 }
64}
65
67{
68 BLI_assert(this->size() == other.size());
69 copy_from_or(*this, other);
70}
71
73{
74 BLI_assert(this->size() == other.size());
75 copy_from_or(*this, other);
76}
77
79{
80 BLI_assert(this->size() == other.size());
81 copy_from_or(*this, other);
82}
83
85{
86 BLI_assert(this->size() == other.size());
87 copy_from_or(*this, other);
88}
89
90std::ostream &operator<<(std::ostream &stream, const BitSpan &span)
91{
92 stream << "(Size: " << span.size() << ", ";
93 for (const BitRef bit : span) {
94 stream << bit;
95 }
96 stream << ")";
97 return stream;
98}
99
100std::ostream &operator<<(std::ostream &stream, const MutableBitSpan &span)
101{
102 return stream << BitSpan(span);
103}
104
105} // namespace blender::bits
#define BLI_assert(a)
Definition BLI_assert.h:46
long long int int64_t
constexpr int64_t size() const
constexpr int64_t start() const
int64_t size() const
void copy_from(const BitSpan other)
Definition bit_span.cc:66
void copy_from(const BitSpan other)
Definition bit_span.cc:78
uint64_t BitInt
static constexpr BitInt BitIndexMask
static constexpr int64_t BitsPerInt
BitInt * int_containing_bit(BitInt *data, const int64_t bit_index)
std::ostream & operator<<(std::ostream &stream, const BitRef &bit)
Definition bit_ref.cc:15
void copy_from_or(FirstBitSpanT &first_arg, const BitSpanT &...args)
BitInt mask_first_n_bits(const int64_t n)
BitInt mask_range_bits(const int64_t start, const int64_t size)
AlignedIndexRanges split_index_range_by_alignment(const IndexRange range, const int64_t alignment)
void initialized_fill_n(T *dst, int64_t n, const T &value)