]>
Commit | Line | Data |
---|---|---|
c44a663d | 1 | /* High precision, low overhead timing functions. sparcv9 version. |
d4697bc9 | 2 | Copyright (C) 2001-2014 Free Software Foundation, Inc. |
c44a663d UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by David S. Miller <davem@redhat.com>, 2001. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
c44a663d UD |
10 | |
11 | The GNU C Library 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 GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
c44a663d | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
c44a663d UD |
19 | |
20 | #ifndef _HP_TIMING_H | |
21 | #define _HP_TIMING_H 1 | |
22 | ||
23 | #include <string.h> | |
24 | #include <sys/param.h> | |
eb96ffb0 | 25 | #include <_itoa.h> |
c44a663d UD |
26 | |
27 | #define HP_TIMING_AVAIL (1) | |
28 | #define HP_TIMING_INLINE (1) | |
29 | ||
30 | typedef unsigned long long int hp_timing_t; | |
31 | ||
c44a663d UD |
32 | #define HP_TIMING_ZERO(Var) (Var) = (0) |
33 | ||
34 | #define HP_TIMING_NOW(Var) \ | |
35 | __asm__ __volatile__ ("rd %%tick, %L0\n\t" \ | |
36 | "srlx %L0, 32, %H0" \ | |
37 | : "=r" (Var)) | |
38 | ||
39 | #define HP_TIMING_DIFF_INIT() \ | |
40 | do { \ | |
41 | int __cnt = 5; \ | |
c31e278f | 42 | GLRO(dl_hp_timing_overhead) = ~0ull; \ |
c44a663d UD |
43 | do \ |
44 | { \ | |
45 | hp_timing_t __t1, __t2; \ | |
46 | HP_TIMING_NOW (__t1); \ | |
47 | HP_TIMING_NOW (__t2); \ | |
c31e278f UD |
48 | if (__t2 - __t1 < GLRO(dl_hp_timing_overhead)) \ |
49 | GLRO(dl_hp_timing_overhead) = __t2 - __t1; \ | |
c44a663d UD |
50 | } \ |
51 | while (--__cnt > 0); \ | |
52 | } while (0) | |
53 | ||
54 | #define HP_TIMING_DIFF(Diff, Start, End) (Diff) = ((End) - (Start)) | |
55 | ||
56 | #define HP_TIMING_ACCUM(Sum, Diff) \ | |
57 | do { \ | |
c31e278f | 58 | hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead); \ |
c44a663d | 59 | __asm__ __volatile__("srl %L0, 0, %%g1\n\t" \ |
62f29da7 UD |
60 | "sllx %H0, 32, %%g6\n\t" \ |
61 | "or %%g1, %%g6, %%g1\n\t" \ | |
c44a663d | 62 | "1: ldx [%1], %%g5\n\t" \ |
62f29da7 UD |
63 | "add %%g5, %%g1, %%g6\n\t" \ |
64 | "casx [%1], %%g5, %%g6\n\t" \ | |
65 | "cmp %%g5, %%g6\n\t" \ | |
c44a663d UD |
66 | "bne,pn %%xcc, 1b\n\t" \ |
67 | " nop" \ | |
68 | : /* no outputs */ \ | |
69 | : "r" (__diff), "r" (&(Sum)) \ | |
62f29da7 | 70 | : "memory", "g1", "g5", "g6"); \ |
c44a663d UD |
71 | } while(0) |
72 | ||
73 | #define HP_TIMING_ACCUM_NT(Sum, Diff) (Sum) += (Diff) | |
74 | ||
75 | #define HP_TIMING_PRINT(Buf, Len, Val) \ | |
76 | do { \ | |
77 | char __buf[20]; \ | |
78 | char *__cp = _itoa (Val, __buf + sizeof (__buf), 10, 0); \ | |
79 | int __len = (Len); \ | |
80 | char *__dest = (Buf); \ | |
81 | while (__len-- > 0 && __cp < __buf + sizeof (__buf)) \ | |
82 | *__dest++ = *__cp++; \ | |
83 | memcpy (__dest, " clock cycles", MIN (__len, sizeof (" clock cycles"))); \ | |
84 | } while (0) | |
85 | ||
86 | #endif /* hp-timing.h */ |