oagTimerUtil.h

Go to the documentation of this file.
00001 /************************************************************************
00002 * oagTimerUtil.h
00003 * Added functionalities to compute cell area, cell leakage power
00004 * and total leakage power of design
00005 * by: Santiago Mok <smok@ee.ucla.edu>
00006 * advised by: Prof. Puneet Gupta
00007 *
00008 **************************************************************************/
00009 #if !defined(oagTimerUtil_P)
00010 #define oagTimerUtil_P 
00011 
00012 #include <string>
00013 #include <vector>
00014 #include <iostream>
00015 #include <iomanip>
00016 #include <map>
00017 #include "oaDesignDB.h"
00018 #include "oagTimerModel.h"
00019 #include "oagTimerTimer.h"
00020 #include "oagTimerTPointMaster.h"
00021 #include "oagTimerLibParserInt.h"
00022 
00023 namespace oagTimer{
00024 /*---------------------------------------------------------*/
00025 
00026 using namespace oa;
00027 using namespace std;
00028 /*---------------------------------------------------------*/
00029 typedef enum {
00030     INPUT,
00031     OUTPUT
00032 } io_Type;
00033 /*---------------------------------------------------------*/
00034 typedef vector<oaModInst*> instVector;
00035 //typedef map<oaModInst*> Inst_Map;
00036 /*---------------------------------------------------------*/
00037 class Util{
00038   private:
00039       oaDesign *topDesign;
00040       Timer *timer;
00041   public:
00042     Util();
00043     ~Util();
00044 
00045     /* To Do: Change Util class to static*/
00046     void add(oaDesign *d, Timer* t){
00047         topDesign = d;
00048         timer = t;
00049     };
00050     double getCellArea(oaInst *inst);
00051     static void   getCellFootprint(oaString cellName, oaString & footprint);
00052     static double getCellLeakagePower(oaModInst *modInst);
00053     static double getCellLeakagePower(oaOccInst *occInst);
00054     static double getCellLeakagePower(oaInst *inst);
00055     static double getCellLeakagePower(oaModule *m);
00056     static double getCellLeakagePower(const char *s);
00057     static double getCellLeakagePower(oaString cellName);
00058     static double getTotalLeakPower(const oaDesign *design);
00059 
00060     static double getPowerSensitivity(const char *curr, const char *other);
00061     
00062     static double getCellInputCap(oaOccInstTerm *i, oaString s, Timer *timer);
00063     oaString getCellName(oaModInst *i);
00064     oaString getCellName(oaOccInst *i);
00065 
00066     oaOccInstTerm* findOccInTerms(oaDesign *design, oaModScalarInst *m);
00067     oaOccInstTerm* findOccOutTerm(oaDesign *design, oaModScalarInst *m);
00068 
00069     oaModInstTerm* getOutInstTerm(oaModNet *net);
00070 
00071     /* Query for the arrival time constraints at 
00072      * output of the given occInst*
00073      */
00074     TimeType getIOArr(oaModInst* i, oaDesign* design, Timer* timing, io_Type io);
00075     TimeType getIOArr(oaOccInst* i, oaDesign* design, Timer* timing, io_Type io);
00076 
00077     DelayType getIOSlack(oaModInst* i, oaDesign* design, Timer* timing, io_Type io);
00078     void updateFanIOTiming(oaDesign* design,Timer* t,oaModInst *m);
00079     void invalidateFanIOTiming(oaDesign* design,Timer* t,oaModInst *m);
00080     
00081     vector<oaModInst*> getOtherFanin(oaModInst* currFanin, oaModInst* currCell);
00082     /* Query for other available cell sizes in the *.lib library;
00083      * list must contain the current *.lib cell name when called
00084      * getMatchCells and the query will return the available sizes 
00085      * in the list vector
00086      * @param vector<oaString>: contains the queried sizes
00087      * @param sizes: 1 upsize only
00088      *              2 downsize only
00089      *              0 all sizes
00090      */
00091     void getMatchCells(vector<oaString> &list, int sizes);
00092     bool isGreaterThan(oaString current, oaString other);
00093     bool isLessThan(oaString current, oaString other);
00094 
00095     int swapCell(oaString cellName,oaModInst* currModInst);
00096 
00098 /*---------------------------------------------------------*/
00108 static double getCellDelayEstimate(oaOccInstTerm *inpTerm, 
00109                             oaString otherSize,
00110                             double load,
00111                             Timer* timer);
00112 /*---------------------------------------------------------*/
00119 //static DelayType getCellDelay(Timer* t, oaOccInstTerm* inPin);
00120 static DelayType getCellRiseDelay(oaOccInstTerm *inPin);
00121 static DelayType getCellFallDelay(oaOccInstTerm *inPin);
00122 static DelayType getCellDelay(oaOccInstTerm *inPin);
00123 /*static DelayType getCellDelay(Timer *timer, 
00124         oaOccInstTerm *inPin, oaOccInstTerm *outPin);*/
00125 /*---------------------------------------------------------*/
00133 //static DelayType getCellDelay(Timer* t, oaOccInstTerm* inPin);
00134 /*static DelayType getCellDelay(Timer *timer, 
00135         oaOccInstTerm *inPin, oaOccInstTerm *outPin);
00136 */
00137 /*---------------------------------------------------------*/
00147 static DelayType getDeltaDelay(oaDesign* design, Timer* timing, 
00148             CellData *c, oaString newSize);
00149 /*---------------------------------------------------------*/
00158 static DelayType getDeltaDelay(oaOccObject *block, 
00159         TPointMaster *otherTM, Timer* timer);
00160 /*---------------------------------------------------------*/
00169 static double getUpSizeDeltaDelay(oaDesign* design, Timer* timing, CellData *c);
00170 /*---------------------------------------------------------*/
00177 static DelayType getWorstInputSlack(Timer* t, oaOccInst* inst);
00178 /*---------------------------------------------------------*/
00187 static double getDownSizeDeltaDelay(oaDesign* design, Timer* timing, CellData *c);
00188 /*---------------------------------------------------------*/
00193 static bool hasValidArrTime(Timer* timer, CellData *cell);
00198 static double getMaxNetDelay(oaOccInstTerm* t);
00199 /*---------------------------------------------------------*/
00200 static oaString getInstName(oaModInst *i){
00201     oaNativeNS NS;
00202     oaString name;
00203     i->getName(NS,name);
00204     return name;
00205 }
00206 static oaString getInstName(oaOccInst *i){
00207     oaNativeNS NS;
00208     oaString name;
00209     i->getName(NS,name);
00210     return name;
00211 }
00212 /*---------------------------------------------------------*/
00213 static void parseLibCellName(oaString &name, oaString &basename, double &size){
00214     if(libParseData.libType.compare("footprint") == 0){
00215         Util::parseFootprintLibCellName(name,basename,size);
00216     }else if(libParseData.libType.compare("nangate") == 0
00217             || libParseData.libType.compare("eyechart") == 0){
00218         Util::parseNangateLibCellName(name,basename,size);
00219     }else if(libParseData.libType.compare("st") == 0){
00220         Util::parseSTLibCellName(name,basename,size);
00221     }else if(libParseData.libType.compare("st_vt") == 0){ 
00222         Util::parseVtSTLibCellName(name,basename,size);
00223     }
00224 }
00225 /*---------------------------------------------------------*/
00226 static void parseVtSTLibCellName(oaString name, oaString &basename, double &size){
00227     size_t index1, index2;
00228     string curr = static_cast<string>(name);
00229     index1 = curr.find_first_of("_");
00230     index2 = curr.find_last_of("_");
00231     /*std::cout << "VtType:" << curr.substr(index1+1,2)
00232         << " Name:" << curr.substr(index2+1) << std::endl;*/
00233     string currBase = curr.substr(index2+1);
00234     string currVt = curr.substr(index1+1,2);
00235     basename = currBase.c_str();
00236     if(currVt == "LH") size = 1;
00237     else if(currVt == "LS") size = 2;
00238     else if(currVt == "LL") size = 3;
00239     /*std::cout << " " << name << " -> " << basename
00240         << " + " << currVt << " " << size << std::endl;*/
00241 }
00242 /*---------------------------------------------------------*/
00243 static void parseSTLibCellName(oaString name, oaString &basename, double &size){
00244     size_t name_index, size_index;
00245     string curr = static_cast<string>(name);
00246     name_index = curr.find_last_of("X");
00247     //if((partition_index) == string::npos){}
00248     /*std::cout << "name:" << curr.substr(0,name_index)
00249         << " size:" << curr.substr(name_index+2) << std::endl;*/
00250     string currBase = curr.substr(0,name_index);
00251     string currSize = curr.substr(name_index+1);
00252     basename = currBase.c_str();
00253     size = atoi(currSize.c_str());
00254     /*std::cout << " " << name << " -> " << basename
00255         << " + " << size << std::endl;*/
00256 }
00257 
00258 /*---------------------------------------------------------*/
00259 static void parseNangateLibCellName(oaString name, oaString &basename, double &size){
00260     size_t name_index, size_index;
00261     string curr = static_cast<string>(name);
00262     std::cout<<"String Name "<<curr<<'\t';
00263     name_index = curr.find_first_of("_");
00264     size_index = curr.find_last_of("_");
00265     if((name_index && size_index) == string::npos){
00266         name_index = curr.find_first_of("X");
00267         size_index = curr.find_last_of("X");
00268         //std::cout << "name:" << curr.substr(0,name_index)
00269           //  << " size:" << curr.substr(size_index+2) << std::endl;
00270     }
00271    
00272   //      std::cout<<"name index"<<name_index<<endl;
00273     string currBase = curr.substr(0,name_index);
00274     string currSize = curr.substr(size_index+2);
00275     basename = currBase.c_str();
00276     size = atoi(currSize.c_str());
00277 //std::cout<<"Base Name "<<basename<<endl;
00278 //std::cout<<"size "<<size<<endl;
00279 //std::cout<<"leakage" << getCellLeakagePower(name) << endl;
00280 }
00281 /*---------------------------------------------------------*/
00282 static void parseFootprintLibCellName(oaString name, oaString &basename, double &size){
00283     size_t name_index, size_index;
00284     string curr = static_cast<string>(name);
00285     //std::cout<<"String Name "<< curr <<'\t';
00286     
00287     
00288     getCellFootprint(name, basename);
00289     size = 0;
00290     
00291     size = getCellLeakagePower(name);
00292     
00293     //std::cout<<"Name  "<< name  << " / " << basename<<'\t'<<"size  "<<size<<endl;
00294     //std::cout<<"leakage" << getCellLeakagePower(name) << endl;
00295 
00296 }
00297 /*---------------------------------------------------------*/
00298 /* Get combinations of size k given the cell instances.
00299  * @param insts: vector of ModInst
00300  * @param k: size of each combination
00301  * @return vector of all the combinations
00302  */
00303 static vector<instVector> 
00304 getCombinations(instVector insts, int k){
00305     vector<instVector> temp_vec;
00306     if(insts.size() <= k){
00307         temp_vec.push_back(insts);
00308         return temp_vec;
00309     }
00310     if(!temp_vec.empty()) temp_vec.empty();
00311     instVector c;
00312     genComb(insts,k,temp_vec,c);
00313     return temp_vec;
00314 }
00315 
00316 /* Recursively generate the combinations in the list L
00317  * and store them in the table T
00318  * @param L: list instances
00319  * @param k: size of combination
00320  * @param T: table storing each combination
00321  * @param C: temporary combination list during each recursion
00322  * @return void
00323  */
00324 static void genComb(instVector L, int k, vector<instVector> &T, instVector &C){
00325     if(k == 1){
00326         for(instVector::iterator it=L.begin(); it!=L.end(); ++it){
00327             C.push_back(*it);
00328             T.push_back(C);
00329             C.pop_back();
00330         }
00331         return;
00332     }
00333     instVector::iterator iter = L.begin();
00334     instVector temp_list = L;
00335     for(int i=0; i<=(L.size()-k); ++i){
00336         C.push_back(*iter);
00337         temp_list.erase(temp_list.begin());
00338         genComb(temp_list,k-1,T,C);
00339         C.pop_back();
00340         ++iter;
00341     }
00342 }
00343 
00344 static void Util::downSizeAll(oaDesign *design, Timer *timer);
00345 static void Util::changeToMinCellSize(oaDesign *design, Timer *timer);
00346 /*---------------------------------------------------------*/
00347 /* Report gates count statistic for the given design
00348  * @param oaDesign*
00349  * @return void
00350  */
00351 static void reportSlacks(oaDesign* design,Timer *timer);
00352 static void reportGates(oaDesign* design);
00353 /* Debug timing information (r/f arrival, cell delay, 
00354  * wire delay) for each timing arc
00355  */
00356 static void reportTimingInfo(oaDesign* design, Timer *t);
00357 static void reportCellTiming(CellData *cell, Timer *t);
00358 static void reportAllCellTiming(oaDesign *design, Timer *t);
00359 static void reportTimingFlag(oaDesign *des);
00365 static void printAllNetData(oaDesign *design);
00366 /*---------------------------------------------------------*/
00372 static std::string getBlockName(oaOccObject *oPtr);
00373 /*---------------------------------------------------------*/
00374 
00383 static void linear_fit(double &a,double &b, double *x, double *y, int N);
00384 /*---------------------------------------------------------*/
00385 };
00386 /*---------------------------------------------------------*/
00387 }
00388 #endif

Generated on Thu Aug 25 14:24:05 2011 by  doxygen 1.3.9.1