34# define FZ_HOST_DEVICE __host__ __device__
36# define FZ_HOST_DEVICE
55 static_assert(std::is_integral<T>::value && std::is_signed<T>::value,
56 "fz::Zigzag<T>: T must be a signed integer type "
57 "(int8_t, int16_t, int32_t, or int64_t).");
60 using UInt =
typename std::make_unsigned<T>::type;
62 static constexpr int W =
sizeof(T) * 8;
70 FZ_HOST_DEVICE
static constexpr UInt
encode(SInt x)
noexcept {
73 return (
static_cast<UInt
>(x) << 1) ^
static_cast<UInt
>(x >> (W - 1));
80 FZ_HOST_DEVICE
static constexpr SInt
decode(UInt u)
noexcept {
83 return static_cast<SInt
>((u >> 1) ^
static_cast<UInt
>(-(
static_cast<SInt
>(u & 1u))));
90using Zigzag8 = Zigzag<int8_t>;
91using Zigzag16 = Zigzag<int16_t>;
92using Zigzag32 = Zigzag<int32_t>;
93using Zigzag64 = Zigzag<int64_t>;
static FZ_HOST_DEVICE constexpr SInt decode(UInt u) noexcept
Definition zigzag.h:80
static FZ_HOST_DEVICE constexpr UInt encode(SInt x) noexcept
Definition zigzag.h:70