Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | #ifndef CPUINFO_H |
| 3 | #define CPUINFO_H |
| 4 | |
| 5 | #ifndef __cplusplus |
| 6 | #include <stdbool.h> |
| 7 | #endif |
| 8 | |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 9 | #ifdef __APPLE__ |
| 10 | #include <TargetConditionals.h> |
| 11 | #endif |
| 12 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 13 | #include <stdint.h> |
| 14 | |
| 15 | /* Identify architecture and define corresponding macro */ |
| 16 | |
| 17 | #if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) |
| 18 | #define CPUINFO_ARCH_X86 1 |
| 19 | #endif |
| 20 | |
| 21 | #if defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) |
| 22 | #define CPUINFO_ARCH_X86_64 1 |
| 23 | #endif |
| 24 | |
| 25 | #if defined(__arm__) || defined(_M_ARM) |
| 26 | #define CPUINFO_ARCH_ARM 1 |
| 27 | #endif |
| 28 | |
| 29 | #if defined(__aarch64__) || defined(_M_ARM64) |
| 30 | #define CPUINFO_ARCH_ARM64 1 |
| 31 | #endif |
| 32 | |
| 33 | #if defined(__PPC64__) || defined(__powerpc64__) || defined(_ARCH_PPC64) |
| 34 | #define CPUINFO_ARCH_PPC64 1 |
| 35 | #endif |
| 36 | |
| 37 | #if defined(__pnacl__) |
| 38 | #define CPUINFO_ARCH_PNACL 1 |
| 39 | #endif |
| 40 | |
| 41 | #if defined(EMSCRIPTEN) |
| 42 | #define CPUINFO_ARCH_ASMJS 1 |
| 43 | #endif |
| 44 | |
| 45 | #if CPUINFO_ARCH_X86 && defined(_MSC_VER) |
| 46 | #define CPUINFO_ABI __cdecl |
| 47 | #elif CPUINFO_ARCH_X86 && defined(__GNUC__) |
| 48 | #define CPUINFO_ABI __attribute__((__cdecl__)) |
| 49 | #else |
| 50 | #define CPUINFO_ABI |
| 51 | #endif |
| 52 | |
| 53 | /* Define other architecture-specific macros as 0 */ |
| 54 | |
| 55 | #ifndef CPUINFO_ARCH_X86 |
| 56 | #define CPUINFO_ARCH_X86 0 |
| 57 | #endif |
| 58 | |
| 59 | #ifndef CPUINFO_ARCH_X86_64 |
| 60 | #define CPUINFO_ARCH_X86_64 0 |
| 61 | #endif |
| 62 | |
| 63 | #ifndef CPUINFO_ARCH_ARM |
| 64 | #define CPUINFO_ARCH_ARM 0 |
| 65 | #endif |
| 66 | |
| 67 | #ifndef CPUINFO_ARCH_ARM64 |
| 68 | #define CPUINFO_ARCH_ARM64 0 |
| 69 | #endif |
| 70 | |
| 71 | #ifndef CPUINFO_ARCH_PPC64 |
| 72 | #define CPUINFO_ARCH_PPC64 0 |
| 73 | #endif |
| 74 | |
| 75 | #ifndef CPUINFO_ARCH_PNACL |
| 76 | #define CPUINFO_ARCH_PNACL 0 |
| 77 | #endif |
| 78 | |
| 79 | #ifndef CPUINFO_ARCH_ASMJS |
| 80 | #define CPUINFO_ARCH_ASMJS 0 |
| 81 | #endif |
| 82 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 83 | #define CPUINFO_CACHE_UNIFIED 0x00000001 |
| 84 | #define CPUINFO_CACHE_INCLUSIVE 0x00000002 |
| 85 | #define CPUINFO_CACHE_COMPLEX_INDEXING 0x00000004 |
| 86 | |
| 87 | struct cpuinfo_cache { |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 88 | /** Cache size in bytes */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 89 | uint32_t size; |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 90 | /** Number of ways of associativity */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 91 | uint32_t associativity; |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 92 | /** Number of sets */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 93 | uint32_t sets; |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 94 | /** Number of partitions */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 95 | uint32_t partitions; |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 96 | /** Line size in bytes */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 97 | uint32_t line_size; |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 98 | /** |
| 99 | * Binary characteristics of the cache (unified cache, inclusive cache, cache with complex indexing). |
| 100 | * |
| 101 | * @see CPUINFO_CACHE_UNIFIED, CPUINFO_CACHE_INCLUSIVE, CPUINFO_CACHE_COMPLEX_INDEXING |
| 102 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 103 | uint32_t flags; |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 104 | /** Index of the first logical processor that shares this cache */ |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 105 | uint32_t processor_start; |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 106 | /** Number of logical processors that share this cache */ |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 107 | uint32_t processor_count; |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | struct cpuinfo_trace_cache { |
| 111 | uint32_t uops; |
| 112 | uint32_t associativity; |
| 113 | }; |
| 114 | |
| 115 | #define CPUINFO_PAGE_SIZE_4KB 0x1000 |
| 116 | #define CPUINFO_PAGE_SIZE_1MB 0x100000 |
| 117 | #define CPUINFO_PAGE_SIZE_2MB 0x200000 |
| 118 | #define CPUINFO_PAGE_SIZE_4MB 0x400000 |
| 119 | #define CPUINFO_PAGE_SIZE_16MB 0x1000000 |
| 120 | #define CPUINFO_PAGE_SIZE_1GB 0x40000000 |
| 121 | |
| 122 | struct cpuinfo_tlb { |
| 123 | uint32_t entries; |
| 124 | uint32_t associativity; |
| 125 | uint64_t pages; |
| 126 | }; |
| 127 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 128 | /** Vendor of processor core design */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 129 | enum cpuinfo_vendor { |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 130 | /** Processor vendor is not known to the library, or the library failed to get vendor information from the OS. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 131 | cpuinfo_vendor_unknown = 0, |
Marat Dukhan | b92e2ed | 2017-09-26 19:26:41 -0700 | [diff] [blame] | 132 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 133 | /* Active vendors of modern CPUs */ |
| 134 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 135 | /** |
| 136 | * Intel Corporation. Vendor of x86, x86-64, IA64, and ARM processor microarchitectures. |
| 137 | * |
| 138 | * Sold its ARM design subsidiary in 2006. The last ARM processor design was released in 2004. |
| 139 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 140 | cpuinfo_vendor_intel = 1, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 141 | /** Advanced Micro Devices, Inc. Vendor of x86 and x86-64 processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 142 | cpuinfo_vendor_amd = 2, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 143 | /** ARM Holdings plc. Vendor of ARM and ARM64 processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 144 | cpuinfo_vendor_arm = 3, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 145 | /** Qualcomm Incorporated. Vendor of ARM and ARM64 processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 146 | cpuinfo_vendor_qualcomm = 4, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 147 | /** Apple Inc. Vendor of ARM and ARM64 processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 148 | cpuinfo_vendor_apple = 5, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 149 | /** Samsung Electronics Co., Ltd. Vendir if ARM64 processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 150 | cpuinfo_vendor_samsung = 6, |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 151 | /** Nvidia Corporation. Vendor of ARM64-compatible processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 152 | cpuinfo_vendor_nvidia = 7, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 153 | /** MIPS Technologies, Inc. Vendor of MIPS processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 154 | cpuinfo_vendor_mips = 8, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 155 | /** International Business Machines Corporation. Vendor of PowerPC processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 156 | cpuinfo_vendor_ibm = 9, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 157 | /** Ingenic Semiconductor. Vendor of MIPS processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 158 | cpuinfo_vendor_ingenic = 10, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 159 | /** |
| 160 | * VIA Technologies, Inc. Vendor of x86 and x86-64 processor microarchitectures. |
| 161 | * |
| 162 | * Processors are designed by Centaur Technology, a subsidiary of VIA Technologies. |
| 163 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 164 | cpuinfo_vendor_via = 11, |
Marat Dukhan | 92dae31 | 2017-05-09 14:10:17 +0000 | [diff] [blame] | 165 | /** Cavium, Inc. Vendor of ARM64 processor microarchitectures. */ |
| 166 | cpuinfo_vendor_cavium = 12, |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 167 | |
| 168 | /* Active vendors of embedded CPUs */ |
| 169 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 170 | /** Texas Instruments Inc. Vendor of ARM processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 171 | cpuinfo_vendor_texas_instruments = 30, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 172 | /** Marvell Technology Group Ltd. Vendor of ARM processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 173 | cpuinfo_vendor_marvell = 31, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 174 | /** RDC Semiconductor Co., Ltd. Vendor of x86 processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 175 | cpuinfo_vendor_rdc = 32, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 176 | /** DM&P Electronics Inc. Vendor of x86 processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 177 | cpuinfo_vendor_dmp = 33, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 178 | /** Motorola, Inc. Vendor of PowerPC and ARM processor microarchitectures. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 179 | cpuinfo_vendor_motorola = 34, |
| 180 | |
| 181 | /* Defunct CPU vendors */ |
Marat Dukhan | b92e2ed | 2017-09-26 19:26:41 -0700 | [diff] [blame] | 182 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 183 | /** |
| 184 | * Transmeta Corporation. Vendor of x86 processor microarchitectures. |
| 185 | * |
| 186 | * Now defunct. The last processor design was released in 2004. |
| 187 | * Transmeta processors implemented VLIW ISA and used binary translation to execute x86 code. |
| 188 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 189 | cpuinfo_vendor_transmeta = 50, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 190 | /** |
| 191 | * Cyrix Corporation. Vendor of x86 processor microarchitectures. |
| 192 | * |
| 193 | * Now defunct. The last processor design was released in 1996. |
| 194 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 195 | cpuinfo_vendor_cyrix = 51, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 196 | /** |
| 197 | * Rise Technology. Vendor of x86 processor microarchitectures. |
| 198 | * |
| 199 | * Now defunct. The last processor design was released in 1999. |
| 200 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 201 | cpuinfo_vendor_rise = 52, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 202 | /** |
| 203 | * National Semiconductor. Vendor of x86 processor microarchitectures. |
| 204 | * |
| 205 | * Sold its x86 design subsidiary in 1999. The last processor design was released in 1998. |
| 206 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 207 | cpuinfo_vendor_nsc = 53, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 208 | /** |
| 209 | * Silicon Integrated Systems. Vendor of x86 processor microarchitectures. |
| 210 | * |
| 211 | * Sold its x86 design subsidiary in 2001. The last processor design was released in 2001. |
| 212 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 213 | cpuinfo_vendor_sis = 54, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 214 | /** |
| 215 | * NexGen. Vendor of x86 processor microarchitectures. |
| 216 | * |
| 217 | * Now defunct. The last processor design was released in 1994. |
| 218 | * NexGen designed the first x86 microarchitecture which decomposed x86 instructions into simple microoperations. |
| 219 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 220 | cpuinfo_vendor_nexgen = 55, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 221 | /** |
| 222 | * United Microelectronics Corporation. Vendor of x86 processor microarchitectures. |
| 223 | * |
| 224 | * Ceased x86 in the early 1990s. The last processor design was released in 1991. |
| 225 | * Designed U5C and U5D processors. Both are 486 level. |
| 226 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 227 | cpuinfo_vendor_umc = 56, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 228 | /** |
| 229 | * Digital Equipment Corporation. Vendor of ARM processor microarchitecture. |
| 230 | * |
| 231 | * Sold its ARM designs in 1997. The last processor design was released in 1997. |
| 232 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 233 | cpuinfo_vendor_dec = 57, |
| 234 | }; |
| 235 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 236 | /** |
| 237 | * Processor microarchitecture |
| 238 | * |
| 239 | * Processors with different microarchitectures often have different instruction performance characteristics, |
| 240 | * and may have dramatically different pipeline organization. |
| 241 | */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 242 | enum cpuinfo_uarch { |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 243 | /** Microarchitecture is unknown, or the library failed to get information about the microarchitecture from OS */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 244 | cpuinfo_uarch_unknown = 0, |
| 245 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 246 | /** Pentium and Pentium MMX microarchitecture. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 247 | cpuinfo_uarch_p5 = 0x00100100, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 248 | /** Intel Quark microarchitecture. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 249 | cpuinfo_uarch_quark = 0x00100101, |
| 250 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 251 | /** Pentium Pro, Pentium II, and Pentium III. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 252 | cpuinfo_uarch_p6 = 0x00100200, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 253 | /** Pentium M. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 254 | cpuinfo_uarch_dothan = 0x00100201, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 255 | /** Intel Core microarchitecture. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 256 | cpuinfo_uarch_yonah = 0x00100202, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 257 | /** Intel Core 2 microarchitecture on 65 nm process. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 258 | cpuinfo_uarch_conroe = 0x00100203, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 259 | /** Intel Core 2 microarchitecture on 45 nm process. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 260 | cpuinfo_uarch_penryn = 0x00100204, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 261 | /** Intel Nehalem and Westmere microarchitectures (Core i3/i5/i7 1st gen). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 262 | cpuinfo_uarch_nehalem = 0x00100205, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 263 | /** Intel Sandy Bridge microarchitecture (Core i3/i5/i7 2nd gen). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 264 | cpuinfo_uarch_sandy_bridge = 0x00100206, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 265 | /** Intel Ivy Bridge microarchitecture (Core i3/i5/i7 3rd gen). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 266 | cpuinfo_uarch_ivy_bridge = 0x00100207, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 267 | /** Intel Haswell microarchitecture (Core i3/i5/i7 4th gen). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 268 | cpuinfo_uarch_haswell = 0x00100208, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 269 | /** Intel Broadwell microarchitecture. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 270 | cpuinfo_uarch_broadwell = 0x00100209, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 271 | /** Intel Sky Lake microarchitecture. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 272 | cpuinfo_uarch_sky_lake = 0x0010020A, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 273 | /** Intel Kaby Lake microarchitecture. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 274 | cpuinfo_uarch_kaby_lake = 0x0010020B, |
| 275 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 276 | /** Pentium 4 with Willamette, Northwood, or Foster cores. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 277 | cpuinfo_uarch_willamette = 0x00100300, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 278 | /** Pentium 4 with Prescott and later cores. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 279 | cpuinfo_uarch_prescott = 0x00100301, |
| 280 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 281 | /** Intel Atom on 45 nm process. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 282 | cpuinfo_uarch_bonnell = 0x00100400, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 283 | /** Intel Atom on 32 nm process. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 284 | cpuinfo_uarch_saltwell = 0x00100401, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 285 | /** Intel Silvermont microarchitecture (22 nm out-of-order Atom). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 286 | cpuinfo_uarch_silvermont = 0x00100402, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 287 | /** Intel Airmont microarchitecture (14 nm out-of-order Atom). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 288 | cpuinfo_uarch_airmont = 0x00100403, |
| 289 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 290 | /** Intel Knights Ferry HPC boards. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 291 | cpuinfo_uarch_knights_ferry = 0x00100500, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 292 | /** Intel Knights Corner HPC boards (aka Xeon Phi). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 293 | cpuinfo_uarch_knights_corner = 0x00100501, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 294 | /** Intel Knights Landing microarchitecture (second-gen MIC). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 295 | cpuinfo_uarch_knights_landing = 0x00100502, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 296 | /** Intel Knights Hill microarchitecture (third-gen MIC). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 297 | cpuinfo_uarch_knights_hill = 0x00100503, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 298 | /** Intel Knights Mill Xeon Phi. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 299 | cpuinfo_uarch_knights_mill = 0x00100504, |
| 300 | |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 301 | /** Intel/Marvell XScale series. */ |
| 302 | cpuinfo_uarch_xscale = 0x00100600, |
| 303 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 304 | /** AMD K5. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 305 | cpuinfo_uarch_k5 = 0x00200100, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 306 | /** AMD K6 and alike. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 307 | cpuinfo_uarch_k6 = 0x00200101, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 308 | /** AMD Athlon and Duron. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 309 | cpuinfo_uarch_k7 = 0x00200102, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 310 | /** AMD Athlon 64, Opteron 64. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 311 | cpuinfo_uarch_k8 = 0x00200103, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 312 | /** AMD Family 10h (Barcelona, Istambul, Magny-Cours). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 313 | cpuinfo_uarch_k10 = 0x00200104, |
| 314 | /** |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 315 | * AMD Bulldozer microarchitecture |
| 316 | * Zambezi FX-series CPUs, Zurich, Valencia and Interlagos Opteron CPUs. |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 317 | */ |
| 318 | cpuinfo_uarch_bulldozer = 0x00200105, |
| 319 | /** |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 320 | * AMD Piledriver microarchitecture |
| 321 | * Vishera FX-series CPUs, Trinity and Richland APUs, Delhi, Seoul, Abu Dhabi Opteron CPUs. |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 322 | */ |
| 323 | cpuinfo_uarch_piledriver = 0x00200106, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 324 | /** AMD Steamroller microarchitecture (Kaveri APUs). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 325 | cpuinfo_uarch_steamroller = 0x00200107, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 326 | /** AMD Excavator microarchitecture (Carizzo APUs). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 327 | cpuinfo_uarch_excavator = 0x00200108, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 328 | /** AMD Zen microarchitecture (Ryzen CPUs). */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 329 | cpuinfo_uarch_zen = 0x00200109, |
| 330 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 331 | /** NSC Geode and AMD Geode GX and LX. */ |
Marat Dukhan | e25187d | 2017-04-16 05:03:07 -0400 | [diff] [blame] | 332 | cpuinfo_uarch_geode = 0x00200200, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 333 | /** AMD Bobcat mobile microarchitecture. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 334 | cpuinfo_uarch_bobcat = 0x00200201, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 335 | /** AMD Jaguar mobile microarchitecture. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 336 | cpuinfo_uarch_jaguar = 0x00200202, |
Marat Dukhan | 818e199 | 2018-02-24 15:39:18 +0100 | [diff] [blame] | 337 | /** AMD Puma mobile microarchitecture. */ |
| 338 | cpuinfo_uarch_puma = 0x00200203, |
Marat Dukhan | b92e2ed | 2017-09-26 19:26:41 -0700 | [diff] [blame] | 339 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 340 | /** ARM7 series. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 341 | cpuinfo_uarch_arm7 = 0x00300100, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 342 | /** ARM9 series. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 343 | cpuinfo_uarch_arm9 = 0x00300101, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 344 | /** ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 345 | cpuinfo_uarch_arm11 = 0x00300102, |
| 346 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 347 | /** ARM Cortex-A5. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 348 | cpuinfo_uarch_cortex_a5 = 0x00300205, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 349 | /** ARM Cortex-A7. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 350 | cpuinfo_uarch_cortex_a7 = 0x00300207, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 351 | /** ARM Cortex-A8. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 352 | cpuinfo_uarch_cortex_a8 = 0x00300208, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 353 | /** ARM Cortex-A9. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 354 | cpuinfo_uarch_cortex_a9 = 0x00300209, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 355 | /** ARM Cortex-A12. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 356 | cpuinfo_uarch_cortex_a12 = 0x00300212, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 357 | /** ARM Cortex-A15. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 358 | cpuinfo_uarch_cortex_a15 = 0x00300215, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 359 | /** ARM Cortex-A17. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 360 | cpuinfo_uarch_cortex_a17 = 0x00300217, |
| 361 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 362 | /** ARM Cortex-A32. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 363 | cpuinfo_uarch_cortex_a32 = 0x00300332, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 364 | /** ARM Cortex-A35. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 365 | cpuinfo_uarch_cortex_a35 = 0x00300335, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 366 | /** ARM Cortex-A53. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 367 | cpuinfo_uarch_cortex_a53 = 0x00300353, |
Marat Dukhan | a8fb3dd | 2017-08-09 13:49:39 -0700 | [diff] [blame] | 368 | /** ARM Cortex-A55. */ |
| 369 | cpuinfo_uarch_cortex_a55 = 0x00300355, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 370 | /** ARM Cortex-A57. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 371 | cpuinfo_uarch_cortex_a57 = 0x00300357, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 372 | /** ARM Cortex-A72. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 373 | cpuinfo_uarch_cortex_a72 = 0x00300372, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 374 | /** ARM Cortex-A73. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 375 | cpuinfo_uarch_cortex_a73 = 0x00300373, |
Marat Dukhan | a8fb3dd | 2017-08-09 13:49:39 -0700 | [diff] [blame] | 376 | /** ARM Cortex-A75. */ |
| 377 | cpuinfo_uarch_cortex_a75 = 0x00300375, |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 378 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 379 | /** Qualcomm Scorpion. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 380 | cpuinfo_uarch_scorpion = 0x00400100, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 381 | /** Qualcomm Krait. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 382 | cpuinfo_uarch_krait = 0x00400101, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 383 | /** Qualcomm Kryo. */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 384 | cpuinfo_uarch_kryo = 0x00400102, |
| 385 | |
Marat Dukhan | 93982f2 | 2017-10-20 13:10:23 -0700 | [diff] [blame] | 386 | /** Nvidia Denver. */ |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 387 | cpuinfo_uarch_denver = 0x00500100, |
| 388 | |
Marat Dukhan | dcf096d | 2018-03-07 11:09:16 -0800 | [diff] [blame^] | 389 | /** Samsung Mongoose M1 (Exynos 8890 big cores). */ |
Marat Dukhan | a750f2a | 2018-03-07 11:07:48 -0800 | [diff] [blame] | 390 | cpuinfo_uarch_mongoose_m1 = 0x00600100, |
Marat Dukhan | dcf096d | 2018-03-07 11:09:16 -0800 | [diff] [blame^] | 391 | /** Samsung Mongoose M2 (Exynos 8895 big cores). */ |
Marat Dukhan | a750f2a | 2018-03-07 11:07:48 -0800 | [diff] [blame] | 392 | cpuinfo_uarch_mongoose_m2 = 0x00600101, |
Marat Dukhan | dcf096d | 2018-03-07 11:09:16 -0800 | [diff] [blame^] | 393 | /** Samsung Mongoose M3 (Exynos 9810 big cores). */ |
Marat Dukhan | a750f2a | 2018-03-07 11:07:48 -0800 | [diff] [blame] | 394 | cpuinfo_uarch_mongoose_m3 = 0x00600102, |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 395 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 396 | /** Apple A6 and A6X processors. */ |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 397 | cpuinfo_uarch_swift = 0x00700100, |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 398 | /** Apple A7 processor. */ |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 399 | cpuinfo_uarch_cyclone = 0x00700101, |
Hao Lu | 922070c | 2017-10-18 16:29:02 -0700 | [diff] [blame] | 400 | /** Apple A8 and A8X processor. */ |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 401 | cpuinfo_uarch_typhoon = 0x00700102, |
Hao Lu | 922070c | 2017-10-18 16:29:02 -0700 | [diff] [blame] | 402 | /** Apple A9 and A9X processor. */ |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 403 | cpuinfo_uarch_twister = 0x00700103, |
Hao Lu | 922070c | 2017-10-18 16:29:02 -0700 | [diff] [blame] | 404 | /** Apple A10 and A10X processor. */ |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 405 | cpuinfo_uarch_hurricane = 0x00700104, |
Hao Lu | 922070c | 2017-10-18 16:29:02 -0700 | [diff] [blame] | 406 | /** Apple A11 processor (big cores). */ |
| 407 | cpuinfo_uarch_monsoon = 0x00700105, |
| 408 | /** Apple A11 processor (little cores). */ |
| 409 | cpuinfo_uarch_mistral = 0x00700106, |
Marat Dukhan | 92dae31 | 2017-05-09 14:10:17 +0000 | [diff] [blame] | 410 | |
| 411 | /** Cavium ThunderX. */ |
| 412 | cpuinfo_uarch_thunderx = 0x00800100, |
Marat Dukhan | 8871832 | 2017-08-24 10:12:20 -0700 | [diff] [blame] | 413 | |
| 414 | /** Marvell PJ4. */ |
| 415 | cpuinfo_uarch_pj4 = 0x00900100, |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 416 | }; |
| 417 | |
| 418 | struct cpuinfo_processor { |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 419 | /** SMT (hyperthread) ID within a core */ |
| 420 | uint32_t smt_id; |
| 421 | /** Core containing this logical processor */ |
| 422 | const struct cpuinfo_core* core; |
| 423 | /** Physical package containing this logical processor */ |
| 424 | const struct cpuinfo_package* package; |
Marat Dukhan | 15e1df9 | 2017-09-13 11:10:10 -0700 | [diff] [blame] | 425 | #if defined(__linux__) |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 426 | /** |
| 427 | * Linux-specific ID for the logical processor: |
| 428 | * - Linux kernel exposes information about this logical processor in /sys/devices/system/cpu/cpu<linux_id>/ |
| 429 | * - Bit <linux_id> in the cpu_set_t identifies this logical processor |
| 430 | */ |
Marat Dukhan | 15e1df9 | 2017-09-13 11:10:10 -0700 | [diff] [blame] | 431 | int linux_id; |
| 432 | #endif |
Marat Dukhan | b2fc4ab | 2018-02-19 22:43:26 -0800 | [diff] [blame] | 433 | #if defined(_WIN32) |
| 434 | /** Windows-specific ID for the group containing the logical processor. */ |
| 435 | uint16_t windows_group_id; |
| 436 | /** |
| 437 | * Windows-specific ID of the logical processor within its group: |
| 438 | * - Bit <windows_processor_id> in the KAFFINITY mask identifies this logical processor within its group. |
| 439 | */ |
| 440 | uint16_t windows_processor_id; |
| 441 | #endif |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 442 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 443 | /** APIC ID (unique x86-specific ID of the logical processor) */ |
| 444 | uint32_t apic_id; |
| 445 | #endif |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 446 | struct { |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 447 | /** Level 1 instruction cache */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 448 | const struct cpuinfo_cache* l1i; |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 449 | /** Level 1 data cache */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 450 | const struct cpuinfo_cache* l1d; |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 451 | /** Level 2 unified or data cache */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 452 | const struct cpuinfo_cache* l2; |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 453 | /** Level 3 unified or data cache */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 454 | const struct cpuinfo_cache* l3; |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 455 | /** Level 4 unified or data cache */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 456 | const struct cpuinfo_cache* l4; |
| 457 | } cache; |
| 458 | }; |
| 459 | |
| 460 | struct cpuinfo_core { |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 461 | /** Index of the first logical processor on this core */ |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 462 | uint32_t processor_start; |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 463 | /** Number of logical processors on this core */ |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 464 | uint32_t processor_count; |
Marat Dukhan | 2d37dc4 | 2017-09-25 01:32:37 -0700 | [diff] [blame] | 465 | /** Core ID within a package */ |
| 466 | uint32_t core_id; |
| 467 | /** Physical package containing this core */ |
| 468 | const struct cpuinfo_package* package; |
| 469 | /** Vendor of the CPU microarchitecture for this core */ |
| 470 | enum cpuinfo_vendor vendor; |
| 471 | /** CPU microarchitecture for this core */ |
| 472 | enum cpuinfo_uarch uarch; |
| 473 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 474 | /** Value of CPUID leaf 1 EAX register for this core */ |
| 475 | uint32_t cpuid; |
| 476 | #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 |
| 477 | /** Value of Main ID Register (MIDR) for this core */ |
| 478 | uint32_t midr; |
| 479 | #endif |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 480 | }; |
| 481 | |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 482 | #define CPUINFO_PACKAGE_NAME_MAX 48 |
Marat Dukhan | c40c731 | 2017-09-21 16:08:18 -0700 | [diff] [blame] | 483 | #define CPUINFO_GPU_NAME_MAX 64 |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 484 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 485 | struct cpuinfo_package { |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 486 | /** SoC or processor chip model name */ |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 487 | char name[CPUINFO_PACKAGE_NAME_MAX]; |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 488 | #if defined(__ANDROID__) || (defined(__APPLE__) && TARGET_OS_IPHONE) |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 489 | /** Integrated GPU model name */ |
| 490 | char gpu_name[CPUINFO_GPU_NAME_MAX]; |
| 491 | #endif |
| 492 | /** Index of the first logical processor on this physical package */ |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 493 | uint32_t processor_start; |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 494 | /** Number of logical processors on this physical package */ |
Marat Dukhan | ab3a127 | 2017-08-25 23:20:07 -0700 | [diff] [blame] | 495 | uint32_t processor_count; |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 496 | /** Index of the first core on this physical package */ |
Marat Dukhan | fb4fbe0 | 2017-09-13 00:51:05 -0700 | [diff] [blame] | 497 | uint32_t core_start; |
Marat Dukhan | 8f79efb | 2017-09-25 11:17:21 -0700 | [diff] [blame] | 498 | /** Number of cores on this physical package */ |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 499 | uint32_t core_count; |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 500 | }; |
| 501 | |
| 502 | #ifdef __cplusplus |
| 503 | extern "C" { |
| 504 | #endif |
| 505 | |
Marat Dukhan | 5355651 | 2018-02-25 09:01:27 +0100 | [diff] [blame] | 506 | bool CPUINFO_ABI cpuinfo_initialize(void); |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 507 | |
| 508 | void CPUINFO_ABI cpuinfo_deinitialize(void); |
| 509 | |
| 510 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 511 | /* This structure is not a part of stable API. Use cpuinfo_has_x86_* functions instead. */ |
| 512 | struct cpuinfo_x86_isa { |
| 513 | #if CPUINFO_ARCH_X86 |
| 514 | bool rdtsc; |
| 515 | #endif |
| 516 | bool rdtscp; |
| 517 | bool rdpid; |
| 518 | bool sysenter; |
| 519 | #if CPUINFO_ARCH_X86 |
| 520 | bool syscall; |
| 521 | #endif |
| 522 | bool msr; |
| 523 | bool clzero; |
| 524 | bool clflush; |
| 525 | bool clflushopt; |
| 526 | bool mwait; |
| 527 | bool mwaitx; |
| 528 | #if CPUINFO_ARCH_X86 |
| 529 | bool emmx; |
| 530 | #endif |
| 531 | bool fxsave; |
| 532 | bool xsave; |
| 533 | #if CPUINFO_ARCH_X86 |
| 534 | bool fpu; |
| 535 | bool mmx; |
| 536 | bool mmx_plus; |
| 537 | #endif |
| 538 | bool three_d_now; |
| 539 | bool three_d_now_plus; |
| 540 | #if CPUINFO_ARCH_X86 |
| 541 | bool three_d_now_geode; |
| 542 | #endif |
| 543 | bool prefetch; |
| 544 | bool prefetchw; |
| 545 | bool prefetchwt1; |
| 546 | #if CPUINFO_ARCH_X86 |
| 547 | bool daz; |
| 548 | bool sse; |
| 549 | bool sse2; |
| 550 | #endif |
| 551 | bool sse3; |
| 552 | bool ssse3; |
| 553 | bool sse4_1; |
| 554 | bool sse4_2; |
| 555 | bool sse4a; |
| 556 | bool misaligned_sse; |
| 557 | bool avx; |
| 558 | bool fma3; |
| 559 | bool fma4; |
| 560 | bool xop; |
| 561 | bool f16c; |
| 562 | bool avx2; |
| 563 | bool avx512f; |
| 564 | bool avx512pf; |
| 565 | bool avx512er; |
| 566 | bool avx512cd; |
| 567 | bool avx512dq; |
| 568 | bool avx512bw; |
| 569 | bool avx512vl; |
| 570 | bool avx512ifma; |
| 571 | bool avx512vbmi; |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 572 | bool avx512vbmi2; |
| 573 | bool avx512bitalg; |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 574 | bool avx512vpopcntdq; |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 575 | bool avx512vnni; |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 576 | bool avx512_4vnniw; |
| 577 | bool avx512_4fmaps; |
| 578 | bool hle; |
| 579 | bool rtm; |
| 580 | bool xtest; |
| 581 | bool mpx; |
| 582 | #if CPUINFO_ARCH_X86 |
| 583 | bool cmov; |
| 584 | bool cmpxchg8b; |
| 585 | #endif |
| 586 | bool cmpxchg16b; |
| 587 | bool clwb; |
| 588 | bool movbe; |
| 589 | #if CPUINFO_ARCH_X86_64 |
| 590 | bool lahf_sahf; |
| 591 | #endif |
| 592 | bool fs_gs_base; |
| 593 | bool lzcnt; |
| 594 | bool popcnt; |
| 595 | bool tbm; |
| 596 | bool bmi; |
| 597 | bool bmi2; |
| 598 | bool adx; |
| 599 | bool aes; |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 600 | bool vaes; |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 601 | bool pclmulqdq; |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 602 | bool vpclmulqdq; |
| 603 | bool gfni; |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 604 | bool rdrand; |
| 605 | bool rdseed; |
| 606 | bool sha; |
| 607 | bool rng; |
| 608 | bool ace; |
| 609 | bool ace2; |
| 610 | bool phe; |
| 611 | bool pmm; |
| 612 | bool lwp; |
| 613 | }; |
| 614 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 615 | extern struct cpuinfo_x86_isa cpuinfo_isa; |
| 616 | #endif |
| 617 | |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 618 | static inline bool cpuinfo_has_x86_rdtsc(void) { |
| 619 | #if CPUINFO_ARCH_X86_64 |
| 620 | return true; |
| 621 | #elif CPUINFO_ARCH_X86 |
| 622 | #if defined(__ANDROID__) |
| 623 | return true; |
| 624 | #else |
| 625 | return cpuinfo_isa.rdtsc; |
| 626 | #endif |
| 627 | #else |
| 628 | return false; |
| 629 | #endif |
| 630 | } |
| 631 | |
| 632 | static inline bool cpuinfo_has_x86_rdtscp(void) { |
| 633 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 634 | return cpuinfo_isa.rdtscp; |
| 635 | #else |
| 636 | return false; |
| 637 | #endif |
| 638 | } |
| 639 | |
| 640 | static inline bool cpuinfo_has_x86_rdpid(void) { |
| 641 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 642 | return cpuinfo_isa.rdpid; |
| 643 | #else |
| 644 | return false; |
| 645 | #endif |
| 646 | } |
| 647 | |
| 648 | static inline bool cpuinfo_has_x86_clzero(void) { |
| 649 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 650 | return cpuinfo_isa.clzero; |
| 651 | #else |
| 652 | return false; |
| 653 | #endif |
| 654 | } |
| 655 | |
| 656 | static inline bool cpuinfo_has_x86_mwait(void) { |
| 657 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 658 | return cpuinfo_isa.mwait; |
| 659 | #else |
| 660 | return false; |
| 661 | #endif |
| 662 | } |
| 663 | |
| 664 | static inline bool cpuinfo_has_x86_mwaitx(void) { |
| 665 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 666 | return cpuinfo_isa.mwaitx; |
| 667 | #else |
| 668 | return false; |
| 669 | #endif |
| 670 | } |
| 671 | |
| 672 | static inline bool cpuinfo_has_x86_fxsave(void) { |
| 673 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 674 | return cpuinfo_isa.fxsave; |
| 675 | #else |
| 676 | return false; |
| 677 | #endif |
| 678 | } |
| 679 | |
| 680 | static inline bool cpuinfo_has_x86_xsave(void) { |
| 681 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 682 | return cpuinfo_isa.xsave; |
| 683 | #else |
| 684 | return false; |
| 685 | #endif |
| 686 | } |
| 687 | |
| 688 | static inline bool cpuinfo_has_x86_fpu(void) { |
| 689 | #if CPUINFO_ARCH_X86_64 |
| 690 | return true; |
| 691 | #elif CPUINFO_ARCH_X86 |
| 692 | #if defined(__ANDROID__) |
| 693 | return true; |
| 694 | #else |
| 695 | return cpuinfo_isa.fpu; |
| 696 | #endif |
| 697 | #else |
| 698 | return false; |
| 699 | #endif |
| 700 | } |
| 701 | |
| 702 | static inline bool cpuinfo_has_x86_mmx(void) { |
| 703 | #if CPUINFO_ARCH_X86_64 |
| 704 | return true; |
| 705 | #elif CPUINFO_ARCH_X86 |
| 706 | #if defined(__ANDROID__) |
| 707 | return true; |
| 708 | #else |
| 709 | return cpuinfo_isa.mmx; |
| 710 | #endif |
| 711 | #else |
| 712 | return false; |
| 713 | #endif |
| 714 | } |
| 715 | |
| 716 | static inline bool cpuinfo_has_x86_mmx_plus(void) { |
| 717 | #if CPUINFO_ARCH_X86_64 |
| 718 | return true; |
| 719 | #elif CPUINFO_ARCH_X86 |
| 720 | #if defined(__ANDROID__) |
| 721 | return true; |
| 722 | #else |
| 723 | return cpuinfo_isa.mmx_plus; |
| 724 | #endif |
| 725 | #else |
| 726 | return false; |
| 727 | #endif |
| 728 | } |
| 729 | |
| 730 | static inline bool cpuinfo_has_x86_3dnow(void) { |
| 731 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 732 | return cpuinfo_isa.three_d_now; |
| 733 | #else |
| 734 | return false; |
| 735 | #endif |
| 736 | } |
| 737 | |
| 738 | static inline bool cpuinfo_has_x86_3dnow_plus(void) { |
| 739 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 740 | return cpuinfo_isa.three_d_now_plus; |
| 741 | #else |
| 742 | return false; |
| 743 | #endif |
| 744 | } |
| 745 | |
| 746 | static inline bool cpuinfo_has_x86_3dnow_geode(void) { |
| 747 | #if CPUINFO_ARCH_X86_64 |
| 748 | return false; |
| 749 | #elif CPUINFO_ARCH_X86 |
| 750 | #if defined(__ANDROID__) |
| 751 | return false; |
| 752 | #else |
| 753 | return cpuinfo_isa.three_d_now_geode; |
| 754 | #endif |
| 755 | #else |
| 756 | return false; |
| 757 | #endif |
| 758 | } |
| 759 | |
| 760 | static inline bool cpuinfo_has_x86_prefetch(void) { |
| 761 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 762 | return cpuinfo_isa.prefetch; |
| 763 | #else |
| 764 | return false; |
| 765 | #endif |
| 766 | } |
| 767 | |
| 768 | static inline bool cpuinfo_has_x86_prefetchw(void) { |
| 769 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 770 | return cpuinfo_isa.prefetchw; |
| 771 | #else |
| 772 | return false; |
| 773 | #endif |
| 774 | } |
| 775 | |
| 776 | static inline bool cpuinfo_has_x86_prefetchwt1(void) { |
| 777 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
Marat Dukhan | 6022f80 | 2017-09-26 11:56:36 -0700 | [diff] [blame] | 778 | return cpuinfo_isa.prefetchwt1; |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 779 | #else |
| 780 | return false; |
| 781 | #endif |
| 782 | } |
| 783 | |
| 784 | static inline bool cpuinfo_has_x86_daz(void) { |
| 785 | #if CPUINFO_ARCH_X86_64 |
| 786 | return true; |
| 787 | #elif CPUINFO_ARCH_X86 |
| 788 | #if defined(__ANDROID__) |
| 789 | return true; |
| 790 | #else |
| 791 | return cpuinfo_isa.daz; |
| 792 | #endif |
| 793 | #else |
| 794 | return false; |
| 795 | #endif |
| 796 | } |
| 797 | |
Marat Dukhan | 9da4c91 | 2017-09-26 10:53:28 -0700 | [diff] [blame] | 798 | static inline bool cpuinfo_has_x86_sse(void) { |
| 799 | #if CPUINFO_ARCH_X86_64 |
| 800 | return true; |
| 801 | #elif CPUINFO_ARCH_X86 |
| 802 | #if defined(__ANDROID__) |
| 803 | return true; |
| 804 | #else |
| 805 | return cpuinfo_isa.sse; |
| 806 | #endif |
| 807 | #else |
| 808 | return false; |
| 809 | #endif |
| 810 | } |
| 811 | |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 812 | static inline bool cpuinfo_has_x86_sse2(void) { |
| 813 | #if CPUINFO_ARCH_X86_64 |
| 814 | return true; |
| 815 | #elif CPUINFO_ARCH_X86 |
| 816 | #if defined(__ANDROID__) |
| 817 | return true; |
| 818 | #else |
| 819 | return cpuinfo_isa.sse2; |
| 820 | #endif |
| 821 | #else |
| 822 | return false; |
| 823 | #endif |
| 824 | } |
| 825 | |
| 826 | static inline bool cpuinfo_has_x86_sse3(void) { |
| 827 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 828 | #if defined(__ANDROID__) |
| 829 | return true; |
| 830 | #else |
| 831 | return cpuinfo_isa.sse3; |
| 832 | #endif |
| 833 | #else |
| 834 | return false; |
| 835 | #endif |
| 836 | } |
| 837 | |
| 838 | static inline bool cpuinfo_has_x86_ssse3(void) { |
| 839 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 840 | #if defined(__ANDROID__) |
| 841 | return true; |
| 842 | #else |
| 843 | return cpuinfo_isa.ssse3; |
| 844 | #endif |
| 845 | #else |
| 846 | return false; |
| 847 | #endif |
| 848 | } |
| 849 | |
| 850 | static inline bool cpuinfo_has_x86_sse4_1(void) { |
| 851 | #if CPUINFO_ARCH_X86_64 |
| 852 | #if defined(__ANDROID__) |
| 853 | return true; |
| 854 | #else |
| 855 | return cpuinfo_isa.sse4_1; |
| 856 | #endif |
| 857 | #elif CPUINFO_ARCH_X86 |
| 858 | return cpuinfo_isa.sse4_1; |
| 859 | #else |
| 860 | return false; |
| 861 | #endif |
| 862 | } |
| 863 | |
| 864 | static inline bool cpuinfo_has_x86_sse4_2(void) { |
| 865 | #if CPUINFO_ARCH_X86_64 |
| 866 | #if defined(__ANDROID__) |
| 867 | return true; |
| 868 | #else |
| 869 | return cpuinfo_isa.sse4_2; |
| 870 | #endif |
| 871 | #elif CPUINFO_ARCH_X86 |
| 872 | return cpuinfo_isa.sse4_2; |
| 873 | #else |
| 874 | return false; |
| 875 | #endif |
| 876 | } |
| 877 | |
| 878 | static inline bool cpuinfo_has_x86_sse4a(void) { |
| 879 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 880 | return cpuinfo_isa.sse4a; |
| 881 | #else |
| 882 | return false; |
| 883 | #endif |
| 884 | } |
| 885 | |
| 886 | static inline bool cpuinfo_has_x86_misaligned_sse(void) { |
| 887 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 888 | return cpuinfo_isa.misaligned_sse; |
| 889 | #else |
| 890 | return false; |
| 891 | #endif |
| 892 | } |
| 893 | |
| 894 | static inline bool cpuinfo_has_x86_avx(void) { |
| 895 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 896 | return cpuinfo_isa.avx; |
| 897 | #else |
| 898 | return false; |
| 899 | #endif |
| 900 | } |
| 901 | |
| 902 | static inline bool cpuinfo_has_x86_fma3(void) { |
| 903 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 904 | return cpuinfo_isa.fma3; |
| 905 | #else |
| 906 | return false; |
| 907 | #endif |
| 908 | } |
| 909 | |
| 910 | static inline bool cpuinfo_has_x86_fma4(void) { |
| 911 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 912 | return cpuinfo_isa.fma4; |
| 913 | #else |
| 914 | return false; |
| 915 | #endif |
| 916 | } |
| 917 | |
| 918 | static inline bool cpuinfo_has_x86_xop(void) { |
| 919 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 920 | return cpuinfo_isa.xop; |
| 921 | #else |
| 922 | return false; |
| 923 | #endif |
| 924 | } |
| 925 | |
| 926 | static inline bool cpuinfo_has_x86_f16c(void) { |
| 927 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 928 | return cpuinfo_isa.f16c; |
| 929 | #else |
| 930 | return false; |
| 931 | #endif |
| 932 | } |
| 933 | |
| 934 | static inline bool cpuinfo_has_x86_avx2(void) { |
| 935 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 936 | return cpuinfo_isa.avx2; |
| 937 | #else |
| 938 | return false; |
| 939 | #endif |
| 940 | } |
| 941 | |
| 942 | static inline bool cpuinfo_has_x86_avx512f(void) { |
| 943 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 944 | return cpuinfo_isa.avx512f; |
| 945 | #else |
| 946 | return false; |
| 947 | #endif |
| 948 | } |
| 949 | |
| 950 | static inline bool cpuinfo_has_x86_avx512pf(void) { |
| 951 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 952 | return cpuinfo_isa.avx512pf; |
| 953 | #else |
| 954 | return false; |
| 955 | #endif |
| 956 | } |
| 957 | |
| 958 | static inline bool cpuinfo_has_x86_avx512er(void) { |
| 959 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 960 | return cpuinfo_isa.avx512er; |
| 961 | #else |
| 962 | return false; |
| 963 | #endif |
| 964 | } |
| 965 | |
| 966 | static inline bool cpuinfo_has_x86_avx512cd(void) { |
| 967 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 968 | return cpuinfo_isa.avx512cd; |
| 969 | #else |
| 970 | return false; |
| 971 | #endif |
| 972 | } |
| 973 | |
| 974 | static inline bool cpuinfo_has_x86_avx512dq(void) { |
| 975 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 976 | return cpuinfo_isa.avx512dq; |
| 977 | #else |
| 978 | return false; |
| 979 | #endif |
| 980 | } |
| 981 | |
| 982 | static inline bool cpuinfo_has_x86_avx512bw(void) { |
| 983 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 984 | return cpuinfo_isa.avx512bw; |
| 985 | #else |
| 986 | return false; |
| 987 | #endif |
| 988 | } |
| 989 | |
| 990 | static inline bool cpuinfo_has_x86_avx512vl(void) { |
| 991 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 992 | return cpuinfo_isa.avx512vl; |
| 993 | #else |
| 994 | return false; |
| 995 | #endif |
| 996 | } |
| 997 | |
| 998 | static inline bool cpuinfo_has_x86_avx512ifma(void) { |
| 999 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1000 | return cpuinfo_isa.avx512ifma; |
| 1001 | #else |
| 1002 | return false; |
| 1003 | #endif |
| 1004 | } |
| 1005 | |
| 1006 | static inline bool cpuinfo_has_x86_avx512vbmi(void) { |
| 1007 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1008 | return cpuinfo_isa.avx512vbmi; |
| 1009 | #else |
| 1010 | return false; |
| 1011 | #endif |
| 1012 | } |
| 1013 | |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 1014 | static inline bool cpuinfo_has_x86_avx512vbmi2(void) { |
| 1015 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1016 | return cpuinfo_isa.avx512vbmi2; |
| 1017 | #else |
| 1018 | return false; |
| 1019 | #endif |
| 1020 | } |
| 1021 | |
| 1022 | static inline bool cpuinfo_has_x86_avx512bitalg(void) { |
| 1023 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1024 | return cpuinfo_isa.avx512bitalg; |
| 1025 | #else |
| 1026 | return false; |
| 1027 | #endif |
| 1028 | } |
| 1029 | |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1030 | static inline bool cpuinfo_has_x86_avx512vpopcntdq(void) { |
| 1031 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1032 | return cpuinfo_isa.avx512vpopcntdq; |
| 1033 | #else |
| 1034 | return false; |
| 1035 | #endif |
| 1036 | } |
| 1037 | |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 1038 | static inline bool cpuinfo_has_x86_avx512vnni(void) { |
Marat Dukhan | 6b33b23 | 2017-10-13 09:36:52 -0700 | [diff] [blame] | 1039 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 1040 | return cpuinfo_isa.avx512vnni; |
| 1041 | #else |
| 1042 | return false; |
| 1043 | #endif |
| 1044 | } |
| 1045 | |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1046 | static inline bool cpuinfo_has_x86_avx512_4vnniw(void) { |
| 1047 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1048 | return cpuinfo_isa.avx512_4vnniw; |
| 1049 | #else |
| 1050 | return false; |
| 1051 | #endif |
| 1052 | } |
| 1053 | |
| 1054 | static inline bool cpuinfo_has_x86_avx512_4fmaps(void) { |
| 1055 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1056 | return cpuinfo_isa.avx512_4fmaps; |
| 1057 | #else |
| 1058 | return false; |
| 1059 | #endif |
| 1060 | } |
| 1061 | |
Marat Dukhan | 9e32e8d | 2017-09-26 11:02:37 -0700 | [diff] [blame] | 1062 | static inline bool cpuinfo_has_x86_hle(void) { |
| 1063 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1064 | return cpuinfo_isa.hle; |
| 1065 | #else |
| 1066 | return false; |
| 1067 | #endif |
| 1068 | } |
| 1069 | |
| 1070 | static inline bool cpuinfo_has_x86_rtm(void) { |
| 1071 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1072 | return cpuinfo_isa.rtm; |
| 1073 | #else |
| 1074 | return false; |
| 1075 | #endif |
| 1076 | } |
| 1077 | |
| 1078 | static inline bool cpuinfo_has_x86_xtest(void) { |
| 1079 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1080 | return cpuinfo_isa.xtest; |
| 1081 | #else |
| 1082 | return false; |
| 1083 | #endif |
| 1084 | } |
| 1085 | |
| 1086 | static inline bool cpuinfo_has_x86_mpx(void) { |
| 1087 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1088 | return cpuinfo_isa.mpx; |
| 1089 | #else |
| 1090 | return false; |
| 1091 | #endif |
| 1092 | } |
| 1093 | |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1094 | static inline bool cpuinfo_has_x86_cmov(void) { |
| 1095 | #if CPUINFO_ARCH_X86_64 |
| 1096 | return true; |
| 1097 | #elif CPUINFO_ARCH_X86 |
| 1098 | return cpuinfo_isa.cmov; |
| 1099 | #else |
| 1100 | return false; |
| 1101 | #endif |
| 1102 | } |
| 1103 | |
| 1104 | static inline bool cpuinfo_has_x86_cmpxchg8b(void) { |
| 1105 | #if CPUINFO_ARCH_X86_64 |
| 1106 | return true; |
| 1107 | #elif CPUINFO_ARCH_X86 |
| 1108 | return cpuinfo_isa.cmpxchg8b; |
| 1109 | #else |
| 1110 | return false; |
| 1111 | #endif |
| 1112 | } |
| 1113 | |
| 1114 | static inline bool cpuinfo_has_x86_cmpxchg16b(void) { |
| 1115 | #if CPUINFO_ARCH_X86_64 |
| 1116 | return cpuinfo_isa.cmpxchg16b; |
| 1117 | #else |
| 1118 | return false; |
| 1119 | #endif |
| 1120 | } |
| 1121 | |
| 1122 | static inline bool cpuinfo_has_x86_clwb(void) { |
| 1123 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1124 | return cpuinfo_isa.clwb; |
| 1125 | #else |
| 1126 | return false; |
| 1127 | #endif |
| 1128 | } |
| 1129 | |
| 1130 | static inline bool cpuinfo_has_x86_movbe(void) { |
Marat Dukhan | 6022f80 | 2017-09-26 11:56:36 -0700 | [diff] [blame] | 1131 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1132 | return cpuinfo_isa.movbe; |
| 1133 | #else |
| 1134 | return false; |
| 1135 | #endif |
| 1136 | } |
| 1137 | |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 1138 | static inline bool cpuinfo_has_x86_lahf_sahf(void) { |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1139 | #if CPUINFO_ARCH_X86 |
| 1140 | return true; |
| 1141 | #elif CPUINFO_ARCH_X86_64 |
| 1142 | return cpuinfo_isa.lahf_sahf; |
| 1143 | #else |
| 1144 | return false; |
| 1145 | #endif |
| 1146 | } |
| 1147 | |
| 1148 | static inline bool cpuinfo_has_x86_lzcnt(void) { |
| 1149 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1150 | return cpuinfo_isa.lzcnt; |
| 1151 | #else |
| 1152 | return false; |
| 1153 | #endif |
| 1154 | } |
| 1155 | |
| 1156 | static inline bool cpuinfo_has_x86_popcnt(void) { |
| 1157 | #if CPUINFO_ARCH_X86_64 |
| 1158 | #if defined(__ANDROID__) |
| 1159 | return true; |
| 1160 | #else |
| 1161 | return cpuinfo_isa.popcnt; |
| 1162 | #endif |
| 1163 | #elif CPUINFO_ARCH_X86 |
| 1164 | return cpuinfo_isa.popcnt; |
| 1165 | #else |
| 1166 | return false; |
| 1167 | #endif |
| 1168 | } |
| 1169 | |
| 1170 | static inline bool cpuinfo_has_x86_tbm(void) { |
| 1171 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1172 | return cpuinfo_isa.tbm; |
| 1173 | #else |
| 1174 | return false; |
| 1175 | #endif |
| 1176 | } |
| 1177 | |
| 1178 | static inline bool cpuinfo_has_x86_bmi(void) { |
| 1179 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1180 | return cpuinfo_isa.bmi; |
| 1181 | #else |
| 1182 | return false; |
| 1183 | #endif |
| 1184 | } |
| 1185 | |
| 1186 | static inline bool cpuinfo_has_x86_bmi2(void) { |
| 1187 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1188 | return cpuinfo_isa.bmi2; |
| 1189 | #else |
| 1190 | return false; |
| 1191 | #endif |
| 1192 | } |
| 1193 | |
| 1194 | static inline bool cpuinfo_has_x86_adx(void) { |
| 1195 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1196 | return cpuinfo_isa.adx; |
| 1197 | #else |
| 1198 | return false; |
| 1199 | #endif |
| 1200 | } |
| 1201 | |
| 1202 | static inline bool cpuinfo_has_x86_aes(void) { |
| 1203 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1204 | return cpuinfo_isa.aes; |
| 1205 | #else |
| 1206 | return false; |
| 1207 | #endif |
| 1208 | } |
| 1209 | |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 1210 | static inline bool cpuinfo_has_x86_vaes(void) { |
| 1211 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1212 | return cpuinfo_isa.vaes; |
| 1213 | #else |
| 1214 | return false; |
| 1215 | #endif |
| 1216 | } |
| 1217 | |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1218 | static inline bool cpuinfo_has_x86_pclmulqdq(void) { |
| 1219 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1220 | return cpuinfo_isa.pclmulqdq; |
| 1221 | #else |
| 1222 | return false; |
| 1223 | #endif |
| 1224 | } |
| 1225 | |
Marat Dukhan | 861d21a | 2017-10-13 07:10:25 -0700 | [diff] [blame] | 1226 | static inline bool cpuinfo_has_x86_vpclmulqdq(void) { |
| 1227 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1228 | return cpuinfo_isa.vpclmulqdq; |
| 1229 | #else |
| 1230 | return false; |
| 1231 | #endif |
| 1232 | } |
| 1233 | |
| 1234 | static inline bool cpuinfo_has_x86_gfni(void) { |
| 1235 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1236 | return cpuinfo_isa.gfni; |
| 1237 | #else |
| 1238 | return false; |
| 1239 | #endif |
| 1240 | } |
| 1241 | |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1242 | static inline bool cpuinfo_has_x86_rdrand(void) { |
| 1243 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1244 | return cpuinfo_isa.rdrand; |
| 1245 | #else |
| 1246 | return false; |
| 1247 | #endif |
| 1248 | } |
| 1249 | |
| 1250 | static inline bool cpuinfo_has_x86_rdseed(void) { |
| 1251 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1252 | return cpuinfo_isa.rdseed; |
| 1253 | #else |
| 1254 | return false; |
| 1255 | #endif |
| 1256 | } |
| 1257 | |
| 1258 | static inline bool cpuinfo_has_x86_sha(void) { |
| 1259 | #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 |
| 1260 | return cpuinfo_isa.sha; |
| 1261 | #else |
| 1262 | return false; |
| 1263 | #endif |
| 1264 | } |
| 1265 | |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 1266 | #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1267 | /* This structure is not a part of stable API. Use cpuinfo_has_arm_* functions instead. */ |
| 1268 | struct cpuinfo_arm_isa { |
| 1269 | #if CPUINFO_ARCH_ARM |
| 1270 | bool thumb; |
| 1271 | bool thumb2; |
| 1272 | bool thumbee; |
| 1273 | bool jazelle; |
| 1274 | bool armv5e; |
| 1275 | bool armv6; |
| 1276 | bool armv6k; |
| 1277 | bool armv7; |
| 1278 | bool armv7mp; |
| 1279 | bool idiv; |
| 1280 | |
| 1281 | bool vfpv2; |
| 1282 | bool vfpv3; |
| 1283 | bool d32; |
| 1284 | bool fp16; |
| 1285 | bool fma; |
| 1286 | |
| 1287 | bool wmmx; |
| 1288 | bool wmmx2; |
| 1289 | bool neon; |
| 1290 | #endif |
| 1291 | #if CPUINFO_ARCH_ARM64 |
| 1292 | bool atomics; |
| 1293 | bool rdm; |
| 1294 | bool fp16arith; |
| 1295 | bool jscvt; |
| 1296 | bool fcma; |
| 1297 | #endif |
| 1298 | |
| 1299 | bool aes; |
| 1300 | bool sha1; |
| 1301 | bool sha2; |
| 1302 | bool pmull; |
| 1303 | bool crc32; |
| 1304 | }; |
| 1305 | |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 1306 | extern struct cpuinfo_arm_isa cpuinfo_isa; |
| 1307 | #endif |
| 1308 | |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1309 | static inline bool cpuinfo_has_arm_thumb(void) { |
| 1310 | #if CPUINFO_ARCH_ARM |
| 1311 | return cpuinfo_isa.thumb; |
| 1312 | #else |
| 1313 | return false; |
| 1314 | #endif |
| 1315 | } |
| 1316 | |
| 1317 | static inline bool cpuinfo_has_arm_thumb2(void) { |
| 1318 | #if CPUINFO_ARCH_ARM |
| 1319 | return cpuinfo_isa.thumb2; |
| 1320 | #else |
| 1321 | return false; |
| 1322 | #endif |
| 1323 | } |
| 1324 | |
| 1325 | static inline bool cpuinfo_has_arm_v5e(void) { |
| 1326 | #if CPUINFO_ARCH_ARM |
| 1327 | return cpuinfo_isa.armv5e; |
| 1328 | #else |
| 1329 | return false; |
| 1330 | #endif |
| 1331 | } |
| 1332 | |
| 1333 | static inline bool cpuinfo_has_arm_v6(void) { |
| 1334 | #if CPUINFO_ARCH_ARM |
| 1335 | return cpuinfo_isa.armv6; |
| 1336 | #else |
| 1337 | return false; |
| 1338 | #endif |
| 1339 | } |
| 1340 | |
| 1341 | static inline bool cpuinfo_has_arm_v6k(void) { |
| 1342 | #if CPUINFO_ARCH_ARM |
| 1343 | return cpuinfo_isa.armv6k; |
| 1344 | #else |
| 1345 | return false; |
| 1346 | #endif |
| 1347 | } |
| 1348 | |
| 1349 | static inline bool cpuinfo_has_arm_v7(void) { |
| 1350 | #if CPUINFO_ARCH_ARM |
| 1351 | return cpuinfo_isa.armv7; |
| 1352 | #else |
| 1353 | return false; |
| 1354 | #endif |
| 1355 | } |
| 1356 | |
| 1357 | static inline bool cpuinfo_has_arm_v7mp(void) { |
| 1358 | #if CPUINFO_ARCH_ARM |
| 1359 | return cpuinfo_isa.armv7mp; |
| 1360 | #else |
| 1361 | return false; |
| 1362 | #endif |
| 1363 | } |
| 1364 | |
| 1365 | static inline bool cpuinfo_has_arm_idiv(void) { |
| 1366 | #if CPUINFO_ARCH_ARM64 |
| 1367 | return true; |
| 1368 | #elif CPUINFO_ARCH_ARM |
| 1369 | return cpuinfo_isa.idiv; |
| 1370 | #else |
| 1371 | return false; |
| 1372 | #endif |
| 1373 | } |
| 1374 | |
| 1375 | static inline bool cpuinfo_has_arm_vfpv2(void) { |
| 1376 | #if CPUINFO_ARCH_ARM |
| 1377 | return cpuinfo_isa.vfpv2; |
| 1378 | #else |
| 1379 | return false; |
| 1380 | #endif |
| 1381 | } |
| 1382 | |
| 1383 | static inline bool cpuinfo_has_arm_vfpv3(void) { |
| 1384 | #if CPUINFO_ARCH_ARM64 |
| 1385 | return true; |
| 1386 | #elif CPUINFO_ARCH_ARM |
| 1387 | return cpuinfo_isa.vfpv3; |
| 1388 | #else |
| 1389 | return false; |
| 1390 | #endif |
| 1391 | } |
| 1392 | |
| 1393 | static inline bool cpuinfo_has_arm_vfpv3_d32(void) { |
| 1394 | #if CPUINFO_ARCH_ARM64 |
| 1395 | return true; |
| 1396 | #elif CPUINFO_ARCH_ARM |
| 1397 | return cpuinfo_isa.vfpv3 && cpuinfo_isa.d32; |
| 1398 | #else |
| 1399 | return false; |
| 1400 | #endif |
| 1401 | } |
| 1402 | |
| 1403 | static inline bool cpuinfo_has_arm_vfpv3_fp16(void) { |
| 1404 | #if CPUINFO_ARCH_ARM64 |
| 1405 | return true; |
| 1406 | #elif CPUINFO_ARCH_ARM |
| 1407 | return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16; |
| 1408 | #else |
| 1409 | return false; |
| 1410 | #endif |
| 1411 | } |
| 1412 | |
| 1413 | static inline bool cpuinfo_has_arm_vfpv3_fp16_d32(void) { |
| 1414 | #if CPUINFO_ARCH_ARM64 |
| 1415 | return true; |
| 1416 | #elif CPUINFO_ARCH_ARM |
| 1417 | return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16 && cpuinfo_isa.d32; |
| 1418 | #else |
| 1419 | return false; |
| 1420 | #endif |
| 1421 | } |
| 1422 | |
Marat Dukhan | 6022f80 | 2017-09-26 11:56:36 -0700 | [diff] [blame] | 1423 | static inline bool cpuinfo_has_arm_vfpv4(void) { |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1424 | #if CPUINFO_ARCH_ARM64 |
| 1425 | return true; |
| 1426 | #elif CPUINFO_ARCH_ARM |
| 1427 | return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma; |
| 1428 | #else |
| 1429 | return false; |
| 1430 | #endif |
| 1431 | } |
| 1432 | |
Marat Dukhan | 6022f80 | 2017-09-26 11:56:36 -0700 | [diff] [blame] | 1433 | static inline bool cpuinfo_has_arm_vfpv4_d32(void) { |
Marat Dukhan | f720d10 | 2017-09-26 10:33:47 -0700 | [diff] [blame] | 1434 | #if CPUINFO_ARCH_ARM64 |
| 1435 | return true; |
| 1436 | #elif CPUINFO_ARCH_ARM |
| 1437 | return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma && cpuinfo_isa.d32; |
| 1438 | #else |
| 1439 | return false; |
| 1440 | #endif |
| 1441 | } |
| 1442 | |
| 1443 | static inline bool cpuinfo_has_arm_wmmx(void) { |
| 1444 | #if CPUINFO_ARCH_ARM |
| 1445 | return cpuinfo_isa.wmmx; |
| 1446 | #else |
| 1447 | return false; |
| 1448 | #endif |
| 1449 | } |
| 1450 | |
| 1451 | static inline bool cpuinfo_has_arm_wmmx2(void) { |
| 1452 | #if CPUINFO_ARCH_ARM |
| 1453 | return cpuinfo_isa.wmmx2; |
| 1454 | #else |
| 1455 | return false; |
| 1456 | #endif |
| 1457 | } |
| 1458 | |
| 1459 | static inline bool cpuinfo_has_arm_neon(void) { |
| 1460 | #if CPUINFO_ARCH_ARM64 |
| 1461 | return true; |
| 1462 | #elif CPUINFO_ARCH_ARM |
| 1463 | return cpuinfo_isa.neon; |
| 1464 | #else |
| 1465 | return false; |
| 1466 | #endif |
| 1467 | } |
| 1468 | |
| 1469 | static inline bool cpuinfo_has_arm_neon_fp16(void) { |
| 1470 | #if CPUINFO_ARCH_ARM64 |
| 1471 | return true; |
| 1472 | #elif CPUINFO_ARCH_ARM |
| 1473 | return cpuinfo_isa.neon && cpuinfo_isa.fp16; |
| 1474 | #else |
| 1475 | return false; |
| 1476 | #endif |
| 1477 | } |
| 1478 | |
| 1479 | static inline bool cpuinfo_has_arm_neon_fma(void) { |
| 1480 | #if CPUINFO_ARCH_ARM64 |
| 1481 | return true; |
| 1482 | #elif CPUINFO_ARCH_ARM |
| 1483 | return cpuinfo_isa.neon && cpuinfo_isa.fma; |
| 1484 | #else |
| 1485 | return false; |
| 1486 | #endif |
| 1487 | } |
| 1488 | |
| 1489 | static inline bool cpuinfo_has_arm_atomics(void) { |
| 1490 | #if CPUINFO_ARCH_ARM64 |
| 1491 | return cpuinfo_isa.atomics; |
| 1492 | #else |
| 1493 | return false; |
| 1494 | #endif |
| 1495 | } |
| 1496 | |
| 1497 | static inline bool cpuinfo_has_arm_neon_rdm(void) { |
| 1498 | #if CPUINFO_ARCH_ARM64 |
| 1499 | return cpuinfo_isa.rdm; |
| 1500 | #else |
| 1501 | return false; |
| 1502 | #endif |
| 1503 | } |
| 1504 | |
| 1505 | static inline bool cpuinfo_has_arm_fp16_arith(void) { |
| 1506 | #if CPUINFO_ARCH_ARM64 |
| 1507 | return cpuinfo_isa.fp16arith; |
| 1508 | #else |
| 1509 | return false; |
| 1510 | #endif |
| 1511 | } |
| 1512 | |
| 1513 | static inline bool cpuinfo_has_arm_jscvt(void) { |
| 1514 | #if CPUINFO_ARCH_ARM64 |
| 1515 | return cpuinfo_isa.jscvt; |
| 1516 | #else |
| 1517 | return false; |
| 1518 | #endif |
| 1519 | } |
| 1520 | |
| 1521 | static inline bool cpuinfo_has_arm_fcma(void) { |
| 1522 | #if CPUINFO_ARCH_ARM64 |
| 1523 | return cpuinfo_isa.fcma; |
| 1524 | #else |
| 1525 | return false; |
| 1526 | #endif |
| 1527 | } |
| 1528 | |
| 1529 | static inline bool cpuinfo_has_arm_aes(void) { |
| 1530 | #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 |
| 1531 | return cpuinfo_isa.aes; |
| 1532 | #else |
| 1533 | return false; |
| 1534 | #endif |
| 1535 | } |
| 1536 | |
| 1537 | static inline bool cpuinfo_has_arm_sha1(void) { |
| 1538 | #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 |
| 1539 | return cpuinfo_isa.sha1; |
| 1540 | #else |
| 1541 | return false; |
| 1542 | #endif |
| 1543 | } |
| 1544 | |
| 1545 | static inline bool cpuinfo_has_arm_sha2(void) { |
| 1546 | #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 |
| 1547 | return cpuinfo_isa.sha2; |
| 1548 | #else |
| 1549 | return false; |
| 1550 | #endif |
| 1551 | } |
| 1552 | |
| 1553 | static inline bool cpuinfo_has_arm_pmull(void) { |
| 1554 | #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 |
| 1555 | return cpuinfo_isa.pmull; |
| 1556 | #else |
| 1557 | return false; |
| 1558 | #endif |
| 1559 | } |
| 1560 | |
| 1561 | static inline bool cpuinfo_has_arm_crc32(void) { |
| 1562 | #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 |
| 1563 | return cpuinfo_isa.crc32; |
| 1564 | #else |
| 1565 | return false; |
| 1566 | #endif |
| 1567 | } |
| 1568 | |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 1569 | const struct cpuinfo_processor* cpuinfo_get_processors(void); |
| 1570 | const struct cpuinfo_core* cpuinfo_get_cores(void); |
| 1571 | const struct cpuinfo_package* cpuinfo_get_packages(void); |
| 1572 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_caches(void); |
| 1573 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_caches(void); |
| 1574 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_caches(void); |
| 1575 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_caches(void); |
| 1576 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_caches(void); |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 1577 | |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 1578 | const struct cpuinfo_processor* cpuinfo_get_processor(uint32_t index); |
| 1579 | const struct cpuinfo_core* cpuinfo_get_core(uint32_t index); |
| 1580 | const struct cpuinfo_package* cpuinfo_get_package(uint32_t index); |
| 1581 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_cache(uint32_t index); |
| 1582 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_cache(uint32_t index); |
| 1583 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_cache(uint32_t index); |
| 1584 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_cache(uint32_t index); |
| 1585 | const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_cache(uint32_t index); |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 1586 | |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 1587 | uint32_t cpuinfo_get_processors_count(void); |
| 1588 | uint32_t cpuinfo_get_cores_count(void); |
| 1589 | uint32_t cpuinfo_get_packages_count(void); |
| 1590 | uint32_t CPUINFO_ABI cpuinfo_get_l1i_caches_count(void); |
| 1591 | uint32_t CPUINFO_ABI cpuinfo_get_l1d_caches_count(void); |
| 1592 | uint32_t CPUINFO_ABI cpuinfo_get_l2_caches_count(void); |
| 1593 | uint32_t CPUINFO_ABI cpuinfo_get_l3_caches_count(void); |
| 1594 | uint32_t CPUINFO_ABI cpuinfo_get_l4_caches_count(void); |
Marat Dukhan | 8ecad1a | 2017-05-08 07:21:57 +0000 | [diff] [blame] | 1595 | |
Marat Dukhan | 3040197 | 2017-09-26 18:35:52 -0700 | [diff] [blame] | 1596 | const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_current_processor(void); |
| 1597 | const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_current_core(void); |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 1598 | |
| 1599 | #ifdef __cplusplus |
| 1600 | } /* extern "C" */ |
| 1601 | #endif |
| 1602 | |
| 1603 | #endif /* CPUINFO_H */ |