2.9
[glibc/nacl-glibc.git] / sysdeps / alpha / hp-timing.h
blobccae06b4879ffe1f718615965104c898e272cd18
1 /* High precision, low overhead timing functions. Alpha version.
2 Copyright (C) 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Richard Henderson <rth@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 /* 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_ZERO: clear `hp_timing_t' object.
48 - HP_TIMING_NOW: place timestamp for current time in variable given as
49 parameter.
51 - HP_TIMING_DIFF_INIT: do whatever is necessary to be able to use the
52 HP_TIMING_DIFF macro.
54 - HP_TIMING_DIFF: compute difference between two times and store it
55 in a third. Source and destination might overlap.
57 - HP_TIMING_ACCUM: add time difference to another variable. This might
58 be a bit more complicated to implement for some platforms as the
59 operation should be thread-safe and 64bit arithmetic on 32bit platforms
60 is not.
62 - HP_TIMING_ACCUM_NT: this is the variant for situations where we know
63 there are no threads involved.
65 - HP_TIMING_PRINT: write decimal representation of the timing value into
66 the given string. This operation need not be inline even though
67 HP_TIMING_INLINE is specified.
70 /* We always have the timestamp register, but it's got only a 4 second
71 range. Use it for ld.so profiling only. */
72 #define HP_TIMING_AVAIL (0)
73 #define HP_SMALL_TIMING_AVAIL (1)
75 /* We indeed have inlined functions. */
76 #define HP_TIMING_INLINE (1)
78 /* We use 32 bit values for the times. */
79 typedef unsigned int hp_timing_t;
81 /* Set timestamp value to zero. */
82 #define HP_TIMING_ZERO(VAR) (VAR) = (0)
84 /* The "rpcc" instruction returns a 32-bit counting half and a 32-bit
85 "virtual cycle counter displacement". Subtracting the two gives us
86 a virtual cycle count. */
87 #define HP_TIMING_NOW(VAR) \
88 do { \
89 unsigned long int x_; \
90 asm volatile ("rpcc %0" : "=r"(x_)); \
91 (VAR) = (int) (x_) - (int) (x_ >> 32); \
92 } while (0)
94 /* ??? Two rpcc instructions can be scheduled simultaneously. */
95 #define HP_TIMING_DIFF_INIT() do { } while (0)
97 /* It's simple arithmetic for us. */
98 #define HP_TIMING_DIFF(Diff, Start, End) (Diff) = ((End) - (Start))
100 /* ??? Don't bother, since we're only used for ld.so. */
101 #define HP_TIMING_ACCUM(Sum, Diff) not implemented
103 /* No threads, no extra work. */
104 #define HP_TIMING_ACCUM_NT(Sum, Diff) (Sum) += (Diff)
106 /* Print the time value. */
107 #define HP_TIMING_PRINT(Buf, Len, Val) \
108 do { \
109 char __buf[20]; \
110 char *__cp = _itoa_word (Val, __buf + sizeof (__buf), 10, 0); \
111 int __len = (Len); \
112 char *__dest = (Buf); \
113 while (__len-- > 0 && __cp < __buf + sizeof (__buf)) \
114 *__dest++ = *__cp++; \
115 memcpy (__dest, " clock cycles", MIN (__len, sizeof (" clock cycles"))); \
116 } while (0)
118 #endif /* hp-timing.h */