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 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 202