-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathSharedDefinitions.h
51 lines (41 loc) · 1.77 KB
/
SharedDefinitions.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
//--------------------------------------------------------------------------------------
// SharedDefinitions.h
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
namespace
{
// Conversion functions
template <typename T> inline constexpr T Kibibytes(T val) { return val * 1024; }
template <typename T> inline constexpr T Mebibytes(T val) { return Kibibytes(val * 1024); }
template <typename T> inline constexpr T Gibibytes(T val) { return Mebibytes(val * 1024); }
// Common Constants
constexpr int c_pageSizeBytes = Kibibytes(64); // Use MEM_LARGE_PAGES; 64 KiB per page.
// ESRAM Constants
constexpr int c_esramSizeBytes = Mebibytes(32); // 32 MiB
constexpr int c_esramPageCount = c_esramSizeBytes / c_pageSizeBytes;
// DRAM Constants
constexpr int c_dramBlockPageCount = 64; // 64 pages per DRAM block; somewhat arbitrarily chosen.
constexpr int c_dramBlockSize = c_dramBlockPageCount * c_pageSizeBytes; // 4 MiB per DRAM block
template <typename T>
inline constexpr T DivRoundUp(T num, T denom)
{
return (num + denom - 1) / denom;
}
template <typename T>
constexpr T PageCount(T byteSize)
{
return DivRoundUp(byteSize, T(c_pageSize));
}
}
namespace ATG
{
struct VMemDeleter
{
void operator()(void* mem) { VirtualFree(mem, 0, MEM_RELEASE); }
};
// Small helper type to perform virtual memory cleanup on destruction.
using VirtualMemPtr = std::unique_ptr<void, VMemDeleter>;
}