43
43
44
44
// SIMD256 can't be compiled on macOS ARM64, and performance of SIMD128 isn't
45
45
// 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.
49
48
#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
52
51
#endif
53
52
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
58
58
59
59
#include "_hacl/Hacl_Hash_Blake2s.h"
60
60
#include "_hacl/Hacl_Hash_Blake2b.h"
61
- #if HACL_CAN_COMPILE_SIMD128
61
+ #if _Py_HACL_CAN_COMPILE_VEC128
62
62
#include "_hacl/Hacl_Hash_Blake2s_Simd128.h"
63
63
#endif
64
- #if HACL_CAN_COMPILE_SIMD256
64
+ #if _Py_HACL_CAN_COMPILE_VEC256
65
65
#include "_hacl/Hacl_Hash_Blake2b_Simd256.h"
66
66
#endif
67
67
@@ -88,7 +88,7 @@ blake2_get_state(PyObject *module)
88
88
return (Blake2State * )state ;
89
89
}
90
90
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 )
92
92
static inline Blake2State *
93
93
blake2_get_state_from_type (PyTypeObject * module )
94
94
{
@@ -181,7 +181,7 @@ blake2module_init_cpu_features(Blake2State *state)
181
181
#undef ECX_SSE3
182
182
#undef EBX_AVX2
183
183
184
- #if HACL_CAN_COMPILE_SIMD128
184
+ #if _Py_HACL_CAN_COMPILE_VEC128
185
185
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
186
186
state -> can_run_simd128 = sse && sse2 && sse3 && sse41 && sse42 && cmov ;
187
187
#else
@@ -191,7 +191,7 @@ blake2module_init_cpu_features(Blake2State *state)
191
191
state -> can_run_simd128 = false;
192
192
#endif
193
193
194
- #if HACL_CAN_COMPILE_SIMD256
194
+ #if _Py_HACL_CAN_COMPILE_VEC256
195
195
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
196
196
state -> can_run_simd256 = state -> can_run_simd128 && avx && avx2 ;
197
197
#else
@@ -332,18 +332,18 @@ is_blake2s(blake2_impl impl)
332
332
static inline blake2_impl
333
333
type_to_impl (PyTypeObject * type )
334
334
{
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 )
336
336
Blake2State * st = blake2_get_state_from_type (type );
337
337
#endif
338
338
if (!strcmp (type -> tp_name , blake2b_type_spec .name )) {
339
- #if HACL_CAN_COMPILE_SIMD256
339
+ #if _Py_HACL_CAN_COMPILE_VEC256
340
340
return st -> can_run_simd256 ? Blake2b_256 : Blake2b ;
341
341
#else
342
342
return Blake2b ;
343
343
#endif
344
344
}
345
345
else if (!strcmp (type -> tp_name , blake2s_type_spec .name )) {
346
- #if HACL_CAN_COMPILE_SIMD128
346
+ #if _Py_HACL_CAN_COMPILE_VEC128
347
347
return st -> can_run_simd128 ? Blake2s_128 : Blake2s ;
348
348
#else
349
349
return Blake2s ;
@@ -357,10 +357,10 @@ typedef struct {
357
357
union {
358
358
Hacl_Hash_Blake2s_state_t * blake2s_state ;
359
359
Hacl_Hash_Blake2b_state_t * blake2b_state ;
360
- #if HACL_CAN_COMPILE_SIMD128
360
+ #if _Py_HACL_CAN_COMPILE_VEC128
361
361
Hacl_Hash_Blake2s_Simd128_state_t * blake2s_128_state ;
362
362
#endif
363
- #if HACL_CAN_COMPILE_SIMD256
363
+ #if _Py_HACL_CAN_COMPILE_VEC256
364
364
Hacl_Hash_Blake2b_Simd256_state_t * blake2b_256_state ;
365
365
#endif
366
366
} ;
@@ -429,13 +429,13 @@ blake2_update_unlocked(Blake2Object *self, uint8_t *buf, Py_ssize_t len)
429
429
switch (self -> impl ) {
430
430
// blake2b_256_state and blake2s_128_state must be if'd since
431
431
// otherwise this results in an unresolved symbol at link-time.
432
- #if HACL_CAN_COMPILE_SIMD256
432
+ #if _Py_HACL_CAN_COMPILE_VEC256
433
433
case Blake2b_256 :
434
434
HACL_UPDATE (Hacl_Hash_Blake2b_Simd256_update ,
435
435
self -> blake2b_256_state , buf , len );
436
436
return ;
437
437
#endif
438
- #if HACL_CAN_COMPILE_SIMD128
438
+ #if _Py_HACL_CAN_COMPILE_VEC128
439
439
case Blake2s_128 :
440
440
HACL_UPDATE (Hacl_Hash_Blake2s_Simd128_update ,
441
441
self -> blake2s_128_state , buf , len );
@@ -555,12 +555,12 @@ py_blake2_new(PyTypeObject *type, PyObject *data, int digest_size,
555
555
// Ensure that the states are NULL-initialized in case of an error.
556
556
// See: py_blake2_clear() for more details.
557
557
switch (self -> impl ) {
558
- #if HACL_CAN_COMPILE_SIMD256
558
+ #if _Py_HACL_CAN_COMPILE_VEC256
559
559
case Blake2b_256 :
560
560
self -> blake2b_256_state = NULL ;
561
561
break ;
562
562
#endif
563
- #if HACL_CAN_COMPILE_SIMD128
563
+ #if _Py_HACL_CAN_COMPILE_VEC128
564
564
case Blake2s_128 :
565
565
self -> blake2s_128_state = NULL ;
566
566
break ;
@@ -623,12 +623,12 @@ py_blake2_new(PyTypeObject *type, PyObject *data, int digest_size,
623
623
} while (0)
624
624
625
625
switch (self -> impl ) {
626
- #if HACL_CAN_COMPILE_SIMD256
626
+ #if _Py_HACL_CAN_COMPILE_VEC256
627
627
case Blake2b_256 :
628
628
BLAKE2_MALLOC (Blake2b_Simd256 , self -> blake2b_256_state );
629
629
break ;
630
630
#endif
631
- #if HACL_CAN_COMPILE_SIMD128
631
+ #if _Py_HACL_CAN_COMPILE_VEC128
632
632
case Blake2s_128 :
633
633
BLAKE2_MALLOC (Blake2s_Simd128 , self -> blake2s_128_state );
634
634
break ;
@@ -756,12 +756,12 @@ blake2_blake2b_copy_unlocked(Blake2Object *self, Blake2Object *cpy)
756
756
} while (0)
757
757
758
758
switch (self -> impl ) {
759
- #if HACL_CAN_COMPILE_SIMD256
759
+ #if _Py_HACL_CAN_COMPILE_VEC256
760
760
case Blake2b_256 :
761
761
BLAKE2_COPY (Blake2b_Simd256 , blake2b_256_state );
762
762
break ;
763
763
#endif
764
- #if HACL_CAN_COMPILE_SIMD128
764
+ #if _Py_HACL_CAN_COMPILE_VEC128
765
765
case Blake2s_128 :
766
766
BLAKE2_COPY (Blake2s_Simd128 , blake2s_128_state );
767
767
break ;
@@ -838,12 +838,12 @@ static uint8_t
838
838
blake2_blake2b_compute_digest (Blake2Object * self , uint8_t * digest )
839
839
{
840
840
switch (self -> impl ) {
841
- #if HACL_CAN_COMPILE_SIMD256
841
+ #if _Py_HACL_CAN_COMPILE_VEC256
842
842
case Blake2b_256 :
843
843
return Hacl_Hash_Blake2b_Simd256_digest (
844
844
self -> blake2b_256_state , digest );
845
845
#endif
846
- #if HACL_CAN_COMPILE_SIMD128
846
+ #if _Py_HACL_CAN_COMPILE_VEC128
847
847
case Blake2s_128 :
848
848
return Hacl_Hash_Blake2s_Simd128_digest (
849
849
self -> blake2s_128_state , digest );
@@ -921,11 +921,11 @@ static Hacl_Hash_Blake2b_index
921
921
hacl_get_blake2_info (Blake2Object * self )
922
922
{
923
923
switch (self -> impl ) {
924
- #if HACL_CAN_COMPILE_SIMD256
924
+ #if _Py_HACL_CAN_COMPILE_VEC256
925
925
case Blake2b_256 :
926
926
return Hacl_Hash_Blake2b_Simd256_info (self -> blake2b_256_state );
927
927
#endif
928
- #if HACL_CAN_COMPILE_SIMD128
928
+ #if _Py_HACL_CAN_COMPILE_VEC128
929
929
case Blake2s_128 :
930
930
return Hacl_Hash_Blake2s_Simd128_info (self -> blake2s_128_state );
931
931
#endif
@@ -973,12 +973,12 @@ py_blake2_clear(PyObject *op)
973
973
} while (0)
974
974
975
975
switch (self -> impl ) {
976
- #if HACL_CAN_COMPILE_SIMD256
976
+ #if _Py_HACL_CAN_COMPILE_VEC256
977
977
case Blake2b_256 :
978
978
BLAKE2_FREE (Blake2b_Simd256 , self -> blake2b_256_state );
979
979
break ;
980
980
#endif
981
- #if HACL_CAN_COMPILE_SIMD128
981
+ #if _Py_HACL_CAN_COMPILE_VEC128
982
982
case Blake2s_128 :
983
983
BLAKE2_FREE (Blake2s_Simd128 , self -> blake2s_128_state );
984
984
break ;
0 commit comments