Remove HP_TIMING_DIFF_INIT and dl_hp_timing_overhead
[glibc.git] / sysdeps / ia64 / hp-timing.h
blob6b49ffc2ebd1c1c85e9755595b2be38afc61e843
1 /* High precision, low overhead timing functions. IA-64 version.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.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>
26 #include <ia64intrin.h>
28 /* The macros defined here use the timestamp counter in IA-64. They
29 provide a very accurate way to measure the time with very little
30 overhead. The time values themself have no real meaning, only
31 differences are interesting.
33 The list of macros we need includes the following:
35 - HP_TIMING_AVAIL: test for availability.
37 - HP_TIMING_INLINE: this macro is non-zero if the functionality is not
38 implemented using function calls but instead uses some inlined code
39 which might simply consist of a few assembler instructions. We have to
40 know this since we might want to use the macros here in places where we
41 cannot make function calls.
43 - hp_timing_t: This is the type for variables used to store the time
44 values.
46 - HP_TIMING_NOW: place timestamp for current time in variable given as
47 parameter.
49 - HP_TIMING_DIFF: compute difference between two times and store it
50 in a third. Source and destination might overlap.
52 - HP_TIMING_ACCUM_NT: add time difference to another variable, without
53 being thread-safe.
55 - HP_TIMING_PRINT: write decimal representation of the timing value into
56 the given string. This operation need not be inline even though
57 HP_TIMING_INLINE is specified.
61 /* We always assume having the timestamp register. */
62 #define HP_TIMING_AVAIL (1)
64 /* We indeed have inlined functions. */
65 #define HP_TIMING_INLINE (1)
67 /* We use 64bit values for the times. */
68 typedef unsigned long int hp_timing_t;
70 /* The Itanium/Merced has a bug where the ar.itc register value read
71 is not correct in some situations. The solution is to read again.
72 For now we always do this until we know how to recognize a fixed
73 processor implementation. */
74 #define REPEAT_READ(val) __builtin_expect ((long int) val == -1, 0)
76 /* That's quite simple. Use the `ar.itc' instruction. */
77 #define HP_TIMING_NOW(Var) \
78 ({ unsigned long int __itc; \
79 do \
80 asm volatile ("mov %0=ar.itc" : "=r" (__itc) : : "memory"); \
81 while (REPEAT_READ (__itc)); \
82 Var = __itc; })
84 /* It's simple arithmetic for us. */
85 #define HP_TIMING_DIFF(Diff, Start, End) (Diff) = ((End) - (Start))
87 #define HP_TIMING_ACCUM_NT(Sum, Diff) (Sum) += (Diff)
89 /* Print the time value. */
90 #define HP_TIMING_PRINT(Buf, Len, Val) \
91 do { \
92 char __buf[20]; \
93 char *__cp = _itoa_word (Val, __buf + sizeof (__buf), 10, 0); \
94 int __len = (Len); \
95 char *__dest = (Buf); \
96 while (__len-- > 0 && __cp < __buf + sizeof (__buf)) \
97 *__dest++ = *__cp++; \
98 memcpy (__dest, " clock cycles", MIN (__len, \
99 (int) sizeof (" clock cycles"))); \
100 } while (0)
102 #endif /* hp-timing.h */