-
Notifications
You must be signed in to change notification settings - Fork 363
/
x86_64.hpp
39 lines (29 loc) · 962 Bytes
/
x86_64.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// -*-C++-*-
#ifndef X86_64_ARCH_HPP
#define X86_64_ARCH_HPP
#define ARCH_x86
namespace os {
// Concept / base class Arch
struct Arch {
static constexpr uintptr_t max_canonical_addr = 0xffffffffffff;
static constexpr uint8_t word_size = sizeof(uintptr_t) * 8;
static constexpr uintptr_t min_page_size = 4096;
static constexpr const char* name = "x86_64";
static inline uint64_t cpu_cycles() noexcept;
static inline void read_memory_barrier() noexcept;
static inline void write_memory_barrier() noexcept;
};
}
// Implementation
uint64_t os::Arch::cpu_cycles() noexcept {
uint32_t hi, lo;
asm("rdtsc" : "=a"(lo), "=d"(hi));
return ((uint64_t) lo) | ((uint64_t) hi) << 32;
}
inline void os::Arch::read_memory_barrier() noexcept {
__asm volatile("lfence" ::: "memory");
}
inline void os::Arch::write_memory_barrier() noexcept {
__asm volatile("mfence" ::: "memory");
}
#endif