Changeset - r10383:81614a16573d
[Not reviewed]
master
0 3 0
rubidium - 16 years ago 2008-11-26 01:03:34
rubidium@openttd.org
(svn r14634) -Change: _rdtsc is defined by some platforms so we can't use that name.
3 files changed with 12 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/debug.h
Show inline comments
 
@@ -75,31 +75,31 @@ const char *GetDebugString();
 
 * for (int i = 0; i < 5; i++) {
 
 *   TIC();
 
 *     --Do yuor code--
 
 *   TOC("A name", 5);
 
 * }
 
 *
 
 * Is the correct usage for multiple TIC() / TOC() calls.
 
 *
 
 * TIC() / TOC() creates it's own block, so make sure not the mangle
 
 *  it with an other block.
 
 **/
 
#define TIC() {\
 
	extern uint64 _rdtsc();\
 
	uint64 _xxx_ = _rdtsc();\
 
	extern uint64 ottd_rdtsc();\
 
	uint64 _xxx_ = ottd_rdtsc();\
 
	static uint64 __sum__ = 0;\
 
	static uint32 __i__ = 0;
 

	
 
#define TOC(str, count)\
 
	__sum__ += _rdtsc() - _xxx_;\
 
	__sum__ += ottd_rdtsc() - _xxx_;\
 
	if (++__i__ == count) {\
 
		DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\
 
		__i__ = 0;\
 
		__sum__ = 0;\
 
	}\
 
}
 

	
 
void ShowInfo(const char *str);
 
void CDECL ShowInfoF(const char *str, ...);
 

	
 
#ifdef DEBUG_DUMP_COMMANDS
 
	void CDECL DebugDumpCommands(const char *s, ...);
src/os_timer.cpp
Show inline comments
 
@@ -2,61 +2,61 @@
 

	
 
/** @file os_timer.cpp OS/compiler dependant real time tick sampling. */
 

	
 
#include "stdafx.h"
 

	
 
#undef RDTSC_AVAILABLE
 

	
 
/* rdtsc for MSC_VER, uses simple inline assembly, or _rdtsc
 
 * from external win64.asm because VS2005 does not support inline assembly */
 
#if defined(_MSC_VER) && !defined(RDTSC_AVAILABLE) && !defined(WINCE)
 
# if _MSC_VER >= 1400
 
#include <intrin.h>
 
uint64 _rdtsc()
 
uint64 ottd_rdtsc()
 
{
 
	return __rdtsc();
 
}
 
#	else
 
uint64 _declspec(naked) _rdtsc()
 
uint64 _declspec(naked) ottd_rdtsc()
 
{
 
	_asm {
 
		rdtsc
 
		ret
 
	}
 
}
 
# endif
 
# define RDTSC_AVAILABLE
 
#endif
 

	
 
/* rdtsc for OS/2. Hopefully this works, who knows */
 
#if defined (__WATCOMC__) && !defined(RDTSC_AVAILABLE)
 
unsigned __int64 _rdtsc();
 
# pragma aux _rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
 
unsigned __int64 ottd_rdtsc();
 
# pragma aux ottd_rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
 
# define RDTSC_AVAILABLE
 
#endif
 

	
 
/* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
 
#if defined(__i386__) || defined(__x86_64__) && !defined(RDTSC_AVAILABLE)
 
uint64 _rdtsc()
 
uint64 ottd_rdtsc()
 
{
 
	uint32 high, low;
 
	__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
 
	return ((uint64)high << 32) | low;
 
}
 
# define RDTSC_AVAILABLE
 
#endif
 

	
 
/* rdtsc for PPC which has this not */
 
#if (defined(__POWERPC__) || defined(__powerpc__)) && !defined(RDTSC_AVAILABLE)
 
uint64 _rdtsc()
 
uint64 ottd_rdtsc()
 
{
 
	uint32 high = 0, high2 = 0, low;
 
	/* PPC does not have rdtsc, so we cheat by reading the two 32-bit time-counters
 
	 * it has, 'Move From Time Base (Upper)'. Since these are two reads, in the
 
	 * very unlikely event that the lower part overflows to the upper part while we
 
	 * read it; we double-check and reread the registers */
 
	asm volatile (
 
				  "mftbu %0\n"
 
				  "mftb %1\n"
 
				  "mftbu %2\n"
 
				  "cmpw %3,%4\n"
 
				  "bne- $-16\n"
 
@@ -66,14 +66,14 @@ uint64 _rdtsc()
 
	return ((uint64)high << 32) | low;
 
}
 
# define RDTSC_AVAILABLE
 
#endif
 

	
 
/* In all other cases we have no support for rdtsc. No major issue,
 
 * you just won't be able to profile your code with TIC()/TOC() */
 
#if !defined(RDTSC_AVAILABLE)
 
/* MSVC (in case of WinCE) can't handle #warning */
 
# if !defined(_MSC_VER)
 
#warning "(non-fatal) No support for rdtsc(), you won't be able to profile with TIC/TOC"
 
# endif
 
uint64 _rdtsc() {return 0;}
 
uint64 ottd_rdtsc() {return 0;}
 
#endif
src/yapf/yapf.hpp
Show inline comments
 
@@ -14,47 +14,47 @@
 
#include "../bridge.h"
 
#include "../station_base.h"
 
#include "../station_map.h"
 
#include "../tile_cmd.h"
 
#include "../landscape.h"
 
#include "yapf.h"
 
#include "../pathfind.h"
 
#include "../waypoint.h"
 
#include "../debug.h"
 
#include "../settings_type.h"
 
#include "../tunnelbridge.h"
 

	
 
extern uint64 _rdtsc();
 
extern uint64 ottd_rdtsc();
 

	
 
#include <limits.h>
 
#include <new>
 

	
 
#if defined(_WIN32) || defined(_WIN64)
 
#  include <windows.h>
 
#else
 
#  include <time.h>
 
#endif
 

	
 
struct CPerformanceTimer
 
{
 
	int64    m_start;
 
	int64    m_acc;
 

	
 
	CPerformanceTimer() : m_start(0), m_acc(0) {}
 

	
 
	FORCEINLINE void Start() {m_start = QueryTime();}
 
	FORCEINLINE void Stop() {m_acc += QueryTime() - m_start;}
 
	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);}
 
};
 

	
 
struct CPerfStartReal
 
{
 
	CPerformanceTimer* m_pperf;
 

	
 
	FORCEINLINE CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf) {if (m_pperf != NULL) m_pperf->Start();}
 
	FORCEINLINE ~CPerfStartReal() {Stop();}
 
	FORCEINLINE void Stop() {if (m_pperf != NULL) {m_pperf->Stop(); m_pperf = NULL;}}
 
};
 

	
0 comments (0 inline, 0 general)