Skip to content

Commit b7fab6f

Browse files
authored
Allow cross-compilation with SIMD (x86_84) (#104)
Replace runtime SIMD check with a compile-only test in case of cross-compilation. You can still use '--enable-simd=no' to build x86_64 code without SIMD instructions.
1 parent 9fc7dea commit b7fab6f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

configure.ac

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,7 @@ AC_ARG_ENABLE(simd,
208208

209209
# Clag is crashing with -g -O2, so we'll get rid of -g for now.
210210
CXXFLAGS=`echo "$CXXFLAGS" | sed 's/-g //'`
211-
212-
if test x"$enable_simd" != x"no"; then
213-
# For x86-64 SIMD, g++ >=5 or clang++ >=7 is required
214-
if test x"$host_cpu" = x"x86_64"; then
215-
AC_LANG(C++)
216-
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
211+
m4_define(SIMD_X86_64_TEST, [[#include <stdio.h>
217212
#include <immintrin.h>
218213
__attribute__ ((target("default"))) int test_ssse3(int x) { return x; }
219214
__attribute__ ((target("default"))) int test_sse2(int x) { return x; }
@@ -233,7 +228,18 @@ __attribute__ ((target("ssse3"))) void more_testing(char* buf, int len)
233228
in8_2 = _mm_lddqu_si128((__m128i_u*)&buf[i + 16]);
234229
}
235230
}
236-
]], [[if (test_ssse3(42) != 42 || test_sse2(42) != 42 || test_avx2(42) != 42) exit(1);]])],[CXX_OK=yes],[CXX_OK=no],[CXX_OK=no])
231+
]])
232+
233+
if test x"$enable_simd" != x"no"; then
234+
# For x86-64 SIMD, g++ >=5 or clang++ >=7 is required
235+
if test x"$host_cpu" = x"x86_64"; then
236+
AC_LANG(C++)
237+
if test x"$host_cpu" = x"$build_cpu"; then
238+
AC_RUN_IFELSE([AC_LANG_PROGRAM([SIMD_X86_64_TEST],[[if (test_ssse3(42) != 42 || test_sse2(42) != 42 || test_avx2(42) != 42) exit(1);]])],
239+
[CXX_OK=yes],[CXX_OK=no])
240+
else
241+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([SIMD_X86_64_TEST])],[CXX_OK=yes],[CXX_OK=no])
242+
fi
237243
AC_LANG(C)
238244
if test x"$CXX_OK" = x"yes"; then
239245
# AC_MSG_RESULT() is called below.

0 commit comments

Comments
 (0)