Multi-core Hash Joins
Main-memory hash join implementations for multi-core CPUs
rdtsc.h
1/*
2 Copyright 2011, Spyros Blanas.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
25#include <stdint.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#if !defined(__i386__) && !defined(__x86_64__) && !defined(__sparc__)
32#warning No supported architecture found -- timers will return junk.
33#endif
34
35static __inline__ uint64_t curtick() {
36 uint64_t tick;
37#if defined(__i386__)
38 unsigned long lo, hi;
39 __asm__ __volatile__ (".byte 0x0f, 0x31" : "=a" (lo), "=d" (hi));
40 tick = (uint64_t) hi << 32 | lo;
41#elif defined(__x86_64__)
42 unsigned long lo, hi;
43 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
44 tick = (uint64_t) hi << 32 | lo;
45#elif defined(__sparc__)
46 __asm__ __volatile__ ("rd %%tick, %0" : "=r" (tick));
47#endif
48 return tick;
49}
50
51static __inline__ void startTimer(uint64_t* t) {
52 *t = curtick();
53}
54
55static __inline__ void stopTimer(uint64_t* t) {
56 *t = curtick() - *t;
57}
58
59#ifdef __cplusplus
60}
61#endif