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
22#include "model/std_cells/DFFQ.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    using std::min;
41
42    DFFQ::DFFQ(const String& instance_name_, const TechModel* tech_model_)
43        : StdCell(instance_name_, tech_model_)
44    {
45        initProperties();
46    }
47
48    DFFQ::~DFFQ()
49    {}
50
51    void DFFQ::initProperties()
52    {
53        return;
54    }
55
56    void DFFQ::constructModel()
57    {
58        // All constructModel should do is create Area/NDDPower/Energy Results as
59        // well as instantiate any sub-instances using only the hard parameters
60
61        createInputPort("D");
62        createInputPort("CK");
63        createOutputPort("Q");
64
65        createLoad("D_Cap");
66        createLoad("CK_Cap");
67        createDelay("D_Setup_delay");
68        createDelay("CK_to_Q_delay");
69        createDriver("Q_Ron", true);
70
71        ElectricalLoad* d_cap = getLoad("D_Cap");
72        ElectricalLoad* ck_cap = getLoad("CK_Cap");
73        ElectricalDelay* d_setup_delay = getDelay("D_Setup_delay");
74        ElectricalDelay* ck_to_q_delay = getDelay("CK_to_Q_delay");
75        ElectricalDriver* q_ron = getDriver("Q_Ron");
76
77        getNet("D")->addDownstreamNode(d_cap);
78        getNet("CK")->addDownstreamNode(ck_cap);
79        d_cap->addDownstreamNode(d_setup_delay);
80        ck_cap->addDownstreamNode(ck_to_q_delay);
81        ck_to_q_delay->addDownstreamNode(q_ron);
82        q_ron->addDownstreamNode(getNet("Q"));
83
84        // Create Area result
85        // Create NDD Power result
86        createElectricalAtomicResults();
87        // Create CK Event Energy Result
88        createElectricalEventAtomicResult("CK");
89        getEventInfo("CK")->setTransitionInfo("CK", TransitionInfo(0.0, 1.0, 0.0));
90        // Create DFF Event Energy Result
91        createElectricalEventAtomicResult("DFFD");
92        getEventInfo("DFFD")->setTransitionInfo("CK", TransitionInfo(0.0, 1.0, 0.0));
93        createElectricalEventAtomicResult("DFFQ");
94        getEventInfo("DFFQ")->setTransitionInfo("CK", TransitionInfo(0.0, 1.0, 0.0));
95
96        // Update Idle event for leakage
97        // CK pin is assumed to be on all the time
98        EventInfo* idle_event_info = getEventInfo("Idle");
99        idle_event_info->setTransitionInfo("CK", TransitionInfo(0.0, 1.0, 0.0));
100        idle_event_info->setTransitionInfo("D", TransitionInfo(0.5, 0.0, 0.5));
101
102        return;
103    }
104
105    void DFFQ::updateModel()
106    {
107        // Get parameters
108        double drive_strength = getDrivingStrength();
109        Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
110
111        // Standard cell cache string
112        String cell_name = "DFFQ_X" + (String) drive_strength;
113
114        // Get timing parameters
115        getLoad("D_Cap")->setLoadCap(cache->get(cell_name + "->Cap->D"));
116        getLoad("CK_Cap")->setLoadCap(cache->get(cell_name + "->Cap->CK"));
117        getDriver("Q_Ron")->setOutputRes(cache->get(cell_name + "->DriveRes->Q"));
118        getDelay("CK_to_Q_delay")->setDelay(cache->get(cell_name + "->Delay->CK_to_Q"));
119        getDelay("D_Setup_delay")->setDelay(cache->get(cell_name + "->Delay->D_Setup"));
120
121        // Set the cell area
122        getAreaResult("Active")->setValue(cache->get(cell_name + "->Area->Active"));
123        getAreaResult("Metal1Wire")->setValue(cache->get(cell_name + "->Area->Metal1Wire"));
124
125        return;
126    }
127
128    void DFFQ::evaluateModel()
129    {
130        return;
131    }
132
133    void DFFQ::useModel()
134    {
135        // Get parameters
136        double drive_strength = getDrivingStrength();
137        Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache();
138
139        // Standard cell cache string
140        String cell_name = "DFFQ_X" + (String) drive_strength;
141
142        // Propagate the transition info and get P_D, P_M, and P_Q
143        propagateTransitionInfo();
144        double P_D = getInputPort("D")->getTransitionInfo().getProbability1();
145        double P_CK = getInputPort("CK")->getTransitionInfo().getProbability1();
146        double P_Q = getOutputPort("Q")->getTransitionInfo().getProbability1();
147        double CK_num_trans_01 = getInputPort("CK")->getTransitionInfo().getNumberTransitions01();
148        double D_num_trans_01 = getInputPort("D")->getTransitionInfo().getNumberTransitions01();
149        double M_num_trans_01 = m_trans_M_.getNumberTransitions01();
150        double Q_num_trans_01 = getOutputPort("Q")->getTransitionInfo().getNumberTransitions01();
151
152        // Calculate leakage
153        double leakage = 0;
154        leakage += cache->get(cell_name + "->Leakage->!D!CK!Q") * (1 - P_D) * (1 - P_CK) * (1 - P_Q);
155        leakage += cache->get(cell_name + "->Leakage->!D!CKQ") * (1 - P_D) * (1 - P_CK) * P_Q;
156        leakage += cache->get(cell_name + "->Leakage->!DCK!Q") * (1 - P_D) * P_CK * (1 - P_Q);
157        leakage += cache->get(cell_name + "->Leakage->!DCKQ") * (1 - P_D) * P_CK * P_Q;
158        leakage += cache->get(cell_name + "->Leakage->D!CK!Q") * P_D * (1 - P_CK) * (1 - P_Q);
159        leakage += cache->get(cell_name + "->Leakage->D!CKQ") * P_D * (1 - P_CK) * P_Q;
160        leakage += cache->get(cell_name + "->Leakage->DCK!Q") * P_D * P_CK * (1 - P_Q);
161        leakage += cache->get(cell_name + "->Leakage->DCKQ") * P_D * P_CK * P_Q;
162        getNddPowerResult("Leakage")->setValue(leakage);
163
164        // Get VDD
165        double vdd = getTechModel()->get("Vdd");
166
167        // Get capacitances
168        double ck_b_cap = cache->get(cell_name + "->Cap->CK_b");
169        double ck_i_cap = cache->get(cell_name + "->Cap->CK_i");
170        double d_b_cap = cache->get(cell_name + "->Cap->D_b");
171        double m_b_cap = cache->get(cell_name + "->Cap->M_b");
172        double m_cap = cache->get(cell_name + "->Cap->M");
173        double m_i_cap = cache->get(cell_name + "->Cap->M_i");
174        double q_b_cap = cache->get(cell_name + "->Cap->Q_b");
175        double q_cap = cache->get(cell_name + "->Cap->Q");
176        double q_load_cap = getNet("Q")->getTotalDownstreamCap();
177
178        // Calculate CK Event energy
179        double ck_event_energy = 0.0;
180        ck_event_energy += (ck_b_cap + ck_i_cap) * CK_num_trans_01;
181        ck_event_energy *= vdd * vdd;
182        getEventResult("CK")->setValue(ck_event_energy);
183        // Calculate DFFD Event energy
184        double dffd_event_energy = 0.0;
185        dffd_event_energy += (d_b_cap) * D_num_trans_01;
186        dffd_event_energy += (m_b_cap + m_cap) * M_num_trans_01;
187        dffd_event_energy *= vdd * vdd;
188        getEventResult("DFFD")->setValue(dffd_event_energy);
189        // Calculate DFFQ Event energy
190        double dffq_event_energy = 0.0;
191        dffq_event_energy += (m_i_cap + q_b_cap + q_cap + q_load_cap) * Q_num_trans_01;
192        dffq_event_energy *= vdd * vdd;
193        getEventResult("DFFQ")->setValue(dffq_event_energy);
194
195        return;
196    }
197
198    void DFFQ::propagateTransitionInfo()
199    {
200        const TransitionInfo& trans_CK = getInputPort("CK")->getTransitionInfo();
201        const TransitionInfo& trans_D = getInputPort("D")->getTransitionInfo();
202
203        double CK_num_trans_01 = trans_CK.getNumberTransitions01();
204        double CK_num_trans_10 = CK_num_trans_01;
205        double CK_num_trans_00 = trans_CK.getNumberTransitions00();
206        double D_freq_mult = trans_D.getFrequencyMultiplier();
207
208        // If thre is no activity on the clock or D, assume M node is randomly distributed among 0 and 1
209        if(LibUtil::Math::isEqual(CK_num_trans_10 + CK_num_trans_00, 0.0) || LibUtil::Math::isEqual(D_freq_mult, 0.0))
210        {
211            m_trans_M_ = TransitionInfo(0.5, 0.0, 0.5);
212        }
213        // If the master latch is sampling just as fast or faster than input data signal
214        // Then it can capture all transitions (though it should be normalized to clock)
215        else if((CK_num_trans_10 + CK_num_trans_00) >= D_freq_mult)
216        {
217            m_trans_M_ = trans_D.scaleFrequencyMultiplier(CK_num_trans_10 + CK_num_trans_00);
218        }
219        // If the master latch is sampling slower than the input data signal, then input
220        // will look like they transition more
221        else
222        {
223            // Calculate scale ratio
224            double scale_ratio = (CK_num_trans_10 + CK_num_trans_00) / D_freq_mult;
225            // 00 and 11 transitions become fewer
226            double D_scaled_diff = 0.5 * (1 - scale_ratio) * (trans_D.getNumberTransitions00() + trans_D.getNumberTransitions11());
227            double D_scaled_num_trans_00 = trans_D.getNumberTransitions00() * scale_ratio;
228            double D_scaled_num_trans_11 = trans_D.getNumberTransitions11() * scale_ratio;
229            // 01 and 10 transitions become more frequent
230            double D_scaled_num_trans_10 = trans_D.getNumberTransitions01() + D_scaled_diff;
231
232            // Create final transition info, remembering to apply scaling ratio to normalize to CK
233            m_trans_M_ = TransitionInfo(D_scaled_num_trans_00 * scale_ratio,
234                                        D_scaled_num_trans_10 * scale_ratio,
235                                        D_scaled_num_trans_11 * scale_ratio);
236        }
237
238        // If the clock activity is 0 or if D activity is 0, then we assume that the output is randomly distributed among 0 and 1
239        if(LibUtil::Math::isEqual(CK_num_trans_01, 0.0) || LibUtil::Math::isEqual(D_freq_mult, 0.0))
240        {
241            getOutputPort("Q")->setTransitionInfo(TransitionInfo(0.5, 0.0, 0.5));
242        }
243        // If the DFF's CK is running at a higher frequency than D, Q is just D with a
244        // scaled up frequency multiplier
245        else if(CK_num_trans_01 >= D_freq_mult)
246        {
247            const TransitionInfo& trans_Q = trans_D.scaleFrequencyMultiplier(CK_num_trans_01);
248            getOutputPort("Q")->setTransitionInfo(trans_Q);
249        }
250        // If the DFF is sampling slower than the input data signal, then inputs
251        // will look like they transition more
252        else
253        {
254            // Calculate scale ratio
255            double scale_ratio = CK_num_trans_01 / D_freq_mult;
256            // 00 and 11 transitions become fewer
257            double D_scaled_diff = 0.5 * (1 - scale_ratio) * (trans_D.getNumberTransitions00() + trans_D.getNumberTransitions11());
258            double D_scaled_num_trans_00 = trans_D.getNumberTransitions00() * scale_ratio;
259            double D_scaled_num_trans_11 = trans_D.getNumberTransitions11() * scale_ratio;
260            // 01 and 10 transitions become more frequent
261            double D_scaled_num_trans_10 = trans_D.getNumberTransitions01() + D_scaled_diff;
262            const TransitionInfo trans_Q(   D_scaled_num_trans_00 * scale_ratio,
263                    D_scaled_num_trans_10 * scale_ratio,
264                    D_scaled_num_trans_11 * scale_ratio);
265            getOutputPort("Q")->setTransitionInfo(trans_Q);
266        }
267        return;
268    }
269
270    // Creates the standard cell, characterizes and abstracts away the details
271    void DFFQ::cacheStdCell(StdCellLib* cell_lib_, double drive_strength_)
272    {
273        // Get parameters
274        double gate_pitch = cell_lib_->getTechModel()->get("Gate->PitchContacted");
275        Map<double>* cache = cell_lib_->getStdCellCache();
276
277        // Standard cell cache string
278        String cell_name = "DFFQ_X" + (String) drive_strength_;
279
280        Log::printLine("=== " + cell_name + " ===");
281
282
283        // Now actually build the full standard cell model
284        createInputPort("D");
285        createInputPort("CK");
286        createOutputPort("Q");
287
288        createNet("D_b");
289        createNet("M_b");
290        createNet("M");
291        createNet("M_i");
292        createNet("Q_b");
293        createNet("CK_b");
294        createNet("CK_i");
295
296        // Adds macros
297        CellMacros::addInverter(this, "INV1", false, true, "D", "D_b");
298        CellMacros::addInverter(this, "INV2", false, true, "M_b", "M");
299        CellMacros::addInverter(this, "INV3", false, true, "M_i", "Q_b");
300        CellMacros::addInverter(this, "INV4", true, true, "Q_b", "Q");
301        CellMacros::addInverter(this, "INV5", false, true, "CK", "CK_b");
302        CellMacros::addInverter(this, "INV6", false, true, "CK_b", "CK_i");
303        CellMacros::addTristate(this, "INVZ1", false, true, false, false, "D_b", "CK_b", "CK_i", "M_b");        //trace timing through A->ZN path only
304        CellMacros::addTristate(this, "INVZ2", false, false, false, false, "M", "CK_i", "CK_b", "M_b");         //don't trace timing through the feedback path
305        CellMacros::addTristate(this, "INVZ3", false, false, true, true, "M", "CK_i", "CK_b", "M_i");           //trace timing from OE->ZN and OEN->ZN paths only
306        CellMacros::addTristate(this, "INVZ4", false, false, false, false, "Q_b", "CK_b", "CK_i", "M_i");       //don't trace timing through the feedback path
307
308        // Update macros
309        CellMacros::updateInverter(this, "INV1", drive_strength_ * 0.125);
310        CellMacros::updateInverter(this, "INV2", drive_strength_ * 0.5);
311        CellMacros::updateInverter(this, "INV3", drive_strength_ * 0.5);
312        CellMacros::updateInverter(this, "INV4", drive_strength_ * 1.0);
313        CellMacros::updateInverter(this, "INV5", drive_strength_ * 0.125);
314        CellMacros::updateInverter(this, "INV6", drive_strength_ * 0.125);
315        CellMacros::updateTristate(this, "INVZ1", drive_strength_ * 0.5);
316        CellMacros::updateTristate(this, "INVZ2", drive_strength_ * 0.0625);
317        CellMacros::updateTristate(this, "INVZ3", drive_strength_ * 0.5);
318        CellMacros::updateTristate(this, "INVZ4", drive_strength_ * 0.0625);
319
320        // Cache area result
321        double area = 0.0;
322        area += gate_pitch * getTotalHeight() * 1;
323        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV1_GatePitches").toDouble();
324        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV2_GatePitches").toDouble();
325        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV3_GatePitches").toDouble();
326        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV4_GatePitches").toDouble();
327        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV5_GatePitches").toDouble();
328        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV6_GatePitches").toDouble();
329        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ1_GatePitches").toDouble();
330        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ2_GatePitches").toDouble();
331        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ3_GatePitches").toDouble();
332        area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ4_GatePitches").toDouble();
333        cache->set(cell_name + "->Area->Active", area);
334        cache->set(cell_name + "->Area->Metal1Wire", area);
335        Log::printLine(cell_name + "->Area->Active=" + (String) area);
336        Log::printLine(cell_name + "->Area->Metal1Wire=" + (String) area);
337
338        // --------------------------------------------------------------------
339        // Leakage Model Calculation
340        // --------------------------------------------------------------------
341        // Cache leakage power results (for every single signal combination)
342        double leakage_000 = 0;         //!D, !CK, !Q
343        double leakage_001 = 0;         //!D, !CK, Q
344        double leakage_010 = 0;         //!D, CK, !Q
345        double leakage_011 = 0;         //!D, CK, Q
346        double leakage_100 = 0;         //D, !CK, !Q
347        double leakage_101 = 0;         //D, !CK, Q
348        double leakage_110 = 0;         //D, CK, !Q
349        double leakage_111 = 0;         //D, CK, Q
350
351        //This is so painful...
352        leakage_000 += getGenProperties()->get("INV1_LeakagePower_0").toDouble();
353        leakage_000 += getGenProperties()->get("INV2_LeakagePower_0").toDouble();
354        leakage_000 += getGenProperties()->get("INV3_LeakagePower_0").toDouble();
355        leakage_000 += getGenProperties()->get("INV4_LeakagePower_1").toDouble();
356        leakage_000 += getGenProperties()->get("INV5_LeakagePower_0").toDouble();
357        leakage_000 += getGenProperties()->get("INV6_LeakagePower_1").toDouble();
358        leakage_000 += getGenProperties()->get("INVZ1_LeakagePower_101_0").toDouble();
359        leakage_000 += getGenProperties()->get("INVZ2_LeakagePower_011_0").toDouble();
360        leakage_000 += getGenProperties()->get("INVZ3_LeakagePower_011_0").toDouble();
361        leakage_000 += getGenProperties()->get("INVZ4_LeakagePower_101_0").toDouble();
362
363        leakage_001 += getGenProperties()->get("INV1_LeakagePower_0").toDouble();
364        leakage_001 += getGenProperties()->get("INV2_LeakagePower_0").toDouble();
365        leakage_001 += getGenProperties()->get("INV3_LeakagePower_1").toDouble();
366        leakage_001 += getGenProperties()->get("INV4_LeakagePower_0").toDouble();
367        leakage_001 += getGenProperties()->get("INV5_LeakagePower_0").toDouble();
368        leakage_001 += getGenProperties()->get("INV6_LeakagePower_1").toDouble();
369        leakage_001 += getGenProperties()->get("INVZ1_LeakagePower_101_0").toDouble();
370        leakage_001 += getGenProperties()->get("INVZ2_LeakagePower_011_0").toDouble();
371        leakage_001 += getGenProperties()->get("INVZ3_LeakagePower_011_1").toDouble();
372        leakage_001 += getGenProperties()->get("INVZ4_LeakagePower_100_1").toDouble();
373
374        leakage_010 += getGenProperties()->get("INV1_LeakagePower_0").toDouble();
375        leakage_010 += getGenProperties()->get("INV2_LeakagePower_0").toDouble();
376        leakage_010 += getGenProperties()->get("INV3_LeakagePower_0").toDouble();
377        leakage_010 += getGenProperties()->get("INV4_LeakagePower_1").toDouble();
378        leakage_010 += getGenProperties()->get("INV5_LeakagePower_1").toDouble();
379        leakage_010 += getGenProperties()->get("INV6_LeakagePower_0").toDouble();
380        leakage_010 += getGenProperties()->get("INVZ1_LeakagePower_011_0").toDouble();
381        leakage_010 += getGenProperties()->get("INVZ2_LeakagePower_101_0").toDouble();
382        leakage_010 += getGenProperties()->get("INVZ3_LeakagePower_101_0").toDouble();
383        leakage_010 += getGenProperties()->get("INVZ4_LeakagePower_011_0").toDouble();
384
385        leakage_011 += getGenProperties()->get("INV1_LeakagePower_0").toDouble();
386        leakage_011 += getGenProperties()->get("INV2_LeakagePower_1").toDouble();
387        leakage_011 += getGenProperties()->get("INV3_LeakagePower_1").toDouble();
388        leakage_011 += getGenProperties()->get("INV4_LeakagePower_0").toDouble();
389        leakage_011 += getGenProperties()->get("INV5_LeakagePower_1").toDouble();
390        leakage_011 += getGenProperties()->get("INV6_LeakagePower_0").toDouble();
391        leakage_011 += getGenProperties()->get("INVZ1_LeakagePower_011_1").toDouble();
392        leakage_011 += getGenProperties()->get("INVZ2_LeakagePower_100_1").toDouble();
393        leakage_011 += getGenProperties()->get("INVZ3_LeakagePower_100_1").toDouble();
394        leakage_011 += getGenProperties()->get("INVZ4_LeakagePower_010_1").toDouble();
395
396        leakage_100 += getGenProperties()->get("INV1_LeakagePower_1").toDouble();
397        leakage_100 += getGenProperties()->get("INV2_LeakagePower_1").toDouble();
398        leakage_100 += getGenProperties()->get("INV3_LeakagePower_0").toDouble();
399        leakage_100 += getGenProperties()->get("INV4_LeakagePower_1").toDouble();
400        leakage_100 += getGenProperties()->get("INV5_LeakagePower_0").toDouble();
401        leakage_100 += getGenProperties()->get("INV6_LeakagePower_1").toDouble();
402        leakage_100 += getGenProperties()->get("INVZ1_LeakagePower_100_1").toDouble();
403        leakage_100 += getGenProperties()->get("INVZ2_LeakagePower_010_1").toDouble();
404        leakage_100 += getGenProperties()->get("INVZ3_LeakagePower_010_0").toDouble();
405        leakage_100 += getGenProperties()->get("INVZ4_LeakagePower_101_0").toDouble();
406
407        leakage_101 += getGenProperties()->get("INV1_LeakagePower_1").toDouble();
408        leakage_101 += getGenProperties()->get("INV2_LeakagePower_1").toDouble();
409        leakage_101 += getGenProperties()->get("INV3_LeakagePower_1").toDouble();
410        leakage_101 += getGenProperties()->get("INV4_LeakagePower_0").toDouble();
411        leakage_101 += getGenProperties()->get("INV5_LeakagePower_0").toDouble();
412        leakage_101 += getGenProperties()->get("INV6_LeakagePower_1").toDouble();
413        leakage_101 += getGenProperties()->get("INVZ1_LeakagePower_100_1").toDouble();
414        leakage_101 += getGenProperties()->get("INVZ2_LeakagePower_010_1").toDouble();
415        leakage_101 += getGenProperties()->get("INVZ3_LeakagePower_010_1").toDouble();
416        leakage_101 += getGenProperties()->get("INVZ4_LeakagePower_100_1").toDouble();
417
418        leakage_110 += getGenProperties()->get("INV1_LeakagePower_1").toDouble();
419        leakage_110 += getGenProperties()->get("INV2_LeakagePower_0").toDouble();
420        leakage_110 += getGenProperties()->get("INV3_LeakagePower_0").toDouble();
421        leakage_110 += getGenProperties()->get("INV4_LeakagePower_1").toDouble();
422        leakage_110 += getGenProperties()->get("INV5_LeakagePower_1").toDouble();
423        leakage_110 += getGenProperties()->get("INV6_LeakagePower_0").toDouble();
424        leakage_110 += getGenProperties()->get("INVZ1_LeakagePower_010_0").toDouble();
425        leakage_110 += getGenProperties()->get("INVZ2_LeakagePower_101_0").toDouble();
426        leakage_110 += getGenProperties()->get("INVZ3_LeakagePower_101_0").toDouble();
427        leakage_110 += getGenProperties()->get("INVZ4_LeakagePower_011_0").toDouble();
428
429        leakage_111 += getGenProperties()->get("INV1_LeakagePower_1").toDouble();
430        leakage_111 += getGenProperties()->get("INV2_LeakagePower_1").toDouble();
431        leakage_111 += getGenProperties()->get("INV3_LeakagePower_1").toDouble();
432        leakage_111 += getGenProperties()->get("INV4_LeakagePower_0").toDouble();
433        leakage_111 += getGenProperties()->get("INV5_LeakagePower_1").toDouble();
434        leakage_111 += getGenProperties()->get("INV6_LeakagePower_0").toDouble();
435        leakage_111 += getGenProperties()->get("INVZ1_LeakagePower_010_1").toDouble();
436        leakage_111 += getGenProperties()->get("INVZ2_LeakagePower_100_1").toDouble();
437        leakage_111 += getGenProperties()->get("INVZ3_LeakagePower_100_1").toDouble();
438        leakage_111 += getGenProperties()->get("INVZ4_LeakagePower_010_1").toDouble();
439
440        cache->set(cell_name + "->Leakage->!D!CK!Q", leakage_000);
441        cache->set(cell_name + "->Leakage->!D!CKQ", leakage_001);
442        cache->set(cell_name + "->Leakage->!DCK!Q", leakage_010);
443        cache->set(cell_name + "->Leakage->!DCKQ", leakage_011);
444        cache->set(cell_name + "->Leakage->D!CK!Q", leakage_100);
445        cache->set(cell_name + "->Leakage->D!CKQ", leakage_101);
446        cache->set(cell_name + "->Leakage->DCK!Q", leakage_110);
447        cache->set(cell_name + "->Leakage->DCKQ", leakage_111);
448        Log::printLine(cell_name + "->Leakage->!D!CK!Q=" + (String) leakage_000);
449        Log::printLine(cell_name + "->Leakage->!D!CKQ=" + (String) leakage_001);
450        Log::printLine(cell_name + "->Leakage->!DCK!Q=" + (String) leakage_010);
451        Log::printLine(cell_name + "->Leakage->!DCKQ=" + (String) leakage_011);
452        Log::printLine(cell_name + "->Leakage->D!CK!Q=" + (String) leakage_100);
453        Log::printLine(cell_name + "->Leakage->D!CKQ=" + (String) leakage_101);
454        Log::printLine(cell_name + "->Leakage->DCK!Q=" + (String) leakage_110);
455        Log::printLine(cell_name + "->Leakage->DCKQ=" + (String) leakage_111);
456        // --------------------------------------------------------------------
457
458        /*
459        // Cache event energy results
460        double event_ck_flip = 0.0;
461        event_ck_flip += getGenProperties()->get("INV5_A_Flip").toDouble() + getGenProperties()->get("INV5_ZN_Flip").toDouble();
462        event_ck_flip += getGenProperties()->get("INV6_A_Flip").toDouble() + getGenProperties()->get("INV6_ZN_Flip").toDouble();
463        event_ck_flip += getGenProperties()->get("INVZ1_OE_Flip").toDouble() + getGenProperties()->get("INVZ1_OEN_Flip").toDouble();
464        event_ck_flip += getGenProperties()->get("INVZ2_OE_Flip").toDouble() + getGenProperties()->get("INVZ2_OEN_Flip").toDouble();
465        event_ck_flip += getGenProperties()->get("INVZ3_OE_Flip").toDouble() + getGenProperties()->get("INVZ3_OEN_Flip").toDouble();
466        event_ck_flip += getGenProperties()->get("INVZ4_OE_Flip").toDouble() + getGenProperties()->get("INVZ4_OEN_Flip").toDouble();
467        cache->set(cell_name + "->Event_CK_Flip", event_ck_flip);
468        Log::printLine(cell_name + "->Event_CK_Flip=" + (String) event_ck_flip);
469
470        // Update D flip results
471        double event_d_flip = 0.0;
472        event_d_flip += getGenProperties()->get("INV1_A_Flip").toDouble() + getGenProperties()->get("INV1_ZN_Flip").toDouble();
473        event_d_flip += getGenProperties()->get("INVZ1_A_Flip").toDouble();
474        cache->set(cell_name + "->Event_D_Flip", event_d_flip);
475        Log::printLine(cell_name + "->Event_D_Flip=" + (String) event_d_flip);
476        // Update M flip results
477        double event_m_flip = 0.0;
478        event_m_flip += getGenProperties()->get("INVZ1_ZN_Flip").toDouble();
479        event_m_flip += getGenProperties()->get("INV2_A_Flip").toDouble() + getGenProperties()->get("INV2_ZN_Flip").toDouble();
480        event_m_flip += getGenProperties()->get("INVZ2_A_Flip").toDouble() + getGenProperties()->get("INVZ2_ZN_Flip").toDouble();
481        event_m_flip += getGenProperties()->get("INVZ3_A_Flip").toDouble();
482        cache->set(cell_name + "->Event_M_Flip", event_m_flip);
483        Log::printLine(cell_name + "->Event_M_Flip=" + (String) event_m_flip);
484        // Update Q flip results
485        double event_q_flip = 0.0;
486        event_q_flip += getGenProperties()->get("INVZ3_ZN_Flip").toDouble();
487        event_q_flip += getGenProperties()->get("INV3_A_Flip").toDouble() + getGenProperties()->get("INV3_ZN_Flip").toDouble();
488        event_q_flip += getGenProperties()->get("INVZ4_A_Flip").toDouble() + getGenProperties()->get("INVZ4_ZN_Flip").toDouble();
489        event_q_flip += getGenProperties()->get("INV4_A_Flip").toDouble() + getGenProperties()->get("INV4_ZN_Flip").toDouble();
490        cache->set(cell_name + "->Event_Q_Flip", event_q_flip);
491        Log::printLine(cell_name + "->Event_Q_Flip=" + (String) event_q_flip);
492         */
493
494        // --------------------------------------------------------------------
495        // Get Node Capacitances
496        // --------------------------------------------------------------------
497        double d_cap = getNet("D")->getTotalDownstreamCap();
498        double d_b_cap = getNet("D_b")->getTotalDownstreamCap();
499        double m_b_cap = getNet("M_b")->getTotalDownstreamCap();
500        double m_cap = getNet("M")->getTotalDownstreamCap();
501        double m_i_cap = getNet("M_i")->getTotalDownstreamCap();
502        double q_b_cap = getNet("Q_b")->getTotalDownstreamCap();
503        double q_cap = getNet("Q")->getTotalDownstreamCap();
504        double ck_cap = getNet("CK")->getTotalDownstreamCap();
505        double ck_b_cap = getNet("CK_b")->getTotalDownstreamCap();
506        double ck_i_cap = getNet("CK_i")->getTotalDownstreamCap();
507
508        cache->set(cell_name + "->Cap->D", d_cap);
509        cache->set(cell_name + "->Cap->D_b", d_b_cap);
510        cache->set(cell_name + "->Cap->M_b", m_b_cap);
511        cache->set(cell_name + "->Cap->M", m_cap);
512        cache->set(cell_name + "->Cap->M_i", m_i_cap);
513        cache->set(cell_name + "->Cap->Q_b", q_b_cap);
514        cache->set(cell_name + "->Cap->Q", q_cap);
515        cache->set(cell_name + "->Cap->CK", ck_cap);
516        cache->set(cell_name + "->Cap->CK_b", ck_b_cap);
517        cache->set(cell_name + "->Cap->CK_i", ck_i_cap);
518
519        Log::printLine(cell_name + "->Cap->D=" + (String) d_cap);
520        Log::printLine(cell_name + "->Cap->D_b=" + (String) d_b_cap);
521        Log::printLine(cell_name + "->Cap->M_b=" + (String) m_b_cap);
522        Log::printLine(cell_name + "->Cap->M=" + (String) m_cap);
523        Log::printLine(cell_name + "->Cap->M_i=" + (String) m_i_cap);
524        Log::printLine(cell_name + "->Cap->Q_b=" + (String) q_b_cap);
525        Log::printLine(cell_name + "->Cap->Q=" + (String) q_cap);
526        Log::printLine(cell_name + "->Cap->CK=" + (String) ck_cap);
527        Log::printLine(cell_name + "->Cap->CK_b=" + (String) ck_b_cap);
528        Log::printLine(cell_name + "->Cap->CK_i=" + (String) ck_i_cap);
529        // --------------------------------------------------------------------
530
531        // --------------------------------------------------------------------
532        // Build Internal Delay Model
533        // --------------------------------------------------------------------
534        double q_ron = getDriver("INV4_RonZN")->getOutputRes();
535
536        double d_setup_delay = getDriver("INV1_RonZN")->calculateDelay() +
537            getDriver("INVZ1_RonZN")->calculateDelay() +
538            getDriver("INV2_RonZN")->calculateDelay();
539        double ck_to_q_delay = getDriver("INV5_RonZN")->calculateDelay() +
540            getDriver("INV6_RonZN")->calculateDelay() +
541            getDriver("INVZ3_RonZN")->calculateDelay() +
542            getDriver("INV3_RonZN")->calculateDelay() +
543            getDriver("INV4_RonZN")->calculateDelay();
544
545        cache->set(cell_name + "->DriveRes->Q", q_ron);
546        cache->set(cell_name + "->Delay->D_Setup", d_setup_delay);
547        cache->set(cell_name + "->Delay->CK_to_Q", ck_to_q_delay);
548        Log::printLine(cell_name + "->DriveRes->Q=" + (String) q_ron);
549        Log::printLine(cell_name + "->Delay->D_Setup=" + (String) d_setup_delay);
550        Log::printLine(cell_name + "->Delay->CK_to_Q=" + (String) ck_to_q_delay);
551
552        return;
553        // --------------------------------------------------------------------
554    }
555
556} // namespace DSENT
557
558