Skip to content

Commit 0849a67

Browse files
Scottcjnclaude
andcommitted
Fix AltiVec bool keyword conflict with wrapper header
GCC's AltiVec extension makes 'bool' a keyword meaning '__vector __bool int' when compiling with -maltivec. This conflicts with C99/C11 stdbool.h where bool means _Bool, breaking all scalar bool usage in HACL* BLAKE2 SIMD128 code. Note: the simpler -Dbool=_Bool approach does not work because altivec.h re-enables the keyword after the macro is defined. The fix is a small wrapper header (ppc_altivec_fix.h) that: 1. Includes altivec.h (which activates the bool keyword) 2. Immediately #undefs bool/true/false 3. Redefines them as C99 _Bool/1/0 This header is force-included (-include) via LIBHACL_SIMD128_FLAGS before HACL source files. The __ALTIVEC__ guard ensures it only activates on PowerPC. Vector boolean types remain available via the explicit __vector __bool syntax. This is a known GCC/AltiVec interaction; the same approach is used by FFmpeg and other projects that mix AltiVec intrinsics with C99. Verified: Hacl_Hash_Blake2s_Simd128.c compiles cleanly on POWER8 (GCC 10.5, -maltivec -mvsx -std=c11) producing a valid ELF64 object. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 40e72eb commit 0849a67

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

Modules/_hacl/ppc_altivec_fix.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* PowerPC AltiVec bool keyword fix for HACL* BLAKE2 SIMD128.
3+
*
4+
* When GCC compiles with -maltivec, it makes "bool" a keyword meaning
5+
* "__vector __bool int" (a 128-bit vector type). This conflicts with
6+
* C99/C11 stdbool.h where bool means _Bool (a scalar type).
7+
*
8+
* The -Dbool=_Bool workaround does NOT work because altivec.h re-enables
9+
* the keyword after the macro is defined. Instead, this header includes
10+
* altivec.h first, then undefines the bool/true/false keywords and
11+
* restores the C99 scalar definitions. Vector boolean types remain
12+
* accessible via the explicit __vector __bool syntax.
13+
*
14+
* This header is force-included (-include) before HACL SIMD128 sources
15+
* via LIBHACL_SIMD128_FLAGS in configure.ac.
16+
*/
17+
#ifndef PPC_ALTIVEC_BOOL_FIX_H
18+
#define PPC_ALTIVEC_BOOL_FIX_H
19+
20+
#if defined(__ALTIVEC__) || defined(__VSX__)
21+
#include <altivec.h>
22+
23+
#undef bool
24+
#undef true
25+
#undef false
26+
27+
#define bool _Bool
28+
#define true 1
29+
#define false 0
30+
#endif /* __ALTIVEC__ || __VSX__ */
31+
32+
#endif /* PPC_ALTIVEC_BOOL_FIX_H */

configure

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8133,7 +8133,7 @@ then
81338133
dnl x86 SSE not available; check for PowerPC AltiVec/VSX (Power8+).
81348134
dnl HACL* libintvector.h has a complete vec128 implementation for __powerpc64__.
81358135
AX_CHECK_COMPILE_FLAG([-maltivec -mvsx],[
8136-
[LIBHACL_SIMD128_FLAGS="-maltivec -mvsx -flax-vector-conversions -Wno-return-type"]
8136+
[LIBHACL_SIMD128_FLAGS="-maltivec -mvsx -flax-vector-conversions -Wno-return-type -include \$(srcdir)/Modules/_hacl/ppc_altivec_fix.h"]
81378137
81388138
AC_DEFINE([_Py_HACL_CAN_COMPILE_VEC128], [1], [
81398139
HACL* library can compile SIMD128 implementations])

0 commit comments

Comments
 (0)