Blender V5.0
index_range.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_index_range.hh"
10#include "BLI_utildefines.h"
11
12#include <ostream>
13
14namespace blender {
15
17{
18 BLI_assert(is_power_of_2(alignment));
19 const int64_t mask = alignment - 1;
20
21 AlignedIndexRanges aligned_ranges;
22
23 const int64_t start_chunk = range.start() & ~mask;
24 const int64_t end_chunk = range.one_after_last() & ~mask;
25 if (start_chunk == end_chunk) {
26 aligned_ranges.prefix = range;
27 }
28 else {
29 int64_t prefix_size = 0;
30 int64_t suffix_size = 0;
31 if (range.start() != start_chunk) {
32 prefix_size = alignment - (range.start() & mask);
33 }
34 if (range.one_after_last() != end_chunk) {
35 suffix_size = range.one_after_last() - end_chunk;
36 }
37 aligned_ranges.prefix = IndexRange(range.start(), prefix_size);
38 aligned_ranges.suffix = IndexRange(end_chunk, suffix_size);
39 aligned_ranges.aligned = IndexRange(aligned_ranges.prefix.one_after_last(),
40 range.size() - prefix_size - suffix_size);
41 }
42
43 return aligned_ranges;
44}
45
46std::ostream &operator<<(std::ostream &stream, IndexRange range)
47{
48 stream << '[' << range.start() << ", " << range.one_after_last() << ')';
49 return stream;
50}
51
52} // namespace blender
#define BLI_assert(a)
Definition BLI_assert.h:46
long long int int64_t
constexpr int64_t one_after_last() const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t start() const
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
AlignedIndexRanges split_index_range_by_alignment(const IndexRange range, const int64_t alignment)
std::ostream & operator<<(std::ostream &stream, const eAlpha &space)
Definition BLI_color.cc:15