1 /*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #define __STDC_FORMAT_MACROS 1
17
18 #include <cpu-features.h>
19 #include <inttypes.h>
20 #include <stdio.h>
21
main(void)22 int main(void)
23 {
24 AndroidCpuFamily family = android_getCpuFamily();
25 switch (family) {
26 case ANDROID_CPU_FAMILY_ARM:
27 printf("CPU family is ARM\n");
28 break;
29 case ANDROID_CPU_FAMILY_X86:
30 printf("CPU family is x86\n");
31 break;
32 case ANDROID_CPU_FAMILY_MIPS:
33 printf("CPU family is MIPS\n");
34 break;
35 case ANDROID_CPU_FAMILY_ARM64:
36 printf("CPU family is ARM64\n");
37 break;
38 case ANDROID_CPU_FAMILY_X86_64:
39 printf("CPU family is x86_64\n");
40 break;
41 case ANDROID_CPU_FAMILY_MIPS64:
42 printf("CPU family is MIPS64\n");
43 break;
44 default:
45 fprintf(stderr, "Unsupported CPU family: %d\n", family);
46 return 1;
47 }
48
49 if (family == ANDROID_CPU_FAMILY_ARM) {
50 uint64_t features = android_getCpuFeatures();
51 printf( "Supported ARM features:\n");
52 #define CHECK(name) \
53 if ((features & ANDROID_CPU_ARM_FEATURE_## name) != 0) { \
54 printf( " "#name"\n" ); \
55 }
56 CHECK(LDREX_STREX)
57 CHECK(VFPv2)
58 CHECK(ARMv7)
59 CHECK(VFPv3)
60 CHECK(VFP_D32)
61 CHECK(VFP_FP16)
62 CHECK(VFP_FMA)
63 CHECK(NEON)
64 CHECK(NEON_FMA)
65 CHECK(IDIV_ARM)
66 CHECK(IDIV_THUMB2)
67 CHECK(iWMMXt)
68 #undef CHECK
69 }
70
71 #ifdef __arm__
72 uint32_t cpu_id = android_getCpuIdArm();
73 printf( "ARM CpuID: %08x\n", cpu_id);
74 printf( " implementer: %02x\n", (cpu_id >> 24) & 0xff);
75 printf( " variant : %02x\n", (cpu_id >> 20) & 0x0f);
76 printf( " part : %03x\n", (cpu_id >> 4) & 0xfff);
77 printf( " revision : %x\n", cpu_id & 0x0f);
78 #endif
79
80 if (family == ANDROID_CPU_FAMILY_X86) {
81 uint64_t features = android_getCpuFeatures();
82 printf( "Supported x86 features:\n");
83 #define CHECK(name) \
84 if ((features & ANDROID_CPU_X86_FEATURE_## name) != 0) { \
85 printf( " "#name"\n" ); \
86 }
87 CHECK(SSSE3)
88 CHECK(POPCNT)
89 CHECK(MOVBE)
90 #undef CHECK
91 }
92
93 int result = 0;
94
95 // Check that the CPU features mask is empty for anything that isn't
96 // 32-bit ARM or 32-bit x86.
97 if (family != ANDROID_CPU_FAMILY_ARM &&
98 family != ANDROID_CPU_FAMILY_X86) {
99 uint64_t features = android_getCpuFeatures();
100 if (features != 0) {
101 printf("ERROR: Unexpected CPU features mask: %016" PRIX64 "\n",
102 features);
103 result = 1;
104 }
105 }
106
107 int count = android_getCpuCount();
108 printf( "Number of CPU cores: %d\n", count);
109 return result;
110 }
111