Blame sysdeps/x86/hp-timing.h

Packit Service 9e899f
/* High precision, low overhead timing functions.  x86 version.
Packit Service 9e899f
   Copyright (C) 2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
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
#ifndef _HP_TIMING_H
Packit 6c4009
#define _HP_TIMING_H	1
Packit 6c4009
Packit Service 9e899f
#include <isa.h>
Packit Service 9e899f
Packit Service 9e899f
#if MINIMUM_ISA == 686 || MINIMUM_ISA == 8664
Packit 6c4009
/* We always assume having the timestamp register.  */
Packit Service 9e899f
# define HP_TIMING_AVAIL	(1)
Packit Service 9e899f
# define HP_SMALL_TIMING_AVAIL	(1)
Packit 6c4009
Packit 6c4009
/* We indeed have inlined functions.  */
Packit Service 9e899f
# define HP_TIMING_INLINE	(1)
Packit 6c4009
Packit 6c4009
/* We use 64bit values for the times.  */
Packit 6c4009
typedef unsigned long long int hp_timing_t;
Packit 6c4009
Packit 6c4009
/* That's quite simple.  Use the `rdtsc' instruction.  Note that the value
Packit 6c4009
   might not be 100% accurate since there might be some more instructions
Packit 6c4009
   running in this moment.  This could be changed by using a barrier like
Packit 6c4009
   'cpuid' right before the `rdtsc' instruciton.  But we are not interested
Packit Service f8acdb
   in accurate clock cycles here so we don't do this.
Packit Service f8acdb
Packit Service f8acdb
   NB: Use __builtin_ia32_rdtsc directly since including <x86intrin.h>
Packit Service f8acdb
   makes building glibc very slow.  */
Packit Service 6bc0b2
# ifdef USE_RDTSCP
Packit Service 6bc0b2
/* RDTSCP waits until all previous instructions have executed and all
Packit Service 6bc0b2
   previous loads are globally visible before reading the counter.
Packit Service 6bc0b2
   RDTSC doesn't wait until all previous instructions have been executed
Packit Service 6bc0b2
   before reading the counter.  */
Packit Service 6bc0b2
#  define HP_TIMING_NOW(Var) \
Packit Service 6bc0b2
  (__extension__ ({				\
Packit Service 6bc0b2
    unsigned int __aux;				\
Packit Service 6bc0b2
    (Var) = __builtin_ia32_rdtscp (&__aux);	\
Packit Service 6bc0b2
  }))
Packit Service 6bc0b2
# else
Packit Service 6bc0b2
#  define HP_TIMING_NOW(Var) ((Var) = __builtin_ia32_rdtsc ())
Packit Service 6bc0b2
# endif
Packit 6c4009
Packit Service 9e899f
# include <hp-timing-common.h>
Packit Service 9e899f
#else
Packit Service 9e899f
/* NB: Undefine _HP_TIMING_H so that <sysdeps/generic/hp-timing.h> will
Packit Service 9e899f
   be included.  */
Packit Service 9e899f
# undef _HP_TIMING_H
Packit Service 9e899f
# include <sysdeps/generic/hp-timing.h>
Packit Service 9e899f
#endif
Packit 6c4009
Packit Service 9e899f
#endif /* hp-timing.h */