1// Copyright 2018 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5//+build !amd64,!amd64p32,!386 6 7package cpu 8 9import ( 10 "io/ioutil" 11) 12 13const ( 14 _AT_HWCAP = 16 15 _AT_HWCAP2 = 26 16 17 procAuxv = "/proc/self/auxv" 18 19 uintSize = int(32 << (^uint(0) >> 63)) 20) 21 22// For those platforms don't have a 'cpuid' equivalent we use HWCAP/HWCAP2 23// These are initialized in cpu_$GOARCH.go 24// and should not be changed after they are initialized. 25var HWCap uint 26var HWCap2 uint 27 28func init() { 29 buf, err := ioutil.ReadFile(procAuxv) 30 if err != nil { 31 panic("read proc auxv failed: " + err.Error()) 32 } 33 34 bo := hostByteOrder() 35 for len(buf) >= 2*(uintSize/8) { 36 var tag, val uint 37 switch uintSize { 38 case 32: 39 tag = uint(bo.Uint32(buf[0:])) 40 val = uint(bo.Uint32(buf[4:])) 41 buf = buf[8:] 42 case 64: 43 tag = uint(bo.Uint64(buf[0:])) 44 val = uint(bo.Uint64(buf[8:])) 45 buf = buf[16:] 46 } 47 switch tag { 48 case _AT_HWCAP: 49 HWCap = val 50 case _AT_HWCAP2: 51 HWCap2 = val 52 } 53 } 54 doinit() 55} 56