interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / src / hwtime.h

84 lines · 2440 bytes Raw Blame History
1/*
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 and x86_64 class CPUs.
15*/
16#ifndef SQLITE_HWTIME_H
17#define SQLITE_HWTIME_H
18
19#if defined(_MSC_VER) && defined(_WIN32)
20
21 #include "windows.h"
22 #include <profileapi.h>
23
24 __inline sqlite3_uint64 sqlite3Hwtime(void){
25 LARGE_INTEGER tm;
26 QueryPerformanceCounter(&tm);
27 return (sqlite3_uint64)tm.QuadPart;
28 }
29
30#elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && \
31 (defined(i586) || defined(__i586__) || defined(_M_IX86))
32
33 __inline__ sqlite_uint64 sqlite3Hwtime(void){
34 unsigned int lo, hi;
35 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
36 return (sqlite_uint64)hi << 32 | lo;
37 }
38
39#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
40
41 __inline__ sqlite_uint64 sqlite3Hwtime(void){
42 unsigned int lo, hi;
43 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
44 return (sqlite_uint64)hi << 32 | lo;
45 }
46
47#elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__aarch64__)
48
49 __inline__ sqlite_uint64 sqlite3Hwtime(void){
50 sqlite3_uint64 cnt;
51 __asm__ __volatile__ ("mrs %0, cntvct_el0" : "=r" (cnt));
52 return cnt;
53 }
54
55#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
56
57 __inline__ sqlite_uint64 sqlite3Hwtime(void){
58 unsigned long long retval;
59 unsigned long junk;
60 __asm__ __volatile__ ("\n\
61 1: mftbu %1\n\
62 mftb %L0\n\
63 mftbu %0\n\
64 cmpw %0,%1\n\
65 bne 1b"
66 : "=r" (retval), "=r" (junk));
67 return retval;
68 }
69
70#else
71
72 /*
73 ** asm() is needed for hardware timing support. Without asm(),
74 ** disable the sqlite3Hwtime() routine.
75 **
76 ** sqlite3Hwtime() is only used for some obscure debugging
77 ** and analysis configurations, not in any deliverable, so this
78 ** should not be a great loss.
79 */
80 sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
81
82#endif
83
84#endif /* !defined(SQLITE_HWTIME_H) */