33# define FZ_HOST_DEVICE __host__ __device__
35# define FZ_HOST_DEVICE
42 static_assert(std::is_integral<T>::value && std::is_signed<T>::value,
43 "fz::Zigzag<T>: T must be a signed integer type "
44 "(int8_t, int16_t, int32_t, or int64_t).");
47 using UInt =
typename std::make_unsigned<T>::type;
49 static constexpr int W =
sizeof(T) * 8;
57 FZ_HOST_DEVICE
static constexpr UInt encode(SInt x)
noexcept {
60 return (
static_cast<UInt
>(x) << 1) ^
static_cast<UInt
>(x >> (W - 1));
67 FZ_HOST_DEVICE
static constexpr SInt decode(UInt u)
noexcept {
70 return static_cast<SInt
>((u >> 1) ^
static_cast<UInt
>(-(
static_cast<SInt
>(u & 1u))));
77using Zigzag8 = Zigzag<int8_t>;
78using Zigzag16 = Zigzag<int16_t>;
79using Zigzag32 = Zigzag<int32_t>;
80using Zigzag64 = Zigzag<int64_t>;
Definition fzm_format.h:25