Skip to content

Commit

Permalink
Backup and clear CMAKE_C_FLAGS before performing _Float16 configure c…
Browse files Browse the repository at this point in the history
…hecks (HDFGroup#4217)
  • Loading branch information
jhendersonHDF authored Mar 23, 2024
1 parent c1a56f4 commit cdc5112
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions config/cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -905,12 +905,24 @@ if (${HDF_PREFIX}_SIZEOF__FLOAT16)
# compile a program that will generate these functions to check for _Float16
# support. If we fail to compile this program, we will simply disable
# _Float16 support for the time being.

# Some compilers, notably AppleClang on MacOS 12, will succeed in the
# configure check below when optimization flags like -O3 are manually
# passed in CMAKE_C_FLAGS. However, the build will then fail when it
# reaches compilation of H5Tconv.c because of the issue mentioned above.
# MacOS 13 appears to have fixed this, but, just to be sure, backup and
# clear CMAKE_C_FLAGS before performing these configure checks.
set (cmake_c_flags_backup "${CMAKE_C_FLAGS}")
set (CMAKE_C_FLAGS "")

H5ConversionTests (
${HDF_PREFIX}_FLOAT16_CONVERSION_FUNCS_LINK
FALSE
"Checking if compiler can convert _Float16 type with casts"
)

set (CMAKE_C_FLAGS "${cmake_c_flags_backup}")

if (${${HDF_PREFIX}_FLOAT16_CONVERSION_FUNCS_LINK})
# Finally, MacOS 13 appears to have a bug specifically when converting
# long double values to _Float16. Release builds of the dt_arith test
Expand All @@ -919,12 +931,19 @@ if (${HDF_PREFIX}_SIZEOF__FLOAT16)
# simply chopping off all the bytes of the value except for the first 2.
# These tests pass on MacOS 14, so let's perform a quick test to check
# if the hardware conversion is done correctly.

# Backup and clear CMAKE_C_FLAGS before performing configure checks
set (cmake_c_flags_backup "${CMAKE_C_FLAGS}")
set (CMAKE_C_FLAGS "")

H5ConversionTests (
${HDF_PREFIX}_LDOUBLE_TO_FLOAT16_CORRECT
TRUE
"Checking if correctly converting long double to _Float16 values"
)

set (CMAKE_C_FLAGS "${cmake_c_flags_backup}")

if (NOT ${${HDF_PREFIX}_LDOUBLE_TO_FLOAT16_CORRECT})
message (VERBOSE "Conversions from long double to _Float16 appear to be incorrect. These will be emulated through a soft conversion function.")
endif ()
Expand Down

0 comments on commit cdc5112

Please sign in to comment.