StdCellLib.cc (10447:a465576671d4) StdCellLib.cc (10448:bc1a3b7ab5ef)
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
1#include "model/std_cells/StdCellLib.h"
2
3#include <cmath>
4
5#include "model/std_cells/StdCell.h"
6#include "model/std_cells/INV.h"
7#include "model/ModelGen.h"
8
9namespace DSENT
10{
11 using std::pow;
12
13 StdCellLib::StdCellLib(TechModel* tech_model_)
14 : m_tech_model_(tech_model_)
15 {
16 m_std_cell_cache_ = new Map<double>();
17 ASSERT((m_tech_model_ != NULL), "[Error] StdCellLib -> tech_model is NULL");
18 createLib();
19 }
20
21 StdCellLib::~StdCellLib()
22 {
23 delete m_std_cell_cache_;
24 }
25
26 const TechModel* StdCellLib::getTechModel() const
27 {
28 return m_tech_model_;
29 }
30
31 StdCell* StdCellLib::createStdCell(const String& std_cell_name_, const String& instance_name_) const
32 {
33 // Create the standard cell
34 StdCell* created_cell = ModelGen::createStdCell(std_cell_name_, instance_name_, getTechModel());
35 // Grab the variants of each standard cell
36 String driving_strength_str = getTechModel()->get("StdCell->AvailableSizes");
37 // Set library properties for the standard cell
38 created_cell->setPToNRatio(getPToNRatio());
39 created_cell->setActiveHeight(getActiveHeight());
40 created_cell->setTotalHeight(getTotalHeight());
41 created_cell->setAvailableDrivingStrengths(driving_strength_str);
42 return created_cell;
43 }
44
45 // Get PMOS to NMOS ratio
46 double StdCellLib::getPToNRatio() const
47 {
48 return m_p_to_n_ratio_;
49 }
50
51 void StdCellLib::setPToNRatio(double p_to_n_ratio_)
52 {
53 m_p_to_n_ratio_ = p_to_n_ratio_;
54 }
55
56 // Get height of the standard cell taken by active transistors
57 double StdCellLib::getActiveHeight() const
58 {
59 return m_active_height_;
60 }
61
62 void StdCellLib::setActiveHeight(double active_height_)
63 {
64 m_active_height_ = active_height_;
65 }
66
67 // Get total height of the standard cell including overheads
68 double StdCellLib::getTotalHeight() const
69 {
70 return m_total_height_;
71 }
72
73 void StdCellLib::setTotalHeight(double total_height_)
74 {
75 m_total_height_ = total_height_;
76 }
77
78 void StdCellLib::createLib()
79 {
80 Log::printLine("Standard cell library creation for tech model " + getTechModel()->get("Name"));
81
82 // Get technology parameters
83 double nmos_eff_res = getTechModel()->get("Nmos->EffResWidth");
84 double pmos_eff_res = getTechModel()->get("Pmos->EffResWidth");
85 double gate_min_width = getTechModel()->get("Gate->MinWidth");
86
87 // Create standard cell common parameters
88 double pn_ratio = pmos_eff_res / nmos_eff_res;
89 double nmos_unit_width = gate_min_width;
90 double pmos_unit_width = gate_min_width * pn_ratio;
91
92 // Derive the height of each cell in the standard cell library, as well as the max Nmos and Pmos widths
93 double std_cell_total_height = getTechModel()->get("StdCell->Tracks").toDouble() *
94 (getTechModel()->get("Wire->Metal1->MinWidth").toDouble() + getTechModel()->get("Wire->Metal1->MinSpacing").toDouble());
95 double std_cell_active_height = std_cell_total_height / getTechModel()->get("StdCell->HeightOverheadFactor").toDouble();
96
97 Log::printLine("Standard cell P-to-N ratio (Beta) = " + (String) pn_ratio);
98 Log::printLine("Standard cell NMOS unit width = " + (String) nmos_unit_width);
99 Log::printLine("Standard cell PMOS unit width = " + (String) pmos_unit_width);
100 Log::printLine("Standard cell active height = " + (String) std_cell_active_height);
101 Log::printLine("Standard cell total height = " + (String) std_cell_total_height);
102
103 setPToNRatio(pn_ratio);
104 setActiveHeight(std_cell_active_height);
105 setTotalHeight(std_cell_total_height);
106
107 const vector<String>& cell_sizes = getTechModel()->get("StdCell->AvailableSizes").split("[,]");
108 // Create cached standard cells
109 for (unsigned int i = 0; i < cell_sizes.size(); ++i)
110 {
111 StdCell* inv = createStdCell("INV", "CachedINV");
112 inv->cacheStdCell(this, cell_sizes[i].toDouble());
113 delete inv;
114
115 StdCell* nand2 = createStdCell("NAND2", "CachedNAND2");
116 nand2->cacheStdCell(this, cell_sizes[i].toDouble());
117 delete nand2;
118
119 StdCell* nor2 = createStdCell("NOR2", "CachedNOR2");
120 nor2->cacheStdCell(this, cell_sizes[i].toDouble());
121 delete nor2;
122
123 StdCell* mux2 = createStdCell("MUX2", "CachedMUX2");
124 mux2->cacheStdCell(this, cell_sizes[i].toDouble());
125 delete mux2;
126
127 StdCell* xor2 = createStdCell("XOR2", "CachedXOR2");
128 xor2->cacheStdCell(this, cell_sizes[i].toDouble());
129 delete xor2;
130
131 StdCell* addf = createStdCell("ADDF", "CachedADDF");
132 addf->cacheStdCell(this, cell_sizes[i].toDouble());
133 delete addf;
134
135 StdCell* dffq = createStdCell("DFFQ", "CachedDFFQ");
136 dffq->cacheStdCell(this, cell_sizes[i].toDouble());
137 delete dffq;
138
139 StdCell* latq = createStdCell("LATQ", "CachedLATQ");
140 latq->cacheStdCell(this, cell_sizes[i].toDouble());
141 delete latq;
142
143 StdCell* or2 = createStdCell("OR2", "CachedOR2");
144 or2->cacheStdCell(this, cell_sizes[i].toDouble());
145 delete or2;
146
147 StdCell* and2 = createStdCell("AND2", "CachedAND2");
148 and2->cacheStdCell(this, cell_sizes[i].toDouble());
149 delete and2;
150 }
151
152 Log::printLine("Standard cell library creation - End");
153 return;
154 }
155
156 StdCellLib* StdCellLib::clone() const
157 {
158 StdCellLib* new_lib = new StdCellLib(m_tech_model_);
159 return new_lib;
160 }
161
162 const String StdCellLib::genDrivingStrengthString(const vector<double>& driving_strength_) const
163 {
164 String ret_str = "[";
165 for(int i = 0; i < (int)driving_strength_.size() - 1; ++i)
166 {
167 ret_str += String(driving_strength_[i]) + ", ";
168 }
169 ret_str += String(driving_strength_[driving_strength_.size() - 1]);
170 ret_str += "]";
171 return ret_str;
172 }
173
174 Map<double>* StdCellLib::getStdCellCache() const
175 {
176 return m_std_cell_cache_;
177 }
178
179} // namespace DSENT
180
22#include "model/std_cells/StdCellLib.h"
23
24#include <cmath>
25
26#include "model/std_cells/StdCell.h"
27#include "model/std_cells/INV.h"
28#include "model/ModelGen.h"
29
30namespace DSENT
31{
32 using std::pow;
33
34 StdCellLib::StdCellLib(TechModel* tech_model_)
35 : m_tech_model_(tech_model_)
36 {
37 m_std_cell_cache_ = new Map<double>();
38 ASSERT((m_tech_model_ != NULL), "[Error] StdCellLib -> tech_model is NULL");
39 createLib();
40 }
41
42 StdCellLib::~StdCellLib()
43 {
44 delete m_std_cell_cache_;
45 }
46
47 const TechModel* StdCellLib::getTechModel() const
48 {
49 return m_tech_model_;
50 }
51
52 StdCell* StdCellLib::createStdCell(const String& std_cell_name_, const String& instance_name_) const
53 {
54 // Create the standard cell
55 StdCell* created_cell = ModelGen::createStdCell(std_cell_name_, instance_name_, getTechModel());
56 // Grab the variants of each standard cell
57 String driving_strength_str = getTechModel()->get("StdCell->AvailableSizes");
58 // Set library properties for the standard cell
59 created_cell->setPToNRatio(getPToNRatio());
60 created_cell->setActiveHeight(getActiveHeight());
61 created_cell->setTotalHeight(getTotalHeight());
62 created_cell->setAvailableDrivingStrengths(driving_strength_str);
63 return created_cell;
64 }
65
66 // Get PMOS to NMOS ratio
67 double StdCellLib::getPToNRatio() const
68 {
69 return m_p_to_n_ratio_;
70 }
71
72 void StdCellLib::setPToNRatio(double p_to_n_ratio_)
73 {
74 m_p_to_n_ratio_ = p_to_n_ratio_;
75 }
76
77 // Get height of the standard cell taken by active transistors
78 double StdCellLib::getActiveHeight() const
79 {
80 return m_active_height_;
81 }
82
83 void StdCellLib::setActiveHeight(double active_height_)
84 {
85 m_active_height_ = active_height_;
86 }
87
88 // Get total height of the standard cell including overheads
89 double StdCellLib::getTotalHeight() const
90 {
91 return m_total_height_;
92 }
93
94 void StdCellLib::setTotalHeight(double total_height_)
95 {
96 m_total_height_ = total_height_;
97 }
98
99 void StdCellLib::createLib()
100 {
101 Log::printLine("Standard cell library creation for tech model " + getTechModel()->get("Name"));
102
103 // Get technology parameters
104 double nmos_eff_res = getTechModel()->get("Nmos->EffResWidth");
105 double pmos_eff_res = getTechModel()->get("Pmos->EffResWidth");
106 double gate_min_width = getTechModel()->get("Gate->MinWidth");
107
108 // Create standard cell common parameters
109 double pn_ratio = pmos_eff_res / nmos_eff_res;
110 double nmos_unit_width = gate_min_width;
111 double pmos_unit_width = gate_min_width * pn_ratio;
112
113 // Derive the height of each cell in the standard cell library, as well as the max Nmos and Pmos widths
114 double std_cell_total_height = getTechModel()->get("StdCell->Tracks").toDouble() *
115 (getTechModel()->get("Wire->Metal1->MinWidth").toDouble() + getTechModel()->get("Wire->Metal1->MinSpacing").toDouble());
116 double std_cell_active_height = std_cell_total_height / getTechModel()->get("StdCell->HeightOverheadFactor").toDouble();
117
118 Log::printLine("Standard cell P-to-N ratio (Beta) = " + (String) pn_ratio);
119 Log::printLine("Standard cell NMOS unit width = " + (String) nmos_unit_width);
120 Log::printLine("Standard cell PMOS unit width = " + (String) pmos_unit_width);
121 Log::printLine("Standard cell active height = " + (String) std_cell_active_height);
122 Log::printLine("Standard cell total height = " + (String) std_cell_total_height);
123
124 setPToNRatio(pn_ratio);
125 setActiveHeight(std_cell_active_height);
126 setTotalHeight(std_cell_total_height);
127
128 const vector<String>& cell_sizes = getTechModel()->get("StdCell->AvailableSizes").split("[,]");
129 // Create cached standard cells
130 for (unsigned int i = 0; i < cell_sizes.size(); ++i)
131 {
132 StdCell* inv = createStdCell("INV", "CachedINV");
133 inv->cacheStdCell(this, cell_sizes[i].toDouble());
134 delete inv;
135
136 StdCell* nand2 = createStdCell("NAND2", "CachedNAND2");
137 nand2->cacheStdCell(this, cell_sizes[i].toDouble());
138 delete nand2;
139
140 StdCell* nor2 = createStdCell("NOR2", "CachedNOR2");
141 nor2->cacheStdCell(this, cell_sizes[i].toDouble());
142 delete nor2;
143
144 StdCell* mux2 = createStdCell("MUX2", "CachedMUX2");
145 mux2->cacheStdCell(this, cell_sizes[i].toDouble());
146 delete mux2;
147
148 StdCell* xor2 = createStdCell("XOR2", "CachedXOR2");
149 xor2->cacheStdCell(this, cell_sizes[i].toDouble());
150 delete xor2;
151
152 StdCell* addf = createStdCell("ADDF", "CachedADDF");
153 addf->cacheStdCell(this, cell_sizes[i].toDouble());
154 delete addf;
155
156 StdCell* dffq = createStdCell("DFFQ", "CachedDFFQ");
157 dffq->cacheStdCell(this, cell_sizes[i].toDouble());
158 delete dffq;
159
160 StdCell* latq = createStdCell("LATQ", "CachedLATQ");
161 latq->cacheStdCell(this, cell_sizes[i].toDouble());
162 delete latq;
163
164 StdCell* or2 = createStdCell("OR2", "CachedOR2");
165 or2->cacheStdCell(this, cell_sizes[i].toDouble());
166 delete or2;
167
168 StdCell* and2 = createStdCell("AND2", "CachedAND2");
169 and2->cacheStdCell(this, cell_sizes[i].toDouble());
170 delete and2;
171 }
172
173 Log::printLine("Standard cell library creation - End");
174 return;
175 }
176
177 StdCellLib* StdCellLib::clone() const
178 {
179 StdCellLib* new_lib = new StdCellLib(m_tech_model_);
180 return new_lib;
181 }
182
183 const String StdCellLib::genDrivingStrengthString(const vector<double>& driving_strength_) const
184 {
185 String ret_str = "[";
186 for(int i = 0; i < (int)driving_strength_.size() - 1; ++i)
187 {
188 ret_str += String(driving_strength_[i]) + ", ";
189 }
190 ret_str += String(driving_strength_[driving_strength_.size() - 1]);
191 ret_str += "]";
192 return ret_str;
193 }
194
195 Map<double>* StdCellLib::getStdCellCache() const
196 {
197 return m_std_cell_cache_;
198 }
199
200} // namespace DSENT
201