10
10
#include <stdint.h> // UINT32_C()
11
11
12
12
/* Macro to mark a CPUID register function parameter as being used. */
13
- #define CPUID_REG (PARAM ) PARAM
13
+ #define CPUID_REG (PARAM ) PARAM
14
14
/* Macro to check one or more CPUID register bits. */
15
15
#define CPUID_CHECK_REG (REG , MASK ) ((((REG) & (MASK)) == (MASK)) ? 0 : 1)
16
16
17
- /*
18
- * For simplicity, we only enable SIMD instructions for Intel CPUs,
19
- * even though we could support ARM NEON and POWER.
20
- */
17
+ // For simplicity, we only enable SIMD instructions for Intel CPUs,
18
+ // even though we could support ARM NEON and POWER.
21
19
#if defined(__x86_64__ ) && defined(__GNUC__ )
22
20
# include <cpuid.h> // __cpuid_count()
23
21
#elif defined(_M_X64 )
33
31
|| defined(CAN_COMPILE_SIMD_SSSE3_INSTRUCTIONS ) \
34
32
|| defined(CAN_COMPILE_SIMD_SSE4_1_INSTRUCTIONS ) \
35
33
|| defined(CAN_COMPILE_SIMD_SSE4_2_INSTRUCTIONS ) \
36
- // macros above should be sorted in an alphabetical order
34
+ // macros above should be sorted in alphabetical order
37
35
/* Used to guard any SSE instructions detection code. */
38
36
# define SIMD_SSE_INSTRUCTIONS_DETECTION_GUARD
39
37
#endif
44
42
|| defined(CAN_COMPILE_SIMD_AVX_VNNI_INSTRUCTIONS ) \
45
43
|| defined(CAN_COMPILE_SIMD_AVX_VNNI_INT8_INSTRUCTIONS ) \
46
44
|| defined(CAN_COMPILE_SIMD_AVX_VNNI_INT16_INSTRUCTIONS ) \
47
- // macros above should be sorted in an alphabetical order
45
+ // macros above should be sorted in alphabetical order
48
46
/* Used to guard any AVX instructions detection code. */
49
47
# define SIMD_AVX_INSTRUCTIONS_DETECTION_GUARD
50
48
#endif
51
49
52
50
#if defined(CAN_COMPILE_SIMD_AVX2_INSTRUCTIONS ) \
53
- // macros above should be sorted in an alphabetical order
51
+ // macros above should be sorted in alphabetical order
54
52
/* Used to guard any AVX-2 instructions detection code. */
55
53
# define SIMD_AVX2_INSTRUCTIONS_DETECTION_GUARD
56
54
#endif
71
69
|| defined(CAN_COMPILE_SIMD_AVX512_VPOPCNTDQ_INSTRUCTIONS ) \
72
70
|| defined(CAN_COMPILE_SIMD_AVX512_4FMAPS_INSTRUCTIONS ) \
73
71
|| defined(CAN_COMPILE_SIMD_AVX512_4VNNIW_INSTRUCTIONS ) \
74
- // macros above should be sorted in an alphabetical order
72
+ // macros above should be sorted in alphabetical order
75
73
/* Used to guard any AVX-512 instructions detection code. */
76
74
# define SIMD_AVX512_INSTRUCTIONS_DETECTION_GUARD
77
75
#endif
84
82
//
85
83
// Additionally, AVX2 cannot be compiled on macOS ARM64 (yet it can be
86
84
// compiled on x86_64). However, since autoconf incorrectly assumes so
87
- // when compiling a universal2 binary, we disable AVX for such builds.
85
+ // when compiling a universal2 binary, we disable AVX on such builds.
88
86
#if defined(__APPLE__ )
89
87
# undef SIMD_AVX512_INSTRUCTIONS_DETECTION_GUARD
90
88
# if defined(__arm64__ )
@@ -181,7 +179,7 @@ get_cpuid_info(uint32_t level /* input eax */,
181
179
#if defined(__x86_64__ ) && defined(__GNUC__ )
182
180
__cpuid_count (level , count , * eax , * ebx , * ecx , * edx );
183
181
#elif defined(_M_X64 )
184
- int32_t info [4 ] = {0 };
182
+ uint32_t info [4 ] = {0 };
185
183
__cpuidex (info , level , count );
186
184
* eax = info [0 ];
187
185
* ebx = info [1 ];
@@ -247,13 +245,13 @@ detect_simd_features(py_simd_features *flags,
247
245
#ifdef CAN_COMPILE_SIMD_SSE4_2_INSTRUCTIONS
248
246
flags -> sse42 = CPUID_CHECK_REG (ecx , ECX_L1_SSE4_2 );
249
247
#endif
250
- #endif
248
+ #endif // !SIMD_SSE_INSTRUCTIONS_DETECTION_GUARD
251
249
252
250
#ifdef SIMD_AVX_INSTRUCTIONS_DETECTION_GUARD
253
251
#ifdef CAN_COMPILE_SIMD_AVX_INSTRUCTIONS
254
252
flags -> avx = CPUID_CHECK_REG (ecx , ECX_L1_AVX );
255
253
#endif
256
- #endif
254
+ #endif // !SIMD_AVX_INSTRUCTIONS_DETECTION_GUARD
257
255
258
256
flags -> os_xsave = CPUID_CHECK_REG (ecx , ECX_L1_OSXSAVE );
259
257
}
@@ -329,7 +327,7 @@ detect_simd_extended_features_ecx_0(py_simd_features *flags,
329
327
#ifdef CAN_COMPILE_SIMD_AVX512_VP2INTERSECT_INSTRUCTIONS
330
328
flags -> avx512_vp2intersect = CPUID_CHECK_REG (edx , EDX_L7_AVX512_VP2INTERSECT );
331
329
#endif
332
- #endif
330
+ #endif // !SIMD_AVX512_INSTRUCTIONS_DETECTION_GUARD
333
331
}
334
332
335
333
/* Extended Feature Bits (LEAF=7, SUBLEAF=1). */
@@ -357,7 +355,7 @@ detect_simd_extended_features_ecx_1(py_simd_features *flags,
357
355
#ifdef CAN_COMPILE_SIMD_AVX_VNNI_INT16_INSTRUCTIONS
358
356
flags -> avx_vnni_int16 = CPUID_CHECK_REG (edx , EDX_L7S1_AVX_VNNI_INT16 );
359
357
#endif
360
- #endif
358
+ #endif // !SIMD_AVX_INSTRUCTIONS_DETECTION_GUARD
361
359
}
362
360
363
361
static inline void
@@ -552,7 +550,7 @@ _Py_detect_simd_features(py_simd_features *flags)
552
550
#else
553
551
(void ) maxleaf ;
554
552
(void ) eax ; (void ) ebx ; (void ) ecx ; (void ) edx ;
555
- #endif
553
+ #endif // !SHOULD_DETECT_SIMD_FEATURES_L1
556
554
#ifdef SHOULD_DETECT_SIMD_FEATURES_L7
557
555
if (maxleaf >= 7 ) {
558
556
#ifdef SHOULD_DETECT_SIMD_FEATURES_L7S0
@@ -569,7 +567,7 @@ _Py_detect_simd_features(py_simd_features *flags)
569
567
#else
570
568
(void ) maxleaf ;
571
569
(void ) eax ; (void ) ebx ; (void ) ecx ; (void ) edx ;
572
- #endif
570
+ #endif // !SHOULD_DETECT_SIMD_FEATURES_L7
573
571
finalize_simd_features (flags );
574
572
if (validate_simd_features (flags ) < 0 ) {
575
573
_Py_disable_simd_features (flags );
0 commit comments