ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/devel.h
(Generate patch)

Comparing deliantra/server/include/devel.h (file contents):
Revision 1.1 by root, Fri Dec 26 10:36:42 2008 UTC vs.
Revision 1.10 by root, Wed Nov 16 23:42:00 2016 UTC

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 (©) 2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 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
23// of the distributon for completeness, it is not supposed to 24// of the distributon for completeness, it is not supposed to
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
30typedef unsigned int cstamp; 32typedef uint64_t cstamp;
33#else
34typedef uint32_t cstamp;
35#endif
36
37#if defined(__i386__) || defined(__x86_64__)
31 38
32static inline cstamp 39static inline cstamp
33stamp (void) 40stamp ()
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__)
54static inline cstamp
55stamp ()
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
41static inline cstamp 78static inline cstamp
42measure (cstamp t) 79measure (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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines