1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
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 |
5 | * |
6 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify |
7 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the terms of the Affero GNU General Public License as published by the |
8 | * the Free Software Foundation, either version 3 of the License, or |
9 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * (at your option) any later version. |
10 | * option) any later version. |
10 | * |
11 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
15 | * |
16 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * You should have received a copy of the Affero GNU General Public License |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | * and the GNU General Public License along with this program. If not, see |
|
|
19 | * <http://www.gnu.org/licenses/>. |
18 | * |
20 | * |
19 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | */ |
22 | */ |
21 | |
23 | |
22 | // This file is only included with -DDEVEL, and is only part |
24 | // This file is only included with -DDEVEL, and is only part |
23 | // of the distributon for completeness, it is not supposed to |
25 | // of the distributon for completeness, it is not supposed to |
… | |
… | |
25 | |
27 | |
26 | #ifndef DEVEL_H |
28 | #ifndef DEVEL_H |
27 | #define DEVEL_H |
29 | #define DEVEL_H |
28 | |
30 | |
29 | // used for benchmarking (x86/amd64-specific) |
31 | // used for benchmarking (x86/amd64-specific) |
|
|
32 | #ifdef DEVEL64 |
30 | typedef unsigned int cstamp; |
33 | typedef uint64_t cstamp; |
|
|
34 | #else |
|
|
35 | typedef uint32_t cstamp; |
|
|
36 | #endif |
|
|
37 | |
|
|
38 | #if defined(__i386__) || defined(__x86_64__) |
31 | |
39 | |
32 | static inline cstamp |
40 | static inline cstamp |
33 | stamp (void) |
41 | stamp () |
34 | { |
42 | { |
35 | cstamp tsc; |
43 | uint32_t l, h; |
|
|
44 | |
36 | asm volatile ("rdtsc" : "=a" (tsc) : : "edx"); |
45 | asm volatile ("rdtsc" : "=a" (l), "=d" (h)); |
|
|
46 | |
|
|
47 | #ifdef DEVEL64 |
|
|
48 | return ((cstamp)h << 32) | l; |
|
|
49 | #else |
37 | return tsc; |
50 | return l; |
|
|
51 | #endif |
38 | } |
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 |
39 | |
78 | |
40 | static inline cstamp |
79 | static inline cstamp |
41 | measure (cstamp t) |
80 | measure (cstamp t) |
42 | { |
81 | { |
43 | return stamp () - t; |
82 | return stamp () - t; |