Expand description
High-performance utility functions for binary data processing.
This module provides optimized primitives for:
- Unaligned memory reads (using byteorder for optimal codegen)
- SIMD-accelerated byte searches (via memchr)
- Fast pointer scanning for batch operations
§Performance Notes
All functions are aggressively inlined and designed to compile down to optimal machine code. On x86-64 and ARM64:
read_u64_lecompiles to a single unaligned load instructionread_u32_lecompiles to a single unaligned load instructionmemchr_nulluses SIMD vectorization (AVX2/NEON when available)
Constants§
- ADDR_
MASK_ 48BIT - Address mask for stripping PAC/TBI bits from pointers. Keeps lower 48 bits which is the actual address portion.
- MIN_
VALID_ POINTER - Minimum valid pointer value (skip small values that are likely not pointers). 0x100000000 = 4GB, typical minimum for 64-bit address space.
Functions§
- align_
down - Aligns a value down to the given power-of-two alignment.
- align_
up - Aligns a value up to the given power-of-two alignment.
- batch_
transform_ u64 - Batch processes an array of u64 values, applying a transformation function.
- is_
aligned - Checks if a value is aligned to the given power-of-two alignment.
- memchr_
find - Finds the position of the first occurrence of
needleinhaystack. - memchr_
null - Finds the position of the first null byte in a slice.
- read_
sleb128_ fast - Reads a signed LEB128 value with fast paths for common cases.
- read_
u16_ le - Reads a little-endian u16 from an unaligned byte slice.
- read_
u16_ le_ at - Reads a little-endian u16 from a byte slice at the given offset.
- read_
u32_ le - Reads a little-endian u32 from an unaligned byte slice.
- read_
u32_ le_ at - Reads a little-endian u32 from a byte slice at the given offset.
- read_
u64_ le - Reads a little-endian u64 from an unaligned byte slice.
- read_
u64_ le_ at - Reads a little-endian u64 from a byte slice at the given offset.
- read_
uleb128_ fast - Reads an unsigned LEB128 value with fast paths for common cases.
- scan_
pointers_ in_ range - Scans a data slice for potential 64-bit pointers.