16#ifndef MORTON_BATCH_HPP
17#define MORTON_BATCH_HPP
31template <
unsigned Dim,
unsigned Bits>
36 using code =
typename M::code_type;
37 const code mask = M::axis_mask(axis);
38 const code notM = code(~mask);
39 const code keep = M::field_mask & notM;
40 const code dk = M::deposit(k, axis);
42 if constexpr (std::is_same_v<code, std::uint64_t>) {
43 if (detail::cpu_has_avx512f()) {
44 detail::avx512::add64(in, out, n, notM, dk, mask, keep);
49 for (std::size_t i = 0; i < n; ++i) {
51 out[i] = code((c | notM) + dk) & mask;
57template <
unsigned Dim,
unsigned Bits>
62 using code =
typename M::code_type;
63 const code mask = M::axis_mask(axis);
64 const code keep = M::field_mask & code(~mask);
65 const code dk = M::deposit(k, axis);
67 if constexpr (std::is_same_v<code, std::uint64_t>) {
68 if (detail::cpu_has_avx512f()) {
69 detail::avx512::sub64(in, out, n, dk, mask, keep);
74 for (std::size_t i = 0; i < n; ++i) {
76 out[i] = (code((c & mask) - dk) & mask) | (c & keep);
81template <
unsigned Dim,
unsigned Bits>
91template <
unsigned Bits>
97 if constexpr (
Bits == 32) {
98 if (detail::cpu_has_avx512f()) {
99 detail::avx512::encode2(
x,
y,
out,
n);
104 for (std::size_t
i = 0;
i <
n; ++
i)
105 out[
i] = M::encode(
x[
i],
y[
i]).code();
109template <
unsigned Bits>
116 if constexpr (
Bits == 21) {
117 if (detail::cpu_has_avx512f()) {
118 detail::avx512::encode3(
x,
y,
z,
out,
n);
123 for (std::size_t
i = 0;
i <
n; ++
i)
128template <
unsigned Bits>
133 if constexpr (
Bits == 32) {
134 if (detail::cpu_has_avx512f()) {
135 detail::avx512::decode2(
in,
x,
y,
n);
140 for (std::size_t
i = 0;
i <
n; ++
i) {
141 auto a = M::from_code(
in[
i]).decode();
148template <
unsigned Bits>
154 if constexpr (
Bits == 21) {
155 if (detail::cpu_has_avx512f()) {
156 detail::avx512::decode3(
in,
x,
y,
z,
n);
161 for (std::size_t
i = 0;
i <
n; ++
i) {
162 auto a = M::from_code(
in[
i]).decode();
A Morton (Z-order) code interleaving Dim unsigned coordinates of Bits bits each.
Definition morton.hpp:203
detail::uint_for_t< Bits > coord_type
Definition morton.hpp:215
detail::uint_for_t< Dim *Bits > code_type
Definition morton.hpp:214
Core Morton<Dim,Bits> type — Z-order codes with O(1) arithmetic in Morton space.
void decode2(const typename Morton< 2, Bits >::code_type *in, typename Morton< 2, Bits >::coord_type *x, typename Morton< 2, Bits >::coord_type *y, std::size_t n)
Decode an array of codes back to coordinate arrays (2D).
Definition batch.hpp:129
void encode3(const typename Morton< 3, Bits >::coord_type *x, const typename Morton< 3, Bits >::coord_type *y, const typename Morton< 3, Bits >::coord_type *z, typename Morton< 3, Bits >::code_type *out, std::size_t n)
Encode arrays of coordinates (3D) into codes.
Definition batch.hpp:110
void sub(const typename Morton< Dim, Bits >::code_type *in, typename Morton< Dim, Bits >::code_type *out, std::size_t n, unsigned axis, typename Morton< Dim, Bits >::coord_type k)
Subtract the same k from axis of every code (wraps). Vectorised.
Definition batch.hpp:58
void encode2(const typename Morton< 2, Bits >::coord_type *x, const typename Morton< 2, Bits >::coord_type *y, typename Morton< 2, Bits >::code_type *out, std::size_t n)
Encode arrays of coordinates (2D) into codes.
Definition batch.hpp:92
void add(const typename Morton< Dim, Bits >::code_type *in, typename Morton< Dim, Bits >::code_type *out, std::size_t n, unsigned axis, typename Morton< Dim, Bits >::coord_type k)
Add the same k to axis of every code (wraps).
Definition batch.hpp:32
void decode3(const typename Morton< 3, Bits >::code_type *in, typename Morton< 3, Bits >::coord_type *x, typename Morton< 3, Bits >::coord_type *y, typename Morton< 3, Bits >::coord_type *z, std::size_t n)
Decode an array of codes back to coordinate arrays (3D).
Definition batch.hpp:149
void step(const typename Morton< Dim, Bits >::code_type *in, typename Morton< Dim, Bits >::code_type *out, std::size_t n, unsigned axis, int dir)
Step every code one cell along ±axis (dir>=0 -> +1, else -1). Vectorised.
Definition batch.hpp:82
Explicit AVX-512 batch kernels for the bulk encode/decode/arithmetic paths.