|
Packit |
6c4009 |
/* High precision, low overhead timing functions. Generic version.
|
|
Packit |
6c4009 |
Copyright (C) 1998-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* In case a platform supports timers in the hardware the following macros
|
|
Packit |
6c4009 |
and types must be defined:
|
|
Packit |
6c4009 |
|
|
Packit Service |
562438 |
- HP_TIMING_AVAIL: test for availability.
|
|
Packit Service |
562438 |
|
|
Packit |
6c4009 |
- HP_TIMING_INLINE: this macro is non-zero if the functionality is not
|
|
Packit |
6c4009 |
implemented using function calls but instead uses some inlined code
|
|
Packit |
6c4009 |
which might simply consist of a few assembler instructions. We have to
|
|
Packit |
6c4009 |
know this since we might want to use the macros here in places where we
|
|
Packit |
6c4009 |
cannot make function calls.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
- hp_timing_t: This is the type for variables used to store the time
|
|
Packit |
6c4009 |
values. This type must be integral.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
- HP_TIMING_NOW: place timestamp for current time in variable given as
|
|
Packit |
6c4009 |
parameter.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The target supports hp-timing. Share the common infrastructure. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <sys/param.h>
|
|
Packit |
6c4009 |
#include <_itoa.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Compute the difference between START and END, storing into DIFF. */
|
|
Packit |
6c4009 |
#define HP_TIMING_DIFF(Diff, Start, End) ((Diff) = (End) - (Start))
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Accumulate ADD into SUM. No attempt is made to be thread-safe. */
|
|
Packit |
6c4009 |
#define HP_TIMING_ACCUM_NT(Sum, Diff) ((Sum) += (Diff))
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Write a decimal representation of the timing value into the given string. */
|
|
Packit |
6c4009 |
#define HP_TIMING_PRINT(Dest, Len, Val) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit Service |
562438 |
char __buf[20]; \
|
|
Packit |
6c4009 |
char *__dest = (Dest); \
|
|
Packit |
6c4009 |
size_t __len = (Len); \
|
|
Packit |
6c4009 |
char *__cp = _itoa ((Val), __buf + sizeof (__buf), 10, 0); \
|
|
Packit |
6c4009 |
size_t __cp_len = MIN (__buf + sizeof (__buf) - __cp, __len); \
|
|
Packit |
6c4009 |
memcpy (__dest, __cp, __cp_len); \
|
|
Packit Service |
562438 |
memcpy (__dest + __cp_len, " cycles", \
|
|
Packit Service |
562438 |
MIN (__len - __cp_len, sizeof (" cycles"))); \
|
|
Packit |
6c4009 |
__dest[__len - 1] = '\0'; \
|
|
Packit |
6c4009 |
} while (0)
|