Skip to content

Commit bd3589f

Browse files
committed
add comments
1 parent a6c443f commit bd3589f

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

Include/internal/pycore_cpuinfo_cpuid_features.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ import os
4242
import sys
4343
4444
ROOT = os.getcwd()
45-
TOOL = os.path.join(ROOT, 'Tools/cpuinfo/cpuid_features_gen.py')
45+
TOOL = os.path.join(ROOT, "Tools/cpuinfo/cpuid_features_gen.py")
4646
TOOL = os.path.realpath(TOOL)
4747
4848
if not os.path.exists(TOOL):
4949
raise FileNotFoundError(TOOL)
5050
5151
sys.path.insert(0, os.path.dirname(os.path.dirname(TOOL)))
52-
module = importlib.import_module('cpuinfo.cpuid_features_gen')
52+
module = importlib.import_module("cpuinfo.cpuid_features_gen")
5353
print(module.generate_cpuid_features_enum("py_cpuid_feature_mask"))
5454
[python start generated code]*/
5555
typedef enum py_cpuid_feature_mask {
@@ -96,7 +96,7 @@ typedef enum py_cpuid_feature_mask {
9696
Py_CPUID_MASK_EDX_L7S1_AVX_NE_CONVERT = 0x00000020, // bit = 5
9797
Py_CPUID_MASK_EDX_L7S1_AVX_VNNI_INT16 = 0x00000400, // bit = 10
9898
} py_cpuid_feature_mask;
99-
/*[python end generated code: output=c4460242e465fa91 input=a07f431329efd11e]*/
99+
/*[python end generated code: output=c4460242e465fa91 input=61d2b5f1bc368b94]*/
100100
// fmt: on
101101

102102
#endif // !Py_INTERNAL_CPUINFO_CPUID_FEATURES_H

Include/internal/pycore_cpuinfo_xsave_features.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* @author Bénédikt Tran
33
* @seealso Tools/cpuinfo/xsave_features_gen.py
44
*
5-
* XSAVE state components (XCR0 control register)
5+
* XSAVE state components (XCR0 control register).
6+
*
7+
* See https://en.wikipedia.org/wiki/Control_register#XCR0_and_XSS.
68
*/
79
#ifndef Py_INTERNAL_CPUINFO_XSAVE_FEATURES_H
810
#define Py_INTERNAL_CPUINFO_XSAVE_FEATURES_H
@@ -24,14 +26,14 @@ import os
2426
import sys
2527
2628
ROOT = os.getcwd()
27-
TOOL = os.path.join(ROOT, 'Tools/cpuinfo/xsave_features_gen.py')
29+
TOOL = os.path.join(ROOT, "Tools/cpuinfo/xsave_features_gen.py")
2830
TOOL = os.path.realpath(TOOL)
2931
3032
if not os.path.exists(TOOL):
3133
raise FileNotFoundError(TOOL)
3234
3335
sys.path.insert(0, os.path.dirname(os.path.dirname(TOOL)))
34-
module = importlib.import_module('cpuinfo.xsave_features_gen')
36+
module = importlib.import_module("cpuinfo.xsave_features_gen")
3537
print(module.generate_xsave_features_enum("py_xsave_feature_mask"))
3638
[python start generated code]*/
3739
typedef enum py_xsave_feature_mask {
@@ -41,7 +43,7 @@ typedef enum py_xsave_feature_mask {
4143
Py_XSAVE_MASK_XCR0_AVX512_ZMM_HI256 = 0x00000040, // bit = 6
4244
Py_XSAVE_MASK_XCR0_AVX512_HI16_ZMM = 0x00000080, // bit = 7
4345
} py_xsave_feature_mask;
44-
/*[python end generated code: output=9a476ed0abbc617b input=78e3d4ff6b796edb]*/
46+
/*[python end generated code: output=9a476ed0abbc617b input=41f35058299c0118]*/
4547
// fmt: on
4648

4749
#endif // !Py_INTERNAL_CPUINFO_XSAVE_FEATURES_H

Tools/cpuinfo/cpuid_features_gen.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
1818
The LEAF value should only 1 or 7 as other values may have different
1919
meanings depending on the underlying architecture.
20+
21+
.. seealso:: Include/internal/pycore_cpuinfo_cpuid_features.h
2022
"""
2123

2224
from __future__ import annotations
@@ -39,7 +41,8 @@
3941
type Feature = str
4042
type Bit = int
4143

42-
CPUID_FEATURES: Final[dict[CPUIDFeatureFamily, dict[Feature, Bit]]] = {
44+
CPUID_FEATURES: Final[dict[FeatureFamily, dict[Feature, Bit]]] = {
45+
# See https://en.wikipedia.org/wiki/CPUID#EAX=1:_Processor_Info_and_Feature_Bits.
4346
(1, 0, "ECX"): {
4447
"SSE3": 0,
4548
"PCLMULQDQ": 1,
@@ -57,6 +60,7 @@
5760
"SSE": 25,
5861
"SSE2": 26,
5962
},
63+
# See https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=0:_Extended_Features.
6064
(7, 0, "EBX"): {
6165
"AVX2": 5,
6266
"AVX512_F": 16,
@@ -80,6 +84,7 @@
8084
"AVX512_4FMAPS": 3,
8185
"AVX512_VP2INTERSECT": 8,
8286
},
87+
# See https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=1:_Extended_Features.
8388
(7, 1, "EAX"): {
8489
"AVX_VNNI": 4,
8590
"AVX_IFMA": 23,
@@ -109,6 +114,11 @@ def get_member_name(
109114

110115

111116
def generate_cpuid_features_enum(enum_name: str) -> str:
117+
"""Used by Include/internal/pycore_cpuinfo_cpuid_features.h.
118+
119+
The C enumeration is generated by this function and Argument Clinic.
120+
"""
121+
112122
# The enumeration is rendered as follows:
113123
#
114124
# <INDENT><MEMBER_NAME> <TAB>= 0x<MASK>, <TAB>// bit = BIT

Tools/cpuinfo/xsave_features_gen.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""
22
Generate enumeration for XSAVE state components (XCR0 control register).
3+
4+
See https://en.wikipedia.org/wiki/Control_register#XCR0_and_XSS.
5+
6+
.. seealso:: Include/internal/pycore_cpuinfo_xsave_features.h
37
"""
48

59
from __future__ import annotations
@@ -36,6 +40,11 @@ def get_member_name(feature: Feature) -> str:
3640

3741

3842
def generate_xsave_features_enum(enum_name: str) -> str:
43+
"""Used by Include/internal/pycore_cpuinfo_xsave_features.h.
44+
45+
The C enumeration is generated by this function and Argument Clinic.
46+
"""
47+
3948
# The enumeration is rendered as follows:
4049
#
4150
# <INDENT><MEMBER_NAME> <TAB>= 0x<MASK>, <TAB>// bit = BIT

0 commit comments

Comments
 (0)