3#include <cuda/std/algorithm>
4#include <cuda/std/cstdint>
5#include <cuda/std/limits>
12template <u
int8_t ExponentBits, u
int8_t MantissaBits>
14 static_assert(ExponentBits > 0U);
15 static_assert(MantissaBits > 0U);
16 static_assert(ExponentBits + MantissaBits == 16U);
42template <
typename Layout = default_register_layout>
43__host__ __device__
inline uint16_t
score(uint64_t hash)
noexcept {
44 constexpr auto layout_mantissa_mask = (1U << Layout::mantissa_bits) - 1U;
45 constexpr auto layout_restore_shift_base = 63U - Layout::mantissa_bits;
46 constexpr auto layout_max_nlz =
47 cuda::std::min(layout_restore_shift_base, (1U << Layout::exponent_bits) - 1U);
49 auto const nlz =
static_cast<uint32_t
>(__clzll(hash | 1ULL));
51 auto const nlz =
static_cast<uint32_t
>(__builtin_clzll(hash | 1ULL));
53 auto const capped = nlz > layout_max_nlz ? layout_max_nlz : nlz;
54 auto const shift = layout_restore_shift_base - capped;
55 auto const mantissa =
static_cast<uint32_t
>((hash >>
shift) & layout_mantissa_mask);
56 auto const inverted =
static_cast<uint32_t
>(mantissa ^ layout_mantissa_mask);
57 auto const raw =
static_cast<uint16_t
>((capped << Layout::mantissa_bits) | inverted);
58 return raw == 0U ?
static_cast<uint16_t
>(1U) : raw;
67template <
typename Layout = default_register_layout>
68__host__ __device__
constexpr uint64_t
restore(uint16_t stored)
noexcept {
69 constexpr auto layout_mantissa_mask = (1U << Layout::mantissa_bits) - 1U;
70 constexpr auto layout_restore_shift_base = 63U - Layout::mantissa_bits;
71 auto const nlz =
static_cast<uint32_t
>(stored >> Layout::mantissa_bits);
72 auto const lowbits =
static_cast<uint32_t
>((~stored) & layout_mantissa_mask);
73 auto const mantissa = (1U << Layout::mantissa_bits) | lowbits;
74 auto const shift = layout_restore_shift_base - nlz;
75 return static_cast<uint64_t
>(mantissa) <<
shift;
86template <
typename Layout = default_register_layout>
88 constexpr auto layout_mantissa_mask = (1U << Layout::mantissa_bits) - 1U;
89 constexpr auto layout_restore_shift_base = 63U - Layout::mantissa_bits;
90 auto const nlz =
static_cast<uint32_t
>(stored >> Layout::mantissa_bits);
91 auto const lowbits =
static_cast<uint32_t
>((~stored) & layout_mantissa_mask);
92 auto const mantissa = (1U << Layout::mantissa_bits) | lowbits;
93 auto const shift = layout_restore_shift_base - nlz;
94 auto const lower =
static_cast<uint64_t
>(mantissa) <<
shift;
97 return lower + ((1ULL <<
shift) >> 1U);
constexpr uint32_t max_nlz
constexpr uint32_t restore_shift_base
Default restoration constants retained for source compatibility.
__host__ __device__ constexpr uint64_t restore_midpoint(uint16_t stored) noexcept
Reconstructs the interval midpoint for restore.
__host__ __device__ constexpr uint64_t restore(uint16_t stored) noexcept
Reconstructs the approximate original hash magnitude from a stored score.
constexpr uint32_t mantissa_mask
__host__ __device__ uint16_t score(uint64_t hash) noexcept
Computes the 16-bit DDL rarity score for hash.
constexpr uint8_t mantissa_bits
Default score layout retained for source compatibility.
Batch operations over contiguous device rows.
Compile-time split of a 16-bit DDL score into exponent and mantissa fields.
static constexpr uint8_t mantissa_bits
static constexpr uint8_t exponent_bits