Documentation
¶
Overview ¶
Package cpu provides CPU feature detection for SIMD operations.
Example ¶
package main
import (
"fmt"
"github.com/tphakala/simd/cpu"
)
func main() {
// Check available SIMD features
fmt.Println("CPU Info:", cpu.Info())
fmt.Println("AVX:", cpu.HasAVX())
fmt.Println("AVX2:", cpu.HasAVX2())
fmt.Println("FMA:", cpu.HasFMA())
fmt.Println("NEON:", cpu.HasNEON())
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasAVX ¶
func HasAVX() bool
HasAVX returns true if AVX is available.
Example ¶
package main
import (
"fmt"
"github.com/tphakala/simd/cpu"
)
func main() {
if cpu.HasAVX() {
fmt.Println("AVX is available")
} else {
fmt.Println("AVX is not available")
}
}
Output:
func HasFP16 ¶ added in v1.0.19
func HasFP16() bool
HasFP16 returns true if ARM FP16 (half-precision) is available.
func HasNEON ¶
func HasNEON() bool
HasNEON returns true if ARM NEON is available.
Example ¶
package main
import (
"fmt"
"github.com/tphakala/simd/cpu"
)
func main() {
if cpu.HasNEON() {
fmt.Println("NEON is available")
} else {
fmt.Println("NEON is not available")
}
}
Output:
func Info ¶
func Info() string
Info returns a string describing the available SIMD features.
Example ¶
package main
import (
"fmt"
"github.com/tphakala/simd/cpu"
)
func main() {
// Returns a string like "AMD64 AVX2+FMA" or "ARM64 NEON"
info := cpu.Info()
fmt.Printf("CPU supports: %s\n", info)
}
Output:
Types ¶
type Features ¶
type Features struct {
// x86/AMD64 features
SSE bool
SSE2 bool
SSE3 bool
SSSE3 bool
SSE41 bool
SSE42 bool
AVX bool
AVX2 bool
AVX512F bool
AVX512VL bool
FMA bool
BMI1 bool
BMI2 bool
POPCNT bool
// ARM64 features
NEON bool
FP16 bool // ARM64 half-precision floating point (FEAT_FP16)
SVE bool
SVE2 bool
}
Features contains detected CPU SIMD capabilities.
var ARM64 Features
ARM64 contains ARM64 CPU features (populated on arm64).
var X86 Features
X86 contains x86/AMD64 CPU features (populated on amd64).
Click to show internal directories.
Click to hide internal directories.