XOR2.cc (10447:a465576671d4) XOR2.cc (10448:bc1a3b7ab5ef)
1/* Copyright (c) 2012 Massachusetts Institute of Technology
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
1#include "model/std_cells/XOR2.h"
2
3#include <cmath>
4
5#include "model/PortInfo.h"
6#include "model/EventInfo.h"
7#include "model/TransitionInfo.h"
8#include "model/std_cells/StdCellLib.h"
9#include "model/std_cells/CellMacros.h"
10#include "model/timing_graph/ElectricalNet.h"
11#include "model/timing_graph/ElectricalDriver.h"
12#include "model/timing_graph/ElectricalLoad.h"
13#include "model/timing_graph/ElectricalDelay.h"
14
15namespace DSENT
16{
17 using std::ceil;
18 using std::max;
19
20 XOR2::XOR2(const String& instance_name_, const TechModel* tech_model_)
21 : StdCell(instance_name_, tech_model_)
22 {
23 initProperties();
24 }
25
26 XOR2::~XOR2()
27 {}
28
29 void XOR2::initProperties()
30 {
31 return;
32 }
33
34 void XOR2::constructModel()
35 {
36 // All constructModel should do is create Area/NDDPower/Energy Results as
37 // well as instantiate any sub-instances using only the hard parameters
38
39 createInputPort("A");
40 createInputPort("B");
41 createOutputPort("Y");
42
43 createLoad("A_Cap");
44 createLoad("B_Cap");
45 createDelay("A_to_Y_delay");
46 createDelay("B_to_Y_delay");
47 createDriver("Y_Ron", true);
48
49 ElectricalLoad* a_cap = getLoad("A_Cap");
50 ElectricalLoad* b_cap = getLoad("B_Cap");
51 ElectricalDelay* a_to_y_delay = getDelay("A_to_Y_delay");
52 ElectricalDelay* b_to_y_delay = getDelay("B_to_Y_delay");
53 ElectricalDriver* y_ron = getDriver("Y_Ron");
54
55 getNet("A")->addDownstreamNode(a_cap);
56 getNet("B")->addDownstreamNode(b_cap);
57 a_cap->addDownstreamNode(a_to_y_delay);
58 b_cap->addDownstreamNode(b_to_y_delay);
59 a_to_y_delay->addDownstreamNode(y_ron);
60 b_to_y_delay->addDownstreamNode(y_ron);
61 y_ron->addDownstreamNode(getNet("Y"));
62
63 // Create Area result
64 // Create NDD Power result
65 createElectricalAtomicResults();
66 // Create XOR2 Event Energy Result
67 createElectricalEventAtomicResult("XOR2");
68
69 getEventInfo("Idle")->setStaticTransitionInfos();
70
71 return;
72 }
73
74 void XOR2::updateModel()
75 {
76 // Get parameters
77 double drive_strength = getDrivingStrength();
78 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
79
80 // Standard cell cache string
81 String cell_name = "XOR2_X" + (String) drive_strength;
82
83 // Get timing parameters
84 getLoad("A_Cap")->setLoadCap(cache->get(cell_name + "->Cap->A"));
85 getLoad("B_Cap")->setLoadCap(cache->get(cell_name + "->Cap->B"));
86
87 getDelay("A_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->A_to_Y"));
88 getDelay("B_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->B_to_Y"));
89
90 getDriver("Y_Ron")->setOutputRes(cache->get(cell_name + "->DriveRes->Y"));
91
92 // Set the cell area
93 getAreaResult("Active")->setValue(cache->get(cell_name + "->ActiveArea"));
94 getAreaResult("Metal1Wire")->setValue(cache->get(cell_name + "->ActiveArea"));
95
96 return;
97 }
98
99 void XOR2::evaluateModel()
100 {
101 return;
102 }
103
104 void XOR2::useModel()
105 {
106 // Get parameters
107 double drive_strength = getDrivingStrength();
108 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
109
110 // Standard cell cache string
111 String cell_name = "XOR2_X" + (String) drive_strength;
112
113 // Propagate the transition info and get the 0->1 transtion count
114 propagateTransitionInfo();
115 double P_A = getInputPort("A")->getTransitionInfo().getProbability1();
116 double P_B = getInputPort("B")->getTransitionInfo().getProbability1();
117 double A_num_trans_01 = getInputPort("A")->getTransitionInfo().getNumberTransitions01();
118 double B_num_trans_01 = getInputPort("B")->getTransitionInfo().getNumberTransitions01();
119 double Y_num_trans_01 = getOutputPort("Y")->getTransitionInfo().getNumberTransitions01();
120
121 // Calculate leakage
122 double leakage = 0;
123 leakage += cache->get(cell_name + "->Leakage->!A!B") * (1 - P_A) * (1 - P_B);
124 leakage += cache->get(cell_name + "->Leakage->!AB") * (1 - P_A) * P_B;
125 leakage += cache->get(cell_name + "->Leakage->A!B") * P_A * (1 - P_B);
126 leakage += cache->get(cell_name + "->Leakage->AB") * P_A * P_B;
127 getNddPowerResult("Leakage")->setValue(leakage);
128
129 // Get VDD
130 double vdd = getTechModel()->get("Vdd");
131
132 // Get capacitances
133 double a_b_cap = cache->get(cell_name + "->Cap->A_b");
134 double b_b_cap = cache->get(cell_name + "->Cap->B_b");
135 double y_cap = cache->get(cell_name + "->Cap->Y");
136 double y_load_cap = getNet("Y")->getTotalDownstreamCap();
137
138 // Calculate XOR Event energy
139 double xor2_event_result = 0.0;
140 xor2_event_result += a_b_cap * A_num_trans_01;
141 xor2_event_result += b_b_cap * B_num_trans_01;
142 xor2_event_result += (y_cap + y_load_cap) * Y_num_trans_01;
143 xor2_event_result *= vdd * vdd;
144 getEventResult("XOR2")->setValue(xor2_event_result);
145
146 return;
147 }
148
149 void XOR2::propagateTransitionInfo()
150 {
151 // Get input signal transition info
152 const TransitionInfo& trans_A = getInputPort("A")->getTransitionInfo();
153 const TransitionInfo& trans_B = getInputPort("B")->getTransitionInfo();
154
155 double max_freq_mult = max(trans_A.getFrequencyMultiplier(), trans_B.getFrequencyMultiplier());
156 const TransitionInfo& scaled_trans_A = trans_A.scaleFrequencyMultiplier(max_freq_mult);
157 const TransitionInfo& scaled_trans_B = trans_B.scaleFrequencyMultiplier(max_freq_mult);
158
159
160 double A_prob_00 = scaled_trans_A.getNumberTransitions00() / max_freq_mult;
161 double A_prob_01 = scaled_trans_A.getNumberTransitions01() / max_freq_mult;
162 double A_prob_10 = A_prob_01;
163 double A_prob_11 = scaled_trans_A.getNumberTransitions11() / max_freq_mult;
164 double B_prob_00 = scaled_trans_B.getNumberTransitions00() / max_freq_mult;
165 double B_prob_01 = scaled_trans_B.getNumberTransitions01() / max_freq_mult;
166 double B_prob_10 = B_prob_01;
167 double B_prob_11 = scaled_trans_B.getNumberTransitions11() / max_freq_mult;
168
169 // Set output transition info
170 double Y_prob_00 = A_prob_00 * B_prob_00 +
171 A_prob_01 * B_prob_01 +
172 A_prob_10 * B_prob_10 +
173 A_prob_11 * B_prob_11;
174 double Y_prob_01 = A_prob_00 * B_prob_01 +
175 A_prob_01 * B_prob_00 +
176 A_prob_10 * B_prob_11 +
177 A_prob_11 * B_prob_10;
178 double Y_prob_11 = A_prob_00 * B_prob_11 +
179 A_prob_01 * B_prob_10 +
180 A_prob_10 * B_prob_01 +
181 A_prob_11 * B_prob_00;
182
183 // Check that probabilities add up to 1.0 with some finite tolerance
184 ASSERT(LibUtil::Math::isEqual((Y_prob_00 + Y_prob_01 + Y_prob_01 + Y_prob_11), 1.0),
185 "[Error] " + getInstanceName() + "Output transition probabilities must add up to 1 (" +
186 (String) Y_prob_00 + ", " + (String) Y_prob_01 + ", " + (String) Y_prob_11 + ")!");
187
188 // Turn probability of transitions per cycle into number of transitions per time unit
189 TransitionInfo trans_Y(Y_prob_00 * max_freq_mult, Y_prob_01 * max_freq_mult, Y_prob_11 * max_freq_mult);
190 getOutputPort("Y")->setTransitionInfo(trans_Y);
191 return;
192 }
193
194 // Creates the standard cell, characterizes and abstracts away the details
195 void XOR2::cacheStdCell(StdCellLib* cell_lib_, double drive_strength_)
196 {
197 // Get parameters
198 double gate_pitch = cell_lib_->getTechModel()->get("Gate->PitchContacted");
199 Map<double>* cache = cell_lib_->getStdCellCache();
200
201 // Standard cell cache string
202 String cell_name = "XOR2_X" + (String) drive_strength_;
203
204 Log::printLine("=== " + cell_name + " ===");
205
206 // Now actually build the full standard cell model
207 createInputPort("A");
208 createInputPort("B");
209 createOutputPort("Y");
210
211 createNet("A_b");
212 createNet("B_b");
213
214 // Adds macros
215 CellMacros::addInverter(this, "INV1", false, true, "A", "A_b");
216 CellMacros::addInverter(this, "INV2", false, true, "B", "B_b");
217 CellMacros::addTristate(this, "INVZ1", true, true, true, true, "B", "A", "A_b", "Y");
218 CellMacros::addTristate(this, "INVZ2", true, true, true, true, "B_b", "A_b", "A", "Y");
219
220 // I have no idea how to size each of the parts haha
221 CellMacros::updateInverter(this, "INV1", drive_strength_ * 0.500);
222 CellMacros::updateInverter(this, "INV2", drive_strength_ * 0.500);
223 CellMacros::updateTristate(this, "INVZ1", drive_strength_ * 1.000);
224 CellMacros::updateTristate(this, "INVZ2", drive_strength_ * 1.000);
225
226 // Cache area result
227 double area = 0.0;
228 area += gate_pitch * getTotalHeight() * 1;
229 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV1_GatePitches").toDouble();
230 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV2_GatePitches").toDouble();
231 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ1_GatePitches").toDouble();
232 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ2_GatePitches").toDouble();
233 cache->set(cell_name + "->ActiveArea", area);
234 Log::printLine(cell_name + "->ActiveArea=" + (String) area);
235
236 // --------------------------------------------------------------------
237 // Leakage Model Calculation
238 // --------------------------------------------------------------------
239 // Cache leakage power results (for every single signal combination)
240 double leakage_00 = 0; //!A, !B
241 double leakage_01 = 0; //!A, B
242 double leakage_10 = 0; //A, !B
243 double leakage_11 = 0; //A, B
244
245 //This is so painful...
246 leakage_00 += getGenProperties()->get("INV1_LeakagePower_0").toDouble();
247 leakage_00 += getGenProperties()->get("INV2_LeakagePower_0").toDouble();
248 leakage_00 += getGenProperties()->get("INVZ1_LeakagePower_010_0").toDouble();
249 leakage_00 += getGenProperties()->get("INVZ2_LeakagePower_101_0").toDouble();
250
251 leakage_01 += getGenProperties()->get("INV1_LeakagePower_0").toDouble();
252 leakage_01 += getGenProperties()->get("INV2_LeakagePower_1").toDouble();
253 leakage_01 += getGenProperties()->get("INVZ1_LeakagePower_011_1").toDouble();
254 leakage_01 += getGenProperties()->get("INVZ2_LeakagePower_100_1").toDouble();
255
256 leakage_10 += getGenProperties()->get("INV1_LeakagePower_1").toDouble();
257 leakage_10 += getGenProperties()->get("INV2_LeakagePower_0").toDouble();
258 leakage_10 += getGenProperties()->get("INVZ1_LeakagePower_100_1").toDouble();
259 leakage_10 += getGenProperties()->get("INVZ2_LeakagePower_011_1").toDouble();
260
261 leakage_11 += getGenProperties()->get("INV1_LeakagePower_1").toDouble();
262 leakage_11 += getGenProperties()->get("INV2_LeakagePower_1").toDouble();
263 leakage_11 += getGenProperties()->get("INVZ1_LeakagePower_101_0").toDouble();
264 leakage_11 += getGenProperties()->get("INVZ2_LeakagePower_010_0").toDouble();
265
266 cache->set(cell_name + "->Leakage->!A!B", leakage_00);
267 cache->set(cell_name + "->Leakage->!AB", leakage_01);
268 cache->set(cell_name + "->Leakage->A!B", leakage_10);
269 cache->set(cell_name + "->Leakage->AB", leakage_11);
270 Log::printLine(cell_name + "->Leakage->!A!B=" + (String) leakage_00);
271 Log::printLine(cell_name + "->Leakage->!AB=" + (String) leakage_01);
272 Log::printLine(cell_name + "->Leakage->A!B=" + (String) leakage_10);
273 Log::printLine(cell_name + "->Leakage->AB=" + (String) leakage_11);
274 // --------------------------------------------------------------------
275
276 // Cache event energy results
277 /*
278 double event_a_flip = 0.0;
279 event_a_flip += getGenProperties()->get("INV1_A_Flip").toDouble() + getGenProperties()->get("INV1_ZN_Flip").toDouble();
280 event_a_flip += getGenProperties()->get("INVZ1_OE_Flip").toDouble() + getGenProperties()->get("INVZ1_OEN_Flip").toDouble();
281 event_a_flip += getGenProperties()->get("INVZ2_OE_Flip").toDouble() + getGenProperties()->get("INVZ2_OEN_Flip").toDouble();
282 cache->set(cell_name + "->Event_A_Flip", event_a_flip);
283 Log::printLine(cell_name + "->Event_A_Flip=" + (String) event_a_flip);
284
285 double event_b_flip = 0.0;
286 event_b_flip += getGenProperties()->get("INV2_A_Flip").toDouble() + getGenProperties()->get("INV2_ZN_Flip").toDouble();
287 event_b_flip += getGenProperties()->get("INVZ1_A_Flip").toDouble();
288 event_b_flip += getGenProperties()->get("INVZ2_A_Flip").toDouble();
289 cache->set(cell_name + "->Event_B_Flip", event_b_flip);
290 Log::printLine(cell_name + "->Event_B_Flip=" + (String) event_b_flip);
291
292 double event_y_flip = 0.0;
293 event_y_flip += getGenProperties()->get("INVZ1_ZN_Flip").toDouble();
294 event_y_flip += getGenProperties()->get("INVZ2_ZN_Flip").toDouble();
295 cache->set(cell_name + "->Event_Y_Flip", event_y_flip);
296 Log::printLine(cell_name + "->Event_Y_Flip=" + (String) event_y_flip);
297 */
298
299 // --------------------------------------------------------------------
300 // Get Node Capacitances
301 // --------------------------------------------------------------------
302 // Build abstracted timing model
303 double a_cap = getNet("A")->getTotalDownstreamCap();
304 double b_cap = getNet("B")->getTotalDownstreamCap();
305 double a_b_cap = getNet("A_b")->getTotalDownstreamCap();
306 double b_b_cap = getNet("B_b")->getTotalDownstreamCap();
307 double y_cap = getNet("Y")->getTotalDownstreamCap();
308
309 cache->set(cell_name + "->Cap->A", a_cap);
310 cache->set(cell_name + "->Cap->B", b_cap);
311 cache->set(cell_name + "->Cap->A_b", a_b_cap);
312 cache->set(cell_name + "->Cap->B_b", b_b_cap);
313 cache->set(cell_name + "->Cap->Y", y_cap);
314 Log::printLine(cell_name + "->Cap->A=" + (String) a_cap);
315 Log::printLine(cell_name + "->Cap->B=" + (String) b_cap);
316 Log::printLine(cell_name + "->Cap->A=" + (String) a_b_cap);
317 Log::printLine(cell_name + "->Cap->B=" + (String) b_b_cap);
318 Log::printLine(cell_name + "->Cap->Y=" + (String) y_cap);
319 // --------------------------------------------------------------------
320
321 // --------------------------------------------------------------------
322 // Build Internal Delay Model
323 // --------------------------------------------------------------------
324 double y_ron = (getDriver("INVZ1_RonZN")->getOutputRes() + getDriver("INVZ2_RonZN")->getOutputRes()) / 2;
325
326 double a_to_y_delay = 0.0;
327 a_to_y_delay += getDriver("INV1_RonZN")->calculateDelay();
328 a_to_y_delay += max(getDriver("INVZ1_RonZN")->calculateDelay(), getDriver("INVZ2_RonZN")->calculateDelay());
329
330 double b_to_y_delay = 0.0;
331 b_to_y_delay += max(getDriver("INVZ1_RonZN")->calculateDelay(), getDriver("INV2_RonZN")->calculateDelay() + getDriver("INVZ2_RonZN")->calculateDelay());
332
333 cache->set(cell_name + "->DriveRes->Y", y_ron);
334 cache->set(cell_name + "->Delay->A_to_Y", a_to_y_delay);
335 cache->set(cell_name + "->Delay->B_to_Y", b_to_y_delay);
336 Log::printLine(cell_name + "->DriveRes->Y=" + (String) y_ron);
337 Log::printLine(cell_name + "->Delay->A_to_Y=" + (String) a_to_y_delay);
338 Log::printLine(cell_name + "->Delay->B_to_Y=" + (String) b_to_y_delay);
339 // --------------------------------------------------------------------
340
341 return;
342 }
343
344} // namespace DSENT
345
22#include "model/std_cells/XOR2.h"
23
24#include <cmath>
25
26#include "model/PortInfo.h"
27#include "model/EventInfo.h"
28#include "model/TransitionInfo.h"
29#include "model/std_cells/StdCellLib.h"
30#include "model/std_cells/CellMacros.h"
31#include "model/timing_graph/ElectricalNet.h"
32#include "model/timing_graph/ElectricalDriver.h"
33#include "model/timing_graph/ElectricalLoad.h"
34#include "model/timing_graph/ElectricalDelay.h"
35
36namespace DSENT
37{
38 using std::ceil;
39 using std::max;
40
41 XOR2::XOR2(const String& instance_name_, const TechModel* tech_model_)
42 : StdCell(instance_name_, tech_model_)
43 {
44 initProperties();
45 }
46
47 XOR2::~XOR2()
48 {}
49
50 void XOR2::initProperties()
51 {
52 return;
53 }
54
55 void XOR2::constructModel()
56 {
57 // All constructModel should do is create Area/NDDPower/Energy Results as
58 // well as instantiate any sub-instances using only the hard parameters
59
60 createInputPort("A");
61 createInputPort("B");
62 createOutputPort("Y");
63
64 createLoad("A_Cap");
65 createLoad("B_Cap");
66 createDelay("A_to_Y_delay");
67 createDelay("B_to_Y_delay");
68 createDriver("Y_Ron", true);
69
70 ElectricalLoad* a_cap = getLoad("A_Cap");
71 ElectricalLoad* b_cap = getLoad("B_Cap");
72 ElectricalDelay* a_to_y_delay = getDelay("A_to_Y_delay");
73 ElectricalDelay* b_to_y_delay = getDelay("B_to_Y_delay");
74 ElectricalDriver* y_ron = getDriver("Y_Ron");
75
76 getNet("A")->addDownstreamNode(a_cap);
77 getNet("B")->addDownstreamNode(b_cap);
78 a_cap->addDownstreamNode(a_to_y_delay);
79 b_cap->addDownstreamNode(b_to_y_delay);
80 a_to_y_delay->addDownstreamNode(y_ron);
81 b_to_y_delay->addDownstreamNode(y_ron);
82 y_ron->addDownstreamNode(getNet("Y"));
83
84 // Create Area result
85 // Create NDD Power result
86 createElectricalAtomicResults();
87 // Create XOR2 Event Energy Result
88 createElectricalEventAtomicResult("XOR2");
89
90 getEventInfo("Idle")->setStaticTransitionInfos();
91
92 return;
93 }
94
95 void XOR2::updateModel()
96 {
97 // Get parameters
98 double drive_strength = getDrivingStrength();
99 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
100
101 // Standard cell cache string
102 String cell_name = "XOR2_X" + (String) drive_strength;
103
104 // Get timing parameters
105 getLoad("A_Cap")->setLoadCap(cache->get(cell_name + "->Cap->A"));
106 getLoad("B_Cap")->setLoadCap(cache->get(cell_name + "->Cap->B"));
107
108 getDelay("A_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->A_to_Y"));
109 getDelay("B_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->B_to_Y"));
110
111 getDriver("Y_Ron")->setOutputRes(cache->get(cell_name + "->DriveRes->Y"));
112
113 // Set the cell area
114 getAreaResult("Active")->setValue(cache->get(cell_name + "->ActiveArea"));
115 getAreaResult("Metal1Wire")->setValue(cache->get(cell_name + "->ActiveArea"));
116
117 return;
118 }
119
120 void XOR2::evaluateModel()
121 {
122 return;
123 }
124
125 void XOR2::useModel()
126 {
127 // Get parameters
128 double drive_strength = getDrivingStrength();
129 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
130
131 // Standard cell cache string
132 String cell_name = "XOR2_X" + (String) drive_strength;
133
134 // Propagate the transition info and get the 0->1 transtion count
135 propagateTransitionInfo();
136 double P_A = getInputPort("A")->getTransitionInfo().getProbability1();
137 double P_B = getInputPort("B")->getTransitionInfo().getProbability1();
138 double A_num_trans_01 = getInputPort("A")->getTransitionInfo().getNumberTransitions01();
139 double B_num_trans_01 = getInputPort("B")->getTransitionInfo().getNumberTransitions01();
140 double Y_num_trans_01 = getOutputPort("Y")->getTransitionInfo().getNumberTransitions01();
141
142 // Calculate leakage
143 double leakage = 0;
144 leakage += cache->get(cell_name + "->Leakage->!A!B") * (1 - P_A) * (1 - P_B);
145 leakage += cache->get(cell_name + "->Leakage->!AB") * (1 - P_A) * P_B;
146 leakage += cache->get(cell_name + "->Leakage->A!B") * P_A * (1 - P_B);
147 leakage += cache->get(cell_name + "->Leakage->AB") * P_A * P_B;
148 getNddPowerResult("Leakage")->setValue(leakage);
149
150 // Get VDD
151 double vdd = getTechModel()->get("Vdd");
152
153 // Get capacitances
154 double a_b_cap = cache->get(cell_name + "->Cap->A_b");
155 double b_b_cap = cache->get(cell_name + "->Cap->B_b");
156 double y_cap = cache->get(cell_name + "->Cap->Y");
157 double y_load_cap = getNet("Y")->getTotalDownstreamCap();
158
159 // Calculate XOR Event energy
160 double xor2_event_result = 0.0;
161 xor2_event_result += a_b_cap * A_num_trans_01;
162 xor2_event_result += b_b_cap * B_num_trans_01;
163 xor2_event_result += (y_cap + y_load_cap) * Y_num_trans_01;
164 xor2_event_result *= vdd * vdd;
165 getEventResult("XOR2")->setValue(xor2_event_result);
166
167 return;
168 }
169
170 void XOR2::propagateTransitionInfo()
171 {
172 // Get input signal transition info
173 const TransitionInfo& trans_A = getInputPort("A")->getTransitionInfo();
174 const TransitionInfo& trans_B = getInputPort("B")->getTransitionInfo();
175
176 double max_freq_mult = max(trans_A.getFrequencyMultiplier(), trans_B.getFrequencyMultiplier());
177 const TransitionInfo& scaled_trans_A = trans_A.scaleFrequencyMultiplier(max_freq_mult);
178 const TransitionInfo& scaled_trans_B = trans_B.scaleFrequencyMultiplier(max_freq_mult);
179
180
181 double A_prob_00 = scaled_trans_A.getNumberTransitions00() / max_freq_mult;
182 double A_prob_01 = scaled_trans_A.getNumberTransitions01() / max_freq_mult;
183 double A_prob_10 = A_prob_01;
184 double A_prob_11 = scaled_trans_A.getNumberTransitions11() / max_freq_mult;
185 double B_prob_00 = scaled_trans_B.getNumberTransitions00() / max_freq_mult;
186 double B_prob_01 = scaled_trans_B.getNumberTransitions01() / max_freq_mult;
187 double B_prob_10 = B_prob_01;
188 double B_prob_11 = scaled_trans_B.getNumberTransitions11() / max_freq_mult;
189
190 // Set output transition info
191 double Y_prob_00 = A_prob_00 * B_prob_00 +
192 A_prob_01 * B_prob_01 +
193 A_prob_10 * B_prob_10 +
194 A_prob_11 * B_prob_11;
195 double Y_prob_01 = A_prob_00 * B_prob_01 +
196 A_prob_01 * B_prob_00 +
197 A_prob_10 * B_prob_11 +
198 A_prob_11 * B_prob_10;
199 double Y_prob_11 = A_prob_00 * B_prob_11 +
200 A_prob_01 * B_prob_10 +
201 A_prob_10 * B_prob_01 +
202 A_prob_11 * B_prob_00;
203
204 // Check that probabilities add up to 1.0 with some finite tolerance
205 ASSERT(LibUtil::Math::isEqual((Y_prob_00 + Y_prob_01 + Y_prob_01 + Y_prob_11), 1.0),
206 "[Error] " + getInstanceName() + "Output transition probabilities must add up to 1 (" +
207 (String) Y_prob_00 + ", " + (String) Y_prob_01 + ", " + (String) Y_prob_11 + ")!");
208
209 // Turn probability of transitions per cycle into number of transitions per time unit
210 TransitionInfo trans_Y(Y_prob_00 * max_freq_mult, Y_prob_01 * max_freq_mult, Y_prob_11 * max_freq_mult);
211 getOutputPort("Y")->setTransitionInfo(trans_Y);
212 return;
213 }
214
215 // Creates the standard cell, characterizes and abstracts away the details
216 void XOR2::cacheStdCell(StdCellLib* cell_lib_, double drive_strength_)
217 {
218 // Get parameters
219 double gate_pitch = cell_lib_->getTechModel()->get("Gate->PitchContacted");
220 Map<double>* cache = cell_lib_->getStdCellCache();
221
222 // Standard cell cache string
223 String cell_name = "XOR2_X" + (String) drive_strength_;
224
225 Log::printLine("=== " + cell_name + " ===");
226
227 // Now actually build the full standard cell model
228 createInputPort("A");
229 createInputPort("B");
230 createOutputPort("Y");
231
232 createNet("A_b");
233 createNet("B_b");
234
235 // Adds macros
236 CellMacros::addInverter(this, "INV1", false, true, "A", "A_b");
237 CellMacros::addInverter(this, "INV2", false, true, "B", "B_b");
238 CellMacros::addTristate(this, "INVZ1", true, true, true, true, "B", "A", "A_b", "Y");
239 CellMacros::addTristate(this, "INVZ2", true, true, true, true, "B_b", "A_b", "A", "Y");
240
241 // I have no idea how to size each of the parts haha
242 CellMacros::updateInverter(this, "INV1", drive_strength_ * 0.500);
243 CellMacros::updateInverter(this, "INV2", drive_strength_ * 0.500);
244 CellMacros::updateTristate(this, "INVZ1", drive_strength_ * 1.000);
245 CellMacros::updateTristate(this, "INVZ2", drive_strength_ * 1.000);
246
247 // Cache area result
248 double area = 0.0;
249 area += gate_pitch * getTotalHeight() * 1;
250 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV1_GatePitches").toDouble();
251 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV2_GatePitches").toDouble();
252 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ1_GatePitches").toDouble();
253 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ2_GatePitches").toDouble();
254 cache->set(cell_name + "->ActiveArea", area);
255 Log::printLine(cell_name + "->ActiveArea=" + (String) area);
256
257 // --------------------------------------------------------------------
258 // Leakage Model Calculation
259 // --------------------------------------------------------------------
260 // Cache leakage power results (for every single signal combination)
261 double leakage_00 = 0; //!A, !B
262 double leakage_01 = 0; //!A, B
263 double leakage_10 = 0; //A, !B
264 double leakage_11 = 0; //A, B
265
266 //This is so painful...
267 leakage_00 += getGenProperties()->get("INV1_LeakagePower_0").toDouble();
268 leakage_00 += getGenProperties()->get("INV2_LeakagePower_0").toDouble();
269 leakage_00 += getGenProperties()->get("INVZ1_LeakagePower_010_0").toDouble();
270 leakage_00 += getGenProperties()->get("INVZ2_LeakagePower_101_0").toDouble();
271
272 leakage_01 += getGenProperties()->get("INV1_LeakagePower_0").toDouble();
273 leakage_01 += getGenProperties()->get("INV2_LeakagePower_1").toDouble();
274 leakage_01 += getGenProperties()->get("INVZ1_LeakagePower_011_1").toDouble();
275 leakage_01 += getGenProperties()->get("INVZ2_LeakagePower_100_1").toDouble();
276
277 leakage_10 += getGenProperties()->get("INV1_LeakagePower_1").toDouble();
278 leakage_10 += getGenProperties()->get("INV2_LeakagePower_0").toDouble();
279 leakage_10 += getGenProperties()->get("INVZ1_LeakagePower_100_1").toDouble();
280 leakage_10 += getGenProperties()->get("INVZ2_LeakagePower_011_1").toDouble();
281
282 leakage_11 += getGenProperties()->get("INV1_LeakagePower_1").toDouble();
283 leakage_11 += getGenProperties()->get("INV2_LeakagePower_1").toDouble();
284 leakage_11 += getGenProperties()->get("INVZ1_LeakagePower_101_0").toDouble();
285 leakage_11 += getGenProperties()->get("INVZ2_LeakagePower_010_0").toDouble();
286
287 cache->set(cell_name + "->Leakage->!A!B", leakage_00);
288 cache->set(cell_name + "->Leakage->!AB", leakage_01);
289 cache->set(cell_name + "->Leakage->A!B", leakage_10);
290 cache->set(cell_name + "->Leakage->AB", leakage_11);
291 Log::printLine(cell_name + "->Leakage->!A!B=" + (String) leakage_00);
292 Log::printLine(cell_name + "->Leakage->!AB=" + (String) leakage_01);
293 Log::printLine(cell_name + "->Leakage->A!B=" + (String) leakage_10);
294 Log::printLine(cell_name + "->Leakage->AB=" + (String) leakage_11);
295 // --------------------------------------------------------------------
296
297 // Cache event energy results
298 /*
299 double event_a_flip = 0.0;
300 event_a_flip += getGenProperties()->get("INV1_A_Flip").toDouble() + getGenProperties()->get("INV1_ZN_Flip").toDouble();
301 event_a_flip += getGenProperties()->get("INVZ1_OE_Flip").toDouble() + getGenProperties()->get("INVZ1_OEN_Flip").toDouble();
302 event_a_flip += getGenProperties()->get("INVZ2_OE_Flip").toDouble() + getGenProperties()->get("INVZ2_OEN_Flip").toDouble();
303 cache->set(cell_name + "->Event_A_Flip", event_a_flip);
304 Log::printLine(cell_name + "->Event_A_Flip=" + (String) event_a_flip);
305
306 double event_b_flip = 0.0;
307 event_b_flip += getGenProperties()->get("INV2_A_Flip").toDouble() + getGenProperties()->get("INV2_ZN_Flip").toDouble();
308 event_b_flip += getGenProperties()->get("INVZ1_A_Flip").toDouble();
309 event_b_flip += getGenProperties()->get("INVZ2_A_Flip").toDouble();
310 cache->set(cell_name + "->Event_B_Flip", event_b_flip);
311 Log::printLine(cell_name + "->Event_B_Flip=" + (String) event_b_flip);
312
313 double event_y_flip = 0.0;
314 event_y_flip += getGenProperties()->get("INVZ1_ZN_Flip").toDouble();
315 event_y_flip += getGenProperties()->get("INVZ2_ZN_Flip").toDouble();
316 cache->set(cell_name + "->Event_Y_Flip", event_y_flip);
317 Log::printLine(cell_name + "->Event_Y_Flip=" + (String) event_y_flip);
318 */
319
320 // --------------------------------------------------------------------
321 // Get Node Capacitances
322 // --------------------------------------------------------------------
323 // Build abstracted timing model
324 double a_cap = getNet("A")->getTotalDownstreamCap();
325 double b_cap = getNet("B")->getTotalDownstreamCap();
326 double a_b_cap = getNet("A_b")->getTotalDownstreamCap();
327 double b_b_cap = getNet("B_b")->getTotalDownstreamCap();
328 double y_cap = getNet("Y")->getTotalDownstreamCap();
329
330 cache->set(cell_name + "->Cap->A", a_cap);
331 cache->set(cell_name + "->Cap->B", b_cap);
332 cache->set(cell_name + "->Cap->A_b", a_b_cap);
333 cache->set(cell_name + "->Cap->B_b", b_b_cap);
334 cache->set(cell_name + "->Cap->Y", y_cap);
335 Log::printLine(cell_name + "->Cap->A=" + (String) a_cap);
336 Log::printLine(cell_name + "->Cap->B=" + (String) b_cap);
337 Log::printLine(cell_name + "->Cap->A=" + (String) a_b_cap);
338 Log::printLine(cell_name + "->Cap->B=" + (String) b_b_cap);
339 Log::printLine(cell_name + "->Cap->Y=" + (String) y_cap);
340 // --------------------------------------------------------------------
341
342 // --------------------------------------------------------------------
343 // Build Internal Delay Model
344 // --------------------------------------------------------------------
345 double y_ron = (getDriver("INVZ1_RonZN")->getOutputRes() + getDriver("INVZ2_RonZN")->getOutputRes()) / 2;
346
347 double a_to_y_delay = 0.0;
348 a_to_y_delay += getDriver("INV1_RonZN")->calculateDelay();
349 a_to_y_delay += max(getDriver("INVZ1_RonZN")->calculateDelay(), getDriver("INVZ2_RonZN")->calculateDelay());
350
351 double b_to_y_delay = 0.0;
352 b_to_y_delay += max(getDriver("INVZ1_RonZN")->calculateDelay(), getDriver("INV2_RonZN")->calculateDelay() + getDriver("INVZ2_RonZN")->calculateDelay());
353
354 cache->set(cell_name + "->DriveRes->Y", y_ron);
355 cache->set(cell_name + "->Delay->A_to_Y", a_to_y_delay);
356 cache->set(cell_name + "->Delay->B_to_Y", b_to_y_delay);
357 Log::printLine(cell_name + "->DriveRes->Y=" + (String) y_ron);
358 Log::printLine(cell_name + "->Delay->A_to_Y=" + (String) a_to_y_delay);
359 Log::printLine(cell_name + "->Delay->B_to_Y=" + (String) b_to_y_delay);
360 // --------------------------------------------------------------------
361
362 return;
363 }
364
365} // namespace DSENT
366