bitpack

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package bitpack implements the pure bit-packing and SIMD kernel layer shared by qdf's integer codecs (FOR, Delta+FOR, dict, PFOR, ALP). It encodes []uint64 deltas as a tight LSB-first bit-stream and decodes it back, with byte-aligned and variable-width fast paths dispatched to hand-written AVX2 (amd64) / NEON (arm64) kernels under the qdf_simd build tag and a portable scalar fallback otherwise.

The layer is dependency-closed: it imports only the standard library and golang.org/x/sys/cpu, and holds no qdf wire-format or codec state. All bit layouts are LSB-first within each byte; Pack and Unpack are exact inverses for every width in [1, 56].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitsForDelta

func BitsForDelta(d uint64) int

BitsForDelta returns the number of bits required to represent values in [0, d], i.e. bits.Len64(d). 0 => no bits needed (all equal).

func DecodeHex4 added in v0.1.1

func DecodeHex4(dst, src []byte, lut *[16]byte)

DecodeHex4 fills dst from a 4-bit nibble stream src via the 16-entry LUT (dst[2i]=lut[src[i]&0xf], dst[2i+1]=lut[src[i]>>4]). Scalar fallback for non-SIMD builds.

func Pack

func Pack(out []byte, vals []uint64, bitsPer int)

Pack writes len(vals)*bits bits into out, LSB-first within each byte. out must have len >= ceil(len(vals)*bits/8). bits must be in [1, 56].

func PackBoolsLSB

func PackBoolsLSB(dst []byte, src []bool, n int)

PackBoolsLSB fallback: plain scalar bit-by-bit pack.

func PackChunk

func PackChunk(out []byte, vals []uint64, bitsPer int, elemOff int)

PackChunk writes a chunk of values starting at element offset elemOff in the output bit-stream. It is Pack generalised to write into the middle of an existing buffer. bitsPer must be in [0, 56].

func Unpack

func Unpack(out []uint64, in []byte, bitsPer int)

Unpack reads len(out)*bits bits from in. bits must be in [1, 56]. in must have len >= ceil(len(out)*bits/8). Byte-aligned widths take a dedicated zero-extend fast path (asm under qdf_simd, otherwise scalar memcpy-with-mask); other widths use the variable-width / sliding-window decoders.

func UnpackScalar

func UnpackScalar(out []uint64, in []byte, bitsPer int)

UnpackScalar is the original byte-at-a-time decoder, kept as a parity reference (oracle) for the fast paths' tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL