mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-22 15:11:54 +00:00
(svn r4191) - Codechange: Properly set newlines and id for os_timer.c
This commit is contained in:
parent
7f134d238f
commit
c35546964d
138
os_timer.c
138
os_timer.c
@ -1,68 +1,70 @@
|
|||||||
#include "stdafx.h"
|
/* $Id$ */
|
||||||
|
|
||||||
#undef RDTSC_AVAILABLE
|
#include "stdafx.h"
|
||||||
|
|
||||||
/* rdtsc for MSC_VER, uses simple inline assembly, or _rdtsc
|
#undef RDTSC_AVAILABLE
|
||||||
* from external win64.asm because VS2005 does not support inline assembly */
|
|
||||||
#if defined(_MSC_VER) && !defined(RDTSC_AVAILABLE)
|
/* rdtsc for MSC_VER, uses simple inline assembly, or _rdtsc
|
||||||
# if defined (_M_AMD64)
|
* from external win64.asm because VS2005 does not support inline assembly */
|
||||||
extern uint64 _rdtsc(void);
|
#if defined(_MSC_VER) && !defined(RDTSC_AVAILABLE)
|
||||||
# else
|
# if defined (_M_AMD64)
|
||||||
uint64 _declspec(naked) _rdtsc(void)
|
extern uint64 _rdtsc(void);
|
||||||
{
|
# else
|
||||||
_asm {
|
uint64 _declspec(naked) _rdtsc(void)
|
||||||
rdtsc
|
{
|
||||||
ret
|
_asm {
|
||||||
}
|
rdtsc
|
||||||
}
|
ret
|
||||||
# endif
|
}
|
||||||
# define RDTSC_AVAILABLE
|
}
|
||||||
#endif
|
# endif
|
||||||
|
# define RDTSC_AVAILABLE
|
||||||
/* rdtsc for OS/2. Hopefully this works, who knows */
|
#endif
|
||||||
#if defined (__WATCOMC__) && !defined(RDTSC_AVAILABLE)
|
|
||||||
unsigned __int64 _rdtsc( void);
|
/* rdtsc for OS/2. Hopefully this works, who knows */
|
||||||
# pragma aux _rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
|
#if defined (__WATCOMC__) && !defined(RDTSC_AVAILABLE)
|
||||||
# define RDTSC_AVAILABLE
|
unsigned __int64 _rdtsc( void);
|
||||||
#endif
|
# pragma aux _rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
|
||||||
|
# define RDTSC_AVAILABLE
|
||||||
/* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
|
#endif
|
||||||
#if defined(__i386__) || defined(__x86_64__) && !defined(RDTSC_AVAILABLE)
|
|
||||||
uint64 _rdtsc(void)
|
/* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
|
||||||
{
|
#if defined(__i386__) || defined(__x86_64__) && !defined(RDTSC_AVAILABLE)
|
||||||
uint32 high, low;
|
uint64 _rdtsc(void)
|
||||||
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
{
|
||||||
return ((uint64)high << 32) | low;
|
uint32 high, low;
|
||||||
}
|
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
||||||
# define RDTSC_AVAILABLE
|
return ((uint64)high << 32) | low;
|
||||||
#endif
|
}
|
||||||
|
# define RDTSC_AVAILABLE
|
||||||
/* rdtsc for PPC which has this not */
|
#endif
|
||||||
#if defined(__POWERPC__) && !defined(RDTSC_AVAILABLE)
|
|
||||||
uint64 _rdtsc(void)
|
/* rdtsc for PPC which has this not */
|
||||||
{
|
#if defined(__POWERPC__) && !defined(RDTSC_AVAILABLE)
|
||||||
uint32 high = 0, high2 = 0, low;
|
uint64 _rdtsc(void)
|
||||||
/* 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
|
uint32 high = 0, high2 = 0, low;
|
||||||
* very unlikely event that the lower part overflows to the upper part while we
|
/* PPC does not have rdtsc, so we cheat by reading the two 32-bit time-counters
|
||||||
* read it; we double-check and reread the registers */
|
* it has, 'Move From Time Base (Upper)'. Since these are two reads, in the
|
||||||
asm volatile (
|
* very unlikely event that the lower part overflows to the upper part while we
|
||||||
"mftbu %0\n"
|
* read it; we double-check and reread the registers */
|
||||||
"mftb %1\n"
|
asm volatile (
|
||||||
"mftbu %2\n"
|
"mftbu %0\n"
|
||||||
"cmpw %3,%4\n"
|
"mftb %1\n"
|
||||||
"bne- $-16\n"
|
"mftbu %2\n"
|
||||||
: "=r" (high), "=r" (low), "=r" (high2)
|
"cmpw %3,%4\n"
|
||||||
: "0" (high), "2" (high2)
|
"bne- $-16\n"
|
||||||
);
|
: "=r" (high), "=r" (low), "=r" (high2)
|
||||||
return ((uint64)high << 32) | low;
|
: "0" (high), "2" (high2)
|
||||||
}
|
);
|
||||||
# define RDTSC_AVAILABLE
|
return ((uint64)high << 32) | low;
|
||||||
#endif
|
}
|
||||||
|
# define RDTSC_AVAILABLE
|
||||||
/* In all other cases we have no support for rdtsc. No major issue,
|
#endif
|
||||||
* you just won't be able to profile your code with TIC()/TOC() */
|
|
||||||
#if !defined(RDTSC_AVAILABLE)
|
/* In all other cases we have no support for rdtsc. No major issue,
|
||||||
#warning "OS has no support for rdtsc()"
|
* you just won't be able to profile your code with TIC()/TOC() */
|
||||||
uint64 _rdtsc(void) {return 0;}
|
#if !defined(RDTSC_AVAILABLE)
|
||||||
#endif
|
#warning "OS has no support for rdtsc()"
|
||||||
|
uint64 _rdtsc(void) {return 0;}
|
||||||
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user