-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache_line.cpp
More file actions
147 lines (121 loc) · 4.39 KB
/
Copy pathcache_line.cpp
File metadata and controls
147 lines (121 loc) · 4.39 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* _ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
. ' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
.............................................
佛祖保佑 永无BUG
佛曰:
写字楼里写字间,写字间里程序员;
程序人员写程序,又拿程序换酒钱。
酒醒只在网上坐,酒醉还来网下眠;
酒醉酒醒日复日,网上网下年复年。
但愿老死电脑间,不愿鞠躬老板前;
奔驰宝马贵者趣,公交自行程序员。
别人笑我忒疯癫,我笑自己命太贱;
不见满街漂亮妹,哪个归得程序员?
*/
/**
* cache_line.cpp
*
* Copyright (C) 2024 SCTY
*
* Description:
*
* Revision History:
*
* 2024-12-14 Created By YangLing (yl.tienon@gmail.com)
*/
#include <cstdint>
#include "cache_line.hpp"
#include "basic_type.cpp"
cache_line::cache_line()
{
state = cache_state_t::MESI_CACHE_I;
dirty = false;
}
// tag
bool cache_line::cmp_tag(const pr_data_opt_t & par) const
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(par)>, bit_30>, "MUST be bit_30");
static_assert(std::is_same_v<std::remove_cvref_t<decltype(tag)>, bit_28>, "MUST be bit_28");
return tag.to_number() == (par.to_number() >> 2);
}
bool cache_line::cmp_tag(const cl_data_tag_t & par) const
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(par)>, bit_28>, "MUST be bit_28");
static_assert(std::is_same_v<std::remove_cvref_t<decltype(tag)>, bit_28>, "MUST be bit_28");
return tag == par;
}
const cl_data_tag_t & cache_line::get_tag(void) const
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(tag)>, bit_28>, "MUST be bit_28");
return tag;
}
void cache_line::set_tag(const pr_data_opt_t & par)
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(par)>, bit_30>, "MUST be bit_30");
static_assert(std::is_same_v<std::remove_cvref_t<decltype(tag)>, bit_28>, "MUST be bit_28");
tag = par.to_number() >> 2;
}
void cache_line::set_tag(const cl_data_tag_t & par)
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(par)>, bit_28>, "MUST be bit_28");
static_assert(std::is_same_v<std::remove_cvref_t<decltype(tag)>, bit_28>, "MUST be bit_28");
tag = par;
}
// dat
const pr_data_val_t & cache_line::get_dat(const pr_data_opt_t & par) const
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(dat)>, std::array<bit_32, 4>>, "Must be bit_128");
static_assert(std::is_same_v<std::remove_cvref_t<decltype(par)>, bit_30>, "MUST be bit_30");
return dat[par.to_number() % 4];
}
const cl_data_val_t & cache_line::get_dat(void) const
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(dat)>, std::array<bit_32, 4>>, "Must be bit_128");
return dat;
}
void cache_line::set_dat(const pr_data_opt_t & par, const pr_data_val_t & val)
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(dat)>, std::array<bit_32, 4>>, "Must be bit_128");
static_assert(std::is_same_v<std::remove_cvref_t<decltype(par)>, bit_30>, "MUST be bit_30");
dat[par.to_number() % 4] = val;
}
void cache_line::set_dat(const cl_data_val_t & par)
{
static_assert(std::is_same_v<std::remove_cvref_t<decltype(dat)>, std::array<bit_32, 4>>, "Must be bit_128");
static_assert(std::is_same_v<std::remove_cvref_t<decltype(par)>, std::array<bit_32, 4>>, "Must be bit_128");
dat = par;
}
// state
cache_state_t cache_line::get_state(void) const
{
return state;
}
void cache_line::set_state(const cache_state_t s)
{
state = s;
}
// dirty
bool cache_line::get_dirty(void) const
{
return dirty;
}
void cache_line::set_dirty(const bool d)
{
dirty = d;
}