From 73223445d66e13c3890ffb85759075ed9b1a6a53 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Sun, 16 Jan 2022 15:55:02 +0000 Subject: [PATCH] MSVC opt /fp:fast /Oi, intrinsic sqrt() w/ XBRZ. For MSVC, add the optimization flags: /fp:fast /Oi , to favor speed for floating point operations and use intrinsic operations where possible. For release builds also add: /O2 . Use sqrt() instead of std::sqrt() in XBRZ for MSVC x64 just in case to make sure it uses the intrinsic version. Test build is reported to run much faster. Signed-off-by: Rafael Kitover --- CMakeLists.txt | 4 ++-- src/filters/xBRZ/xbrz.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c23b989e..773bbbb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -744,12 +744,12 @@ elseif(MSVC) string(REGEX REPLACE "/[Ww][^ ]+" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) string(REGEX REPLACE "/[Ww][^ ]+" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) - add_compile_options(/std:c++17 -D__STDC_LIMIT_MACROS) + add_compile_options(/std:c++17 -D__STDC_LIMIT_MACROS /fp:fast /Oi) if(CMAKE_BUILD_TYPE STREQUAL Debug) add_compile_options(/W4) else() - add_compile_options(/w) + add_compile_options(/w /O2) if(ENABLE_LTO) add_compile_options(/GL) diff --git a/src/filters/xBRZ/xbrz.cpp b/src/filters/xBRZ/xbrz.cpp index 13e6cdc1..17d7830e 100644 --- a/src/filters/xBRZ/xbrz.cpp +++ b/src/filters/xBRZ/xbrz.cpp @@ -76,8 +76,10 @@ inline double fastSqrt(double n) fld n fsqrt } -#else // defined(_MSC_VER) && defined(_M_X64) OR other platforms - // VisualStudio x86_64 does not allow inline ASM +#elif defined(_MSC_VER) + // On MSVC x64 use intrinsic with /Oi and /fp:fast + return sqrt(n); +#else // Other platforms. return std::sqrt(n); #endif }