ElectricalModel.h revision 10447
1#ifndef __DSENT_MODEL_ELECTRICALMODEL_H__
2#define __DSENT_MODEL_ELECTRICALMODEL_H__
3
4#include "util/CommonType.h"
5#include "model/Model.h"
6#include "model/TransitionInfo.h"
7
8namespace DSENT
9{
10    class PortInfo;
11    class EventInfo;
12    class ElectricalDriver;
13    class ElectricalDriverMultiplier;
14    class ElectricalNet;
15    class ElectricalLoad;
16    class ElectricalDelay;
17
18    // A Net index consisting of a start and end index
19    typedef std::pair<int, int> NetIndex;
20
21    // Helper function to make net index
22    inline NetIndex makeNetIndex(int start_index_, int end_index_)
23    {
24        ASSERT((end_index_ >= start_index_), (String)"[Error] Invalid net index range " +
25
26                "[" + (String)start_index_ + ":" + (String)end_index_ + "]");
27
28        return NetIndex(start_index_, end_index_);
29    }
30
31    // Helper function to make net index
32    inline NetIndex makeNetIndex(int index_)
33    {
34        return makeNetIndex(index_, index_);
35    }
36
37    // Helper function to trun NetIndex to String
38    inline String toString(const NetIndex& net_index_)
39    {
40        return "[" + String(net_index_.second) + ":" + String(net_index_.first) + "]";
41    }
42
43    // ElectricalModel specifies physical connectivity to other models as well as the port
44    // parameters for the current model
45    class ElectricalModel : public Model
46    {
47        public:
48            ElectricalModel(const String& instance_name_, const TechModel* tech_model_);
49            virtual ~ElectricalModel();
50
51        public:
52            // Check if all properties needed exist in the m_properties_
53            virtual void checkProperties() const;
54            // Set available driving strength vector from string
55            void setAvailableDrivingStrengths(const String& driving_strengths_);
56
57            //-----------------------------------------------------------------
58            // Connectivity specification
59            //-----------------------------------------------------------------
60            // Net Indices
61            const Map<NetIndex>* getNetReferences() const;
62            const NetIndex getNetReference(const String& name_) const;
63            // Input Ports
64            void createInputPort(const String& name_, const NetIndex& net_indices_ = NetIndex(0, 0));
65            const Map<PortInfo*>* getInputs() const;
66            PortInfo* getInputPort(const String& name_);
67            const PortInfo* getInputPort(const String& name_) const;
68            // Output Ports
69            void createOutputPort(const String& name_, const NetIndex& net_indices_ = NetIndex(0, 0));
70            const Map<PortInfo*>* getOutputs() const;
71            PortInfo* getOutputPort(const String& name_);
72            const PortInfo* getOutputPort(const String& name_) const;
73            // Electrical Nets
74            void createNet(const String& name_);
75            void createNet(const String& name_, const NetIndex& net_indices_);
76            const Map<ElectricalNet*>* getNets() const;
77            ElectricalNet* getNet(const String& name_);
78            ElectricalNet* getNet(const String& name_, const NetIndex& index_);
79
80            // Assign a net to be downstream from another net
81            // case 1: 'assign downstream_net_name_ = upstream_net_name_'
82            void assign(const String& downstream_net_name_, const String& upstream_net_name_);
83            // case 2: 'assign downstream_net_name_[end:begin] = upstream_net_name_'
84            void assign(const String& downstream_net_name_, const NetIndex& downstream_net_indices_, const String& upstream_net_name_);
85            // case 3: 'assign downstream_net_name_ = upstream_net_name_[end:begin]'
86            void assign(const String& downstream_net_name_, const String& upstream_net_name_, const NetIndex& upstream_net_indices_);
87            // case 4: 'assign downstream_net_name_[end:begin] = upstream_net_name_[end:begin]'
88            void assign(const String& downstream_net_name_, const NetIndex& downstream_net_indices_, const String& upstream_net_name_, const NetIndex& upstream_net_indices_);
89
90            // Connect a port (input or output) to some ElectricalNet
91            // case 1: .connect_port_name_(connect_net_name_)
92            void portConnect(ElectricalModel* connect_model_, const String& connect_port_name_, const String& connect_net_name_);
93            // case 2: .connect_port_name_(connect_net_name[end:begin])
94            void portConnect(ElectricalModel* connect_model_, const String& connect_port_name_, const String& connect_net_name_, const NetIndex& connect_net_indices_);
95
96            // Assign a net to be downstream from another net through a driver multipliers
97            void assignVirtualFanout(const String& downstream_net_name_, const String& upstream_net_name_);
98            void assignVirtualFanout(const String& downstream_net_name_, const NetIndex& downstream_net_indices_, const String& upstream_net_name_, const NetIndex& upstream_net_indices_);
99            // Assign a net to be downstream from another net
100            // This is used to enable bit_duplication
101            void assignVirtualFanin(const String& downstream_net_name_, const String& upstream_net_name_);
102            void assignVirtualFanin(const String& downstream_net_name_, const NetIndex& downstream_net_indices_, const String& upstream_net_name_, const NetIndex& upstream_net_indices_);
103            //-----------------------------------------------------------------
104
105            //-----------------------------------------------------------------
106            // Timing Model Components
107            //-----------------------------------------------------------------
108            // Electrical Drivers
109            void createDriver(const String& name_, bool sizable_);
110            //void createDriver(const String& name_, bool sizable_, int start_index_, int end_index_);
111            const Map<ElectricalDriver*>* getDrivers() const;
112            ElectricalDriver* getDriver(const String& name_);
113            // Electrical Driver Multipliers
114            void createDriverMultiplier(const String& name_);
115            const Map<ElectricalDriverMultiplier*>* getDriverMultipliers() const;
116            ElectricalDriverMultiplier* getDriverMultiplier(const String& name_);
117
118
119            // Electrical Loads
120            void createLoad(const String& name_);
121            //void createLoad(const String& name_, int start_index_, int end_index_);
122            const Map<ElectricalLoad*>* getLoads() const;
123            ElectricalLoad* getLoad(const String& name_);
124            // Electrical Delay creation
125            void createDelay(const String& name_);
126            //void createDelay(const String& name_, int start_index_, int end_index_);
127            const Map<ElectricalDelay*>* getDelays() const;
128            ElectricalDelay* getDelay(const String& name_);
129            //-----------------------------------------------------------------
130
131            // Get current driving strength
132            double getDrivingStrength() const;
133            // Get current driving strength index
134            int getDrivingStrengthIdx() const;
135            // Set driving strength by index
136            void setDrivingStrengthIdx(int idx_);
137            // Set the instance to minimum driving strength
138            void setMinDrivingStrength();
139            // Return true if the instance has minimum driving strength
140            bool hasMinDrivingStrength() const;
141            // Return true if the instance has maximum driving strength
142            bool hasMaxDrivingStrength() const;
143            // Increase driving strength index by 1
144            void increaseDrivingStrength();
145            // Decrease driving strength index by 1
146            void decreaseDrivingStrength();
147
148            // Create the default sets of the electrical results
149            void createElectricalResults();
150            // Add the default sets of the electrical results from a model
151            void addElectricalSubResults(const ElectricalModel* model_, double number_models_);
152            // Add extra wire sub results
153            void addElectricalWireSubResult(const String& wire_layer_, const Result* result_, const String& producer_, double number_results_);
154            // Create the default sets of the electrical atomic results
155            void createElectricalAtomicResults();
156            // Accumulate the electrical atomic results' values
157            void addElecticalAtomicResultValues(const ElectricalModel* model_, double number_models_);
158            // Add extra wire sub results
159            void addElecticalWireAtomicResultValue(const String& wire_layer_, double value_);
160            // Reset the electrical atomic results' values
161            void resetElectricalAtomicResults();
162            // Create an electrical event result. This will add an event associate to all input/output ports
163            void createElectricalEventResult(const String& name_);
164            // Create an electrical event atomic result
165            void createElectricalEventAtomicResult(const String& name_);
166
167            //-----------------------------------------------------------------
168            // Helper functions to propagate transition information
169            //-----------------------------------------------------------------
170            void assignPortTransitionInfo(ElectricalModel* downstream_model_, const String& downstream_port_name_, const TransitionInfo& trans_info_);
171            void propagatePortTransitionInfo(const String& downstream_port_name_, const String& upstream_port_name_);
172            void propagatePortTransitionInfo(ElectricalModel* downstream_model_, const String& downstream_port_name_, const String& upstream_port_name_);
173            void propagatePortTransitionInfo(ElectricalModel* downstream_model_, const String& downstream_port_name_, const ElectricalModel* upstream_model_, const String& upstream_port_name_);
174            void propagatePortTransitionInfo(const String& downstream_port_name_, const ElectricalModel* upstream_model_, const String& upstream_port_name_);
175            virtual void propagateTransitionInfo();
176            //-----------------------------------------------------------------
177
178            //-----------------------------------------------------------------
179            // Helper functions to insert and remove buffers
180            //-----------------------------------------------------------------
181
182            //-----------------------------------------------------------------
183
184            virtual void useModel(const String& event_name_);
185            virtual void useModel();
186            // TODO - add comments
187            void applyTransitionInfo(const String& event_name_);
188            // TODO - add comments
189            EventInfo* getEventInfo(const String& event_name_);
190
191        protected:
192            // In an ElectricalModel, the complete port-to-port connectivity
193            // of all sub-instance must be specified. Addition/Removal ports or
194            // port-related nets cannot happen after this step
195            //virtual void constructModel() = 0;
196            // In an ElectricalModel, updateModel MUST finish all necessary
197            // calculations such that a timing model can be run
198            //virtual void updateModel() = 0;
199            // In an ElectricalModel, evaluateModel should calculate all
200            // event energies, now that the connectivity and timing has been
201            // completed
202            //virtual void evaluateModel() = 0;
203
204        private:
205            // Private copy constructor. Use clone to perform copy operation.
206            ElectricalModel(const ElectricalModel& model_);
207
208        private:
209            // Contains the driving strengths in increasing order
210            vector<double> m_driving_strengths_;
211            // Driving strength index in the driving strength vector
212            int m_curr_driving_strengths_idx_;
213
214            //Connectivity elements
215            // Nets can come in various bus widths. A net reference is really
216            // just a helper map mapping a referenced map name to a bunch of
217            // net indices. A net index returns the starting and end indices of
218            // a net if the net is a multi-bit bus of some sort
219            Map<NetIndex>* m_net_references_;
220            // Map of the input ports
221            Map<PortInfo*>* m_input_ports_;
222            // Map of the output ports
223            Map<PortInfo*>* m_output_ports_;
224            // Map of all our electrical nets
225            Map<ElectricalNet*>* m_nets_;
226
227            //Timing model elements
228            // Map of all our electrical drivers
229            Map<ElectricalDriver*>* m_drivers_;
230            // Map of all our driver multipliers
231            Map<ElectricalDriverMultiplier*>* m_driver_multipliers_;
232            // Map of all our electrical loads
233            Map<ElectricalLoad*>* m_loads_;
234            // Map of all our idealized delays
235            Map<ElectricalDelay*>* m_delays_;
236
237            // Map of the event infos
238            Map<EventInfo*>* m_event_infos_;
239
240    }; // class ElectricalModel
241} // namespace DSENT
242
243#endif // __DSENT_MODEL_ELECTRICALMODEL_H__
244
245