1 |
root |
1.1 |
/* |
2 |
|
|
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
|
|
* |
4 |
root |
1.8 |
* Copyright (©) 2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.1 |
* |
6 |
root |
1.4 |
* Deliantra is free software: you can redistribute it and/or modify it under |
7 |
|
|
* the terms of the Affero GNU General Public License as published by the |
8 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
9 |
|
|
* option) any later version. |
10 |
root |
1.1 |
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
root |
1.4 |
* You should have received a copy of the Affero GNU General Public License |
17 |
|
|
* and the GNU General Public License along with this program. If not, see |
18 |
|
|
* <http://www.gnu.org/licenses/>. |
19 |
root |
1.1 |
* |
20 |
|
|
* The authors can be reached via e-mail to <support@deliantra.net> |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
// This file is only included with -DDEVEL, and is only part |
24 |
|
|
// of the distributon for completeness, it is not supposed to |
25 |
|
|
// be useful outside the developers machines. |
26 |
|
|
|
27 |
|
|
#ifndef DEVEL_H |
28 |
|
|
#define DEVEL_H |
29 |
|
|
|
30 |
|
|
// used for benchmarking (x86/amd64-specific) |
31 |
root |
1.3 |
#ifdef DEVEL64 |
32 |
|
|
typedef uint64_t cstamp; |
33 |
|
|
#else |
34 |
|
|
typedef uint32_t cstamp; |
35 |
|
|
#endif |
36 |
|
|
|
37 |
|
|
#if defined(__i386__) || defined(__x86_64__) |
38 |
root |
1.1 |
|
39 |
|
|
static inline cstamp |
40 |
root |
1.5 |
stamp () |
41 |
root |
1.1 |
{ |
42 |
root |
1.3 |
uint32_t l, h; |
43 |
|
|
|
44 |
|
|
asm volatile ("rdtsc" : "=a" (l), "=d" (h)); |
45 |
|
|
|
46 |
|
|
#ifdef DEVEL64 |
47 |
|
|
return ((cstamp)h << 32) | l; |
48 |
|
|
#else |
49 |
|
|
return l; |
50 |
|
|
#endif |
51 |
root |
1.1 |
} |
52 |
|
|
|
53 |
root |
1.3 |
#elif defined(__powerpc__) |
54 |
|
|
static inline cstamp |
55 |
root |
1.5 |
stamp () |
56 |
root |
1.3 |
{ |
57 |
|
|
unsigned uint32_t u, l, tmp; |
58 |
|
|
|
59 |
|
|
asm volatile ( |
60 |
|
|
"0: \n" |
61 |
|
|
"\tmftbu %0 \n" |
62 |
|
|
"\tmftb %1 \n" |
63 |
|
|
"\tmftbu %2 \n" |
64 |
|
|
"\tcmpw %2,%0\n" |
65 |
|
|
"\tbne 0b \n" |
66 |
|
|
: "=r" (h), "=r" (l), "=r" (tmp) |
67 |
|
|
); |
68 |
|
|
|
69 |
|
|
#ifdef DEVEL64 |
70 |
|
|
return ((cstamp)h << 32) | l; |
71 |
|
|
#else |
72 |
|
|
return l; |
73 |
|
|
#endif |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
#endif |
77 |
|
|
|
78 |
root |
1.1 |
static inline cstamp |
79 |
|
|
measure (cstamp t) |
80 |
|
|
{ |
81 |
root |
1.2 |
return stamp () - t; |
82 |
root |
1.1 |
} |
83 |
|
|
|
84 |
|
|
// cstamp s = stamp (); |
85 |
|
|
// s = measure (s); |
86 |
|
|
|
87 |
|
|
#endif |
88 |
|
|
|