From da4c91583fc9808150682bed866f24fdf2ee3cfe Mon Sep 17 00:00:00 2001 From: Erik Lindahl Date: Sun, 16 Aug 2015 13:06:56 +0200 Subject: [PATCH] Fix FP exception in reference build The introduction of the r=0 case for a bond in the complex/nbnxn_rzero test case in combination with FP exceptions being enabled lead to an exception being thrown in the bondeds routine when using the reference build type. Fixed by adding a check that x>0 and otherwise return zero when NDEBUG is not set. Change-Id: If93808e42bb671ef3fd35cc145f2c42807e4d65e --- src/gromacs/gmxlib/copyrite.cpp | 2 +- src/gromacs/math/vec.h | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/gromacs/gmxlib/copyrite.cpp b/src/gromacs/gmxlib/copyrite.cpp index c8ad397cb1..e15940ba04 100644 --- a/src/gromacs/gmxlib/copyrite.cpp +++ b/src/gromacs/gmxlib/copyrite.cpp @@ -731,7 +731,7 @@ static void gmx_print_version_info(FILE *fp) /* A preprocessor trick to avoid duplicating logic from vec.h */ #define gmx_stringify2(x) #x #define gmx_stringify(x) gmx_stringify2(x) - fprintf(fp, "invsqrt routine: %s\n", gmx_stringify(gmx_invsqrt(x))); + fprintf(fp, "invsqrt routine: %s\n", gmx_stringify(gmx_invsqrt_impl(x))); fprintf(fp, "SIMD instructions: %s\n", GMX_SIMD_STRING); fprintf(fp, "FFT library: %s\n", gmx_fft_get_version_info()); #ifdef HAVE_RDTSCP diff --git a/src/gromacs/math/vec.h b/src/gromacs/math/vec.h index 17ef70662e..af5212ee17 100644 --- a/src/gromacs/math/vec.h +++ b/src/gromacs/math/vec.h @@ -174,30 +174,36 @@ static gmx_inline real gmx_software_invsqrt(real x) return y; /* 5 Flops */ #endif } -#define gmx_invsqrt(x) gmx_software_invsqrt(x) + +#define gmx_invsqrt_impl(x) gmx_software_invsqrt(x) #define INVSQRT_DONE #endif /* gmx_invsqrt */ #ifndef INVSQRT_DONE # ifdef GMX_DOUBLE # ifdef HAVE_RSQRT -# define gmx_invsqrt(x) rsqrt(x) +# define gmx_invsqrt_impl(x) rsqrt(x) # else -# define gmx_invsqrt(x) (1.0/sqrt(x)) +# define gmx_invsqrt_impl(x) (1.0/sqrt(x)) # endif # else /* single */ # ifdef HAVE_RSQRTF -# define gmx_invsqrt(x) rsqrtf(x) +# define gmx_invsqrt_impl(x) rsqrtf(x) # elif defined HAVE_RSQRT -# define gmx_invsqrt(x) rsqrt(x) +# define gmx_invsqrt_impl(x) rsqrt(x) # elif defined HAVE_SQRTF -# define gmx_invsqrt(x) (1.0/sqrtf(x)) +# define gmx_invsqrt_impl(x) (1.0/sqrtf(x)) # else -# define gmx_invsqrt(x) (1.0/sqrt(x)) +# define gmx_invsqrt_impl(x) (1.0/sqrt(x)) # endif # endif #endif +#ifdef NDEBUG +# define gmx_invsqrt(x) gmx_invsqrt_impl(x) +#else +# define gmx_invsqrt(x) ( (x > 0) ? gmx_invsqrt_impl(x) : 0.0 ) +#endif static gmx_inline real sqr(real x) { -- 2.11.4.GIT