StdCellLib.cc revision 10447:a465576671d4
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 181