Skip to content

Commit

Permalink
Use precise fp with explicit contraction control
Browse files Browse the repository at this point in the history
VS2019 and older still require strict floating point due to the
older /fp:precise behavior implying contraction, which was
improved in VS2022.
  • Loading branch information
solidpixel authored May 17, 2023
1 parent 6a4e78d commit 8377e52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
24 changes: 17 additions & 7 deletions Docs/ChangeLog-4x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions Source/cmake_core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<CXX_COMPILER_ID:MSVC>:/fp:precise>
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,17>>:/fp:contract>
$<$<AND:$<PLATFORM_ID:Linux,Darwin>,$<CXX_COMPILER_ID:${CLANG_LIKE}>>:-ffp-model=precise>
$<$<PLATFORM_ID:Linux,Darwin>:-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
$<$<CXX_COMPILER_ID:MSVC>:/fp:strict>
$<$<AND:$<PLATFORM_ID:Linux,Darwin>,$<CXX_COMPILER_ID:${CLANG_LIKE}>>:-ffp-model=strict>)
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,17>>:/fp:strict>
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,17>>:/fp:precise>
$<$<AND:$<PLATFORM_ID:Linux,Darwin>,$<CXX_COMPILER_ID:${CLANG_LIKE}>>:-ffp-model=precise>
$<$<PLATFORM_ID:Linux,Darwin>:-ffp-contract=off>)
endif()

if(${ASTCENC_CLI})
Expand Down Expand Up @@ -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
$<$<CXX_COMPILER_ID:MSVC>:/d2ssa-cfg-sink->)
Expand Down

0 comments on commit 8377e52

Please sign in to comment.