Skip to content
Open
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
17 changes: 17 additions & 0 deletions blake3_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

#include "blake3_impl.h"

/* Force disable x86-64 assembly paths if not building for x86-64 */
#if !defined(__x86_64__) && !defined(_M_X64)
#ifndef BLAKE3_NO_SSE2
#define BLAKE3_NO_SSE2 1
#endif
#ifndef BLAKE3_NO_SSE41
#define BLAKE3_NO_SSE41 1
#endif
#ifndef BLAKE3_NO_AVX2
#define BLAKE3_NO_AVX2 1
#endif
#ifndef BLAKE3_NO_AVX512
#define BLAKE3_NO_AVX512 1
#endif
#undef IS_X86
#endif

#if defined(IS_X86)
#if defined(_MSC_VER)
#include <intrin.h>
Expand Down
18 changes: 16 additions & 2 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,19 @@ PHP_ARG_ENABLE(blake3,
[--enable-blake3 Enable BLAKE3 Extension])

if test "$PHP_BLAKE3" != "no"; then
PHP_NEW_EXTENSION(blake3, php_blake3.c blake3.c blake3_dispatch.c blake3_portable.c blake3_sse2_x86-64_unix.S blake3_sse41_x86-64_unix.S blake3_avx2_x86-64_unix.S blake3_avx512_x86-64_unix.S, $ext_shared)
fi
dnl Detect target CPU architecture
AC_MSG_CHECKING([for blake3 architecture optimization])
case "$host_cpu" in
x86_64|amd64)
AC_MSG_RESULT([x86_64 (enabling SSE/AVX assembly)])
BLAKE3_ASM_SOURCES="blake3_sse2_x86-64_unix.S blake3_sse41_x86-64_unix.S blake3_avx2_x86-64_unix.S blake3_avx512_x86-64_unix.S"
;;
*)
AC_MSG_RESULT([$host_cpu (using portable C implementation)])
BLAKE3_ASM_SOURCES=""
;;
esac

dnl Pass detected assembly sources to extension build
PHP_NEW_EXTENSION(blake3, php_blake3.c blake3.c blake3_dispatch.c blake3_portable.c $BLAKE3_ASM_SOURCES, $ext_shared)
fi