8000 rename undocumented `HACL_CAN_COMPILE_SIMD{128,256}` macros · python/cpython@bc635b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc635b0

Browse files
committed
rename undocumented HACL_CAN_COMPILE_SIMD{128,256} macros
1 parent 396ca9a commit bc635b0

File tree

6 files changed

+62
-55
lines changed

6 files changed

+62
-55
lines changed

Modules/blake2module.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@
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

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

5959
#include "_hacl/Hacl_Hash_Blake2s.h"
6060
#include "_hacl/Hacl_Hash_Blake2b.h"
61-
#if HACL_CAN_COMPILE_SIMD128
61+
#if _Py_HACL_CAN_COMPILE_VEC128
6262
#include "_hacl/Hacl_Hash_Blake2s_Simd128.h"
6363
#endif
64-
#if HACL_CAN_COMPILE_SIMD256
64+
#if _Py_HACL_CAN_COMPILE_VEC256
6565
#include "_hacl/Hacl_Hash_Blake2b_Simd256.h"
6666
#endif
6767

@@ -88,7 +88,7 @@ blake2_get_state(PyObject *module)
8888
return (Blake2State *)state;
8989
}
9090

91-
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
91+
#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256)
9292
static inline Blake2State *
9393
blake2_get_state_from_type(PyTypeObject *module)
9494
{
@@ -181,7 +181,7 @@ blake2module_init_cpu_features(Blake2State *state)
181181
#undef ECX_SSE3
182182
#undef EBX_AVX2
183183

184-
#if HACL_CAN_COMPILE_SIMD128
184+
#if _Py_HACL_CAN_COMPILE_VEC128
185185
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
186186
state->can_run_simd128 = sse && sse2 && sse3 && sse41 && sse42 && cmov;
187187
#else
@@ -191,7 +191,7 @@ blake2module_init_cpu_features(Blake2State *state)
191191
state->can_run_simd128 = false;
192192
#endif
193193

194-
#if HACL_CAN_COMPILE_SIMD256
194+
#if _Py_HACL_CAN_COMPILE_VEC256
195195
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
196196
state->can_run_simd256 = state->can_run_simd128 && avx && avx2;
197197
#else
@@ -332,18 +332,18 @@ is_blake2s(blake2_impl impl)
332332
static inline blake2_impl
333333
type_to_impl(PyTypeObject *type)
334334
{
335-
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
335+
#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256)
336336
Blake2State *st = blake2_get_state_from_type(type);
337337
#endif
338338
if (!strcmp(type->tp_name, blake2b_type_spec.name)) {
339-
#if HACL_CAN_COMPILE_SIMD256
339+
#if _Py_HACL_CAN_COMPILE_VEC256
340340
return st->can_run_simd256 ? Blake2b_256 : Blake2b;
341341
#else
342342
return Blake2b;
343343
#endif
344344
}
345345
else if (!strcmp(type->tp_name, blake2s_type_spec.name)) {
346-
#if HACL_CAN_COMPILE_SIMD128
346+
#if _Py_HACL_CAN_COMPILE_VEC128
347347
return st->can_run_simd128 ? Blake2s_128 : Blake2s;
348348
#else
349349
return Blake2s;
@@ -357,10 +357,10 @@ typedef struct {
357357
union {
358358
Hacl_Hash_Blake2s_state_t *blake2s_state;
359359
Hacl_Hash_Blake2b_state_t *blake2b_state;
360-
#if HACL_CAN_COMPILE_SIMD128
360+
#if _Py_HACL_CAN_COMPILE_VEC128
361361
Hacl_Hash_Blake2s_Simd128_state_t *blake2s_128_state;
362362
#endif
363-
#if HACL_CAN_COMPILE_SIMD256
363+
#if _Py_HACL_CAN_COMPILE_VEC256
364364
Hacl_Hash_Blake2b_Simd256_state_t *blake2b_256_state;
365365
#endif
366366
};
@@ -429,13 +429,13 @@ blake2_update_unlocked(Blake2Object *self, uint8_t *buf, Py_ssize_t len)
429429
switch (self->impl) {
430430
// blake2b_256_state and blake2s_128_state must be if'd since
431431
// otherwise this results in an unresolved symbol at link-time.
432-
#if HACL_CAN_COMPILE_SIMD256
432+
#if _Py_HACL_CAN_COMPILE_VEC256
433433
case Blake2b_256:
434434
HACL_UPDATE(Hacl_Hash_Blake2b_Simd256_update,
435435
self->blake2b_256_state, buf, len);
436436
return;
437437
#endif
438-
#if HACL_CAN_COMPILE_SIMD128
438+
#if _Py_HACL_CAN_COMPILE_VEC128
439439
case Blake2s_128:
440440
HACL_UPDATE(Hacl_Hash_Blake2s_Simd128_update,
441441
self->blake2s_128_state, buf, len);
@@ -555,12 +555,12 @@ py_blake2_new(PyTypeObject *type, PyObject *data, int digest_size,
555555
// Ensure that the states are NULL-initialized in case of an error.
556556
// See: py_blake2_clear() for more details.
557557
switch (self->impl) {
558-
#if HACL_CAN_COMPILE_SIMD256
558+
#if _Py_HACL_CAN_COMPILE_VEC256
559559
case Blake2b_256:
560560
self->blake2b_256_state = NULL;
561561
break;
562562
#endif
563-
#if HACL_CAN_COMPILE_SIMD128
563+
#if _Py_HACL_CAN_COMPILE_VEC128
564564
case Blake2s_128:
565565
self->blake2s_128_state = NULL;
566566
break;
@@ -623,12 +623,12 @@ py_blake2_new(PyTypeObject *type, PyObject *data, int digest_size,
623623
} while (0)
624624

625625
switch (self->impl) {
626-
#if HACL_CAN_COMPILE_SIMD256
626+
#if _Py_HACL_CAN_COMPILE_VEC256
627627
case Blake2b_256:
628628
BLAKE2_MALLOC(Blake2b_Simd256, self->blake2b_256_state);
629629
break;
630630
#endif
631-
#if HACL_CAN_COMPILE_SIMD128
631+
#if _Py_HACL_CAN_COMPILE_VEC128
632632
case Blake2s_128:
633633
BLAKE2_MALLOC(Blake2s_Simd128, self->blake2s_128_state);
634634
break;
@@ -756,12 +756,12 @@ blake2_blake2b_copy_unlocked(Blake2Object *self, Blake2Object *cpy)
756756
} while (0)
757757

758758
switch (self->impl) {
759-
#if HACL_CAN_COMPILE_SIMD256
759+
#if _Py_HACL_CAN_COMPILE_VEC256
760760
case Blake2b_256:
761761
BLAKE2_COPY(Blake2b_Simd256, blake2b_256_state);
762762
break;
763763
#endif
764-
#if HACL_CAN_COMPILE_SIMD128
764+
#if _Py_HACL_CAN_COMPILE_VEC128
765765
case Blake2s_128:
766766
BLAKE2_COPY(Blake2s_Simd128, blake2s_128_state);
767767
break;
@@ -838,12 +838,12 @@ static uint8_t
838838
blake2_blake2b_compute_digest(Blake2Object *self, uint8_t *digest)
839839
{
840840
switch (self->impl) {
841-
#if HACL_CAN_COMPILE_SIMD256
841+
#if _Py_HACL_CAN_COMPILE_VEC256
842842
case Blake2b_256:
843843
return Hacl_Hash_Blake2b_Simd256_digest(
844844
self->blake2b_256_state, digest);
845845
#endif
846-
#if HACL_CAN_COMPILE_SIMD128
846+
#if _Py_HACL_CAN_COMPILE_VEC128
847847
case Blake2s_128:
848848
return Hacl_Hash_Blake2s_Simd128_digest(
849849
self->blake2s_128_state, digest);
@@ -921,11 +921,11 @@ static Hacl_Hash_Blake2b_index
921921
hacl_get_blake2_info(Blake2Object *self)
922922
{
923923
switch (self->impl) {
924-
#if HACL_CAN_COMPILE_SIMD256
924+
#if _Py_HACL_CAN_COMPILE_VEC256
925925
case Blake2b_256:
926926
return Hacl_Hash_Blake2b_Simd256_info(self->blake2b_256_state);
927927
#endif
928-
#if HACL_CAN_COMPILE_SIMD128
928+
#if _Py_HACL_CAN_COMPILE_VEC128
929929
case Blake2s_128:
930930
return Hacl_Hash_Blake2s_Simd128_info(self->blake2s_128_state);
931931
#endif
@@ -973,12 +973,12 @@ py_blake2_clear(PyObject *op)
973973
} while (0)
974974

975975
switch (self->impl) {
976-
#if HACL_CAN_COMPILE_SIMD256
976+
#if _Py_HACL_CAN_COMPILE_VEC256
977977
case Blake2b_256:
978978
BLAKE2_FREE(Blake2b_Simd256, self->blake2b_256_state);
979979
break;
980980
#endif
981-
#if HACL_CAN_COMPILE_SIMD128
981+
#if _Py_HACL_CAN_COMPILE_VEC128
982982
case Blake2s_128:
983983
BLAKE2_FREE(Blake2s_Simd128, self->blake2s_128_state);
984984
break;

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
@@ -361,15 +362,15 @@ narrow_hmac_hash_kind(hmacmodule_state *state, HMAC_Hash_Kind kind)
361362
{
362363
switch (kind) {
363364
case Py_hmac_kind_hmac_blake2s_32: {
364-
#if HACL_CAN_COMPILE_SIMD128
365+
#if _Py_HACL_CAN_COMPILE_VEC128
365366
if (state->can_run_simd128) {
366367
return Py_hmac_kind_hmac_vectorized_blake2s_32;
367368
}
368369
#endif
369370
return kind;
370371
}
371372
case Py_hmac_kind_hmac_blake2b_32: {
372-
#if HACL_CAN_COMPILE_SIMD256
373+
#if _Py_HACL_CAN_COMPILE_VEC256
373374
if (state->can_run_simd256) {
374375
return Py_hmac_kind_hmac_vectorized_blake2b_32;
375376
}
@@ -1601,7 +1602,7 @@ hmacmodule_init_cpu_features(hmacmodule_state *state)
16011602
#undef ECX_SSE3
16021603
#undef EBX_AVX2
16031604

1604-
#if HACL_CAN_COMPILE_SIMD128
1605+
#if _Py_HACL_CAN_COMPILE_VEC128
16051606
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
16061607
state->can_run_simd128 = sse && sse2 && sse3 && sse41 && sse42 && cmov;
16071608
#else
@@ -1611,7 +1612,7 @@ hmacmodule_init_cpu_features(hmacmodule_state *state)
16111612
state->can_run_simd128 = false;
16121613
#endif
16131614

1614-
#if HACL_CAN_COMPILE_SIMD256
1615+
#if _Py_HACL_CAN_COMPILE_VEC256
16151616
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
16161617
state->can_run_simd256 = state->can_run_simd128 && avx && avx2;
16171618
#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
@@ -8028,7 +8028,8 @@ then
80288028
AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[
80298029
[LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"]
80308030
8031-
AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations])
8031+
AC_DEFINE([_Py_HACL_CAN_COMPILE_VEC128], [1], [
8032+
HACL* library can compile SIMD128 implementations])
80328033
80338034
# macOS universal2 builds *support* the -msse etc flags because they're
80348035
# available on x86_64. However, performance of the HACL SIMD128 implementation
@@ -8059,7 +8060,8 @@ if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \
80598060
then
80608061
AX_CHECK_COMPILE_FLAG([-mavx2],[
80618062
[LIBHACL_SIMD256_FLAGS="-mavx2"]
8062-
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])
8063+
AC_DEFINE([_Py_HACL_CAN_COMPILE_VEC256], [1], [
8064+
HACL* library can compile SIMD256 implementations])
80638065
80648066
# macOS universal2 builds *support* the -mavx2 compiler flag because it's
80658067
# 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
/* Maximum length in bytes of a thread name */
20272021
#undef _PYTHREAD_NAME_MAXLEN
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