ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tsc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009-2012 Matthias Kretz <kretz@kde.org>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) version 3.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 
19 */
20 
21 #ifndef TSC_H
22 #define TSC_H
23 
24 #ifdef _MSC_VER
25 #include <intrin.h>
26 #pragma intrinsic(__rdtsc)
27 #endif
28 
30 {
31  public:
32  void Start();
33  void Stop();
34  unsigned long long Cycles() const;
35 
36  private:
37  union Data {
38  unsigned long long a;
39  unsigned int b[2];
40  } m_start, m_end;
41 };
42 
44 {
45 #ifdef _MSC_VER
46  unsigned int tmp;
47  m_start.a = __rdtscp(&tmp);
48 #else
49  asm volatile("rdtscp" : "=a"(m_start.b[0]), "=d"(m_start.b[1]) :: "ecx" );
50 #endif
51 }
52 
54 {
55 #ifdef _MSC_VER
56  unsigned int tmp;
57  m_end.a = __rdtscp(&tmp);
58 #else
59  asm volatile("rdtscp" : "=a"(m_end.b[0]), "=d"(m_end.b[1]) :: "ecx" );
60 #endif
61 }
62 
63 inline unsigned long long TimeStampCounter::Cycles() const
64 {
65  return m_end.a - m_start.a;
66 }
67 
68 #endif // TSC_H
union TimeStampCounter::Data m_end
unsigned int b[2]
Definition: tsc.h:39
void Stop()
Definition: tsc.h:53
unsigned long long Cycles() const
Definition: tsc.h:63
union TimeStampCounter::Data m_start
unsigned long long a
Definition: tsc.h:38
void Start()
Definition: tsc.h:43