processorfeatures

package module
v0.0.0-...-5fc72c9 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: BSD-3-Clause Imports: 8 Imported by: 1

README

Go Reference Go Report Card codecov

amd64 arm v linux windows

Processor characteristics

Processor variables direct the Go compiler to use some processor instructions. The variable has an effect only when cross-compiling or re-compiling go locally. The intent is to ease the detection of processor characteristics and the set of the related processor variables.

Linux

Pseudo-file /proc/cpuinfo is parsed to load processor flags. Reported flags are used to determine version of processor. Pseudo-file is /proc/self/auxv is parsed to load machine features.

Windows

Win32 API call IsProcessorFeaturePresent is used to collect the features of the processor.

amd64

Several checks are available but not every instruction of each version. Impact should be limited as the standard expects instructions to all be present for each version. Level is set when all verifiable features are present. Details are available in the structure ProcessorFeatures.

arm

The availability of VFP defines level 6 or higher for GOARM. If v8 instruction set is available, GOARM is unset and GOARCH is set to ARM64.

Further reading

amd64

Microarchitecture_levels Default for Go on amd64 is v1.

arm

ARM Developer handbook

Version history

API is still evolving.
arm machine features are not used for now.

Documentation

Overview

Package processorfeatures provides details on the available processor features

Code generated using 'go generate'; DO NOT EDIT. hwcap2flags files contain the HWCAP flags for each architecture

Index

Constants

View Source
const (
	AT_NULL = 0

	AT_IGNORE = 1
	AT_EXECFD = 2
	AT_PHDR   = 3
	AT_PHENT  = 4
	AT_PHNUM  = 5
	AT_PAGESZ = 6
	AT_BASE   = 7
	AT_FLAGS  = 8
	AT_ENTRY  = 9
	AT_NOTELF = 10
	AT_UID    = 11
	AT_EUID   = 12
	AT_GID    = 13
	AT_EGID   = 14
	AT_CLKTCK = 17

	AT_PLATFORM = 15
	AT_HWCAP    = 16

	AT_FPUCW = 18

	AT_DCACHEBSIZE = 19
	AT_ICACHEBSIZE = 20
	AT_UCACHEBSIZE = 21

	AT_IGNOREPPC = 22

	AT_SECURE = 23

	AT_BASE_PLATFORM = 24

	AT_RANDOM = 25

	AT_HWCAP2 = 26

	AT_EXECFN = 31

	AT_SYSINFO      = 32
	AT_SYSINFO_EHDR = 33

	AT_L1I_CACHESHAPE = 34
	AT_L1D_CACHESHAPE = 35
	AT_L2_CACHESHAPE  = 36
	AT_L3_CACHESHAPE  = 37

	AT_L1I_CACHESIZE     = 40
	AT_L1I_CACHEGEOMETRY = 41
	AT_L1D_CACHESIZE     = 42
	AT_L1D_CACHEGEOMETRY = 43
	AT_L2_CACHESIZE      = 44
	AT_L2_CACHEGEOMETRY  = 45
	AT_L3_CACHESIZE      = 46
	AT_L3_CACHEGEOMETRY  = 47

	AT_MINSIGSTKSZ = 51
)

Variables

View Source
var Bits32 bool // true when 32 bits architecture
View Source
var LEndian bool // true when little (low) endian architecture
View Source
var MachineFeatures = []ProcessorFeature{
	{0, "", "none", "NONE  0"},
	{1, "", "64", "64  1"},
	{2, "", "pc32", "PC32  2"},
	{3, "", "got32", "GOT32  3"},
	{4, "", "plt32", "PLT32  4"},
	{5, "", "copy", "COPY  5"},
	{6, "", "glob_dat", "GLOB_DAT 6"},
	{7, "", "jump_slot", "JUMP_SLOT 7"},
	{8, "", "relative", "RELATIVE 8"},
	{9, "", "gotpcrel", "GOTPCREL 9"},
	{10, "", "32", "32  10"},
	{11, "", "32s", "32S  11"},
	{12, "", "16", "16  12"},
	{13, "", "pc16", "PC16  13"},
	{14, "", "8", "8  14"},
	{15, "", "pc8", "PC8  15"},
	{16, "", "dtpmod64", "DTPMOD64 16"},
	{17, "", "dtpoff64", "DTPOFF64 17"},
	{18, "", "tpoff64", "TPOFF64 18"},
	{19, "", "tlsgd", "TLSGD  19"},
	{20, "", "tlsld", "TLSLD  20"},
	{21, "", "dtpoff32", "DTPOFF32 21"},
	{22, "", "gottpoff", "GOTTPOFF 22"},
	{23, "", "tpoff32", "TPOFF32 23"},
	{24, "", "pc64", "PC64  24"},
	{25, "", "gotoff64", "GOTOFF64 25"},
	{26, "", "gotpc32", "GOTPC32 26"},
	{27, "", "got64", "GOT64  27"},
	{28, "", "gotpcrel64", "GOTPCREL64 28"},
	{29, "", "gotpc64", "GOTPC64 29"},
	{30, "", "gotplt64", "GOTPLT64 30"},
	{31, "", "pltoff64", "PLTOFF64 31"},
	{32, "", "size32", "SIZE32  32"},
	{33, "", "size64", "SIZE64  33"},
	{34, "", "gotpc32_tlsdesc", "GOTPC32_TLSDESC 34"},
	{35, "", "tlsdesc_call", "TLSDESC_CALL   35"},
	{36, "", "tlsdesc", "TLSDESC        36"},
	{37, "", "irelative", "IRELATIVE 37"},
	{38, "", "relative64", "RELATIVE64 38"},
	{41, "", "gotpcrelx", "GOTPCRELX 41"},
	{42, "", "rex_gotpcrelx", "REX_GOTPCRELX 42"},
	{43, "", "num", "NUM  43"},
}
View Source
var ProcessorFeatures = []ProcessorFeature{}/* 138 elements not displayed */

Functions

func IsMachineComplete

func IsMachineComplete(v string) (missing []uint32)

IsMachineComplete verifies all machine features listed for version v

func IsMachineFeaturePresent

func IsMachineFeaturePresent(i uint32) (bool, error)

IsMachineFeaturePresent returns true when the feature identified by the number is present.

func IsProcessorFeaturePresent

func IsProcessorFeaturePresent(i uint32) (bool, error)

IsProcessorFeaturePresent returns true when the feature identified by the number is present.

func IsVersionComplete

func IsVersionComplete(v string) (missing []uint32)

IsVersionComplete verifies all features listed for version v

func LoadHWCAP2

func LoadHWCAP2() (uint32, error)

LoadHWCAP2 returns HWCAP2 as a uint64 by reading /proc/self/auxv. THe error is always returned. The caller can ignore the io.EOF when the value is not 0.

func SetGOAMD64v

func SetGOAMD64v() (v string, err error)

SetGOAMD64v sets GOAMD64 for the current go session. Default v1 is used when no higher version is complete. Version set is returned or an error.

func SetGOARMv

func SetGOARMv() (v string, err error)

SetGOARMv sets GOARM and GOARCH and returns arm64, 7 or 6 depending on identified processor features.

Types

type ProcessorFeature

type ProcessorFeature struct {
	I   uint32 // Feature number
	V   string // Version when defined by standard.
	S   string // Flag name
	Doc string // Documentation
}

Directories

Path Synopsis
architecture module
getauxval module
setprocessor module

Jump to

Keyboard shortcuts

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