os/persistentdata/persistentstorage/sqlite3api/SQLite/hwtime.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
** 2008 May 27
sl@0
     3
**
sl@0
     4
** The author disclaims copyright to this source code.  In place of
sl@0
     5
** a legal notice, here is a blessing:
sl@0
     6
**
sl@0
     7
**    May you do good and not evil.
sl@0
     8
**    May you find forgiveness for yourself and forgive others.
sl@0
     9
**    May you share freely, never taking more than you give.
sl@0
    10
**
sl@0
    11
******************************************************************************
sl@0
    12
**
sl@0
    13
** This file contains inline asm code for retrieving "high-performance"
sl@0
    14
** counters for x86 class CPUs.
sl@0
    15
**
sl@0
    16
** $Id: hwtime.h,v 1.3 2008/08/01 14:33:15 shane Exp $
sl@0
    17
*/
sl@0
    18
#ifndef _HWTIME_H_
sl@0
    19
#define _HWTIME_H_
sl@0
    20
sl@0
    21
/*
sl@0
    22
** The following routine only works on pentium-class (or newer) processors.
sl@0
    23
** It uses the RDTSC opcode to read the cycle count value out of the
sl@0
    24
** processor and returns that value.  This can be used for high-res
sl@0
    25
** profiling.
sl@0
    26
*/
sl@0
    27
#if (defined(__GNUC__) || defined(_MSC_VER)) && \
sl@0
    28
      (defined(i386) || defined(__i386__) || defined(_M_IX86))
sl@0
    29
sl@0
    30
  #if defined(__GNUC__)
sl@0
    31
sl@0
    32
  __inline__ sqlite_uint64 sqlite3Hwtime(void){
sl@0
    33
     unsigned int lo, hi;
sl@0
    34
     __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
sl@0
    35
     return (sqlite_uint64)hi << 32 | lo;
sl@0
    36
  }
sl@0
    37
sl@0
    38
  #elif defined(_MSC_VER)
sl@0
    39
sl@0
    40
  __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
sl@0
    41
     __asm {
sl@0
    42
        rdtsc
sl@0
    43
        ret       ; return value at EDX:EAX
sl@0
    44
     }
sl@0
    45
  }
sl@0
    46
sl@0
    47
  #endif
sl@0
    48
sl@0
    49
#elif (defined(__GNUC__) && defined(__x86_64__))
sl@0
    50
sl@0
    51
  __inline__ sqlite_uint64 sqlite3Hwtime(void){
sl@0
    52
      unsigned long val;
sl@0
    53
      __asm__ __volatile__ ("rdtsc" : "=A" (val));
sl@0
    54
      return val;
sl@0
    55
  }
sl@0
    56
 
sl@0
    57
#elif (defined(__GNUC__) && defined(__ppc__))
sl@0
    58
sl@0
    59
  __inline__ sqlite_uint64 sqlite3Hwtime(void){
sl@0
    60
      unsigned long long retval;
sl@0
    61
      unsigned long junk;
sl@0
    62
      __asm__ __volatile__ ("\n\
sl@0
    63
          1:      mftbu   %1\n\
sl@0
    64
                  mftb    %L0\n\
sl@0
    65
                  mftbu   %0\n\
sl@0
    66
                  cmpw    %0,%1\n\
sl@0
    67
                  bne     1b"
sl@0
    68
                  : "=r" (retval), "=r" (junk));
sl@0
    69
      return retval;
sl@0
    70
  }
sl@0
    71
sl@0
    72
#else
sl@0
    73
sl@0
    74
  #error Need implementation of sqlite3Hwtime() for your platform.
sl@0
    75
sl@0
    76
  /*
sl@0
    77
  ** To compile without implementing sqlite3Hwtime() for your platform,
sl@0
    78
  ** you can remove the above #error and use the following
sl@0
    79
  ** stub function.  You will lose timing support for many
sl@0
    80
  ** of the debugging and testing utilities, but it should at
sl@0
    81
  ** least compile and run.
sl@0
    82
  */
sl@0
    83
  sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
sl@0
    84
sl@0
    85
#endif
sl@0
    86
sl@0
    87
#endif /* !defined(_HWTIME_H_) */