8000 [3.14] gh-135755: rename undocumented `HACL_CAN_COMPILE_SIMD{128,256}… · python/cpython@7028095 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7028095

Browse files
authored
[3.14] gh-135755: rename undocumented HACL_CAN_COMPILE_SIMD{128,256} macros (GH-135847) (#136045)
Rename undocumented `HACL_CAN_COMPILE_SIMD{128,256}` macros to `_Py_HACL_CAN_COMPILE_VEC{128,256}`. These macros are private. (cherry picked from commit 1e975ae)
1 parent eff347c commit 7028095

File tree

6 files changed

+67
-60
lines changed

6 files changed

+67
-60
lines changed

Modules/blake2module.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@
4343

4444
// SIMD256 can't be compiled on macOS ARM64, and performance of SIMD128 isn't
4545
// great; but when compiling a universal2 binary, autoconf will set
46-
// HACL_CAN_COMPILE_SIMD128 and HACL_CAN_COMPILE_SIMD256 because they *can* be
47-
// compiled on x86_64. If we're on macOS ARM64, disable these preprocessor
48-
// symbols.
46+
// _Py_HACL_CAN_COMPILE_VEC{128,256} because they *can* be compiled on x86_64.
47+
// If we're on macOS ARM64, we however disable these preprocessor symbols.
4948
#if defined(__APPLE__) && defined(__arm64__)
50-
# undef HACL_CAN_COMPILE_SIMD128
51-
# undef HACL_CAN_COMPILE_SIMD256
49+
# undef _Py_HACL_CAN_COMPILE_VEC128
50+
# undef _Py_HACL_CAN_COMPILE_VEC256
5251
#endif
5352

5453
// ECX
@@ -114,31 +113,32 @@ void detect_cpu_features(cpu_flags *flags) {
114113
}
115114
}
116115

117-
#ifdef HACL_CAN_COMPILE_SIMD128
116+
#if _Py_HACL_CAN_COMPILE_VEC128
118117
static inline bool has_simd128(cpu_flags *flags) {
119-
// For now this is Intel-only, could conceivably be #ifdef'd to something
118+
// For now this is Intel-only, could conceivably be if'd to something
120119
// else.
121120
return flags->sse && flags->sse2 && flags->sse3 && flags->sse41 && flags->sse42 && flags->cmov;
122121
}
123122
#endif
124123

125-
#ifdef HACL_CAN_COMPILE_SIMD256
124+
#if _Py_HACL_CAN_COMPILE_VEC256
126125
static inline bool has_simd256(cpu_flags *flags) {
127126
return flags->avx && flags->avx2;
128127
}
129128
#endif
130129

131-
// Small mismatch between the variable names Python defines as part of configure
132-
// at the ones HACL* expects to be set in order to enable those headers.
133-
#define HACL_CAN_COMPILE_VEC128 HACL_CAN_COMPILE_SIMD128
134-
#define HACL_CAN_COMPILE_VEC256 HACL_CAN_COMPILE_SIMD256
130+
// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable
131+
// the corresponding SIMD instructions so we need to "forward" the values
132+
// we just deduced above.
133+
#define HACL_CAN_COMPILE_VEC128 _Py_HACL_CAN_COMPILE_VEC128
134+
#define HACL_CAN_COMPILE_VEC256 _Py_HACL_CAN_COMPILE_VEC256
135135

136136
#include "_hacl/Hacl_Hash_Blake2b.h"
137137
#include "_hacl/Hacl_Hash_Blake2s.h"
138-
#if HACL_CAN_COMPILE_SIMD256
138+
#if _Py_HACL_CAN_COMPILE_VEC256
139139
#include "_hacl/Hacl_Hash_Blake2b_Simd256.h"
140140
#endif
141-
#if HACL_CAN_COMPILE_SIMD128
141+
#if _Py_HACL_CAN_COMPILE_VEC128
142142
#include "_hacl/Hacl_Hash_Blake2s_Simd128.h"
143143
#endif
144144

@@ -165,7 +165,7 @@ blake2_get_state(PyObject *module)
165165
return (Blake2State *)state;
166166
}
167167

168-
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
168+
#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256)
169169
static inline Blake2State*
170170
blake2_get_state_from_type(PyTypeObject *module)
171171
{
@@ -329,18 +329,18 @@ static inline bool is_blake2s(blake2_impl impl) {
329329
}
330330

331331
static inline blake2_impl type_to_impl(PyTypeObject *type) {
332-
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
332+
#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256)
333333
Blake2State* st = blake2_get_state_from_type(type);
334334
#endif
335335
if (!strcmp(type->tp_name, blake2b_type_spec.name)) {
336-
#ifdef HACL_CAN_COMPILE_SIMD256
336+
#if _Py_HACL_CAN_COMPILE_VEC256
337337
if (has_simd256(&st->flags))
338338
return Blake2b_256;
339339
else
340340
#endif
341341
return Blake2b;
342342
} else if (!strcmp(type->tp_name, blake2s_type_spec.name)) {
343-
#ifdef HACL_CAN_COMPILE_SIMD128
343+
#if _Py_HACL_CAN_COMPILE_VEC128
344344
if (has_simd128(&st->flags))
345345
return Blake2s_128;
346346
else
@@ -356,10 +356,10 @@ typedef struct {
356356
union {
357357
Hacl_Hash_Blake2s_state_t *blake2s_state;
358358
Hacl_Hash_Blake2b_state_t *blake2b_state;
359-
#ifdef HACL_CAN_COMPILE_SIMD128
359+
#if _Py_HACL_CAN_COMPILE_VEC128
360360
Hacl_Hash_Blake2s_Simd128_state_t *blake2s_128_state;
361361
#endif
362-
#ifdef HACL_CAN_COMPILE_SIMD256
362+
#if _Py_HACL_CAN_COMPILE_VEC256
363363
Hacl_Hash_Blake2b_Simd256_state_t *blake2b_256_state;
364364
#endif
365365
};
@@ -425,14 +425,14 @@ static void
425425
update(Blake2Object *self, uint8_t *buf, Py_ssize_t len)
426426
{
427427
switch (self->impl) {
428-
// These need to be ifdef'd out otherwise it's an unresolved symbol at
429-
// link-time.
430-
#ifdef HACL_CAN_COMPILE_SIMD256
428+
// blake2b_256_state and blake2s_128_state must be if'd since
429+
// otherwise this results in an unresolved symbol at link-time.
430+
#if _Py_HACL_CAN_COMPILE_VEC256
431431
case Blake2b_256:
432432
HACL_UPDATE(Hacl_Hash_Blake2b_Simd256_update,self->blake2b_256_state, buf, len);
433433
return;
434434
#endif
435-
#ifdef HACL_CAN_COMPILE_SIMD128
435+
#if _Py_HACL_CAN_COMPILE_VEC128
436436
case Blake2s_128:
437437
HACL_UPDATE(Hacl_Hash_Blake2s_Simd128_update,self->blake2s_128_state, buf, len);
438438
return;
@@ -468,12 +468,12 @@ py_blake2b_or_s_new(PyTypeObject *type, PyObject *data, int digest_size,
468468
// Ensure that the states are NULL-initialized in case of an error.
469469
// See: py_blake2_clear() for more details.
470470
switch (self->impl) {
471-
#if HACL_CAN_COMPILE_SIMD256
471+
#if _Py_HACL_CAN_COMPILE_VEC256
472472
case Blake2b_256:
473473
self->blake2b_256_state = NULL;
474474
break;
475475
#endif
476-
#if HACL_CAN_COMPILE_SIMD128
476+
#if _Py_HACL_CAN_COMPILE_VEC128
477477
case Blake2s_128:
478478
self->blake2s_128_state = NULL;
479479
break;
@@ -591,7 +591,7 @@ py_blake2b_or_s_new(PyTypeObject *type, PyObject *data, int digest_size,
591591
};
592592

593593
switch (self->impl) {
594-
#if HACL_CAN_COMPILE_SIMD256
594+
#if _Py_HACL_CAN_COMPILE_VEC256
595595
case Blake2b_256: {
596596
self->blake2b_256_state = Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key(&params, last_node, key->buf);
597597
if (self->blake2b_256_state == NULL) {
@@ -601,7 +601,7 @@ py_blake2b_or_s_new(PyTypeObject *type, PyObject *data, int digest_size,
601601
break;
602602
}
603603
#endif
604-
#if HACL_CAN_COMPILE_SIMD128
604+
#if _Py_HACL_CAN_COMPILE_VEC128
605605
case Blake2s_128: {
606606
self->blake2s_128_state = Hacl_Hash_Blake2s_Simd128_malloc_with_params_and_key(&params, last_node, key->buf);
607607
if (self->blake2s_128_state == NULL) {
@@ -733,7 +733,7 @@ blake2_blake2b_copy_locked(Blake2Object *self, Blake2Object *cpy)
733733
{
734734
assert(cpy != NULL);
735735
switch (self->impl) {
736-
#if HACL_CAN_COMPILE_SIMD256
736+
#if _Py_HACL_CAN_COMPILE_VEC256
737737
case Blake2b_256: {
738738
cpy->blake2b_256_state = Hacl_Hash_Blake2b_Simd256_copy(self->blake2b_256_state);
739739
if (cpy->blake2b_256_state == NULL) {
@@ -742,7 +742,7 @@ blake2_blake2b_copy_locked(Blake2Object *self, Blake2Object *cpy)
742742
break;
743743
}
744744
#endif
745-
#if HACL_CAN_COMPILE_SIMD128
745+
#if _Py_HACL_CAN_COMPILE_VEC128
746746
case Blake2s_128: {
747747
cpy->blake2s_128_state = Hacl_Hash_Blake2s_Simd128_copy(self->blake2s_128_state);
748748
if (cpy->blake2s_128_state == NULL) {
@@ -853,12 +853,12 @@ _blake2_blake2b_digest_impl(Blake2Object *self)
853853
ENTER_HASHLIB(self);
854854
uint8_t digest_length = 0;
855855
switch (self->impl) {
856-
#if HACL_CAN_COMPILE_SIMD256
856+
#if _Py_HACL_CAN_COMPILE_VEC256
857857
case Blake2b_256:
858858
digest_length = Hacl_Hash_Blake2b_Simd256_digest(self->blake2b_256_state, digest);
859859
break;
860860
#endif
861-
#if HACL_CAN_COMPILE_SIMD128
861+
#if _Py_HACL_CAN_COMPILE_VEC128
862862
case Blake2s_128:
863863
digest_length = Hacl_Hash_Blake2s_Simd128_digest(self->blake2s_128_state, digest);
864864
break;
@@ -891,12 +891,12 @@ _blake2_blake2b_hexdigest_impl(Blake2Object *self)
891891
ENTER_HASHLIB(self);
892892
uint8_t digest_length = 0;
893893
switch (self->impl) {
894-
#if HACL_CAN_COMPILE_SIMD256
894+
#if _Py_HACL_CAN_COMPILE_VEC256
895895
case Blake2b_256:
896896
digest_length = Hacl_Hash_Blake2b_Simd256_digest(self->blake2b_256_state, digest);
897897
break;
898898
#endif
899-
#if HACL_CAN_COMPILE_SIMD128
899+
#if _Py_HACL_CAN_COMPILE_VEC128
900900
case Blake2s_128:
901901
digest_length = Hacl_Hash_Blake2s_Simd128_digest(self->blake2s_128_state, digest);
902902
break;
@@ -947,11 +947,11 @@ py_blake2b_get_digest_size(PyObject *op, void *Py_UNUSED(closure))
947947
{
948948
Blake2Object *self = _Blake2Object_CAST(op);
949949
switch (self->impl) {
950-
#if HACL_CAN_COMPILE_SIMD256
950+
#if _Py_HACL_CAN_COMPILE_VEC256
951951
case Blake2b_256:
952952
return PyLong_FromLong(Hacl_Hash_Blake2b_Simd256_info(self->blake2b_256_state).digest_length);
953953
#endif
954-
#if HACL_CAN_COMPILE_SIMD128
954+
#if _Py_HACL_CAN_COMPILE_VEC128
955955
case Blake2s_128:
956956
return PyLong_FromLong(Hacl_Hash_Blake2s_Simd128_info(self->blake2s_128_state).digest_length);
957957
#endif
@@ -982,15 +982,15 @@ py_blake2_clear(PyObject *op)
982982
// it. If an error occurs in the constructor, we should only free
983983
// states that were allocated (i.e. that are not NULL).
984984
switch (self->impl) {
985-
#if HACL_CAN_COMPILE_SIMD256
985+
#if _Py_HACL_CAN_COMPILE_VEC256
986986
case Blake2b_256:
987987
if (self->blake2b_256_state != NULL) {
988988
Hacl_Hash_Blake2b_Simd256_free(self->blake2b_256_state);
989989
self->blake2b_256_state = NULL;
990990
}
991991
break;
992992
#endif
993-
#if HACL_CAN_COMPILE_SIMD128
993+
#if _Py_HACL_CAN_COMPILE_VEC128
994994
case Blake2s_128:
995995
if (self->blake2s_128_state != NULL) {
996996
Hacl_Hash_Blake2s_Simd128_free(self->blake2s_128_state);

Modules/hmacmodule.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
#endif
3232

3333
#if defined(__APPLE__) && defined(__arm64__)
34-
# undef HACL_CAN_COMPILE_SIMD128
35-
# undef HACL_CAN_COMPILE_SIMD256
34+
# undef _Py_HACL_CAN_COMPILE_VEC128
35+
# undef _Py_HACL_CAN_COMPILE_VEC256
3636
#endif
3737

38-
// Small mismatch between the variable names Python defines as part of configure
39-
// at the ones HACL* expects to be set in order to enable those headers.
40-
#define HACL_CAN_COMPILE_VEC128 HACL_CAN_COMPILE_SIMD128
41-
#define HACL_CAN_COMPILE_VEC256 HACL_CAN_COMPILE_SIMD256
38+
// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable
39+
// the corresponding SIMD instructions so we need to "forward" the values
40+
// we just deduced above.
41+
#define HACL_CAN_COMPILE_VEC128 _Py_HACL_CAN_COMPILE_VEC128
42+
#define HACL_CAN_COMPILE_VEC256 _Py_HACL_CAN_COMPILE_VEC256
4243

4344
#include "_hacl/Hacl_HMAC.h"
4445
#include "_hacl/Hacl_Streaming_HMAC.h" // Hacl_Agile_Hash_* identifiers
@@ -464,15 +465,15 @@ narrow_hmac_hash_kind(hmacmodule_state *state, HMAC_Hash_Kind kind)
464465
{
465466
switch (kind) {
466467
case Py_hmac_kind_hmac_blake2s_32: {
467-
#if HACL_CAN_COMPILE_SIMD128
468+
#if _Py_HACL_CAN_COMPILE_VEC128
468469
if (state->can_run_simd128) {
469470
return Py_hmac_kind_hmac_vectorized_blake2s_32;
470471
}
471472
#endif
472473
return kind;
473474
}
474475
case Py_hmac_kind_hmac_blake2b_32: {
475-
#if HACL_CAN_COMPILE_SIMD256
476+
#if _Py_HACL_CAN_COMPILE_VEC256
476477
if (state->can_run_simd256) {
477478
return Py_hmac_kind_hmac_vectorized_blake2b_32;
478479
}
@@ -1761,7 +1762,7 @@ hmacmodule_init_cpu_features(hmacmodule_state *state)
17611762
#undef ECX_SSE3
17621763
#undef EBX_AVX2
17631764

1764-
#if HACL_CAN_COMPILE_SIMD128
1765+
#if _Py_HACL_CAN_COMPILE_VEC128
17651766
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
17661767
state->can_run_simd128 = sse && sse2 && sse3 && sse41 && sse42 && cmov;
17671768
#else
@@ -1771,7 +1772,7 @@ hmacmodule_init_cpu_features(hmacmodule_state *state)
17711772
state->can_run_simd128 = false;
17721773
#endif
17731774

1774-
#if HACL_CAN_COMPILE_SIMD256
1775+
#if _Py_HACL_CAN_COMPILE_VEC256
17751776
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
17761777
state->can_run_simd256 = state->can_run_simd128 && avx && avx2;
17771778
#else

PCbuild/pythoncore.vcxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,12 @@
419419
<ClCompile Include="..\Modules\_abc.c" />
420420
<ClCompile Include="..\Modules\_bisectmodule.c" />
421421
<ClCompile Include="..\Modules\blake2module.c">
422-
<PreprocessorDefinitions Condition="'$(Platform)' == 'x64'">HACL_CAN_COMPILE_SIMD128;%(PreprocessorDefinitions)</PreprocessorDefinitions>
423-
<PreprocessorDefinitions Condition="'$(Platform)' == 'x64'">HACL_CAN_COMPILE_SIMD256;%(PreprocessorDefinitions)</PreprocessorDefinitions>
422+
<PreprocessorDefinitions Condition="'$(Platform)' == 'x64'">
423+
_Py_HACL_CAN_COMPILE_VEC128;%(PreprocessorDefinitions)
424+
</PreprocessorDefinitions>
425+
<PreprocessorDefinitions Condition="'$(Platform)' == 'x64'">
426+
_Py_HACL_CAN_COMPILE_VEC256;%(PreprocessorDefinitions)
427+
</PreprocessorDefinitions>
424428
</ClCompile>
425429
<ClCompile Include="..\Modules\_codecsmodule.c" />
426430
<ClCompile Include="..\Modules\_collectionsmodule.c" />

configure

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8017,7 +8017,8 @@ then
80178017
AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[
80188018
[LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"]
80198019
8020-
AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations])
8020+
AC_DEFINE([_Py_HACL_CAN_COMPILE_VEC128], [1], [
8021+
HACL* library can compile SIMD128 implementations])
80218022
80228023
# macOS universal2 builds *support* the -msse etc flags because they're
80238024
# available on x86_64. However, performance of the HACL SIMD128 implementation
@@ -8048,7 +8049,8 @@ if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \
80488049
then
80498050
AX_CHECK_COMPILE_FLAG([-mavx2],[
80508051
[LIBHACL_SIMD256_FLAGS="-mavx2"]
8051-
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])
8052+
AC_DEFINE([_Py_HACL_CAN_COMPILE_VEC256], [1], [
8053+
HACL* library can compile SIMD256 implementations])
80528054
80538055
# macOS universal2 builds *support* the -mavx2 compiler flag because it's
80548056
# available on x86_64; but the HACL SIMD256 build then fails because the

pyconfig.h.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@
5050
/* Define if getpgrp() must be called as getpgrp(0). */
5151
#undef GETPGRP_HAVE_ARG
5252

53-
/* HACL* library can compile SIMD128 implementations */
54-
#undef HACL_CAN_COMPILE_SIMD128
55-
56-
/* HACL* library can compile SIMD256 implementations */
57-
#undef HACL_CAN_COMPILE_SIMD256
58-
5953
/* Define if you have the 'accept' function. */
6054
#undef HAVE_ACCEPT
6155

@@ -2026,6 +2020,12 @@
20262020
/* Defined if _Complex C type can be used with libffi. */
20272021
#undef _Py_FFI_SUPPORT_C_COMPLEX
20282022

2023+
/* HACL* library can compile SIMD128 implementations */
2024+
#undef _Py_HACL_CAN_COMPILE_VEC128
2025+
2026+
/* HACL* library can compile SIMD256 implementations */
2027+
#undef _Py_HACL_CAN_COMPILE_VEC256
2028+
20292029
/* Define to force use of thread-safe errno, h_errno, and other functions */
20302030
#undef _REENTRANT
20312031

0 commit comments

Comments
 (0)
0