1 # - Define macro to determine floating point format properties
3 # GMX_TEST_FLOAT_FORMAT(FP_IEEE754 FP_BIG_ENDIAN_BYTE FP_BIG_ENDIAN_WORD)
5 # The thee variables are set to true when:
6 # FP_IEEE754 Floating-point numbers are stored in IEEE754 format
7 # FP_BIG_ENDIAN_BYTE The order of bytes in each FP word (4 bytes) is big endian
8 # FP_BIG_ENDIAN_WORD The order of FP words in double precision dwords (2 words) is big endian
10 # On *most* platforms the two last tests will be the same as the integer endian,
11 # big e.g. ARM processors have different byte/word order for floating-point storage,
12 # so we figured it is a good idea to test both before relying on the format.
14 MACRO(GMX_TEST_FLOAT_FORMAT FP_IEEE754 FP_BIG_ENDIAN_BYTE FP_BIG_ENDIAN_WORD)
15 IF(NOT DEFINED HAVE_${FP_IEEE754})
16 MESSAGE(STATUS "Checking floating point format")
18 TRY_COMPILE(HAVE_${FP_IEEE754} "${CMAKE_BINARY_DIR}"
19 "${CMAKE_SOURCE_DIR}/cmake/TestFloatFormat.c"
20 COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin")
22 if(HAVE_${FP_IEEE754})
24 # dont match first/last letter because of string rounding errors :-)
25 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
26 GMX_IEEE754_BB_BW LIMIT_COUNT 1 REGEX "ROMACS")
27 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
28 GMX_IEEE754_BB_LW LIMIT_COUNT 1 REGEX "CSXGRO")
29 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
30 GMX_IEEE754_LB_BW LIMIT_COUNT 1 REGEX "ORGXSC")
31 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
32 GMX_IEEE754_LB_LW REGEX "SCAMOR")
33 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
34 GMX_IEEE754 REGEX "GROMACS|CSXGRO|ORGXSC|SCAMOR")
36 # OS X Universal binaries will contain both strings, set it to the host
37 IF(GMX_IEEE754_BB_BW AND GMX_IEEE754_LB_LW)
38 IF(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
39 SET(GMX_IEEE754_BB_BW TRUE)
40 SET(GMX_IEEE754_LB_LW FALSE)
41 ELSE(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
42 SET(GMX_IEEE754_BB_BW FALSE)
43 SET(GMX_IEEE754_LB_LW TRUE)
44 ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
45 MESSAGE(STATUS "GMX_TEST_IEEE754_FORMAT found different results, consider setting CMAKE_OSX_ARCHITECTURES or CMAKE_TRY_COMPILE_OSX_ARCHITECTURES to one or no architecture !")
46 ENDIF(GMX_IEEE754_BB_BW AND GMX_IEEE754_LB_LW)
49 SET(${FP_IEEE754} 1 CACHE INTERNAL "Result of test for IEEE754 FP format" FORCE)
52 IF(GMX_IEEE754_BB_BW OR GMX_IEEE754_BB_LW)
53 SET(${FP_BIG_ENDIAN_BYTE} 1 CACHE INTERNAL "Result of test for big endian FP byte order" FORCE)
54 ENDIF(GMX_IEEE754_BB_BW OR GMX_IEEE754_BB_LW)
56 IF(GMX_IEEE754_BB_BW OR GMX_IEEE754_LB_BW)
57 SET(${FP_BIG_ENDIAN_WORD} 1 CACHE INTERNAL "Result of test for big endian FP word order" FORCE)
58 ENDIF(GMX_IEEE754_BB_BW OR GMX_IEEE754_LB_BW)
60 endif(HAVE_${FP_IEEE754})
62 # just some informational output for the user
64 MESSAGE(STATUS "Checking floating point format - IEEE754 (BE byte, BE word)")
65 elseif(GMX_IEEE754_BB_LW)
66 MESSAGE(STATUS "Checking floating point format - IEEE754 (BE byte, LE word)")
67 elseif(GMX_IEEE754_LB_BW)
68 MESSAGE(STATUS "Checking floating point format - IEEE754 (LE byte, BE word)")
69 elseif(GMX_IEEE754_LB_LW)
70 MESSAGE(STATUS "Checking floating point format - IEEE754 (LE byte, LE word)")
71 else(GMX_IEEE754_LB_LW)
72 MESSAGE(STATUS "Checking floating point format - unknown")
73 endif(GMX_IEEE754_BB_BW)
74 ENDIF(NOT DEFINED HAVE_${FP_IEEE754})
75 ENDMACRO(GMX_TEST_FLOAT_FORMAT FP_IEEE754 FP_BIG_ENDIAN_BYTE FP_BIG_ENDIAN_WORD)