93inline typename std::enable_if<Dim != 1 && Dim != 2, void>::type
interleaveBits(
94 const IntType coords[Dim], IntType mnr[Dim]) {
96 const int BitLength =
sizeof(IntType) << 3;
99 for (
int d = 0; d < Dim; d++) {
108 for (
int i = 0; i < BitLength; ++i) {
110 for (
int d = 0; d < Dim; d++) {
112 mnr[k / BitLength] |= ((coords[d] >> i) & 0x1) << (k % BitLength);
127inline typename std::enable_if<Dim == 2, void>::type
interleaveBits(
const unsigned int coords[Dim],
128 unsigned int mnr[Dim]) {
130 const size_t HalfBitLength =
sizeof(
unsigned int) << 2;
138 unsigned int x_lo[2] = {coords[0], coords[1]};
141 unsigned int x_hi[2] = {coords[0] >> HalfBitLength, coords[1] >> HalfBitLength};
144 unsigned int mask = ~0x0;
146 for (
unsigned int i = (HalfBitLength); i > 0; i = i >> 1) {
149 mask = mask ^ (mask << i);
152 x_lo[0] = (x_lo[0] | (x_lo[0] << i)) & mask;
153 x_lo[1] = (x_lo[1] | (x_lo[1] << i)) & mask;
155 x_hi[0] = (x_hi[0] | (x_hi[0] << i)) & mask;
156 x_hi[1] = (x_hi[1] | (x_hi[1] << i)) & mask;
160 mnr[0] = x_lo[0] | (x_lo[1] << 1);
163 mnr[1] = x_hi[0] | (x_hi[1] << 1);