Thanks, I have not tried that one yet.
On-line engine blitz tourney November
Moderators: hgm, Rebel, chrisw
-
- Posts: 536
- Joined: Thu Mar 09, 2006 3:01 pm
Re: On-line engine blitz tourney November
-
- Posts: 27808
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: On-line engine blitz tourney November
WinBoard uses gettimeofday() to read the clock, as a first choice. (I didn't know that even was available in a MinGW compile. In Fairy-Max I have an #ifdef WIN32 to choose between GetTickCount() and gettimeofday(), and it seems I would not even need that! )
I am afraid that in MinGW gettimeofday() just ticks every 16msec, though, despite the microsec precision.
I guess I could prefix this with an #ifdef WIN32 to make QueryPerformanceCounter the first choice. How would that work? Should I also use QueryPerformanceFrequency to normalize thhe count? And is that frequency a constant, or should I do that every time (because of turbo boost)? Would this work?:
I am afraid that in MinGW gettimeofday() just ticks every 16msec, though, despite the microsec precision.
Code: Select all
/* Get the current time as a TimeMark */
void
GetTimeMark (TimeMark *tm)
{
#if HAVE_GETTIMEOFDAY
struct timeval timeVal;
struct timezone timeZone;
gettimeofday(&timeVal, &timeZone);
tm->sec = (long) timeVal.tv_sec;
tm->ms = (int) (timeVal.tv_usec / 1000L);
#else /*!HAVE_GETTIMEOFDAY*/
#if HAVE_FTIME
// include <sys/timeb.h> / moved to just above start of function
struct timeb timeB;
ftime(&timeB);
tm->sec = (long) timeB.time;
tm->ms = (int) timeB.millitm;
#else /*!HAVE_FTIME && !HAVE_GETTIMEOFDAY*/
tm->sec = (long) time(NULL);
tm->ms = 0;
#endif
#endif
}
Code: Select all
#ifdef WIN32
long long
int freq, ticks;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&ticks);
ticks *= 1000000; ticks /= freq;
tm->sec = ticks / 1000000;
tm->ms = (ticks / 1000) % 1000;
#else
...
#endif
-
- Posts: 2488
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: On-line engine blitz tourney November
Try clock_gettime(), does this have the same issue?
That's what I'm doing for the Windows compile. Omitting the Windows build ifdefs:I guess I could prefix this with an #ifdef WIN32 to make QueryPerformanceCounter the first choice.
Code: Select all
#include <windows.h>
#include <process.h>
LARGE_INTEGER clock_ticks_start, clock_ticks_freq;
/*init time acquisition, to be called on program start*/
void Init_Millisecs(void)
{
/*QueryPerformanceFrequency doesn't change after Windows has booted*/
QueryPerformanceFrequency(&clock_ticks_freq);
QueryPerformanceCounter(&clock_ticks_start);
}
/*gets the absolute timestamp in milliseconds since Init_Millisecs() call*/
int64_t Get_Millisecs(void)
{
LARGE_INTEGER clock_ticks_now, clock_ticks_elapsed, millisecs_elapsed;
QueryPerformanceCounter(&clock_ticks_now);
clock_ticks_elapsed.QuadPart = clock_ticks_now.QuadPart - clock_ticks_start.QuadPart;
/*ticks to milliseconds:
the tick counter won't overflow for a 100 years, but the milliseconds
calculation might overflow if multiplying the tick difference by 1000
and directly dividing by the clock frequency. That would require
having the application open for 0.1 years, i.e. 36.5 days, which
might be feasible.*/
/*whole seconds*/
millisecs_elapsed.QuadPart = clock_ticks_elapsed.QuadPart / clock_ticks_freq.QuadPart;
/*fractional seconds in ticks*/
clock_ticks_elapsed.QuadPart %= clock_ticks_freq.QuadPart;
/*whole seconds to milliseconds*/
millisecs_elapsed.QuadPart *= 1000;
/*add fractional seconds in milliseconds, rounding downwards*/
millisecs_elapsed.QuadPart += (clock_ticks_elapsed.QuadPart * 1000) / clock_ticks_freq.QuadPart;
return((int64_t)millisecs_elapsed.QuadPart);
}
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net
-
- Posts: 27808
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: On-line engine blitz tourney November
Hmm... It seems my compiler doesn't recognize 'struct timespec' or CLOCK_REALTIME even after #including time.h. And I get a linker error for QueryPerformanceFrequency. So this will be harder than I expected.
-
- Posts: 2488
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: On-line engine blitz tourney November
IIRC MingW uses the pthread stuff for that, which requires:
Code: Select all
#define _POSIX_C_SOURCE 200809L
#include <pthread.h>
Further headers that I have included, for both Linux and Windows:
Code: Select all
#include <inttypes.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
That's strange indeed.And I get a linker error for QueryPerformanceFrequency.
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net
-
- Posts: 27808
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: On-line engine blitz tourney November
The problem could be that I am using gcc 3.4.4 under Cygwin. (It says (C) 2004...)
Newer versions do not support the -mno-cygwin flag, though. I would need a separate MinGW compiler. I have that on my laptop (because the virus scanner removed Cygwin there), but it doesn't understand the Makefile that comes with WinBoard, so that I have to build by hand. Which is a real pain for a project as complex as WinBoard.
Newer versions do not support the -mno-cygwin flag, though. I would need a separate MinGW compiler. I have that on my laptop (because the virus scanner removed Cygwin there), but it doesn't understand the Makefile that comes with WinBoard, so that I have to build by hand. Which is a real pain for a project as complex as WinBoard.
-
- Posts: 2488
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: On-line engine blitz tourney November
That might be a problem. You could try one of these packages: https://sourceforge.net/projects/mingw- ... gw-builds/. Under Windows, I used x86_64-7.3.0-posix-seh-rt_v5-rev0 (64 bit) and i686-7.3.0-posix-dwarf-rt_v5-rev0 (32 bit) for static linkage.
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net