blob: 79a38a0b9bccb3f8de6e4e02345245d528376f66 [file] [log] [blame]
Ian Lance Tayloraa8901e2019-09-06 18:12:46 +00001// 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
5package cpu
6
Ian Lance Tayloraa8901e2019-09-06 18:12:46 +00007// HWCAP/HWCAP2 bits. These are exposed by Linux.
8const (
9 hwcap_FP = 1 << 0
10 hwcap_ASIMD = 1 << 1
11 hwcap_EVTSTRM = 1 << 2
12 hwcap_AES = 1 << 3
13 hwcap_PMULL = 1 << 4
14 hwcap_SHA1 = 1 << 5
15 hwcap_SHA2 = 1 << 6
16 hwcap_CRC32 = 1 << 7
17 hwcap_ATOMICS = 1 << 8
18 hwcap_FPHP = 1 << 9
19 hwcap_ASIMDHP = 1 << 10
20 hwcap_CPUID = 1 << 11
21 hwcap_ASIMDRDM = 1 << 12
22 hwcap_JSCVT = 1 << 13
23 hwcap_FCMA = 1 << 14
24 hwcap_LRCPC = 1 << 15
25 hwcap_DCPOP = 1 << 16
26 hwcap_SHA3 = 1 << 17
27 hwcap_SM3 = 1 << 18
28 hwcap_SM4 = 1 << 19
29 hwcap_ASIMDDP = 1 << 20
30 hwcap_SHA512 = 1 << 21
31 hwcap_SVE = 1 << 22
32 hwcap_ASIMDFHM = 1 << 23
33)
34
35func doinit() {
Ian Lance Taylorf75af8c2020-07-27 22:27:54 -070036 if err := readHWCAP(); err != nil {
37 // failed to read /proc/self/auxv, try reading registers directly
38 readARM64Registers()
39 return
40 }
41
Ian Lance Tayloraa8901e2019-09-06 18:12:46 +000042 // HWCAP feature bits
43 ARM64.HasFP = isSet(hwCap, hwcap_FP)
44 ARM64.HasASIMD = isSet(hwCap, hwcap_ASIMD)
45 ARM64.HasEVTSTRM = isSet(hwCap, hwcap_EVTSTRM)
46 ARM64.HasAES = isSet(hwCap, hwcap_AES)
47 ARM64.HasPMULL = isSet(hwCap, hwcap_PMULL)
48 ARM64.HasSHA1 = isSet(hwCap, hwcap_SHA1)
49 ARM64.HasSHA2 = isSet(hwCap, hwcap_SHA2)
50 ARM64.HasCRC32 = isSet(hwCap, hwcap_CRC32)
51 ARM64.HasATOMICS = isSet(hwCap, hwcap_ATOMICS)
52 ARM64.HasFPHP = isSet(hwCap, hwcap_FPHP)
53 ARM64.HasASIMDHP = isSet(hwCap, hwcap_ASIMDHP)
54 ARM64.HasCPUID = isSet(hwCap, hwcap_CPUID)
55 ARM64.HasASIMDRDM = isSet(hwCap, hwcap_ASIMDRDM)
56 ARM64.HasJSCVT = isSet(hwCap, hwcap_JSCVT)
57 ARM64.HasFCMA = isSet(hwCap, hwcap_FCMA)
58 ARM64.HasLRCPC = isSet(hwCap, hwcap_LRCPC)
59 ARM64.HasDCPOP = isSet(hwCap, hwcap_DCPOP)
60 ARM64.HasSHA3 = isSet(hwCap, hwcap_SHA3)
61 ARM64.HasSM3 = isSet(hwCap, hwcap_SM3)
62 ARM64.HasSM4 = isSet(hwCap, hwcap_SM4)
63 ARM64.HasASIMDDP = isSet(hwCap, hwcap_ASIMDDP)
64 ARM64.HasSHA512 = isSet(hwCap, hwcap_SHA512)
65 ARM64.HasSVE = isSet(hwCap, hwcap_SVE)
66 ARM64.HasASIMDFHM = isSet(hwCap, hwcap_ASIMDFHM)
67}
68
69func isSet(hwc uint, value uint) bool {
70 return hwc&value != 0
71}