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/electrical/RippleAdder.h"
26 #include "model/PortInfo.h"
27 #include "model/TransitionInfo.h"
28 #include "model/EventInfo.h"
29 #include "model/std_cells/StdCell.h"
30 #include "model/std_cells/StdCellLib.h"
34 RippleAdder::RippleAdder(const String
& instance_name_
, const TechModel
* tech_model_
)
35 : ElectricalModel(instance_name_
, tech_model_
)
41 RippleAdder::~RippleAdder()
44 void RippleAdder::initParameters()
46 addParameterName("NumberBits");
50 void RippleAdder::initProperties()
55 void RippleAdder::constructModel()
58 unsigned int number_bits
= (unsigned int) getParameter("NumberBits");
60 //Construct electrical ports and nets
61 createInputPort("CI");
62 createOutputPort("CO");
63 for(unsigned int i
= 0; i
< number_bits
; ++i
)
65 createInputPort("A" + String(i
));
66 createInputPort("B" + String(i
));
67 createOutputPort("S" + String(i
));
68 createNet("C" + String(i
));
70 createNet("C" + String(number_bits
));
72 //Create energy, power, and area results
73 createElectricalResults();
74 getEventInfo("Idle")->setStaticTransitionInfos();
75 createElectricalEventResult("Add");
76 Result
* add_event
= getEventResult("Add");
80 assign("CO", "C" + String(number_bits
));
81 for (unsigned int i
= 0; i
< number_bits
; ++i
)
83 String n
= (String
) i
;
84 StdCell
* adder
= getTechModel()->getStdCellLib()->createStdCell("ADDF", "ADDF_" + n
);
87 //Build electrical connectivity
88 portConnect(adder
, "A", "A" + String(i
));
89 portConnect(adder
, "B", "B" + String(i
));
90 portConnect(adder
, "CI", "C" + String(i
));
91 portConnect(adder
, "S", "S" + String(i
));
92 portConnect(adder
, "CO", "C" + String(i
+ 1));
94 //Add ADDF instance, leakage power, energy, and add event results
95 addSubInstances(adder
, 1.0);
96 addElectricalSubResults(adder
, 1.0);
97 add_event
->addSubResult(adder
->getEventResult("ADDF"), "ADDF_" + n
, 1.0);
103 void RippleAdder::propagateTransitionInfo()
105 unsigned int number_bits
= getParameter("NumberBits").toUInt();
107 TransitionInfo current_trans_CI
= getInputPort("CI")->getTransitionInfo();
108 for(unsigned int i
= 0; i
< number_bits
; ++i
)
110 ElectricalModel
* adder
= (ElectricalModel
*)getSubInstance("ADDF_" + String(i
));
112 // Propagate input transition info
113 propagatePortTransitionInfo(adder
, "A", "A" + String(i
));
114 propagatePortTransitionInfo(adder
, "B", "B" + String(i
));
115 assignPortTransitionInfo(adder
, "CI", current_trans_CI
);
118 // Assign output transition info
119 propagatePortTransitionInfo("S" + String(i
), adder
, "S");
120 current_trans_CI
= adder
->getOutputPort("CO")->getTransitionInfo();
122 getOutputPort("CO")->setTransitionInfo(current_trans_CI
);