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
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#ifdef _MSC_VER
# include <immintrin.h>
# include <intrin.h>
#endif
#if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \
defined(_M_AMD64)
# define SNMALLOC_VA_BITS_64
#else
# define SNMALLOC_VA_BITS_32
#endif
namespace snmalloc
{
/**
* x86-specific architecture abstraction layer minimised for use
* inside SGX enclaves.
*/
class AAL_x86_sgx
{
public:
/**
* Bitmap of AalFeature flags
*/
static constexpr uint64_t aal_features = IntegerPointers;
static constexpr enum AalName aal_name = X86_SGX;
static constexpr size_t smallest_page_size = 0x1000;
/**
* On pipelined processors, notify the core that we are in a spin loop and
* that speculative execution past this point may not be a performance gain.
*/
static inline void pause()
{
#ifdef _MSC_VER
_mm_pause();
#else
asm volatile("pause");
#endif
}
/**
* Issue a prefetch hint at the specified address.
*/
static inline void prefetch(void* ptr)
{
#ifdef _MSC_VER
_mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0);
#else
asm volatile("prefetcht0 %0" ::"m"(ptr));
#endif
}
/**
* Return a cycle counter value.
* Not guaranteed inside an enclave, so just always return 0.
* This is only used for benchmarking inside snmalloc.
*/
static inline uint64_t tick()
{
return 0;
}
};
using AAL_Arch = AAL_x86_sgx;
} // namespace snmalloc