OR2.cc revision 10447:a465576671d4
1#include "model/std_cells/OR2.h"
2
3#include <cmath>
4
5#include "model/PortInfo.h"
6#include "model/TransitionInfo.h"
7#include "model/EventInfo.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::max;
18
19    OR2::OR2(const String& instance_name_, const TechModel* tech_model_)
20        : StdCell(instance_name_, tech_model_)
21    {
22        initProperties();
23    }
24
25    OR2::~OR2()
26    {}
27
28    void OR2::initProperties()
29    {
30        return;
31    }
32
33    void OR2::constructModel()
34    {
35        createInputPort("A");
36        createInputPort("B");
37        createOutputPort("Y");
38
39        createLoad("A_Cap");
40        createLoad("B_Cap");
41        createDelay("A_to_Y_delay");
42        createDelay("B_to_Y_delay");
43        createDriver("Y_Ron", true);
44
45        ElectricalLoad* a_cap = getLoad("A_Cap");
46        ElectricalLoad* b_cap = getLoad("B_Cap");
47        ElectricalDelay* a_to_y_delay = getDelay("A_to_Y_delay");
48        ElectricalDelay* b_to_y_delay = getDelay("B_to_Y_delay");
49        ElectricalDriver* y_ron = getDriver("Y_Ron");
50
51        getNet("A")->addDownstreamNode(a_cap);
52        getNet("B")->addDownstreamNode(b_cap);
53        a_cap->addDownstreamNode(a_to_y_delay);
54        b_cap->addDownstreamNode(b_to_y_delay);
55        a_to_y_delay->addDownstreamNode(y_ron);
56        b_to_y_delay->addDownstreamNode(y_ron);
57        y_ron->addDownstreamNode(getNet("Y"));
58
59        // Create Area result
60        // Create NDD Power result
61        createElectricalAtomicResults();
62        // Create OR Event Energy Result
63        createElectricalEventAtomicResult("OR2");
64
65        getEventInfo("Idle")->setStaticTransitionInfos();
66
67        return;
68    }
69
70    void OR2::updateModel()
71    {
72        // Get parameters
73        double drive_strength = getDrivingStrength();
74        Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
75
76        // Standard cell cache string
77        const String& cell_name = "OR2_X" + (String) drive_strength;
78
79        // Get timing parameters
80        getLoad("A_Cap")->setLoadCap(cache->get(cell_name + "->Cap->A"));
81        getLoad("B_Cap")->setLoadCap(cache->get(cell_name + "->Cap->B"));
82        getDelay("A_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->A_to_Y"));
83        getDelay("B_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->B_to_Y"));
84        getDriver("Y_Ron")->setOutputRes(cache->get(cell_name + "->DriveRes->Y"));
85
86        // Set the cell area
87        getAreaResult("Active")->setValue(cache->get(cell_name + "->ActiveArea"));
88        getAreaResult("Metal1Wire")->setValue(cache->get(cell_name + "->ActiveArea"));
89
90        return;
91    }
92
93    void OR2::evaluateModel()
94    {
95        return;
96    }
97
98    void OR2::useModel()
99    {
100        // Get parameters
101        double drive_strength = getDrivingStrength();
102        Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
103
104        // Stadard cell cache string
105        const String& cell_name = "OR2_X" + (String) drive_strength;
106
107        // Propagate the transition info and get the 0->1 transtion count
108        propagateTransitionInfo();
109        double P_A = getInputPort("A")->getTransitionInfo().getProbability1();
110        double P_B = getInputPort("B")->getTransitionInfo().getProbability1();
111        double Y_num_trans_01 = getOutputPort("Y")->getTransitionInfo().getNumberTransitions01();
112
113        // Calculate leakage
114        double leakage = 0;
115        leakage += cache->get(cell_name + "->Leakage->!A!B") * (1 - P_A) * (1 - P_B);
116        leakage += cache->get(cell_name + "->Leakage->!AB") * (1 - P_A) * P_B;
117        leakage += cache->get(cell_name + "->Leakage->A!B") * P_A * (1 - P_B);
118        leakage += cache->get(cell_name + "->Leakage->AB") * P_A * P_B;
119        getNddPowerResult("Leakage")->setValue(leakage);
120
121        // Get VDD
122        double vdd = getTechModel()->get("Vdd");
123
124        // Get capacitances
125        double y_b_cap = cache->get(cell_name + "->Cap->Y_b");
126        double y_cap = cache->get(cell_name + "->Cap->Y");
127        double y_load_cap = getNet("Y")->getTotalDownstreamCap();
128
129        // Calculate OR2Event energy
130        double energy_per_trans_01 = (y_b_cap + y_cap + y_load_cap) * vdd * vdd;
131        getEventResult("OR2")->setValue(energy_per_trans_01 * Y_num_trans_01);
132
133        return;
134    }
135
136    void OR2::propagateTransitionInfo()
137    {
138        // Get input signal transition info
139        const TransitionInfo& trans_A = getInputPort("A")->getTransitionInfo();
140        const TransitionInfo& trans_B = getInputPort("B")->getTransitionInfo();
141
142        double max_freq_mult = max(trans_A.getFrequencyMultiplier(), trans_B.getFrequencyMultiplier());
143        const TransitionInfo& scaled_trans_A = trans_A.scaleFrequencyMultiplier(max_freq_mult);
144        const TransitionInfo& scaled_trans_B = trans_B.scaleFrequencyMultiplier(max_freq_mult);
145
146        double A_prob_00 = scaled_trans_A.getNumberTransitions00() / max_freq_mult;
147        double A_prob_01 = scaled_trans_A.getNumberTransitions01() / max_freq_mult;
148        double A_prob_10 = A_prob_01;
149        double A_prob_11 = scaled_trans_A.getNumberTransitions11() / max_freq_mult;
150        double B_prob_00 = scaled_trans_B.getNumberTransitions00() / max_freq_mult;
151        double B_prob_01 = scaled_trans_B.getNumberTransitions01() / max_freq_mult;
152        double B_prob_10 = B_prob_01;
153        double B_prob_11 = scaled_trans_B.getNumberTransitions11() / max_freq_mult;
154
155        // Set output transition info
156        double Y_prob_00 = A_prob_00 * B_prob_00;
157        double Y_prob_01 = A_prob_00 * B_prob_01 +
158                        A_prob_01 * (B_prob_00 + B_prob_01);
159        double Y_prob_11 = A_prob_00 * B_prob_11 +
160                        A_prob_01 * (B_prob_10 + B_prob_11) +
161                        A_prob_10 * (B_prob_01 + B_prob_11) +
162                        A_prob_11;
163
164        // Check that probabilities add up to 1.0 with some finite tolerance
165        ASSERT(LibUtil::Math::isEqual((Y_prob_00 + Y_prob_01 + Y_prob_01 + Y_prob_11), 1.0), "[Error] " + getInstanceName() +
166            "Output transition probabilities must add up to 1 (" + (String) Y_prob_00 + ", " +
167            (String) Y_prob_01 + ", " + (String) Y_prob_11 + ")!");
168
169        // Turn probability of transitions per cycle into number of transitions per time unit
170        TransitionInfo trans_Y(Y_prob_00 * max_freq_mult, Y_prob_01 * max_freq_mult, Y_prob_11 * max_freq_mult);
171        getOutputPort("Y")->setTransitionInfo(trans_Y);
172        return;
173    }
174
175    // Creates the standard cell, characterizes and abstracts away the details
176    void OR2::cacheStdCell(StdCellLib* cell_lib_, double drive_strength_)
177    {
178        // Get parameters
179        double gate_pitch = cell_lib_->getTechModel()->get("Gate->PitchContacted");
180        Map<double>* cache = cell_lib_->getStdCellCache();
181
182        // Stadard cell cache string
183        const String& cell_name = "OR2_X" + (String) drive_strength_;
184
185        Log::printLine("=== " + cell_name + " ===");
186
187        // Now actually build the full standard cell model
188        createInputPort("A");
189        createInputPort("B");
190        createOutputPort("Y");
191
192        createNet("Y_b");
193
194        // Adds macros
195        CellMacros::addNor2(this, "NOR2", false, true, true, "A", "B", "Y_b");
196        CellMacros::addInverter(this, "INV", false, true, "Y_b", "Y");
197
198        // Update macros
199        CellMacros::updateNor2(this, "NOR2", drive_strength_ * 0.66);
200        CellMacros::updateInverter(this, "INV", drive_strength_ * 1.0);
201
202        // Cache area result
203        double area = 0.0;
204        area += gate_pitch * getTotalHeight() * 1;
205        area += gate_pitch * getTotalHeight() * getGenProperties()->get("NOR2_GatePitches").toDouble();
206        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV_GatePitches").toDouble();
207        cache->set(cell_name + "->ActiveArea", area);
208        Log::printLine(cell_name + "->ActiveArea=" + (String)area);
209
210        // --------------------------------------------------------------------
211        // Leakage Model Calculation
212        // --------------------------------------------------------------------
213        // Cache leakage power results (for every single signal combination)
214        double leakage_00 = 0.0; // !A, !B
215        double leakage_01 = 0.0; // !A, B
216        double leakage_10 = 0.0; // A, !B
217        double leakage_11 = 0.0; // A, B
218
219        leakage_00 += getGenProperties()->get("NOR2_LeakagePower_00").toDouble();
220        leakage_00 += getGenProperties()->get("INV_LeakagePower_1").toDouble();
221
222        leakage_01 += getGenProperties()->get("NOR2_LeakagePower_01").toDouble();
223        leakage_01 += getGenProperties()->get("INV_LeakagePower_0").toDouble();
224
225        leakage_10 += getGenProperties()->get("NOR2_LeakagePower_10").toDouble();
226        leakage_10 += getGenProperties()->get("INV_LeakagePower_0").toDouble();
227
228        leakage_11 += getGenProperties()->get("NOR2_LeakagePower_11").toDouble();
229        leakage_11 += getGenProperties()->get("INV_LeakagePower_0").toDouble();
230
231        cache->set(cell_name + "->Leakage->!A!B", leakage_00);
232        cache->set(cell_name + "->Leakage->!AB", leakage_01);
233        cache->set(cell_name + "->Leakage->A!B", leakage_10);
234        cache->set(cell_name + "->Leakage->AB", leakage_11);
235        Log::printLine(cell_name + "->Leakage->!A!B=" + (String) leakage_00);
236        Log::printLine(cell_name + "->Leakage->!AB=" + (String) leakage_01);
237        Log::printLine(cell_name + "->Leakage->A!B=" + (String) leakage_10);
238        Log::printLine(cell_name + "->Leakage->AB=" + (String) leakage_11);
239        // --------------------------------------------------------------------
240
241        // --------------------------------------------------------------------
242        // Get Node Capacitances
243        // --------------------------------------------------------------------
244        double a_cap = getNet("A")->getTotalDownstreamCap();
245        double b_cap = getNet("B")->getTotalDownstreamCap();
246        double y_b_cap = getNet("Y_b")->getTotalDownstreamCap();
247        double y_cap = getNet("Y")->getTotalDownstreamCap();
248
249        cache->set(cell_name + "->Cap->A", a_cap);
250        cache->set(cell_name + "->Cap->B", b_cap);
251        cache->set(cell_name + "->Cap->Y_b", y_b_cap);
252        cache->set(cell_name + "->Cap->Y", y_cap);
253        Log::printLine(cell_name + "->Cap->A_Cap=" + (String) a_cap);
254        Log::printLine(cell_name + "->Cap->B_Cap=" + (String) b_cap);
255        Log::printLine(cell_name + "->Cap->Y_b_Cap=" + (String) y_b_cap);
256        Log::printLine(cell_name + "->Cap->Y_Cap=" + (String) y_cap);
257        // --------------------------------------------------------------------
258
259        // --------------------------------------------------------------------
260        // Build Internal Delay Model
261        // --------------------------------------------------------------------
262        double y_ron = getDriver("INV_RonZN")->getOutputRes();
263        double a_to_y_delay = getDriver("NOR2_RonZN")->calculateDelay() +
264                              getDriver("INV_RonZN")->calculateDelay();
265        double b_to_y_delay = getDriver("NOR2_RonZN")->calculateDelay() +
266                              getDriver("INV_RonZN")->calculateDelay();
267
268        cache->set(cell_name + "->DriveRes->Y", y_ron);
269        cache->set(cell_name + "->Delay->A_to_Y", a_to_y_delay);
270        cache->set(cell_name + "->Delay->B_to_Y", b_to_y_delay);
271        Log::printLine(cell_name + "->DriveRes->Y=" + (String) y_ron);
272        Log::printLine(cell_name + "->Delay->A_to_Y=" + (String) a_to_y_delay);
273        Log::printLine(cell_name + "->Delay->B_to_Y=" + (String) b_to_y_delay);
274        // --------------------------------------------------------------------
275
276        return;
277    }
278} // namespace DSENT
279
280