(svn r25652) -Fix: Improve text caret movement for complex scripts.
[openttd/fttd.git] / src / os_timer.cpp
blob47cc1afd5d01e6a9ad524ce5b22828e2e614386f
1 /* $Id$ */
3 /*
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/>.
8 */
10 /** @file os_timer.cpp OS/compiler dependant real time tick sampling. */
12 #include "stdafx.h"
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)
19 #include <intrin.h>
20 uint64 ottd_rdtsc()
22 return __rdtsc();
24 #define RDTSC_AVAILABLE
25 #endif
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
32 #endif
34 /* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
35 #if (defined(__i386__) || defined(__x86_64__)) && !defined(__DJGPP__) && !defined(RDTSC_AVAILABLE)
36 uint64 ottd_rdtsc()
38 uint32 high, low;
39 __asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
40 return ((uint64)high << 32) | low;
42 # define RDTSC_AVAILABLE
43 #endif
45 /* rdtsc for PPC which has this not */
46 #if (defined(__POWERPC__) || defined(__powerpc__)) && !defined(RDTSC_AVAILABLE)
47 uint64 ottd_rdtsc()
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 */
54 asm volatile (
55 "mftbu %0\n"
56 "mftb %1\n"
57 "mftbu %2\n"
58 "cmpw %3,%4\n"
59 "bne- $-16\n"
60 : "=r" (high), "=r" (low), "=r" (high2)
61 : "0" (high), "2" (high2)
63 return ((uint64)high << 32) | low;
65 # define RDTSC_AVAILABLE
66 #endif
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"
74 # endif
75 uint64 ottd_rdtsc() {return 0;}
76 #endif