Skip to content

Commit d213b67

Browse files
committed
update C comments
1 parent bd3589f commit d213b67

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Include/internal/pycore_cpuinfo.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ extern "C" {
2929

3030
typedef struct py_cpuid_features {
3131
uint32_t maxleaf;
32-
/* Macro to declare a member flag of 'py_cpuid_features' as a uint8_t. */
32+
/*
33+
* Macro to declare a member flag of 'py_cpuid_features' as a uint8_t.
34+
* Whenever this macro is used, do not forget to update the number of
35+
* fields and the bitsize of the 'ready' member (see structure end).
36+
*/
3337
#define _Py_CPUID_DECL_FLAG(MEMBER_NAME) uint8_t MEMBER_NAME:1
3438
// --- Streaming SIMD Extensions ------------------------------------------
3539
_Py_CPUID_DECL_FLAG(sse);
@@ -94,8 +98,8 @@ typedef struct py_cpuid_features {
9498
_Py_CPUID_DECL_FLAG(popcnt);
9599
_Py_CPUID_DECL_FLAG(pclmulqdq);
96100

97-
_Py_CPUID_DECL_FLAG(xsave); // XSAVE/XRSTOR/XSETBV/XGETBV
98-
_Py_CPUID_DECL_FLAG(osxsave); // XSAVE is enabled by the OS
101+
_Py_CPUID_DECL_FLAG(xsave); // XSAVE/XRSTOR/XSETBV/XGETBV
102+
_Py_CPUID_DECL_FLAG(osxsave); // XSAVE is enabled by the OS
99103

100104
// --- XCR0 register bits -------------------------------------------------
101105
_Py_CPUID_DECL_FLAG(xcr0_sse);

Python/cpuinfo.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ detect_cpuid_maxleaf(void)
162162
static inline void
163163
detect_cpuid_features(py_cpuid_features *flags, CPUID_REG ecx, CPUID_REG edx)
164164
{
165+
assert(flags->maxleaf >= 1);
165166
// Keep the ordering and newlines as they are declared in the structure.
166167
#ifdef SIMD_SSE_INSTRUCTIONS_DETECTION_GUARD
167168
#ifdef Py_CAN_COMPILE_SIMD_SSE_INSTRUCTIONS
@@ -206,6 +207,7 @@ static inline void
206207
detect_cpuid_extended_features_L7S0(py_cpuid_features *flags,
207208
CPUID_REG ebx, CPUID_REG ecx, CPUID_REG edx)
208209
{
210+
assert(flags->maxleaf >= 7);
209211
(void)ebx, (void)ecx, (void)edx; // to suppress unused warnings
210212
// Keep the ordering and newlines as they are declared in the structure.
211213
#ifdef SIMD_AVX2_INSTRUCTIONS_DETECTION_GUARD
@@ -282,6 +284,7 @@ detect_cpuid_extended_features_L7S1(py_cpuid_features *flags,
282284
CPUID_REG ecx,
283285
CPUID_REG edx)
284286
{
287+
assert(flags->maxleaf >= 7);
285288
(void)eax, (void)ebx, (void)ecx, (void)edx; // to suppress unused warnings
286289
// Keep the ordering and newlines as they are declared in the structure.
287290
#ifdef SIMD_AVX_INSTRUCTIONS_DETECTION_GUARD
@@ -309,6 +312,7 @@ static inline void
309312
detect_cpuid_xsave_state(py_cpuid_features *flags)
310313
{
311314
// Keep the ordering and newlines as they are declared in the structure.
315+
assert(flags->maxleaf >= 1);
312316
#ifdef HAS_XGETBV_SUPPORT
313317
uint64_t xcr0 = flags->osxsave ? get_xgetbv(0) : 0;
314318
flags->xcr0_sse = XSAVE_CHECK_REG(xcr0, XCR0_SSE);
@@ -501,6 +505,7 @@ cpuid_detect_l1_features(py_cpuid_features *flags)
501505
static inline void
502506
cpuid_detect_l7s0_features(py_cpuid_features *flags)
503507
{
508+
assert(flags->maxleaf >= 7);
504509
CPUID_REG eax = 0, ebx = 0, ecx = 0, edx = 0;
505510
get_cpuid_info(7, 0, &eax, &ebx, &ecx, &edx);
506511
detect_cpuid_extended_features_L7S0(flags, ebx, ecx, edx);
@@ -513,6 +518,7 @@ cpuid_detect_l7s0_features(py_cpuid_features *flags)
513518
static inline void
514519
cpuid_detect_l7s1_features(py_cpuid_features *flags)
515520
{
521+
assert(flags->maxleaf >= 7);
516522
CPUID_REG eax = 0, ebx = 0, ecx = 0, edx = 0;
517523
get_cpuid_info(7, 1, &eax, &ebx, &ecx, &edx);
518524
detect_cpuid_extended_features_L7S1(flags, eax, ebx, ecx, edx);

0 commit comments

Comments
 (0)