Add support for runtime x86 CPU feature detection
[wimlib] / include / wimlib / x86_cpu_features.h
1 #ifndef _WIMLIB_X86_CPU_FEATURES_H
2 #define _WIMLIB_X86_CPU_FEATURES_H
3
4 #include "wimlib/types.h"
5
6 #if defined(__i386__) || defined(__x86_64__)
7
8 #define X86_CPU_FEATURE_SSE             0x00000001
9 #define X86_CPU_FEATURE_SSE2            0x00000002
10 #define X86_CPU_FEATURE_SSE3            0x00000004
11 #define X86_CPU_FEATURE_SSSE3           0x00000008
12 #define X86_CPU_FEATURE_SSE4_1          0x00000010
13 #define X86_CPU_FEATURE_SSE4_2          0x00000020
14 #define X86_CPU_FEATURE_AVX             0x00000040
15 #define X86_CPU_FEATURE_BMI             0x00000080
16 #define X86_CPU_FEATURE_AVX2            0x00000100
17 #define X86_CPU_FEATURE_BMI2            0x00000200
18
19 #define X86_CPU_FEATURES_KNOWN          0x80000000
20
21 extern u32 _x86_cpu_features;
22
23 extern void
24 x86_setup_cpu_features(void);
25
26 /* Does the processor has the specified feature?  */
27 static inline bool
28 x86_have_cpu_feature(u32 feature)
29 {
30         if (!(_x86_cpu_features & X86_CPU_FEATURES_KNOWN))
31                 x86_setup_cpu_features();
32         return _x86_cpu_features & feature;
33 }
34
35 #else
36
37 static inline bool
38 x86_have_cpu_feature(u32 feature)
39 {
40         return false;
41 }
42
43 #endif /* __i386__ || __x86_64__ */
44
45 #endif /* _WIMLIB_X86_CPU_FEATURES_H */