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