blob: ba34d385c8fa7f20c9b55a5b5916b4109ee5e433 [file] [log] [blame]
shane9bcbdad2008-05-29 20:22:37 +00001/*
2** 2008 May 27
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11******************************************************************************
12**
13** This file contains inline asm code for retrieving "high-performance"
14** counters for x86 class CPUs.
15**
16** $Id: hwtime.h,v 1.1 2008/05/29 20:22:37 shane Exp $
17*/
18#ifndef _HWTIME_H_
19#define _HWTIME_H_
20
21/*
22** The following routine only works on pentium-class (or newer) processors.
23** It uses the RDTSC opcode to read the cycle count value out of the
24** processor and returns that value. This can be used for high-res
25** profiling.
26*/
27#if (defined(__GNUC__) || defined(_MSC_VER)) && \
28 (defined(i386) || defined(__i386__) || defined(_M_IX86))
29
30 #if defined(__GNUC__)
31
32 __inline__ sqlite_uint64 sqlite3Hwtime(void){
33 unsigned int lo, hi;
34 /* We cannot use "=A", since this would use %rax on x86_64 */
35 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
36 return (sqlite_uint64)hi << 32 | lo;
37 }
38
39 #elif defined(_MSC_VER)
40
41 __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
42 __asm {
43 rdtsc
44 ret ; return value at EDX:EAX
45 }
46 }
47
48 #endif
49
50#else
51
52 #error Need implementation of sqlite3Hwtime() for your platform.
53
54 /*
55 ** To compile without implementing sqlite3Hwtime() for your platform,
56 ** you can remove the above #error and use the following
57 ** stub function. You will lose timing support for many
58 ** of the debugging and testing utilities, but it should at
59 ** least compile and run.
60 */
61 sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
62
63#endif
64
65#endif /* !defined(_HWTIME_H_) */