StdCellLib.cc revision 10448
111527Sdavid.guillen@arm.com/* Copyright (c) 2012 Massachusetts Institute of Technology 211527Sdavid.guillen@arm.com * 311527Sdavid.guillen@arm.com * Permission is hereby granted, free of charge, to any person obtaining a copy 411527Sdavid.guillen@arm.com * of this software and associated documentation files (the "Software"), to deal 511527Sdavid.guillen@arm.com * in the Software without restriction, including without limitation the rights 611527Sdavid.guillen@arm.com * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 711527Sdavid.guillen@arm.com * copies of the Software, and to permit persons to whom the Software is 811527Sdavid.guillen@arm.com * furnished to do so, subject to the following conditions: 911527Sdavid.guillen@arm.com * 1011527Sdavid.guillen@arm.com * The above copyright notice and this permission notice shall be included in 1111527Sdavid.guillen@arm.com * all copies or substantial portions of the Software. 1211527Sdavid.guillen@arm.com * 1311527Sdavid.guillen@arm.com * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1411527Sdavid.guillen@arm.com * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1511527Sdavid.guillen@arm.com * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1611527Sdavid.guillen@arm.com * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1711527Sdavid.guillen@arm.com * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1811527Sdavid.guillen@arm.com * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1911527Sdavid.guillen@arm.com * THE SOFTWARE. 2011527Sdavid.guillen@arm.com */ 2111527Sdavid.guillen@arm.com 2211527Sdavid.guillen@arm.com#include "model/std_cells/StdCellLib.h" 2311527Sdavid.guillen@arm.com 2411527Sdavid.guillen@arm.com#include <cmath> 2511527Sdavid.guillen@arm.com 2611527Sdavid.guillen@arm.com#include "model/std_cells/StdCell.h" 2711527Sdavid.guillen@arm.com#include "model/std_cells/INV.h" 2811527Sdavid.guillen@arm.com#include "model/ModelGen.h" 2911527Sdavid.guillen@arm.com 3011527Sdavid.guillen@arm.comnamespace DSENT 3111527Sdavid.guillen@arm.com{ 3211527Sdavid.guillen@arm.com using std::pow; 3311527Sdavid.guillen@arm.com 3411527Sdavid.guillen@arm.com StdCellLib::StdCellLib(TechModel* tech_model_) 3511527Sdavid.guillen@arm.com : m_tech_model_(tech_model_) 3611527Sdavid.guillen@arm.com { 3711527Sdavid.guillen@arm.com m_std_cell_cache_ = new Map<double>(); 3811527Sdavid.guillen@arm.com ASSERT((m_tech_model_ != NULL), "[Error] StdCellLib -> tech_model is NULL"); 3911527Sdavid.guillen@arm.com createLib(); 4011527Sdavid.guillen@arm.com } 4111527Sdavid.guillen@arm.com 4211527Sdavid.guillen@arm.com StdCellLib::~StdCellLib() 4311527Sdavid.guillen@arm.com { 4411531Ssergei.trofimov@arm.com delete m_std_cell_cache_; 4511527Sdavid.guillen@arm.com } 4611527Sdavid.guillen@arm.com 4711527Sdavid.guillen@arm.com const TechModel* StdCellLib::getTechModel() const 4811527Sdavid.guillen@arm.com { 4911527Sdavid.guillen@arm.com return m_tech_model_; 5011527Sdavid.guillen@arm.com } 5111527Sdavid.guillen@arm.com 5211527Sdavid.guillen@arm.com StdCell* StdCellLib::createStdCell(const String& std_cell_name_, const String& instance_name_) const 5311527Sdavid.guillen@arm.com { 5411527Sdavid.guillen@arm.com // Create the standard cell 5511527Sdavid.guillen@arm.com StdCell* created_cell = ModelGen::createStdCell(std_cell_name_, instance_name_, getTechModel()); 5611527Sdavid.guillen@arm.com // Grab the variants of each standard cell 5711527Sdavid.guillen@arm.com String driving_strength_str = getTechModel()->get("StdCell->AvailableSizes"); 5811527Sdavid.guillen@arm.com // Set library properties for the standard cell 5911527Sdavid.guillen@arm.com created_cell->setPToNRatio(getPToNRatio()); 6011527Sdavid.guillen@arm.com created_cell->setActiveHeight(getActiveHeight()); 6111527Sdavid.guillen@arm.com created_cell->setTotalHeight(getTotalHeight()); 6211527Sdavid.guillen@arm.com created_cell->setAvailableDrivingStrengths(driving_strength_str); 6311527Sdavid.guillen@arm.com return created_cell; 6411527Sdavid.guillen@arm.com } 6511527Sdavid.guillen@arm.com 6611527Sdavid.guillen@arm.com // Get PMOS to NMOS ratio 6711527Sdavid.guillen@arm.com double StdCellLib::getPToNRatio() const 6811527Sdavid.guillen@arm.com { 6911527Sdavid.guillen@arm.com return m_p_to_n_ratio_; 7011527Sdavid.guillen@arm.com } 7111527Sdavid.guillen@arm.com 7211527Sdavid.guillen@arm.com void StdCellLib::setPToNRatio(double p_to_n_ratio_) 7311527Sdavid.guillen@arm.com { 7411527Sdavid.guillen@arm.com m_p_to_n_ratio_ = p_to_n_ratio_; 7511527Sdavid.guillen@arm.com } 7611527Sdavid.guillen@arm.com 7711527Sdavid.guillen@arm.com // Get height of the standard cell taken by active transistors 7811527Sdavid.guillen@arm.com double StdCellLib::getActiveHeight() const 7911527Sdavid.guillen@arm.com { 8011527Sdavid.guillen@arm.com return m_active_height_; 8111527Sdavid.guillen@arm.com } 8211527Sdavid.guillen@arm.com 8311527Sdavid.guillen@arm.com void StdCellLib::setActiveHeight(double active_height_) 8411527Sdavid.guillen@arm.com { 8511527Sdavid.guillen@arm.com m_active_height_ = active_height_; 8611527Sdavid.guillen@arm.com } 8711527Sdavid.guillen@arm.com 8811527Sdavid.guillen@arm.com // Get total height of the standard cell including overheads 8911527Sdavid.guillen@arm.com double StdCellLib::getTotalHeight() const 9011527Sdavid.guillen@arm.com { 9111527Sdavid.guillen@arm.com return m_total_height_; 9211527Sdavid.guillen@arm.com } 9311527Sdavid.guillen@arm.com 9411527Sdavid.guillen@arm.com void StdCellLib::setTotalHeight(double total_height_) 9511527Sdavid.guillen@arm.com { 9611527Sdavid.guillen@arm.com m_total_height_ = total_height_; 9711527Sdavid.guillen@arm.com } 9811527Sdavid.guillen@arm.com 9911527Sdavid.guillen@arm.com void StdCellLib::createLib() 10011527Sdavid.guillen@arm.com { 10111527Sdavid.guillen@arm.com Log::printLine("Standard cell library creation for tech model " + getTechModel()->get("Name")); 10211527Sdavid.guillen@arm.com 10311527Sdavid.guillen@arm.com // Get technology parameters 10411527Sdavid.guillen@arm.com double nmos_eff_res = getTechModel()->get("Nmos->EffResWidth"); 10511527Sdavid.guillen@arm.com double pmos_eff_res = getTechModel()->get("Pmos->EffResWidth"); 10611527Sdavid.guillen@arm.com double gate_min_width = getTechModel()->get("Gate->MinWidth"); 10711527Sdavid.guillen@arm.com 10811527Sdavid.guillen@arm.com // Create standard cell common parameters 10911527Sdavid.guillen@arm.com double pn_ratio = pmos_eff_res / nmos_eff_res; 11011527Sdavid.guillen@arm.com double nmos_unit_width = gate_min_width; 11111527Sdavid.guillen@arm.com double pmos_unit_width = gate_min_width * pn_ratio; 11211527Sdavid.guillen@arm.com 11311527Sdavid.guillen@arm.com // Derive the height of each cell in the standard cell library, as well as the max Nmos and Pmos widths 11411527Sdavid.guillen@arm.com double std_cell_total_height = getTechModel()->get("StdCell->Tracks").toDouble() * 11511527Sdavid.guillen@arm.com (getTechModel()->get("Wire->Metal1->MinWidth").toDouble() + getTechModel()->get("Wire->Metal1->MinSpacing").toDouble()); 11611527Sdavid.guillen@arm.com double std_cell_active_height = std_cell_total_height / getTechModel()->get("StdCell->HeightOverheadFactor").toDouble(); 11711527Sdavid.guillen@arm.com 11811527Sdavid.guillen@arm.com Log::printLine("Standard cell P-to-N ratio (Beta) = " + (String) pn_ratio); 11911527Sdavid.guillen@arm.com Log::printLine("Standard cell NMOS unit width = " + (String) nmos_unit_width); 12011527Sdavid.guillen@arm.com Log::printLine("Standard cell PMOS unit width = " + (String) pmos_unit_width); 12111527Sdavid.guillen@arm.com Log::printLine("Standard cell active height = " + (String) std_cell_active_height); 12211527Sdavid.guillen@arm.com Log::printLine("Standard cell total height = " + (String) std_cell_total_height); 12311527Sdavid.guillen@arm.com 12411527Sdavid.guillen@arm.com setPToNRatio(pn_ratio); 12511527Sdavid.guillen@arm.com setActiveHeight(std_cell_active_height); 12611527Sdavid.guillen@arm.com setTotalHeight(std_cell_total_height); 12711527Sdavid.guillen@arm.com 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 202