-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformula.cpp
336 lines (306 loc) · 11.9 KB
/
formula.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// This file contains code from NVSim, (c) 2012-2013, Pennsylvania State University
//and Hewlett-Packard Company. See LICENSE_NVSim file in the top-level directory.
//No part of DESTINY Project, including this file, may be copied,
//modified, propagated, or distributed except according to the terms
//contained in the LICENSE file.
#include "formula.h"
#include "constant.h"
#include <stdlib.h>
bool isPow2(int n) {
if (n < 1)
return false;
return !(n & (n - 1));
}
double CalculateGateCap(double width, Technology tech) {
return (tech.capIdealGate + tech.capOverlap + 3 * tech.capFringe) * width
+ tech.phyGateLength * tech.capPolywire;
}
double CalculateFBRAMGateCap(double width, double thicknessFactor, Technology tech) {
return (tech.capIdealGate / thicknessFactor + tech.capOverlap + 3 * tech.capFringe) * width
+ tech.phyGateLength * tech.capPolywire;
}
double CalculateFBRAMDrainCap(double width, Technology tech) {
return (3 * tech.capSidewall + tech.capDrainToChannel) * width;
}
double CalculateGateArea(
int gateType, int numInput,
double widthNMOS, double widthPMOS,
double heightTransistorRegion, Technology tech,
double *height, double *width) {
double ratio = widthPMOS / (widthPMOS + widthNMOS);
double maxWidthPMOS, maxWidthNMOS;
double unitWidthRegionP, unitWidthRegionN;
double widthRegionP, widthRegionN;
double heightRegionP, heightRegionN;
if (ratio == 0) { /* no PMOS */
maxWidthPMOS = 0;
maxWidthNMOS = heightTransistorRegion;
} else if (ratio == 1) { /* no NMOS */
maxWidthPMOS = heightTransistorRegion;
maxWidthNMOS = 0;
} else {
maxWidthPMOS = ratio * (heightTransistorRegion - MIN_GAP_BET_P_AND_N_DIFFS * tech.featureSize);
maxWidthNMOS = maxWidthPMOS / ratio * (1 - ratio);
}
if (widthPMOS > 0) {
if (widthPMOS < maxWidthPMOS) { /* No folding */
unitWidthRegionP = tech.featureSize;
heightRegionP = widthPMOS;
} else { /* Folding */
int numFoldedPMOS = (int)(ceil(widthPMOS / (maxWidthPMOS - 3 * tech.featureSize))); /* 3F for folding overhead */
unitWidthRegionP = numFoldedPMOS * tech.featureSize + (numFoldedPMOS-1) * tech.featureSize * MIN_GAP_BET_POLY;
heightRegionP = maxWidthPMOS;
}
} else {
unitWidthRegionP = 0;
heightRegionP = 0;
}
if (widthNMOS > 0) {
if (widthNMOS < maxWidthNMOS) { /* No folding */
unitWidthRegionN = tech.featureSize;
heightRegionN = widthNMOS;
} else { /* Folding */
int numFoldedNMOS = (int)(ceil(widthNMOS / (maxWidthNMOS - 3 * tech.featureSize))); /* 3F for folding overhead */
unitWidthRegionN = numFoldedNMOS * tech.featureSize + (numFoldedNMOS-1) * tech.featureSize * MIN_GAP_BET_POLY;
heightRegionN = maxWidthNMOS;
}
} else {
unitWidthRegionN = 0;
heightRegionN = 0;
}
switch (gateType) {
case INV:
widthRegionP = 2 * tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2) + unitWidthRegionP;
widthRegionN = 2 * tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2) + unitWidthRegionN;
break;
case NOR:
widthRegionP = 2 * tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2)
+ unitWidthRegionP * numInput + (numInput - 1) * tech.featureSize * MIN_GAP_BET_POLY;
widthRegionN = 2 * tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2)
+ unitWidthRegionN * numInput
+ (numInput - 1) * tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2);
break;
case NAND:
widthRegionN = 2 * tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2)
+ unitWidthRegionN * numInput + (numInput - 1) * tech.featureSize * MIN_GAP_BET_POLY;
widthRegionP = 2 * tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2)
+ unitWidthRegionP * numInput
+ (numInput - 1) * tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2);
break;
default:
widthRegionN = widthRegionP = 0;
}
*width = MAX(widthRegionN, widthRegionP);
if (widthPMOS > 0 && widthNMOS > 0) { /* it is a gate */
*height = heightRegionN + heightRegionP + tech.featureSize * MIN_GAP_BET_P_AND_N_DIFFS
+ 2 * tech.featureSize * MIN_WIDTH_POWER_RAIL;
} else { /* it is a transistor */
*height = heightRegionN + heightRegionP; /* one of them is zero, and no power rail is added */
}
return (*width)*(*height);
}
void CalculateGateCapacitance(
int gateType, int numInput,
double widthNMOS, double widthPMOS,
double heightTransistorRegion, Technology tech,
double *capInput, double *capOutput) {
/* TO-DO: most parts of this function is the same of CalculateGateArea,
* perhaps they will be combined in future
*/
double ratio = widthPMOS / (widthPMOS + widthNMOS);
double maxWidthPMOS = 0, maxWidthNMOS = 0;
double unitWidthDrainP = 0, unitWidthDrainN = 0;
double widthDrainP = 0, widthDrainN = 0;
double heightDrainP = 0, heightDrainN = 0;
int numFoldedPMOS = 1, numFoldedNMOS = 1;
if (ratio == 0) { /* no PMOS */
maxWidthPMOS = 0;
maxWidthNMOS = heightTransistorRegion;
} else if (ratio == 1) { /* no NMOS */
maxWidthPMOS = heightTransistorRegion;
maxWidthNMOS = 0;
} else {
maxWidthPMOS = ratio * (heightTransistorRegion - MIN_GAP_BET_P_AND_N_DIFFS * tech.featureSize);
maxWidthNMOS = maxWidthPMOS / ratio * (1 - ratio);
}
if (widthPMOS > 0) {
if (widthPMOS < maxWidthPMOS) { /* No folding */
unitWidthDrainP = 0;
heightDrainP = widthPMOS;
} else { /* Folding */
if (maxWidthPMOS < 3 * tech.featureSize) {
cout << "Error: Unable to do PMOS folding because PMOS size limitation is less than 3F!" <<endl;
exit(-1);
}
numFoldedPMOS = (int)(ceil(widthPMOS / (maxWidthPMOS - 3 * tech.featureSize))); /* 3F for folding overhead */
unitWidthDrainP = (numFoldedPMOS-1) * tech.featureSize * MIN_GAP_BET_POLY;
heightDrainP = maxWidthPMOS;
}
} else {
unitWidthDrainP = 0;
heightDrainP = 0;
}
if (widthNMOS > 0) {
if (widthNMOS < maxWidthNMOS) { /* No folding */
unitWidthDrainN = 0;
heightDrainN = widthNMOS;
} else { /* Folding */
if (maxWidthNMOS < 3 * tech.featureSize) {
cout << "Error: Unable to do NMOS folding because NMOS size limitation is less than 3F!" <<endl;
exit(-1);
}
numFoldedNMOS = (int)(ceil(widthNMOS / (maxWidthNMOS - 3 * tech.featureSize))); /* 3F for folding overhead */
unitWidthDrainN = (numFoldedNMOS-1) * tech.featureSize * MIN_GAP_BET_POLY;
heightDrainN = maxWidthNMOS;
}
} else {
unitWidthDrainN = 0;
heightDrainN = 0;
}
switch (gateType) {
case INV:
if (widthPMOS > 0)
widthDrainP = tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2) + unitWidthDrainP;
if (widthNMOS > 0)
widthDrainN = tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2) + unitWidthDrainN;
break;
case NOR:
/* PMOS is in series, worst case capacitance is below */
if (widthPMOS > 0)
widthDrainP = tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2)
+ unitWidthDrainP * numInput + (numInput - 1) * tech.featureSize * MIN_GAP_BET_POLY;
/* NMOS is parallel, capacitance is multiplied as below */
if (widthNMOS > 0)
widthDrainN = (tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2)
+ unitWidthDrainN) * numInput;
break;
case NAND:
/* NMOS is in series, worst case capacitance is below */
if (widthNMOS > 0)
widthDrainN = tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2)
+ unitWidthDrainN * numInput + (numInput - 1) * tech.featureSize * MIN_GAP_BET_POLY;
/* PMOS is parallel, capacitance is multiplied as below */
if (widthPMOS > 0)
widthDrainP = (tech.featureSize * (CONTACT_SIZE + MIN_GAP_BET_CONTACT_POLY * 2)
+ unitWidthDrainP) * numInput;
break;
default:
widthDrainN = widthDrainP = 0;
}
/* Junction capacitance */
double capDrainBottomN = widthDrainN * heightDrainN * tech.capJunction;
double capDrainBottomP = widthDrainP * heightDrainP * tech.capJunction;
/* Sidewall capacitance */
double capDrainSidewallN, capDrainSidewallP;
if (numFoldedNMOS % 2 == 0)
capDrainSidewallN = 2 * widthDrainN * tech.capSidewall;
else
capDrainSidewallN = (2 * widthDrainN + heightDrainN) * tech.capSidewall;
if (numFoldedPMOS % 2 == 0)
capDrainSidewallP = 2 * widthDrainP * tech.capSidewall;
else
capDrainSidewallP = (2* widthDrainP + heightDrainP) * tech.capSidewall;
/* Drain to channel capacitance */
double capDrainToChannelN = numFoldedNMOS * heightDrainN * tech.capDrainToChannel;
double capDrainToChannelP = numFoldedPMOS * heightDrainP * tech.capDrainToChannel;
if (capOutput)
*(capOutput) = capDrainBottomN + capDrainBottomP + capDrainSidewallN + capDrainSidewallP + capDrainToChannelN + capDrainToChannelP;
if (capInput)
*(capInput) = CalculateGateCap(widthNMOS, tech) + CalculateGateCap(widthPMOS, tech);
}
double CalculateDrainCap(
double width, int type,
double heightTransistorRegion, Technology tech) {
double drainCap = 0;
if (type == NMOS)
CalculateGateCapacitance(INV, 1, width, 0, heightTransistorRegion, tech, NULL, &drainCap);
else
CalculateGateCapacitance(INV, 1, 0, width, heightTransistorRegion, tech, NULL, &drainCap);
return drainCap;
}
double CalculateGateLeakage(
int gateType, int numInput,
double widthNMOS, double widthPMOS,
double temperature, Technology tech) {
int tempIndex = (int)temperature - 300;
if ((tempIndex > 100) || (tempIndex < 0)) {
cout<<"Error: Temperature is out of range"<<endl;
exit(-1);
}
double *leakN = tech.currentOffNmos;
double *leakP = tech.currentOffPmos;
double leakageN, leakageP;
switch (gateType) {
case INV:
leakageN = widthNMOS * leakN[tempIndex];
leakageP = widthPMOS * leakP[tempIndex];
return MAX(leakageN, leakageP);
case NOR:
leakageN = widthNMOS * leakN[tempIndex] * numInput;
if (numInput == 2) {
return AVG_RATIO_LEAK_2INPUT_NOR * leakageN;
}
else {
return AVG_RATIO_LEAK_3INPUT_NOR * leakageN;
}
case NAND:
leakageP = widthPMOS * leakP[tempIndex] * numInput;
if (numInput == 2) {
return AVG_RATIO_LEAK_2INPUT_NAND * leakageP;
}
else {
return AVG_RATIO_LEAK_3INPUT_NAND * leakageP;
}
default:
return 0.0;
}
}
double CalculateOnResistance(double width, int type, double temperature, Technology tech) {
double r;
int tempIndex = (int)temperature - 300;
if ((tempIndex > 100) || (tempIndex < 0)) {
cout<<"Error: Temperature is out of range"<<endl;
exit(-1);
}
if (type == NMOS)
r = tech.effectiveResistanceMultiplier * tech.vdd / (tech.currentOnNmos[tempIndex] * width);
else
r = tech.effectiveResistanceMultiplier * tech.vdd / (tech.currentOnPmos[tempIndex] * width);
return r;
}
double CalculateTransconductance(double width, int type, Technology tech) {
double gm;
double vsat;
if (type == NMOS) {
vsat = MIN(tech.vdsatNmos, tech.vdd - tech.vth);
gm = (tech.effectiveElectronMobility * tech.capOx) / 2 * width / tech.phyGateLength * vsat;
} else {
vsat = MIN(tech.vdsatPmos, tech.vdd - tech.vth);
gm = (tech.effectiveHoleMobility * tech.capOx) / 2 * width / tech.phyGateLength * vsat;
}
return gm;
}
double horowitz(double tr, double beta, double rampInput, double *rampOutput) {
double alpha;
alpha = 1 / rampInput / tr;
double vs = 0.5; /* Normalized switching voltage */
double result = tr * sqrt(log(vs) * log(vs) + 2 * alpha * beta * (1 - vs));
if (rampOutput)
*rampOutput = (1 - vs) / result;
return result;
}
double CalculateWireResistance(
double resistivity, double wireWidth, double wireThickness,
double barrierThickness, double dishingThickness, double alphaScatter) {
return(alphaScatter * resistivity / (wireThickness - barrierThickness - dishingThickness)
/ (wireWidth - 2 * barrierThickness));
}
double CalculateWireCapacitance(
double permittivity, double wireWidth, double wireThickness, double wireSpacing,
double ildThickness, double millerValue, double horizontalDielectric,
double verticalDielectric, double fringeCap) {
double verticalCap, sidewallCap;
verticalCap = 2 * permittivity * verticalDielectric * wireWidth / ildThickness;
sidewallCap = 2 * permittivity * millerValue * horizontalDielectric * wireThickness / wireSpacing;
return (verticalCap + sidewallCap + fringeCap);
}