4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file os_timer.cpp OS/compiler dependant real time tick sampling. */
14 #undef RDTSC_AVAILABLE
16 /* rdtsc for MSC_VER, uses simple inline assembly, or _rdtsc
17 * from external win64.asm because VS2005 does not support inline assembly */
18 #if defined(_MSC_VER) && !defined(RDTSC_AVAILABLE) && !defined(WINCE)
24 #define RDTSC_AVAILABLE
27 /* rdtsc for OS/2. Hopefully this works, who knows */
28 #if defined (__WATCOMC__) && !defined(RDTSC_AVAILABLE)
29 unsigned __int64
ottd_rdtsc();
30 # pragma aux ottd_rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
31 # define RDTSC_AVAILABLE
34 /* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
35 #if (defined(__i386__) || defined(__x86_64__)) && !defined(__DJGPP__) && !defined(RDTSC_AVAILABLE)
39 __asm__
__volatile__ ("rdtsc" : "=a" (low
), "=d" (high
));
40 return ((uint64
)high
<< 32) | low
;
42 # define RDTSC_AVAILABLE
45 /* rdtsc for PPC which has this not */
46 #if (defined(__POWERPC__) || defined(__powerpc__)) && !defined(RDTSC_AVAILABLE)
49 uint32 high
= 0, high2
= 0, low
;
50 /* PPC does not have rdtsc, so we cheat by reading the two 32-bit time-counters
51 * it has, 'Move From Time Base (Upper)'. Since these are two reads, in the
52 * very unlikely event that the lower part overflows to the upper part while we
53 * read it; we double-check and reread the registers */
60 : "=r" (high
), "=r" (low
), "=r" (high2
)
61 : "0" (high
), "2" (high2
)
63 return ((uint64
)high
<< 32) | low
;
65 # define RDTSC_AVAILABLE
68 /* In all other cases we have no support for rdtsc. No major issue,
69 * you just won't be able to profile your code with TIC()/TOC() */
70 #if !defined(RDTSC_AVAILABLE)
71 /* MSVC (in case of WinCE) can't handle #warning */
72 # if !defined(_MSC_VER)
73 #warning "(non-fatal) No support for rdtsc(), you won't be able to profile with TIC/TOC"
75 uint64
ottd_rdtsc() {return 0;}