Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
9a6ccb5
support simple SIMD detection
picnixz Oct 5, 2024
f4e4f99
add _Py prefix
picnixz Oct 5, 2024
5006686
Use `_py` prefix
picnixz Oct 5, 2024
3c0b4f1
make the interface friendlier for future adjustments
picnixz Oct 6, 2024
01ed21a
Allow `cpu_simd_flags` to be merged.
picnixz Oct 6, 2024
969a619
update comments
picnixz Oct 6, 2024
5a5acc2
fix typo
picnixz Oct 6, 2024
ac1b165
fix configure script
picnixz Oct 6, 2024
6f304f2
fix bit detection
picnixz Oct 6, 2024
f3bd027
Harden detection of AVX instructions.
picnixz Oct 7, 2024
16b2aed
do not guard the parsing of `os_xsave`
picnixz Oct 7, 2024
5018fa9
Remove old comment.
picnixz Oct 7, 2024
e758065
Update cpuinfo.c comments
picnixz Oct 7, 2024
731be81
Update pycore_cpuinfo.h comments
picnixz Oct 7, 2024
7947715
fix lint
picnixz Oct 7, 2024
7a17cbb
I really shouldn't use a Web UI
picnixz Oct 7, 2024
76f67b1
Fix _xgetbv() on Windows builds.
picnixz Oct 7, 2024
0b49a50
fix comment
picnixz Oct 8, 2024
9fd6152
harden detection of CPU features
picnixz Oct 8, 2024
97a0fc5
update configure
picnixz Oct 11, 2024
f7da530
Merge remote-tracking branch 'upstream/main' into core/simd-helpers-1…
picnixz Oct 11, 2024
5f2884d
update comments
picnixz Oct 13, 2024
7c3b74e
update Makefile
picnixz Oct 13, 2024
130d099
address Erlend's review
picnixz Oct 14, 2024
cd575f0
lint & comment fixups
picnixz Oct 14, 2024
2b597a4
Update docs
picnixz Oct 27, 2024
78be530
Fix typo
picnixz Oct 27, 2024
fd47f0e
Merge branch 'main' into core/simd-helpers
picnixz Dec 17, 2024
cbb7b53
re-export functions for extension modules
picnixz Dec 17, 2024
21d8ca8
rename os_xsave to osxsave for future automatism
picnixz Dec 17, 2024
1f9dbb4
remember `maxleaf` and make detection more readable
picnixz Dec 18, 2024
553aa7c
use enumeration for flags
picnixz Dec 18, 2024
39d2ba4
fix warnings
picnixz Dec 21, 2024
602bb9c
Merge branch 'main' into core/simd-helpers
picnixz Dec 21, 2024
d6a3523
remove un-necessary comment and newline continuation
picnixz Dec 22, 2024
ff4212e
Merge branch 'main' into core/simd-helpers
picnixz Feb 16, 2025
3cb79f6
regen configure
picnixz Feb 17, 2025
e0a578c
clinic now supports empty comment lines in Python blocks
picnixz Feb 17, 2025
6fdbbdf
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Mar 11, 2025
c265851
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Mar 29, 2025
c12f9c7
move cpuinfo enumerations to real invokable Python scripts
picnixz Mar 29, 2025
a6c443f
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Apr 5, 2025
bd3589f
add comments
picnixz Apr 5, 2025
d213b67
update C comments
picnixz Apr 8, 2025
4109d90
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Apr 8, 2025
19b7d86
TMP: usage proof-of-concept
picnixz Apr 8, 2025
1732b6b
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Apr 22, 2025
d59d06d
improve configure.ac
picnixz Apr 22, 2025
bc2c1e5
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Apr 25, 2025
4a92103
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Jun 2, 2025
26ed6fd
Merge branch 'main' into feat/core/simd-125022
picnixz Jun 30, 2025
d00da3e
post-merge
picnixz Jun 30, 2025
8b7ecfb
use `_Py` prefix to prevent public namespace pollution
picnixz Jun 30, 2025
3c31ba3
let the compiler decide on the inlineness
picnixz Jun 30, 2025
143d57e
drop CPUID_REG alias
picnixz Jun 30, 2025
ee2a83c
simplify `_Py_cpuid_check_features`
picnixz Jun 30, 2025
e6d4583
amend docs for `_Py_cpuid_disable_features`
picnixz Jun 30, 2025
838f928
use macros to support larger flag ranges
picnixz Jun 30, 2025
62c9a40
handle -Wpedantic
picnixz Jun 30, 2025
a22aa95
reorganize files
picnixz Jul 8, 2025
87039dc
suppress compilation warnings
picnixz Jul 8, 2025
8a4b120
add linting
picnixz Jul 8, 2025
8603e14
typo
picnixz Jul 8, 2025
d6213a5
typo
picnixz Jul 8, 2025
79d5b34
log more!
picnixz Jul 13, 2025
f69d74a
skip CI
picnixz Jul 13, 2025
cb9065d
more printf
picnixz Jul 13, 2025
88df3b7
faster ci
picnixz Jul 13, 2025
db64ba5
!!
picnixz Jul 13, 2025
04012b4
!!
picnixz Jul 13, 2025
144d9ef
does it work now..?
picnixz Jul 14, 2025
b364ad2
does it work now..?
picnixz Jul 14, 2025
0791e89
remove xgetbv support?
picnixz Jul 14, 2025
48b2cb2
remove xgetbv support?
picnixz Jul 14, 2025
34f1337
huh?
picnixz Jul 14, 2025
91effb4
only parse maxleaf
picnixz Jul 14, 2025
6dc532d
use different variables!
picnixz Jul 14, 2025
6d5dd0b
disable everything!
picnixz Jul 14, 2025
8e5b2f0
revert CI
picnixz Jul 14, 2025
3b495f6
only check maxleaf
picnixz Jul 14, 2025
8019f09
parse L1
picnixz Jul 14, 2025
820d140
parse L7
picnixz Jul 14, 2025
df85ce5
it *should* work now
picnixz Jul 14, 2025
915383e
:@
picnixz Jul 14, 2025
c6cf903
:@
picnixz Jul 14, 2025
498518f
waaaaa!
picnixz Jul 14, 2025
3d56d93
remove support for XCR0 registers
picnixz Jul 14, 2025
08daa8a
fix SIMD-256 detection
picnixz Jul 14, 2025
afd1137
simplify `get_cpuid_info`
picnixz Jul 14, 2025
79eb72d
add CODEOWNERS
picnixz Jul 15, 2025
09c150a
Merge branch 'main' into feat/core/simd-125022
picnixz Jul 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove support for XCR0 registers
  • Loading branch information
picnixz committed Jul 14, 2025
commit 3d56d9391682d1d6e7fa8155fa5c3b23d448436a
15 changes: 2 additions & 13 deletions Include/internal/pycore_cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern "C" {

#include "Python.h"
#include "pycore_cpuinfo_cpuid_features.h"
#include "pycore_cpuinfo_xsave_features.h"

typedef struct _Py_cpuid_features_s {
uint32_t maxleaf;
Expand Down Expand Up @@ -101,21 +100,11 @@ typedef struct _Py_cpuid_features_s {
_Py_CPUID_DECL_FLAG(xsave); // XSAVE/XRSTOR/XSETBV/XGETBV
_Py_CPUID_DECL_FLAG(osxsave); // XSAVE is enabled by the OS

// --- XCR0 register bits -------------------------------------------------
_Py_CPUID_DECL_FLAG(xcr0_sse);
// On some Intel CPUs, it is possible for the CPU to support AVX2
// instructions even though the underlying OS does not know about
// AVX. In particular, only (SSE) XMM registers will be saved and
// restored on context-switch, but not (AVX) YMM registers.
_Py_CPUID_DECL_FLAG(xcr0_avx);
_Py_CPUID_DECL_FLAG(xcr0_avx512_opmask);
_Py_CPUID_DECL_FLAG(xcr0_avx512_zmm_hi256);
_Py_CPUID_DECL_FLAG(xcr0_avx512_hi16_zmm);
#undef _Py_CPUID_DECL_FLAG
// Whenever a field is added or removed above, update the
// number of fields (40) and adjust the bitsize of 'ready'
// number of fields (35) and adjust the bitsize of 'ready'
// so that the size of this structure is a multiple of 8.
uint8_t ready; // set if the structure is ready for usage
uint8_t ready: 5; // set if the structure is ready for usage
} _Py_cpuid_features;

/*
Expand Down
43 changes: 0 additions & 43 deletions Include/internal/pycore_cpuinfo_xsave_features.h

This file was deleted.

4 changes: 0 additions & 4 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,6 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_context.h \
$(srcdir)/Include/internal/pycore_cpuinfo.h \
$(srcdir)/Include/internal/pycore_cpuinfo_cpuid_features.h \
$(srcdir)/Include/internal/pycore_cpuinfo_xsave_features.h \
$(srcdir)/Include/internal/pycore_critical_section.h \
$(srcdir)/Include/internal/pycore_crossinterp.h \
$(srcdir)/Include/internal/pycore_crossinterp_data_registry.h \
Expand Down Expand Up @@ -1938,9 +1937,6 @@ Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(srcdir)/Include/pydt
$(MULTIARCH_CPPFLAGS) \
-o $@ $(srcdir)/Python/sysmodule.c

Python/cpuinfo.o: $(srcdir)/Python/cpuinfo.c Makefile
$(CC) -c $(PY_CORE_CFLAGS) @CORE_CPUINFO_CFLAGS@ -o $@ $(srcdir)/Python/cpuinfo.c

$(IO_OBJS): $(IO_H)

.PHONY: regen-pegen-metaparser
Expand Down
1 change: 0 additions & 1 deletion PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
<ClInclude Include="..\Include\internal\pycore_context.h" />
<ClInclude Include="..\Include\internal\pycore_cpuinfo.h" />
<ClInclude Include="..\Include\internal\pycore_cpuinfo_cpuid_features.h" />
<ClInclude Include="..\Include\internal\pycore_cpuinfo_xsave_features.h" />
<ClInclude Include="..\Include\internal\pycore_critical_section.h" />
<ClInclude Include="..\Include\internal\pycore_crossinterp.h" />
<ClInclude Include="..\Include\internal\pycore_crossinterp_data_registry.h" />
Expand Down
3 changes: 0 additions & 3 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,6 @@
<ClInclude Include="..\Include\internal\pycore_cpuinfo_cpuid_features.h">
<Filter>Include\internal</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_cpuinfo_xsave_features.h">
<Filter>Include\internal</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_critical_section.h">
<Filter>Include\internal</Filter>
</ClInclude>
Expand Down
61 changes: 0 additions & 61 deletions Python/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
#define HAS_CPUID_SUPPORT
#if defined(__x86_64__) && defined(__GNUC__)
# include <cpuid.h> // __cpuid_count()
# include <immintrin.h> // _xgetbv()
#elif defined(_M_X64) || defined(__amd64__) || defined(_M_AMD64)
# include <intrin.h> // __cpuidex()
# include <immintrin.h> // _xgetbv()
#else
# undef HAS_CPUID_SUPPORT
#endif
Expand All @@ -24,13 +22,6 @@
// corresponding flags or if we are not on an 64-bit platform we do not
// even try to inspect the output of CPUID for those specific features.
#ifdef HAS_CPUID_SUPPORT
#if defined(_Py_CPUINFO_USE_XGETBV_FUNC) \
|| defined(_Py_CPUINFO_USE_XGETBV_OPCODE)
# define HAS_XGETBV_SUPPORT
#endif

#undef HAS_XGETBV_SUPPORT

#if defined(_Py_CAN_COMPILE_SIMD_SSE_INSTRUCTIONS) \
|| defined(_Py_CAN_COMPILE_SIMD_SSE2_INSTRUCTIONS) \
|| defined(_Py_CAN_COMPILE_SIMD_SSE3_INSTRUCTIONS) \
Expand Down Expand Up @@ -155,34 +146,6 @@ get_cpuid_info(uint32_t level /* input eax */,
#endif
}

#if defined(HAS_XGETBV_SUPPORT) && defined(SHOULD_PARSE_CPUID_L1)
static uint64_t /* should only be used after calling cpuid(1, 0, ...) */
get_xgetbv(uint32_t index)
{
assert(index == 0); // only XCR0 is supported for now
#if defined(_Py_CPUINFO_USE_XGETBV_FUNC)
/* directly use the compiler's helper if -mxsave is available */
return (uint64_t)_xgetbv(index);
#elif defined(__x86_64__) && defined(__GNUC__)
uint32_t eax = 0, edx = 0;
__asm__ volatile(
/* raw opcode for xgetbv for compatibility with older toolchains */
".byte 0x0f, 0x01, 0xd0"
: "=a" (eax), "=d" (edx)
: "c" (index)
);
return ((uint64_t)edx << 32) | eax;
#elif defined(_M_X64)
return (uint64_t)_xgetbv(index);
#else
(void)index;
return 0;
#endif
}
#else
#define get_xgetbv(_INDEX) 0
#endif

/* Highest Function Parameter and Manufacturer ID (LEAF=0, SUBLEAF=0). */
static uint32_t
detect_cpuid_maxleaf(void)
Expand Down Expand Up @@ -349,23 +312,6 @@ detect_cpuid_extended_features_L7S1(_Py_cpuid_features *flags,
}
#endif

#ifdef SHOULD_PARSE_CPUID_L1
static void /* should only be used after calling cpuid(1, 0, ...) */
detect_cpuid_xsave_state(_Py_cpuid_features *flags)
{
assert(flags->ready == 0);
assert(flags->maxleaf >= 1);
(void)flags;
// Keep the ordering and newlines as they are declared in the structure.
uint64_t xcr0 = flags->xsave && flags->osxsave ? get_xgetbv(0) : 0;
flags->xcr0_sse = XSAVE_CHECK_REG(xcr0, XCR0_SSE);
flags->xcr0_avx = XSAVE_CHECK_REG(xcr0, XCR0_AVX);
flags->xcr0_avx512_opmask = XSAVE_CHECK_REG(xcr0, XCR0_AVX512_OPMASK);
flags->xcr0_avx512_zmm_hi256 = XSAVE_CHECK_REG(xcr0, XCR0_AVX512_ZMM_HI256);
flags->xcr0_avx512_hi16_zmm = XSAVE_CHECK_REG(xcr0, XCR0_AVX512_HI16_ZMM);
}
#endif

static void
cpuid_features_finalize(_Py_cpuid_features *flags)
{
Expand Down Expand Up @@ -460,12 +406,6 @@ _Py_cpuid_check_features(const _Py_cpuid_features *flags)
\
MACRO(xsave); \
MACRO(osxsave); \
\
MACRO(xcr0_sse); \
MACRO(xcr0_avx); \
MACRO(xcr0_avx512_opmask); \
MACRO(xcr0_avx512_zmm_hi256); \
MACRO(xcr0_avx512_hi16_zmm); \
} while (0)

void
Expand Down Expand Up @@ -530,7 +470,6 @@ cpuid_detect_l1_features(_Py_cpuid_features *flags)
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
get_cpuid_info(1, 0, &eax, &ebx, &ecx, &edx);
detect_cpuid_features(flags, ecx, edx);
detect_cpuid_xsave_state(flags);
}
}
#else
Expand Down
51 changes: 0 additions & 51 deletions Tools/cpuinfo/libcpuinfo/features/xsave.py

This file was deleted.

Loading
Loading