TestModel.cc revision 10447
1#include "model/electrical/TestModel.h"
2
3#include <cmath>
4
5#include "model/std_cells/StdCell.h"
6#include "model/std_cells/StdCellLib.h"
7#include "model/electrical/RippleAdder.h"
8#include "model/electrical/Multiplexer.h"
9#include "model/timing_graph/ElectricalNet.h"
10#include "model/timing_graph/ElectricalDriver.h"
11#include "model/timing_graph/ElectricalLoad.h"
12#include "model/timing_graph/ElectricalTimingTree.h"
13
14namespace DSENT
15{
16    TestModel::TestModel(const String& instance_name_, const TechModel* tech_model_)
17        : ElectricalModel(instance_name_, tech_model_)
18    {
19        initProperties();
20    }
21
22    TestModel::~TestModel()
23    {}
24
25    void TestModel::initProperties()
26    {
27        return;
28    }
29
30    TestModel* TestModel::clone() const
31    {
32        return NULL;
33    }
34
35    void TestModel::constructModel()
36    {
37        unsigned int num_bits = 64;
38        unsigned int mux_bits = 1;
39
40        // Create the instance
41        createNet("CK");
42        createNet("CI");
43        getNet("CI")->setDistributedCap(100e-15);
44        getNet("CI")->setDistributedRes(10);
45        createNet("CO");
46        createNet("A", makeNetIndex(0, num_bits - 1));
47        createNet("B", makeNetIndex(0, num_bits - 1));
48        createNet("S", makeNetIndex(0, num_bits - 1));
49
50        StdCell* ci_reg = getTechModel()->getStdCellLib()->createStdCell("DFFQ", "DFFQ-CI");
51        ci_reg->setProperty("P(D)", 0.5);
52        ci_reg->setProperty("P(CK)", 0.5);
53        ci_reg->construct();
54        portConnect(ci_reg, "Q", "CI");
55        portConnect(ci_reg, "CK", "CK");
56        //ci_reg->connect("Q", getNet("CI"));
57        //ci_reg->connect("CK", getNet("CK"));
58        addSubInstances(ci_reg, 1.0);
59
60        StdCell* co_reg = getTechModel()->getStdCellLib()->createStdCell("DFFQ", "DFFQ-CO");
61        co_reg->setProperty("P(D)", 0.5);
62        co_reg->setProperty("P(CK)", 0.5);
63        co_reg->construct();
64        portConnect(co_reg, "D", "CO");
65        portConnect(co_reg, "CK", "CK");
66        //co_reg->connect("D", getNet("CO"));
67        //co_reg->connect("CK", getNet("CK"));
68        addSubInstances(co_reg, 1.0);
69
70        for (unsigned int i = 0; i < num_bits; i++)
71        {
72            StdCell* a_reg = getTechModel()->getStdCellLib()->createStdCell("DFFQ", "DFFQ-A[" + (String) i + "]");
73            a_reg->setProperty("P(D)", 0.5);
74            a_reg->setProperty("P(CK)", 0.5);
75            a_reg->construct();
76            portConnect(a_reg, "Q", "A", makeNetIndex(i));
77            portConnect(a_reg, "CK", "CK");
78            //a_reg->connect("Q", getNet("A[" + (String) i + "]"));
79            //a_reg->connect("CK", getNet("CK"));
80            addSubInstances(a_reg, 1.0);
81
82            StdCell* b_reg = getTechModel()->getStdCellLib()->createStdCell("DFFQ", "DFFQ-B[" + (String) i + "]");
83            b_reg->setProperty("P(D)", 0.5);
84            b_reg->setProperty("P(CK)", 0.5);
85            b_reg->construct();
86            portConnect(b_reg, "Q", "B", makeNetIndex(i));
87            portConnect(b_reg, "CK", "CK");
88            //b_reg->connect("Q", getNet("B[" + (String) i + "]"));
89            //b_reg->connect("CK", getNet("CK"));
90            addSubInstances(b_reg, 1.0);
91
92            StdCell* s_reg = getTechModel()->getStdCellLib()->createStdCell("DFFQ", "DFFQ-S[" + (String) i + "]");
93            s_reg->setProperty("P(D)", 0.5);
94            s_reg->setProperty("P(CK)", 0.5);
95            s_reg->construct();
96            portConnect(s_reg, "D", "S", makeNetIndex(i));
97            portConnect(s_reg, "CK", "CK");
98            //s_reg->connect("D", getNet("A[" + (String) i + "]"));
99            //s_reg->connect("CK", getNet("CK"));
100            addSubInstances(s_reg, 1.0);
101        }
102
103
104        //Create some adders!
105
106        ElectricalModel* ripple_adder = new RippleAdder("Adder_1", getTechModel());
107        ripple_adder->setParameter("NumberBits", num_bits);
108        ripple_adder->setProperty("P(A)", 0.5);
109        ripple_adder->setProperty("P(B)", 0.5);
110        ripple_adder->setProperty("P(CI)", 0.5);
111
112        ripple_adder->construct();
113        addSubInstances(ripple_adder, 1.0);
114        portConnect(ripple_adder, "CI", "CI");
115        portConnect(ripple_adder, "CO", "CO");
116        portConnect(ripple_adder, "A", "A");
117        portConnect(ripple_adder, "B", "B");
118        portConnect(ripple_adder, "S", "S");
119
120        ElectricalModel* multiplexer = new Multiplexer("Mux_1", getTechModel());
121        multiplexer->setParameter("NumberInputs", 2);
122        multiplexer->setParameter("NumberBits", mux_bits);
123        multiplexer->setParameter("BitDuplicate", "FALSE");
124        //multiplexer->setProperty("P(In)", "[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]");
125        //multiplexer->setProperty("P(Sel)", "[0.5, 0.5, 0.5]");
126        //multiplexer->setProperty("Act(In)", "[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]");
127        //multiplexer->setProperty("Act(Sel)", "[2.0, 4.0, 8.0]");
128        multiplexer->setProperty("P(In)", "[0.5, 0.5]");
129        multiplexer->setProperty("P(Sel)", "[0.5]");
130        multiplexer->setProperty("Act(In)", "[1.0, 1.0]");
131        multiplexer->setProperty("Act(Sel)", "[1.0]");
132        multiplexer->construct();
133
134        createNet("In0", makeNetIndex(0, mux_bits-1));
135        createNet("In1", makeNetIndex(0, mux_bits-1));
136        createNet("In2", makeNetIndex(0, mux_bits-1));
137        createNet("In3", makeNetIndex(0, mux_bits-1));
138        createNet("In4", makeNetIndex(0, mux_bits-1));
139        createNet("Out", makeNetIndex(0, mux_bits-1));
140
141        portConnect(multiplexer, "In0", "In0");
142        portConnect(multiplexer, "In1", "In1");
143        //portConnect(multiplexer, "In2", "In2");
144        //portConnect(multiplexer, "In3", "In3");
145        //portConnect(multiplexer, "In4", "In4");
146        portConnect(multiplexer, "Out", "Out");
147
148        for (unsigned int i = 0; i < mux_bits; ++i)
149        {
150            String n = (String) i;
151
152            createLoad("OutLoad[" + n + "]");
153            getLoad("OutLoad[" + n + "]")->setLoadCap(100e-15);
154
155            getNet("Out", makeNetIndex(i))->addDownstreamNode(getLoad("OutLoad[" + n + "]"));
156        }
157        createNet("Sel", makeNetIndex(0, 2));
158        assign("Sel", makeNetIndex(0), "CK");
159        assign("Sel", makeNetIndex(1), "CK");
160        assign("Sel", makeNetIndex(2), "CK");
161
162        //portConnect(multiplexer, "Sel", "Sel");
163
164        addSubInstances(multiplexer, 1.0);
165
166        //ElectricalTimingAbstract* abstract = new ElectricalTimingAbstract("HAHAHA", getTechModel(), ripple_adder);
167        //abstract->buildAbstract();
168
169        return;
170    }
171
172    void TestModel::updateModel()
173    {
174        Model::updateModel();
175
176        //ElectricalTimingTree* t = new ElectricalTimingTree("Add", this);
177        //t->performTimingOpt(getNet("CK"), 4.21300e-8);
178        //t->performTimingOpt(getNet("CK"), 1e-9);
179        //delete t;
180
181        ElectricalTimingTree* t2 = new ElectricalTimingTree("Mux", this);
182        t2->performTimingOpt(getNet("In1", makeNetIndex(0)), 500e-12);
183        delete t2;
184
185
186    }
187
188    void TestModel::evaluateModel()
189    {
190        Model::evaluateModel();
191
192        //ripple_adder->getNddPowerResult("LeakagePower")->print("RippleAdder->Leakage", 10, cout);
193        getSubInstance("Adder_1")->getNddPowerResult("Leakage")->print("RippleAdder->Leakage", 0, cout);
194        //ripple_adder->getAreaResult("TotalArea")->print("RippleAdder->TotalArea", 10, cout);
195        getSubInstance("Adder_1")->getAreaResult("Active")->print("RippleAdder->ActiveArea", 0, cout);
196        //ripple_adder->getEventResult("AddEvent")->print("RippleAdder->AddEvent", 10, cout);
197        getSubInstance("Adder_1")->getEventResult("Add")->print("RippleAdder->Add", 0, cout);
198
199        getSubInstance("Mux_1")->getNddPowerResult("Leakage")->print("Multiplexer->Leakage", 0, cout);
200        getSubInstance("Mux_1")->getAreaResult("Active")->print("Multiplexer->ActiveArea", 0, cout);
201        getSubInstance("Mux_1")->getEventResult("Mux")->print("Multiplexer->MuxEvent", 0, cout);
202        cout << "Multiplexer->P(Out) = " << getSubInstance("Mux_1")->getGenProperties()->get("P(Out)") << endl;
203
204        getSubInstance("DFFQ-CI")->getNddPowerResult("Leakage")->print("DFFQ-CI->Leakage", 0, cout);
205        getSubInstance("DFFQ-CI")->getAreaResult("Active")->print("DFFQ-CI->ActiveArea", 0, cout);
206        getSubInstance("DFFQ-CI")->getEventResult("DFF")->print("DFFQ-CI->DFF", 0, cout);
207        getSubInstance("DFFQ-CI")->getEventResult("CK")->print("DFFQ-CI->CK", 0, cout);
208
209        //ripple_adder->getNddPowerResult("LeakagePower")->print("RippleAdder->Leakage", 10, cout);
210        getSubInstance("Adder_1")->getNddPowerResult("Leakage")->print("RippleAdder->Leakage", 0, cout);
211        //ripple_adder->getAreaResult("TotalArea")->print("RippleAdder->TotalArea", 10, cout);
212        getSubInstance("Adder_1")->getAreaResult("Active")->print("RippleAdder->ActiveArea", 0, cout);
213        //ripple_adder->getEventResult("AddEvent")->print("RippleAdder->AddEvent", 10, cout);
214        getSubInstance("Adder_1")->getEventResult("Add")->print("RippleAdder->AddEvent", 0, cout);
215    }
216
217} // namespace DSENT
218
219