]>
Commit | Line | Data |
---|---|---|
c44a663d | 1 | /* High precision, low overhead timing functions. sparc64 version. |
c31e278f | 2 | Copyright (C) 2001, 2002, 2003, 2004 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 AJ |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, write to the Free | |
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
19 | 02111-1307 USA. */ | |
c44a663d UD |
20 | |
21 | #ifndef _HP_TIMING_H | |
22 | #define _HP_TIMING_H 1 | |
23 | ||
24 | #include <string.h> | |
25 | #include <sys/param.h> | |
26 | #include <stdio-common/_itoa.h> | |
27 | ||
28 | #define HP_TIMING_AVAIL (1) | |
29 | #define HP_TIMING_INLINE (1) | |
30 | ||
31 | typedef unsigned long int hp_timing_t; | |
32 | ||
c44a663d UD |
33 | #define HP_TIMING_ZERO(Var) (Var) = (0) |
34 | ||
35 | #define HP_TIMING_NOW(Var) __asm__ __volatile__ ("rd %%tick, %0" : "=r" (Var)) | |
36 | ||
37 | #define HP_TIMING_DIFF_INIT() \ | |
38 | do { \ | |
39 | int __cnt = 5; \ | |
c31e278f | 40 | GLRO(dl_hp_timing_overhead) = ~0ull; \ |
c44a663d UD |
41 | do \ |
42 | { \ | |
43 | hp_timing_t __t1, __t2; \ | |
44 | HP_TIMING_NOW (__t1); \ | |
45 | HP_TIMING_NOW (__t2); \ | |
c31e278f UD |
46 | if (__t2 - __t1 < GLRO(dl_hp_timing_overhead)) \ |
47 | GLRO(dl_hp_timing_overhead) = __t2 - __t1; \ | |
c44a663d UD |
48 | } \ |
49 | while (--__cnt > 0); \ | |
50 | } while (0) | |
51 | ||
52 | #define HP_TIMING_DIFF(Diff, Start, End) (Diff) = ((End) - (Start)) | |
53 | ||
54 | #define HP_TIMING_ACCUM(Sum, Diff) \ | |
55 | do { \ | |
c31e278f | 56 | hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead); \ |
c44a663d UD |
57 | hp_timing_t tmp1, tmp2; \ |
58 | __asm__ __volatile__("1: ldx [%3], %0\n\t" \ | |
59 | "add %0, %2, %1\n\t" \ | |
60 | "casx [%3], %0, %1\n\t" \ | |
61 | "cmp %0, %1\n\t" \ | |
62 | "bne,pn %%xcc, 1b\n\t" \ | |
63 | " nop" \ | |
64 | : "=&r" (tmp1), "=&r" (tmp2) \ | |
65 | : "r" (__diff), "r" (&(Sum)) \ | |
62f29da7 | 66 | : "memory", "g1", "g5", "g6"); \ |
c44a663d UD |
67 | } while(0) |
68 | ||
69 | #define HP_TIMING_ACCUM_NT(Sum, Diff) (Sum) += (Diff) | |
70 | ||
71 | #define HP_TIMING_PRINT(Buf, Len, Val) \ | |
72 | do { \ | |
73 | char __buf[20]; \ | |
74 | char *__cp = _itoa (Val, __buf + sizeof (__buf), 10, 0); \ | |
75 | int __len = (Len); \ | |
76 | char *__dest = (Buf); \ | |
77 | while (__len-- > 0 && __cp < __buf + sizeof (__buf)) \ | |
78 | *__dest++ = *__cp++; \ | |
79 | memcpy (__dest, " clock cycles", MIN (__len, sizeof (" clock cycles"))); \ | |
80 | } while (0) | |
81 | ||
82 | #endif /* hp-timing.h */ |