[m-rev.] diff: speed up is_finite/1 and is_nan/1 in C grades

Julien Fischer jfischer at opturion.com
Fri Sep 19 20:53:09 AEST 2014


On Fri, 19 Sep 2014, Julien Fischer wrote:

>> float.m: In function ‘float_module22’:
>> float.m:718:5: warning: implicit declaration of function ‘isinf’ 
>> [-Wimplicit-function-declaration]
>> float.m: In function ‘float_module23’:
>> float.m:680:5: warning: implicit declaration of function ‘isnan’ 
>> [-Wimplicit-function-declaration]
>> float.m: In function ‘float_module26’:
>> float.m:753:5: warning: implicit declaration of function ‘finite’ 
>> [-Wimplicit-function-declaration]
>> 
>> Not sure what the fix should be.
>
> The immediate fix is to only use the macro versions if we are using C99.

I've committed the following which implements the immediate fix
described above.  I look into disabling the use of -ansi with GCC by
default separately.

Cheers,
Julien.

Fix problems with gcc -ansi.

runtime/mercury_float.h:
 	Only define MR_is_{nan,infinite,finite} as macros on systems that
 	support C99.

diff --git a/runtime/mercury_float.h b/runtime/mercury_float.h
index 91b91e6..b3dae3a 100644
--- a/runtime/mercury_float.h
+++ b/runtime/mercury_float.h
@@ -211,38 +211,39 @@ void MR_sprintf_float(char *buf, MR_Float f);
  MR_Integer MR_hash_float(MR_Float);

  /*
-** We define MR_is_{nan,infinite} as macros if we support the relevant bits
-** of C99 since the resulting code is faster.
+** We define MR_is_{nan,infinite,finite} as macros if we support C99 
+** since the resulting code is faster.
  */
-#if defined(MR_USE_SINGLE_PREC_FLOAT) && defined(MR_HAVE_ISNANF)
-    #define MR_is_nan(f) isnanf((f))
-#elif defined(MR_HAVE_ISNAN)
-    #define MR_is_nan(f) isnan((f))
+#if __STDC_VERSION__ >= 199901
+    #if defined(MR_USE_SINGLE_PREC_FLOAT)
+        #define MR_is_nan(f) isnanf((f))
+    #else
+        #define MR_is_nan(f) isnan((f))
+    #endif
  #else
-    #define MR_is_nan(f) MS_is_nan_func((f))
+    #define MR_is_nan(f) MR_is_nan_func((f))
  #endif

  /*
  ** See comments for function MR_is_infinite_func in mercury_float.c for the
  ** handling of Solaris here.
  */
-#if defined(MR_USE_SINGLE_PREC_FLOAT) && defined(MR_HAVE_ISINFF) && !defined(MR_SOLARIS)
-    #define MR_is_infinite(f) isinff((f))
-#elif defined(MR_HAVE_ISINF) && !defined(MR_SOLARIS)
-    #define MR_is_infinite(f) isinf((f))
+#if __STDC_VERSION__ >= 199901 && !defined(MR_SOLARIS)
+    #if defined(MR_USE_SINGLE_PREC_FLOAT)
+        #define MR_is_infinite(f) isinff((f))
+    #else
+        #define MR_is_infinite(f) isinf((f))
+    #endif
  #else
      #define MR_is_infinite(f) MR_is_infinite_func((f))
  #endif

  /*
  ** XXX I don't know whether isfinite works on Solaris or not.
-** The finite function apparently does, so we use that instead.
  */
-#if defined(MR_HAVE_ISFINITE) && !defined(MR_SOLARIS)
+#if __STDC_VERSION__ >= 199901 && !defined(MR_SOLARIS)
      #define MR_is_finite(f) isfinite((f))
-#elif defined(MR_HAVE_FINITE)
-    #define MR_is_finite(f) finite((f))
-#else
+#else
      #define MR_is_finite(f) (!MR_is_infinite((f)) && !MR_is_nan((f)))
  #endif


More information about the reviews mailing list