xref: /aosp_15_r20/external/libyuv/util/cpuid.c (revision 4e366538070a3a6c5c163c31b791eab742e1657a)
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_riscv = TestCpuFlag(kCpuHasRISCV);
25   int has_x86 = TestCpuFlag(kCpuHasX86);
26   int has_mips = TestCpuFlag(kCpuHasMIPS);
27   int has_loongarch = TestCpuFlag(kCpuHasLOONGARCH);
28   (void)argc;
29   (void)argv;
30 
31 #if defined(__i386__) || defined(__x86_64__) || \
32     defined(_M_IX86) || defined(_M_X64)
33   if (has_x86) {
34     int family, model, cpu_info[4];
35     // Vendor ID:
36     // AuthenticAMD AMD processor
37     // CentaurHauls Centaur processor
38     // CyrixInstead Cyrix processor
39     // GenuineIntel Intel processor
40     // GenuineTMx86 Transmeta processor
41     // Geode by NSC National Semiconductor processor
42     // NexGenDriven NexGen processor
43     // RiseRiseRise Rise Technology processor
44     // SiS SiS SiS  SiS processor
45     // UMC UMC UMC  UMC processor
46     CpuId(0, 0, &cpu_info[0]);
47     cpu_info[0] = cpu_info[1];  // Reorder output
48     cpu_info[1] = cpu_info[3];
49     cpu_info[3] = 0;
50     printf("Cpu Vendor: %s\n", (char*)(&cpu_info[0]));
51 
52     // CPU Family and Model
53     // 3:0 - Stepping
54     // 7:4 - Model
55     // 11:8 - Family
56     // 13:12 - Processor Type
57     // 19:16 - Extended Model
58     // 27:20 - Extended Family
59     CpuId(1, 0, &cpu_info[0]);
60     family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0);
61     model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0);
62     printf("Cpu Family %d (0x%x), Model %d (0x%x)\n", family, family,
63            model, model);
64   }
65 #endif
66   printf("Cpu Flags 0x%x\n", cpu_flags);
67   if (has_arm) {
68     int has_neon = TestCpuFlag(kCpuHasNEON);
69     printf("Has ARM 0x%x\n", has_arm);
70     printf("Has NEON 0x%x\n", has_neon);
71   }
72   if (has_riscv) {
73     int has_rvv = TestCpuFlag(kCpuHasRVV);
74     printf("Has RISCV 0x%x\n", has_riscv);
75     printf("Has RVV 0x%x\n", has_rvv);
76   }
77   if (has_mips) {
78     int has_msa = TestCpuFlag(kCpuHasMSA);
79     printf("Has MIPS 0x%x\n", has_mips);
80     printf("Has MSA 0x%x\n", has_msa);
81   }
82   if (has_loongarch) {
83     int has_lsx  = TestCpuFlag(kCpuHasLSX);
84     int has_lasx = TestCpuFlag(kCpuHasLASX);
85     printf("Has LOONGARCH 0x%x\n", has_loongarch);
86     printf("Has LSX 0x%x\n", has_lsx);
87     printf("Has LASX 0x%x\n", has_lasx);
88   }
89   if (has_x86) {
90     int has_sse2 = TestCpuFlag(kCpuHasSSE2);
91     int has_ssse3 = TestCpuFlag(kCpuHasSSSE3);
92     int has_sse41 = TestCpuFlag(kCpuHasSSE41);
93     int has_sse42 = TestCpuFlag(kCpuHasSSE42);
94     int has_avx = TestCpuFlag(kCpuHasAVX);
95     int has_avx2 = TestCpuFlag(kCpuHasAVX2);
96     int has_erms = TestCpuFlag(kCpuHasERMS);
97     int has_fma3 = TestCpuFlag(kCpuHasFMA3);
98     int has_f16c = TestCpuFlag(kCpuHasF16C);
99     int has_avx512bw = TestCpuFlag(kCpuHasAVX512BW);
100     int has_avx512vl = TestCpuFlag(kCpuHasAVX512VL);
101     int has_avx512vnni = TestCpuFlag(kCpuHasAVX512VNNI);
102     int has_avx512vbmi = TestCpuFlag(kCpuHasAVX512VBMI);
103     int has_avx512vbmi2 = TestCpuFlag(kCpuHasAVX512VBMI2);
104     int has_avx512vbitalg = TestCpuFlag(kCpuHasAVX512VBITALG);
105     int has_avx10 = TestCpuFlag(kCpuHasAVX10);
106     int has_avxvnni = TestCpuFlag(kCpuHasAVXVNNI);
107     int has_avxvnniint8 = TestCpuFlag(kCpuHasAVXVNNIINT8);
108     printf("Has X86 0x%x\n", has_x86);
109     printf("Has SSE2 0x%x\n", has_sse2);
110     printf("Has SSSE3 0x%x\n", has_ssse3);
111     printf("Has SSE4.1 0x%x\n", has_sse41);
112     printf("Has SSE4.2 0x%x\n", has_sse42);
113     printf("Has AVX 0x%x\n", has_avx);
114     printf("Has AVX2 0x%x\n", has_avx2);
115     printf("Has ERMS 0x%x\n", has_erms);
116     printf("Has FMA3 0x%x\n", has_fma3);
117     printf("Has F16C 0x%x\n", has_f16c);
118     printf("Has AVX512BW 0x%x\n", has_avx512bw);
119     printf("Has AVX512VL 0x%x\n", has_avx512vl);
120     printf("Has AVX512VNNI 0x%x\n", has_avx512vnni);
121     printf("Has AVX512VBMI 0x%x\n", has_avx512vbmi);
122     printf("Has AVX512VBMI2 0x%x\n", has_avx512vbmi2);
123     printf("Has AVX512VBITALG 0x%x\n", has_avx512vbitalg);
124     printf("Has AVX10 0x%x\n", has_avx10);
125     printf("HAS AVXVNNI 0x%x\n", has_avxvnni);
126     printf("Has AVXVNNIINT8 0x%x\n", has_avxvnniint8);
127   }
128   return 0;
129 }
130 
131