Blender V4.3
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
5#include "BLI_bit_span.hh"
6#include "BLI_bit_span_ops.hh"
7
8#include <ostream>
9
10namespace blender::bits {
11
13{
14 if (bit_range_.is_empty()) {
15 return;
16 }
18 {
20 const BitInt first_int_mask = mask_range_bits(ranges.prefix.start() & BitIndexMask,
21 ranges.prefix.size());
22 first_int |= first_int_mask;
23 }
24 {
25 BitInt *start = int_containing_bit(data_, ranges.aligned.start());
26 const int64_t ints_to_fill = ranges.aligned.size() / BitsPerInt;
27 constexpr BitInt fill_value = BitInt(-1);
28 initialized_fill_n(start, ints_to_fill, fill_value);
29 }
30 {
32 const BitInt last_int_mask = mask_first_n_bits(ranges.suffix.size());
33 last_int |= last_int_mask;
34 }
35}
36
38{
39 if (bit_range_.is_empty()) {
40 return;
41 }
43 {
45 const BitInt first_int_mask = mask_range_bits(ranges.prefix.start() & BitIndexMask,
46 ranges.prefix.size());
47 first_int &= ~first_int_mask;
48 }
49 {
50 BitInt *start = int_containing_bit(data_, ranges.aligned.start());
51 const int64_t ints_to_fill = ranges.aligned.size() / BitsPerInt;
52 constexpr BitInt fill_value = 0;
53 initialized_fill_n(start, ints_to_fill, fill_value);
54 }
55 {
57 const BitInt last_int_mask = mask_first_n_bits(ranges.suffix.size());
58 last_int &= ~last_int_mask;
59 }
60}
61
63{
64 BLI_assert(this->size() == other.size());
65 copy_from_or(*this, other);
66}
67
69{
70 BLI_assert(this->size() == other.size());
71 copy_from_or(*this, other);
72}
73
75{
76 BLI_assert(this->size() == other.size());
77 copy_from_or(*this, other);
78}
79
81{
82 BLI_assert(this->size() == other.size());
83 copy_from_or(*this, other);
84}
85
86std::ostream &operator<<(std::ostream &stream, const BitSpan &span)
87{
88 stream << "(Size: " << span.size() << ", ";
89 for (const BitRef bit : span) {
90 stream << bit;
91 }
92 stream << ")";
93 return stream;
94}
95
96std::ostream &operator<<(std::ostream &stream, const MutableBitSpan &span)
97{
98 return stream << BitSpan(span);
99}
100
101} // namespace blender::bits
#define BLI_assert(a)
Definition BLI_assert.h:50
constexpr int64_t one_after_last() const
constexpr bool is_empty() const
constexpr int64_t start() const
int64_t size() const
void copy_from(const BitSpan other)
Definition bit_span.cc:62
void copy_from(const BitSpan other)
Definition bit_span.cc:74
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:11
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)
__int64 int64_t
Definition stdint.h:89