-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmdk.h
59 lines (49 loc) · 1.47 KB
/
pmdk.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include <emmintrin.h>
#include <x86intrin.h>
#include <cstdint>
#define FLUSH_ALIGN ((uintptr_t)64)
#define force_inline __attribute__((always_inline)) inline
static force_inline void predrain_memory_barrier(void) {
_mm_sfence(); /* ensure CLWB or CLFLUSHOPT completes */
}
static force_inline void flush_clflush_nolog(const void *addr, size_t len) {
uintptr_t uptr;
/*
* Loop through cache-line-size (typically 64B) aligned chunks
* covering the given range.
*/
for (uptr = (uintptr_t)addr & ~(FLUSH_ALIGN - 1);
uptr < (uintptr_t)addr + len; uptr += FLUSH_ALIGN)
_mm_clflush((char *)uptr);
}
/*
* flush_clflushopt_nolog -- flush the CPU cache, using clflushopt
*/
static force_inline void flush_clflushopt_nolog(const void *addr, size_t len) {
uintptr_t uptr;
/*
* Loop through cache-line-size (typically 64B) aligned chunks
* covering the given range.
*/
for (uptr = (uintptr_t)addr & ~(FLUSH_ALIGN - 1);
uptr < (uintptr_t)addr + len; uptr += FLUSH_ALIGN) {
_mm_clflushopt((char *)uptr);
}
}
/*
* flush_clwb_nolog -- flush the CPU cache, using clwb
*/
static force_inline void flush_clwb_nolog(const void *addr, size_t len) {
uintptr_t uptr;
/*
* Loop through cache-line-size (typically 64B) aligned chunks
* covering the given range.
*/
for (uptr = (uintptr_t)addr & ~(FLUSH_ALIGN - 1);
uptr < (uintptr_t)addr + len; uptr += FLUSH_ALIGN) {
#ifndef __APPLE__
_mm_clwb((char *)uptr);
#endif
}
}