FZGPUModules 2.0
GPU-accelerated modular compression pipelines
Loading...
Searching...
No Matches
fz::Negabinary< T > Struct Template Reference

#include <negabinary.h>

Static Public Member Functions

static FZ_HOST_DEVICE constexpr UInt encode (SInt n) noexcept
 
static FZ_HOST_DEVICE constexpr SInt decode (UInt u) noexcept
 

Detailed Description

template<typename T>
struct fz::Negabinary< T >

Negabinary (base -2) encoding helper.

Maps signed integers to unsigned negabinary representations using a compact XOR-mask formula. After differencing smooth data the high-order bits vanish faster than zigzag, producing denser zero runs at high bit-planes when followed by bitshuffle + RZE. Encode and decode are both O(1) bitwise ops.

All functions are __host__ __device__ — callable from CUDA kernels and host code. Used internally by NegabinaryStage<TIn, TOut>.

Template Parameters
TSigned integer type (int8_t, int16_t, int32_t, int64_t).

Member Function Documentation

◆ encode()

template<typename T >
static FZ_HOST_DEVICE constexpr UInt fz::Negabinary< T >::encode ( SInt  n)
inlinestaticconstexprnoexcept

Negabinary encode: signed integer → unsigned negabinary.

The formula (n + MASK) ^ MASK converts two's complement to base-(-2).

◆ decode()

template<typename T >
static FZ_HOST_DEVICE constexpr SInt fz::Negabinary< T >::decode ( UInt  u)
inlinestaticconstexprnoexcept

Negabinary decode: unsigned negabinary → signed integer. Inverse of encode(); decode(encode(n)) == n for all n.

Derivation from encode u = (n + MASK) ^ MASK: u ^ MASK = n + MASK n = (u ^ MASK) - MASK (unsigned subtraction wraps, then reinterpret as SInt)