2020-05-21 17:42:44 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-03-02 13:17:33 +00:00
|
|
|
package cpu
|
2020-05-21 17:42:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
#include <sys/auxv.h>
|
|
|
|
|
|
|
|
unsigned long gethwcap() {
|
|
|
|
return getauxval(AT_HWCAP);
|
|
|
|
}
|
2022-10-14 20:11:41 +00:00
|
|
|
unsigned long gethwcap2() {
|
|
|
|
return getauxval(AT_HWCAP2);
|
|
|
|
}
|
2020-05-21 17:42:44 +00:00
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
2022-10-14 18:04:36 +00:00
|
|
|
/*
|
|
|
|
all special features for arm should be defined here; canonical list:
|
|
|
|
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/include/uapi/asm/hwcap.h
|
|
|
|
*/
|
2020-05-21 17:42:44 +00:00
|
|
|
const (
|
|
|
|
/* extension instructions */
|
|
|
|
CPU_ARM_FEATURE_SWP = 1 << iota
|
|
|
|
CPU_ARM_FEATURE_HALF
|
|
|
|
CPU_ARM_FEATURE_THUMB
|
|
|
|
CPU_ARM_FEATURE_26BIT
|
|
|
|
CPU_ARM_FEATURE_FASTMUL
|
|
|
|
CPU_ARM_FEATURE_FPA
|
|
|
|
CPU_ARM_FEATURE_VFP
|
|
|
|
CPU_ARM_FEATURE_EDSP
|
|
|
|
CPU_ARM_FEATURE_JAVA
|
|
|
|
CPU_ARM_FEATURE_IWMMXT
|
|
|
|
CPU_ARM_FEATURE_CRUNCH
|
|
|
|
CPU_ARM_FEATURE_THUMBEE
|
|
|
|
CPU_ARM_FEATURE_NEON
|
|
|
|
CPU_ARM_FEATURE_VFPv3
|
|
|
|
CPU_ARM_FEATURE_VFPv3D16
|
|
|
|
CPU_ARM_FEATURE_TLS
|
|
|
|
CPU_ARM_FEATURE_VFPv4
|
|
|
|
CPU_ARM_FEATURE_IDIVA
|
|
|
|
CPU_ARM_FEATURE_IDIVT
|
|
|
|
CPU_ARM_FEATURE_VFPD32
|
|
|
|
CPU_ARM_FEATURE_LPAE
|
|
|
|
CPU_ARM_FEATURE_EVTSTRM
|
2022-10-14 20:11:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
CPU_ARM_FEATURE2_AES = 1 << iota
|
|
|
|
CPU_ARM_FEATURE2_PMULL
|
|
|
|
CPU_ARM_FEATURE2_SHA1
|
|
|
|
CPU_ARM_FEATURE2_SHA2
|
|
|
|
CPU_ARM_FEATURE2_CRC32
|
2020-05-21 17:42:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var flagNames_arm = map[uint64]string{
|
|
|
|
CPU_ARM_FEATURE_SWP: "SWP",
|
|
|
|
CPU_ARM_FEATURE_HALF: "HALF",
|
|
|
|
CPU_ARM_FEATURE_THUMB: "THUMB",
|
|
|
|
CPU_ARM_FEATURE_26BIT: "26BIT",
|
|
|
|
CPU_ARM_FEATURE_FASTMUL: "FASTMUL",
|
|
|
|
CPU_ARM_FEATURE_FPA: "FPA",
|
|
|
|
CPU_ARM_FEATURE_VFP: "VFP",
|
|
|
|
CPU_ARM_FEATURE_EDSP: "EDSP",
|
|
|
|
CPU_ARM_FEATURE_JAVA: "JAVA",
|
|
|
|
CPU_ARM_FEATURE_IWMMXT: "IWMMXT",
|
|
|
|
CPU_ARM_FEATURE_CRUNCH: "CRUNCH",
|
|
|
|
CPU_ARM_FEATURE_THUMBEE: "THUMBEE",
|
|
|
|
CPU_ARM_FEATURE_NEON: "NEON",
|
|
|
|
CPU_ARM_FEATURE_VFPv3: "VFPv3",
|
|
|
|
CPU_ARM_FEATURE_VFPv3D16: "VFPv3D16",
|
|
|
|
CPU_ARM_FEATURE_TLS: "TLS",
|
|
|
|
CPU_ARM_FEATURE_VFPv4: "VFPv4",
|
|
|
|
CPU_ARM_FEATURE_IDIVA: "IDIVA",
|
|
|
|
CPU_ARM_FEATURE_IDIVT: "IDIVT",
|
|
|
|
CPU_ARM_FEATURE_VFPD32: "VFPD32",
|
|
|
|
CPU_ARM_FEATURE_LPAE: "LPAE",
|
|
|
|
CPU_ARM_FEATURE_EVTSTRM: "EVTSTRM",
|
2022-10-14 20:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var flag2Names_arm = map[uint64]string{
|
|
|
|
CPU_ARM_FEATURE2_AES: "AES",
|
|
|
|
CPU_ARM_FEATURE2_PMULL: "PMULL",
|
|
|
|
CPU_ARM_FEATURE2_SHA1: "SHA1",
|
|
|
|
CPU_ARM_FEATURE2_SHA2: "SHA2",
|
|
|
|
CPU_ARM_FEATURE2_CRC32: "CRC32",
|
2020-05-21 17:42:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 13:17:33 +00:00
|
|
|
func getCpuidFlags() []string {
|
2020-05-21 17:42:44 +00:00
|
|
|
r := make([]string, 0, 20)
|
|
|
|
hwcap := uint64(C.gethwcap())
|
2022-10-14 20:11:41 +00:00
|
|
|
hwcap2 := uint64(C.gethwcap2())
|
2020-05-21 17:42:44 +00:00
|
|
|
for i := uint(0); i < 64; i++ {
|
|
|
|
key := uint64(1 << i)
|
2022-10-13 11:56:49 +00:00
|
|
|
val, ok := flagNames_arm[key]
|
|
|
|
if hwcap&key != 0 && ok {
|
2020-05-21 17:42:44 +00:00
|
|
|
r = append(r, val)
|
|
|
|
}
|
|
|
|
}
|
2022-10-14 20:11:41 +00:00
|
|
|
for i := uint(0); i < 64; i++ {
|
|
|
|
key := uint64(1 << i)
|
|
|
|
val, ok := flag2Names_arm[key]
|
|
|
|
if hwcap2&key != 0 && ok {
|
|
|
|
r = append(r, val)
|
|
|
|
}
|
|
|
|
}
|
2020-05-21 17:42:44 +00:00
|
|
|
return r
|
|
|
|
}
|
2024-04-22 17:14:39 +00:00
|
|
|
|
|
|
|
func getCpuidAttributes() map[string]string { return nil }
|