From d8b42792a62d00de3f5a4998efc5dd7175eb6cac Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 30 May 2019 18:24:01 +0300 Subject: [PATCH] cmake: update ENABLE_FAST_MATH option --- CMakeLists.txt | 2 +- cmake/OpenCVCompilerOptimizations.cmake | 4 ---- cmake/OpenCVCompilerOptions.cmake | 27 +++++++++++++++++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ed7e41be3..25e7160841 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -473,7 +473,7 @@ OCV_OPTION(ENABLE_COVERAGE "Enable coverage collection with GCov" OCV_OPTION(OPENCV_ENABLE_MEMORY_SANITIZER "Better support for memory/address sanitizers" OFF) OCV_OPTION(ENABLE_OMIT_FRAME_POINTER "Enable -fomit-frame-pointer for GCC" ON IF CV_GCC ) OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CV_GCC AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) ) -OCV_OPTION(ENABLE_FAST_MATH "Enable -ffast-math (not recommended for GCC 4.6.x)" OFF IF (CV_GCC AND (X86 OR X86_64)) ) +OCV_OPTION(ENABLE_FAST_MATH "Enable compiler options for fast math optimizations on FP computations (not recommended)" OFF) if(NOT IOS) # Use CPU_BASELINE instead OCV_OPTION(ENABLE_NEON "Enable NEON instructions" (NEON OR ANDROID_ARM_NEON OR AARCH64) IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) ) OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) ) diff --git a/cmake/OpenCVCompilerOptimizations.cmake b/cmake/OpenCVCompilerOptimizations.cmake index 8247a9a53c..fcf31135f0 100644 --- a/cmake/OpenCVCompilerOptimizations.cmake +++ b/cmake/OpenCVCompilerOptimizations.cmake @@ -635,10 +635,6 @@ macro(ocv_compiler_optimization_options_finalize) if(MSVC) # Generate Intrinsic Functions set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /Oi") - - if((X86 OR X86_64) AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND ";${CPU_BASELINE_FINAL};" MATCHES ";SSE;") - set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /fp:fast") # !! important - be on the same wave with x64 compilers - endif() endif(MSVC) endmacro() diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index fc29d279c4..23b08b2f36 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -75,11 +75,25 @@ if(NOT MSVC) add_extra_compiler_option(-fsigned-char) endif() -if(CV_ICC AND NOT ENABLE_FAST_MATH) - if(MSVC) - add_extra_compiler_option("/fp:precise") - else() - add_extra_compiler_option("-fp-model precise") +if(MSVC) + if(NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " /fp:") + if(ENABLE_FAST_MATH) + add_extra_compiler_option("/fp:fast") + else() + add_extra_compiler_option("/fp:precise") + endif() + endif() +elseif(CV_ICC) + if(NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " /fp:" + AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fp-model" + ) + if(NOT ENABLE_FAST_MATH) + add_extra_compiler_option("-fp-model precise") + endif() + endif() +elseif(CV_GCC OR CV_CLANG) + if(ENABLE_FAST_MATH) + add_extra_compiler_option(-ffast-math) endif() endif() @@ -165,9 +179,6 @@ if(CV_GCC OR CV_CLANG) elseif(DEFINED ENABLE_OMIT_FRAME_POINTER) add_extra_compiler_option(-fno-omit-frame-pointer) endif() - if(ENABLE_FAST_MATH) - add_extra_compiler_option(-ffast-math) - endif() # Profiling? if(ENABLE_PROFILING)