hwtime.h

Go to the documentation of this file.
00001 /*
00002 ** 2008 May 27
00003 **
00004 ** The author disclaims copyright to this source code.  In place of
00005 ** a legal notice, here is a blessing:
00006 **
00007 **    May you do good and not evil.
00008 **    May you find forgiveness for yourself and forgive others.
00009 **    May you share freely, never taking more than you give.
00010 **
00011 ******************************************************************************
00012 **
00013 ** This file contains inline asm code for retrieving "high-performance"
00014 ** counters for x86 class CPUs.
00015 **
00016 ** $Id: hwtime.h,v 1.3 2008/08/01 14:33:15 shane Exp $
00017 */
00018 #ifndef _HWTIME_H_
00019 #define _HWTIME_H_
00020 
00021 /*
00022 ** The following routine only works on pentium-class (or newer) processors.
00023 ** It uses the RDTSC opcode to read the cycle count value out of the
00024 ** processor and returns that value.  This can be used for high-res
00025 ** profiling.
00026 */
00027 #if (defined(__GNUC__) || defined(_MSC_VER)) && \
00028       (defined(i386) || defined(__i386__) || defined(_M_IX86))
00029 
00030   #if defined(__GNUC__)
00031 
00032   __inline__ sqlite_uint64 sqlite3Hwtime(void){
00033      unsigned int lo, hi;
00034      __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
00035      return (sqlite_uint64)hi << 32 | lo;
00036   }
00037 
00038   #elif defined(_MSC_VER)
00039 
00040   __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
00041      __asm {
00042         rdtsc
00043         ret       ; return value at EDX:EAX
00044      }
00045   }
00046 
00047   #endif
00048 
00049 #elif (defined(__GNUC__) && defined(__x86_64__))
00050 
00051   __inline__ sqlite_uint64 sqlite3Hwtime(void){
00052       unsigned long val;
00053       __asm__ __volatile__ ("rdtsc" : "=A" (val));
00054       return val;
00055   }
00056  
00057 #elif (defined(__GNUC__) && defined(__ppc__))
00058 
00059   __inline__ sqlite_uint64 sqlite3Hwtime(void){
00060       unsigned long long retval;
00061       unsigned long junk;
00062       __asm__ __volatile__ ("\n\
00063           1:      mftbu   %1\n\
00064                   mftb    %L0\n\
00065                   mftbu   %0\n\
00066                   cmpw    %0,%1\n\
00067                   bne     1b"
00068                   : "=r" (retval), "=r" (junk));
00069       return retval;
00070   }
00071 
00072 #else
00073 
00074   #error Need implementation of sqlite3Hwtime() for your platform.
00075 
00076   /*
00077   ** To compile without implementing sqlite3Hwtime() for your platform,
00078   ** you can remove the above #error and use the following
00079   ** stub function.  You will lose timing support for many
00080   ** of the debugging and testing utilities, but it should at
00081   ** least compile and run.
00082   */
00083   sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
00084 
00085 #endif
00086 
00087 #endif /* !defined(_HWTIME_H_) */

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:54 2011 by Doxygen 1.6.1