]> git.ozlabs.org Git - ccan/blob - ccan/cpuid/test/run.c
cpuid: new module
[ccan] / ccan / cpuid / test / run.c
1 #include "cpuid.h"
2
3 #include <stdio.h>
4
5 int main()
6 {
7         if (!cpuid_is_supported()) {
8                 printf ("CPUID instruction is not supported by this CPU\n");
9                 return 1;
10         }
11
12         printf ("MMX:  %s\n", cpuid_has_mmx()  ? "Yes" : "No");
13         printf ("SSE:  %s\n", cpuid_has_sse()  ? "Yes" : "No");
14         printf ("SSE2: %s\n", cpuid_has_sse2() ? "Yes" : "No");
15         printf ("SSE3: %s\n", cpuid_has_sse3() ? "Yes" : "No");
16         printf ("x64:  %s\n", cpuid_has_x64()  ? "Yes" : "No");
17
18         char buf[128];
19         cpuid(CPU_VENDORID, buf);
20         printf ("Vendor ID: %s\n", buf);
21
22         cpuid(CPU_PROC_BRAND_STRING, buf);
23         printf ("Processor Brand: %s\n", buf);
24
25         int addr;
26         cpuid(CPU_HIGHEST_EXTENDED_FUNCTION_SUPPORTED, &addr);
27         printf ("Highest extended function supported: %#010x\n", addr);
28
29         int virtphys_size;
30         cpuid(CPU_VIRT_PHYS_ADDR_SIZES, &virtphys_size);
31         printf ("Virtual and physical address sizes: %d\n", virtphys_size);
32
33         int extfeatures[2];
34         cpuid(CPU_EXTENDED_PROC_INFO_FEATURE_BITS, extfeatures);
35         printf ("Extended processor info and feature bits: %d %d\n", extfeatures[0], extfeatures[1]);
36
37         int l2features[3];
38         cpuid(CPU_EXTENDED_L2_CACHE_FEATURES, l2features);
39         printf ("L2 Cache Size: %u KB\tLine Size: %u bytes\tAssociativity: %02xh\n",
40                         l2features[0], l2features[1], l2features[2]);
41
42         int invalid;
43         cpuid(0x0ffffffUL, &invalid);
44         printf ("Testing invalid: %#010x\n", invalid);
45         return 0;
46 }
47