Blender V4.3
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
5#include "BLI_index_range.hh"
6#include "BLI_utildefines.h"
7
8#include <ostream>
9
10namespace blender {
11
13{
14 BLI_assert(is_power_of_2(alignment));
15 const int64_t mask = alignment - 1;
16
17 AlignedIndexRanges aligned_ranges;
18
19 const int64_t start_chunk = range.start() & ~mask;
20 const int64_t end_chunk = range.one_after_last() & ~mask;
21 if (start_chunk == end_chunk) {
22 aligned_ranges.prefix = range;
23 }
24 else {
25 int64_t prefix_size = 0;
26 int64_t suffix_size = 0;
27 if (range.start() != start_chunk) {
28 prefix_size = alignment - (range.start() & mask);
29 }
30 if (range.one_after_last() != end_chunk) {
31 suffix_size = range.one_after_last() - end_chunk;
32 }
33 aligned_ranges.prefix = IndexRange(range.start(), prefix_size);
34 aligned_ranges.suffix = IndexRange(end_chunk, suffix_size);
35 aligned_ranges.aligned = IndexRange(aligned_ranges.prefix.one_after_last(),
36 range.size() - prefix_size - suffix_size);
37 }
38
39 return aligned_ranges;
40}
41
42std::ostream &operator<<(std::ostream &stream, IndexRange range)
43{
44 stream << '[' << range.start() << ", " << range.one_after_last() << ')';
45 return stream;
46}
47
48} // namespace blender
#define BLI_assert(a)
Definition BLI_assert.h:50
constexpr int64_t one_after_last() const
IndexRange range
ccl_device_inline float4 mask(const int4 mask, const float4 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:11
__int64 int64_t
Definition stdint.h:89