simd

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package simd provides a SIMD abstraction layer for vector operations. This package supports runtime detection of SIMD capabilities and provides fallback implementations for systems without SIMD support.

NOTE: The codebase now uses github.com/zeebo/xxh3 for hashing, which already includes native ARM64 NEON and x86 SSE/AVX SIMD optimizations. This package remains for future SIMD operations beyond hashing.

PERFORMANCE: Do NOT replace xxh3 with cryptographic hashes (SHA-256, etc.). xxh3 is ~20x faster and is designed for deduplication, not security.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignSlice

func AlignSlice(data []byte) []byte

AlignSlice ensures a slice is properly aligned for SIMD operations. It returns a new slice with appropriate alignment and padding.

func Available

func Available() bool

Available returns true if SIMD operations are available and can be used. It performs runtime checks for:

  • Architecture support (AMD64 or ARM64)
  • SIMD instruction set availability
  • Go version compatibility

Currently, this returns false on ARM64 systems (including Apple Silicon) as the simd/archsimd package is AMD64-only in Go 1.26.

func UnsafeBytes

func UnsafeBytes[T any](data []byte) *T

UnsafeBytes casts a byte slice to a specific type pointer for SIMD operations. This is a helper function for future SIMD implementations.

WARNING: This function uses unsafe operations and must be used carefully. The caller must ensure:

  • The input slice has sufficient capacity
  • The type T is appropriate for the data
  • Alignment requirements are met

func UnsafeSlice

func UnsafeSlice[T any](data []byte) []T

UnsafeSlice casts a byte slice to a slice of a specific type. This is a helper function for future SIMD implementations.

WARNING: This function uses unsafe operations and must be used carefully.

func VectorSize

func VectorSize() int

VectorSize returns the optimal vector size for SIMD operations on this system. This helps callers prepare data appropriately.

Types

type Hasher

type Hasher interface {
	// Hash computes a hash of the input data using SIMD operations if available.
	Hash(data []byte) []byte

	// HashSlice computes hash for a slice of byte slices.
	// This allows for batching multiple hash operations.
	HashSlice(data [][]byte) [][]byte
}

Hasher interface defines operations for SIMD-optimized hashing. Implementations should use vector instructions when available.

func NewHasher

func NewHasher() Hasher

NewHasher returns the best available Hasher implementation. It chooses:

  • SIMD hasher when SIMD is available and supported
  • Fallback hasher for systems without SIMD support

Jump to

Keyboard shortcuts

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