diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-02-18 17:16:04 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-02-19 02:42:11 +0000 |
commit | 493ab6bcf368de4cb795cbf023dce9a0d71ab655 (patch) | |
tree | f86468c0ae7a7e5b2ac52eeaba732eae8b1013f1 | |
parent | e29dca79f2faccfab156871dff8b200c6768d841 (diff) |
Check whether emmintrin.h can be used *without* -msse4.2.
If not, we can't use SSE 4.2, as we need to be able to include it in
files that use tvb_pbrk_compile()/tvb_pbrk_exec() even if they're not
compiled with -msse4.2 (most files aren't, as we need to isolate SSE 4.2
instructions to a small bit of code that uses them only if running on
hardware that supports them).
Change-Id: I62262a3c45fa14e200967916ac0ffc283f8e322c
Reviewed-on: https://code.wireshark.org/review/7246
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | configure.ac | 64 | ||||
-rw-r--r-- | wsutil/CMakeLists.txt | 40 |
2 files changed, 71 insertions, 33 deletions
diff --git a/configure.ac b/configure.ac index d1ec39a17e..72b48ab08b 100644 --- a/configure.ac +++ b/configure.ac @@ -1131,36 +1131,62 @@ if test "x$ac_sse4_2_flag" != x; then # # OK, we have a compiler flag to enable SSE 4.2. # - # Make sure we have the necessary header for the SSE4.2 intrinsics - # and that we can use it. + # Make sure we have the necessary headers for the SSE4.2 intrinsics + # and that we can use them. # - AC_MSG_CHECKING([whether there is nmmintrin.h header and we can use it]) - - # - # Add the SSE4.2 flags to the beginning of CFLAGS, in case the - # user explicitly specified -mno-sse4.2 (or in case Gentoo's build - # tools did so); if they did so, we only want this to work if - # we can use the #pragma to override that for ws_mempbrk_sse42.c, - # and putting it at the beginning means that the CFLAGS setting - # in the environment will come later and override it. + # First, check whether we have emmintrin.h and can use it + # *without* the SSE 4.2 flag. # - saved_CFLAGS="$CFLAGS" - CFLAGS="$ac_sse4_2_flag $CFLAGS" + AC_MSG_CHECKING([whether there is emmintrin.h header and we can use it]) AC_TRY_COMPILE( - [#include <nmmintrin.h>], + [#include <emmintrin.h>], [return 0;], [ - have_sse42=yes - AC_DEFINE(HAVE_SSE4_2, 1, [Support SSSE4.2 (Streaming SIMD Extensions 4.2) instructions]) - CFLAGS_SSE42="$ac_sse4_2_flag" + emmintrin_h_works=yes AC_MSG_RESULT([yes]) ], [ - have_sse42=no + emmintrin_h_works=no AC_MSG_RESULT([no]) ] ) - CFLAGS="$saved_CFLAGS" + + # + # OK, if that works, see whether we have nmmintrin.h and + # can use it *with* the SSE 4.2 flag. + # + if test "x$emmintrin_h_works" = "xyes"; then + # + # Add the SSE4.2 flags to the beginning of CFLAGS, + # in case the user explicitly specified -mno-sse4.2 + # (or in case Gentoo's build tools did so); if they + # did so, we only want this to work if we can use + # the #pragma to override that for ws_mempbrk_sse42.c, + # and putting it at the beginning means that the + # CFLAGS setting in the environment will come later + # and override it. + # + AC_MSG_CHECKING([whether there is nmmintrin.h header and we can use it]) + saved_CFLAGS="$CFLAGS" + CFLAGS="$ac_sse4_2_flag $CFLAGS" + AC_TRY_COMPILE( + [#include <nmmintrin.h>], + [return 0;], + [ + have_sse42=yes + AC_DEFINE(HAVE_SSE4_2, 1, [Support SSSE4.2 (Streaming SIMD Extensions 4.2) instructions]) + CFLAGS_SSE42="$ac_sse4_2_flag" + AC_MSG_RESULT([yes]) + ], + [ + have_sse42=no + AC_MSG_RESULT([no]) + ] + ) + CFLAGS="$saved_CFLAGS" + else + have_sse42=no + fi else have_sse42=no fi diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index fe2d662eac..6741ce4c8c 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -104,24 +104,36 @@ else() endif() if(COMPILER_CAN_HANDLE_SSE4_2) # - # Make sure we have the necessary header for the SSE4.2 intrinsics - # and that we can use it. + # Make sure we have the necessary headers for the SSE4.2 intrinsics + # and that we can use them. # - + # First, check whether we have emmintrin.h and can use it + # *without* the SSE 4.2 flag. # - # Does this add the SSE4.2 flags to the beginning of CFLAGS? + check_include_file("emmintrin.h" EMMINTRIN_H_WORKS) + # - # Note that if there's a mix of "enable SSE 4.2" and"disable - # SSE 4.2" flags, this may not indicate that we can use the - # header. That's not a bug, that's a feature; the other flags - # may have been forced by the build process, e.g. in Gentoo - # Linux, and we want to check this with whatever flags will - # actually be used when building (see bug 10792). + # OK, if that works, see whether we have nmmintrin.h and + # can use it *with* the SSE 4.2 flag. # - cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}") - check_include_file("nmmintrin.h" HAVE_SSE4_2) - cmake_pop_check_state() + if(EMMINTRIN_H_WORKS) + # + # Does this add the SSE4.2 flags to the beginning of + # CFLAGS? + # + # Note that if there's a mix of "enable SSE 4.2" and + # "disable SSE 4.2" flags, this may not indicate that + # we can use the header. That's not a bug, that's a + # feature; the other flags may have been forced by + # the build process, e.g. in Gentoo Linux, and we want + # to check this with whatever flags will actually be + # used when building (see bug 10792). + # + cmake_push_check_state() + set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}") + check_include_file("nmmintrin.h" HAVE_SSE4_2) + cmake_pop_check_state() + endif() endif() if(HAVE_SSE4_2) set(WSUTIL_FILES ${WSUTIL_FILES} ws_mempbrk_sse42.c) |