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 ¶
- func ContainsAny(s string, substrs []string) bool
- func ContainsWord(s, word string) bool
- func FastContains(s, substr string) bool
- func FastCountBytes(data string, target byte) int
- func FastEqual(a, b string) bool
- func FastHasANSI(data string) bool
- func FastLower(s string) string
- func HasANSI(data string) bool
- func IsWordChar(c byte) bool
- func Process(data string) string
- func SplitWords(input string) []string
- func StripANSI(input string) string
- type CPUFeatures
- type Dispatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsAny ¶
ContainsAny checks if string contains any of the substrings
func ContainsWord ¶
ContainsWord checks if string contains word (space-delimited)
func FastContains ¶
FastContains checks if string contains substring (optimized for small patterns)
func FastCountBytes ¶
FastCountBytes counts bytes using unrolled scalar loop (dispatches to AVX2 on amd64 when available).
func FastHasANSI ¶
FastHasANSI checks for ANSI sequences using unrolled scalar loop (dispatches to AVX2 on amd64 when available).
func SplitWords ¶
SplitWords splits string into words (optimized)
Types ¶
type CPUFeatures ¶
CPUFeatures holds detected CPU 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.