cpu

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 1 Imported by: 1

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())
}

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")
	}
}

func HasAVX2

func HasAVX2() bool

HasAVX2 returns true if AVX2 is available.

func HasAVX512VL

func HasAVX512VL() bool

HasAVX512VL returns true if AVX-512VL is available.

func HasFMA

func HasFMA() bool

HasFMA returns true if FMA is available.

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")
	}
}

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)
}

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).

Jump to

Keyboard shortcuts

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