Update copyright notices with scripts/update-copyrights
[jlayton/glibc.git] / sysdeps / sparc / sparc64 / hp-timing.h
1 /* High precision, low overhead timing functions.  sparc64 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.
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, see
18    <http://www.gnu.org/licenses/>.  */
19
20 #ifndef _HP_TIMING_H
21 #define _HP_TIMING_H    1
22
23 #include <string.h>
24 #include <sys/param.h>
25 #include <_itoa.h>
26
27 #define HP_TIMING_AVAIL         (1)
28 #define HP_TIMING_INLINE        (1)
29
30 typedef unsigned long int hp_timing_t;
31
32 #define HP_TIMING_ZERO(Var)     (Var) = (0)
33
34 #define HP_TIMING_NOW(Var) __asm__ __volatile__ ("rd %%tick, %0" : "=r" (Var))
35
36 #define HP_TIMING_DIFF_INIT() \
37   do {                                                                        \
38     int __cnt = 5;                                                            \
39     GLRO(dl_hp_timing_overhead) = ~0ull;                                      \
40     do                                                                        \
41       {                                                                       \
42         hp_timing_t __t1, __t2;                                               \
43         HP_TIMING_NOW (__t1);                                                 \
44         HP_TIMING_NOW (__t2);                                                 \
45         if (__t2 - __t1 < GLRO(dl_hp_timing_overhead))                        \
46           GLRO(dl_hp_timing_overhead) = __t2 - __t1;                          \
47       }                                                                       \
48     while (--__cnt > 0);                                                      \
49   } while (0)
50
51 #define HP_TIMING_DIFF(Diff, Start, End)        (Diff) = ((End) - (Start))
52
53 #define HP_TIMING_ACCUM(Sum, Diff)                              \
54 do {                                                            \
55   hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead);    \
56   hp_timing_t tmp1, tmp2;                                       \
57   __asm__ __volatile__("1: ldx  [%3], %0\n\t"                   \
58                        "add     %0, %2, %1\n\t"                 \
59                        "casx    [%3], %0,  %1\n\t"              \
60                        "cmp     %0, %1\n\t"                     \
61                        "bne,pn  %%xcc, 1b\n\t"                  \
62                        " nop"                                   \
63                        : "=&r" (tmp1), "=&r" (tmp2)             \
64                        : "r" (__diff), "r" (&(Sum))             \
65                        : "memory", "g1", "g5", "g6");           \
66 } while(0)
67
68 #define HP_TIMING_ACCUM_NT(Sum, Diff)   (Sum) += (Diff)
69
70 #define HP_TIMING_PRINT(Buf, Len, Val) \
71   do {                                                                        \
72     char __buf[20];                                                           \
73     char *__cp = _itoa (Val, __buf + sizeof (__buf), 10, 0);                  \
74     int __len = (Len);                                                        \
75     char *__dest = (Buf);                                                     \
76     while (__len-- > 0 && __cp < __buf + sizeof (__buf))                      \
77       *__dest++ = *__cp++;                                                    \
78     memcpy (__dest, " clock cycles", MIN (__len, sizeof (" clock cycles")));  \
79   } while (0)
80
81 #endif  /* hp-timing.h */