OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 The Android Open Source Project | 2 * Copyright (C) 2010 The Android Open Source Project |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above copyright | 10 * * Redistributions in binary form must reproduce the above copyright |
(...skipping 15 matching lines...) Expand all Loading... |
26 * SUCH DAMAGE. | 26 * SUCH DAMAGE. |
27 */ | 27 */ |
28 #ifndef CPU_FEATURES_H | 28 #ifndef CPU_FEATURES_H |
29 #define CPU_FEATURES_H | 29 #define CPU_FEATURES_H |
30 | 30 |
31 #include <sys/cdefs.h> | 31 #include <sys/cdefs.h> |
32 #include <stdint.h> | 32 #include <stdint.h> |
33 | 33 |
34 __BEGIN_DECLS | 34 __BEGIN_DECLS |
35 | 35 |
| 36 /* A list of valid values returned by android_getCpuFamily(). |
| 37 * They describe the CPU Architecture of the current process. |
| 38 */ |
36 typedef enum { | 39 typedef enum { |
37 ANDROID_CPU_FAMILY_UNKNOWN = 0, | 40 ANDROID_CPU_FAMILY_UNKNOWN = 0, |
38 ANDROID_CPU_FAMILY_ARM, | 41 ANDROID_CPU_FAMILY_ARM, |
39 ANDROID_CPU_FAMILY_X86, | 42 ANDROID_CPU_FAMILY_X86, |
40 ANDROID_CPU_FAMILY_MIPS, | 43 ANDROID_CPU_FAMILY_MIPS, |
| 44 ANDROID_CPU_FAMILY_ARM64, |
| 45 ANDROID_CPU_FAMILY_X86_64, |
| 46 ANDROID_CPU_FAMILY_MIPS64, |
41 | 47 |
42 ANDROID_CPU_FAMILY_MAX /* do not remove */ | 48 ANDROID_CPU_FAMILY_MAX /* do not remove */ |
43 | 49 |
44 } AndroidCpuFamily; | 50 } AndroidCpuFamily; |
45 | 51 |
46 /* Return family of the device's CPU */ | 52 /* Return the CPU family of the current process. |
47 extern AndroidCpuFamily android_getCpuFamily(void); | 53 * |
| 54 * Note that this matches the bitness of the current process. I.e. when |
| 55 * running a 32-bit binary on a 64-bit capable CPU, this will return the |
| 56 * 32-bit CPU family value. |
| 57 */ |
| 58 extern AndroidCpuFamily android_getCpuFamily(void); |
48 | 59 |
49 /* The list of feature flags for ARM CPUs that can be recognized by the | 60 /* Return a bitmap describing a set of optional CPU features that are |
50 * library. Value details are: | 61 * supported by the current device's CPU. The exact bit-flags returned |
| 62 * depend on the value returned by android_getCpuFamily(). See the |
| 63 * documentation for the ANDROID_CPU_*_FEATURE_* flags below for details. |
| 64 * |
| 65 * NOTE: This will return 0 for the following architectures that don't have |
| 66 * optional features listed at the moment: |
| 67 * |
| 68 * ANDROID_CPU_FAMILY_MIPS |
| 69 * ANDROID_CPU_FAMILY_ARM64 |
| 70 * ANDROID_CPU_FAMILY_X86_64 |
| 71 * ANDROID_CPU_FAMILY_MIPS64 |
| 72 */ |
| 73 extern uint64_t android_getCpuFeatures(void); |
| 74 |
| 75 /* The list of feature flags for ANDROID_CPU_FAMILY_ARM that can be |
| 76 * recognized by the library (see note below for 64-bit ARM). Value details |
| 77 * are: |
51 * | 78 * |
52 * VFPv2: | 79 * VFPv2: |
53 * CPU supports the VFPv2 instruction set. Many, but not all, ARMv6 CPUs | 80 * CPU supports the VFPv2 instruction set. Many, but not all, ARMv6 CPUs |
54 * support these instructions. VFPv2 is a subset of VFPv3 so this will | 81 * support these instructions. VFPv2 is a subset of VFPv3 so this will |
55 * be set whenever VFPv3 is set too. | 82 * be set whenever VFPv3 is set too. |
56 * | 83 * |
57 * ARMv7: | 84 * ARMv7: |
58 * CPU supports the ARMv7-A basic instruction set. | 85 * CPU supports the ARMv7-A basic instruction set. |
59 * This feature is mandated by the 'armeabi-v7a' ABI. | 86 * This feature is mandated by the 'armeabi-v7a' ABI. |
60 * | 87 * |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 * | 123 * |
97 * IDIV_THUMB2: | 124 * IDIV_THUMB2: |
98 * Integer division available in Thumb-2 mode. Only available | 125 * Integer division available in Thumb-2 mode. Only available |
99 * on recent CPUs (e.g. Cortex-A15). | 126 * on recent CPUs (e.g. Cortex-A15). |
100 * | 127 * |
101 * iWMMXt: | 128 * iWMMXt: |
102 * Optional extension that adds MMX registers and operations to an | 129 * Optional extension that adds MMX registers and operations to an |
103 * ARM CPU. This is only available on a few XScale-based CPU designs | 130 * ARM CPU. This is only available on a few XScale-based CPU designs |
104 * sold by Marvell. Pretty rare in practice. | 131 * sold by Marvell. Pretty rare in practice. |
105 * | 132 * |
| 133 * AES: |
| 134 * CPU supports AES instructions. These instructions are only |
| 135 * available for 32-bit applications running on ARMv8 CPU. |
| 136 * |
| 137 * CRC32: |
| 138 * CPU supports CRC32 instructions. These instructions are only |
| 139 * available for 32-bit applications running on ARMv8 CPU. |
| 140 * |
| 141 * SHA2: |
| 142 * CPU supports SHA2 instructions. These instructions are only |
| 143 * available for 32-bit applications running on ARMv8 CPU. |
| 144 * |
| 145 * SHA1: |
| 146 * CPU supports SHA1 instructions. These instructions are only |
| 147 * available for 32-bit applications running on ARMv8 CPU. |
| 148 * |
| 149 * PMULL: |
| 150 * CPU supports 64-bit PMULL and PMULL2 instructions. These |
| 151 * instructions are only available for 32-bit applications |
| 152 * running on ARMv8 CPU. |
| 153 * |
106 * If you want to tell the compiler to generate code that targets one of | 154 * If you want to tell the compiler to generate code that targets one of |
107 * the feature set above, you should probably use one of the following | 155 * the feature set above, you should probably use one of the following |
108 * flags (for more details, see technical note at the end of this file): | 156 * flags (for more details, see technical note at the end of this file): |
109 * | 157 * |
110 * -mfpu=vfp | 158 * -mfpu=vfp |
111 * -mfpu=vfpv2 | 159 * -mfpu=vfpv2 |
112 * These are equivalent and tell GCC to use VFPv2 instructions for | 160 * These are equivalent and tell GCC to use VFPv2 instructions for |
113 * floating-point operations. Use this if you want your code to | 161 * floating-point operations. Use this if you want your code to |
114 * run on *some* ARMv6 devices, and any ARMv7-A device supported | 162 * run on *some* ARMv6 devices, and any ARMv7-A device supported |
115 * by Android. | 163 * by Android. |
(...skipping 27 matching lines...) Expand all Loading... |
143 * features. | 191 * features. |
144 * | 192 * |
145 * -mcpu=cortex-a7 | 193 * -mcpu=cortex-a7 |
146 * -mcpu=cortex-a15 | 194 * -mcpu=cortex-a15 |
147 * Generated code requires VFPv3|VFP_FP16|VFP_FMA|VFP_D32| | 195 * Generated code requires VFPv3|VFP_FP16|VFP_FMA|VFP_D32| |
148 * NEON|NEON_FMA|IDIV_ARM|IDIV_THUMB2 | 196 * NEON|NEON_FMA|IDIV_ARM|IDIV_THUMB2 |
149 * This flag implies -mfpu=neon-vfpv4. | 197 * This flag implies -mfpu=neon-vfpv4. |
150 * | 198 * |
151 * -mcpu=iwmmxt | 199 * -mcpu=iwmmxt |
152 * Allows the use of iWMMXt instrinsics with GCC. | 200 * Allows the use of iWMMXt instrinsics with GCC. |
| 201 * |
| 202 * IMPORTANT NOTE: These flags should only be tested when |
| 203 * android_getCpuFamily() returns ANDROID_CPU_FAMILY_ARM, i.e. this is a |
| 204 * 32-bit process. |
| 205 * |
| 206 * When running a 64-bit ARM process on an ARMv8 CPU, |
| 207 * android_getCpuFeatures() will return a different set of bitflags |
153 */ | 208 */ |
154 enum { | 209 enum { |
155 ANDROID_CPU_ARM_FEATURE_ARMv7 = (1 << 0), | 210 ANDROID_CPU_ARM_FEATURE_ARMv7 = (1 << 0), |
156 ANDROID_CPU_ARM_FEATURE_VFPv3 = (1 << 1), | 211 ANDROID_CPU_ARM_FEATURE_VFPv3 = (1 << 1), |
157 ANDROID_CPU_ARM_FEATURE_NEON = (1 << 2), | 212 ANDROID_CPU_ARM_FEATURE_NEON = (1 << 2), |
158 ANDROID_CPU_ARM_FEATURE_LDREX_STREX = (1 << 3), | 213 ANDROID_CPU_ARM_FEATURE_LDREX_STREX = (1 << 3), |
159 ANDROID_CPU_ARM_FEATURE_VFPv2 = (1 << 4), | 214 ANDROID_CPU_ARM_FEATURE_VFPv2 = (1 << 4), |
160 ANDROID_CPU_ARM_FEATURE_VFP_D32 = (1 << 5), | 215 ANDROID_CPU_ARM_FEATURE_VFP_D32 = (1 << 5), |
161 ANDROID_CPU_ARM_FEATURE_VFP_FP16 = (1 << 6), | 216 ANDROID_CPU_ARM_FEATURE_VFP_FP16 = (1 << 6), |
162 ANDROID_CPU_ARM_FEATURE_VFP_FMA = (1 << 7), | 217 ANDROID_CPU_ARM_FEATURE_VFP_FMA = (1 << 7), |
163 ANDROID_CPU_ARM_FEATURE_NEON_FMA = (1 << 8), | 218 ANDROID_CPU_ARM_FEATURE_NEON_FMA = (1 << 8), |
164 ANDROID_CPU_ARM_FEATURE_IDIV_ARM = (1 << 9), | 219 ANDROID_CPU_ARM_FEATURE_IDIV_ARM = (1 << 9), |
165 ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2 = (1 << 10), | 220 ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2 = (1 << 10), |
166 ANDROID_CPU_ARM_FEATURE_iWMMXt = (1 << 11), | 221 ANDROID_CPU_ARM_FEATURE_iWMMXt = (1 << 11), |
| 222 ANDROID_CPU_ARM_FEATURE_AES = (1 << 12), |
| 223 ANDROID_CPU_ARM_FEATURE_PMULL = (1 << 13), |
| 224 ANDROID_CPU_ARM_FEATURE_SHA1 = (1 << 14), |
| 225 ANDROID_CPU_ARM_FEATURE_SHA2 = (1 << 15), |
| 226 ANDROID_CPU_ARM_FEATURE_CRC32 = (1 << 16), |
167 }; | 227 }; |
168 | 228 |
| 229 /* The bit flags corresponding to the output of android_getCpuFeatures() |
| 230 * when android_getCpuFamily() returns ANDROID_CPU_FAMILY_ARM64. Value details |
| 231 * are: |
| 232 * |
| 233 * FP: |
| 234 * CPU has Floating-point unit. |
| 235 * |
| 236 * ASIMD: |
| 237 * CPU has Advanced SIMD unit. |
| 238 * |
| 239 * AES: |
| 240 * CPU supports AES instructions. |
| 241 * |
| 242 * CRC32: |
| 243 * CPU supports CRC32 instructions. |
| 244 * |
| 245 * SHA2: |
| 246 * CPU supports SHA2 instructions. |
| 247 * |
| 248 * SHA1: |
| 249 * CPU supports SHA1 instructions. |
| 250 * |
| 251 * PMULL: |
| 252 * CPU supports 64-bit PMULL and PMULL2 instructions. |
| 253 */ |
| 254 enum { |
| 255 ANDROID_CPU_ARM64_FEATURE_FP = (1 << 0), |
| 256 ANDROID_CPU_ARM64_FEATURE_ASIMD = (1 << 1), |
| 257 ANDROID_CPU_ARM64_FEATURE_AES = (1 << 2), |
| 258 ANDROID_CPU_ARM64_FEATURE_PMULL = (1 << 3), |
| 259 ANDROID_CPU_ARM64_FEATURE_SHA1 = (1 << 4), |
| 260 ANDROID_CPU_ARM64_FEATURE_SHA2 = (1 << 5), |
| 261 ANDROID_CPU_ARM64_FEATURE_CRC32 = (1 << 6), |
| 262 }; |
| 263 /* The bit flags corresponding to the output of android_getCpuFeatures() |
| 264 * when android_getCpuFamily() returns ANDROID_CPU_FAMILY_X86. |
| 265 */ |
169 enum { | 266 enum { |
170 ANDROID_CPU_X86_FEATURE_SSSE3 = (1 << 0), | 267 ANDROID_CPU_X86_FEATURE_SSSE3 = (1 << 0), |
171 ANDROID_CPU_X86_FEATURE_POPCNT = (1 << 1), | 268 ANDROID_CPU_X86_FEATURE_POPCNT = (1 << 1), |
172 ANDROID_CPU_X86_FEATURE_MOVBE = (1 << 2), | 269 ANDROID_CPU_X86_FEATURE_MOVBE = (1 << 2), |
173 }; | 270 }; |
174 | 271 |
175 extern uint64_t android_getCpuFeatures(void); | |
176 | |
177 /* Return the number of CPU cores detected on this device. */ | 272 /* Return the number of CPU cores detected on this device. */ |
178 extern int android_getCpuCount(void); | 273 extern int android_getCpuCount(void); |
179 | 274 |
180 /* The following is used to force the CPU count and features | 275 /* The following is used to force the CPU count and features |
181 * mask in sandboxed processes. Under 4.1 and higher, these processes | 276 * mask in sandboxed processes. Under 4.1 and higher, these processes |
182 * cannot access /proc, which is the only way to get information from | 277 * cannot access /proc, which is the only way to get information from |
183 * the kernel about the current hardware (at least on ARM). | 278 * the kernel about the current hardware (at least on ARM). |
184 * | 279 * |
185 * It _must_ be called only once, and before any android_getCpuXXX | 280 * It _must_ be called only once, and before any android_getCpuXXX |
186 * function, any other case will fail. | 281 * function, any other case will fail. |
187 * | 282 * |
188 * This function return 1 on success, and 0 on failure. | 283 * This function return 1 on success, and 0 on failure. |
189 */ | 284 */ |
190 extern int android_setCpu(int cpu_count, | 285 extern int android_setCpu(int cpu_count, |
191 uint64_t cpu_features); | 286 uint64_t cpu_features); |
192 | 287 |
| 288 #ifdef __arm__ |
| 289 /* Retrieve the ARM 32-bit CPUID value from the kernel. |
| 290 * Note that this cannot work on sandboxed processes under 4.1 and |
| 291 * higher, unless you called android_setCpuArm() before. |
| 292 */ |
| 293 extern uint32_t android_getCpuIdArm(void); |
| 294 |
| 295 /* An ARM-specific variant of android_setCpu() that also allows you |
| 296 * to set the ARM CPUID field. |
| 297 */ |
| 298 extern int android_setCpuArm(int cpu_count, |
| 299 uint64_t cpu_features, |
| 300 uint32_t cpu_id); |
| 301 #endif |
| 302 |
193 __END_DECLS | 303 __END_DECLS |
194 | 304 |
195 #endif /* CPU_FEATURES_H */ | 305 #endif /* CPU_FEATURES_H */ |
OLD | NEW |