Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enable HACL* BLAKE2s SIMD128 vectorization on PowerPC64 (POWER8+) using
AltiVec/VSX instructions. The HACL* library already contained a complete
PowerPC64 vec128 implementation but CPython's configure never enabled it.
32 changes: 32 additions & 0 deletions Modules/_hacl/ppc_altivec_fix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* PowerPC AltiVec bool keyword fix for HACL* BLAKE2 SIMD128.
*
* When GCC compiles with -maltivec, it makes "bool" a keyword meaning
* "__vector __bool int" (a 128-bit vector type). This conflicts with
* C99/C11 stdbool.h where bool means _Bool (a scalar type).
*
* The -Dbool=_Bool workaround does NOT work because altivec.h re-enables
* the keyword after the macro is defined. Instead, this header includes
* altivec.h first, then undefines the bool/true/false keywords and
* restores the C99 scalar definitions. Vector boolean types remain
* accessible via the explicit __vector __bool syntax.
*
* This header is force-included (-include) before HACL SIMD128 sources
* via LIBHACL_SIMD128_FLAGS in configure.ac.
*/
#ifndef PPC_ALTIVEC_BOOL_FIX_H
#define PPC_ALTIVEC_BOOL_FIX_H

#if defined(__ALTIVEC__) || defined(__VSX__)
#include <altivec.h>

#undef bool
#undef true
#undef false

#define bool _Bool
#define true 1
#define false 0
#endif /* __ALTIVEC__ || __VSX__ */

#endif /* PPC_ALTIVEC_BOOL_FIX_H */
54 changes: 54 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -8110,7 +8110,7 @@ fi
if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \
{ test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; }
then
dnl This can be extended here to detect e.g. Power8, which HACL* should also support.
dnl Check for x86 SSE support (SIMD128)
AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[
[LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"]

Expand All @@ -8129,7 +8129,20 @@ then
AC_MSG_RESULT([standard])
fi

], [], [-Werror])
], [
dnl x86 SSE not available; check for PowerPC AltiVec/VSX (Power8+).
dnl HACL* libintvector.h has a complete vec128 implementation for __powerpc64__.
AX_CHECK_COMPILE_FLAG([-maltivec -mvsx],[
[LIBHACL_SIMD128_FLAGS="-maltivec -mvsx -flax-vector-conversions -Wno-return-type -include \$(srcdir)/Modules/_hacl/ppc_altivec_fix.h"]

AC_DEFINE([_Py_HACL_CAN_COMPILE_VEC128], [1], [
HACL* library can compile SIMD128 implementations])

[LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"]
AC_MSG_CHECKING([for HACL* SIMD128 implementation])
AC_MSG_RESULT([PowerPC AltiVec/VSX])
], [], [-Werror])
], [-Werror])
fi
AC_SUBST([LIBHACL_SIMD128_FLAGS])
AC_SUBST([LIBHACL_BLAKE2_SIMD128_OBJS])
Expand Down
Loading