Blame sysdeps/generic/hp-timing-common.h

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