Back to index

glibc  2.9
hp-timing.h
Go to the documentation of this file.
00001 /* High precision, low overhead timing functions.  sparc64 version.
00002    Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by David S. Miller <davem@redhat.com>, 2001.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _HP_TIMING_H
00022 #define _HP_TIMING_H 1
00023 
00024 #include <string.h>
00025 #include <sys/param.h>
00026 #include <stdio-common/_itoa.h>
00027 
00028 #define HP_TIMING_AVAIL            (1)
00029 #define HP_TIMING_INLINE    (1)
00030 
00031 typedef unsigned long int hp_timing_t;
00032 
00033 #define HP_TIMING_ZERO(Var) (Var) = (0)
00034 
00035 #define HP_TIMING_NOW(Var) __asm__ __volatile__ ("rd %%tick, %0" : "=r" (Var))
00036 
00037 #define HP_TIMING_DIFF_INIT() \
00038   do {                                                               \
00039     int __cnt = 5;                                                   \
00040     GLRO(dl_hp_timing_overhead) = ~0ull;                             \
00041     do                                                               \
00042       {                                                                     \
00043        hp_timing_t __t1, __t2;                                              \
00044        HP_TIMING_NOW (__t1);                                                \
00045        HP_TIMING_NOW (__t2);                                                \
00046        if (__t2 - __t1 < GLRO(dl_hp_timing_overhead))                       \
00047          GLRO(dl_hp_timing_overhead) = __t2 - __t1;                         \
00048       }                                                                     \
00049     while (--__cnt > 0);                                             \
00050   } while (0)
00051 
00052 #define HP_TIMING_DIFF(Diff, Start, End)  (Diff) = ((End) - (Start))
00053 
00054 #define HP_TIMING_ACCUM(Sum, Diff)                      \
00055 do {                                                    \
00056   hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead);   \
00057   hp_timing_t tmp1, tmp2;                               \
00058   __asm__ __volatile__("1: ldx     [%3], %0\n\t"               \
00059                      "add   %0, %2, %1\n\t"                    \
00060                      "casx  [%3], %0,  %1\n\t"          \
00061                      "cmp   %0, %1\n\t"                 \
00062                      "bne,pn       %%xcc, 1b\n\t"                     \
00063                      " nop"                             \
00064                      : "=&r" (tmp1), "=&r" (tmp2)              \
00065                      : "r" (__diff), "r" (&(Sum))              \
00066                      : "memory", "g1", "g5", "g6");            \
00067 } while(0)
00068 
00069 #define HP_TIMING_ACCUM_NT(Sum, Diff)     (Sum) += (Diff)
00070 
00071 #define HP_TIMING_PRINT(Buf, Len, Val) \
00072   do {                                                               \
00073     char __buf[20];                                                  \
00074     char *__cp = _itoa (Val, __buf + sizeof (__buf), 10, 0);                \
00075     int __len = (Len);                                                      \
00076     char *__dest = (Buf);                                            \
00077     while (__len-- > 0 && __cp < __buf + sizeof (__buf))                    \
00078       *__dest++ = *__cp++;                                           \
00079     memcpy (__dest, " clock cycles", MIN (__len, sizeof (" clock cycles")));  \
00080   } while (0)
00081 
00082 #endif /* hp-timing.h */