Source File
cpu.go
Belonging Package
golang.org/x/sys/cpu
// Copyright 2018 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// Package cpu implements processor feature detection for// various CPU architectures.package cpuimport ()// Initialized reports whether the CPU features were initialized.//// For some GOOS/GOARCH combinations initialization of the CPU features depends// on reading an operating specific file, e.g. /proc/self/auxv on linux/arm// Initialized will report false if reading the file fails.var Initialized bool// CacheLinePad is used to pad structs to avoid false sharing.type CacheLinePad struct{ _ [cacheLineSize]byte }// X86 contains the supported CPU features of the// current X86/AMD64 platform. If the current platform// is not X86/AMD64 then all feature flags are false.//// X86 is padded to avoid false sharing. Further the HasAVX// and HasAVX2 are only set if the OS supports XMM and YMM// registers in addition to the CPUID feature bit being set.var X86 struct {_ CacheLinePadHasAES bool // AES hardware implementation (AES NI)HasADX bool // Multi-precision add-carry instruction extensionsHasAVX bool // Advanced vector extensionHasAVX2 bool // Advanced vector extension 2HasAVX512 bool // Advanced vector extension 512HasAVX512F bool // Advanced vector extension 512 Foundation InstructionsHasAVX512CD bool // Advanced vector extension 512 Conflict Detection InstructionsHasAVX512ER bool // Advanced vector extension 512 Exponential and Reciprocal InstructionsHasAVX512PF bool // Advanced vector extension 512 Prefetch InstructionsHasAVX512VL bool // Advanced vector extension 512 Vector Length ExtensionsHasAVX512BW bool // Advanced vector extension 512 Byte and Word InstructionsHasAVX512DQ bool // Advanced vector extension 512 Doubleword and Quadword InstructionsHasAVX512IFMA bool // Advanced vector extension 512 Integer Fused Multiply AddHasAVX512VBMI bool // Advanced vector extension 512 Vector Byte Manipulation InstructionsHasAVX5124VNNIW bool // Advanced vector extension 512 Vector Neural Network Instructions Word variable precisionHasAVX5124FMAPS bool // Advanced vector extension 512 Fused Multiply Accumulation Packed Single precisionHasAVX512VPOPCNTDQ bool // Advanced vector extension 512 Double and quad word population count instructionsHasAVX512VPCLMULQDQ bool // Advanced vector extension 512 Vector carry-less multiply operationsHasAVX512VNNI bool // Advanced vector extension 512 Vector Neural Network InstructionsHasAVX512GFNI bool // Advanced vector extension 512 Galois field New InstructionsHasAVX512VAES bool // Advanced vector extension 512 Vector AES instructionsHasAVX512VBMI2 bool // Advanced vector extension 512 Vector Byte Manipulation Instructions 2HasAVX512BITALG bool // Advanced vector extension 512 Bit AlgorithmsHasAVX512BF16 bool // Advanced vector extension 512 BFloat16 InstructionsHasAMXTile bool // Advanced Matrix Extension Tile instructionsHasAMXInt8 bool // Advanced Matrix Extension Int8 instructionsHasAMXBF16 bool // Advanced Matrix Extension BFloat16 instructionsHasBMI1 bool // Bit manipulation instruction set 1HasBMI2 bool // Bit manipulation instruction set 2HasCX16 bool // Compare and exchange 16 BytesHasERMS bool // Enhanced REP for MOVSB and STOSBHasFMA bool // Fused-multiply-add instructionsHasOSXSAVE bool // OS supports XSAVE/XRESTOR for saving/restoring XMM registers.HasPCLMULQDQ bool // PCLMULQDQ instruction - most often used for AES-GCMHasPOPCNT bool // Hamming weight instruction POPCNT.HasRDRAND bool // RDRAND instruction (on-chip random number generator)HasRDSEED bool // RDSEED instruction (on-chip random number generator)HasSSE2 bool // Streaming SIMD extension 2 (always available on amd64)HasSSE3 bool // Streaming SIMD extension 3HasSSSE3 bool // Supplemental streaming SIMD extension 3HasSSE41 bool // Streaming SIMD extension 4 and 4.1HasSSE42 bool // Streaming SIMD extension 4 and 4.2_ CacheLinePad}// ARM64 contains the supported CPU features of the// current ARMv8(aarch64) platform. If the current platform// is not arm64 then all feature flags are false.var ARM64 struct {_ CacheLinePadHasFP bool // Floating-point instruction set (always available)HasASIMD bool // Advanced SIMD (always available)HasEVTSTRM bool // Event stream supportHasAES bool // AES hardware implementationHasPMULL bool // Polynomial multiplication instruction setHasSHA1 bool // SHA1 hardware implementationHasSHA2 bool // SHA2 hardware implementationHasCRC32 bool // CRC32 hardware implementationHasATOMICS bool // Atomic memory operation instruction setHasFPHP bool // Half precision floating-point instruction setHasASIMDHP bool // Advanced SIMD half precision instruction setHasCPUID bool // CPUID identification scheme registersHasASIMDRDM bool // Rounding double multiply add/subtract instruction setHasJSCVT bool // Javascript conversion from floating-point to integerHasFCMA bool // Floating-point multiplication and addition of complex numbersHasLRCPC bool // Release Consistent processor consistent supportHasDCPOP bool // Persistent memory supportHasSHA3 bool // SHA3 hardware implementationHasSM3 bool // SM3 hardware implementationHasSM4 bool // SM4 hardware implementationHasASIMDDP bool // Advanced SIMD double precision instruction setHasSHA512 bool // SHA512 hardware implementationHasSVE bool // Scalable Vector ExtensionsHasASIMDFHM bool // Advanced SIMD multiplication FP16 to FP32_ CacheLinePad}// ARM contains the supported CPU features of the current ARM (32-bit) platform.// All feature flags are false if:// 1. the current platform is not arm, or// 2. the current operating system is not Linux.var ARM struct {_ CacheLinePadHasSWP bool // SWP instruction supportHasHALF bool // Half-word load and store supportHasTHUMB bool // ARM Thumb instruction setHas26BIT bool // Address space limited to 26-bitsHasFASTMUL bool // 32-bit operand, 64-bit result multiplication supportHasFPA bool // Floating point arithmetic supportHasVFP bool // Vector floating point supportHasEDSP bool // DSP Extensions supportHasJAVA bool // Java instruction setHasIWMMXT bool // Intel Wireless MMX technology supportHasCRUNCH bool // MaverickCrunch context switching and handlingHasTHUMBEE bool // Thumb EE instruction setHasNEON bool // NEON instruction setHasVFPv3 bool // Vector floating point version 3 supportHasVFPv3D16 bool // Vector floating point version 3 D8-D15HasTLS bool // Thread local storage supportHasVFPv4 bool // Vector floating point version 4 supportHasIDIVA bool // Integer divide instruction support in ARM modeHasIDIVT bool // Integer divide instruction support in Thumb modeHasVFPD32 bool // Vector floating point version 3 D15-D31HasLPAE bool // Large Physical Address ExtensionsHasEVTSTRM bool // Event stream supportHasAES bool // AES hardware implementationHasPMULL bool // Polynomial multiplication instruction setHasSHA1 bool // SHA1 hardware implementationHasSHA2 bool // SHA2 hardware implementationHasCRC32 bool // CRC32 hardware implementation_ CacheLinePad}// MIPS64X contains the supported CPU features of the current mips64/mips64le// platforms. If the current platform is not mips64/mips64le or the current// operating system is not Linux then all feature flags are false.var MIPS64X struct {_ CacheLinePadHasMSA bool // MIPS SIMD architecture_ CacheLinePad}// PPC64 contains the supported CPU features of the current ppc64/ppc64le platforms.// If the current platform is not ppc64/ppc64le then all feature flags are false.//// For ppc64/ppc64le, it is safe to check only for ISA level starting on ISA v3.00,// since there are no optional categories. There are some exceptions that also// require kernel support to work (DARN, SCV), so there are feature bits for// those as well. The struct is padded to avoid false sharing.var PPC64 struct {_ CacheLinePadHasDARN bool // Hardware random number generator (requires kernel enablement)HasSCV bool // Syscall vectored (requires kernel enablement)IsPOWER8 bool // ISA v2.07 (POWER8)IsPOWER9 bool // ISA v3.00 (POWER9), implies IsPOWER8_ CacheLinePad}// S390X contains the supported CPU features of the current IBM Z// (s390x) platform. If the current platform is not IBM Z then all// feature flags are false.//// S390X is padded to avoid false sharing. Further HasVX is only set// if the OS supports vector registers in addition to the STFLE// feature bit being set.var S390X struct {_ CacheLinePadHasZARCH bool // z/Architecture mode is active [mandatory]HasSTFLE bool // store facility list extendedHasLDISP bool // long (20-bit) displacementsHasEIMM bool // 32-bit immediatesHasDFP bool // decimal floating pointHasETF3EH bool // ETF-3 enhancedHasMSA bool // message security assist (CPACF)HasAES bool // KM-AES{128,192,256} functionsHasAESCBC bool // KMC-AES{128,192,256} functionsHasAESCTR bool // KMCTR-AES{128,192,256} functionsHasAESGCM bool // KMA-GCM-AES{128,192,256} functionsHasGHASH bool // KIMD-GHASH functionHasSHA1 bool // K{I,L}MD-SHA-1 functionsHasSHA256 bool // K{I,L}MD-SHA-256 functionsHasSHA512 bool // K{I,L}MD-SHA-512 functionsHasSHA3 bool // K{I,L}MD-SHA3-{224,256,384,512} and K{I,L}MD-SHAKE-{128,256} functionsHasVX bool // vector facilityHasVXE bool // vector-enhancements facility 1_ CacheLinePad}func () {archInit()initOptions()processOptions()}// options contains the cpu debug options that can be used in GODEBUG.// Options are arch dependent and are added by the arch specific initOptions functions.// Features that are mandatory for the specific GOARCH should have the Required field set// (e.g. SSE2 on amd64).var options []option// Option names should be lower case. e.g. avx instead of AVX.type option struct {Name stringFeature *boolSpecified bool // whether feature value was specified in GODEBUGEnable bool // whether feature should be enabledRequired bool // whether feature is mandatory and can not be disabled}func () {:= os.Getenv("GODEBUG"):for != "" {:= "":= strings.IndexByte(, ',')if < 0 {, = , ""} else {, = [:], [+1:]}if len() < 4 || [:4] != "cpu." {continue}= strings.IndexByte(, '=')if < 0 {print("GODEBUG sys/cpu: no value specified for \"", , "\"\n")continue}, := [4:], [+1:] // e.g. "SSE2", "on"var boolswitch {case "on":= truecase "off":= falsedefault:print("GODEBUG sys/cpu: value \"", , "\" not supported for cpu option \"", , "\"\n")continue}if == "all" {for := range options {options[].Specified = trueoptions[].Enable = || options[].Required}continue}for := range options {if options[].Name == {options[].Specified = trueoptions[].Enable =continue}}print("GODEBUG sys/cpu: unknown cpu feature \"", , "\"\n")}for , := range options {if !.Specified {continue}if .Enable && !*.Feature {print("GODEBUG sys/cpu: can not enable \"", .Name, "\", missing CPU support\n")continue}if !.Enable && .Required {print("GODEBUG sys/cpu: can not disable \"", .Name, "\", required CPU feature\n")continue}*.Feature = .Enable}}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |