Documentation
¶
Index ¶
- Constants
- Variables
- func AbsoluteDifferenceBetweenBytes(a, b uint64) uint64
- func AddBytesWithMaximum(a, b uint64) uint64
- func AddBytesWithWrapping(a, b uint64) uint64
- func AverageBytes(a, b uint64) uint64
- func BytesToLanes(b []byte) ([]uint64, int)
- func CountOnesPerByte(v uint64) uint64
- func Dupe(c byte) uint64
- func ExtractLowBits(v uint64) byte
- func HighBitWhereEqual(v, cm uint64) uint64
- func HighBitWhereGreater(v, cm uint64) uint64
- func HighBitWhereLess(v, cm uint64) uint64
- func IntToLanes(i uint64) [8]byte
- func LanesToBytes(lanes []uint64) []byte
- func LanesToInt(lanes [8]byte) uint64
- func ReverseEachByte(v uint64) uint64
- func SelectByLowBit(a, b, mask uint64) uint64
- func SelectLargerBytes(a, b uint64) uint64
- func SelectSmallerBytes(a, b uint64) uint64
- func SubtractBytesWithMinimum(a, b uint64) uint64
- func SubtractBytesWithWrapping(a, b uint64) uint64
- func SwapByteHalves(v uint64) uint64
Constants ¶
const ( // HighBits is a mask with the high bit set in all 8 bytes of a uint64 HighBits uint64 = 0x8080_8080_8080_8080 )
const ( // LowBits has the lowest bit set in each byte for value duplication LowBits uint64 = 0x0101_0101_0101_0101 )
Variables ¶
var Lookup = struct { OnesPositions [256][]int }{ func() (res [256][]int) { for b := range res { for i := 0; i < 8; i++ { if b>>i&1 == 1 { res[b] = append(res[b], i) } } } return }()}
Lookup provides precomputed data for optimized operations OnesPositions maps byte values to positions of their set bits
Functions ¶
func AbsoluteDifferenceBetweenBytes ¶
AbsoluteDifferenceBetweenBytes calculates |a-b| for each byte Computes unsigned distances for metrics and signal processing
func AddBytesWithMaximum ¶
AddBytesWithMaximum performs byte-wise addition clamped at 255 Saturating addition to prevent overflow in all 8 bytes
func AddBytesWithWrapping ¶
AddBytesWithWrapping performs byte-wise addition with wrap-around Parallel addition across all 8 bytes with overflow wrapping to zero
func AverageBytes ¶
AverageBytes calculates (a+b)/2 for each byte without overflow Perfect for signal processing, image manipulation, and smoothing
func BytesToLanes ¶
BytesToLanes converts a []byte to []uint64 for SWAR processing Returns uint64 lanes and index where unused bytes begin
func CountOnesPerByte ¶
CountOnesPerByte counts set bits in each byte Parallel population count for hamming distance and feature extraction
func Dupe ¶
Dupe duplicates a byte across all 8 bytes of a uint64 Creates comparison values for parallel operations
func ExtractLowBits ¶
ExtractLowBits packs the low bit from each byte into a single byte Compacts 8 comparison results into a single byte
func HighBitWhereEqual ¶
HighBitWhereEqual sets the high bit (0x80) in each byte where v == cm Ideal for pattern matching and finding specific values in data
func HighBitWhereGreater ¶
HighBitWhereGreater sets the high bit (0x80) in each byte where v > cm Perfect for threshold detection across multiple values
func HighBitWhereLess ¶
HighBitWhereLess sets the high bit (0x80) in each byte where v < cm Enables parallel comparison of 8 bytes simultaneously
func IntToLanes ¶
IntToLanes converts a uint64 to an 8-byte array Access individual bytes for mixed SWAR/byte-level operations
func LanesToBytes ¶
LanesToBytes converts []uint64 back to []byte Zero-copy conversion for optimal performance
func LanesToInt ¶
LanesToInt converts an 8-byte array to uint64 Zero-copy conversion from byte-level to SWAR format
func ReverseEachByte ¶
ReverseEachByte reverses the bit order within each byte Useful for endianness conversion and bit-level manipulations
func SelectByLowBit ¶
SelectByLowBit selects values from a or b based on mask bits Branchless selection between values based on conditions
func SelectLargerBytes ¶
SelectLargerBytes returns max(a,b) for each byte Ideal for peak detection, ceiling operations, and filtering
func SelectSmallerBytes ¶
SelectSmallerBytes returns min(a,b) for each byte Efficient for clipping, filtering, and data preprocessing
func SubtractBytesWithMinimum ¶
SubtractBytesWithMinimum performs byte-wise subtraction clamped at zero Provides saturating subtraction to prevent underflow in all 8 bytes
func SubtractBytesWithWrapping ¶
SubtractBytesWithWrapping performs byte-wise subtraction with wrapping Parallel subtraction across all 8 bytes with wrap-around behavior
func SwapByteHalves ¶
SwapByteHalves swaps the high and low nibbles in each byte Useful for BCD encoding/decoding and nibble-level transforms
Types ¶
This section is empty.