From: maier Date: Wed, 12 Sep 2012 15:41:17 +0000 (+0000) Subject: A bunch of compiler feature tests X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e1d6c20093c01cf4ab657438213577d694ea19a;p=dealii-svn.git A bunch of compiler feature tests git-svn-id: https://svn.dealii.org/branches/branch_cmake@26315 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/contrib/cmake/check/check_for_compiler_features.cmake b/deal.II/contrib/cmake/check/check_for_compiler_features.cmake index 3030edc086..f8e4127fa5 100644 --- a/deal.II/contrib/cmake/check/check_for_compiler_features.cmake +++ b/deal.II/contrib/cmake/check/check_for_compiler_features.cmake @@ -1,5 +1,5 @@ INCLUDE(CheckCXXSourceCompiles) -INCLUDE(CheckIncludeFiles) +INCLUDE(CheckCXXSourceRuns) # @@ -163,3 +163,216 @@ CHECK_CXX_SOURCE_COMPILES( } " HAVE_LIBSTDCXX_DEMANGLER) + + + +# +# See if the compiler understands the attribute to mark functions +# as deprecated. +# + +# +# First see if the following compiles without error (it should +# produce a warning but we don't care about this) + + +CHECK_CXX_SOURCE_COMPILES( + " + int old_fn () __attribute__((deprecated)); + int old_fn () {}; + int (*fn_ptr)() = old_fn; + int main() { return 0; } + " + DEAL_II_COMPILER_HAS_ATTRIBUTE_DEPRECATED) + +LIST(APPEND CMAKE_REQUIRED_FLAGS "-Werror") +CHECK_CXX_SOURCE_COMPILES( + " + int old_fn () __attribute__((deprecated)); + int old_fn () {}; + int (*fn_ptr)() = old_fn; + int main() { return 0; } + " + DEAL_II_COMPILER_HAS_ATTRIBUTE_DEPRECATED_SHOULD_FAIL) +LIST(REMOVE_ITEM CMAKE_REQUIRED_FLAGS "-Werror") + +IF(DEAL_II_COMPILER_HAS_ATTRIBUTE_DEPRECATED AND NOT + DEAL_II_COMPILER_HAS_ATTRIBUTE_DEPRECATED_SHOULD_FAIL) + SET(DEAL_II_DEPRECATED TRUE) +ENDIF() + + + +# +# Check whether the compiler allows for vectorization and that +# vectorization actually works. For this test, we use compiler +# intrinsics similar to what is used in the deal.II library and +# check whether the arithmetic operations are correctly performed +# on examples where all numbers are exactly represented as +# floating point numbers. +# +CHECK_CXX_SOURCE_RUNS( + " + #include + #include + int main() + { + __m128d a, b; + const unsigned int vector_bytes = sizeof(__m128d); + const int n_vectors = vector_bytes/sizeof(double); + __m128d * data = + reinterpret_cast<__m128d*>(_mm_malloc (2*vector_bytes, vector_bytes)); + double * ptr = reinterpret_cast(&a); + ptr[0] = (volatile double)(1.0); + for (int i=1; i(&data[1]); + unsigned int return_value = 0; + if (ptr[0] != 7.3125) + return_value = 1; + for (int i=1; i + #include + int main() + { + __m256d a, b; + const unsigned int vector_bytes = sizeof(__m256d); + const int n_vectors = vector_bytes/sizeof(double); + __m256d * data = + reinterpret_cast<__m256d*>(_mm_malloc (2*vector_bytes, vector_bytes)); + double * ptr = reinterpret_cast(&a); + ptr[0] = (volatile double)(1.0); + for (int i=1; i(&data[1]); + unsigned int return_value = 0; + if (ptr[0] != 7.3125) + return_value = 1; + for (int i=1; i + int main() + { + __m128d a, b; + a = _mm_set_sd (1.0); + b = _mm_set1_pd (2.1); + __m128d c = a + b; + __m128d d = b - c; + __m128d e = c * a + d; + __m128d f = e/a; + (void)f; + } + " + DEAL_II_COMPILER_USE_VECTOR_ARITHMETICS) + + + +# +# Check if the declared prototype of abort() has a throw() +# specification. We overload abort() in our testsuite, so have +# to make sure that we match the exception specification +# correctly. +# +#include +CHECK_CXX_SOURCE_COMPILES( + " + extern \\"C\\" void abort () { for(;;) ; } + int main(){ return 0; } + " + DEAL_II_ABORT_WITHOUT_NOTHROW_EXCEPTION) + +IF(DEAL_II_ABORT_WITHOUT_NOTHROW_EXCEPTION) + SET(DEAL_II_ABORT_NOTHROW_EXCEPTION TRUE) +ENDIF() + + + +# +# Gcc and some other compilers have __PRETTY_FUNCTION__, showing +# an unmangled version of the function we are presently in, +# while __FUNCTION__ (or __func__ in ISO C99) simply give the +# function name which would not include the arguments of that +# function, leading to problems in C++ with overloaded function +# names. +# +# If __PRETTY_FUNCTION__ is not available, try to find out whether +# __func__ is available and use the preprocessor to set the first +# thing to the second. If this is also not the case, then set it +# to something indicating non-availability. +# + +CHECK_CXX_SOURCE_COMPILES( + " + #include + int main() + { + std::cout << __PRETTY_FUNCTION__ << std::endl; + return 0; + } + " + DEAL_II_COMPILER_HAS_ATTRIBUTE_PRETTY_FUNCTION) + +IF(NOT DEAL_II_COMPILER_HAS_ATTRIBUTE_PRETTY_FUNCTION) + CHECK_CXX_SOURCE_COMPILES( + " + #include + int main() + { + std::cout << __func__ << std::endl; + return 0; + } + " + DEAL_II_COMPILER_HAS_ATTRIBUTE_FUNC) + + IF(DEAL_II_COMPILER_HAS_ATTRIBUTE_FUNC) + SET(__PRETTY_FUNCTION__ "__func") + ELSE() + SET(__PRETTY_FUNCTION__ "(not available)") + ENDIF() + +ENDIF() diff --git a/deal.II/contrib/cmake/check/check_for_cxx_features.cmake b/deal.II/contrib/cmake/check/check_for_cxx_features.cmake index 86c15bfec1..b4fe1a6c1c 100644 --- a/deal.II/contrib/cmake/check/check_for_cxx_features.cmake +++ b/deal.II/contrib/cmake/check/check_for_cxx_features.cmake @@ -208,3 +208,6 @@ CHECK_INCLUDE_FILES("sys/syscall.h" HAVE_SYS_SYSCALL_H) CHECK_INCLUDE_FILES("sys/times.h" HAVE_SYS_TIMES_H) CHECK_INCLUDE_FILES("sys/types.h" HAVE_SYS_TYPES_H) + + + diff --git a/deal.II/include/deal.II/base/config.h.in b/deal.II/include/deal.II/base/config.h.in index 5428ceb97f..ad9782919f 100644 --- a/deal.II/include/deal.II/base/config.h.in +++ b/deal.II/include/deal.II/base/config.h.in @@ -179,6 +179,21 @@ libstdc++ interface. */ #cmakedefine HAVE_LIBSTDCXX_DEMANGLER + SET(DEAL_II_DEPRECATED TRUE) + +/* Equal to 0 in the generic case, equal to 1 if CPU compiled for supports + SSE2, equal to 2 if CPU compiled for supports AVX */ +#define DEAL_II_COMPILER_VECTORIZATION_LEVEL @DEAL_II_COMPILER_VECTORIZATION_LEVEL@ + +/* Defined if the compiler can use arithmetic operations on vectorized data + types */ +#cmakedefine DEAL_II_COMPILER_USE_VECTOR_ARITHMETICS + +/* If already available, do not define at all. Otherwise, define to __func__ + if that is available. In all other cases, indicate that no information + about the present function is available for this compiler. */ +#cmakedefine __PRETTY_FUNCTION__ @__PRETTY_FUNCTION__@ + diff --git a/deal.II/include/deal.II/base/config.h.in.old b/deal.II/include/deal.II/base/config.h.in.old index 4b563eb0e9..9b8e2095ec 100644 --- a/deal.II/include/deal.II/base/config.h.in.old +++ b/deal.II/include/deal.II/base/config.h.in.old @@ -39,19 +39,18 @@ floating point computations on cygwin systems. */ #cmakedefine DEAL_II_BROKEN_SOCKETS +/* Define if the compiler provides a header file which does not + define all error codes such as EINTR. In that case, use the system include + file at /usr/include instead. There is probably a better way to do this, + but it is not apparent by looking at the C/C++ compatibility header + provided by the compiler. */ +#cmakedefine DEAL_II_USE_DIRECT_ERRNO_H + /* Backward compatibility support for functions and classes that do not take an explicit mapping variable, but rather use a default Q1 mapping instead */ #cmakedefine DEAL_II_COMPAT_MAPPING -/* Defined if the compiler can use arithmetic operations on vectorized data - types */ -#cmakedefine DEAL_II_COMPILER_USE_VECTOR_ARITHMETICS - -/* Equal to 0 in the generic case, equal to 1 if CPU compiled for supports - SSE2, equal to 2 if CPU compiled for supports AVX */ -#cmakedefine DEAL_II_COMPILER_VECTORIZATION_LEVEL - /* Defined if the compiler has a bug in deducing the type of pointers to const member functions. */ #cmakedefine DEAL_II_CONST_MEMBER_DEDUCTION_BUG @@ -172,13 +171,6 @@ /* Defined if an ARPACK installation was found and is going to be used */ #cmakedefine DEAL_II_USE_ARPACK -/* Define if the compiler provides a header file which does not - define all error codes such as EINTR. In that case, use the system include - file at /usr/include instead. There is probably a better way to do this, - but it is not apparent by looking at the C/C++ compatibility header - provided by the compiler. */ -#cmakedefine DEAL_II_USE_DIRECT_ERRNO_H - /* Defined if a Metis installation was found and is going to be used */ #cmakedefine DEAL_II_USE_METIS @@ -437,12 +429,6 @@ # endif #endif -/* If already available, do not define at all. Otherwise, define to __func__ - if that is available. In all other cases, indicate that no information - about the present function is available for this compiler. */ -#cmakedefine __PRETTY_FUNCTION__ - - /** * A #define that indicates whether we are using the Microsoft * Windows Visual C/C++ compiler. We currently do not run ./configure diff --git a/deal.II/threads.m4 b/deal.II/threads.m4 deleted file mode 100644 index b586c5d774..0000000000 --- a/deal.II/threads.m4 +++ /dev/null @@ -1,37 +0,0 @@ -dnl ------------------------------------------------------------- -dnl In some cases, -threads (or whatever else command line option) -dnl switches on some preprocessor flags. If this is not the case, -dnl then define them explicitely. -dnl -dnl Usage: DEAL_II_THREAD_CPPFLAGS -dnl -dnl ------------------------------------------------------------- -AC_DEFUN(DEAL_II_THREAD_CPPFLAGS, dnl -[ - AC_MSG_CHECKING(for platform specific multi-threading defines) - AC_LANG(C++) - CXXFLAGS="$CXXFLAGSG" - AC_TRY_COMPILE( - [ -# if !defined (_REENTRANT) && !defined (_THREAD_SAFE) -# error Neither _REENTRANT nor _THREAD_SAFE were defined. - nonsense -# endif - ], - [ - ; - ], - [ - AC_MSG_RESULT(not necessary) - ], - [ - AC_MSG_RESULT(-D_REENTRANT -D_THREAD_SAFE) - CXXFLAGSG="$CXXFLAGSG -D_REENTRANT -D_THREAD_SAFE" - CXXFLAGSO="$CXXFLAGSO -D_REENTRANT -D_THREAD_SAFE" - ]) -]) - - - - -