1
2
3
4
5 package cpu
6
7 import (
8 "os"
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
28 if a := getAuxv(); len(a) > 0 {
29 for len(a) >= 2 {
30 tag, val := a[0], uint(a[1])
31 a = a[2:]
32 switch tag {
33 case _AT_HWCAP:
34 hwCap = val
35 case _AT_HWCAP2:
36 hwCap2 = val
37 }
38 }
39 return nil
40 }
41
42 buf, err := os.ReadFile(procAuxv)
43 if err != nil {
44
45
46
47
48 return err
49 }
50 bo := hostByteOrder()
51 for len(buf) >= 2*(uintSize/8) {
52 var tag, val uint
53 switch uintSize {
54 case 32:
55 tag = uint(bo.Uint32(buf[0:]))
56 val = uint(bo.Uint32(buf[4:]))
57 buf = buf[8:]
58 case 64:
59 tag = uint(bo.Uint64(buf[0:]))
60 val = uint(bo.Uint64(buf[8:]))
61 buf = buf[16:]
62 }
63 switch tag {
64 case _AT_HWCAP:
65 hwCap = val
66 case _AT_HWCAP2:
67 hwCap2 = val
68 }
69 }
70 return nil
71 }
72
View as plain text