Source File
hwcap_linux.go
Belonging Package
vendor/golang.org/x/sys/cpu
// Copyright 2019 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
import (
)
const (
_AT_HWCAP = 16
_AT_HWCAP2 = 26
procAuxv = "/proc/self/auxv"
uintSize = int(32 << (^uint(0) >> 63))
)
// For those platforms don't have a 'cpuid' equivalent we use HWCAP/HWCAP2
// These are initialized in cpu_$GOARCH.go
// and should not be changed after they are initialized.
var hwCap uint
var hwCap2 uint
func readHWCAP() error {
// For Go 1.21+, get auxv from the Go runtime.
if := getAuxv(); len() > 0 {
for len() >= 2 {
, := [0], uint([1])
= [2:]
switch {
case _AT_HWCAP:
hwCap =
case _AT_HWCAP2:
hwCap2 =
}
}
return nil
}
, := os.ReadFile(procAuxv)
if != nil {
// e.g. on android /proc/self/auxv is not accessible, so silently
// ignore the error and leave Initialized = false. On some
// architectures (e.g. arm64) doinit() implements a fallback
// readout and will set Initialized = true again.
return
}
:= hostByteOrder()
for len() >= 2*(uintSize/8) {
var , uint
switch uintSize {
case 32:
= uint(.Uint32([0:]))
= uint(.Uint32([4:]))
= [8:]
case 64:
= uint(.Uint64([0:]))
= uint(.Uint64([8:]))
= [16:]
}
switch {
case _AT_HWCAP:
hwCap =
case _AT_HWCAP2:
hwCap2 =
}
}
return nil
}
The pages are generated with Golds v0.7.0-preview. (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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |