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 )
9292static inline Blake2State *
9393blake2_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)
332332static inline blake2_impl
333333type_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 ;
@@ -840,12 +840,12 @@ static uint8_t
840840blake2_blake2b_compute_digest (Blake2Object * self , uint8_t * digest )
841841{
842842 switch (self -> impl ) {
843- #if HACL_CAN_COMPILE_SIMD256
843+ #if _Py_HACL_CAN_COMPILE_VEC256
844844 case Blake2b_256 :
845845 return Hacl_Hash_Blake2b_Simd256_digest (
846846 self -> blake2b_256_state , digest );
847847#endif
848- #if HACL_CAN_COMPILE_SIMD128
848+ #if _Py_HACL_CAN_COMPILE_VEC128
849849 case Blake2s_128 :
850850 return Hacl_Hash_Blake2s_Simd128_digest (
851851 self -> blake2s_128_state , digest );
@@ -923,11 +923,11 @@ static Hacl_Hash_Blake2b_index
923923hacl_get_blake2_info (Blake2Object * self )
924924{
925925 switch (self -> impl ) {
926- #if HACL_CAN_COMPILE_SIMD256
926+ #if _Py_HACL_CAN_COMPILE_VEC256
927927 case Blake2b_256 :
928928 return Hacl_Hash_Blake2b_Simd256_info (self -> blake2b_256_state );
929929#endif
930- #if HACL_CAN_COMPILE_SIMD128
930+ #if _Py_HACL_CAN_COMPILE_VEC128
931931 case Blake2s_128 :
932932 return Hacl_Hash_Blake2s_Simd128_info (self -> blake2s_128_state );
933933#endif
@@ -975,12 +975,12 @@ py_blake2_clear(PyObject *op)
975975 } while (0)
976976
977977 switch (self -> impl ) {
978- #if HACL_CAN_COMPILE_SIMD256
978+ #if _Py_HACL_CAN_COMPILE_VEC256
979979 case Blake2b_256 :
980980 BLAKE2_FREE (Blake2b_Simd256 , self -> blake2b_256_state );
981981 break ;
982982#endif
983- #if HACL_CAN_COMPILE_SIMD128
983+ #if _Py_HACL_CAN_COMPILE_VEC128
984984 case Blake2s_128 :
985985 BLAKE2_FREE (Blake2s_Simd128 , self -> blake2s_128_state );
986986 break ;
0 commit comments