fastops

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package fastops CPU feature detection. Detection uses golang.org/x/sys/cpu for runtime CPUID queries (amd64) and static defaults (arm64 always has NEON).

SIMD implementations:

  • amd64 (AVX2): fastops_amd64.s with //go:noescape declarations
  • arm64 (NEON): deferred — Go's plan9 assembler has limited GP↔NEON register transfer support (VMOV with element indexing and VLD1 addressing are unreliable in user-written assembly). When Go >=1.28 or a future release stabilizes NEON instruction support, add fastops_arm64.s with VLD1/VEOR/VCNT/VUADDLV sequences and wire them through the Dispatcher.

Package fastops provides performance-optimized string operations using manual loop unrolling (processing 16 bytes per iteration). These are manually unrolled scalar loops that improve performance by reducing branch overhead and enabling better CPU pipelining. The Go compiler may auto-vectorize some patterns, but correctness does not depend on hardware SIMD support.

On amd64 with AVX2 support (detected via golang.org/x/sys/cpu), FastHasANSI and FastCountBytes dispatch to AVX2 assembly implementations (fastops_amd64.s) for ~4-8x throughput improvement on data >32 bytes. The scalar unrolled path serves as a fallback for systems without AVX2 or when processing short strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsAny

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

ContainsAny checks if string contains any of the substrings

func ContainsWord

func ContainsWord(s, word string) bool

ContainsWord checks if string contains word (space-delimited)

func FastContains

func FastContains(s, substr string) bool

FastContains checks if string contains substring (optimized for small patterns)

func FastCountBytes

func FastCountBytes(data string, target byte) int

FastCountBytes counts bytes using unrolled scalar loop (dispatches to AVX2 on amd64 when available).

func FastEqual

func FastEqual(a, b string) bool

FastEqual compares strings with early exit

func FastHasANSI

func FastHasANSI(data string) bool

FastHasANSI checks for ANSI sequences using unrolled scalar loop (dispatches to AVX2 on amd64 when available).

func FastLower

func FastLower(s string) string

FastLower ASCII lowercase conversion (optimized with unsafe)

func HasANSI

func HasANSI(data string) bool

HasANSI is an alias for FastHasANSI for backward compatibility

func IsWordChar

func IsWordChar(c byte) bool

IsWordChar checks if byte is a word character

func Process

func Process(data string) string

Process is an alias for StripANSI for backward compatibility

func SplitWords

func SplitWords(input string) []string

SplitWords splits string into words (optimized)

func StripANSI

func StripANSI(input string) string

StripANSI removes ANSI sequences using optimized byte operations

Types

type CPUFeatures

type CPUFeatures struct {
	HasAVX2   bool
	HasAVX512 bool
	HasNEON   bool
}

CPUFeatures holds detected CPU capabilities.

func Detect

func Detect() CPUFeatures

Detect returns CPU SIMD capabilities

type Dispatcher

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

Dispatcher selects optimal implementation. FastHasANSI and FastCountBytes dispatch to AVX2 (amd64) when available; EntropyFilter always uses scalar (float64 SIMD is a separate concern, deferred).

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates a new Dispatcher with detected CPU features.

func (*Dispatcher) EntropyFilter

func (d *Dispatcher) EntropyFilter(data []float64) float64

EntropyFilter dispatches to scalar implementation (float64 SIMD deferred). SIMD implementations are platform-specific and deferred: - AVX2 (amd64): requires VFMADD231PD assembly in entropy_amd64.s - NEON (arm64): requires FMLA assembly in entropy_arm64.s Current scalar implementation provides baseline performance.

Jump to

Keyboard shortcuts

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