1 /*
2  *  Copyright 2012 The LibYuv Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS. All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 
15 #include "libyuv/cpu_id.h"
16 
17 #ifdef __cplusplus
18 using namespace libyuv;
19 #endif
20 
main(int argc,const char * argv[])21 int main(int argc, const char* argv[]) {
22   int cpu_flags = TestCpuFlag(-1);
23   int has_arm = TestCpuFlag(kCpuHasARM);
24   int has_mips = TestCpuFlag(kCpuHasMIPS);
25   int has_x86 = TestCpuFlag(kCpuHasX86);
26   (void)argc;
27   (void)argv;
28 
29 #if defined(__i386__) || defined(__x86_64__) || \
30     defined(_M_IX86) || defined(_M_X64)
31   if (has_x86) {
32     int family, model, cpu_info[4];
33     // Vendor ID:
34     // AuthenticAMD AMD processor
35     // CentaurHauls Centaur processor
36     // CyrixInstead Cyrix processor
37     // GenuineIntel Intel processor
38     // GenuineTMx86 Transmeta processor
39     // Geode by NSC National Semiconductor processor
40     // NexGenDriven NexGen processor
41     // RiseRiseRise Rise Technology processor
42     // SiS SiS SiS  SiS processor
43     // UMC UMC UMC  UMC processor
44     CpuId(0, 0, &cpu_info[0]);
45     cpu_info[0] = cpu_info[1];  // Reorder output
46     cpu_info[1] = cpu_info[3];
47     cpu_info[3] = 0;
48     printf("Cpu Vendor: %s\n", (char*)(&cpu_info[0]));
49 
50     // CPU Family and Model
51     // 3:0 - Stepping
52     // 7:4 - Model
53     // 11:8 - Family
54     // 13:12 - Processor Type
55     // 19:16 - Extended Model
56     // 27:20 - Extended Family
57     CpuId(1, 0, &cpu_info[0]);
58     family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0);
59     model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0);
60     printf("Cpu Family %d (0x%x), Model %d (0x%x)\n", family, family,
61            model, model);
62   }
63 #endif
64   printf("Cpu Flags %x\n", cpu_flags);
65   printf("Has ARM %x\n", has_arm);
66   printf("Has MIPS %x\n", has_mips);
67   printf("Has X86 %x\n", has_x86);
68   if (has_arm) {
69     int has_neon = TestCpuFlag(kCpuHasNEON);
70     printf("Has NEON %x\n", has_neon);
71   }
72   if (has_mips) {
73     int has_msa = TestCpuFlag(kCpuHasMSA);
74     printf("Has MSA %x\n", has_msa);
75     int has_mmi = TestCpuFlag(kCpuHasMMI);
76     printf("Has MMI %x\n", has_mmi);
77   }
78   if (has_x86) {
79     int has_sse2 = TestCpuFlag(kCpuHasSSE2);
80     int has_ssse3 = TestCpuFlag(kCpuHasSSSE3);
81     int has_sse41 = TestCpuFlag(kCpuHasSSE41);
82     int has_sse42 = TestCpuFlag(kCpuHasSSE42);
83     int has_avx = TestCpuFlag(kCpuHasAVX);
84     int has_avx2 = TestCpuFlag(kCpuHasAVX2);
85     int has_erms = TestCpuFlag(kCpuHasERMS);
86     int has_fma3 = TestCpuFlag(kCpuHasFMA3);
87     int has_f16c = TestCpuFlag(kCpuHasF16C);
88     int has_gfni = TestCpuFlag(kCpuHasGFNI);
89     int has_avx512bw = TestCpuFlag(kCpuHasAVX512BW);
90     int has_avx512vl = TestCpuFlag(kCpuHasAVX512VL);
91     int has_avx512vbmi = TestCpuFlag(kCpuHasAVX512VBMI);
92     int has_avx512vbmi2 = TestCpuFlag(kCpuHasAVX512VBMI2);
93     int has_avx512vbitalg = TestCpuFlag(kCpuHasAVX512VBITALG);
94     int has_avx512vpopcntdq = TestCpuFlag(kCpuHasAVX512VPOPCNTDQ);
95     printf("Has SSE2 %x\n", has_sse2);
96     printf("Has SSSE3 %x\n", has_ssse3);
97     printf("Has SSE4.1 %x\n", has_sse41);
98     printf("Has SSE4.2 %x\n", has_sse42);
99     printf("Has AVX %x\n", has_avx);
100     printf("Has AVX2 %x\n", has_avx2);
101     printf("Has ERMS %x\n", has_erms);
102     printf("Has FMA3 %x\n", has_fma3);
103     printf("Has F16C %x\n", has_f16c);
104     printf("Has GFNI %x\n", has_gfni);
105     printf("Has AVX512BW %x\n", has_avx512bw);
106     printf("Has AVX512VL %x\n", has_avx512vl);
107     printf("Has AVX512VBMI %x\n", has_avx512vbmi);
108     printf("Has AVX512VBMI2 %x\n", has_avx512vbmi2);
109     printf("Has AVX512VBITALG %x\n", has_avx512vbitalg);
110     printf("Has AVX512VPOPCNTDQ %x\n", has_avx512vpopcntdq);
111   }
112   return 0;
113 }
114 
115