mirror of https://github.com/OpenTTD/OpenTTD
(svn r14634) -Change: _rdtsc is defined by some platforms so we can't use that name.
parent
131f9e39d3
commit
69eb6978e7
|
@ -84,13 +84,13 @@ const char *GetDebugString();
|
||||||
* it with an other block.
|
* it with an other block.
|
||||||
**/
|
**/
|
||||||
#define TIC() {\
|
#define TIC() {\
|
||||||
extern uint64 _rdtsc();\
|
extern uint64 ottd_rdtsc();\
|
||||||
uint64 _xxx_ = _rdtsc();\
|
uint64 _xxx_ = ottd_rdtsc();\
|
||||||
static uint64 __sum__ = 0;\
|
static uint64 __sum__ = 0;\
|
||||||
static uint32 __i__ = 0;
|
static uint32 __i__ = 0;
|
||||||
|
|
||||||
#define TOC(str, count)\
|
#define TOC(str, count)\
|
||||||
__sum__ += _rdtsc() - _xxx_;\
|
__sum__ += ottd_rdtsc() - _xxx_;\
|
||||||
if (++__i__ == count) {\
|
if (++__i__ == count) {\
|
||||||
DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\
|
DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\
|
||||||
__i__ = 0;\
|
__i__ = 0;\
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
#if defined(_MSC_VER) && !defined(RDTSC_AVAILABLE) && !defined(WINCE)
|
#if defined(_MSC_VER) && !defined(RDTSC_AVAILABLE) && !defined(WINCE)
|
||||||
# if _MSC_VER >= 1400
|
# if _MSC_VER >= 1400
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
uint64 _rdtsc()
|
uint64 ottd_rdtsc()
|
||||||
{
|
{
|
||||||
return __rdtsc();
|
return __rdtsc();
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
uint64 _declspec(naked) _rdtsc()
|
uint64 _declspec(naked) ottd_rdtsc()
|
||||||
{
|
{
|
||||||
_asm {
|
_asm {
|
||||||
rdtsc
|
rdtsc
|
||||||
|
@ -29,14 +29,14 @@ uint64 _declspec(naked) _rdtsc()
|
||||||
|
|
||||||
/* rdtsc for OS/2. Hopefully this works, who knows */
|
/* rdtsc for OS/2. Hopefully this works, who knows */
|
||||||
#if defined (__WATCOMC__) && !defined(RDTSC_AVAILABLE)
|
#if defined (__WATCOMC__) && !defined(RDTSC_AVAILABLE)
|
||||||
unsigned __int64 _rdtsc();
|
unsigned __int64 ottd_rdtsc();
|
||||||
# pragma aux _rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
|
# pragma aux ottd_rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
|
||||||
# define RDTSC_AVAILABLE
|
# define RDTSC_AVAILABLE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
|
/* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
|
||||||
#if defined(__i386__) || defined(__x86_64__) && !defined(RDTSC_AVAILABLE)
|
#if defined(__i386__) || defined(__x86_64__) && !defined(RDTSC_AVAILABLE)
|
||||||
uint64 _rdtsc()
|
uint64 ottd_rdtsc()
|
||||||
{
|
{
|
||||||
uint32 high, low;
|
uint32 high, low;
|
||||||
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
||||||
|
@ -47,7 +47,7 @@ uint64 _rdtsc()
|
||||||
|
|
||||||
/* rdtsc for PPC which has this not */
|
/* rdtsc for PPC which has this not */
|
||||||
#if (defined(__POWERPC__) || defined(__powerpc__)) && !defined(RDTSC_AVAILABLE)
|
#if (defined(__POWERPC__) || defined(__powerpc__)) && !defined(RDTSC_AVAILABLE)
|
||||||
uint64 _rdtsc()
|
uint64 ottd_rdtsc()
|
||||||
{
|
{
|
||||||
uint32 high = 0, high2 = 0, low;
|
uint32 high = 0, high2 = 0, low;
|
||||||
/* PPC does not have rdtsc, so we cheat by reading the two 32-bit time-counters
|
/* PPC does not have rdtsc, so we cheat by reading the two 32-bit time-counters
|
||||||
|
@ -75,5 +75,5 @@ uint64 _rdtsc()
|
||||||
# if !defined(_MSC_VER)
|
# if !defined(_MSC_VER)
|
||||||
#warning "(non-fatal) No support for rdtsc(), you won't be able to profile with TIC/TOC"
|
#warning "(non-fatal) No support for rdtsc(), you won't be able to profile with TIC/TOC"
|
||||||
# endif
|
# endif
|
||||||
uint64 _rdtsc() {return 0;}
|
uint64 ottd_rdtsc() {return 0;}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "../settings_type.h"
|
#include "../settings_type.h"
|
||||||
#include "../tunnelbridge.h"
|
#include "../tunnelbridge.h"
|
||||||
|
|
||||||
extern uint64 _rdtsc();
|
extern uint64 ottd_rdtsc();
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
@ -45,7 +45,7 @@ struct CPerformanceTimer
|
||||||
FORCEINLINE void Stop() {m_acc += QueryTime() - m_start;}
|
FORCEINLINE void Stop() {m_acc += QueryTime() - m_start;}
|
||||||
FORCEINLINE int Get(int64 coef) {return (int)(m_acc * coef / QueryFrequency());}
|
FORCEINLINE int Get(int64 coef) {return (int)(m_acc * coef / QueryFrequency());}
|
||||||
|
|
||||||
FORCEINLINE int64 QueryTime() {return _rdtsc();}
|
FORCEINLINE int64 QueryTime() {return ottd_rdtsc();}
|
||||||
FORCEINLINE int64 QueryFrequency() {return ((int64)2200 * 1000000);}
|
FORCEINLINE int64 QueryFrequency() {return ((int64)2200 * 1000000);}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue