1
2
3
4
5 package cpu
6
7 import (
8 "io/ioutil"
9 )
10
11 const (
12 _AT_HWCAP = 16
13 _AT_HWCAP2 = 26
14
15 procAuxv = "/proc/self/auxv"
16
17 uintSize = int(32 << (^uint(0) >> 63))
18 )
19
20
21
22
23 var hwCap uint
24 var hwCap2 uint
25
26 func readHWCAP() error {
27 buf, err := ioutil.ReadFile(procAuxv)
28 if err != nil {
29
30
31
32
33 return err
34 }
35 bo := hostByteOrder()
36 for len(buf) >= 2*(uintSize/8) {
37 var tag, val uint
38 switch uintSize {
39 case 32:
40 tag = uint(bo.Uint32(buf[0:]))
41 val = uint(bo.Uint32(buf[4:]))
42 buf = buf[8:]
43 case 64:
44 tag = uint(bo.Uint64(buf[0:]))
45 val = uint(bo.Uint64(buf[8:]))
46 buf = buf[16:]
47 }
48 switch tag {
49 case _AT_HWCAP:
50 hwCap = val
51 case _AT_HWCAP2:
52 hwCap2 = val
53 }
54 }
55 return nil
56 }
57
View as plain text