Skip to content

gh-123748: Add conditional compilation rules to allow HACL SIMD256 to be compiled on universal #123989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,9 @@ Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Bla
Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c $(LIBHACL_BLAKE2_HEADERS)
$(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD256_FLAGS) -DHACL_CAN_COMPILE_VEC256 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c

Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c $(LIBHACL_BLAKE2_HEADERS)
$(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD256_FLAGS) -DHACL_CAN_COMPILE_VEC256 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c

Modules/_hacl/Lib_Memzero0.o: $(srcdir)/Modules/_hacl/Lib_Memzero0.c $(LIBHACL_BLAKE2_HEADERS)
$(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Lib_Memzero0.c

Expand Down
19 changes: 19 additions & 0 deletions Misc/sbom.spdx.json

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

15 changes: 15 additions & 0 deletions Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file isn't part of a standard HACL source tree.
//
// It is required for compatibility with universal2 macOS builds. The code in
// Hacl_Hash_Blake2b_Simd256.c *will* compile on macOS x86_64, but *won't*
// compile on ARM64. However, because universal2 builds are compiled in a
// single pass, autoconf detects that the required compiler features *are*
// available, and tries to compile this file, which then fails because of the
// lack of support on ARM64.
//
// To compensate for this, autoconf will include *this* file instead of
// Hacl_Hash_Blake2b_Simd256.c when compiling for universal. This allows the
// underlying source code of HACL to remain unmodified.
#if !(defined(__APPLE__) && defined(__arm64__))
#include "Hacl_Hash_Blake2b_Simd256.c"
#endif
8 changes: 8 additions & 0 deletions Modules/blake2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@

#include <stdbool.h>

// SIMD256 can't be compiled on macOS ARM64; but when compiling a universal2
// binary, autoconf will set HACL_CAN_COMPILE_SIMD256 because it *can* be
// compiled on x86_64. If we're on macOS ARM64, disable the
// HACL_CAN_COMPILE_SIMD256 preprocessor symbol.
#if defined(__APPLE__) && defined(__arm64__)
# undef HACL_CAN_COMPILE_SIMD256
#endif

// ECX
#define ECX_SSE3 (1 << 0)
#define ECX_SSSE3 (1 << 9)
Expand Down
17 changes: 16 additions & 1 deletion configure

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

14 changes: 13 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7814,8 +7814,20 @@ AC_SUBST([LIBHACL_SIMD128_OBJS])

AX_CHECK_COMPILE_FLAG([-mavx2],[
[LIBHACL_SIMD256_FLAGS="-mavx2"]
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"]
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])

# macOS universal2 builds *support* the -mavx2 compiler flag because it's
# available on x86_64; but the HACL SIMD256 build then fails because the
# implementation requires symbols that aren't available on ARM64. Use a
# wrapped implementation if we're building for universal2.
AC_MSG_CHECKING([for HACL* SIMD256 implementation])
if test "$UNIVERSAL_ARCHS" == "universal2"; then
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"]
AC_MSG_RESULT([universal2])
else
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"]
AC_MSG_RESULT([standard])
fi
], [], [-Werror])

AC_SUBST([LIBHACL_SIMD256_FLAGS])
Expand Down
Loading