NOR2.cc revision 10447:a465576671d4
1#include "model/std_cells/NOR2.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::ceil;
18    using std::max;
19
20    NOR2::NOR2(const String& instance_name_, const TechModel* tech_model_)
21        : StdCell(instance_name_, tech_model_)
22    {
23        initProperties();
24    }
25
26    NOR2::~NOR2()
27    {}
28
29    void NOR2::initProperties()
30    {
31        return;
32    }
33
34    void NOR2::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("A_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 NOR Event Energy Result
67        createElectricalEventAtomicResult("NOR2");
68
69        getEventInfo("Idle")->setStaticTransitionInfos();
70
71        return;
72    }
73
74    void NOR2::updateModel()
75    {
76        // All updateModel should do is calculate numbers for the Area/NDDPower/Energy
77        // Results as anything else that needs to be done using either soft or hard parameters
78
79        // Get parameters
80        double drive_strength = getDrivingStrength();
81        Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
82
83        // Standard cell cache string
84        String cell_name = "NOR2_X" + (String) drive_strength;
85
86        // Get timing parameters
87        getLoad("A_Cap")->setLoadCap(cache->get(cell_name + "->Cap->A"));
88        getLoad("B_Cap")->setLoadCap(cache->get(cell_name + "->Cap->B"));
89        getDelay("A_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->A_to_Y"));
90        getDelay("B_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->B_to_Y"));
91        getDriver("Y_Ron")->setOutputRes(cache->get(cell_name + "->DriveRes->Y"));
92
93        // Set the cell area
94        getAreaResult("Active")->setValue(cache->get(cell_name + "->ActiveArea"));
95        getAreaResult("Metal1Wire")->setValue(cache->get(cell_name + "->ActiveArea"));
96
97        return;
98    }
99
100    void NOR2::useModel()
101    {
102        // Get parameters
103        double drive_strength = getDrivingStrength();
104        Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
105
106        // Standard cell cache string
107        String cell_name = "NOR2_X" + (String) drive_strength;
108
109        // Propagate the transition info and get the 0->1 transtion count
110        propagateTransitionInfo();
111        double P_A = getInputPort("A")->getTransitionInfo().getProbability1();
112        double P_B = getInputPort("B")->getTransitionInfo().getProbability1();
113        double Y_num_trans_01 = getOutputPort("Y")->getTransitionInfo().getNumberTransitions01();
114
115        // Calculate leakage
116        double leakage = 0;
117        leakage += cache->get(cell_name + "->Leakage->!A!B") * (1 - P_A) * (1 - P_B);
118        leakage += cache->get(cell_name + "->Leakage->!AB") * (1 - P_A) * P_B;
119        leakage += cache->get(cell_name + "->Leakage->A!B") * P_A * (1 - P_B);
120        leakage += cache->get(cell_name + "->Leakage->AB") * P_A * P_B;
121        getNddPowerResult("Leakage")->setValue(leakage);
122
123        // Get VDD
124        double vdd = getTechModel()->get("Vdd");
125        // Get capacitances
126        double y_cap = cache->get(cell_name + "->Cap->Y");
127        double y_load_cap = getNet("Y")->getTotalDownstreamCap();
128
129        // Calculate NOR2Event energy
130        double energy_per_trans_01 = (y_cap + y_load_cap) * vdd * vdd;
131        getEventResult("NOR2")->setValue(energy_per_trans_01 * Y_num_trans_01);
132
133        return;
134    }
135
136    void NOR2::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_11 +
157                        A_prob_01 * (B_prob_10 + B_prob_11) +
158                        A_prob_10 * (B_prob_01 + B_prob_11) +
159                        A_prob_11;
160        double Y_prob_01 = A_prob_00 * B_prob_10 +
161                        A_prob_10 * (B_prob_00 + B_prob_10);
162        double Y_prob_11 = A_prob_00 * B_prob_00;
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),
166            "[Error] " + getInstanceName() +  "Output transition probabilities must add up to 1 (" +
167            (String) Y_prob_00 + ", " + (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    void NOR2::cacheStdCell(StdCellLib* cell_lib_, double drive_strength_)
176    {
177        // Standard cell cache string
178        String cell_name = "NOR2_X" + (String) drive_strength_;
179
180        Log::printLine("=== " + cell_name + " ===");
181
182        // Get parameters
183        double gate_pitch = cell_lib_->getTechModel()->get("Gate->PitchContacted");
184        Map<double>* cache = cell_lib_->getStdCellCache();
185
186        // Now actually build the full standard cell model
187        // Create the two input ports
188        createInputPort("A");
189        createInputPort("B");
190        createOutputPort("Y");
191
192        // Adds macros
193        CellMacros::addNor2(this, "NOR", true, true, true, "A", "B", "Y");
194        CellMacros::updateNor2(this, "NOR", drive_strength_);
195
196        // Cache area result
197        double area = gate_pitch * getTotalHeight() * (1 + getGenProperties()->get("NOR_GatePitches").toDouble());
198        cache->set(cell_name + "->ActiveArea", area);
199        Log::printLine(cell_name + "->ActiveArea=" + (String) area);
200
201        // --------------------------------------------------------------------
202        // Leakage Model Calculation
203        // --------------------------------------------------------------------
204        double leakage_00 = getGenProperties()->get("NOR_LeakagePower_00").toDouble();
205        double leakage_01 = getGenProperties()->get("NOR_LeakagePower_01").toDouble();
206        double leakage_10 = getGenProperties()->get("NOR_LeakagePower_10").toDouble();
207        double leakage_11 = getGenProperties()->get("NOR_LeakagePower_11").toDouble();
208        cache->set(cell_name + "->Leakage->!A!B", leakage_00);
209        cache->set(cell_name + "->Leakage->!AB", leakage_01);
210        cache->set(cell_name + "->Leakage->A!B", leakage_10);
211        cache->set(cell_name + "->Leakage->AB", leakage_11);
212        Log::printLine(cell_name + "->Leakage->!A!B=" + (String) leakage_00);
213        Log::printLine(cell_name + "->Leakage->!AB=" + (String) leakage_01);
214        Log::printLine(cell_name + "->Leakage->A!B=" + (String) leakage_10);
215        Log::printLine(cell_name + "->Leakage->AB=" + (String) leakage_11);
216        // --------------------------------------------------------------------
217
218        /*
219        // Cache event energy results
220        double event_a_flip = getGenProperties()->get("NOR_A1_Flip").toDouble();
221        double event_b_flip = getGenProperties()->get("NOR_A2_Flip").toDouble();
222        double event_zn_flip = getGenProperties()->get("NOR_ZN_Flip").toDouble();
223
224        cache->set(cell_name + "->Event_A_Flip", event_a_flip);
225        cache->set(cell_name + "->Event_B_Flip", event_b_flip);
226        cache->set(cell_name + "->Event_ZN_Flip", event_zn_flip);
227        Log::printLine(cell_name + "->Event_A_Flip=" + (String) event_a_flip);
228        Log::printLine(cell_name + "->Event_B_Flip=" + (String) event_b_flip);
229        Log::printLine(cell_name + "->Event_ZN_Flip=" + (String) event_zn_flip);
230        */
231
232        // --------------------------------------------------------------------
233        // Get Node Capacitances
234        // --------------------------------------------------------------------
235        // Build abstracted timing model
236        double a_cap = getNet("A")->getTotalDownstreamCap();
237        double b_cap = getNet("B")->getTotalDownstreamCap();
238        double y_cap = getNet("Y")->getTotalDownstreamCap();
239
240        cache->set(cell_name + "->Cap->A", a_cap);
241        cache->set(cell_name + "->Cap->B", b_cap);
242        cache->set(cell_name + "->Cap->Y", y_cap);
243        Log::printLine(cell_name + "->Cap->A_Cap=" + (String) a_cap);
244        Log::printLine(cell_name + "->Cap->B_Cap=" + (String) b_cap);
245        Log::printLine(cell_name + "->Cap->Y_Cap=" + (String) y_cap);
246        // --------------------------------------------------------------------
247
248        // --------------------------------------------------------------------
249        // Build Internal Delay Model
250        // --------------------------------------------------------------------
251        double y_ron = getDriver("NOR_RonZN")->getOutputRes();
252        double a_to_y_delay = getDriver("NOR_RonZN")->calculateDelay();
253        double b_to_y_delay = getDriver("NOR_RonZN")->calculateDelay();
254
255        cache->set(cell_name + "->DriveRes->Y", y_ron);
256        cache->set(cell_name + "->Delay->A_to_Y", a_to_y_delay);
257        cache->set(cell_name + "->Delay->B_to_Y", b_to_y_delay);
258        Log::printLine(cell_name + "->DriveRes->Y=" + (String) y_ron);
259        Log::printLine(cell_name + "->Delay->A_to_Y=" + (String) a_to_y_delay);
260        Log::printLine(cell_name + "->Delay->B_to_Y=" + (String) b_to_y_delay);
261        // --------------------------------------------------------------------
262
263        return;
264
265    }
266
267} // namespace DSENT
268
269