8000 gh-125022: add support for simple SIMD features detection by picnixz · Pull Request #125011 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-125022: add support for simple SIMD features detection #125011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 90 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
90 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 8000 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
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
update comments
  • Loading branch information
picnixz committed Oct 6, 2024
commit 969a619c82d56741168e31ccfeb8c659a60f074f
43 changes: 22 additions & 21 deletions Python/cpuinfo.c
< 8000 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#include "Python.h"
#include "pycore_cpuinfo.h"

#define CPUID_REG(ARG) ARG
/* Macro to mark a CPUID register function parameter as being used. */
#define CPUID_REG(PARAM) PARAM
/* Macro to check a CPUID register bit. */
#define CPUID_CHECK_REG(REGISTER, MASK) ((REGISTER) & (MASK)) == 0 ? 0 : 1

/*
* For simplicity, we only enable SIMD instructions for Intel CPUs,
Expand All @@ -19,7 +22,7 @@
# include <intrin.h>
#else
# undef CPUID_REG
# define CPUID_REG(ARG) Py_UNUSED(ARG)
# define CPUID_REG(PARAM) Py_UNUSED(PARAM)
#endif

// AVX2 cannot be compiled on macOS ARM64 (yet it can be compiled on x86_64).
Expand All @@ -38,18 +41,16 @@
*
* - REGISTER is either EBX, ECX or EDX,
* - PAGE is either 1 or 7 depending, and
* - FEATURE is an SIMD instruction set.
* - FEATURE is a SIMD feature (with one or more specialized instructions).
*/
#define EDX1_SSE (1 << 25) // sse, EDX, page 1, bit 25
#define EDX1_SSE2 (1 << 26) // sse2, EDX, page 1, bit 26
#define ECX1_SSE3 (1 << 9) // sse3, ECX, page 1, bit 0
#define ECX1_SSE4_1 (1 << 19) // sse4.1, ECX, page 1, bit 19
#define ECX1_SSE4_2 (1 << 20) // sse4.2, ECX, page 1, bit 20
#define ECX1_AVX (1 << 28) // avx, ECX, page 1, bit 28
#define EBX7_AVX2 (1 << 5) // avx2, EBX, page 7, bit 5
#define ECX7_AVX512_VBMI (1 << 1) // avx512-vbmi, ECX, page 7, bit 1

#define CHECK_CPUID_REGISTER(REGISTER, MASK) ((REGISTER) & (MASK)) == 0 ? 0 : 1
#define EDX1_SSE (1 << 25)
#define EDX1_SSE2 (1 << 26)
#define ECX1_SSE3 (1 << 9)
#define ECX1_SSE4_1 (1 << 19)
#define ECX1_SSE4_2 (1 << 20)
#define ECX1_AVX (1 << 28)
#define EBX7_AVX2 (1 << 5)
#define ECX7_AVX512_VBMI (1 << 1)

/*
* Indicate whether the CPUID input EAX=1 may be needed to
Expand Down Expand Up @@ -100,22 +101,22 @@ detect_cpu_simd_features(py_cpu_simd_flags *flags)
int32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
get_cpuid_info(1, 0, &eax, &ebx, &ecx, &edx);
#ifdef CAN_COMPILE_SIMD_SSE_INSTRUCTIONS
flags->sse = CHECK_CPUID_REGISTER(edx, EDX1_SSE);
flags->sse = CPUID_CHECK_REG(edx, EDX1_SSE);
#endif
#ifdef CAN_COMPILE_SIMD_SSE2_INSTRUCTIONS
flags->sse2 = CHECK_CPUID_REGISTER(edx, EDX1_SSE2);
flags->sse2 = CPUID_CHECK_REG(edx, EDX1_SSE2);
#endif
#ifdef CAN_COMPILE_SIMD_SSE3_INSTRUCTIONS
flags->sse3 = CHECK_CPUID_REGISTER(ecx, ECX1_SSE3);
flags->sse3 = CPUID_CHECK_REG(ecx, ECX1_SSE3);
#endif
#ifdef CAN_COMPILE_SIMD_SSE4_1_INSTRUCTIONS
flags->sse41 = CHECK_CPUID_REGISTER(ecx, ECX1_SSE4_1);
flags->sse41 = CPUID_CHECK_REG(ecx, ECX1_SSE4_1);
#endif
#ifdef CAN_COMPILE_SIMD_SSE4_2_INSTRUCTIONS
flags->sse42 = CHECK_CPUID_REGISTER(ecx, ECX1_SSE4_2);
flags->sse42 = CPUID_CHECK_REG(ecx, ECX1_SSE4_2);
#endif
#ifdef CAN_COMPILE_SIMD_AVX_INSTRUCTIONS
flags->avx = CHECK_CPUID_REGISTER(ecx, ECX1_AVX);
flags->avx = CPUID_CHECK_REG(ecx, ECX1_AVX);
#endif
}

Expand All @@ -126,10 +127,10 @@ detect_cpu_simd_extended_features(py_cpu_simd_flags *flags)
int32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
get_cpuid_info(7, 0, &eax, &ebx, &ecx, &edx);
#ifdef CAN_COMPILE_SIMD_AVX2_INSTRUCTIONS
flags->avx2 = CHECK_CPUID_REGISTER(ebx, EBX7_AVX2);
flags->avx2 = CPUID_CHECK_REG(ebx, EBX7_AVX2);
#endif
#ifdef CAN_COMPILE_SIMD_AVX512_VBMI_INSTRUCTIONS
flags->avx512vbmi = CHECK_CPUID_REGISTER(ecx, ECX7_AVX512_VBMI);
flags->avx512vbmi = CPUID_CHECK_REG(ecx, ECX7_AVX512_VBMI);
#endif
}

Expand Down
Loading
0