2#include <vector_types.h>
3#include <cuda_runtime.h>
8MUDA_GENERIC MUDA_INLINE std::uint32_t expand_bits(std::uint32_t v)
noexcept
10 v = (v * 0x00010001u) & 0xFF0000FFu;
11 v = (v * 0x00000101u) & 0x0F00F00Fu;
12 v = (v * 0x00000011u) & 0xC30C30C3u;
13 v = (v * 0x00000005u) & 0x49249249u;
19MUDA_GENERIC MUDA_INLINE std::uint32_t morton_code(float4 xyz,
float resolution = 1024.0f) noexcept
21 xyz.x = ::fminf(::fmaxf(xyz.x * resolution, 0.0f), resolution - 1.0f);
22 xyz.y = ::fminf(::fmaxf(xyz.y * resolution, 0.0f), resolution - 1.0f);
23 xyz.z = ::fminf(::fmaxf(xyz.z * resolution, 0.0f), resolution - 1.0f);
24 const std::uint32_t xx = expand_bits(
static_cast<std::uint32_t
>(xyz.x));
25 const std::uint32_t yy = expand_bits(
static_cast<std::uint32_t
>(xyz.y));
26 const std::uint32_t zz = expand_bits(
static_cast<std::uint32_t
>(xyz.z));
27 return xx * 4 + yy * 2 + zz;
30MUDA_GENERIC MUDA_INLINE std::uint32_t morton_code(double4 xyz,
double resolution = 1024.0) noexcept
32 xyz.x = ::fmin(::fmax(xyz.x * resolution, 0.0), resolution - 1.0);
33 xyz.y = ::fmin(::fmax(xyz.y * resolution, 0.0), resolution - 1.0);
34 xyz.z = ::fmin(::fmax(xyz.z * resolution, 0.0), resolution - 1.0);
35 const std::uint32_t xx = expand_bits(
static_cast<std::uint32_t
>(xyz.x));
36 const std::uint32_t yy = expand_bits(
static_cast<std::uint32_t
>(xyz.y));
37 const std::uint32_t zz = expand_bits(
static_cast<std::uint32_t
>(xyz.z));
38 return xx * 4 + yy * 2 + zz;
41__device__ MUDA_INLINE
int common_upper_bits(
const unsigned int lhs,
const unsigned int rhs)
noexcept
43 return ::__clz(lhs ^ rhs);
45__device__ MUDA_INLINE
int common_upper_bits(
const unsigned long long int lhs,
46 const unsigned long long int rhs)
noexcept
48 return ::__clzll(lhs ^ rhs);