chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / sysdeps / sparc / sparc32 / sparcv9 / hp-timing.h
1 /* High precision, low overhead timing functions.  sparcv9 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.
5
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.
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
14    Lesser General Public License for more details.
15
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.  */
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 long int hp_timing_t;
32
33 #define HP_TIMING_ZERO(Var)     (Var) = (0)
34
35 #define HP_TIMING_NOW(Var) \
36       __asm__ __volatile__ ("rd %%tick, %L0\n\t" \
37                             "srlx %L0, 32, %H0" \
38                             : "=r" (Var))
39
40 #define HP_TIMING_DIFF_INIT() \
41   do {                                                                        \
42     int __cnt = 5;                                                            \
43     GLRO(dl_hp_timing_overhead) = ~0ull;                                      \
44     do                                                                        \
45       {                                                                       \
46         hp_timing_t __t1, __t2;                                               \
47         HP_TIMING_NOW (__t1);                                                 \
48         HP_TIMING_NOW (__t2);                                                 \
49         if (__t2 - __t1 < GLRO(dl_hp_timing_overhead))                        \
50           GLRO(dl_hp_timing_overhead) = __t2 - __t1;                          \
51       }                                                                       \
52     while (--__cnt > 0);                                                      \
53   } while (0)
54
55 #define HP_TIMING_DIFF(Diff, Start, End)        (Diff) = ((End) - (Start))
56
57 #define HP_TIMING_ACCUM(Sum, Diff)                              \
58 do {                                                            \
59   hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead);    \
60   __asm__ __volatile__("srl     %L0, 0, %%g1\n\t"               \
61                        "sllx    %H0, 32, %%g6\n\t"              \
62                        "or      %%g1, %%g6, %%g1\n\t"           \
63                        "1: ldx  [%1], %%g5\n\t"                 \
64                        "add     %%g5, %%g1, %%g6\n\t"           \
65                        "casx    [%1], %%g5,  %%g6\n\t"          \
66                        "cmp     %%g5, %%g6\n\t"                 \
67                        "bne,pn  %%xcc, 1b\n\t"                  \
68                        " nop"                                   \
69                        : /* no outputs */                       \
70                        : "r" (__diff), "r" (&(Sum))             \
71                        : "memory", "g1", "g5", "g6");           \
72 } while(0)
73
74 #define HP_TIMING_ACCUM_NT(Sum, Diff)   (Sum) += (Diff)
75
76 #define HP_TIMING_PRINT(Buf, Len, Val) \
77   do {                                                                        \
78     char __buf[20];                                                           \
79     char *__cp = _itoa (Val, __buf + sizeof (__buf), 10, 0);                  \
80     int __len = (Len);                                                        \
81     char *__dest = (Buf);                                                     \
82     while (__len-- > 0 && __cp < __buf + sizeof (__buf))                      \
83       *__dest++ = *__cp++;                                                    \
84     memcpy (__dest, " clock cycles", MIN (__len, sizeof (" clock cycles")));  \
85   } while (0)
86
87 #endif  /* hp-timing.h */