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