OpenQMC API
Loading...
Searching...
No Matches
range.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 <cassert>
13#include <cstdint>
14
15namespace oqmc
16{
17
40OQMC_HOST_DEVICE constexpr std::uint32_t uintToRange(std::uint32_t value,
41 std::uint32_t range)
42{
43 assert(range > 0);
44
45 // Modern compilers will optimise this down to a standard mult instruction,
46 // avoiding 64 bits, taking only the upper order bits in the EAX register.
47 const auto x = static_cast<std::uint64_t>(value);
48 const auto y = static_cast<std::uint64_t>(range);
49 return x * y >> 32;
50}
51
63OQMC_HOST_DEVICE constexpr std::uint32_t
64uintToRange(std::uint32_t value, std::uint32_t begin, std::uint32_t end)
65{
66 assert(begin < end);
67
68 return uintToRange(value, end - begin) + begin;
69}
70
71} // 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::uint32_t uintToRange(std::uint32_t value, std::uint32_t range)
Compute an unsigned integer within 0-bounded half-open range.
Definition range.h:40
Definition bntables.h:21