1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Interface to retrieve hardware capabilities. It relies on Linux's getauxval 16 // or `/proc/self/auxval` under the hood. 17 #ifndef CPU_FEATURES_INCLUDE_INTERNAL_HWCAPS_H_ 18 #define CPU_FEATURES_INCLUDE_INTERNAL_HWCAPS_H_ 19 20 #include <stdint.h> 21 #include "cpu_features_macros.h" 22 23 CPU_FEATURES_START_CPP_NAMESPACE 24 25 // To avoid depending on the linux kernel we reproduce the architecture specific 26 // constants here. 27 28 // http://elixir.free-electrons.com/linux/latest/source/arch/arm64/include/uapi/asm/hwcap.h 29 #define AARCH64_HWCAP_FP (1UL << 0) 30 #define AARCH64_HWCAP_ASIMD (1UL << 1) 31 #define AARCH64_HWCAP_AES (1UL << 3) 32 #define AARCH64_HWCAP_PMULL (1UL << 4) 33 #define AARCH64_HWCAP_SHA1 (1UL << 5) 34 #define AARCH64_HWCAP_SHA2 (1UL << 6) 35 #define AARCH64_HWCAP_CRC32 (1UL << 7) 36 37 // http://elixir.free-electrons.com/linux/latest/source/arch/arm/include/uapi/asm/hwcap.h 38 #define ARM_HWCAP_SWP (1UL << 0) 39 #define ARM_HWCAP_HALF (1UL << 1) 40 #define ARM_HWCAP_THUMB (1UL << 2) 41 #define ARM_HWCAP_26BIT (1UL << 3) 42 #define ARM_HWCAP_FAST_MULT (1UL << 4) 43 #define ARM_HWCAP_FPA (1UL << 5) 44 #define ARM_HWCAP_VFP (1UL << 6) 45 #define ARM_HWCAP_EDSP (1UL << 7) 46 #define ARM_HWCAP_JAVA (1UL << 8) 47 #define ARM_HWCAP_IWMMXT (1UL << 9) 48 #define ARM_HWCAP_CRUNCH (1UL << 10) 49 #define ARM_HWCAP_THUMBEE (1UL << 11) 50 #define ARM_HWCAP_NEON (1UL << 12) 51 #define ARM_HWCAP_VFPV3 (1UL << 13) 52 #define ARM_HWCAP_VFPV3D16 (1UL << 14) 53 #define ARM_HWCAP_TLS (1UL << 15) 54 #define ARM_HWCAP_VFPV4 (1UL << 16) 55 #define ARM_HWCAP_IDIVA (1UL << 17) 56 #define ARM_HWCAP_IDIVT (1UL << 18) 57 #define ARM_HWCAP_VFPD32 (1UL << 19) 58 #define ARM_HWCAP_LPAE (1UL << 20) 59 #define ARM_HWCAP_EVTSTRM (1UL << 21) 60 #define ARM_HWCAP2_AES (1UL << 0) 61 #define ARM_HWCAP2_PMULL (1UL << 1) 62 #define ARM_HWCAP2_SHA1 (1UL << 2) 63 #define ARM_HWCAP2_SHA2 (1UL << 3) 64 #define ARM_HWCAP2_CRC32 (1UL << 4) 65 66 // http://elixir.free-electrons.com/linux/latest/source/arch/mips/include/uapi/asm/hwcap.h 67 #define MIPS_HWCAP_R6 (1UL << 0) 68 #define MIPS_HWCAP_MSA (1UL << 1) 69 #define MIPS_HWCAP_CRC32 (1UL << 2) 70 71 // http://elixir.free-electrons.com/linux/latest/source/arch/powerpc/include/uapi/asm/cputable.h 72 #ifndef _UAPI__ASM_POWERPC_CPUTABLE_H 73 /* in AT_HWCAP */ 74 #define PPC_FEATURE_32 0x80000000 75 #define PPC_FEATURE_64 0x40000000 76 #define PPC_FEATURE_601_INSTR 0x20000000 77 #define PPC_FEATURE_HAS_ALTIVEC 0x10000000 78 #define PPC_FEATURE_HAS_FPU 0x08000000 79 #define PPC_FEATURE_HAS_MMU 0x04000000 80 #define PPC_FEATURE_HAS_4xxMAC 0x02000000 81 #define PPC_FEATURE_UNIFIED_CACHE 0x01000000 82 #define PPC_FEATURE_HAS_SPE 0x00800000 83 #define PPC_FEATURE_HAS_EFP_SINGLE 0x00400000 84 #define PPC_FEATURE_HAS_EFP_DOUBLE 0x00200000 85 #define PPC_FEATURE_NO_TB 0x00100000 86 #define PPC_FEATURE_POWER4 0x00080000 87 #define PPC_FEATURE_POWER5 0x00040000 88 #define PPC_FEATURE_POWER5_PLUS 0x00020000 89 #define PPC_FEATURE_CELL 0x00010000 90 #define PPC_FEATURE_BOOKE 0x00008000 91 #define PPC_FEATURE_SMT 0x00004000 92 #define PPC_FEATURE_ICACHE_SNOOP 0x00002000 93 #define PPC_FEATURE_ARCH_2_05 0x00001000 94 #define PPC_FEATURE_PA6T 0x00000800 95 #define PPC_FEATURE_HAS_DFP 0x00000400 96 #define PPC_FEATURE_POWER6_EXT 0x00000200 97 #define PPC_FEATURE_ARCH_2_06 0x00000100 98 #define PPC_FEATURE_HAS_VSX 0x00000080 99 100 #define PPC_FEATURE_PSERIES_PERFMON_COMPAT 0x00000040 101 102 /* Reserved - do not use 0x00000004 */ 103 #define PPC_FEATURE_TRUE_LE 0x00000002 104 #define PPC_FEATURE_PPC_LE 0x00000001 105 106 /* in AT_HWCAP2 */ 107 #define PPC_FEATURE2_ARCH_2_07 0x80000000 108 #define PPC_FEATURE2_HTM 0x40000000 109 #define PPC_FEATURE2_DSCR 0x20000000 110 #define PPC_FEATURE2_EBB 0x10000000 111 #define PPC_FEATURE2_ISEL 0x08000000 112 #define PPC_FEATURE2_TAR 0x04000000 113 #define PPC_FEATURE2_VEC_CRYPTO 0x02000000 114 #define PPC_FEATURE2_HTM_NOSC 0x01000000 115 #define PPC_FEATURE2_ARCH_3_00 0x00800000 116 #define PPC_FEATURE2_HAS_IEEE128 0x00400000 117 #define PPC_FEATURE2_DARN 0x00200000 118 #define PPC_FEATURE2_SCV 0x00100000 119 #define PPC_FEATURE2_HTM_NO_SUSPEND 0x00080000 120 #endif 121 122 typedef struct { 123 unsigned long hwcaps; 124 unsigned long hwcaps2; 125 } HardwareCapabilities; 126 127 HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void); 128 129 typedef struct { 130 char platform[64]; // 0 terminated string 131 char base_platform[64]; // 0 terminated string 132 } PlatformType; 133 134 PlatformType CpuFeatures_GetPlatformType(void); 135 136 CPU_FEATURES_END_CPP_NAMESPACE 137 138 #endif // CPU_FEATURES_INCLUDE_INTERNAL_HWCAPS_H_ 139