Fix FP exception in reference build
authorErik Lindahl <erik@kth.se>
Sun, 16 Aug 2015 11:06:56 +0000 (13:06 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 29 Aug 2015 03:23:52 +0000 (05:23 +0200)
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
src/gromacs/math/vec.h

index c8ad397cb1832f21b559824dc74029d913c487d2..e15940ba04a698948e5955356076f9fcf20ba84f 100644 (file)
@@ -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
index 17ef70662e5eb3ee4d100686e8e40d533fcd8161..af5212ee17fcc8c7d5458b6182ea44ff8d3b7ebf 100644 (file)
@@ -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)
 {