XED
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
xed-get-time.h
Go to the documentation of this file.
1 /*BEGIN_LEGAL
2 Intel Open Source License
3 
4 Copyright (c) 2002-2014 Intel Corporation. All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9 
10 Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer. Redistributions
12 in binary form must reproduce the above copyright notice, this list of
13 conditions and the following disclaimer in the documentation and/or
14 other materials provided with the distribution. Neither the name of
15 the Intel Corporation nor the names of its contributors may be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 END_LEGAL */
31 
32 #if !defined(_XED_GET_TIME_H_)
33 # define _XED_GET_TIME_H_
34 
35 # include "xed-portability.h"
36 # include "xed-types.h"
37 
38 # if defined(__INTEL_COMPILER) && __INTEL_COMPILER > 810 && !defined(_M_IA64)
39 # include <ia32intrin.h>
40 # endif
41 # if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 810 && !defined(_M_IA64)
42 # if __INTEL_COMPILER < 1000
43 # pragma intrinsic(__rdtsc)
44 # endif
45 # endif
46 # if !defined(__INTEL_COMPILER)
47  /* MSVS8 and later */
48 # if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(_M_IA64)
49 # include <intrin.h>
50 # pragma intrinsic(__rdtsc)
51 # endif
52 # endif
53 
54 
59 static XED_INLINE xed_uint64_t xed_get_time(void) {
60  xed_union64_t ticks;
61  // __STRICT_ANSI__ comes from the -std=c99
62 # if defined(__GNUC__) //&& !defined(__STRICT_ANSI__)
63 # if defined(__i386__) || defined(i386) || defined(i686) || defined(__x86_64__)
64  __asm__ volatile ("rdtsc":"=a" (ticks.s.lo32), "=d"(ticks.s.hi32));
65 # define FOUND_RDTSC
66 # endif
67 # endif
68 # if defined(__INTEL_COMPILER) && __INTEL_COMPILER>=810 && !defined(_M_IA64)
69  ticks.u64 = __rdtsc();
70 # define FOUND_RDTSC
71 # endif
72 # if !defined(__INTEL_COMPILER)
73 # if !defined(FOUND_RDTSC) && defined(_MSC_VER) && _MSC_VER >= 1400 && \
74  !defined(_M_IA64) && !defined(_MANAGED) /* MSVS7, 8 */
75  ticks.u64 = __rdtsc();
76 # define FOUND_RDTSC
77 # endif
78 # endif
79 # if !defined(FOUND_RDTSC)
80  ticks.u64 = 0;
81 # endif
82  return ticks.u64;
83 }
84 
85 #endif
xed_uint32_t hi32
Definition: xed-types.h:130
xed_uint64_t u64
Definition: xed-types.h:132
struct xed_union64_t::@12 s
#define XED_INLINE
static XED_INLINE xed_uint64_t xed_get_time(void)
xed_get_time() must be compiled with gnu99 on linux to enable the asm() statements.
Definition: xed-get-time.h:59
xed_uint32_t lo32
Definition: xed-types.h:129