[basic-improvements] Use double instead of float for timevar

Matt Austern austern@apple.com
Fri Nov 8 13:47:00 GMT 2002


As mentioned on gcc@gcc.gnu.org: timevar works by storing
various times as 'float' values, and then subtracting them
to get time intervals.

This is a very bad idea.  On most platforms, float only
gives you 24 bits of precision.  Subtract two largish
24-bit numbers and you'll often be left with nothing but
noise.

Here's a patch to use double instead of float, tested on
ppc/darwin.  OK to commit to BIB?


			--Matt


	* timevar.[ch]: Use double instead of float for time stamps.

Index: gcc/timevar.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/timevar.c,v
retrieving revision 1.20.8.2
diff -u -r1.20.8.2 timevar.c
--- gcc/timevar.c	15 Oct 2002 01:33:01 -0000	1.20.8.2
+++ gcc/timevar.c	8 Nov 2002 21:42:20 -0000
@@ -100,13 +100,13 @@
     precompute them.  Whose wonderful idea was it to make all those
     _constants_ variable at run time, anyway?  */
  #ifdef USE_TIMES
-static float ticks_to_msec;
-#define TICKS_TO_MSEC (1 / (float)TICKS_PER_SECOND)
+static double ticks_to_msec;
+#define TICKS_TO_MSEC (1 / (double)TICKS_PER_SECOND)
  #endif

  #ifdef USE_CLOCK
-static float clocks_to_msec;
-#define CLOCKS_TO_MSEC (1 / (float)CLOCKS_PER_SEC)
+static double clocks_to_msec;
+#define CLOCKS_TO_MSEC (1 / (double)CLOCKS_PER_SEC)
  #endif

  #include "flags.h"
@@ -449,7 +449,7 @@
    for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id)
      {
        struct timevar_def *tv = &timevars[(timevar_id_t) id];
-      const float tiny = 5e-3;
+      const double tiny = 5e-3;

        /* Don't print the total execution time here; that goes at the
  	 end.  */
Index: gcc/timevar.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/timevar.h,v
retrieving revision 1.8
diff -u -r1.8 timevar.h
--- gcc/timevar.h	31 May 2002 22:15:33 -0000	1.8
+++ gcc/timevar.h	8 Nov 2002 21:42:20 -0000
@@ -53,14 +53,14 @@
  struct timevar_time_def
  {
    /* User time in this process.  */
-  float user;
+  double user;

    /* System time (if applicable for this host platform) in this
       process.  */
-  float sys;
+  double sys;

    /* Wall clock time.  */
-  float wall;
+  double wall;
  };

  /* An enumeration of timing variable identifiers.  Constructed from



More information about the Gcc-patches mailing list