36#if defined(__CUDACC__) || defined(__HIPCC__)
37# define FZ_HOST_DEVICE __host__ __device__
39# define FZ_HOST_DEVICE
58 static_assert(std::is_integral<T>::value && std::is_signed<T>::value,
59 "fz::Zigzag<T>: T must be a signed integer type "
60 "(int8_t, int16_t, int32_t, or int64_t).");
63 using UInt =
typename std::make_unsigned<T>::type;
65 static constexpr int W =
sizeof(T) * 8;
73 FZ_HOST_DEVICE
static constexpr UInt
encode(SInt x)
noexcept {
76 return (
static_cast<UInt
>(x) << 1) ^
static_cast<UInt
>(x >> (W - 1));
83 FZ_HOST_DEVICE
static constexpr SInt
decode(UInt u)
noexcept {
86 return static_cast<SInt
>((u >> 1) ^
static_cast<UInt
>(-(
static_cast<SInt
>(u & 1u))));
93using Zigzag8 = Zigzag<int8_t>;
94using Zigzag16 = Zigzag<int16_t>;
95using Zigzag32 = Zigzag<int32_t>;
96using Zigzag64 = Zigzag<int64_t>;
Definition algorithms.h:48
static FZ_HOST_DEVICE constexpr SInt decode(UInt u) noexcept
Definition zigzag.h:83
static FZ_HOST_DEVICE constexpr UInt encode(SInt x) noexcept
Definition zigzag.h:73