From 8377e52e57c1fb5bcf159aa981f3b25b7bad1cb3 Mon Sep 17 00:00:00 2001 From: Pete Harris Date: Wed, 17 May 2023 20:14:07 +0100 Subject: [PATCH] Use precise fp with explicit contraction control VS2019 and older still require strict floating point due to the older /fp:precise behavior implying contraction, which was improved in VS2022. --- Docs/ChangeLog-4x.md | 24 +++++++++++++++++------- Source/cmake_core.cmake | 13 ++++++++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Docs/ChangeLog-4x.md b/Docs/ChangeLog-4x.md index 2a99fac74..7dc1b5beb 100644 --- a/Docs/ChangeLog-4x.md +++ b/Docs/ChangeLog-4x.md @@ -14,13 +14,23 @@ clocked at 4.2 GHz, running `astcenc` using AVX2 and 6 threads. The 4.5.0 release is a maintenance release with minor fixes and improvements. * **General:** - * **Bug-fix:** Invariant Clang and GCC builds now force `-ffp-model=strict`, - which is needed due to recent changes in compiler defaults. These builds - will be slower than the previous release, which was not guaranteed to be - invariant. Use a non-invariant build to recover lost performance if needed. - * **Bug-fix:** Non-invariant Clang and GCC builds now force - `-ffp-model=precise`, which is needed due to recent changes in compiler - defaults. + * **Bug-fix:** Invariant Clang builds now use `-ffp-model=precise` with + `-ffp-contract=off` which is needed to restore invariance due to recent + changes in compiler defaults. + * **Change:** Invariant MSVC builds for VS2022 now use `/fp:precise` instead + of `/fp:strict`, which is is now possible because precise no longer implies + contraction. This should improve performance for MSVC builds. + * **Change:** Non-invariant Clang builds now use `-ffp-model=precise` with + `-ffp-contract=on`. This should improve performance on older Clang + versions which defaulted to no contraction. + * **Change:** Non-invariant MSVC builds for VS2022 now use `/fp:precise` + with `/fp:contract`. This should improve performance for MSVC builds. + * **Change:** CMake config variables now use an `ASTCENC_` prefix to add a + namespace and group options when the library is used in a larger project. + * **Change:** CMake config `ASTCENC_NO_INVARIANCE` has been inverted to + remove the negated option, and is now `ASTCENC_INVARIANCE` with a default + of `ON`. Disablign this option can substantially improve performance, but + images can different across platforms and compilers. ## 4.4.0 diff --git a/Source/cmake_core.cmake b/Source/cmake_core.cmake index 42c6f8fe0..2298d25eb 100644 --- a/Source/cmake_core.cmake +++ b/Source/cmake_core.cmake @@ -200,16 +200,23 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER) PRIVATE ASTCENC_NO_INVARIANCE=1) + # For Visual Studio prior to 2022 (compiler < 17.0) /fp:precise + # For Visual Studio 2022 (compiler >= 17.0) /fp:precise and /fp:contract target_compile_options(${ASTCENC_TARGET_NAME} PRIVATE $<$:/fp:precise> + $<$,$,17>>:/fp:contract> $<$,$>:-ffp-model=precise> $<$:-ffp-contract=fast>) else() + # For Visual Studio prior to 2022 (compiler < 17.0) /fp:strict + # For Visual Studio 2022 (compiler >= 17.0) /fp:precise target_compile_options(${ASTCENC_TARGET_NAME} PRIVATE - $<$:/fp:strict> - $<$,$>:-ffp-model=strict>) + $<$,$,17>>:/fp:strict> + $<$,$,17>>:/fp:precise> + $<$,$>:-ffp-model=precise> + $<$:-ffp-contract=off>) endif() if(${ASTCENC_CLI}) @@ -249,7 +256,7 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER) # Workaround MSVC codegen bug for NEON builds on VS 2022 17.2 or older # https://developercommunity.visualstudio.com/t/inlining-turns-constant-into-register-operand-for/1394798 - if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND MSVC_VERSION LESS 1933) + if((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND (MSVC_VERSION LESS 1933)) target_compile_options(${ASTCENC_TARGET_NAME} PRIVATE $<$:/d2ssa-cfg-sink->)