From 90315af428610adae95d0928498f2861766f6ed4 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 14 Sep 2015 10:50:30 -0500 Subject: [svn-r27770] Bring r27428 from trunk Reverts the following changes: 27737, 27742, 27743 These involve double conversions that cause problems with the IBM XL compiler. Tested on: h5committest ostrich w/ XL C compiler --- config/cmake/ConfigureChecks.cmake | 30 +++++ config/cmake/ConversionTests.c | 82 ++++++++++++++ config/cmake/H5pubconf.h.in | 11 ++ configure | 220 ++++++++++++++++++++++++++++++++++++- configure.ac | 157 ++++++++++++++++++++++++++ release_docs/INSTALL_CMake.txt | 1 + release_docs/RELEASE.txt | 25 ----- src/H5T.c | 8 ++ src/H5Tconv.c | 8 ++ src/H5Tpkg.h | 33 ++++++ src/H5config.h.in | 11 ++ test/dt_arith.c | 90 ++++++++++++--- 12 files changed, 634 insertions(+), 42 deletions(-) diff --git a/config/cmake/ConfigureChecks.cmake b/config/cmake/ConfigureChecks.cmake index e223553..09f1caf 100644 --- a/config/cmake/ConfigureChecks.cmake +++ b/config/cmake/ConfigureChecks.cmake @@ -33,6 +33,18 @@ endif (HDF5_METADATA_TRACE_FILE) MARK_AS_ADVANCED (HDF5_METADATA_TRACE_FILE) # ---------------------------------------------------------------------- +# Decide whether the data accuracy has higher priority during data +# conversions. If not, some hard conversions will still be prefered even +# though the data may be wrong (for example, some compilers don't +# support denormalized floating values) to maximize speed. +# +option (HDF5_WANT_DATA_ACCURACY "IF data accuracy is guaranteed during data conversions" ON) +if (HDF5_WANT_DATA_ACCURACY) + set (H5_WANT_DATA_ACCURACY 1) +endif (HDF5_WANT_DATA_ACCURACY) +MARK_AS_ADVANCED (HDF5_WANT_DATA_ACCURACY) + +# ---------------------------------------------------------------------- # Decide whether the presence of user's exception handling functions is # checked and data conversion exceptions are returned. This is mainly # for the speed optimization of hard conversions. Soft conversions can @@ -220,6 +232,24 @@ H5ConversionTests (H5_LDOUBLE_TO_LONG_SPECIAL "Checking IF your system converts # H5ConversionTests (H5_LONG_TO_LDOUBLE_SPECIAL "Checking IF your system can convert (unsigned) long to long double values with special algorithm") # ---------------------------------------------------------------------- +# Set the flag to indicate that the machine can accurately convert +# 'long double' to '(unsigned) long long' values. (This flag should be set for +# all machines, except for Mac OS 10.4 and SGI IRIX64 6.5. When the bit sequence +# of long double is 0x4351ccf385ebc8a0bfcc2a3c..., the values of (unsigned)long long +# start to go wrong on these two machines. Adjusting it higher to +# 0x4351ccf385ebc8a0dfcc... or 0x4351ccf385ebc8a0ffcc... will make the converted +# values wildly wrong. This test detects this wrong behavior and disable the test. +# +H5ConversionTests (H5_LDOUBLE_TO_LLONG_ACCURATE "Checking IF correctly converting long double to (unsigned) long long values") +# ---------------------------------------------------------------------- +# Set the flag to indicate that the machine can accurately convert +# '(unsigned) long long' to 'long double' values. (This flag should be set for +# all machines, except for Mac OS 10.4, when the bit sequences are 003fff..., +# 007fff..., 00ffff..., 01ffff..., ..., 7fffff..., the converted values are twice +# as big as they should be. +# +H5ConversionTests (H5_LLONG_TO_LDOUBLE_CORRECT "Checking IF correctly converting (unsigned) long long to long double values") +# ---------------------------------------------------------------------- # Check if pointer alignments are enforced # H5ConversionTests (H5_NO_ALIGNMENT_RESTRICTIONS "Checking IF alignment restrictions are strictly enforced") diff --git a/config/cmake/ConversionTests.c b/config/cmake/ConversionTests.c index cd2e8bb..d964bf8 100644 --- a/config/cmake/ConversionTests.c +++ b/config/cmake/ConversionTests.c @@ -116,6 +116,88 @@ done: #endif +#ifdef H5_LDOUBLE_TO_LLONG_ACCURATE_TEST +int main(void) +{ + long double ld = 20041683600089727.779961L; + long long ll; + unsigned long long ull; + unsigned char s[16]; + int ret = 0; + + if(sizeof(long double) == 16) { + /*make sure the long double type is the same as the failing type + *which has 16 bytes in size and 11 bits of exponent. If it is, + *the bit sequence should be like below. It's not + *a decent way to check but this info isn't available. */ + memcpy(s, &ld, 16); + if(s[0]==0x43 && s[1]==0x51 && s[2]==0xcc && s[3]==0xf3 && + s[4]==0x85 && s[5]==0xeb && s[6]==0xc8 && s[7]==0xa0 && + s[8]==0xbf && s[9]==0xcc && s[10]==0x2a && s[11]==0x3c) { + + /*slightly adjust the bit sequence (s[8]=0xdf). The converted + *values will go wild on Mac OS 10.4 and IRIX64 6.5.*/ + s[0]=0x43; s[1]=0x51; s[2]=0xcc; s[3]=0xf3; + s[4]=0x85; s[5]=0xeb; s[6]=0xc8; s[7]=0xa0; + s[8]=0xdf; s[9]=0xcc; s[10]=0x2a; s[11]=0x3c; + s[12]=0x3d; s[13]=0x85; s[14]=0x56; s[15]=0x20; + + memcpy(&ld, s, 16); + ll = (long long)ld; + ull = (unsigned long long)ld; + + if(ll != 20041683600089728 || ull != 20041683600089728) + ret = 1; + } + } +done: + exit(ret); +} +#endif + +#ifdef H5_LLONG_TO_LDOUBLE_CORRECT_TEST +int main(void) +{ + long double ld; + long long ll; + unsigned long long ull; + unsigned char s[16]; + int flag=0, ret=0; + + /*Determine if long double has 16 byte in size, 11 bit exponent, and + *the bias is 0x3ff */ + if(sizeof(long double) == 16) { + ld = 1.0L; + memcpy(s, &ld, 16); + if(s[0]==0x3f && s[1]==0xf0 && s[2]==0x00 && s[3]==0x00 && + s[4]==0x00 && s[5]==0x00 && s[6]==0x00 && s[7]==0x00) + flag = 1; + } + + if(flag==1 && sizeof(long long)==8) { + ll = 0x01ffffffffffffffLL; + ld = (long double)ll; + memcpy(s, &ld, 16); + /*Check if the bit sequence is as supposed to be*/ + if(s[0]!=0x43 || s[1]!=0x7f || s[2]!=0xff || s[3]!=0xff || + s[4]!=0xff || s[5]!=0xff || s[6]!=0xff || s[7]!=0xff || + s[8]!=0xf0 || s[9]!=0x00 || s[10]!=0x00 || s[11]!=0x00) + ret = 1; + } + if(flag==1 && sizeof(unsigned long long)==8) { + ull = 0x01ffffffffffffffULL; + ld = (long double)ull; + memcpy(s, &ld, 16); + if(s[0]!=0x43 || s[1]!=0x7f || s[2]!=0xff || s[3]!=0xff || + s[4]!=0xff || s[5]!=0xff || s[6]!=0xff || s[7]!=0xff || + s[8]!=0xf0 || s[9]!=0x00 || s[10]!=0x00 || s[11]!=0x00) + ret = 1; + } +done: + exit(ret); +} +#endif + #ifdef H5_NO_ALIGNMENT_RESTRICTIONS_TEST #include diff --git a/config/cmake/H5pubconf.h.in b/config/cmake/H5pubconf.h.in index 10cf1bc..874c8f0 100644 --- a/config/cmake/H5pubconf.h.in +++ b/config/cmake/H5pubconf.h.in @@ -362,10 +362,18 @@ /* Define if HDF5's high-level library headers should be included in hdf5.h */ #cmakedefine H5_INCLUDE_HL @H5_INCLUDE_HL@ +/* Define if your system can convert long double to (unsigned) long long + values correctly. */ +#cmakedefine H5_LDOUBLE_TO_LLONG_ACCURATE @H5_LDOUBLE_TO_LLONG_ACCURATE@ + /* Define if your system converts long double to (unsigned) long values with special algorithm. */ #cmakedefine H5_LDOUBLE_TO_LONG_SPECIAL @H5_LDOUBLE_TO_LONG_SPECIAL@ +/* Define if your system can convert (unsigned) long long to long double + values correctly. */ +#cmakedefine H5_LLONG_TO_LDOUBLE_CORRECT @H5_LLONG_TO_LDOUBLE_CORRECT@ + /* Define if your system can convert (unsigned) long to long double values with special algorithm. */ #cmakedefine H5_LONG_TO_LDOUBLE_SPECIAL @H5_LONG_TO_LDOUBLE_SPECIAL@ @@ -567,6 +575,9 @@ /* Version number of package */ #define H5_VERSION "@HDF5_PACKAGE_VERSION_STRING@" +/* Data accuracy is prefered to speed during data conversions */ +#cmakedefine H5_WANT_DATA_ACCURACY @H5_WANT_DATA_ACCURACY@ + /* Check exception handling functions during data conversions */ #cmakedefine H5_WANT_DCONV_EXCEPTION @H5_WANT_DCONV_EXCEPTION@ diff --git a/configure b/configure index a9a5994..71c3318 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac Id: configure.ac 27757 2015-09-11 04:35:01Z derobins . +# From configure.ac Id: configure.ac 27759 2015-09-11 05:37:17Z derobins . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for HDF5 1.8.16-snap16. # @@ -911,6 +911,7 @@ with_mpe enable_direct_vfd with_default_plugindir enable_dconv_exception +enable_dconv_accuracy enable_build_all enable_deprecated_symbols with_default_api_version @@ -1607,6 +1608,8 @@ Optional Features: --enable-dconv-exception if exception handling functions is checked during data conversions [default=yes] + --enable-dconv-accuracy if data accuracy is guaranteed during data + conversions [default=yes] --enable-build-all Build helper programs that only developers should need [default=no] --enable-deprecated-symbols @@ -27247,6 +27250,33 @@ $as_echo "no" >&6; } fi ## ---------------------------------------------------------------------- +## Decide whether the data accuracy has higher priority during data +## conversions. If not, some hard conversions will still be prefered even +## though the data may be wrong (for example, some compilers don't +## support denormalized floating values) to maximize speed. +## +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether data accuracy is guaranteed during data conversions" >&5 +$as_echo_n "checking whether data accuracy is guaranteed during data conversions... " >&6; } +# Check whether --enable-dconv-accuracy was given. +if test "${enable_dconv_accuracy+set}" = set; then : + enableval=$enable_dconv_accuracy; DATA_ACCURACY=$enableval +else + DATA_ACCURACY=yes +fi + + +if test "$DATA_ACCURACY" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define WANT_DATA_ACCURACY 1" >>confdefs.h + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +## ---------------------------------------------------------------------- ## Set the flag to indicate that the machine has window style pathname, ## that is, "drive-letter:\" (e.g. "C:") or "drive-letter:/" (e.g. "C:/"). ## (This flag should be _unset_ for all machines, except for Windows, where @@ -27510,6 +27540,194 @@ $as_echo "no" >&6; } fi ## ---------------------------------------------------------------------- +## Set the flag to indicate that the machine can accurately convert +## 'long double' to '(unsigned) long long' values. This flag should +## be set for all machines, except for IBM XL C compilers. Historically, +## this has also been a problem with OS X (version 10.4) but not current +## versions of that OS. +## +## When the bit sequence of long double is 0x4351ccf385ebc8a0bfcc2a3c..., +## the values of (unsigned)long long start to go wrong on these +## two machines. Adjusting it higher to 0x4351ccf385ebc8a0dfcc... or +## 0x4351ccf385ebc8a0ffcc... will make the converted values wildly wrong. +## This test detects this wrong behavior and disable the test. +## +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if correctly converting long double to (unsigned) long long values" >&5 +$as_echo_n "checking if correctly converting long double to (unsigned) long long values... " >&6; } + +if test ${ac_cv_sizeof_long_double} = 0; then + hdf5_cv_ldouble_to_llong_accurate=${hdf5_cv_ldouble_to_llong_accurate=no} +else + if ${hdf5_cv_ldouble_to_llong_accurate+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run test program while cross compiling +See \`config.log' for more details" "$LINENO" 5; } +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + int main(void) + { + long double ld = 20041683600089727.779961L; + long long ll; + unsigned long long ull; + unsigned char s[16]; + int ret = 0; + + if(sizeof(long double) == 16) { + /*make sure the long double type is the same as the failing type + *which has 16 bytes in size and 11 bits of exponent. If it is, + *the bit sequence should be like below. It's not + *a decent way to check but this info isn't available. */ + memcpy(s, &ld, 16); + if(s[0]==0x43 && s[1]==0x51 && s[2]==0xcc && s[3]==0xf3 && + s[4]==0x85 && s[5]==0xeb && s[6]==0xc8 && s[7]==0xa0 && + s[8]==0xbf && s[9]==0xcc && s[10]==0x2a && s[11]==0x3c) { + + /*slightly adjust the bit sequence (s[8]=0xdf). The converted + *values will go wild on Mac OS 10.4 and IRIX64 6.5.*/ + s[0]=0x43; s[1]=0x51; s[2]=0xcc; s[3]=0xf3; + s[4]=0x85; s[5]=0xeb; s[6]=0xc8; s[7]=0xa0; + s[8]=0xdf; s[9]=0xcc; s[10]=0x2a; s[11]=0x3c; + s[12]=0x3d; s[13]=0x85; s[14]=0x56; s[15]=0x20; + + memcpy(&ld, s, 16); + ll = (long long)ld; + ull = (unsigned long long)ld; + + if(ll != 20041683600089728 || ull != 20041683600089728) + ret = 1; + } + } + done: + exit(ret); + } + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + hdf5_cv_ldouble_to_llong_accurate=yes +else + hdf5_cv_ldouble_to_llong_accurate=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi + +fi + +if test ${hdf5_cv_ldouble_to_llong_accurate} = "yes"; then + +$as_echo "#define LDOUBLE_TO_LLONG_ACCURATE 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +## ---------------------------------------------------------------------- +## Set the flag to indicate that the machine can accurately convert +## '(unsigned) long long' to 'long double' values. This flag should +## be set for all machines, except for IBM XL C compilers. Historically, +## this has also been a problem with OS X (version 10.4) but not current +## versions of that OS. +## +## When the bit sequences are 003fff..., 007fff..., 00ffff..., 01ffff..., +## ..., 7fffff..., the converted values are twice as big as they should be. +## +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if correctly converting (unsigned) long long to long double values" >&5 +$as_echo_n "checking if correctly converting (unsigned) long long to long double values... " >&6; } + +if test ${ac_cv_sizeof_long_double} = 0; then + hdf5_cv_llong_to_ldouble_correct=${hdf5_cv_llong_to_ldouble_correct=no} +else + if ${hdf5_cv_llong_to_ldouble_correct+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run test program while cross compiling +See \`config.log' for more details" "$LINENO" 5; } +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + int main(void) + { + long double ld; + long long ll; + unsigned long long ull; + unsigned char s[16]; + int flag=0, ret=0; + + /*Determine if long double has 16 byte in size, 11 bit exponent, and + *the bias is 0x3ff */ + if(sizeof(long double) == 16) { + ld = 1.0L; + memcpy(s, &ld, 16); + if(s[0]==0x3f && s[1]==0xf0 && s[2]==0x00 && s[3]==0x00 && + s[4]==0x00 && s[5]==0x00 && s[6]==0x00 && s[7]==0x00) + flag = 1; + } + + if(flag==1 && sizeof(long long)==8) { + ll = 0x01ffffffffffffffLL; + ld = (long double)ll; + memcpy(s, &ld, 16); + /*Check if the bit sequence is as supposed to be*/ + if(s[0]!=0x43 || s[1]!=0x7f || s[2]!=0xff || s[3]!=0xff || + s[4]!=0xff || s[5]!=0xff || s[6]!=0xff || s[7]!=0xff || + s[8]!=0xf0 || s[9]!=0x00 || s[10]!=0x00 || s[11]!=0x00) + ret = 1; + } + if(flag==1 && sizeof(unsigned long long)==8) { + ull = 0x01ffffffffffffffULL; + ld = (long double)ull; + memcpy(s, &ld, 16); + if(s[0]!=0x43 || s[1]!=0x7f || s[2]!=0xff || s[3]!=0xff || + s[4]!=0xff || s[5]!=0xff || s[6]!=0xff || s[7]!=0xff || + s[8]!=0xf0 || s[9]!=0x00 || s[10]!=0x00 || s[11]!=0x00) + ret = 1; + } + done: + exit(ret); + } + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + hdf5_cv_llong_to_ldouble_correct=yes +else + hdf5_cv_llong_to_ldouble_correct=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi + +fi + +if test ${hdf5_cv_llong_to_ldouble_correct} = "yes"; then + +$as_echo "#define LLONG_TO_LDOUBLE_CORRECT 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +## ---------------------------------------------------------------------- ## Set some variables for general configuration information to be saved ## and installed with the libraries (used to generate libhdf5.settings). ## diff --git a/configure.ac b/configure.ac index 26f3d88..c15071f 100644 --- a/configure.ac +++ b/configure.ac @@ -2213,6 +2213,27 @@ else fi ## ---------------------------------------------------------------------- +## Decide whether the data accuracy has higher priority during data +## conversions. If not, some hard conversions will still be prefered even +## though the data may be wrong (for example, some compilers don't +## support denormalized floating values) to maximize speed. +## +AC_MSG_CHECKING([whether data accuracy is guaranteed during data conversions]) +AC_ARG_ENABLE([dconv-accuracy], + [AS_HELP_STRING([--enable-dconv-accuracy], + [if data accuracy is guaranteed during + data conversions [default=yes]])], + [DATA_ACCURACY=$enableval], [DATA_ACCURACY=yes]) + +if test "$DATA_ACCURACY" = "yes"; then + AC_MSG_RESULT([yes]) + AC_DEFINE([WANT_DATA_ACCURACY], [1], + [Data accuracy is prefered to speed during data conversions]) +else + AC_MSG_RESULT([no]) +fi + +## ---------------------------------------------------------------------- ## Set the flag to indicate that the machine has window style pathname, ## that is, "drive-letter:\" (e.g. "C:") or "drive-letter:/" (e.g. "C:/"). ## (This flag should be _unset_ for all machines, except for Windows, where @@ -2392,6 +2413,142 @@ else fi ## ---------------------------------------------------------------------- +## Set the flag to indicate that the machine can accurately convert +## 'long double' to '(unsigned) long long' values. This flag should +## be set for all machines, except for IBM XL C compilers. Historically, +## this has also been a problem with OS X (version 10.4) but not current +## versions of that OS. +## +## When the bit sequence of long double is 0x4351ccf385ebc8a0bfcc2a3c..., +## the values of (unsigned)long long start to go wrong on these +## two machines. Adjusting it higher to 0x4351ccf385ebc8a0dfcc... or +## 0x4351ccf385ebc8a0ffcc... will make the converted values wildly wrong. +## This test detects this wrong behavior and disable the test. +## +AC_MSG_CHECKING([if correctly converting long double to (unsigned) long long values]) + +if test ${ac_cv_sizeof_long_double} = 0; then + hdf5_cv_ldouble_to_llong_accurate=${hdf5_cv_ldouble_to_llong_accurate=no} +else + AC_CACHE_VAL([hdf5_cv_ldouble_to_llong_accurate], + [AC_TRY_RUN([ + int main(void) + { + long double ld = 20041683600089727.779961L; + long long ll; + unsigned long long ull; + unsigned char s[16]; + int ret = 0; + + if(sizeof(long double) == 16) { + /*make sure the long double type is the same as the failing type + *which has 16 bytes in size and 11 bits of exponent. If it is, + *the bit sequence should be like below. It's not + *a decent way to check but this info isn't available. */ + memcpy(s, &ld, 16); + if(s[0]==0x43 && s[1]==0x51 && s[2]==0xcc && s[3]==0xf3 && + s[4]==0x85 && s[5]==0xeb && s[6]==0xc8 && s[7]==0xa0 && + s[8]==0xbf && s[9]==0xcc && s[10]==0x2a && s[11]==0x3c) { + + /*slightly adjust the bit sequence (s[8]=0xdf). The converted + *values will go wild on Mac OS 10.4 and IRIX64 6.5.*/ + s[0]=0x43; s[1]=0x51; s[2]=0xcc; s[3]=0xf3; + s[4]=0x85; s[5]=0xeb; s[6]=0xc8; s[7]=0xa0; + s[8]=0xdf; s[9]=0xcc; s[10]=0x2a; s[11]=0x3c; + s[12]=0x3d; s[13]=0x85; s[14]=0x56; s[15]=0x20; + + memcpy(&ld, s, 16); + ll = (long long)ld; + ull = (unsigned long long)ld; + + if(ll != 20041683600089728 || ull != 20041683600089728) + ret = 1; + } + } + done: + exit(ret); + } + ], [hdf5_cv_ldouble_to_llong_accurate=yes], [hdf5_cv_ldouble_to_llong_accurate=no],)]) +fi + +if test ${hdf5_cv_ldouble_to_llong_accurate} = "yes"; then + AC_DEFINE([LDOUBLE_TO_LLONG_ACCURATE], [1], + [Define if your system can convert long double to (unsigned) long long values correctly.]) + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi + + +## ---------------------------------------------------------------------- +## Set the flag to indicate that the machine can accurately convert +## '(unsigned) long long' to 'long double' values. This flag should +## be set for all machines, except for IBM XL C compilers. Historically, +## this has also been a problem with OS X (version 10.4) but not current +## versions of that OS. +## +## When the bit sequences are 003fff..., 007fff..., 00ffff..., 01ffff..., +## ..., 7fffff..., the converted values are twice as big as they should be. +## +AC_MSG_CHECKING([if correctly converting (unsigned) long long to long double values]) + +if test ${ac_cv_sizeof_long_double} = 0; then + hdf5_cv_llong_to_ldouble_correct=${hdf5_cv_llong_to_ldouble_correct=no} +else + AC_CACHE_VAL([hdf5_cv_llong_to_ldouble_correct], + [AC_TRY_RUN([ + int main(void) + { + long double ld; + long long ll; + unsigned long long ull; + unsigned char s[16]; + int flag=0, ret=0; + + /*Determine if long double has 16 byte in size, 11 bit exponent, and + *the bias is 0x3ff */ + if(sizeof(long double) == 16) { + ld = 1.0L; + memcpy(s, &ld, 16); + if(s[0]==0x3f && s[1]==0xf0 && s[2]==0x00 && s[3]==0x00 && + s[4]==0x00 && s[5]==0x00 && s[6]==0x00 && s[7]==0x00) + flag = 1; + } + + if(flag==1 && sizeof(long long)==8) { + ll = 0x01ffffffffffffffLL; + ld = (long double)ll; + memcpy(s, &ld, 16); + /*Check if the bit sequence is as supposed to be*/ + if(s[0]!=0x43 || s[1]!=0x7f || s[2]!=0xff || s[3]!=0xff || + s[4]!=0xff || s[5]!=0xff || s[6]!=0xff || s[7]!=0xff || + s[8]!=0xf0 || s[9]!=0x00 || s[10]!=0x00 || s[11]!=0x00) + ret = 1; + } + if(flag==1 && sizeof(unsigned long long)==8) { + ull = 0x01ffffffffffffffULL; + ld = (long double)ull; + memcpy(s, &ld, 16); + if(s[0]!=0x43 || s[1]!=0x7f || s[2]!=0xff || s[3]!=0xff || + s[4]!=0xff || s[5]!=0xff || s[6]!=0xff || s[7]!=0xff || + s[8]!=0xf0 || s[9]!=0x00 || s[10]!=0x00 || s[11]!=0x00) + ret = 1; + } + done: + exit(ret); + } + ], [hdf5_cv_llong_to_ldouble_correct=yes], [hdf5_cv_llong_to_ldouble_correct=no],)]) +fi + +if test ${hdf5_cv_llong_to_ldouble_correct} = "yes"; then + AC_DEFINE([LLONG_TO_LDOUBLE_CORRECT], [1], + [Define if your system can convert (unsigned) long long to long double values correctly.]) + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi + +## ---------------------------------------------------------------------- ## Set some variables for general configuration information to be saved ## and installed with the libraries (used to generate libhdf5.settings). ## diff --git a/release_docs/INSTALL_CMake.txt b/release_docs/INSTALL_CMake.txt index df6291f..fc4cdcc 100644 --- a/release_docs/INSTALL_CMake.txt +++ b/release_docs/INSTALL_CMake.txt @@ -591,6 +591,7 @@ HDF5_STRICT_FORMAT_CHECKS "Whether to perform strict file format checks" HDF5_TEST_VFD "Execute tests with different VFDs" OFF HDF5_USE_16_API_DEFAULT "Use the HDF5 1.6.x API by default" OFF HDF5_USE_FOLDERS "Enable folder grouping of projects in IDEs." OFF +HDF5_WANT_DATA_ACCURACY "IF data accuracy is guaranteed during data conversions" ON HDF5_WANT_DCONV_EXCEPTION "exception handling functions is checked during data conversions" ON HDF5_ENABLE_THREADSAFE "Enable Threadsafety" OFF if (APPLE) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 7ddbd05..92e8fdc 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -170,13 +170,6 @@ New Features (DER - 2015/09/09 HDFFV-9188) - - Removed WANT_DATA_ACCURACY symbol and associated code from the - library. - - This is no longer attached to any supported platforms. - - (DER - 2015/09/09 HDFFV-9194) - - Removed _BSD_SOURCE and _DEFAULT_SOURCE from configure.ac These are old BSD-compatibility symbols that are no longer needed by @@ -192,24 +185,6 @@ New Features (DER - 2015/09/10 HDFFV-9189) - - Removed LDOUBLE_TO_LLONG_ACCURATE symbol and associated code from the - library. - - This was part of a work-around for VS.NET 2003, 64-bit IRIX 6.5, - OS X 10.4, and some versions of HP/UX, none of which are currently - supported. - - (DER - 2015/09/10 HDFFV-9192) - - - Removed LLONG_TO_LDOUBLE_CORRECT symbol and associated code from the - library. - - This was a part of a work-around for Visual Studio 6, OS X 10.4, - IRIX 6.5, and very old versions of FreeBSD and 64-bit Solaris. None - of these platforms/compilers are currently supported. - - (DER - 2015/09/10 HDFFV-9193) - - Removed the BAD_LOG2_CODE_GENERATED symbol and associated code from the library. diff --git a/src/H5T.c b/src/H5T.c index 1eab57f..29d8f40 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -1224,12 +1224,16 @@ H5T_init_interface(void) /* From long long to floats */ status |= H5T_register(H5T_PERS_HARD, "llong_flt", native_llong, native_float, H5T__conv_llong_float, H5AC_ind_dxpl_id, FALSE); status |= H5T_register(H5T_PERS_HARD, "llong_dbl", native_llong, native_double, H5T__conv_llong_double, H5AC_ind_dxpl_id, FALSE); +#ifdef H5T_CONV_INTERNAL_LLONG_LDOUBLE status |= H5T_register(H5T_PERS_HARD, "llong_ldbl", native_llong, native_ldouble, H5T__conv_llong_ldouble, H5AC_ind_dxpl_id, FALSE); +#endif /* H5T_CONV_INTERNAL_LLONG_LDOUBLE */ /* From unsigned long long to floats */ status |= H5T_register(H5T_PERS_HARD, "ullong_flt", native_ullong, native_float, H5T__conv_ullong_float, H5AC_ind_dxpl_id, FALSE); status |= H5T_register(H5T_PERS_HARD, "ullong_dbl", native_ullong, native_double, H5T__conv_ullong_double, H5AC_ind_dxpl_id, FALSE); +#ifdef H5T_CONV_INTERNAL_ULLONG_LDOUBLE status |= H5T_register(H5T_PERS_HARD, "ullong_ldbl", native_ullong, native_ldouble, H5T__conv_ullong_ldouble, H5AC_ind_dxpl_id, FALSE); +#endif /* H5T_CONV_INTERNAL_ULLONG_LDOUBLE */ /* From floats to char */ status |= H5T_register(H5T_PERS_HARD, "flt_schar", native_float, native_schar, H5T__conv_float_schar, H5AC_ind_dxpl_id, FALSE); @@ -1273,12 +1277,16 @@ H5T_init_interface(void) /* From floats to long long */ status |= H5T_register(H5T_PERS_HARD, "flt_llong", native_float, native_llong, H5T__conv_float_llong, H5AC_ind_dxpl_id, FALSE); status |= H5T_register(H5T_PERS_HARD, "dbl_llong", native_double, native_llong, H5T__conv_double_llong, H5AC_ind_dxpl_id, FALSE); +#ifdef H5T_CONV_INTERNAL_LDOUBLE_LLONG status |= H5T_register(H5T_PERS_HARD, "ldbl_llong", native_ldouble, native_llong, H5T__conv_ldouble_llong, H5AC_ind_dxpl_id, FALSE); +#endif /* H5T_CONV_INTERNAL_LDOUBLE_LLONG */ /* From floats to unsigned long long */ status |= H5T_register(H5T_PERS_HARD, "flt_ullong", native_float, native_ullong, H5T__conv_float_ullong, H5AC_ind_dxpl_id, FALSE); status |= H5T_register(H5T_PERS_HARD, "dbl_ullong", native_double, native_ullong, H5T__conv_double_ullong, H5AC_ind_dxpl_id, FALSE); +#if H5T_CONV_INTERNAL_LDOUBLE_ULLONG status |= H5T_register(H5T_PERS_HARD, "ldbl_ullong", native_ldouble, native_ullong, H5T__conv_ldouble_ullong, H5AC_ind_dxpl_id, FALSE); +#endif /* H5T_CONV_INTERNAL_LDOUBLE_ULLONG */ /* * The special no-op conversion is the fastest, so we list it last. The diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 63f0e8e..49bfeec 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -7904,6 +7904,7 @@ H5T__conv_llong_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, * *------------------------------------------------------------------------- */ +#if H5T_CONV_INTERNAL_LLONG_LDOUBLE herr_t H5T__conv_llong_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, size_t buf_stride, @@ -7912,6 +7913,7 @@ H5T__conv_llong_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, { H5T_CONV_xF(LLONG, LDOUBLE, long long, long double, -, -); } +#endif /* H5T_CONV_INTERNAL_LLONG_LDOUBLE */ /*------------------------------------------------------------------------- @@ -7979,6 +7981,7 @@ H5T__conv_ullong_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, * *------------------------------------------------------------------------- */ +#if H5T_CONV_INTERNAL_ULLONG_LDOUBLE herr_t H5T__conv_ullong_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, size_t buf_stride, @@ -7987,6 +7990,7 @@ H5T__conv_ullong_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, { H5T_CONV_xF(ULLONG, LDOUBLE, unsigned long long, long double, -, -); } +#endif /*H5T_CONV_INTERNAL_ULLONG_LDOUBLE*/ /*------------------------------------------------------------------------- @@ -8756,6 +8760,7 @@ H5T__conv_double_ullong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, * *------------------------------------------------------------------------- */ +#if H5T_CONV_INTERNAL_LDOUBLE_LLONG herr_t H5T__conv_ldouble_llong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, size_t buf_stride, @@ -8766,6 +8771,7 @@ H5_GCC_DIAG_OFF(float-equal) H5T_CONV_Fx(LDOUBLE, LLONG, long double, long long, LLONG_MIN, LLONG_MAX); H5_GCC_DIAG_ON(float-equal) } +#endif /*H5T_CONV_INTERNAL_LDOUBLE_LLONG*/ /*------------------------------------------------------------------------- @@ -8783,6 +8789,7 @@ H5_GCC_DIAG_ON(float-equal) * *------------------------------------------------------------------------- */ +#if H5T_CONV_INTERNAL_LDOUBLE_ULLONG herr_t H5T__conv_ldouble_ullong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, size_t buf_stride, @@ -8791,6 +8798,7 @@ H5T__conv_ldouble_ullong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, { H5T_CONV_Fx(LDOUBLE, ULLONG, long double, unsigned long long, 0, ULLONG_MAX); } +#endif /*H5T_CONV_INTERNAL_LDOUBLE_ULLONG*/ /*------------------------------------------------------------------------- diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h index 4697bfc..0b0cd61 100644 --- a/src/H5Tpkg.h +++ b/src/H5Tpkg.h @@ -111,6 +111,39 @@ /* (_not_ setting H5T_VISIT_SIMPLE and setting either H5T_VISIT_COMPLEX_FIRST or H5T_VISIT_COMPLEX_LAST will mean visiting all nodes _except_ "simple" "leafs" in the "tree" */ +/* Define an internal macro for converting long long to long double. Mac OS 10.4 gives some + * incorrect conversions. */ +#if (H5_WANT_DATA_ACCURACY && defined(H5_LLONG_TO_LDOUBLE_CORRECT)) || (!H5_WANT_DATA_ACCURACY) +#define H5T_CONV_INTERNAL_LLONG_LDOUBLE 1 +#endif + +/* Define an internal macro for converting unsigned long long to long double. SGI compilers give + * some incorect conversion. 64-bit Solaris does different rounding. Windows Visual Studio 6 does + * not support unsigned long long. For FreeBSD(sleipnir), the last 2 bytes of mantissa are lost when + * compiler tries to do the conversion. For Cygwin, compiler doesn't do rounding correctly. + * Mac OS 10.4 gives some incorrect result. */ +#if (H5_WANT_DATA_ACCURACY && defined(H5_LLONG_TO_LDOUBLE_CORRECT)) || (!H5_WANT_DATA_ACCURACY) +#define H5T_CONV_INTERNAL_ULLONG_LDOUBLE 1 +#endif + +/* Define an internal macro for converting long double to long long. SGI compilers give some incorrect + * conversions. Mac OS 10.4 gives incorrect conversions. HP-UX 11.00 compiler generates floating exception. + * The hard conversion on Windows .NET 2003 has a bug and gives wrong exception value. */ +#if (H5_WANT_DATA_ACCURACY && defined(H5_LDOUBLE_TO_LLONG_ACCURATE)) || \ + (!H5_WANT_DATA_ACCURACY) +#define H5T_CONV_INTERNAL_LDOUBLE_LLONG 1 +#endif + +/* Define an internal macro for converting long double to unsigned long long. SGI compilers give some + * incorrect conversions. Mac OS 10.4 gives incorrect conversions. HP-UX 11.00 compiler generates + * floating exception. */ +#if (H5_WANT_DATA_ACCURACY && defined(H5_LDOUBLE_TO_LLONG_ACCURATE)) || \ + (!H5_WANT_DATA_ACCURACY) +#define H5T_CONV_INTERNAL_LDOUBLE_ULLONG 1 +#else +#define H5T_CONV_INTERNAL_LDOUBLE_ULLONG 0 +#endif + /* Statistics about a conversion function */ struct H5T_stats_t { unsigned ncalls; /*num calls to conversion function */ diff --git a/src/H5config.h.in b/src/H5config.h.in index 60c2121..6075f3f 100644 --- a/src/H5config.h.in +++ b/src/H5config.h.in @@ -350,10 +350,18 @@ /* Define if HDF5's high-level library headers should be included in hdf5.h */ #undef INCLUDE_HL +/* Define if your system can convert long double to (unsigned) long long + values correctly. */ +#undef LDOUBLE_TO_LLONG_ACCURATE + /* Define if your system converts long double to (unsigned) long values with special algorithm. */ #undef LDOUBLE_TO_LONG_SPECIAL +/* Define if your system can convert (unsigned) long long to long double + values correctly. */ +#undef LLONG_TO_LDOUBLE_CORRECT + /* Define if your system can convert (unsigned) long to long double values with special algorithm. */ #undef LONG_TO_LDOUBLE_SPECIAL @@ -536,6 +544,9 @@ /* Version number of package */ #undef VERSION +/* Data accuracy is prefered to speed during data conversions */ +#undef WANT_DATA_ACCURACY + /* Check exception handling functions during data conversions */ #undef WANT_DCONV_EXCEPTION diff --git a/test/dt_arith.c b/test/dt_arith.c index 8e8ffba..4337690 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -4930,8 +4930,32 @@ run_int_fp_conv(const char *name) #endif #endif /* H5_SIZEOF_LONG!=H5_SIZEOF_INT */ #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG +#if H5_LLONG_TO_LDOUBLE_CORRECT nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_LLONG, H5T_NATIVE_LDOUBLE); +#else /* H5_LLONG_TO_LDOUBLE_CORRECT */ + { + char str[256]; /*hello string */ + + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", + name, "long long", "long double"); + printf("%-70s", str); + SKIPPED(); + HDputs(" Test skipped due to compiler error in handling conversion."); + } +#endif /* H5_LLONG_TO_LDOUBLE_CORRECT */ +#if H5_LLONG_TO_LDOUBLE_CORRECT nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_ULLONG, H5T_NATIVE_LDOUBLE); +#else /* H5_LLONG_TO_LDOUBLE_CORRECT */ + { + char str[256]; /*hello string */ + + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", + name, "unsigned long long", "long double"); + printf("%-70s", str); + SKIPPED(); + HDputs(" Test skipped due to compiler not handling conversion."); + } +#endif /* H5_LLONG_TO_LDOUBLE_CORRECT */ #endif #endif @@ -4979,15 +5003,15 @@ run_fp_int_conv(const char *name) nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_UINT); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_UINT); -#if H5_SIZEOF_LONG!=H5_SIZEOF_INT +#if H5_SIZEOF_LONG != H5_SIZEOF_INT nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_LONG); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_LONG); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_ULONG); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_ULONG); -#endif +#endif /* H5_SIZEOF_LONG != H5_SIZEOF_INT */ -#if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG +#if H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG if(!strcmp(name, "hw")) { /* Hardware conversion */ nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_LLONG); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_LLONG); @@ -4997,20 +5021,20 @@ run_fp_int_conv(const char *name) } nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_ULLONG); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_ULLONG); -#endif +#endif /* H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG */ -#if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE +#if H5_SIZEOF_LONG_DOUBLE != H5_SIZEOF_DOUBLE nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_SCHAR); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_UCHAR); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_SHORT); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_USHORT); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_INT); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_UINT); -#if H5_SIZEOF_LONG!=H5_SIZEOF_INT && H5_SIZEOF_LONG_DOUBLE!=0 +#if H5_SIZEOF_LONG != H5_SIZEOF_INT && H5_SIZEOF_LONG_DOUBLE != 0 #ifndef H5_LDOUBLE_TO_LONG_SPECIAL nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_LONG); nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_ULONG); -#else +#else /* H5_LDOUBLE_TO_LONG_SPECIAL */ { char str[256]; /*string */ @@ -5018,24 +5042,58 @@ run_fp_int_conv(const char *name) name, "long double", "(unsigned) long"); printf("%-70s", str); SKIPPED(); -#if H5_SIZEOF_LONG_DOUBLE!=0 +#if H5_SIZEOF_LONG_DOUBLE != 0 HDputs(" Test skipped due to the special algorithm of hardware conversion."); -#else +#else /* H5_SIZEOF_LONG_DOUBLE */ HDputs(" Test skipped due to disabled long double."); -#endif +#endif /* H5_SIZEOF_LONG_DOUBLE */ } -#endif -#endif /*H5_SIZEOF_LONG!=H5_SIZEOF_INT && H5_SIZEOF_LONG_DOUBLE!=0 */ +#endif /* H5_LDOUBLE_TO_LONG_SPECIAL */ -#if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG && H5_SIZEOF_LONG_DOUBLE!=0 +#endif /*H5_SIZEOF_LONG != H5_SIZEOF_INT && H5_SIZEOF_LONG_DOUBLE != 0 */ + +#if H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG && H5_SIZEOF_LONG_DOUBLE != 0 +#ifdef H5_LDOUBLE_TO_LLONG_ACCURATE nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_LLONG); +#else /*H5_LDOUBLE_TO_LLONG_ACCURATE*/ + { + char str[256]; /*string */ + + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", + name, "long double", "long long"); + printf("%-70s", str); + SKIPPED(); +#if H5_SIZEOF_LONG_DOUBLE != 0 + HDputs(" Test skipped due to hardware conversion error."); +#else /* H5_SIZEOF_LONG_DOUBLE != 0 */ + HDputs(" Test skipped due to disabled long double."); +#endif /* H5_SIZEOF_LONG_DOUBLE != 0 */ + } +#endif /*H5_LDOUBLE_TO_LLONG_ACCURATE*/ +#if defined(H5_LDOUBLE_TO_LLONG_ACCURATE) nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_ULLONG); -#endif -#endif +#else /*H5_LDOUBLE_TO_LLONG_ACCURATE*/ + { + char str[256]; /*string */ + + HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions", + name, "long double", "unsigned long long"); + printf("%-70s", str); + SKIPPED(); +#if H5_SIZEOF_LONG_DOUBLE != 0 + HDputs(" Test skipped due to hardware conversion error."); +#else /* H5_SIZEOF_LONG_DOUBLE != 0 */ + HDputs(" Test skipped due to disabled long double."); +#endif /* H5_SIZEOF_LONG_DOUBLE !=0 */ + } +#endif /*H5_LDOUBLE_TO_LLONG_ACCURATE*/ + +#endif /* H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG && H5_SIZEOF_LONG_DOUBLE != 0 */ +#endif /* H5_SIZEOF_LONG_DOUBLE != H5_SIZEOF_DOUBLE */ } /* end for */ return nerrors; -} +} /* end run_fp_int_conv() */ /*------------------------------------------------------------------------- -- cgit v0.12