From 91e6f1e04de956b44c89ebaaeff5d9e91d8355c4 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Wed, 19 Aug 2009 16:57:12 -0500 Subject: [svn-r17387] I added a detection for the correctness of converting from unsigned long to float in the configure.in. The Pathscale compiler on Sandia's Linux machine misinterprets the values of unsigned long as negative during the conversion to float, when the first bit of unsigned long is on. Tested on jam. Need to test it on Sandia's machine. --- configure | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++- configure.in | 50 +++++++++++++++++++++++++++ src/H5T.c | 6 ++-- src/H5Tconv.c | 8 ++--- src/H5Tpkg.h | 12 +++++-- src/H5config.h.in | 4 +++ 6 files changed, 172 insertions(+), 9 deletions(-) diff --git a/configure b/configure index d3cf674..66b4a75 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Id: configure.in 17339 2009-08-12 02:27:55Z lrknox . +# From configure.in Id: configure.in 17368 2009-08-16 22:06:45Z lrknox . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for HDF5 1.8.3-snap7. # @@ -50650,6 +50650,105 @@ else echo "${ECHO_T}no" >&6; } fi +{ echo "$as_me:$LINENO: checking if accurately converting unsigned long to float values" >&5 +echo $ECHO_N "checking if accurately converting unsigned long to float values... $ECHO_C" >&6; } + +if test "${hdf5_ulong_to_float_accurate+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + int main(void) + { + int ret = 0; + unsigned long l1; + unsigned long l2; + unsigned long l3; + float f1; + float f2; + float f3; + + + if(sizeof(unsigned long)==8) { + l1 = 0xffffffffffffffffUL; + l2 = 0xffffffffffff0000UL; + l3 = 0xf000000000000000UL; + + f1 = (float)l1; + f2 = (float)l2; + f3 = (float)l3; + + if((f1 < 0) || (f2 < 0) || (f3 < 0)) + ret = 1; + } + +done: + exit(ret); + } + +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + hdf5_ulong_to_float_accurate=yes +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +hdf5_ulong_to_float_accurate=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + +fi + + +if test ${hdf5_ulong_to_float_accurate} = "yes"; then + +cat >>confdefs.h <<\_ACEOF +#define ULONG_TO_FLOAT_ACCURATE 1 +_ACEOF + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + { echo "$as_me:$LINENO: checking if accurately converting unsigned long long to floating-point values" >&5 echo $ECHO_N "checking if accurately converting unsigned long long to floating-point values... $ECHO_C" >&6; } diff --git a/configure.in b/configure.in index bd6bfc2..23c74ee 100644 --- a/configure.in +++ b/configure.in @@ -3063,6 +3063,56 @@ fi dnl ---------------------------------------------------------------------- dnl Set the flag to indicate that the machine can accurately convert +dnl 'unsigned long' to 'float' values. +dnl (This flag should be set for all machines, except for Pathscale compiler +dnl on Sandia's Linux machine where the compiler interprets 'unsigned long' +dnl values as negative when the first bit of 'unsigned long' is on during +dnl the conversion to float.) +dnl +AC_MSG_CHECKING([if accurately converting unsigned long to float values]) + +AC_CACHE_VAL([hdf5_ulong_to_float_accurate], + [AC_TRY_RUN([ + int main(void) + { + int ret = 0; + unsigned long l1; + unsigned long l2; + unsigned long l3; + float f1; + float f2; + float f3; + + + if(sizeof(unsigned long)==8) { + l1 = 0xffffffffffffffffUL; + l2 = 0xffffffffffff0000UL; + l3 = 0xf000000000000000UL; + + f1 = (float)l1; + f2 = (float)l2; + f3 = (float)l3; + + if((f1 < 0) || (f2 < 0) || (f3 < 0)) + ret = 1; + } + +done: + exit(ret); + } + ], [hdf5_ulong_to_float_accurate=yes], [hdf5_ulong_to_float_accurate=no],)]) + +if test ${hdf5_ulong_to_float_accurate} = "yes"; then + AC_DEFINE([ULONG_TO_FLOAT_ACCURATE], [1], + [Define if your system accurately converting unsigned long to float values.]) + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi + + +dnl ---------------------------------------------------------------------- +dnl Set the flag to indicate that the machine can accurately convert dnl 'unsigned (long) long' values to 'float' and 'double' values. dnl (This flag should be set for all machines, except for the SGIs, where dnl the cache value is set in the config/irix6.x config file) and Solaris diff --git a/src/H5T.c b/src/H5T.c index 4b710d3..1e30f77 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -1198,10 +1198,12 @@ H5T_init_interface(void) #endif /* H5T_CONV_INTERNAL_INTEGER_LDOUBLE */ /* From unsigned long to floats */ -#if H5T_CONV_INTERNAL_ULONG_FP +#if H5T_CONV_INTERNAL_ULONG_FLT status |= H5T_register(H5T_PERS_HARD, "ulong_flt", native_ulong, native_float, H5T_conv_ulong_float, H5AC_dxpl_id, FALSE); +#endif /* H5T_CONV_INTERNAL_ULONG_FLT */ +#if H5T_CONV_INTERNAL_ULONG_DBL status |= H5T_register(H5T_PERS_HARD, "ulong_dbl", native_ulong, native_double, H5T_conv_ulong_double, H5AC_dxpl_id, FALSE); -#endif /* H5T_CONV_INTERNAL_ULONG_FP */ +#endif /* H5T_CONV_INTERNAL_ULONG_DBL */ #if H5T_CONV_INTERNAL_ULONG_LDOUBLE status |= H5T_register(H5T_PERS_HARD, "ulong_ldbl", native_ulong, native_ldouble, H5T_conv_ulong_ldouble, H5AC_dxpl_id, FALSE); #endif /* H5T_CONV_INTERNAL_ULONG_LDOUBLE */ diff --git a/src/H5Tconv.c b/src/H5Tconv.c index c621bf4..08e7fa1 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -8417,7 +8417,7 @@ done: * *------------------------------------------------------------------------- */ -#if H5T_CONV_INTERNAL_ULONG_FP +#if H5T_CONV_INTERNAL_ULONG_FLT herr_t H5T_conv_ulong_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, size_t buf_stride, @@ -8433,7 +8433,7 @@ H5T_conv_ulong_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, done: FUNC_LEAVE_NOAPI(ret_value) } -#endif /* H5T_CONV_INTERNAL_ULONG_FP */ +#endif /* H5T_CONV_INTERNAL_ULONG_FLT */ /*------------------------------------------------------------------------- @@ -8451,7 +8451,7 @@ done: * *------------------------------------------------------------------------- */ -#if H5T_CONV_INTERNAL_ULONG_FP +#if H5T_CONV_INTERNAL_ULONG_DBL herr_t H5T_conv_ulong_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, size_t buf_stride, @@ -8467,7 +8467,7 @@ H5T_conv_ulong_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, done: FUNC_LEAVE_NOAPI(ret_value) } -#endif /* H5T_CONV_INTERNAL_ULONG_FP */ +#endif /* H5T_CONV_INTERNAL_ULONG_DBL */ /*------------------------------------------------------------------------- diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h index 7ef4b63..18bf7cf 100644 --- a/src/H5Tpkg.h +++ b/src/H5Tpkg.h @@ -133,10 +133,18 @@ #define H5T_CONV_INTERNAL_INTEGER_LDOUBLE 1 #endif -/* Define an internal macro for converting unsigned (long) long to floating numbers. +/* Define an internal macro for converting unsigned long to float. + * Pathscale compiler on Sandia's Linux machine has some problem. + * 64-bit Solaris does different rounding. */ +#if (H5_WANT_DATA_ACCURACY && H5_ULONG_TO_FLOAT_ACCURATE && H5_ULONG_TO_FP_BOTTOM_BIT_ACCURATE) || \ + (!H5_WANT_DATA_ACCURACY) +#define H5T_CONV_INTERNAL_ULONG_FLT 1 +#endif + +/* Define an internal macro for converting unsigned (long) long to double. * 64-bit Solaris does different rounding. */ #if (H5_WANT_DATA_ACCURACY && H5_ULONG_TO_FP_BOTTOM_BIT_ACCURATE) || (!H5_WANT_DATA_ACCURACY) -#define H5T_CONV_INTERNAL_ULONG_FP 1 +#define H5T_CONV_INTERNAL_ULONG_DBL 1 #endif /* Define an internal macro for converting unsigned long to long double. SGI compilers give some diff --git a/src/H5config.h.in b/src/H5config.h.in index 8ac19fc..ca73c6a 100644 --- a/src/H5config.h.in +++ b/src/H5config.h.in @@ -614,6 +614,10 @@ correct precision. */ #undef ULLONG_TO_LDOUBLE_PRECISION +/* Define if your system accurately converting unsigned long to float values. + */ +#undef ULONG_TO_FLOAT_ACCURATE + /* Define if your system can accurately convert unsigned (long) long values to floating-point values. */ #undef ULONG_TO_FP_BOTTOM_BIT_ACCURATE -- cgit v0.12