Fix FMA4 compile for GCC and MSVC
authorRoland Schulz <roland@utk.edu>
Sun, 11 Nov 2012 04:49:24 +0000 (23:49 -0500)
committerRoland Schulz <roland@utk.edu>
Sun, 11 Nov 2012 04:49:24 +0000 (23:49 -0500)
GCC requires -mfma4 and MSVC requires intrin.h

Fixes #1023

Change-Id: I770a9d7fc5d9b0736042ea01ed0ed0d77aac95c6

CMakeLists.txt
include/gmx_math_x86_avx_128_fma_single.h
src/config.h.cmakein

index 3579113f6c551b8dafc4e8e25b77ed7101706404..874360b7efe4e4632d5ea5ce165122d200f4c76d 100644 (file)
@@ -787,6 +787,20 @@ elseif(${GMX_ACCELERATION} STREQUAL "AVX_128_FMA" OR ${GMX_ACCELERATION} STREQUA
         endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
     endif()
 
+    # Set the FMA4 flags (MSVC doesn't require any)
+    if(${GMX_ACCELERATION} STREQUAL "AVX_128_FMA" AND NOT MSVC)
+        GMX_TEST_CFLAG(GNU_FMA_CFLAG "-mfma4" GROMACS_C_FLAGS)
+        if (NOT GNU_FMA_CFLAG)
+            message(WARNING "No C FMA4 flag found. Consider a newer compiler, or disable AVX_128_FMA for much lower performance.")
+        endif(NOT GNU_FMA_CFLAG)
+        if (CMAKE_CXX_COMPILER_LOADED)
+            GMX_TEST_CXXFLAG(GNU_FMA_CXXFLAG "-mfma4" GROMACS_CXX_FLAGS)
+            if (NOT GNU_FMA_CXXFLAG)
+                message(WARNING "No C++ FMA flag found. Consider a newer compiler, or disable AVX_128_FMA for much lower performance.")
+            endif (NOT GNU_FMA_CXXFLAG)
+        endif()
+    endif()
+
     # Only test the header after we have tried to add the flag for AVX support
     check_include_file(immintrin.h  HAVE_IMMINTRIN_H ${GROMACS_C_FLAGS})
 
@@ -794,8 +808,9 @@ elseif(${GMX_ACCELERATION} STREQUAL "AVX_128_FMA" OR ${GMX_ACCELERATION} STREQUA
         message(FATAL_ERROR "Cannot find immintrin.h, which is required for AVX intrinsics support. Consider switching compiler.")
     endif(NOT HAVE_IMMINTRIN_H)
 
-    # AMD says we should include x86intrin.h for FMA support, but MSVC seems to do fine without it, so don't require it.
+    # GCC requires x86intrin.h for FMA support. MSVC 2010 requires intrin.h for FMA support.
     check_include_file(x86intrin.h HAVE_X86INTRIN_H ${GROMACS_C_FLAGS})
+    check_include_file(intrin.h HAVE_INTRIN_H ${GROMACS_C_FLAGS})
 
     # The user should not be able to set this orthogonally to the acceleration
     set(GMX_X86_SSE4_1 1)
index 8d48f2cbca1d5ffd3c5008ef07728b2a77d819e3..0adb058a9d152ac5671184b22de97829ad82b3d0 100644 (file)
@@ -25,6 +25,9 @@
 #ifdef HAVE_X86INTRIN_H
 #include <x86intrin.h> /* FMA */
 #endif
+#ifdef HAVE_INTRIN_H
+#include <intrin.h> /* FMA MSVC */
+#endif
 
 #include <math.h>
 
index fc307eda7cfcaed7af694fe84c099847aa4540ab..a5024ef659bdb8339049a0da9f279302b23f9e41 100644 (file)
 /* Define to 1 if you have the <x86intrin.h> header file */
 #cmakedefine HAVE_X86INTRIN_H
 
+/* Define to 1 if you have the <intrin.h> header file */
+#cmakedefine HAVE_INTRIN_H
+
 /* Define to 1 if you have the <sched.h> header */
 #cmakedefine HAVE_SCHED_H