remove \r
[extl.git] / extl / platform_ / windows / counter / rdtsc_counter.h
blob8e9d354f9a6623a2aa21e5b3dff84f8cc9251deb
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: rdtsc_counter.h
4 * Created: 08.02.17
5 * Updated: 08.11.13
7 * Brief: The rdtsc_counter class - precision: cpu clock count
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_PLATFORM_WINDOWS_RDTSC_COUNTER_H
13 #define EXTL_PLATFORM_WINDOWS_RDTSC_COUNTER_H
15 /*!\file rdtsc_counter.h
16 * \brief rdtsc_counter class - precision: cpu clock count
18 #ifndef __cplusplus
19 # error rdtsc_counter.h need be supported by c++.
20 #endif
22 /* ///////////////////////////////////////////////////////////////////////
23 * Includes
25 #include "prefix.h"
27 /* ///////////////////////////////////////////////////////////////////////
28 * Compatibility
30 #ifndef EXTL_WINDOWS_COUNTER_RDTSC_COUNTER_SUPPORT
31 # error rdtsc_counter.h is not supported by current compiler.
32 #endif
34 // 'rdtsc' : no return value
35 #if defined(EXTL_COMPILER_IS_MSVC) && (_MSC_VER ==1200)
36 # pragma warning(disable:4035)
37 // missing return statement at stop of non-void function "rdtsc"
38 #elif defined(EXTL_COMPILER_IS_INTEL)
39 # pragma warning(disable:1011)
40 // Function should return a value in function rdtsc_counter::rdtsc() const
41 #elif defined(EXTL_COMPILER_IS_BORLAND)
42 # pragma warn -8070
43 #endif
45 /* ///////////////////////////////////////////////////////////////////////
46 * ::extl::platform::windows namespace
48 EXTL_WINDOWS_BEGIN_WHOLE_NAMESPACE
50 /*!\brief rdtsc_counter class
52 * \ingroup extl_group_counter
54 class rdtsc_counter
56 /// \name Constructors
57 /// @{
58 public :
59 rdtsc_counter();
60 /// @}
62 /// \name Types
63 /// @{
64 private:
65 typedef rdtsc_counter class_type;
67 #ifndef EXTL_64BIT_INT_SUPPORT
68 typedef e_uint64_t interval_type;
69 typedef e_uint64_t size_type;
70 #else
71 typedef e_uint32_t interval_type;
72 typedef e_uint32_t size_type;
73 #endif
74 /// @}
76 /// \name Operations
77 /// @{
78 public:
79 inline void start();
80 inline void stop();
81 /// @}
83 /// \name Attributes
84 /// @{
85 public:
86 inline interval_type count() const;
88 private:
89 #ifdef EXTL_INLINE_ASM_IN_INLINE_SUPPORT
90 inline size_type rdtsc() const;
91 #else
92 size_type rdtsc() const;
93 #endif
94 /// @}
96 /// \name Members
97 /// @{
98 private:
99 size_type m_start;
100 size_type m_stop;
101 /// @}
104 /* ///////////////////////////////////////////////////////////////////////
105 * Class implementation
107 inline rdtsc_counter::rdtsc_counter()
108 : m_start(0), m_stop(0)
112 #ifdef EXTL_INLINE_ASM_IN_INLINE_SUPPORT
113 inline rdtsc_counter::size_type rdtsc_counter::rdtsc() const
114 #else
115 rdtsc_counter::size_type rdtsc_counter::rdtsc() const
116 #endif
118 #ifdef EXTL_INLINE_ASM_SUPPORT
119 __asm CPUID
120 /* __asm _emit 0x0F */
121 /* __asm _emit 0xA2 */
122 __asm RDTSC
123 /* __asm _emit 0x0F */
124 /* __asm _emit 0x31 */
125 #endif
128 inline void rdtsc_counter::start()
130 m_start = rdtsc();
132 inline void rdtsc_counter::stop()
134 m_stop = rdtsc();
136 inline rdtsc_counter::interval_type rdtsc_counter::count() const
138 EXTL_ASSERT(m_stop >= m_start);
139 return static_cast<interval_type>(m_stop - m_start);
142 /* ///////////////////////////////////////////////////////////////////////
143 * ::extl::platform::windows namespace
145 EXTL_WINDOWS_END_WHOLE_NAMESPACE
147 /* //////////////////////////////////////////////////////////////////// */
148 #endif /* EXTL_PLATFORM_WINDOWS_RDTSC_COUNTER_H */
149 /* //////////////////////////////////////////////////////////////////// */