mirror of https://github.com/python/cpython
gh-123189: [`Modules/blake2module.c`]: Move function definitions and their usage under the macros (#123190)
This commit is contained in:
parent
f8a736b8e1
commit
8aaf7525ab
|
@ -104,15 +104,19 @@ void detect_cpu_features(cpu_flags *flags) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HACL_CAN_COMPILE_SIMD128
|
||||||
static inline bool has_simd128(cpu_flags *flags) {
|
static inline bool has_simd128(cpu_flags *flags) {
|
||||||
// For now this is Intel-only, could conceivably be #ifdef'd to something
|
// For now this is Intel-only, could conceivably be #ifdef'd to something
|
||||||
// else.
|
// else.
|
||||||
return flags->sse && flags->sse2 && flags->sse3 && flags->sse41 && flags->sse42 && flags->cmov;
|
return flags->sse && flags->sse2 && flags->sse3 && flags->sse41 && flags->sse42 && flags->cmov;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HACL_CAN_COMPILE_SIMD256
|
||||||
static inline bool has_simd256(cpu_flags *flags) {
|
static inline bool has_simd256(cpu_flags *flags) {
|
||||||
return flags->avx && flags->avx2;
|
return flags->avx && flags->avx2;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Small mismatch between the variable names Python defines as part of configure
|
// Small mismatch between the variable names Python defines as part of configure
|
||||||
// at the ones HACL* expects to be set in order to enable those headers.
|
// at the ones HACL* expects to be set in order to enable those headers.
|
||||||
|
@ -151,6 +155,7 @@ blake2_get_state(PyObject *module)
|
||||||
return (Blake2State *)state;
|
return (Blake2State *)state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
|
||||||
static inline Blake2State*
|
static inline Blake2State*
|
||||||
blake2_get_state_from_type(PyTypeObject *module)
|
blake2_get_state_from_type(PyTypeObject *module)
|
||||||
{
|
{
|
||||||
|
@ -158,6 +163,7 @@ blake2_get_state_from_type(PyTypeObject *module)
|
||||||
assert(state != NULL);
|
assert(state != NULL);
|
||||||
return (Blake2State *)state;
|
return (Blake2State *)state;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static struct PyMethodDef blake2mod_functions[] = {
|
static struct PyMethodDef blake2mod_functions[] = {
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
|
@ -311,7 +317,9 @@ static inline bool is_blake2s(blake2_impl impl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline blake2_impl type_to_impl(PyTypeObject *type) {
|
static inline blake2_impl type_to_impl(PyTypeObject *type) {
|
||||||
|
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
|
||||||
Blake2State* st = blake2_get_state_from_type(type);
|
Blake2State* st = blake2_get_state_from_type(type);
|
||||||
|
#endif
|
||||||
if (!strcmp(type->tp_name, blake2b_type_spec.name)) {
|
if (!strcmp(type->tp_name, blake2b_type_spec.name)) {
|
||||||
#ifdef HACL_CAN_COMPILE_SIMD256
|
#ifdef HACL_CAN_COMPILE_SIMD256
|
||||||
if (has_simd256(&st->flags))
|
if (has_simd256(&st->flags))
|
||||||
|
|
Loading…
Reference in New Issue