From 9430106c71f429235d3942fe19067a9d58fdf83f Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 8 Jan 2016 22:43:04 +0100 Subject: [PATCH] Allow to disable inline assembly from configure This is required for the -fsanitize options that don't support inline assembly statements. --- cmdline/portable.h | 4 +++- configure.ac | 11 ++++++++++ raid/internal.h | 54 +++++++++++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/cmdline/portable.h b/cmdline/portable.h index 2e37eeba..18867f89 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -75,8 +75,9 @@ /** - * Architecture. + * Architecture for inline assembly. */ +#if HAVE_ASSEMBLY #if defined(__i386__) #define CONFIG_X86 1 #define CONFIG_X86_32 1 @@ -86,6 +87,7 @@ #define CONFIG_X86 1 #define CONFIG_X86_64 1 #endif +#endif /** * Includes some platform specific headers. diff --git a/configure.ac b/configure.ac index 2175a6fc..c04f1a2a 100644 --- a/configure.ac +++ b/configure.ac @@ -118,6 +118,14 @@ AC_CHECK_CC_OPT([-Wextra], CFLAGS="$CFLAGS -Wextra", []) AC_CHECK_CC_OPT([-Wuninitialized], CFLAGS="$CFLAGS -Wuninitialized", []) AC_CHECK_CC_OPT([-Wshadow], CFLAGS="$CFLAGS -Wshadow", []) +dnl Checks for asm +AC_ARG_ENABLE([asm], + AS_HELP_STRING([--disable-asm], [Disable inline assembly])) +AS_IF([test "x$enable_asm" != "xno"], + [AC_DEFINE([HAVE_ASSEMBLY], [1], [Define to 1 if inline assembly should be used.])] + +dnl AS_IF(HAVE_ASSEMBLY) NOT closed here + dnl Checks for AS supporting the SSE2 instructions. AC_MSG_CHECKING([for sse2]) asmsse2=no @@ -183,6 +191,9 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ [AC_DEFINE([HAVE_AVX2], [1], [Define to 1 if avx2 is supported by the assembler.]) asmavx2=yes]) AC_MSG_RESULT([$asmavx2]) +dnl AS_IF(HAVE_ASSEMBLY) closed here +) + dnl Checks for test environment AS_CASE([$host], [*-*-mingw*], diff --git a/raid/internal.h b/raid/internal.h index ba2f35f6..4465cb97 100644 --- a/raid/internal.h +++ b/raid/internal.h @@ -15,21 +15,6 @@ #ifndef __RAID_INTERNAL_H #define __RAID_INTERNAL_H -/* - * Supported architecture. - * - * Detect the target architecture directly from the compiler. - */ -#if defined(__i386__) -#define CONFIG_X86 1 -#define CONFIG_X86_32 1 -#endif - -#if defined(__x86_64__) -#define CONFIG_X86 1 -#define CONFIG_X86_64 1 -#endif - /* * Supported instruction sets. * @@ -45,19 +30,44 @@ /* Includes the project configuration for HAVE_* defines */ #include "config.h" -#if HAVE_SSE2 /* Enables SSE2 only if the assembler supports it */ +/* If the compiler supports assembly */ +#if HAVE_ASSEMBLY +/* Autodetect from the compiler */ +#if defined(__i386__) +#define CONFIG_X86 1 +#define CONFIG_X86_32 1 +#endif +#if defined(__x86_64__) +#define CONFIG_X86 1 +#define CONFIG_X86_64 1 +#endif +#endif + +/* Enables SSE2, SSSE3, AVX2 only if the assembler supports it */ +#if HAVE_SSE2 #define CONFIG_SSE2 1 #endif - -#if HAVE_SSSE3 /* Enables SSSE3 only if the assembler supports it */ +#if HAVE_SSSE3 #define CONFIG_SSSE3 1 #endif - -#if HAVE_AVX2 /* Enables AVX2 only if the assembler supports it */ +#if HAVE_AVX2 #define CONFIG_AVX2 1 #endif -#else -/* If no config file, assumes the assembler supports everything in x86 */ + +#else /* if HAVE_CONFIG_H is not defined */ + +/* Assume that assembly is always supported */ +#if defined(__i386__) +#define CONFIG_X86 1 +#define CONFIG_X86_32 1 +#endif + +#if defined(__x86_64__) +#define CONFIG_X86 1 +#define CONFIG_X86_64 1 +#endif + +/* Assumes that the assembler supports everything */ #ifdef CONFIG_X86 #define CONFIG_SSE2 1 #define CONFIG_SSSE3 1