OpenQMC API
Loading...
Searching...
No Matches
encode.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Contributors to the OpenQMC Project.
3
8
9#pragma once
10
11#include "gpu.h"
12
13#include <cstdint>
14
15namespace oqmc
16{
17
25{
26 int x;
27 int y;
28 int z;
29};
30
44template <int XBits, int YBits, int ZBits>
45OQMC_HOST_DEVICE inline std::uint16_t encodeBits16(EncodeKey key)
46{
47 constexpr auto sum = XBits + YBits + ZBits;
48
49 static_assert(sum <= 16, "Precision sum must be equal or less than 16");
50
51 constexpr auto maskX = (1 << XBits) - 1;
52 constexpr auto maskY = (1 << YBits) - 1;
53 constexpr auto maskZ = (1 << ZBits) - 1;
54
55 constexpr auto offsetX = 0;
56 constexpr auto offsetY = XBits;
57 constexpr auto offsetZ = XBits + YBits;
58
59 std::uint16_t value = 0;
60 value |= (key.x & maskX) << offsetX;
61 value |= (key.y & maskY) << offsetY;
62 value |= (key.z & maskZ) << offsetZ;
63
64 return value;
65}
66
80template <int XBits, int YBits, int ZBits>
82{
83 constexpr auto sum = XBits + YBits + ZBits;
84
85 static_assert(sum <= 16, "Precision sum must be equal or less than 16");
86
87 constexpr auto maskX = (1 << XBits) - 1;
88 constexpr auto maskY = (1 << YBits) - 1;
89 constexpr auto maskZ = (1 << ZBits) - 1;
90
91 constexpr auto offsetX = 0;
92 constexpr auto offsetY = XBits;
93 constexpr auto offsetZ = XBits + YBits;
94
95 const auto x = (value >> offsetX) & maskX;
96 const auto y = (value >> offsetY) & maskY;
97 const auto z = (value >> offsetZ) & maskZ;
98
99 return {x, y, z};
100}
101
102} // namespace oqmc
#define OQMC_HOST_DEVICE
Definition gpu.h:13
int y
y axis coordinate.
Definition encode.h:27
int z
z axis coordinate.
Definition encode.h:28
int x
x axis coordinate.
Definition encode.h:26
EncodeKey decodeBits16(std::uint16_t value)
Decode a value back into a key.
Definition encode.h:81
std::uint16_t encodeBits16(EncodeKey key)
Encode a key value into 16 bits.
Definition encode.h:45
Key to encode pixel coordinates.
Definition encode.h:25
Definition bntables.h:21