1 #ifndef AMREX_MORTON_H_
2 #define AMREX_MORTON_H_
3 #include <AMReX_Config.H>
31 std::uint32_t
makeSpace (std::uint32_t x) noexcept {
32 #if (AMREX_SPACEDIM == 3)
34 x = (
x | (
x << 16)) & 0x030000FF;
39 x = (
x | (
x << 8)) & 0x0300F00F;
44 x = (
x | (
x << 4)) & 0x030C30C3;
49 x = (
x | (
x << 2)) & 0x09249249;
55 #elif (AMREX_SPACEDIM == 2)
57 x = (
x | (
x << 8)) & 0x00FF00FF;
62 x = (
x | (
x << 4)) & 0x0F0F0F0F;
67 x = (
x | (
x << 2)) & 0x33333333;
72 x = (
x | (
x << 1)) & 0x55555555;
78 #elif (AMREX_SPACEDIM == 1)
97 std::uint32_t
toUInt10 (amrex::Real x, amrex::Real xmin, amrex::Real xmax) noexcept {
99 constexpr std::uint32_t code_offset = (1U << 10);
100 return (std::uint32_t)(((
x - xmin)/(xmax - xmin)) * code_offset);
117 std::uint32_t
toUInt16 (amrex::Real x, amrex::Real xmin, amrex::Real xmax) noexcept {
119 constexpr std::uint32_t code_offset = (1U << 16);
120 return (std::uint32_t)(((
x - xmin)/(xmax - xmin)) * code_offset);
135 std::uint32_t
toUInt32 (amrex::Real x, amrex::Real xmin, amrex::Real xmax) noexcept {
137 constexpr
unsigned long long code_offset = (1ULL << 32);
138 return (std::uint32_t)(((
x - xmin)/(xmax - xmin)) * Real(code_offset));
161 #if (AMREX_SPACEDIM == 3)
162 std::uint32_t a =
toUInt10(
x, plo[0], phi[0]);
163 std::uint32_t
b =
toUInt10(y, plo[1], phi[1]);
164 std::uint32_t c =
toUInt10(z, plo[2], phi[2]);
165 #elif (AMREX_SPACEDIM == 2)
166 std::uint32_t a =
toUInt16(
x, plo[0], phi[0]);
167 std::uint32_t
b =
toUInt16(y, plo[1], phi[1]);
168 #elif (AMREX_SPACEDIM == 1)
169 std::uint32_t a =
toUInt32(
x, plo[0], phi[0]);
185 #if (AMREX_SPACEDIM == 3)
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
Definition: AMReX_Morton.H:12
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint32_t toUInt32(amrex::Real x, amrex::Real xmin, amrex::Real xmax) noexcept
Convert a Real to a uint32, keeping all significant bits. It is assumed that xmin <= x < xmax.
Definition: AMReX_Morton.H:135
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint32_t toUInt16(amrex::Real x, amrex::Real xmin, amrex::Real xmax) noexcept
Convert a Real to a uint32, keeping only 16 significant bits. This puts the first 16 bits of x into r...
Definition: AMReX_Morton.H:117
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint32_t makeSpace(std::uint32_t x) noexcept
This makes space in the input 32-bit integer by splitting the bits so they can be interleaved.
Definition: AMReX_Morton.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint32_t get32BitCode(AMREX_D_DECL(Real x, Real y, Real z), const GpuArray< amrex::Real, AMREX_SPACEDIM > &plo, const GpuArray< amrex::Real, AMREX_SPACEDIM > &phi) noexcept
Given a 3D real-space coordinate, returns a Morton code stored in an unsigned 32 bit integer.
Definition: AMReX_Morton.H:158
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint32_t toUInt10(amrex::Real x, amrex::Real xmin, amrex::Real xmax) noexcept
Convert a Real to a uint32, keeping only 10 significant bits. This puts the first 10 bits of x into r...
Definition: AMReX_Morton.H:97
Definition: AMReX_Array.H:34
Definition: AMReX_Dim3.H:13