-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCAM_InputEncoder.cpp
202 lines (188 loc) · 6.6 KB
/
CAM_InputEncoder.cpp
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "CAM_InputEncoder.h"
#include "global.h"
#include "formula.h"
#include "typedef.h"
CAM_InputEncoder::CAM_InputEncoder() {
// TODO Auto-generated constructor stub
initialized = false;
capLoad = 0;
resLoad = 0;
typeEncoder = encoding_two_bit;
isCustom = false;
numInputBits = 2;
capNandIn = 0;
capNandOut = 0;
widthNandN = 0;
widthNandP = 0;
rampInput = 0;
rampOutput = 0;
}
CAM_InputEncoder::~CAM_InputEncoder() {
// TODO Auto-generated destructor stub
}
void CAM_InputEncoder::Initialize(TypeOfInputEncoder _typeEncoder, bool _isCustom, double _capLoad, double _resLoad){
if (initialized)
cout << "[CAM_InputEncoder] Warning: Already initialized!" << endl;
capLoad = _capLoad;
resLoad = _resLoad;
typeEncoder = _typeEncoder;
isCustom = _isCustom;
if(isCustom) {
// TODO Customizable Input Encoder
cout<<"[CAM_InputEncoder] Error: Customized input encoder is under development."<<endl;
return;
}
else if(typeEncoder == encoding_two_bit) {
numInputBits = 2;
/* gate sizing: built up with 2-input nand */
widthNandN = 2 * MIN_NMOS_SIZE * tech->featureSize;
widthNandP = tech->pnSizeRatio * MIN_NMOS_SIZE * tech->featureSize;
double logicEffort = (2+tech->pnSizeRatio) / (1+tech->pnSizeRatio);
CalculateGateCapacitance(NAND, 2, widthNandN, widthNandP, tech->featureSize*MAX_TRANSISTOR_HEIGHT, *tech, &capNandIn, &capNandOut);
outputDriver.Initialize(logicEffort, capNandOut, capLoad, resLoad, true, latency_first, 0);
initialized = true;
}
else {
// TODO Encoding scheme look up table
cout<<"[CAM_InputEncoder] Error: Two-bit encoder in JSSC11 is the only scheme supported in this version."<<endl;
return;
}
}
void CAM_InputEncoder::CalculateArea(){
if (!initialized) {
cout << "[CAM_InputEncoder] Error: Require initialization first!" << endl;
} else {
if(isCustom) {
// TODO Customizable Input Encoder
cout<<"[CAM_InputEncoder] Error: Customized input encoder is under development."<<endl;
return;
}
else if(typeEncoder == encoding_two_bit) {
outputDriver.CalculateArea();
height = outputDriver.height * numInputBits * 2;
width = outputDriver.width;
double hNand, wNand;
CalculateGateArea(NAND, 2, widthNandN, widthNandP, tech->featureSize*MAX_TRANSISTOR_HEIGHT, *tech, &hNand, &wNand);
width += wNand;
height = MAX(height, hNand * numInputBits * 2);
area = height * width;
}
else {
// TODO Encoding scheme look up table
cout<<"[CAM_InputEncoder] Error: Two-bit encoder in JSSC11 is the only scheme supported in this version."<<endl;
return;
}
}
}
void CAM_InputEncoder::CalculateRC() {
if (!initialized) {
cout << "[CAM_InputEncoder] Error: Require initialization first!" << endl;
} else {
if(isCustom) {
// TODO Customizable Input Encoder
cout<<"[CAM_InputEncoder] Error: Customized input encoder is under development."<<endl;
return;
}
else if(typeEncoder == encoding_two_bit) {
outputDriver.CalculateRC();
CalculateGateCapacitance(NAND, 2, widthNandN, widthNandP, tech->featureSize*MAX_TRANSISTOR_HEIGHT, *tech, &capNandIn, &capNandOut);
}
else {
// TODO Encoding scheme look up table
cout<<"[CAM_InputEncoder] Error: Two-bit encoder in JSSC11 is the only scheme supported in this version."<<endl;
return;
}
}
}
void CAM_InputEncoder::CalculateLatency(double _rampInput) {
if (!initialized) {
cout << "[CAM_InputEncoder] Error: Require initialization first!" << endl;
} else {
if(isCustom) {
// TODO Customizable Input Encoder
cout<<"[CAM_InputEncoder] Error: Customized input encoder is under development."<<endl;
return;
}
else if(typeEncoder == encoding_two_bit) {
rampInput = _rampInput;
double resPullDown;
double cap;
double tr; /* time constant */
double gm; /* transconductance */
double beta; /* for horowitz calculation */
double rampInternal;
/* nand and the driver */
resPullDown = CalculateOnResistance(widthNandN, NMOS, inputParameter->temperature, *tech);
gm = CalculateTransconductance(widthNandN, NMOS, *tech);
beta = 1 / (resPullDown * gm);
cap = capNandOut + outputDriver.capInput[0];
tr = resPullDown * cap;
readLatency = horowitz(tr, beta, rampInput, &rampInternal);
outputDriver.CalculateLatency(rampInternal);
readLatency += outputDriver.readLatency;
writeLatency = readLatency;
rampOutput = outputDriver.rampOutput;
}
else {
// TODO Encoding scheme look up table
cout<<"[CAM_InputEncoder] Error: Two-bit encoder in JSSC11 is the only scheme supported in this version."<<endl;
return;
}
}
}
void CAM_InputEncoder::CalculatePower() {
if (!initialized) {
cout << "[CAM_InputEncoder] Error: Require initialization first!" << endl;
} else {
outputDriver.CalculatePower();
if(isCustom) {
// TODO Customizable Input Encoder
cout<<"[CAM_InputEncoder] Error: Customized input encoder is under development."<<endl;
return;
}
else if(typeEncoder == encoding_two_bit) {
leakage = CalculateGateLeakage(NAND, 2, widthNandN, widthNandP, inputParameter->temperature, *tech) * tech->vdd * numInputBits * 2;
leakage += outputDriver.leakage * numInputBits * 2;
/* nand and the driver */
double cap;
cap = outputDriver.capInput[0] + capNandOut;
readDynamicEnergy = numInputBits * 2 * cap * tech->vdd * tech->vdd;
readDynamicEnergy += (numInputBits * 2 * outputDriver.readDynamicEnergy);
writeDynamicEnergy = readDynamicEnergy;
}
else {
// TODO Encoding scheme look up table
cout<<"[CAM_InputEncoder] Error: Two-bit encoder in JSSC11 is the only scheme supported in this version."<<endl;
return;
}
}
}
void CAM_InputEncoder::PrintProperty() {
cout << "CAM_InputEncoder Properties:" << endl;
FunctionUnit::PrintProperty();
}
CAM_InputEncoder & CAM_InputEncoder::operator=(const CAM_InputEncoder &rhs) {
height = rhs.height;
width = rhs.width;
area = rhs.area;
readLatency = rhs.readLatency;
writeLatency = rhs.writeLatency;
readDynamicEnergy = rhs.readDynamicEnergy;
writeDynamicEnergy = rhs.writeDynamicEnergy;
leakage = rhs.leakage;
initialized = rhs.initialized;
capLoad = rhs.capLoad;
rampInput = rhs.rampInput;
rampOutput = rhs.rampOutput;
resLoad = rhs.resLoad;
capNandIn = rhs.capNandIn;
capNandOut = rhs.capNandOut;
widthNandN = rhs.widthNandN;
widthNandP = rhs.widthNandP;
rampInput = rhs.rampInput;
rampOutput = rhs.rampOutput;
isCustom = rhs.isCustom;
typeEncoder = rhs.typeEncoder;
numInputBits = rhs.numInputBits;
return *this;
}