1 /* Copyright (c) 2012 Massachusetts Institute of Technology
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
22 #include "model/std_cells/NOR2.h"
26 #include "model/PortInfo.h"
27 #include "model/TransitionInfo.h"
28 #include "model/EventInfo.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"
41 NOR2::NOR2(const String
& instance_name_
, const TechModel
* tech_model_
)
42 : StdCell(instance_name_
, tech_model_
)
50 void NOR2::initProperties()
55 void NOR2::constructModel()
57 // All constructModel should do is create Area/NDDPower/Energy Results as
58 // well as instantiate any sub-instances using only the hard parameters
62 createOutputPort("Y");
66 createDelay("A_to_Y_delay");
67 createDelay("B_to_Y_delay");
68 createDriver("Y_Ron", true);
70 ElectricalLoad
* a_cap
= getLoad("A_Cap");
71 ElectricalLoad
* b_cap
= getLoad("A_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");
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"));
85 // Create NDD Power result
86 createElectricalAtomicResults();
87 // Create NOR Event Energy Result
88 createElectricalEventAtomicResult("NOR2");
90 getEventInfo("Idle")->setStaticTransitionInfos();
95 void NOR2::updateModel()
97 // All updateModel should do is calculate numbers for the Area/NDDPower/Energy
98 // Results as anything else that needs to be done using either soft or hard parameters
101 double drive_strength
= getDrivingStrength();
102 Map
<double>* cache
= getTechModel()->getStdCellLib()->getStdCellCache();
104 // Standard cell cache string
105 String cell_name
= "NOR2_X" + (String
) drive_strength
;
107 // Get timing parameters
108 getLoad("A_Cap")->setLoadCap(cache
->get(cell_name
+ "->Cap->A"));
109 getLoad("B_Cap")->setLoadCap(cache
->get(cell_name
+ "->Cap->B"));
110 getDelay("A_to_Y_delay")->setDelay(cache
->get(cell_name
+ "->Delay->A_to_Y"));
111 getDelay("B_to_Y_delay")->setDelay(cache
->get(cell_name
+ "->Delay->B_to_Y"));
112 getDriver("Y_Ron")->setOutputRes(cache
->get(cell_name
+ "->DriveRes->Y"));
115 getAreaResult("Active")->setValue(cache
->get(cell_name
+ "->ActiveArea"));
116 getAreaResult("Metal1Wire")->setValue(cache
->get(cell_name
+ "->ActiveArea"));
121 void NOR2::useModel()
124 double drive_strength
= getDrivingStrength();
125 Map
<double>* cache
= getTechModel()->getStdCellLib()->getStdCellCache();
127 // Standard cell cache string
128 String cell_name
= "NOR2_X" + (String
) drive_strength
;
130 // Propagate the transition info and get the 0->1 transtion count
131 propagateTransitionInfo();
132 double P_A
= getInputPort("A")->getTransitionInfo().getProbability1();
133 double P_B
= getInputPort("B")->getTransitionInfo().getProbability1();
134 double Y_num_trans_01
= getOutputPort("Y")->getTransitionInfo().getNumberTransitions01();
138 leakage
+= cache
->get(cell_name
+ "->Leakage->!A!B") * (1 - P_A
) * (1 - P_B
);
139 leakage
+= cache
->get(cell_name
+ "->Leakage->!AB") * (1 - P_A
) * P_B
;
140 leakage
+= cache
->get(cell_name
+ "->Leakage->A!B") * P_A
* (1 - P_B
);
141 leakage
+= cache
->get(cell_name
+ "->Leakage->AB") * P_A
* P_B
;
142 getNddPowerResult("Leakage")->setValue(leakage
);
145 double vdd
= getTechModel()->get("Vdd");
147 double y_cap
= cache
->get(cell_name
+ "->Cap->Y");
148 double y_load_cap
= getNet("Y")->getTotalDownstreamCap();
150 // Calculate NOR2Event energy
151 double energy_per_trans_01
= (y_cap
+ y_load_cap
) * vdd
* vdd
;
152 getEventResult("NOR2")->setValue(energy_per_trans_01
* Y_num_trans_01
);
157 void NOR2::propagateTransitionInfo()
159 // Get input signal transition info
160 const TransitionInfo
& trans_A
= getInputPort("A")->getTransitionInfo();
161 const TransitionInfo
& trans_B
= getInputPort("B")->getTransitionInfo();
163 double max_freq_mult
= max(trans_A
.getFrequencyMultiplier(), trans_B
.getFrequencyMultiplier());
164 const TransitionInfo
& scaled_trans_A
= trans_A
.scaleFrequencyMultiplier(max_freq_mult
);
165 const TransitionInfo
& scaled_trans_B
= trans_B
.scaleFrequencyMultiplier(max_freq_mult
);
167 double A_prob_00
= scaled_trans_A
.getNumberTransitions00() / max_freq_mult
;
168 double A_prob_01
= scaled_trans_A
.getNumberTransitions01() / max_freq_mult
;
169 double A_prob_10
= A_prob_01
;
170 double A_prob_11
= scaled_trans_A
.getNumberTransitions11() / max_freq_mult
;
171 double B_prob_00
= scaled_trans_B
.getNumberTransitions00() / max_freq_mult
;
172 double B_prob_01
= scaled_trans_B
.getNumberTransitions01() / max_freq_mult
;
173 double B_prob_10
= B_prob_01
;
174 double B_prob_11
= scaled_trans_B
.getNumberTransitions11() / max_freq_mult
;
176 // Set output transition info
177 double Y_prob_00
= A_prob_00
* B_prob_11
+
178 A_prob_01
* (B_prob_10
+ B_prob_11
) +
179 A_prob_10
* (B_prob_01
+ B_prob_11
) +
181 double Y_prob_01
= A_prob_00
* B_prob_10
+
182 A_prob_10
* (B_prob_00
+ B_prob_10
);
183 double Y_prob_11
= A_prob_00
* B_prob_00
;
185 // Check that probabilities add up to 1.0 with some finite tolerance
186 ASSERT(LibUtil::Math::isEqual((Y_prob_00
+ Y_prob_01
+ Y_prob_01
+ Y_prob_11
), 1.0),
187 "[Error] " + getInstanceName() + "Output transition probabilities must add up to 1 (" +
188 (String
) Y_prob_00
+ ", " + (String
) Y_prob_01
+ ", " + (String
) Y_prob_11
+ ")!");
190 // Turn probability of transitions per cycle into number of transitions per time unit
191 TransitionInfo
trans_Y(Y_prob_00
* max_freq_mult
, Y_prob_01
* max_freq_mult
, Y_prob_11
* max_freq_mult
);
192 getOutputPort("Y")->setTransitionInfo(trans_Y
);
196 void NOR2::cacheStdCell(StdCellLib
* cell_lib_
, double drive_strength_
)
198 // Standard cell cache string
199 String cell_name
= "NOR2_X" + (String
) drive_strength_
;
201 Log::printLine("=== " + cell_name
+ " ===");
204 double gate_pitch
= cell_lib_
->getTechModel()->get("Gate->PitchContacted");
205 Map
<double>* cache
= cell_lib_
->getStdCellCache();
207 // Now actually build the full standard cell model
208 // Create the two input ports
209 createInputPort("A");
210 createInputPort("B");
211 createOutputPort("Y");
214 CellMacros::addNor2(this, "NOR", true, true, true, "A", "B", "Y");
215 CellMacros::updateNor2(this, "NOR", drive_strength_
);
218 double area
= gate_pitch
* getTotalHeight() * (1 + getGenProperties()->get("NOR_GatePitches").toDouble());
219 cache
->set(cell_name
+ "->ActiveArea", area
);
220 Log::printLine(cell_name
+ "->ActiveArea=" + (String
) area
);
222 // --------------------------------------------------------------------
223 // Leakage Model Calculation
224 // --------------------------------------------------------------------
225 double leakage_00
= getGenProperties()->get("NOR_LeakagePower_00").toDouble();
226 double leakage_01
= getGenProperties()->get("NOR_LeakagePower_01").toDouble();
227 double leakage_10
= getGenProperties()->get("NOR_LeakagePower_10").toDouble();
228 double leakage_11
= getGenProperties()->get("NOR_LeakagePower_11").toDouble();
229 cache
->set(cell_name
+ "->Leakage->!A!B", leakage_00
);
230 cache
->set(cell_name
+ "->Leakage->!AB", leakage_01
);
231 cache
->set(cell_name
+ "->Leakage->A!B", leakage_10
);
232 cache
->set(cell_name
+ "->Leakage->AB", leakage_11
);
233 Log::printLine(cell_name
+ "->Leakage->!A!B=" + (String
) leakage_00
);
234 Log::printLine(cell_name
+ "->Leakage->!AB=" + (String
) leakage_01
);
235 Log::printLine(cell_name
+ "->Leakage->A!B=" + (String
) leakage_10
);
236 Log::printLine(cell_name
+ "->Leakage->AB=" + (String
) leakage_11
);
237 // --------------------------------------------------------------------
240 // Cache event energy results
241 double event_a_flip = getGenProperties()->get("NOR_A1_Flip").toDouble();
242 double event_b_flip = getGenProperties()->get("NOR_A2_Flip").toDouble();
243 double event_zn_flip = getGenProperties()->get("NOR_ZN_Flip").toDouble();
245 cache->set(cell_name + "->Event_A_Flip", event_a_flip);
246 cache->set(cell_name + "->Event_B_Flip", event_b_flip);
247 cache->set(cell_name + "->Event_ZN_Flip", event_zn_flip);
248 Log::printLine(cell_name + "->Event_A_Flip=" + (String) event_a_flip);
249 Log::printLine(cell_name + "->Event_B_Flip=" + (String) event_b_flip);
250 Log::printLine(cell_name + "->Event_ZN_Flip=" + (String) event_zn_flip);
253 // --------------------------------------------------------------------
254 // Get Node Capacitances
255 // --------------------------------------------------------------------
256 // Build abstracted timing model
257 double a_cap
= getNet("A")->getTotalDownstreamCap();
258 double b_cap
= getNet("B")->getTotalDownstreamCap();
259 double y_cap
= getNet("Y")->getTotalDownstreamCap();
261 cache
->set(cell_name
+ "->Cap->A", a_cap
);
262 cache
->set(cell_name
+ "->Cap->B", b_cap
);
263 cache
->set(cell_name
+ "->Cap->Y", y_cap
);
264 Log::printLine(cell_name
+ "->Cap->A_Cap=" + (String
) a_cap
);
265 Log::printLine(cell_name
+ "->Cap->B_Cap=" + (String
) b_cap
);
266 Log::printLine(cell_name
+ "->Cap->Y_Cap=" + (String
) y_cap
);
267 // --------------------------------------------------------------------
269 // --------------------------------------------------------------------
270 // Build Internal Delay Model
271 // --------------------------------------------------------------------
272 double y_ron
= getDriver("NOR_RonZN")->getOutputRes();
273 double a_to_y_delay
= getDriver("NOR_RonZN")->calculateDelay();
274 double b_to_y_delay
= getDriver("NOR_RonZN")->calculateDelay();
276 cache
->set(cell_name
+ "->DriveRes->Y", y_ron
);
277 cache
->set(cell_name
+ "->Delay->A_to_Y", a_to_y_delay
);
278 cache
->set(cell_name
+ "->Delay->B_to_Y", b_to_y_delay
);
279 Log::printLine(cell_name
+ "->DriveRes->Y=" + (String
) y_ron
);
280 Log::printLine(cell_name
+ "->Delay->A_to_Y=" + (String
) a_to_y_delay
);
281 Log::printLine(cell_name
+ "->Delay->B_to_Y=" + (String
) b_to_y_delay
);
282 // --------------------------------------------------------------------