X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Futil.h;h=f8ae175a8af4128ac6268cf8db87ed8b059e41ad;hp=eb3773d4e568a1b3316d24a0c8c227b06defa53d;hb=95432d94ee6d5cd0c1f71c36b78e195f1b96892f;hpb=a6290d5ab0d369d6807bad92d05a4f38560bf111 diff --git a/src/util.h b/src/util.h index eb3773d..f8ae175 100644 --- a/src/util.h +++ b/src/util.h @@ -24,4 +24,55 @@ static INLINE int32_t cround64(double val) return *(int32_t*)&val; } +uint32_t perf_start_count, perf_interval_count; + +#ifdef __WATCOMC__ +void perf_start(void); +#pragma aux perf_start = \ + "rdtsc" \ + "mov [perf_start_count], eax" \ + modify[eax edx]; + +void perf_end(void); +#pragma aux perf_end = \ + "rdtsc" \ + "sub eax, [perf_start_count]" \ + "mov [perf_interval_count], eax" \ + modify [eax edx]; +#endif + +#ifdef __GNUC__ +#define perf_start() asm volatile ( \ + "rdtsc\n" \ + "mov %%eax, %0\n" \ + : "=m"(perf_start_count) :: "%eax", "%edx") + +#define perf_end() asm volatile ( \ + "rdtsc\n" \ + "sub %1, %%eax\n" \ + "mov %%eax, %0\n" \ + : "=m"(perf_interval_count) \ + : "m"(perf_start_count) \ + : "%eax", "%edx") +#endif + +#ifdef _MSC_VER +#define perf_start() \ + do { \ + __asm { \ + rdtsc \ + mov [perf_start_count], eax \ + } \ + } while(0) + +#define perf_end() \ + do { \ + __asm { \ + rdtsc \ + sub eax, [perf_start_count] \ + mov [perf_interval_count], eax \ + } \ + } while(0) +#endif + #endif /* UTIL_H_ */