Use libc_hidden_* for fputs (bug 15105).
[glibc.git] / sysdeps / generic / hp-timing-common.h
blob505c6bf5d2ee9395a31598bcad51c3280dc44e0c
1 /* High precision, low overhead timing functions. Generic version.
2 Copyright (C) 1998-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
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 /* In case a platform supports timers in the hardware the following macros
21 and types must be defined:
23 - HP_TIMING_AVAIL: test for availability.
25 - HP_TIMING_INLINE: this macro is non-zero if the functionality is not
26 implemented using function calls but instead uses some inlined code
27 which might simply consist of a few assembler instructions. We have to
28 know this since we might want to use the macros here in places where we
29 cannot make function calls.
31 - hp_timing_t: This is the type for variables used to store the time
32 values. This type must be integral.
34 - HP_TIMING_NOW: place timestamp for current time in variable given as
35 parameter.
38 /* The target supports hp-timing. Share the common infrastructure. */
40 #include <string.h>
41 #include <sys/param.h>
42 #include <_itoa.h>
44 /* Compute the difference between START and END, storing into DIFF. */
45 #define HP_TIMING_DIFF(Diff, Start, End) ((Diff) = (End) - (Start))
47 /* Accumulate ADD into SUM. No attempt is made to be thread-safe. */
48 #define HP_TIMING_ACCUM_NT(Sum, Diff) ((Sum) += (Diff))
50 /* Write a decimal representation of the timing value into the given string. */
51 #define HP_TIMING_PRINT(Dest, Len, Val) \
52 do { \
53 char __buf[20]; \
54 char *__dest = (Dest); \
55 size_t __len = (Len); \
56 char *__cp = _itoa ((Val), __buf + sizeof (__buf), 10, 0); \
57 size_t __cp_len = MIN (__buf + sizeof (__buf) - __cp, __len); \
58 memcpy (__dest, __cp, __cp_len); \
59 memcpy (__dest + __cp_len, " cycles", \
60 MIN (__len - __cp_len, sizeof (" cycles"))); \
61 __dest[__len - 1] = '\0'; \
62 } while (0)