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