23#ifndef NANOVDB_UTIL_MASKPREFIXSUM_H_HAS_BEEN_INCLUDED
24#define NANOVDB_UTIL_MASKPREFIXSUM_H_HAS_BEEN_INCLUDED
41static constexpr uint64_t kSpread = UINT64_C(0x0101010101010101);
61inline uint64_t transposeByteRow(uint64_t src)
63 uint64_t v = src & 0xFFu;
65 v = (v | (v << 14) | (v << 28) | (v << 42)) & UINT64_C(0x0003000300030003);
67 v = (v | (v << 7)) & UINT64_C(0x0101010101010101);
99template <
bool Invert = false>
103 uint16_t offsets[512])
105 const uint64_t *maskWords = mask.
words();
107 alignas(64) QWord data[8][8];
118 for (
int x = 0; x < 8; x++) {
119 const uint64_t word = Invert ? ~maskWords[x] : maskWords[x];
121 for (
int y = 0; y < 8; y++)
122 data[x][y].ui64 = transposeByteRow(word >> (y * 8));
136 for (
int x = 0; x < 8; x++) {
138 for (
int y = 0; y < 8; y++) {
139 uint64_t& zRow = data[x][y].ui64;
160 alignas(64) QWord shifts[8][8];
161 for (
int x = 0; x < 8; x++) {
163 for (
int y = 0; y < 8; y++)
164 shifts[x][y].ui64 = data[x][y].ui64 >> 56;
168 alignas(64) QWord rowOffset[8][8];
169 for (
int x = 0; x < 8; x++)
170 rowOffset[x][0].ui64 = 0;
171 for (
int y = 1; y < 8; y++)
172 for (
int x = 0; x < 8; x++)
173 rowOffset[x][y].ui64 = rowOffset[x][y-1].ui64 + shifts[x][y-1].ui64;
176 for (
int x = 0; x < 8; x++) {
178 for (
int y = 0; y < 8; y++)
179 data[x][y].ui64 += rowOffset[x][y].ui64 * kSpread;
191 for (
int x = 0; x < 8; x++)
192 for (
int y = 0; y < 8; y++)
193 for (
int z = 0; z < 8; z++)
194 offsets[x*64 + y*8 + z] = data[x][y].ui8[z];
205 for (
int x = 1; x < 8; x++) {
206 const uint16_t ones =
static_cast<uint16_t
>((
prefixSum >> (9*(x-1))) & 0x1FFu);
207 if constexpr (Invert)
208 xOffset[x] =
static_cast<uint16_t
>(64 * x) - ones;
213 for (
int x = 0; x < 8; x++) {
214 uint16_t *p = offsets + x * 64;
215 for (
int i = 0; i < 64; i++)
Implements a light-weight self-contained VDB data-structure in a single file! In other words,...
Bit-mask to encode active states and facilitate sequential iterators and a fast codec for I/O compres...
Definition NanoVDB.h:1068
__hostdev__ uint64_t * words()
Return a pointer to the list of words of the bit mask.
Definition NanoVDB.h:1192
void buildMaskPrefixSums(const Mask< 3 > &mask, uint64_t prefixSum, uint16_t offsets[512])
Compute the 512-entry inclusive prefix-sum table for a NanoVDB Mask<3> leaf, optionally over the inve...
Definition MaskPrefixSum.h:100
T prefixSum(std::vector< T > &vec, bool threaded=true, OpT op=OpT())
Computes inclusive prefix sum of a vector.
Definition PrefixSum.h:74
Definition GridHandle.h:27