2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc64 / hp-timing.h
blobe45c6a88fcda85b73d08527e7b5430c89f45cba5
1 /* High precision, low overhead timing functions. sparc64 version.
2 Copyright (C) 2001, 2002, 2003, 2004 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _HP_TIMING_H
22 #define _HP_TIMING_H 1
24 #include <string.h>
25 #include <sys/param.h>
26 #include <stdio-common/_itoa.h>
28 #define HP_TIMING_AVAIL (1)
29 #define HP_TIMING_INLINE (1)
31 typedef unsigned long int hp_timing_t;
33 #define HP_TIMING_ZERO(Var) (Var) = (0)
35 #define HP_TIMING_NOW(Var) __asm__ __volatile__ ("rd %%tick, %0" : "=r" (Var))
37 #define HP_TIMING_DIFF_INIT() \
38 do { \
39 int __cnt = 5; \
40 GLRO(dl_hp_timing_overhead) = ~0ull; \
41 do \
42 { \
43 hp_timing_t __t1, __t2; \
44 HP_TIMING_NOW (__t1); \
45 HP_TIMING_NOW (__t2); \
46 if (__t2 - __t1 < GLRO(dl_hp_timing_overhead)) \
47 GLRO(dl_hp_timing_overhead) = __t2 - __t1; \
48 } \
49 while (--__cnt > 0); \
50 } while (0)
52 #define HP_TIMING_DIFF(Diff, Start, End) (Diff) = ((End) - (Start))
54 #define HP_TIMING_ACCUM(Sum, Diff) \
55 do { \
56 hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead); \
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)) \
66 : "memory", "g1", "g5", "g6"); \
67 } while(0)
69 #define HP_TIMING_ACCUM_NT(Sum, Diff) (Sum) += (Diff)
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)
82 #endif /* hp-timing.h */