Commit 83801940 authored by John van Groningen's avatar John van Groningen
Browse files

port to 64 bit windows

parent 48ef631f
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define CPUID _asm _emit 0x0f _asm _emit 0xa2 #define CPUID _asm _emit 0x0f _asm _emit 0xa2
#define RDTSC _asm _emit 0x0f _asm _emit 0x31 #define RDTSC _asm _emit 0x0f _asm _emit 0x31
#ifndef _WIN64
static int has_time_stamp_counter (void) static int has_time_stamp_counter (void)
{ {
_asm { _asm {
...@@ -58,6 +59,19 @@ _asm{ ...@@ -58,6 +59,19 @@ _asm{
pop ecx pop ecx
} }
} }
#else
unsigned __int64 __rdtsc(void);
#pragma intrinsic(__rdtsc)
#endif
# ifdef _WIN64
__int64 p_time=0;
int g_time_hi=0,g_time_lo=0;
extern void compute_profile_overhead (LARGE_INTEGER *large_int_p);
# else
int p_time_hi=0,p_time_lo=0,g_time_hi=0,g_time_lo=0; int p_time_hi=0,p_time_lo=0,g_time_hi=0,g_time_lo=0;
...@@ -144,6 +158,8 @@ compute_profile_overhead_lp2: ...@@ -144,6 +158,8 @@ compute_profile_overhead_lp2:
} }
} }
# endif
#else #else
extern int has_time_stamp_counter (void); extern int has_time_stamp_counter (void);
...@@ -152,6 +168,9 @@ extern void compute_profile_overhead (LARGE_INTEGER *); ...@@ -152,6 +168,9 @@ extern void compute_profile_overhead (LARGE_INTEGER *);
#endif #endif
#ifdef _WIN64
# define float_div(a,b) ((a)/(b))
#else
double float_div (double a,double b) double float_div (double a,double b)
{ {
_asm { _asm {
...@@ -159,6 +178,7 @@ double float_div (double a,double b) ...@@ -159,6 +178,7 @@ double float_div (double a,double b)
fdiv b fdiv b
} }
} }
#endif
#define N_TIME_SAMPLES 40 #define N_TIME_SAMPLES 40
#define N_PROFILE_SAMPLES 40 #define N_PROFILE_SAMPLES 40
...@@ -262,12 +282,20 @@ static double determine_cpu_clock_speed (double frequency) ...@@ -262,12 +282,20 @@ static double determine_cpu_clock_speed (double frequency)
QueryPerformanceCounter (&begin_time0); QueryPerformanceCounter (&begin_time0);
do { do {
QueryPerformanceCounter (&begin_time); QueryPerformanceCounter (&begin_time);
#ifdef _WIN64
tsc_begin_time.QuadPart=__rdtsc();
#else
read_time_stamp_counter (&tsc_begin_time); read_time_stamp_counter (&tsc_begin_time);
#endif
} while (begin_time0.HighPart==begin_time.HighPart && begin_time0.LowPart==begin_time.LowPart); } while (begin_time0.HighPart==begin_time.HighPart && begin_time0.LowPart==begin_time.LowPart);
do { do {
QueryPerformanceCounter (&end_time); QueryPerformanceCounter (&end_time);
#ifdef _WIN64
tsc_end_time.QuadPart=__rdtsc();
#else
read_time_stamp_counter (&tsc_end_time); read_time_stamp_counter (&tsc_end_time);
#endif
} while ( (end_time.HighPart==begin_time.HighPart) } while ( (end_time.HighPart==begin_time.HighPart)
? (end_time.LowPart-begin_time.LowPart<N_TICKS) ? (end_time.LowPart-begin_time.LowPart<N_TICKS)
: (end_time.HighPart==begin_time.HighPart+1 && end_time.LowPart-(unsigned)N_TICKS<begin_time.LowPart)); : (end_time.HighPart==begin_time.HighPart+1 && end_time.LowPart-(unsigned)N_TICKS<begin_time.LowPart));
...@@ -358,6 +386,7 @@ static void set_thread_priority (HANDLE thread_handle,int old_priority,int new_p ...@@ -358,6 +386,7 @@ static void set_thread_priority (HANDLE thread_handle,int old_priority,int new_p
static void init_fpu (void) static void init_fpu (void)
{ {
#ifndef _WIN64
_asm { _asm {
finit finit
fldz fldz
...@@ -368,6 +397,7 @@ static void init_fpu (void) ...@@ -368,6 +397,7 @@ static void init_fpu (void)
fldz fldz
fldz fldz
} }
#endif
} }
int measure_clock_speed_and_profile_overhead (double *clock_speed_p,double *profile_overhead_p) int measure_clock_speed_and_profile_overhead (double *clock_speed_p,double *profile_overhead_p)
...@@ -377,12 +407,14 @@ int measure_clock_speed_and_profile_overhead (double *clock_speed_p,double *prof ...@@ -377,12 +407,14 @@ int measure_clock_speed_and_profile_overhead (double *clock_speed_p,double *prof
HANDLE thread_handle; HANDLE thread_handle;
int priority; int priority;
#ifndef _WIN64
if (!has_time_stamp_counter()){ if (!has_time_stamp_counter()){
*clock_speed_p=0.0; *clock_speed_p=0.0;
*profile_overhead_p=0.0; *profile_overhead_p=0.0;
init_fpu(); /* for virtualpc */ init_fpu(); /* for virtualpc */
return 1; return 1;
} }
#endif
thread_handle=GetCurrentThread(); thread_handle=GetCurrentThread();
priority=GetThreadPriority (thread_handle); priority=GetThreadPriority (thread_handle);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment