simd

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package simd provides SIMD-optimized operations for Tokman compression.

Current Status: Auto-vectorized fallback implementations. The Go compiler may auto-vectorize some loops on supported architectures.

TODO(simd): Implement native SIMD support when Go 1.26+ is released. Requirements:

  • Go 1.26+ with GOEXPERIMENT=simd
  • CPU feature detection (AVX2, AVX-512, ARM NEON)
  • Build tags for architecture-specific implementations

Implementation Plan:

  1. Add build tags: //go:build goexperiment.simd && (amd64 || arm64)
  2. Use golang.org/x/sys/cpu for feature detection
  3. Implement SIMD versions of: - StripANSI (byte scanning with SIMD comparison) - IndexByteSet (parallel byte matching) - CountByte (population count) - SplitWords (whitespace detection)
  4. Benchmark against auto-vectorized versions

References:

Index

Constants

This section is empty.

Variables

View Source
var DefaultBracketPairs = []BracketPair{
	{'{', '}'},
	{'[', ']'},
	{'(', ')'},
	{'<', '>'},
}
View Source
var Enabled bool

Enabled reports whether native SIMD optimizations are available. Currently false - using auto-vectorized fallback implementations. TODO(simd): Set to true when native SIMD is implemented and detected.

Functions

func ContainsAny

func ContainsAny(s string, substrs []string) bool

ContainsAny checks if s contains any of the substrings. Uses first-character matching for speed.

func ContainsWord

func ContainsWord(s, w string) bool

ContainsWord checks if s contains the word w (whole word matching).

func CountBrackets

func CountBrackets(s string, pairs []BracketPair) (opens, closes int)

CountBrackets counts opening and closing brackets in s.

func CountByte

func CountByte(s string, c byte) int

CountByte counts occurrences of c in s using byte scanning.

func CountByteSet

func CountByteSet(s string, set []byte) int

CountByteSet counts occurrences of any byte in set.

func FindWordBoundary

func FindWordBoundary(s string, pos int) int

FindWordBoundary finds the next word boundary starting from pos. Returns the position of the next non-word character or end of string.

func HasANSI

func HasANSI(input string) bool

HasANSI checks if input contains ANSI escape sequences.

func IndexByte

func IndexByte(s string, c byte) int

IndexByte finds the first occurrence of c in s using the standard library's SIMD-optimized implementation.

func IndexByteSet

func IndexByteSet(s string, set []byte) int

IndexByteSet finds the first occurrence of any byte in set. Uses a lookup table for fast byte set membership testing.

func IsWhitespace

func IsWhitespace(c byte) bool

IsWhitespace checks if a byte is whitespace.

func IsWordChar

func IsWordChar(c byte) bool

IsWordChar checks if a byte is part of a word (alphanumeric or underscore).

func Memcmp

func Memcmp(a, b []byte) int

Memcmp compares two byte slices.

func Memset

func Memset(buf []byte, c byte)

Memset fills buf with byte c.

func SplitWords

func SplitWords(s string) []string

SplitWords splits string into words using SIMD-optimized scanning.

func StripANSI

func StripANSI(input string) string

StripANSI strips ANSI escape sequences from input using optimized byte scanning. This is significantly faster than regex-based approaches for large inputs.

Types

type BracketPair

type BracketPair struct {
	Open, Close byte
}

BracketPair represents a pair of matching brackets.

type SIMDAccelerator

type SIMDAccelerator struct {
	// contains filtered or unexported fields
}

func NewSIMDAccelerator

func NewSIMDAccelerator() *SIMDAccelerator

func (*SIMDAccelerator) CompareBytes

func (s *SIMDAccelerator) CompareBytes(a, b []byte) bool

func (*SIMDAccelerator) CountBytes

func (s *SIMDAccelerator) CountBytes(data []byte, target byte) int

func (*SIMDAccelerator) Features

func (s *SIMDAccelerator) Features() map[string]bool

func (*SIMDAccelerator) FindByte

func (s *SIMDAccelerator) FindByte(data []byte, target byte) int

func (*SIMDAccelerator) HasSIMD

func (s *SIMDAccelerator) HasSIMD() bool

Jump to

Keyboard shortcuts

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