Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / sparc / sparc32 / sparcv9 / hp-timing.h
blobfd7e76ecae735fa37435cfe6569370944f1dd071
1 /* High precision, low overhead timing functions. sparcv9 version.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by David S. Miller <davem@redhat.com>, 2001.
6 The GNU C Library is free software; you can redistribute it and/or
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.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _HP_TIMING_H
21 #define _HP_TIMING_H 1
23 #include <string.h>
24 #include <sys/param.h>
25 #include <_itoa.h>
27 #define HP_TIMING_AVAIL (1)
28 #define HP_TIMING_INLINE (1)
30 typedef unsigned long long int hp_timing_t;
32 #define HP_TIMING_ZERO(Var) (Var) = (0)
34 #define HP_TIMING_NOW(Var) \
35 __asm__ __volatile__ ("rd %%tick, %L0\n\t" \
36 "srlx %L0, 32, %H0" \
37 : "=r" (Var))
39 #define HP_TIMING_DIFF_INIT() \
40 do { \
41 int __cnt = 5; \
42 GLRO(dl_hp_timing_overhead) = ~0ull; \
43 do \
44 { \
45 hp_timing_t __t1, __t2; \
46 HP_TIMING_NOW (__t1); \
47 HP_TIMING_NOW (__t2); \
48 if (__t2 - __t1 < GLRO(dl_hp_timing_overhead)) \
49 GLRO(dl_hp_timing_overhead) = __t2 - __t1; \
50 } \
51 while (--__cnt > 0); \
52 } while (0)
54 #define HP_TIMING_DIFF(Diff, Start, End) (Diff) = ((End) - (Start))
56 #define HP_TIMING_ACCUM(Sum, Diff) \
57 do { \
58 hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead); \
59 __asm__ __volatile__("srl %L0, 0, %%g1\n\t" \
60 "sllx %H0, 32, %%g6\n\t" \
61 "or %%g1, %%g6, %%g1\n\t" \
62 "1: ldx [%1], %%g5\n\t" \
63 "add %%g5, %%g1, %%g6\n\t" \
64 "casx [%1], %%g5, %%g6\n\t" \
65 "cmp %%g5, %%g6\n\t" \
66 "bne,pn %%xcc, 1b\n\t" \
67 " nop" \
68 : /* no outputs */ \
69 : "r" (__diff), "r" (&(Sum)) \
70 : "memory", "g1", "g5", "g6"); \
71 } while(0)
73 #define HP_TIMING_ACCUM_NT(Sum, Diff) (Sum) += (Diff)
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)
86 #endif /* hp-timing.h */