Repository navigation
Expand file tree
/
Copy pathMemoryConstants.h
More file actions
80 lines (48 loc) · 1.63 KB
/
Copy pathMemoryConstants.h
File metadata and controls
80 lines (48 loc) · 1.63 KB
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
71
72
73
74
75
76
77
78
79
80
#pragma once
#include <climits>
#include <stdint.h>
#ifdef TEST_CONSTANTS
#define OFFSET_WIDTH 1
#define PHYSICAL_ADDRESS_WIDTH 4
#define VIRTUAL_ADDRESS_WIDTH 5
#elif NORMAL_CONSTANTS
#define OFFSET_WIDTH 4
#define PHYSICAL_ADDRESS_WIDTH 10
#define VIRTUAL_ADDRESS_WIDTH 20
#elif OFFSET_DIFFERENT_FROM_INDEX
#define OFFSET_WIDTH 2
#define PHYSICAL_ADDRESS_WIDTH 5
#define VIRTUAL_ADDRESS_WIDTH 7
#elif SINGLE_TABLE_CONSTANTS
#define OFFSET_WIDTH 5
#define PHYSICAL_ADDRESS_WIDTH 6
#define VIRTUAL_ADDRESS_WIDTH 10
#elif UNREACHABLE_FRAMES_CONSTANTS
#define OFFSET_WIDTH 3
#define PHYSICAL_ADDRESS_WIDTH 9
#define VIRTUAL_ADDRESS_WIDTH 6
#elif NO_EVICTION_CONSTANTS
#define OFFSET_WIDTH 5
#define PHYSICAL_ADDRESS_WIDTH 5
#define VIRTUAL_ADDRESS_WIDTH 5
#else
#error "You didn't define which constants to use"
#endif
/* ----------- common to all constant configurations -------------- */
// word
typedef int word_t;
// number of bits in a word
#define WORD_WIDTH (sizeof(word_t) * CHAR_BIT)
// page/frame size in words
// in this implementation this is also the number of entries in a table
#define PAGE_SIZE (1LL << OFFSET_WIDTH)
// RAM size in words
#define RAM_SIZE (1LL << PHYSICAL_ADDRESS_WIDTH)
// virtual memory size in words
#define VIRTUAL_MEMORY_SIZE (1LL << VIRTUAL_ADDRESS_WIDTH)
// number of frames in the RAM
#define NUM_FRAMES (RAM_SIZE / PAGE_SIZE)
// number of pages in the virtual memory
#define NUM_PAGES (VIRTUAL_MEMORY_SIZE / PAGE_SIZE)
#define CEIL(VARIABLE) ( (VARIABLE - (int)VARIABLE)==0 ? (int)VARIABLE : (int)VARIABLE+1 )
#define TABLES_DEPTH CEIL((((VIRTUAL_ADDRESS_WIDTH - OFFSET_WIDTH) / (double)OFFSET_WIDTH)))