OpenQMC API
Loading...
Searching...
No Matches
reverse.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Contributors to the OpenQMC Project.
3
7
8#pragma once
9
10#include "gpu.h"
11
12#include <cstdint>
13
14namespace oqmc
15{
16
25OQMC_HOST_DEVICE constexpr std::uint32_t reverseBits32(std::uint32_t value)
26{
27#if defined(__CUDA_ARCH__)
29#else
30 value = (((value & 0xaaaaaaaa) >> 1) | ((value & 0x55555555) << 1));
31 value = (((value & 0xcccccccc) >> 2) | ((value & 0x33333333) << 2));
32 value = (((value & 0xf0f0f0f0) >> 4) | ((value & 0x0f0f0f0f) << 4));
33
34#if defined(_MSC_VER)
35 value = (((value & 0xff00ff00) >> 8) | ((value & 0x00ff00ff) << 8));
36 value = ((value >> 16) | (value << 16));
37#else
39#endif
40#endif
41
42 return value;
43}
44
53OQMC_HOST_DEVICE constexpr std::uint16_t reverseBits16(std::uint16_t value)
54{
55#if defined(__CUDA_ARCH__)
56 value = __brev(value) >> 16;
57#else
58 value = (((value & 0xaaaaaaaa) >> 1) | ((value & 0x55555555) << 1));
59 value = (((value & 0xcccccccc) >> 2) | ((value & 0x33333333) << 2));
60 value = (((value & 0xf0f0f0f0) >> 4) | ((value & 0x0f0f0f0f) << 4));
61
62#if defined(_MSC_VER)
63 value = ((value >> 8) | (value << 8));
64#else
66#endif
67#endif
68
69 return value;
70}
71
72} // namespace oqmc
#define OQMC_HOST_DEVICE
Definition gpu.h:13
EncodeKey decodeBits16(std::uint16_t value)
Decode a value back into a key.
Definition encode.h:81
constexpr std::uint16_t reverseBits16(std::uint16_t value)
Reverse bits of an unsigned 16 bit integer.
Definition reverse.h:53
constexpr std::uint32_t reverseBits32(std::uint32_t value)
Reverse bits of an unsigned 32 bit integer.
Definition reverse.h:25
Definition bntables.h:21