|
FZGPUModules 2.0
GPU-accelerated modular compression pipelines
|
Zigzag (two's complement to magnitude-sign) encoding helpers. More...
#include <cstdint>#include <type_traits>Go to the source code of this file.
Classes | |
| struct | fz::Zigzag< T > |
Zigzag (two's complement to magnitude-sign) encoding helpers.
Zigzag (TCMS - Two's Complement to Magnitude-Sign) encoding.
Maps signed integers to unsigned integers so that small-magnitude values (both positive and negative) map to small non-negative integers:
encode: u = (x << 1) ^ (x >> (W-1)) // signed → unsigned decode: x = (u >> 1) ^ -(u & 1) // unsigned → signed
Design constraints:
Usage: using ZZ = fz::Zigzag<int32_t>; uint32_t u = ZZ::encode(-3); // → 5 int32_t x = ZZ::decode(5u); // → -3