2 // Copyright Oliver Kowalke 2009.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
15 #include <boost/assert.hpp>
16 #include <boost/bind.hpp>
17 #include <boost/cstdint.hpp>
19 #define BOOST_CONTEXT_CYCLE
21 typedef boost::uint64_t cycle_type;
25 # pragma intrinsic(__rdtsc)
29 #elif defined(__INTEL_COMPILER) || defined(__ICC) || defined(_ECC) || defined(__ICL)
33 #elif defined(__GNUC__) || defined(__SUNPRO_C)
37 boost::uint32_t lo, hi;
39 __asm__ __volatile__ (
42 ::: "%rax", "%rbx", "%rcx", "%rdx"
44 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi) );
45 __asm__ __volatile__ (
48 ::: "%rax", "%rbx", "%rcx", "%rdx"
51 return ( cycle_type)hi << 32 | lo;
54 # error "this compiler is not supported"
59 cycle_type operator()()
61 cycle_type start( cycles() );
62 return cycles() - start;
67 cycle_type overhead_cycle()
69 std::size_t iterations( 10);
70 std::vector< cycle_type > overhead( iterations, 0);
71 for ( std::size_t i( 0); i < iterations; ++i)
73 overhead.begin(), overhead.end(),
75 BOOST_ASSERT( overhead.begin() != overhead.end() );
76 return std::accumulate( overhead.begin(), overhead.end(), 0) / iterations;
79 #endif // CYCLE_X86_64_H