This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: (libf2c) libu77 SYSTEM_CLOCK win32 support.


craig@jcb-sc.com writes:
> >In a message dated 4/15/99 9:30:46 PM Pacific Daylight Time, 
> >khan@xraylith.wisc.EDU writes:
> >
> >> +  if (cnt > (unsigned long) (INT_MAX))
> >>  +    *count = INT_MAX;		/* also dubious */
> >
> >I'd prefer to let it run on into negative values, which can be checked for b
> y 
> >the receiver and adjusted if desired.  I'd also prefer to have higher 
> >resolution than 1 msec, without of course going to a timer which overflows i
> n 
> >a matter of minutes.  I wouldn't expect people to use SYSTEM_CLOCK() to 
> >measure uptime, but you know better than I.
> 
> Working clocks tick.  And most of them overflow in one way or another,
> at some time or another.
> 
> So, I agree, I'd rather not have SYSTEM_CLOCK changed to stop ticking.
> It's already documented (or should be) to have overflow problems on
> some systems.

I'm game either way, as long as everybody concerned agree about this.
Please consider the following patch then. Once we settle on the
functionality, I'll resubmit according to the way Jeff wants. Although
I must admit I don't understand Jeff's comment about using autoconf in
this particular case -- autoconf will only tell me that on _WIN32, 
GetTickCount exists, which is already guaranteed to be true. Perhaps I'm 
missing Jeff's point.

Tim, this is very similar to your version that you had sent me long
time ago, except I'm not taking only the low-order 32 bits, which I
consider to be somewhat deceptive/disingenuous. Also, note the "dubious" 
cast for count_max; I kept that to be consistent with the other 
ports that define HAVE_TIMES, but obviously open to change.

btw, the 1ms is still faster that what you'd see in the Linux implementation 
of this same routine where the count rate is 100.

Fri Apr 16 10:57:01 1999  Mumit Khan  <khan@xraylith.wisc.edu>
	
	* libU77/sys_clock_.c (G77_system_clock_0): Support windows32. 

Index: libU77/sys_clock_.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/egcs-1.2-dev/libf2c/libU77/sys_clock_.c,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 libU77/sys_clock_.c
--- libU77/sys_clock_.c	1999/04/15 20:53:16	1.1.1.1
+++ libU77/sys_clock_.c	1999/04/16 03:33:50
@@ -36,6 +36,11 @@ Boston, MA 02111-1307, USA.  */
 #if HAVE_UNISTD_H
 #  include <unistd.h>
 #endif
+#if defined (_WIN32)
+#  include <windows.h>
+#  undef min
+#  undef max
+#endif
 #include <errno.h>		/* for ENOSYS */
 #include "f2c.h"
 
@@ -46,7 +51,47 @@ int G77_system_clock_0 (count, count_rat
 int G77_system_clock_0 (integer *count, integer *count_rate, integer *count_max)
 #endif
 {
-#if defined (HAVE_TIMES)
+#if defined (_WIN32)
+  /* Windows32 provides a slew of interfaces for getting time information;
+     we use the high resolution performance counters available on all ix86 
+     and Alphas. The downside is that all the information is 64bit. We
+     could use GetTickCount or timeGetTime interface, but then the resolution
+     is only 1.0e-3s. */
+
+  unsigned long long clock_freq;
+  unsigned long long cnt;
+  LARGE_INTEGER counter_val;
+  LARGE_INTEGER freq;
+  if (! QueryPerformanceFrequency (&freq))
+    {
+      errno = ENOSYS;
+      return -1;
+    }
+
+  clock_freq = ((unsigned long long) freq.HighPart << 32)
+	       + ((unsigned) freq.LowPart);
+  if (count_rate) 
+    {
+       /* the following cast is obviously dubious, but there is only so much
+          one can do with 32bit quantities. */
+      *count_rate = (unsigned long) clock_freq;
+    }
+  if (count_max)		/* optional arg present? */
+    *count_max = INT_MAX;		/* dubious */
+
+  if (! QueryPerformanceCounter (&counter_val))
+    {
+      errno = ENOSYS;
+      return -1;
+    }
+
+  cnt = ((unsigned long long) counter_val.HighPart << 32)
+	+ ((unsigned) counter_val.LowPart);
+  
+  /* another dubious cast. */
+  *count = (unsigned long) cnt;
+  return 0;
+#elif defined (HAVE_TIMES)
   struct tms buffer;
   unsigned long cnt;
   if (count_rate) {

Regards,
Mumit



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]