1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (c) 2019, Nefelus Inc
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright notice, this
11 //   list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright notice,
14 //   this list of conditions and the following disclaimer in the documentation
15 //   and/or other materials provided with the distribution.
16 //
17 // * Neither the name of the copyright holder nor the names of its
18 //   contributors may be used to endorse or promote products derived from
19 //   this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 
33 #ifndef ADS_EXTRCAP_H
34 #define ADS_EXTRCAP_H
35 
36 #include <darr.h>
37 #include <dbExtControl.h>
38 #include <dbShape.h>
39 #include <dbUtil.h>
40 #include <gseq.h>
41 #include <util.h>
42 
43 #include "ISdb.h"
44 #include "ZObject.h"
45 #include "db.h"
46 #include "wire.h"
47 #include "extprocess.h"
48 #include "gseq.h"
49 #include "odb.h"
50 
51 #ifndef _WIN32
52 #define D2I_ROUND (name) rint(name)
53 #else
54 #define D2I_ROUND (name) name
55 #endif
56 
57 //#define NEW_GS_FLOW
58 
59 #define HI_ACC_1
60 #ifdef HI_ACC_1
61 #define HI_ACC_2
62 #define DAVID_ACC_08_02
63 #define GS_CROSS_LINES_ONLY 1
64 #define BUG_LAYER_CNT 1
65 #endif
66 
67 #include <map>
68 
69 namespace utl {
70 class Logger;
71 }
72 
73 namespace rcx {
74 
75 class extMeasure;
76 
77 using utl::Logger;
78 
79 class extMetBox  // assume cross-section on the z-direction
80 {
81   int _bot[3];
82   int _top[3];
83   uint _botDX;
84   uint _topDX;
85 };
86 
87 class ext2dBox  // assume cross-section on the z-direction
88 {
89   int _ll[2];
90   int _ur[2];
91   uint _met;
92   uint _dir;
93   uint _id;
94   uint _map;
95 
96   void rotate();
97   bool matchCoords(int* ll, int* ur);
98   void printGeoms3D(FILE* fp, double h, double t, int* orig);
99   uint length();
100   uint width();
101   int loX();
102   int loY();
103   uint id();
104 
105   friend class extMeasure;
106   friend class extRCModel;
107 };
108 class extGeoVarTable
109 {
110   int _x;
111   int _y;
112   double _nominal;
113   double _epsilon;
114   char* _layerName;
115   Ath__array1D<double>* _diffTable;
116   Ath__array1D<double>* _varCoeffTable;
117   bool _fractionDiff;
118   bool _simpleVersion;
119 
120  public:
121   extGeoVarTable(int x,
122                  int y,
123                  double nom,
124                  double e,
125                  Ath__array1D<double>* A,
126                  bool simpleVersion,
127                  bool calcDiff);
128   ~extGeoVarTable();
129   double getVal(uint n, double& nom);
130   int getLowerBound(uint dir);
131   bool getThicknessDiff(int n, double& delta_th);
132 };
133 
134 class extGeoThickTable
135 {
136   char* _layerName;
137   Ath__array1D<uint>* _widthTable;
138   uint _rowCnt;
139   uint _colCnt;
140   uint _tileSize;
141   int _ll[2];
142   int _ur[2];
143 
144   extGeoVarTable*** _thickTable;
145 
146  public:
147   extGeoThickTable(int x1,
148                    int y1,
149                    int x2,
150                    int y2,
151                    uint tileSize,
152                    Ath__array1D<double>* A,
153                    uint units);
154   ~extGeoThickTable();
155   extGeoVarTable* addVarTable(int x,
156                               int y,
157                               double nom,
158                               double e,
159                               Ath__array1D<double>* A,
160                               bool simpleVersion,
161                               bool calcDiff);
162   bool getThicknessDiff(int x, int y, uint w, double& delta_th);
163   extGeoVarTable* getSquare(int x, int y, uint* rowCol);
164   int getLowerBound(uint dir, uint* rowCol);
165   int getUpperBound(uint dir, uint* rowCol);
166   int getRowCol(int xy, int base, uint bucket, uint bound);
167 };
168 
169 class extSpef;
170 
171 class extDistRC
172 {
173  private:
174   // double _dist;
175   int _sep;
176   double _coupling;
177   double _fringe;
178   double _diag;
179   double _res;
180 
181  protected:
182   Logger* logger_;
183 
184  public:
setLogger(Logger * logger)185   void setLogger(Logger* logger) { logger_ = logger; }
186   void printDebug(const char*,
187                   const char*,
188                   uint,
189                   uint,
190                   extDistRC* rcUnit = NULL);
191   void printDebugRC_values(const char* msg);
192   void printDebugRC(const char*, Logger* logger);
193   void printDebugRC(int met,
194                     int overMet,
195                     int underMet,
196                     int width,
197                     int dist,
198                     int len,
199                     Logger* logger);
200   void printDebugRC_sum(int len, int dbUnit, Logger* logger);
201   void printDebugRC_diag(int met,
202                          int overMet,
203                          int underMet,
204                          int width,
205                          int dist,
206                          int dbUnit,
207                          Logger* logger);
208   double GetDBcoords(int x, int db_factor);
209   void debugRC(const char* debugWord, const char* from, int width, int level);
210   void set(uint d, double cc, double fr, double a, double r);
211   void readRC(Ath__parser* parser, double dbFactor = 1.0);
212   void readRC_res2(Ath__parser* parser, double dbFactor = 1.0);
213   double getFringe();
214   double getCoupling();
215   double getDiag();
216   double getRes();
getTotalCap()217   double getTotalCap() { return _coupling + _fringe + _diag; };
218   void addRC(extDistRC* rcUnit, uint len, bool addCC);
219   void writeRC(FILE* fp, bool bin);
220   void writeRC();
221   void interpolate(uint d, extDistRC* rc1, extDistRC* rc2);
222   double interpolate_res(uint d, extDistRC* rc2);
223 
224   friend class extDistRCTable;
225   friend class extDistWidthRCTable;
226   friend class extMeasure;
227   friend class extMain;
228 };
229 class extDistRCTable
230 {
231  private:
232   // Ath__array1D<double> *_distTable;
233   // Ath__array1D<uint> *_distMapTable;
234 
235   Ath__array1D<extDistRC*>* _measureTable;
236   Ath__array1D<extDistRC*>* _computeTable;
237   Ath__array1D<extDistRC*>* _measureTableR[16];
238   Ath__array1D<extDistRC*>* _computeTableR[16];  // OPTIMIZE
239   int _maxDist;
240   uint _distCnt;
241   uint _unit;
242 
243   void makeCapTableOver();
244   void makeCapTableUnder();
245 
246  protected:
247   Logger* logger_;
248 
249  public:
250   extDistRCTable(uint distCnt);
251   ~extDistRCTable();
252 
253   extDistRC* getRC_99();
254   void ScaleRes(double SUB_MULT_RES, Ath__array1D<extDistRC*>* table);
255   extDistRC* findRes(int dist1, int dist2, bool compute);
256 
257   uint addMeasureRC(extDistRC* rc);
258   void makeComputeTable(uint maxDist, uint distUnit);
259   extDistRC* getLastRC();
260   extDistRC* getRC_index(int n);
261   extDistRC* getComputeRC(double dist);
262   extDistRC* getComputeRC(uint dist);
263   extDistRC* getRC(uint s, bool compute);
264   extDistRC* getComputeRC_res(uint dist1, uint dist2);
265   extDistRC* findIndexed_res(uint dist1, uint dist2);
266   int getComputeRC_maxDist();
267   uint writeRules(FILE* fp,
268                   Ath__array1D<extDistRC*>* table,
269                   double w,
270                   bool bin);
271   uint writeRules(FILE* fp, double w, bool compute, bool bin);
272   uint writeDiagRules(FILE* fp,
273                       Ath__array1D<extDistRC*>* table,
274                       double w1,
275                       double w2,
276                       double s,
277                       bool bin);
278   uint writeDiagRules(FILE* fp,
279                       double w1,
280                       double w2,
281                       double s,
282                       bool compute,
283                       bool bin);
284   uint readRules(Ath__parser* parser,
285                  AthPool<extDistRC>* rcPool,
286                  bool compute,
287                  bool bin,
288                  bool ignore,
289                  double dbFactor = 1.0);
290   uint readRules_res2(Ath__parser* parser,
291                       AthPool<extDistRC>* rcPool,
292                       bool compute,
293                       bool bin,
294                       bool ignore,
295                       double dbFactor = 1.0);
296   uint interpolate(uint distUnit, int maxDist, AthPool<extDistRC>* rcPool);
297   uint mapInterpolate(extDistRC* rc1,
298                       extDistRC* rc2,
299                       uint distUnit,
300                       int maxDist,
301                       AthPool<extDistRC>* rcPool);
302   uint mapExtrapolate(uint loDist,
303                       extDistRC* rc2,
304                       uint distUnit,
305                       AthPool<extDistRC>* rcPool);
306 
307   void getFringeTable(Ath__array1D<int>* sTable,
308                       Ath__array1D<double>* rcTable,
309                       bool compute);
310 };
311 extDistRC* findRes(Ath__array1D<extDistRC*>* sTable,
312                    int dist1,
313                    int dist2,
314                    bool compute);
315 
316 class extDistWidthRCTable
317 {
318  public:
319   bool _ouReadReverse;
320   bool _over;
321   uint _layerCnt;
322   uint _met;
323 
324   Ath__array1D<int>* _widthTable;
325   Ath__array1D<uint>* _widthMapTable;
326   Ath__array1D<int>* _diagWidthTable[32];
327   Ath__array1D<int>* _diagDistTable[32];
328   Ath__array1D<uint>* _diagWidthMapTable[32];
329   Ath__array1D<uint>* _diagDistMapTable[32];
330 
331   uint _modulo;
332   int _firstWidth = 0;
333   int _lastWidth = -1;
334   Ath__array1D<int>* _firstDiagWidth;
335   Ath__array1D<int>* _lastDiagWidth;
336   Ath__array1D<int>* _firstDiagDist;
337   Ath__array1D<int>* _lastDiagDist;
338   bool _widthTableAllocFlag;  // if false widthtable is pointer
339 
340   extDistRCTable*** _rcDistTable;  // per over/under metal, per width
341   extDistRCTable***** _rcDiagDistTable;
342   uint _metCnt;  // if _over==false _metCnt???
343 
344   AthPool<extDistRC>* _rcPoolPtr;
345   extDistRC* _rc31;
346 
347  public:
348   extDistWidthRCTable(bool dummy,
349                       uint met,
350                       uint layerCnt,
351                       uint width);
352   extDistWidthRCTable(bool over,
353                       uint met,
354                       uint layerCnt,
355                       uint metCnt,
356                       Ath__array1D<double>* widthTable,
357                       AthPool<extDistRC>* rcPool,
358                       double dbFactor = 1.0);
359   extDistWidthRCTable(bool over,
360                       uint met,
361                       uint layerCnt,
362                       uint metCnt,
363                       Ath__array1D<double>* widthTable,
364                       int diagWidthCnt,
365                       int diagDistCnt,
366                       AthPool<extDistRC>* rcPool,
367                       double dbFactor = 1.0);
368   extDistWidthRCTable(bool over,
369                       uint met,
370                       uint layerCnt,
371                       uint metCnt,
372                       uint maxWidthCnt,
373                       AthPool<extDistRC>* rcPool);
374   void addRCw(uint n, uint w, extDistRC* rc);
375   void createWidthMap();
376   void makeWSmapping();
377 
378   ~extDistWidthRCTable();
379   void setDiagUnderTables(uint met,
380                           Ath__array1D<double>* diagWidthTable,
381                           Ath__array1D<double>* diagDistTable,
382                           double dbFactor = 1.0);
383   uint getWidthIndex(uint w);
384   uint getDiagWidthIndex(uint m, uint w);
385   uint getDiagDistIndex(uint m, uint s);
386   uint addCapOver(uint met, uint metUnder, extDistRC* rc);
387   extDistRC* getCapOver(uint met, uint metUnder);
388   uint writeWidthTable(FILE* fp, bool bin);
389   uint writeDiagWidthTable(FILE* fp, uint met, bool bin);
390   uint writeDiagDistTable(FILE* fp, uint met, bool bin);
391   void writeDiagTablesCnt(FILE* fp, uint met, bool bin);
392   uint writeRulesOver(FILE* fp, bool bin);
393   uint writeRulesOver_res(FILE* fp, bool bin);
394   uint writeRulesUnder(FILE* fp, bool bin);
395   uint writeRulesDiagUnder(FILE* fp, bool bin);
396   uint writeRulesDiagUnder2(FILE* fp, bool bin);
397   uint writeRulesOverUnder(FILE* fp, bool bin);
398   uint getMetIndexUnder(uint mOver);
399   uint readRulesOver(Ath__parser* parser,
400                      uint widthCnt,
401                      bool bin,
402                      bool ignore,
403                      const char* OVER,
404                      double dbFactor = 1.0);
405   uint readRulesUnder(Ath__parser* parser,
406                       uint widthCnt,
407                       bool bin,
408                       bool ignore,
409                       double dbFactor = 1.0);
410   uint readRulesDiagUnder(Ath__parser* parser,
411                           uint widthCnt,
412                           uint diagWidthCnt,
413                           uint diagDistCnt,
414                           bool bin,
415                           bool ignore,
416                           double dbFactor = 1.0);
417   uint readRulesDiagUnder(Ath__parser* parser,
418                           uint widthCnt,
419                           bool bin,
420                           bool ignore,
421                           double dbFactor = 1.0);
422   uint readRulesOverUnder(Ath__parser* parser,
423                           uint widthCnt,
424                           bool bin,
425                           bool ignore,
426                           double dbFactor = 1.0);
427   uint readMetalHeader(Ath__parser* parser,
428                        uint& met,
429                        const char* keyword,
430                        bool bin,
431                        bool ignore);
432 
433   // extDistRC* getRC(uint mou, double w, double s);
434   extDistRC* getRes(uint mou, uint w, int dist1, int dist2);
435   extDistRC* getRC(uint mou, uint w, uint s);
436   extDistRC* getRC(uint mou, uint w, uint dw, uint ds, uint s);
437   extDistRC* getFringeRC(uint mou, uint w, int index_dist = -1);
438   void getFringeTable(uint mou,
439                       uint w,
440                       Ath__array1D<int>* sTable,
441                       Ath__array1D<double>* rcTable,
442                       bool map);
443 
444   extDistRC* getLastWidthFringeRC(uint mou);
445   extDistRC* getRC_99(uint mou, uint w, uint dw, uint ds);
446   extDistRCTable* getRuleTable(uint mou, uint w);
447 };
448 class extMetRCTable
449 {
450  public:
451   uint _layerCnt;
452   char _name[128];
453   extDistWidthRCTable** _resOver;
454   extDistWidthRCTable** _capOver;
455   extDistWidthRCTable** _capUnder;
456   extDistWidthRCTable** _capOverUnder;
457   extDistWidthRCTable** _capDiagUnder;
458 
459   AthPool<extDistRC>* _rcPoolPtr;
460   double _rate;
461   Logger* logger_;
462 
463  public:
464   extMetRCTable(uint layerCnt, AthPool<extDistRC>* rcPool, Logger* logger_);
465   ~extMetRCTable();
466   void allocateInitialTables(uint layerCnt,
467                              uint widthCnt,
468                              bool over,
469                              bool under,
470                              bool diag = false);
471   void allocOverTable(uint met,
472                       Ath__array1D<double>* wTable,
473                       double dbFactor = 1.0);
474   void allocDiagUnderTable(uint met,
475                            Ath__array1D<double>* wTable,
476                            int diagWidthCnt,
477                            int diagDistCnt,
478                            double dbFactor = 1.0);
479   void allocDiagUnderTable(uint met,
480                            Ath__array1D<double>* wTable,
481                            double dbFactor = 1.0);
482   void allocUnderTable(uint met,
483                        Ath__array1D<double>* wTable,
484                        double dbFactor = 1.0);
485   void allocOverUnderTable(uint met,
486                            Ath__array1D<double>* wTable,
487                            double dbFactor = 1.0);
488   void setDiagUnderTables(uint met,
489                           uint overMet,
490                           Ath__array1D<double>* diagWTable,
491                           Ath__array1D<double>* diagSTable,
492                           double dbFactor = 1.0);
493   void addRCw(extMeasure* m);
494   uint readRCstats(Ath__parser* parser);
495   void mkWidthAndSpaceMappings();
496 
497   uint addCapOver(uint met, uint metUnder, extDistRC* rc);
498   uint addCapUnder(uint met, uint metOver, extDistRC* rc);
499   extDistRC* getCapOver(uint met, uint metUnder);
500   extDistRC* getCapUnder(uint met, uint metOver);
501   extDistRC* getOverFringeRC(extMeasure* m, int index_dist = -1);
502   extDistRC* getOverFringeRC_last(int met, int width);
503   AthPool<extDistRC>* getRCPool();
504 };
505 class extRCTable
506 {
507  private:
508   bool _over;
509   uint _maxCnt1;
510   Ath__array1D<extDistRC*>*** _inTable;  // per metal per width
511   Ath__array1D<extDistRC*>*** _table;
512 
513   void makeCapTableOver();
514   void makeCapTableUnder();
515 
516  public:
517   extRCTable(bool over, uint layerCnt);
518   uint addCapOver(uint met, uint metUnder, extDistRC* rc);
519   extDistRC* getCapOver(uint met, uint metUnder);
520 };
521 
522 class extMain;
523 class extMeasure;
524 class extMainOptions;
525 
526 class extRCModel
527 {
528  private:
529   bool _ouReadReverse;
530   uint _layerCnt;
531   char _name[128];
532 
533   int _noVariationIndex;
534   uint _modelCnt;
535   Ath__array1D<double>* _dataRateTable;
536   Ath__array1D<int>* _dataRateTableMap;
537   extMetRCTable** _modelTable;
538   uint _tmpDataRate;
539   bool _diag;
540   bool _verticalDiag;
541   bool _maxMinFlag;
542   uint _diagModel;
543   bool _keepFile;
544   uint _metLevel;
545 
546   extRCTable* _resOver;
547   extRCTable* _capOver;
548   extRCTable* _capDiagUnder;
549   extRCTable* _capUnder;
550   AthPool<extDistRC>* _rcPoolPtr;
551   extProcess* _process;
552   char* _ruleFileName;
553   char* _wireFileName;
554   char* _wireDirName;
555   char* _topDir;
556   char* _patternName;
557   Ath__parser* _parser;
558   char* _solverFileName;
559 
560   FILE* _capLogFP;
561   FILE* _logFP;
562 
563   bool _writeFiles;
564   bool _readSolver;
565   bool _runSolver;
566 
567   bool _readCapLog;
568   char _commentLine[10000];
569   bool _commentFlag;
570 
571   uint* _singlePlaneLayerMap;
572   uint** _overUnderPlaneLayerMap;
573 
574   extMain* _extMain;
575 
576  protected:
577   Logger* logger_;
578 
579  public:
getMetRCTable(uint ii)580   extMetRCTable* getMetRCTable(uint ii) { return _modelTable[ii]; };
581 
getModelCnt()582   int getModelCnt() { return _modelCnt; };
getLayerCnt()583   int getLayerCnt() { return _layerCnt; };
setLayerCnt(uint n)584   void setLayerCnt(uint n) { _layerCnt = n; };
getDiagModel()585   int getDiagModel() { return _diagModel; };
getVerticalDiagFlag()586   bool getVerticalDiagFlag() { return _verticalDiag; };
setDiagModel(uint i)587   void setDiagModel(uint i) { _diagModel = i; }
588   extRCModel(uint layerCnt, const char* name, Logger* logger);
589   extRCModel(const char* name, Logger* logger);
590   extProcess* getProcess();
591   uint findBiggestDatarateIndex(double d);
592   int findVariationZero(double d);
593   int findClosestDataRate(uint n, double diff);
594   ~extRCModel();
595   void setExtMain(extMain* x);
596   void createModelTable(uint n, uint layerCnt);
597 
598   uint addLefTotRC(uint met, uint underMet, double fr, double r);
599   uint addCapOver(uint met,
600                   uint underMet,
601                   uint d,
602                   double cc,
603                   double fr,
604                   double a,
605                   double r);
606   double getTotCapOverSub(uint met);
607   double getRes(uint met);
608 
609   uint benchWithVar_density(extMainOptions* opt, extMeasure* measure);
610   uint benchWithVar_lists(extMainOptions* opt, extMeasure* measure);
611 
612   uint readCapacitanceBench3D(bool readCapLog,
613                               extMeasure* m,
614                               bool skipPrintWires);
615   bool measureNetPattern(extMeasure* m,
616                          uint shapeId,
617                          Ath__array1D<ext2dBox*>* boxArray);
618   uint writePatternGeoms(extMeasure* m, Ath__array1D<ext2dBox*>* boxArray);
619   bool makePatternNet3D(extMeasure* measure, Ath__array1D<ext2dBox*>* boxArray);
620   uint netWiresBench(extMainOptions* opt,
621                      extMain* xMain,
622                      uint netId,
623                      odb::ZPtr<odb::ISdb> netSearch);
624   uint runWiresSolver(uint netId, int shapeId);
625   uint getNetCapMatrixValues3D(uint nodeCnt, uint shapeId, extMeasure* m);
626 
627   void setProcess(extProcess* p);
628   void setDataRateTable(uint met);
629   uint singleLineOver(uint widthCnt);
630   uint twoLineOver(uint widthCnt, uint spaceCnt);
631   uint threeLineOver(uint widthCnt, uint spaceCnt);
632   uint getCapValues(uint lastNode,
633                     double& cc1,
634                     double& cc2,
635                     double& fr,
636                     double& tot,
637                     extMeasure* m);
638   uint getCapValues3D(uint lastNode,
639                       double& cc1,
640                       double& cc2,
641                       double& fr,
642                       double& tot,
643                       extMeasure* m);
644   uint getCapMatrixValues(uint lastNode, extMeasure* m);
645   uint getCapMatrixValues3D(uint lastNode, extMeasure* m);
646   uint readCapacitance(uint wireNum,
647                        double& cc1,
648                        double& cc2,
649                        double& fr,
650                        double& tot,
651                        bool readCapLog,
652                        extMeasure* m = NULL);
653   uint readCapacitanceBench(bool readCapLog, extMeasure* m);
654   uint readCapacitanceBenchDiag(bool readCapLog, extMeasure* m);
655   uint readCapacitanceBench3D(bool readCapLog, extMeasure* m);
656   extDistRC* readCap(uint wireCnt, double w, double s, double r);
657   uint readCap(uint wireCnt, double cc1, double cc2, double fr, double tot);
658   FILE* openFile(const char* topDir,
659                  const char* name,
660                  const char* suffix,
661                  const char* permissions);
662   FILE* openSolverFile();
663   void mkNet_prefix(extMeasure* m, const char* wiresNameSuffix);
664   void mkFileNames(extMeasure* m, char* wiresNameSuffix);
665   void writeWires(FILE* fp,
666                   extMasterConductor* m,
667                   uint wireCnt,
668                   double X,
669                   double w,
670                   double s);
671   void writeWires(FILE* fp, extMeasure* measure, uint wireCnt);
672   void writeWires2(FILE* fp, extMeasure* measure, uint wireCnt);
673   void writeRuleWires(FILE* fp, extMeasure* measure, uint wireCnt);
674   void writeWires2_3D(FILE* fp, extMeasure* measure, uint wireCnt);
675   void writeRuleWires_3D(FILE* fp, extMeasure* measure, uint wireCnt);
676   int writeBenchWires(FILE* fp, extMeasure* measure);
677   void writeRaphaelCaps(FILE* fp, extMeasure* measure, uint wireCnt);
678   void writeRaphaelCaps3D(FILE* fp, extMeasure* measure, uint wireCnt);
679   void setOptions(const char* topDir,
680                   const char* pattern,
681                   bool writeFiles,
682                   bool readSolver,
683                   bool runSolver);
684   void setOptions(const char* topDir,
685                   const char* pattern,
686                   bool writeFiles,
687                   bool readSolver,
688                   bool runSolver,
689                   bool keepFile,
690                   uint metLevel = 0);
691   void runSolver(const char* solverOption);
692   bool solverStep(extMeasure* m);
693   void cleanFiles();
694 
695   extDistRC* measurePattern(uint met,
696                             int underMet,
697                             int overMet,
698                             double width,
699                             double space,
700                             uint wireCnt,
701                             char* ou,
702                             bool readCapLog);
703   bool measurePatternVar(extMeasure* m,
704                          double top_width,
705                          double bot_width,
706                          double thickness,
707                          uint wireCnt,
708                          char* wiresNameSuffix,
709                          double res = 0.0);
710   uint measureDiagWithVar(extMeasure* measure);
711   double measureResistance(extMeasure* m,
712                            double ro,
713                            double top_widthR,
714                            double bot_widthR,
715                            double thicknessR);
716 
717   uint linesOverBench(extMainOptions* opt);
718   uint linesUnderBench(extMainOptions* opt);
719   uint linesDiagUnderBench(extMainOptions* opt);
720   uint linesOverUnderBench(extMainOptions* opt);
721 
722   uint benchWithVar(extMeasure* measure);
723   uint measureWithVar(extMeasure* m);
724   void addRC(extMeasure* m);
725   int getOverUnderIndex(extMeasure* m, uint maxCnt);
726   uint getUnderIndex(extMeasure* m);
727   extDistWidthRCTable* getWidthDistRCtable(uint met,
728                                            int mUnder,
729                                            int mOver,
730                                            int& n,
731                                            double dRate);
732 
733   // void printCommentLine(char commentChar, double w, double width, double s,
734   // double spacing, double h, double height, double t, double thickeness);
735   void printCommentLine(char commentChar, extMeasure* m);
736 
737   uint linesOver(uint wireCnt,
738                  uint widthCnt,
739                  uint spaceCnt,
740                  uint dCnt,
741                  uint met = 0);
742   uint linesDiagUnder(uint wireCnt,
743                       uint widthCnt,
744                       uint spaceCnt,
745                       uint dCnt,
746                       uint met = 0);
747   uint linesUnder(uint wireCnt,
748                   uint widthCnt,
749                   uint spaceCnt,
750                   uint dCnt,
751                   uint met = 0);
752   uint linesOverUnder(uint wireCnt,
753                       uint widthCnt,
754                       uint spaceCnt,
755                       uint dCnt,
756                       uint met = 0);
757 
758   void allocOverTable(extMeasure* measure);
759   void allocDiagUnderTable(extMeasure* measure);
760   void allocUnderTable(extMeasure* measure);
761   void allocOverUnderTable(extMeasure* measure);
762   void computeTables(extMeasure* m,
763                      uint wireCnt,
764                      uint widthCnt,
765                      uint spaceCnt,
766                      uint dCnt);
767 
768   void getDiagTables(extMeasure* m, uint widthCnt, uint spaceCnt);
769   void setDiagUnderTables(extMeasure* m);
770   void getRCtable(uint met, int mUnder, int OverMet, double w, double dRate);
771   void getRCtable(Ath__array1D<int>* sTable,
772                   Ath__array1D<double>* rcTable,
773                   uint valType,
774                   uint met,
775                   int mUnder,
776                   int mOver,
777                   int width,
778                   double dRate);
779 
780   void writeRules(char* name, bool binary);
781   bool readRules(char* name,
782                  bool binary,
783                  bool over,
784                  bool under,
785                  bool overUnder,
786                  bool diag,
787                  uint cornerCnt = 0,
788                  uint* cornerTable = NULL,
789                  double dbFactor = 1.0);
790   uint readMetalHeader(Ath__parser* parser,
791                        uint& met,
792                        const char* keyword,
793                        bool bin,
794                        bool ignore);
795   Ath__array1D<double>* readHeaderAndWidth(Ath__parser* parser,
796                                            uint& met,
797                                            const char* ouKey,
798                                            const char* wKey,
799                                            bool bin,
800                                            bool ignore);
801   uint readRules(Ath__parser* parser,
802                  uint m,
803                  uint ii,
804                  const char* ouKey,
805                  const char* wKey,
806                  bool over,
807                  bool under,
808                  bool bin,
809                  bool diag,
810                  bool ignore,
811                  double dbFactor = 1.0);
812 
813   extDistRC* getOverFringeRC(uint met, uint underMet, uint width);
814   double getFringeOver(uint met, uint mUnder, uint w, uint s);
815   double getCouplingOver(uint met, uint mUnder, uint w, uint s);
816   extDistRC* getOverRC(extMeasure* m);
817   extDistRC* getUnderRC(extMeasure* m);
818   extDistRC* getOverUnderRC(extMeasure* m);
819 
820   extDistRC* getOverFringeRC(extMeasure* m);
821   extDistRC* getOverUnderFringeRC(extMeasure* m);
822   extDistRC* getUnderFringeRC(extMeasure* m);
823 
824   int findDatarateIndex(double d);
825 
826   uint linesUnder(uint wireCnt, uint widthCnt, uint spaceCnt);
827   FILE* mkPatternFile();
828   bool openCapLogFile();
829   void closeCapLogFile();
830   void closeFiles();
831 
setRuleFileName(char * name)832   void setRuleFileName(char* name) { _ruleFileName = name; }
getRuleFileName()833   char* getRuleFileName() { return _ruleFileName; }
getMaxCnt(int met)834   uint getMaxCnt(int met)
835   {
836     return _modelTable[_tmpDataRate]->_capOverUnder[met]->_metCnt;
837   }
838   uint benchDB_WS(extMainOptions* opt, extMeasure* measure);
839   int writeBenchWires_DB(extMeasure* measure);
840   int writeBenchWires_DB_res(extMeasure* measure);
841 
842   int writeBenchWires_DB_diag(extMeasure* measure);
843   extMetRCTable* initCapTables(uint layerCnt, uint widthCnt);
844 
845   extDistRC* getMinRC(int met, int width);
846   extDistRC* getMaxRC(int met, int width, int dist);
847 };
848 class extNetStats
849 {
850  public:
851   double _tcap[2];
852   double _ccap[2];
853   double _cc2tcap[2];
854   double _cc[2];
855   int _len[2];
856   int _layerCnt[2];
857   int _wCnt[2];
858   int _vCnt[2];
859   int _resCnt[2];
860   double _res[2];
861   int _ccCnt[2];
862   int _gndCnt[2];
863   int _termCnt[2];
864   int _btermCnt[2];
865   int _id;
866   bool _layerFilter[20];
867   int _ll[2];
868   int _ur[2];
869   void reset();
870   void update_double_limits(int n,
871                             double v1,
872                             double v2,
873                             double* val,
874                             double units = 1.0);
875   void update_int_limits(int n, int v1, int v2, int* val, uint units = 1);
876   void update_double(Ath__parser* parser,
877                      const char* word,
878                      double* val,
879                      double units = 1.0);
880   void update_int(Ath__parser* parser,
881                   const char* word,
882                   int* val,
883                   uint units = 1);
884   void update_bbox(Ath__parser* parser, const char* bbox);
885 
886  protected:
887   Logger* logger_;
888 };
889 class extLenOU  // assume cross-section on the z-direction
890 {
891  public:
892   int _met;
893   int _underMet;
894   int _overMet;
895   uint _len;
896   bool _over;
897   bool _overUnder;
898   bool _under;
899 
900   void reset();
901   void addOverOrUnderLen(int met, bool over, uint len);
902   void addOULen(int underMet, int overMet, uint len);
903 };
904 class extMeasure
905 {
906  public:
907   bool _skip_delims;
908   extMeasure();
909   ~extMeasure();
910 
911   bool _no_debug;
912   void rcNetInfo();
913   bool rcSegInfo();
914   bool ouCovered_debug(int covered);
915   void segInfo(const char* msg, uint netId, int rsegId);
916   bool isVia(uint rsegId);
917   bool ouRCvalues(const char* msg, uint jj);
918   bool OverSubDebug(extDistRC* rc, int lenOverSub, int lenOverSub_res);
919   bool OverSubDebug(extDistRC* rc,
920                     int lenOverSub,
921                     int lenOverSub_res,
922                     double res,
923                     double cap,
924                     const char* openDist);
925   bool Debug_DiagValues(double res, double cap, const char* openDist);
926   bool IsDebugNet();
927   bool DebugStart(bool allNets = false);
928   bool DebugDiagCoords(int met,
929                        int targetMet,
930                        int len1,
931                        int diagDist,
932                        int ll[2],
933                        int ur[2]);
934   double GetDBcoords(uint coord);
935   double GetDBcoords(int coord);
936   void printNetCaps();
937 
setLogger(Logger * logger)938   void setLogger(Logger* logger) { logger_ = logger; }
939 
940   void printTraceNetInfo(const char* msg, uint netId, int rsegId);
941   bool printTraceNet(const char* msg,
942                      bool init,
943                      odb::dbCCSeg* cc = NULL,
944                      uint overSub = 0,
945                      uint covered = 0);
946 
947   bool parse_setLayer(Ath__parser* parser1, uint& layerNum, bool print = false);
948   odb::dbNet* createSingleWireNet(char* name,
949                                   uint level,
950                                   bool viaFlag,
951                                   bool debug,
952                                   bool skipVias,
953                                   bool skipBterms = false);
954   extDistRC* areaCapOverSub(uint modelNum, extMetRCTable* rcModel);
955 
956   extDistRC* getUnderLastWidthDistRC(extMetRCTable* rcModel, uint overMet);
957   void createCap(int rsegId1, uint rsegId2, double* capTable);
958   void areaCap(int rsegId1, uint rsegId2, uint len, uint tgtMet);
959   bool verticalCap(int rsegId1,
960                    uint rsegId2,
961                    uint len,
962                    uint diagDist,
963                    uint tgtWidth,
964                    uint tgtMet);
965   extDistRC* getVerticalUnderRC(extMetRCTable* rcModel,
966                                 uint diagDist,
967                                 uint tgtWidth,
968                                 uint overMet);
969 
970   int readQcap(extMain* extmain,
971                const char* filename,
972                const char* design,
973                const char* capFile,
974                bool skipBterms,
975                odb::dbDatabase* db);
976   int readAB(extMain* extMain,
977              const char* filename,
978              const char* design,
979              const char* capFile,
980              bool skipBterms,
981              odb::dbDatabase* db);
982   odb::dbRSeg* getRseg(const char* netname,
983                        const char* capMsg,
984                        const char* tableEntryName);
985   int readCapFile(const char* filename, uint& ccCnt);
986   bool getFirstShape(odb::dbNet* net, odb::dbShape& s);
987 
988   void swap_coords(odb::SEQ* s);
989   uint swap_coords(uint initCnt,
990                    uint endCnt,
991                    Ath__array1D<odb::SEQ*>* resTable);
992   uint getOverlapSeq(uint met, odb::SEQ* s, Ath__array1D<odb::SEQ*>* resTable);
993   uint getOverlapSeq(uint met,
994                      int* ll,
995                      int* ur,
996                      Ath__array1D<odb::SEQ*>* resTable);
997 
998   bool isBtermConnection(odb::dbRSeg* rseg1, odb::dbRSeg* rseg2);
999   bool isConnectedToBterm(odb::dbRSeg* rseg1);
1000   uint defineBox(CoupleOptions& options);
1001   void printCoords(FILE* fp);
1002   void printNet(odb::dbRSeg* rseg, uint netId);
1003   void updateBox(uint w_layout, uint s_layout, int dir = -1);
1004   void printBox(FILE* fp);
1005   uint initWS_box(extMainOptions* opt, uint gCnt);
1006   odb::dbRSeg* getFirstDbRseg(uint netId);
1007   uint createNetSingleWire(char* dirName,
1008                            uint idCnt,
1009                            uint w_layout,
1010                            uint s_layout,
1011                            int dir = -1);
1012   uint createDiagNetSingleWire(char* dirName,
1013                                uint idCnt,
1014                                int base,
1015                                int w_layout,
1016                                int s_layout,
1017                                int dir = -1);
1018   uint createNetSingleWire_cntx(int met,
1019                                 char* dirName,
1020                                 uint idCnt,
1021                                 int d,
1022                                 int ll[2],
1023                                 int ur[2],
1024                                 int s_layout = -1);
1025   uint createContextNets(char* dirName,
1026                          int bboxLL[2],
1027                          int bboxUR[2],
1028                          int met,
1029                          double pitchMult);
1030   uint getPatternExtend();
1031 
1032   uint createContextObstruction(const char* dirName,
1033                                 int x1,
1034                                 int y1,
1035                                 int bboxUR[2],
1036                                 int met,
1037                                 double pitchMult);
1038   uint createContextGrid(char* dirName,
1039                          int bboxLL[2],
1040                          int bboxUR[2],
1041                          int met,
1042                          int s_layout = -1);
1043   uint createContextGrid_dir(char* dirName,
1044                              int bboxLL[2],
1045                              int bboxUR[2],
1046                              int met);
1047 
1048   double getCCfringe(uint lastNode, uint n, uint start, uint end);
1049   double getCCfringe3D(uint lastNode, uint n, uint start, uint end);
1050 
1051   void updateForBench(extMainOptions* opt, extMain* extMain);
1052   uint measureOverUnderCap();
1053   uint measureOverUnderCap_orig(odb::gs* pixelTable,
1054                                 uint** ouPixelTableIndexMap);
1055   uint getSeqOverOrUnder(Ath__array1D<odb::SEQ*>* seqTable,
1056                          odb::gs* pixelTable,
1057                          uint met,
1058                          Ath__array1D<odb::SEQ*>* resTable);
1059   uint computeOverOrUnderSeq(Ath__array1D<odb::SEQ*>* seqTable,
1060                              uint met,
1061                              Ath__array1D<odb::SEQ*>* resTable,
1062                              bool over);
1063   uint computeOverUnder(int* ll, int* ur, Ath__array1D<odb::SEQ*>* resTable);
1064 
1065   void release(Ath__array1D<odb::SEQ*>* seqTable, odb::gs* pixelTable = NULL);
1066   void addSeq(Ath__array1D<odb::SEQ*>* seqTable, odb::gs* pixelTable);
1067   void addSeq(int* ll,
1068               int* ur,
1069               Ath__array1D<odb::SEQ*>* seqTable,
1070               odb::gs* pixelTable = NULL);
1071   odb::SEQ* addSeq(int* ll, int* ur);
1072   void copySeq(odb::SEQ* t,
1073                Ath__array1D<odb::SEQ*>* seqTable,
1074                odb::gs* pixelTable);
1075   void tableCopyP(Ath__array1D<odb::SEQ*>* src, Ath__array1D<odb::SEQ*>* dst);
1076   void tableCopy(Ath__array1D<odb::SEQ*>* src,
1077                  Ath__array1D<odb::SEQ*>* dst,
1078                  odb::gs* pixelTable);
1079 
1080   uint measureDiagFullOU();
1081   uint ouFlowStep(Ath__array1D<odb::SEQ*>* overTable);
1082   int underFlowStep(Ath__array1D<odb::SEQ*>* srcTable,
1083                     Ath__array1D<odb::SEQ*>* overTable);
1084 
1085   void measureRC(CoupleOptions& options);
1086   int computeAndStoreRC(odb::dbRSeg* rseg1, odb::dbRSeg* rseg2, int srcCovered);
1087   int computeAndStoreRC_720(odb::dbRSeg* rseg1,
1088                             odb::dbRSeg* rseg2,
1089                             int srcCovered);
1090 
1091   double ScaleResbyTrack(bool openEnded, double& dist_track);
1092   void OverSubRC(odb::dbRSeg* rseg1,
1093                  odb::dbRSeg* rseg2,
1094                  int ouCovered,
1095                  int diagCovered,
1096                  int srcCovered);
1097   void OverSubRC_dist(odb::dbRSeg* rseg1,
1098                       odb::dbRSeg* rseg2,
1099                       int ouCovered,
1100                       int diagCovered,
1101                       int srcCovered);
1102 
1103   void copySeqUsingPool(odb::SEQ* t, Ath__array1D<odb::SEQ*>* seqTable);
1104   void seq_release(Ath__array1D<odb::SEQ*>* table);
1105   void calcOU(uint len);
1106   void calcRC(odb::dbRSeg* rseg1, odb::dbRSeg* rseg2, uint totLenCovered);
1107   int getMaxDist(int tgtMet, uint modelIndex);
1108   void calcRes(int rsegId1, uint len, int dist1, int dist2, int tgtMet);
1109   void calcRes0(double* deltaRes,
1110                 uint tgtMet,
1111                 uint len,
1112                 int dist1 = 0,
1113                 int dist2 = 0);
1114   uint computeRes(odb::SEQ* s,
1115                   uint targetMet,
1116                   uint dir,
1117                   uint planeIndex,
1118                   uint trackn,
1119                   Ath__array1D<odb::SEQ*>* residueSeq);
1120   int computeResDist(odb::SEQ* s,
1121                      uint trackMin,
1122                      uint trackMax,
1123                      uint targetMet,
1124                      Ath__array1D<odb::SEQ*>* diagTable);
1125   uint computeDiag(odb::SEQ* s,
1126                    uint targetMet,
1127                    uint dir,
1128                    uint planeIndex,
1129                    uint trackn,
1130                    Ath__array1D<odb::SEQ*>* diagTable);
1131 
1132   odb::dbCCSeg* makeCcap(odb::dbRSeg* rseg1, odb::dbRSeg* rseg2, double ccCap);
1133   void addCCcap(odb::dbCCSeg* ccap, double v, uint model);
1134   void addFringe(odb::dbRSeg* rseg1,
1135                  odb::dbRSeg* rseg2,
1136                  double frCap,
1137                  uint model);
1138   void calcDiagRC(int rsegid1,
1139                   uint rsegid2,
1140                   uint len,
1141                   uint diagWidth,
1142                   uint diagDist,
1143                   uint tgtMet);
1144   void calcDiagRC(int rsegid1, uint rsegid2, uint len, uint dist, uint tgtMet);
1145   int calcDist(int* ll, int* ur);
1146 
1147   void ccReportProgress();
1148   uint getOverUnderIndex();
1149 
1150   uint getLength(odb::SEQ* s, int dir);
1151   uint blackCount(uint start, Ath__array1D<odb::SEQ*>* resTable);
1152   extDistRC* computeR(uint len, double* valTable);
1153   extDistRC* computeOverFringe(uint overMet,
1154                                uint overWidth,
1155                                uint len,
1156                                uint dist);
1157   extDistRC* computeUnderFringe(uint underMet,
1158                                 uint underWidth,
1159                                 uint len,
1160                                 uint dist);
1161 
1162   double getDiagUnderCC(extMetRCTable* rcModel, uint dist, uint overMet);
1163   double getDiagUnderCC(extMetRCTable* rcModel,
1164                         uint diagWidth,
1165                         uint diagDist,
1166                         uint overMet);
1167   extDistRC* getDiagUnderCC2(extMetRCTable* rcModel,
1168                              uint diagWidth,
1169                              uint diagDist,
1170                              uint overMet);
1171   extDistRC* computeOverUnderRC(uint len);
1172   extDistRC* computeOverRC(uint len);
1173   extDistRC* computeUnderRC(uint len);
1174   extDistRC* getOverUnderFringeRC(extMetRCTable* rcModel);
1175   extDistRC* getOverUnderRC(extMetRCTable* rcModel);
1176   extDistRC* getOverRC(extMetRCTable* rcModel);
1177   uint getUnderIndex();
1178   uint getUnderIndex(uint overMet);
1179   extDistRC* getUnderRC(extMetRCTable* rcModel);
1180 
1181   extDistRC* getFringe(uint len, double* valTable);
1182 
1183   void tableCopyP(Ath__array1D<int>* src, Ath__array1D<int>* dst);
1184   void getMinWidth(odb::dbTech* tech);
1185   uint measureOverUnderCapCJ();
1186   uint computeOverUnder(int xy1, int xy2, Ath__array1D<int>* resTable);
1187   uint computeOUwith2planes(int* ll,
1188                             int* ur,
1189                             Ath__array1D<odb::SEQ*>* resTable);
1190   uint intersectContextArray(int pmin,
1191                              int pmax,
1192                              uint met1,
1193                              uint met2,
1194                              Ath__array1D<int>* tgtContext);
1195   uint computeOverOrUnderSeq(Ath__array1D<int>* srcTable,
1196                              uint met,
1197                              Ath__array1D<int>* resTable,
1198                              bool over);
1199   bool updateLengthAndExit(int& remainder, int& totCovered, int len);
1200   int compute_Diag_Over_Under(Ath__array1D<odb::SEQ*>* seqTable,
1201                               Ath__array1D<odb::SEQ*>* resTable);
1202   int compute_Diag_OverOrUnder(Ath__array1D<odb::SEQ*>* seqTable,
1203                                bool over,
1204                                uint met,
1205                                Ath__array1D<odb::SEQ*>* resTable);
1206   uint measureUnderOnly(bool diagFlag);
1207   uint measureOverOnly(bool diagFlag);
1208   uint measureDiagOU(uint ouLevelLimit, uint diagLevelLimit);
1209 
1210   uint mergeContextArray(Ath__array1D<int>* srcContext,
1211                          int minS,
1212                          Ath__array1D<int>* tgtContext);
1213   uint mergeContextArray(Ath__array1D<int>* srcContext,
1214                          int minS,
1215                          int pmin,
1216                          int pmax,
1217                          Ath__array1D<int>* tgtContext);
1218   uint makeMergedContextArray(uint met, int minS);
1219   uint makeMergedContextArray(uint met);
1220   uint makeMergedContextArray(int pmin, int pmax, uint met, int minS);
1221   uint makeMergedContextArray(int pmin, int pmax, uint met);
1222   uint intersectContextArray(Ath__array1D<int>* s1Context,
1223                              Ath__array1D<int>* s2Context,
1224                              int minS1,
1225                              int minS2,
1226                              Ath__array1D<int>* tgtContext);
1227 
1228   extDistRC* addRC(extDistRC* rcUnit, uint len, uint jj);
1229 
1230   void setMets(int m, int u, int o);
1231   void setTargetParams(double w,
1232                        double s,
1233                        double r,
1234                        double t,
1235                        double h,
1236                        double w2 = 0.0,
1237                        double s2 = 0.0);
1238   void setEffParams(double wTop, double wBot, double teff);
1239   void addCap();
1240   void printStats(FILE* fp);
1241   void printMets(FILE* fp);
1242 
1243   ext2dBox* addNew2dBox(odb::dbNet* net,
1244                         int* ll,
1245                         int* ur,
1246                         uint m,
1247                         uint d,
1248                         uint id,
1249                         bool cntx);
1250   void clean2dBoxTable(int met, bool cntx);
1251   uint writeRaphael3D(FILE* fp,
1252                       int met,
1253                       bool cntx,
1254                       double x1,
1255                       double y1,
1256                       double th);
1257   uint writeDiagRaphael3D(FILE* fp,
1258                           int met,
1259                           bool cntx,
1260                           double x1,
1261                           double y1,
1262                           double th);
1263   void writeRaphaelPointXY(FILE* fp, double X, double Y);
1264   void getBox(int met, bool cntx, int& xlo, int& ylo, int& xhi, int& yhi);
1265   uint getBoxLength(uint ii, int met, bool cntx);
1266 
1267   int getDgPlaneAndTrackIndex(uint tgt_met,
1268                               int trackDist,
1269                               int& loTrack,
1270                               int& hiTrack);
1271   int computeDiagOU(odb::SEQ* s,
1272                     uint targetMet,
1273                     Ath__array1D<odb::SEQ*>* residueSeq);
1274   int computeDiagOU(odb::SEQ* s,
1275                     uint trackMin,
1276                     uint trackMax,
1277                     uint targetMet,
1278                     Ath__array1D<odb::SEQ*>* residueSeq);
1279   void printDgContext();
1280   void initTargetSeq();
1281   void getDgOverlap(CoupleOptions &options);
1282   void getDgOverlap(odb::SEQ* sseq,
1283                     uint dir,
1284                     Ath__array1D<odb::SEQ*>* dgContext,
1285                     Ath__array1D<odb::SEQ*>* overlapSeq,
1286                     Ath__array1D<odb::SEQ*>* residueSeq);
1287   void getDgOverlap_res(odb::SEQ* sseq,
1288                         uint dir,
1289                         Ath__array1D<odb::SEQ*>* dgContext,
1290                         Ath__array1D<odb::SEQ*>* overlapSeq,
1291                         Ath__array1D<odb::SEQ*>* residueSeq);
1292 
1293   void writeBoxRaphael3D(FILE* fp,
1294                          ext2dBox* bb,
1295                          int* base_ll,
1296                          int* base_ur,
1297                          double y1,
1298                          double th,
1299                          double volt);
1300   uint getRSeg(odb::dbNet* net, uint shapeId);
1301 
1302   void allocOUpool();
get_nm(double n)1303   int get_nm(double n) { return 1000 * (n / _dbunit); };
1304 
1305   int _met;
1306   int _underMet;
1307   int _overMet;
1308   uint _wireCnt;
1309 
1310   uint _dirTable[10000];
1311   int _minSpaceTable[32];
1312 
1313   int _minWidth;
1314   int _minSpace;
1315   int _pitch;
1316 
1317   double _w_m;
1318   int _w_nm;
1319   double _s_m;
1320   int _s_nm;
1321   double _w2_m;
1322   int _w2_nm;
1323   double _s2_m;
1324   int _s2_nm;
1325 
1326   double _r;
1327   double _t;
1328   double _h;
1329 
1330   uint _wIndex;
1331   uint _sIndex;
1332   uint _dwIndex;
1333   uint _dsIndex;
1334   uint _rIndex;
1335   uint _pIndex;
1336 
1337   double _topWidth;
1338   double _botWidth;
1339   double _teff;
1340   double _heff;
1341   double _seff;
1342 
1343   double _topWidthR;
1344   double _botWidthR;
1345   double _teffR;
1346   double _peffR;
1347 
1348   bool _benchFlag;
1349   bool _varFlag;
1350   bool _3dFlag;
1351   bool _over;
1352   bool _res;
1353   bool _overUnder;
1354   bool _diag;
1355   bool _verticalDiag;
1356   bool _plate;
1357   bool _thickVarFlag;
1358   bool _metExtFlag;
1359   uint _diagModel;
1360 
1361   extDistRC* _rc[20];
1362   extDistRC* _tmpRC;
1363   bool _rcValid;
1364   extRCTable* _capTable;
1365   Ath__array1D<double> _widthTable;
1366   Ath__array1D<double> _spaceTable;
1367   Ath__array1D<double> _dataTable;
1368   Ath__array1D<double> _pTable;
1369   Ath__array1D<double> _widthTable0;
1370   Ath__array1D<double> _spaceTable0;
1371   Ath__array1D<double> _diagSpaceTable0;
1372   Ath__array1D<double> _diagWidthTable0;
1373 
1374   Ath__array1D<odb::SEQ*>*** _dgContextArray;  // array
1375   uint* _dgContextDepth;                       // not array
1376   uint* _dgContextPlanes;                      // not array
1377   uint* _dgContextTracks;                      // not array
1378   uint* _dgContextBaseLvl;                     // not array
1379   int* _dgContextLowLvl;                       // not array
1380   int* _dgContextHiLvl;                        // not array
1381   uint* _dgContextBaseTrack;                   // array
1382   int* _dgContextLowTrack;                     // array
1383   int* _dgContextHiTrack;                      // array
1384   int** _dgContextTrackBase;                   // array
1385   FILE* _dgContextFile;
1386   uint _dgContextCnt;
1387 
1388   uint* _ccContextLength;
1389   Ath__array1D<int>** _ccContextArray;
1390 
1391   Ath__array1D<ext2dBox*>
1392       _2dBoxTable[2][20];  // assume 20 layers; 0=main net; 1=context
1393   AthPool<ext2dBox>* _2dBoxPool;
1394   uint* _ccMergedContextLength;
1395   Ath__array1D<int>** _ccMergedContextArray;
1396 
1397   int _ll[2];
1398   int _ur[2];
1399 
1400   uint _len;
1401   int _dist;
1402   uint _width;
1403   uint _dir;
1404   uint _layerCnt;
1405   odb::dbBlock* _block;
1406   odb::dbTech* _tech;
1407   double _capMatrix[100][100];
1408   uint _idTable[10000];
1409   uint _mapTable[10000];
1410   uint _maxCapNodeCnt;
1411 
1412   extMain* _extMain;
1413   extRCModel* _currentModel;
1414   Ath__array1D<extMetRCTable*> _metRCTable;
1415   uint _minModelIndex;
1416   uint _maxModelIndex;
1417 
1418   uint _totCCcnt;
1419   uint _totSmallCCcnt;
1420   uint _totBigCCcnt;
1421   uint _totSignalSegCnt;
1422   uint _totSegCnt;
1423 
1424   double _resFactor;
1425   bool _resModify;
1426   double _ccFactor;
1427   bool _ccModify;
1428   double _gndcFactor;
1429   bool _gndcModify;
1430 
1431   odb::gs* _pixelTable;
1432   uint** _ouPixelTableIndexMap;
1433 
1434   Ath__array1D<odb::SEQ*>* _diagTable;
1435   Ath__array1D<odb::SEQ*>* _tmpSrcTable;
1436   Ath__array1D<odb::SEQ*>* _tmpDstTable;
1437   Ath__array1D<odb::SEQ*>* _tmpTable;
1438   Ath__array1D<odb::SEQ*>* _underTable;
1439   Ath__array1D<odb::SEQ*>* _ouTable;
1440   Ath__array1D<odb::SEQ*>* _overTable;
1441 
1442   int _diagLen;
1443   uint _netId;
1444   int _rsegSrcId;
1445   int _rsegTgtId;
1446   int _netSrcId;
1447   int _netTgtId;
1448   FILE* _debugFP;
1449 
1450   AthPool<odb::SEQ>* _seqPool;
1451 
1452   AthPool<extLenOU>* _lenOUPool;
1453   Ath__array1D<extLenOU*>* _lenOUtable;
1454 
1455   bool _diagFlow;
1456   bool _btermThreshold;
1457   bool _toHi;
1458   bool _sameNetFlag;
1459 
1460   bool _rotatedGs;
1461 
1462   odb::dbCreateNetUtil _create_net_util;
1463   int _dbunit;
1464 
1465  protected:
1466   Logger* logger_;
1467 };
1468 class extWire
1469 {
1470  public:
1471   uint _netId;
1472   int _shapeId;
1473   odb::dbTechLayer* _layer;
1474 };
1475 class extWireBin
1476 {
1477  public:
1478   uint _dir;
1479   uint _num;
1480   int _base;
1481   Ath__array1D<extWire*>* _table;
1482   AthPool<extWire>* _extWirePool;
1483 
1484   extWireBin(uint d,
1485              uint num,
1486              int base,
1487              AthPool<extWire>* wpool,
1488              uint allocChunk);
1489   int addWire(uint netId, int sid, odb::dbTechLayer* layer);
1490   uint createDbNets(odb::dbBlock* block, odb::dbCreateNetUtil* createDbNet);
1491   uint createDbNetsGS(odb::dbBlock* block, odb::dbCreateNetUtil* createDbNet);
1492 };
1493 
1494 class extTileSystem
1495 {
1496  public:
1497   Ath__array1D<uint>** _signalTable[2];
1498   Ath__array1D<uint>** _instTable[2];
1499   Ath__array1D<uint>* _powerTable;
1500   Ath__array1D<uint>* _tmpIdTable;
1501   uint _tileCnt[2];
1502   uint _tileSize[2];
1503   int _ll[2];
1504   int _ur[2];
1505 
1506   extTileSystem(odb::Rect& extRect, uint* size);
1507   ~extTileSystem();
1508 };
1509 
1510 class extWindow
1511 {
1512  public:
1513   uint _num;
1514   uint* _dirTable;
1515   uint* _minSpaceTable;
1516   int _ll[2];
1517   int _ur[2];
1518 
1519   uint _maxLayerCnt;  // for allocation
1520 
1521   uint _step_nm[2];
1522 
1523   uint _ccDist;
1524 
1525   uint _sigtype;
1526   uint _pwrtype;
1527 
1528   uint* _pitchTable;
1529   uint* _widthTable;
1530   uint _layerCnt;
1531 
1532   uint _maxPitch;
1533   uint _maxWidth;
1534 
1535   int _lo_gs[2];
1536   int _hi_gs[2];
1537   int _lo_sdb[2];
1538   int _hi_sdb[2];
1539   int _minExtracted;
1540   int _extractLimit;
1541   int _gs_limit;
1542   int _hiXY;
1543   int _deallocLimit;
1544 
1545   int* _extTrack[2];
1546   int* _extLimit[2];
1547   int* _cntxTrack[2];
1548   int* _cntxLimit[2];
1549   int* _sdbBase[2];
1550 
1551   uint _totPowerWireCnt;
1552   uint _totSignalWireCnt;
1553   uint _totWireCnt;
1554   uint _processPowerWireCnt;
1555   uint _processSignalWireCnt;
1556   uint _totalWiresExtracted;
1557   double _prev_percent_extracted;
1558 
1559   uint _currentDir;
1560   bool _gsRotatedFlag;
1561 
1562   extWindow(uint maxLayerCnt, Logger* logger);
1563   void init(uint maxLayerCnt);
1564   extWindow(extWindow* e, uint num, Logger* logger);
1565   ~extWindow();
1566 
1567   void initWindowStep(odb::Rect& extRect,
1568                       uint trackStep,
1569                       uint layerCnt,
1570                       uint modelLevelCnt);
1571   void makeSdbBuckets(uint sdbBucketCnt[2],
1572                       uint sdbBucketSize[2],
1573                       int sdbTable_ll[2],
1574                       int sdbTable_ur[2]);
1575   int setExtBoundaries(uint dir);
1576   int adjust_hiXY(int hiXY);
1577   int set_extractLimit();
1578   void reportProcessedWires(bool rlog);
1579   int getDeallocLimit();
1580   void updateLoBounds(bool reportFlag);
1581   void printBoundaries(FILE* fp, bool flag);
1582   void get_extractLimit(extWindow* e);
1583   void updateExtLimits(int** limitArray);
1584   void printExtLimits(FILE* fp);
1585   void printLimits(FILE* fp,
1586                    const char* header,
1587                    uint maxLayer,
1588                    int** limitArray,
1589                    int** trackArray);
1590   odb::dbBlock* createExtBlock(extMeasure* m,
1591                                odb::dbBlock* mainBlock,
1592                                odb::Rect& extRect);
1593   int getIntProperty(odb::dbBlock* block, const char* name);
1594   void getExtProperties(odb::dbBlock* block);
1595   void makeIntArrayProperty(odb::dbBlock* block,
1596                             uint ii,
1597                             int* A,
1598                             const char* name);
1599   int getIntArrayProperty(odb::dbBlock* block, uint ii, const char* name);
1600 
1601  protected:
1602   Logger* logger_;
1603 };
1604 
1605 class extMainOptions
1606 {
1607  public:
1608   extMainOptions();
1609 
1610   uint _overDist;
1611   uint _underDist;
1612   int _met_cnt;
1613   int _met;
1614   int _underMet;
1615   int _overMet;
1616   uint _wireCnt;
1617   const char* _topDir;
1618   const char* _name;
1619   const char* _wTable;
1620   const char* _sTable;
1621   const char* _thTable;
1622   const char* _dTable;
1623 
1624   bool _write_to_solver;
1625   bool _read_from_solver;
1626   bool _run_solver;
1627 
1628   bool _listsFlag;
1629   bool _thListFlag;
1630   bool _wsListFlag;
1631   bool _default_lef_rules;
1632   bool _nondefault_lef_rules;
1633 
1634   bool _multiple_widths;
1635 
1636   bool _varFlag;
1637   bool _3dFlag;
1638   bool _over;
1639   bool _overUnder;
1640   int _diag;
1641   bool _db_only;
1642   bool _gen_def_patterns;
1643 
1644   bool _res_patterns;
1645 
1646   odb::dbTech* _tech;
1647   odb::dbBlock* _block;
1648 
1649   Ath__array1D<double> _widthTable;
1650   Ath__array1D<double> _spaceTable;
1651   Ath__array1D<double> _densityTable;
1652   Ath__array1D<double> _thicknessTable;
1653   Ath__array1D<double> _gridTable;
1654 
1655   int _ll[2];
1656   int _ur[2];
1657   uint _len;
1658   int _dist;
1659   uint _width;
1660   uint _dir;
1661   extRCModel* _rcModel;
1662   uint _layerCnt;
1663 };
1664 
1665 class extCorner
1666 {
1667  public:
1668   char* _name;
1669   int _model;
1670   int _dbIndex;
1671   int _scaledCornerIdx;
1672   float _resFactor;
1673   float _ccFactor;
1674   float _gndFactor;
1675   extCorner* _extCornerPtr;
1676 
1677   extCorner();
1678 };
1679 
1680 class extMain
1681 {
1682  protected:
1683   Logger* logger_;
1684 
1685  private:
1686   bool _batchScaleExt;
1687   Ath__array1D<extCorner*>* _processCornerTable;
1688   Ath__array1D<extCorner*>* _scaledCornerTable;
1689 
1690   Ath__array1D<extRCModel*>* _modelTable;
1691   Ath__array1D<uint> _modelMap;  // TO_TEST
1692   Ath__array1D<extMetRCTable*> _metRCTable;
1693   double _resistanceTable[20][20];
1694   double _capacitanceTable[20][20];  // 20 layers by 20 rc models
1695   double _minWidthTable[20];
1696   uint _minDistTable[20];
1697   double _tmpCapTable[20];
1698   double _tmpSumCapTable[20];
1699   double _tmpResTable[20];
1700   double _tmpSumResTable[20];
1701   int _sumUpdated;
1702   int _minModelIndex;  // TO_TEST
1703   int _typModelIndex;  //
1704   int _maxModelIndex;  //
1705 
1706   odb::dbDatabase* _db;
1707   odb::dbTech* _tech;
1708   odb::dbBlock* _block;
1709   uint _blockId;
1710   extSpef* _spef;
1711   bool _writeNameMap;
1712   bool _fullIncrSpef;
1713   bool _noFullIncrSpef;
1714   char* _origSpefFilePrefix;
1715   char* _newSpefFilePrefix;
1716   char* _excludeCells;
1717   uint _bufSpefCnt;
1718   bool _incrNoBackSlash;
1719   uint _cornerCnt;
1720   uint _extDbCnt;
1721 
1722   int _remote;
1723   bool _extracted;
1724   bool _reExtract;
1725   bool _allNet;
1726   bool _eco;
1727   odb::Rect* _ibox;
1728 
1729   bool _getBandWire;
1730   bool _printBandInfo;
1731   bool _reuseMetalFill;
1732   uint _ccPreseveGeom;
1733   uint _ccUp;
1734   uint _couplingFlag;
1735   uint _cc_band_tracks;
1736   uint _use_signal_tables;
1737   // 1: signal table,  NO rotation;
1738   // 2: signal table,  rotation;
1739   // 3: NO signal table,  rotation
1740   bool _rotatedGs;
1741   uint _ccContextDepth;
1742   uint _debug;
1743   int _ccMinX;
1744   int _ccMinY;
1745   int _ccMaxX;
1746   int _ccMaxY;
1747   double _mergeResBound;
1748   bool _mergeViaRes;
1749   bool _mergeParallelCC;
1750   bool _unifiedMeasureInit;
1751   bool _reportNetNoWire;
1752   int _netNoWireCnt;
1753 
1754   double _resFactor;
1755   bool _resModify;
1756   double _ccFactor;
1757   bool _ccModify;
1758   double _gndcFactor;
1759   bool _gndcModify;
1760 
1761   float _netGndcCalibFactor;
1762   bool _netGndcCalibration;
1763 
1764   bool _useDbSdb;
1765 
1766   Ath__array1D<int>* _nodeTable;
1767   Ath__array1D<int>* _btermTable;
1768   Ath__array1D<int>* _itermTable;
1769 
1770   odb::ZPtr<odb::ISdb> _extNetSDB;
1771   odb::ZPtr<odb::ISdb> _extCcapSDB;
1772   odb::ZPtr<odb::ISdb> _reExtCcapSDB;
1773   uint _menuId;
1774   uint _dbPowerId;
1775   uint _dbSignalId;
1776   uint _RsegId;
1777   uint _CCsegId;
1778 
1779   uint _CCnoPowerSource;
1780   uint _CCnoPowerTarget;
1781   int _x1;
1782   int _y1;
1783   int _x2;
1784   int _y2;
1785 
1786   double _coupleThreshold;
1787 
1788   uint _totCCcnt;
1789   uint _totSmallCCcnt;
1790   uint _totBigCCcnt;
1791   uint _totSignalSegCnt;
1792   uint _totSegCnt;
1793 
1794   bool _lefRC;
1795   bool _noModelRC;
1796   extRCModel* _currentModel;
1797 
1798   uint* _singlePlaneLayerMap;
1799   uint** _overUnderPlaneLayerMap;
1800   bool _usingMetalPlanes;
1801   bool _alwaysNewGs;
1802 
1803   odb::gs* _geomSeq;
1804 
1805   AthPool<odb::SEQ>* _seqPool;
1806 
1807   Ath__array1D<odb::SEQ*>*** _dgContextArray;
1808   uint _dgContextDepth;
1809   uint _dgContextPlanes;
1810   uint _dgContextTracks;
1811   uint _dgContextBaseLvl;
1812   int _dgContextLowLvl;
1813   int _dgContextHiLvl;
1814   uint* _dgContextBaseTrack;
1815   int* _dgContextLowTrack;
1816   int* _dgContextHiTrack;
1817   int** _dgContextTrackBase;
1818 
1819   uint* _ccContextLength;
1820   Ath__array1D<int>** _ccContextArray;
1821   uint* _ccMergedContextLength;
1822   Ath__array1D<int>** _ccMergedContextArray;
1823   Ath__array1D<int>* _tContextArray;
1824 
1825   extGeoThickTable** _geoThickTable;
1826   int _measureRcCnt;
1827   int _shapeRcCnt;
1828   int _updateTotalCcnt;
1829   FILE* _printFile;
1830   FILE* _ptFile;
1831 
1832   uint _extRun;
1833   odb::dbExtControl* _prevControl;
1834 
1835   bool _independentExtCorners;
1836   bool _foreign;
1837   bool _rsegCoord;
1838   bool _overCell;
1839   bool _diagFlow;
1840 
1841   std::vector<uint> _rsegJid;
1842   std::vector<uint> _shortSrcJid;
1843   std::vector<uint> _shortTgtJid;
1844 
1845   std::vector<odb::dbBTerm*> _connectedBTerm;
1846   std::vector<odb::dbITerm*> _connectedITerm;
1847 
1848   Ath__gridTable* _search;
1849 
1850   int _noVariationIndex;
1851 
1852   extWireBin*** _wireBinTable;
1853   extWireBin*** _cntxBinTable;
1854   Ath__array1D<uint>*** _cntxInstTable;
1855 
1856   extTileSystem* _tiles;
1857   bool _ignoreWarning_1st;
1858   bool _keepExtModel;
1859 
1860   FILE* _searchFP;
1861   friend class extMeasure;
1862 
1863   // 021411D BEGIN
1864   FILE* _blkInfoVDD;
1865   FILE* _viaInfoVDD;
1866   FILE* _blkInfoGND;
1867   FILE* _viaInfoGND;
1868 
1869   FILE* _stdCirVDD;
1870   FILE* _globCirVDD;
1871   FILE* _globGeomVDD;
1872   FILE* _stdCirGND;
1873   FILE* _globCirGND;
1874 
1875   FILE* _stdCirHeadVDD;
1876   FILE* _globCirHeadVDD;
1877   FILE* _globGeomGND;
1878   FILE* _stdCirHeadGND;
1879   FILE* _globCirHeadGND;
1880   FILE* _blkInfo;
1881   FILE* _viaInfo;
1882   FILE* _globCir;
1883   FILE* _globGeom;
1884   FILE* _stdCir;
1885   FILE* _globCirHead;
1886   FILE* _stdCirHead;
1887   FILE* _viaStackGlobCir;
1888   FILE* _viaStackGlobVDD;
1889   FILE* _viaStackGlobGND;
1890   // 021411D END
1891 
1892   // 021511D BEGIN
1893   Ath__array1D<int>* _junct2viaMap;
1894   bool _dbgPowerFlow;
1895   odb::dbCreateNetUtil* _netUtil;
1896   // 021511D END
1897 
1898   // 021911D BEGIN
1899   std::vector<odb::dbBox*> _viaUp_VDDtable;
1900   std::vector<odb::dbBox*> _viaUp_GNDtable;
1901   std::vector<odb::dbBox*> _viaM1_GNDtable;
1902   std::vector<odb::dbBox*> _viaM1_VDDtable;
1903   std::vector<odb::dbBox*>* _viaM1Table;
1904   std::vector<odb::dbBox*>* _viaUpTable;
1905   // 021911D END
1906   bool _adjust_colinear;
1907   // 032811D END
1908   // 061711D BEGIN
1909   uint _stackedViaResCnt;
1910   uint _totViaResCnt;
1911   Ath__array1D<int>* _via2JunctionMap;
1912   std::map<odb::dbBox*, odb::dbNet*> _via_map;
1913   std::map<uint, odb::dbNet*> _via_id_map;
1914   std::map<uint, float> _capNode_map;
1915   std::vector<odb::dbInst*> _powerMacroTable;
1916   std::vector<odb::dbBox*> _viaUpperTable[2];
1917   // 061711D END
1918   // 021712D BEGIN
1919   Ath__array1D<char*>** _supplyViaMap[2];
1920   Ath__array1D<odb::dbBox*>** _supplyViaTable[2];
1921   char* _power_source_file;
1922   std::vector<char*> _powerSourceTable[2];
1923   // 021712D END
1924   FILE* _coordsFP;
1925   FILE* _coordsGND;
1926   FILE* _coordsVDD;
1927   std::vector<uint> _vddItermIdTable;
1928   std::vector<uint> _gndItermIdTable;
1929   FILE* _subCktNodeFP[2][2];
1930   uint _subCktNodeCnt[2][2];
1931   bool _power_extract_only;
1932   bool _skip_power_stubs;
1933   bool _skip_m1_caps;
1934   const char* _power_exclude_cell_list;
1935   // 062212D
1936   bool _nodeCoords;
1937   int _prevX;
1938   int _prevY;
1939   char _node_blk_dir[1024];
1940   char _node_blk_prefix[1024];
1941   char _node_inst_prefix[1024];
1942   // 100812D
1943   Ath__array1D<odb::dbITerm*>* _junct2iterm;
1944   // 102912D
1945   std::map<uint, odb::dbSBox*> _sbox_id_map;
1946 
1947   uint _powerWireCnt;
1948   uint _mergedPowerWireCnt;
1949   uint _overlapPowerWireCnt;
1950   uint _viaOverlapPowerCnt;
1951   uint _multiViaCnt;
1952 
1953   std::vector<odb::Rect*> _multiViaTable[20];
1954   std::vector<odb::dbBox*> _multiViaBoxTable[20];
1955 
1956   uint _debug_net_id;
1957   bool _skip_via_wires;
1958   float _previous_percent_extracted;
1959 
1960   double _minCapTable[64][64];
1961   double _maxCapTable[64][64];
1962   double _minResTable[64][64];
1963   double _maxResTable[64][64];
1964   uint _rcLayerCnt;
1965   uint _rcCornerCnt;
1966 
1967  public:
1968   bool _lef_res;
1969 
1970   void init(odb::dbDatabase* db, Logger* logger);
1971   double getTotalCouplingCap(odb::dbNet* net,
1972                              const char* filterNet,
1973                              uint corner);
1974 
1975   uint calcMinMaxRC();
1976   void resetMinMaxRC(uint ii, uint jj);
1977   uint getExtStats(odb::dbNet* net,
1978                    uint corner,
1979                    int& wlen,
1980                    double& min_cap,
1981                    double& max_cap,
1982                    double& min_res,
1983                    double& max_res,
1984                    double& via_res,
1985                    uint& via_cnt);
1986   char _tmpLenStats[1024000];
1987 
1988   enum INCR_SPEF_TYPE
1989   {
1990     ISPEF_NONE,
1991     ISPEF_ORIGINAL,
1992     ISPEF_NEW,
1993     ISPEF_ORIGINAL_PLUS_HALO,
1994     ISPEF_NEW_PLUS_HALO,
1995   };
1996   extMain(uint menuId);
1997 
set_debug_nets(const char * nets)1998   void set_debug_nets(const char* nets)
1999   {
2000     _debug_net_id = 0;
2001     if (nets != NULL) {
2002       _debug_net_id = atoi(nets);
2003       // TODO: 531 - make a list
2004     }
2005   }
2006 
2007   static void createShapeProperty(odb::dbNet* net, int id, int id_val);
2008   static int getShapeProperty(odb::dbNet* net, int id);
2009   static int getShapeProperty_rc(odb::dbNet* net, int rc_id);
2010 
skip_via_wires(bool v)2011   void skip_via_wires(bool v) { _skip_via_wires = v; };
2012 
2013   uint getDir(int x1, int y1, int x2, int y2);
2014   uint getDir(odb::Rect& r);
2015   bool outOfBounds_i(int limit[2], int v);
2016   bool outOfBounds_d(double limit[2], double v);
2017   bool printNetRC(char* buff, odb::dbNet* net, extNetStats* st);
2018   bool printNetDB(char* buff, odb::dbNet* net, extNetStats* st);
2019   uint printNetStats(FILE* fp,
2020                      odb::dbBlock* block,
2021                      extNetStats* st,
2022                      bool skipRC,
2023                      bool skipDb,
2024                      bool skipPower,
2025                      std::list<int>* list_of_nets);
2026 
2027   uint initSearchForNets(int* X1,
2028                          int* Y1,
2029                          uint* pitchTable,
2030                          uint* widthTable,
2031                          uint* dirTable,
2032                          odb::Rect& extRect,
2033                          bool skipBaseCalc);
2034   uint addNetSBoxes(odb::dbNet* net,
2035                     uint dir,
2036                     int* bb_ll,
2037                     int* bb_ur,
2038                     uint wtype,
2039                     odb::dbCreateNetUtil* netUtil = NULL);
2040   uint addNetSBoxes2(odb::dbNet* net,
2041                      uint dir,
2042                      int* bb_ll,
2043                      int* bb_ur,
2044                      uint wtype,
2045                      uint step = 0);
2046   uint addPowerNets(uint dir,
2047                     int* bb_ll,
2048                     int* bb_ur,
2049                     uint wtype,
2050                     odb::dbCreateNetUtil* netUtil = NULL);
2051   uint addNetShapesOnSearch(odb::dbNet* net,
2052                             uint dir,
2053                             int* bb_ll,
2054                             int* bb_ur,
2055                             uint wtype,
2056                             FILE* fp,
2057                             odb::dbCreateNetUtil* netUtil = NULL);
2058   int GetDBcoords2(int coord);
2059   void GetDBcoords2(odb::Rect& r);
2060   double GetDBcoords1(int coord);
2061   uint addViaBoxes(odb::dbShape& sVia,
2062                    odb::dbNet* net,
2063                    uint shapeId,
2064                    uint wtype);
2065   void getViaCapacitance(odb::dbShape svia, odb::dbNet* net);
2066 
2067   uint addSignalNets(uint dir,
2068                      int* bb_ll,
2069                      int* bb_ur,
2070                      uint wtype,
2071                      odb::dbCreateNetUtil* netUtil = NULL);
2072   uint addInstsGs(Ath__array1D<uint>* instTable,
2073                   Ath__array1D<uint>* tmpInstIdTable,
2074                   uint dir);
2075   uint mkSignalTables(uint* nm_step,
2076                       int* bb_ll,
2077                       int* bb_ur,
2078                       Ath__array1D<uint>*** sdbSignalTable,
2079                       Ath__array1D<uint>*** signalGsTable,
2080                       uint* bucketCnt);
2081   uint mkSignalTables(uint* nm_step,
2082                       int* bb_ll,
2083                       int* bb_ur,
2084                       Ath__array1D<uint>*** sdbSignalTable,
2085                       Ath__array1D<uint>*** signalGsTable,
2086                       Ath__array1D<uint>*** instTable,
2087                       uint* bucketCnt);
2088   void freeSignalTables(bool rlog,
2089                         Ath__array1D<uint>*** sdbSignalTable,
2090                         Ath__array1D<uint>*** signalGsTable,
2091                         uint* bucketCnt);
2092   uint addNets(uint dir,
2093                int* bb_ll,
2094                int* bb_ur,
2095                uint wtype,
2096                uint ptype,
2097                Ath__array1D<uint>* sdbSignalTable);
2098   uint addNetOnTable(uint netId,
2099                      uint dir,
2100                      odb::Rect* maxRect,
2101                      uint* nm_step,
2102                      int* bb_ll,
2103                      int* bb_ur,
2104                      Ath__array1D<uint>*** wireTable);
2105   void getNetShapes(odb::dbNet* net,
2106                     odb::Rect** maxRectSdb,
2107                     odb::Rect& maxRectGs,
2108                     bool* hasSdbWires,
2109                     bool& hasGsWires);
2110   void getNetSboxes(odb::dbNet* net,
2111                     odb::Rect** maxRectSdb,
2112                     odb::Rect& maxRectGs,
2113                     bool* hasSdbWires,
2114                     bool& hasGsWires);
2115   uint addNetsGs(Ath__array1D<uint>* gsTable, int dir);
2116   uint addNetShapesGs(odb::dbNet* net,
2117                       bool gsRotated,
2118                       bool swap_coords,
2119                       int dir,
2120                       odb::dbCreateNetUtil* createDbNet = NULL);
2121   uint addNetSboxesGs(odb::dbNet* net,
2122                       bool gsRotated,
2123                       bool swap_coords,
2124                       int dir,
2125                       odb::dbCreateNetUtil* createDbNet = NULL);
2126 
2127   uint getBucketNum(int base, int max, uint step, int xy);
2128   int getXY_gs(int base, int XY, uint minRes);
2129   int getXY_gs2(int base, int hiXY, int loXY, uint minRes);
2130   int fill_gs(int dir,
2131               int* ll,
2132               int* ur,
2133               int hiXY,
2134               int minExt,
2135               uint minRes,
2136               uint layerCnt,
2137               uint* pitchTable,
2138               uint* widthTable);
2139   int fill_gs2(int dir,
2140                int* ll,
2141                int* ur,
2142                int* lo_gs,
2143                int* lo_gst,
2144                uint layerCnt,
2145                uint* dirTable,
2146                uint* pitchTable,
2147                uint* widthTable,
2148                uint bucket,
2149                Ath__array1D<uint>*** gsTable,
2150                Ath__array1D<uint>*** instGsTable);
2151   // int fill_gs2(int dir, int *ll, int *ur, int hiXY, int minExt, uint
2152   // layerCnt, uint *dirTable, uint *pitchTable, uint *widthTable);
2153   uint couplingFlow(bool rlog,
2154                     odb::Rect& extRect,
2155                     uint trackStep,
2156                     uint ccDist,
2157                     extMeasure* m,
2158                     CoupleAndCompute coupleAndCompute);
2159   uint initPlanes(uint dir,
2160                   uint layerCnt,
2161                   uint* pitchTable,
2162                   uint* widthTable,
2163                   int* ll,
2164                   int* ur);
2165   uint initPlanes(uint dir,
2166                   int* wLL,
2167                   int* wUR,
2168                   uint layerCnt,
2169                   uint* pitchTable,
2170                   uint* widthTable,
2171                   uint* dirTable,
2172                   int* bb_ll,
2173                   bool skipMemAlloc = false);
2174 
2175   uint couplingWindowFlow(bool rlog,
2176                           odb::Rect& extRect,
2177                           uint trackStep,
2178                           uint ccFlag,
2179                           bool doExt,
2180                           extMeasure* m,
2181                           CoupleAndCompute coupleAndCompute);
2182   bool isIncluded(odb::Rect& r, uint dir, int* ll, int* ur);
2183   bool matchDir(uint dir, odb::Rect& r);
2184   bool isIncludedInsearch(odb::Rect& r, uint dir, int* bb_ll, int* bb_ur);
2185 
2186   uint makeTree(uint netId);
2187   uint benchNets(extMainOptions* opt,
2188                  uint netId,
2189                  uint trackCnt,
2190                  odb::ZPtr<odb::ISdb> netSdb);
2191   uint runSolver(extMainOptions* opt, uint netId, int shapeId);
2192 
2193   bool printNetStats(FILE* fp,
2194                      odb::dbBlock* block,
2195                      bool skipRC,
2196                      bool skipDb,
2197                      bool skipPOwer);
2198   void resetSumRCtable();
2199   void addToSumRCtable();
2200   void copyToSumRCtable();
2201   uint getResCapTable(bool lefRC);
2202   double getLoCoupling();
2203   void ccReportProgress();
2204   void measureRC(CoupleOptions& options);
2205   void updateTotalRes(odb::dbRSeg* rseg1,
2206                       odb::dbRSeg* rseg2,
2207                       extMeasure* m,
2208                       double* delta,
2209                       uint modelCnt);
2210   void updateTotalCap(odb::dbRSeg* rseg,
2211                       double frCap,
2212                       double ccCap,
2213                       double deltaFr,
2214                       uint modelIndex);
2215   void updateTotalCap(odb::dbRSeg* rseg,
2216                       extMeasure* m,
2217                       double* deltaFr,
2218                       uint modelCnt,
2219                       bool includeCoupling,
2220                       bool includeDiag = false);
2221   void updateCCCap(odb::dbRSeg* rseg1, odb::dbRSeg* rseg2, double ccCap);
2222   double measureOverUnderCap(extMeasure* m, int x1, int y1, int x2, int y2);
2223   uint initPlanes(uint layerCnt, odb::Rect* bb = NULL);
2224   uint allocateOverUnderMaps(uint layerCnt);
2225   uint initPlanesOld(uint cnt);
2226   uint initPlanesNew(uint cnt, odb::Rect* bb = NULL);
2227   uint makeIntersectPlanes(uint layerCnt);
2228   void deletePlanes(uint layerCnt);
2229   void getBboxPerLayer(odb::Rect* rectTable);
2230 
2231   uint readCmpStats(const char* name,
2232                     uint& tileSze,
2233                     int& X1,
2234                     int& Y1,
2235                     int& X2,
2236                     int& Y2);
2237   uint readCmpFile(const char* name);
2238   int setMinTypMax(bool minModel,
2239                    bool typModel,
2240                    bool maxModel,
2241                    const char* cmp_file,
2242                    bool density_model,
2243                    bool litho,
2244                    int setMin,
2245                    int setTyp,
2246                    int setMax,
2247                    uint cornerCnt);
2248 
2249   extRCModel* getRCmodel(uint n);
2250 
2251   void calcRes0(double* deltaRes,
2252                 uint tgtMet,
2253                 uint width,
2254                 uint len,
2255                 int dist1 = 0,
2256                 int dist2 = 0);
2257   double getLefResistance(uint level, uint width, uint length, uint model);
2258   double getResistance(uint level, uint width, uint len, uint model);
2259   double getFringe(uint met, uint width, uint modelIndex, double& areaCap);
2260   void printNet(odb::dbNet* net, uint netId);
2261   double calcFringe(extDistRC* rc, double deltaFr, bool includeCoupling);
2262   double updateTotalCap(odb::dbRSeg* rseg, double cap, uint modelIndex);
2263   bool updateCoupCap(odb::dbRSeg* rseg1, odb::dbRSeg* rseg2, int jj, double v);
2264   double updateRes(odb::dbRSeg* rseg, double res, uint model);
2265 
2266   // void extCompute(void *a, void *b, int c);
2267 
2268   uint makeGuiBoxes(uint extGuiBoxType);
2269   uint setupSearchDb(const char* bbox, uint debug, odb::ZInterface* Interface);
2270   odb::ZPtr<odb::ISdb> getCcSdb();
2271   odb::ZPtr<odb::ISdb> getNetSdb();
2272   uint computeXcaps(uint boxType);
2273   bool getExtAreaCoords(const char* bbox);
2274   uint getExtBbox(int* x1, int* y1, int* x2, int* y2);
2275   void setExtractionBbox(const char* bbox);
2276 
2277   void setupMapping(uint itermCnt);
2278   uint getMultiples(uint cnt, uint base);
2279   uint getExtLayerCnt(odb::dbTech* tech);
2280   uint addExtModel(odb::dbTech* tech = NULL);
2281   uint readExtRules(const char* name,
2282                     const char* filename,
2283                     int min,
2284                     int typ,
2285                     int max);
2286 
2287   void setBlockFromChip();
2288   void setBlock(odb::dbBlock* block);
getBlock()2289   odb::dbBlock* getBlock() { return _block; }
getTech()2290   odb::dbTech* getTech() { return _tech; }
getRCModel()2291   extRCModel* getRCModel() { return _modelTable->get(0); }
2292 
2293   //	int db_test_wires();
2294 
2295   int db_test_wires(odb::dbDatabase* db = NULL);
2296 
2297   void print_RC(odb::dbRSeg* rc);
2298   void resetMapping(odb::dbBTerm* term, odb::dbITerm* iterm, uint junction);
2299   uint resetMapNodes(odb::dbNet* net);
2300   void setResCapFromLef(odb::dbRSeg* rc,
2301                         uint targetCapId,
2302                         odb::dbShape& s,
2303                         uint len);
2304   bool isTermPathEnded(odb::dbBTerm* bterm, odb::dbITerm* iterm);
2305   uint getCapNodeId(odb::dbWirePath& path, odb::dbNet* net, bool branch);
2306   uint getCapNodeId(odb::dbNet* net,
2307                     odb::dbBTerm* bterm,
2308                     odb::dbITerm* iterm,
2309                     uint junction,
2310                     bool branch = false);
2311   void unlinkExt(std::vector<odb::dbNet*>& nets);
2312   void unlinkCC(std::vector<odb::dbNet*>& nets);
2313   void unlinkRSeg(std::vector<odb::dbNet*>& nets);
2314   void unlinkCapNode(std::vector<odb::dbNet*>& nets);
2315   void removeExt(std::vector<odb::dbNet*>& nets);
2316   void removeExt();
2317   void removeCC(std::vector<odb::dbNet*>& nets);
2318   void removeRSeg(std::vector<odb::dbNet*>& nets);
2319   void removeCapNode(std::vector<odb::dbNet*>& nets);
2320   void removeSdb(std::vector<odb::dbNet*>& nets);
2321   void adjustRC(double resFactor, double ccFactor, double gndcFactor);
2322   void updatePrevControl();
2323   void getPrevControl();
2324 
2325   uint makeBlockRCsegs(bool btermThresholdFlag,
2326                        const char* cmp,
2327                        bool density_model,
2328                        bool litho,
2329                        const char* netNames,
2330                        const char* bbox,
2331                        const char* ibox,
2332                        uint cc_up,
2333                        uint ccFlag,
2334                        int ccBandTracks,
2335                        uint use_signal_table,
2336                        double resBound,
2337                        bool mergeViaRes,
2338                        uint debug,
2339                        int cc_preseve_geom,
2340                        bool re_extract,
2341                        bool eco,
2342                        bool gs,
2343                        bool log,
2344                        odb::ZPtr<odb::ISdb> sdb,
2345                        double ccThres,
2346                        int contextDepth,
2347                        bool overCell,
2348                        const char* extRules,
2349                        odb::ZInterface* context);
2350 
2351   uint getShortSrcJid(uint jid);
2352   void markPathHeadTerm(odb::dbWirePath& path);
2353   void make1stRSeg(odb::dbNet* net,
2354                    odb::dbWirePath& path,
2355                    uint cnid,
2356                    bool skipStartWarning);
2357   uint makeNetRCsegs_old(odb::dbNet* net, double resBound, uint debug = 0);
2358   uint makeNetRCsegs(odb::dbNet* net, bool skipStartWarning = false);
2359   uint addPowerGs(int dir = -1, int* ll = NULL, int* ur = NULL);
2360   uint addSignalGs(int dir = -1, int* ll = NULL, int* ur = NULL);
2361   uint addItermShapesOnPlanes(odb::dbInst* inst,
2362                               bool rotatedFlag,
2363                               bool swap_coords);
2364   uint addObsShapesOnPlanes(odb::dbInst* inst,
2365                             bool rotatedFlag,
2366                             bool swap_coords);
2367   uint addInstShapesOnPlanes(uint dir = 0, int* ll = NULL, int* ur = NULL);
2368   double getViaResistance(odb::dbTechVia* tvia);
2369   double getViaResistance_b(odb::dbVia* via, odb::dbNet* net = NULL);
2370 
2371   void getShapeRC(odb::dbNet* net,
2372                   odb::dbShape& s,
2373                   odb::Point& prevPoint,
2374                   odb::dbWirePathShape& pshape);
2375   void setResAndCap(odb::dbRSeg* rc, double* restbl, double* captbl);
2376   void setBranchCapNodeId(odb::dbNet* net, uint junction);
2377   odb::dbRSeg* addRSeg(odb::dbNet* net,
2378                        std::vector<uint>& rsegJid,
2379                        uint& srcId,
2380                        odb::Point& prevPoint,
2381                        odb::dbWirePath& path,
2382                        odb::dbWirePathShape& pshape,
2383                        bool isBranch,
2384                        double* restbl,
2385                        double* captbl);
2386   uint print_shape(odb::dbShape& shape, uint j1, uint j2);
2387   uint getNodeId(odb::dbWirePath& path, bool branch, uint* nodeType);
2388   uint getNodeId(odb::dbWirePathShape& pshape, uint* nodeType);
2389   uint computePathDir(odb::Point& p1, odb::Point& p2, uint* length);
2390   uint openSpefFile(char* filename, uint mode);
2391 
2392   //-------------------------------------------------------------- SPEF
2393   uint match(char* filename,
2394              bool m_map,
2395              const char* dbCornerName,
2396              int corner,
2397              int spefCorner);
2398   uint calibrate(char* filename,
2399                  bool m_map,
2400                  float upperLimit,
2401                  float lowerLimit,
2402                  const char* dbCornerName,
2403                  int corner,
2404                  int spefCorner);
2405   void setUniqueExttreeCorner();
2406   uint readSPEF(char* filename,
2407                 char* netNames,
2408                 bool force,
2409                 bool useIds,
2410                 bool rConn,
2411                 char* nodeCoord,
2412                 bool rCap,
2413                 bool rOnlyCCcap,
2414                 bool rRes,
2415                 float cc_thres,
2416                 float cc_gnd_factor,
2417                 float length_unit,
2418                 bool m_map,
2419                 bool noCapNumCollapse,
2420                 char* capNodeMapFile,
2421                 bool log,
2422                 int corner,
2423                 double low,
2424                 double up,
2425                 char* excludeSubWord,
2426                 char* subWord,
2427                 char* statsFile,
2428                 const char* dbCornerName,
2429                 const char* calibrateBaseCorner,
2430                 int spefCorner,
2431                 int fixLoop,
2432                 bool keepLoadedCorner,
2433                 bool stampWire = false,
2434                 odb::ZPtr<odb::ISdb> netSdb = NULL,
2435                 uint testParsing = 0,
2436                 bool moreToRead = false,
2437                 bool diff = false,
2438                 bool calib = false,
2439                 int app_ptint_limit = 0);
2440   uint readSPEFincr(char* filename);
2441   uint writeSPEF(bool stop);
2442   uint writeSPEF(uint netId,
2443                  bool single_pi,
2444                  uint debug,
2445                  int corner,
2446                  const char* corner_name);
2447   uint writeSPEF(char* filename,
2448                  char* netNames,
2449                  bool useIds,
2450                  bool noNameMap,
2451                  char* nodeCoord,
2452                  bool termJxy,
2453                  const char* excludeCells,
2454                  const char* capUnit,
2455                  const char* resUnit,
2456                  bool gzFlag,
2457                  bool stopAfterMap,
2458                  bool wClock,
2459                  bool wConn,
2460                  bool wCap,
2461                  bool wOnlyCCcap,
2462                  bool wRes,
2463                  bool noCnum,
2464                  bool initOnly,
2465                  bool single_pi,
2466                  bool no_backslash,
2467                  int corner,
2468                  const char* corner_name,
2469                  bool flatten,
2470                  bool parallel);
2471   uint writeNetSPEF(odb::dbNet* net, double resBound, uint debug);
2472   uint makeITermCapNode(uint id, odb::dbNet* net);
2473   uint makeBTermCapNode(uint id, odb::dbNet* net);
2474 
2475   void initIncrementalSpef(const char* origp,
2476                            const char* newp,
2477                            const char* excludeCell,
2478                            bool noBackSlash);
2479   void reportTotalCap(const char* file,
2480                       bool cap,
2481                       bool res,
2482                       double ccmult,
2483                       const char* ref,
2484                       const char* rd_file);
2485   void reportTotalCc(const char* file, const char* ref, const char* rd_file);
2486   double getTotalNetCap(uint netId, uint cornerNum);
2487   void extDump(char* filename,
2488                bool openTreeFile,
2489                bool closeTreeFile,
2490                bool ccCapGeom,
2491                bool ccNetGeom,
2492                bool trackCnt,
2493                bool signal,
2494                bool power,
2495                uint layer);
2496   void extCount(bool signalWireSeg, bool powerWireSeg);
2497   void initContextArray();
2498   void initDgContextArray();
2499   void removeDgContextArray();
2500 
2501   // ruLESgeN
2502   bool getFirstShape(odb::dbNet* net, odb::dbShape& shape);
2503   uint readProcess(const char* name, const char* file);
2504   uint rulesGen(const char* name,
2505                 const char* topDir,
2506                 const char* rulesFile,
2507                 int pattern,
2508                 bool skipSolv,
2509                 bool readSolv,
2510                 bool runSolver,
2511                 bool keepFile);
2512   uint metRulesGen(const char* name,
2513                    const char* topDir,
2514                    const char* rulesFile,
2515                    int pattern,
2516                    bool writeFiles,
2517                    bool readFiles,
2518                    bool runSolver,
2519                    bool keepFile,
2520                    uint met);
2521   uint writeRules(const char* name,
2522                   const char* topDir,
2523                   const char* rulesFile,
2524                   int pattern,
2525                   bool readDb = false,
2526                   bool readFiles = false);
2527   uint benchWires(extMainOptions* options);
2528   uint GenExtRules(const char* rulesFileName, int pattern);
getPtFile()2529   FILE* getPtFile() { return _ptFile; };
2530   static void destroyExtSdb(std::vector<odb::dbNet*>& nets, void* ext);
2531   void writeIncrementalSpef(char* filename,
2532                             std::vector<odb::dbNet*>& buf_nets,
2533                             uint nn,
2534                             bool dual_incr_spef);
2535   void writeIncrementalSpef(std::vector<odb::dbNet*>& buf_nets,
2536                             INCR_SPEF_TYPE type,
2537                             bool coupled_rc,
2538                             bool dual_incr_spef);
2539   void writeIncrementalSpef(Darr<odb::dbNet*>& buf_nets,
2540                             odb::dbBlock* block,
2541                             INCR_SPEF_TYPE type,
2542                             bool coupled_rc,
2543                             bool dual_incr_spef);
2544   void writeIncrementalSpef(Darr<odb::dbNet*>& buf_nets,
2545                             std::vector<odb::dbNet*>& ccHaloNets,
2546                             odb::dbBlock* block,
2547                             INCR_SPEF_TYPE type,
2548                             bool coupled_rc,
2549                             bool dual_incr_spef);
2550   void writeIncrementalSpef(std::vector<odb::dbNet*>& buf_nets,
2551                             odb::dbBlock* block,
2552                             INCR_SPEF_TYPE type,
2553                             bool coupled_rc,
2554                             bool dual_incr_spef);
2555   void writeIncrementalSpef(std::vector<odb::dbNet*>& buf_nets,
2556                             std::vector<odb::dbNet*>& ccHaloNets,
2557                             odb::dbBlock* block,
2558                             INCR_SPEF_TYPE type,
2559                             bool coupled_rc,
2560                             bool dual_incr_spef);
2561   void writeSpef(char* filename,
2562                  std::vector<odb::dbNet*>& tnets,
2563                  int corner,
2564                  char* coord);
2565   int getExtCornerIndex(odb::dbBlock* block, const char* cornerName);
2566 
2567   void initExtractedCorners(odb::dbBlock* block);
2568 
2569   void addDummyCorners(uint cornerCnt);
2570   static void addDummyCorners(odb::dbBlock* block, uint cnt, Logger* logger);
2571   char* addRCCorner(const char* name, int model, int userDefined = 1);
2572   char* addRCCornerScaled(const char* name,
2573                           uint model,
2574                           float resFactor,
2575                           float ccFactor,
2576                           float gndFactor);
2577   void getCorners(std::list<std::string>& ecl);
2578   void deleteCorners();
2579   void cleanCornerTables();
2580   int getDbCornerIndex(const char* name);
2581   int getDbCornerModel(const char* name);
2582   bool setCorners(const char* rulesFileName, const char* cmp_file);
2583   int getProcessCornerDbIndex(int pcidx);
2584   void getScaledCornerDbIndex(int pcidx, int& sidx, int& scdbIdx);
2585   void getScaledRC(int sidx, double& res, double& cap);
2586   void getScaledGndC(int sidx, double& cap);
2587   void getScaledCC(int sidx, double& cap);
2588   void genScaledExt();
2589   // void makeCornerNameMap(char *buff, int cornerCnt, bool spef);
2590   void makeCornerNameMap();
2591   void getExtractedCorners();
2592   void makeCornerMapFromExtControl();
2593   bool checkLayerResistance();
2594 
2595   uint getNetBbox(odb::dbNet* net, odb::Rect& maxRect);
2596   uint mkSignalTables2(uint* nm_step,
2597                        int* bb_ll,
2598                        int* bb_ur,
2599                        Ath__array1D<uint>*** sdbSignalTable,
2600                        Ath__array1D<uint>* sdbPowerTable,
2601                        Ath__array1D<uint>*** instTable,
2602                        uint* bucketCnt);
2603   uint addSignalNets2(uint dir,
2604                       int* lo_sdb,
2605                       int* hi_sdb,
2606                       int* bb_ll,
2607                       int* bb_ur,
2608                       uint* bucketSize,
2609                       uint wtype,
2610                       Ath__array1D<uint>*** sdbSignalTable,
2611                       Ath__array1D<uint>* tmpNetIdTable,
2612                       odb::dbCreateNetUtil* createDbNet = NULL);
2613 
2614   uint addPowerNets2(uint dir,
2615                      int* bb_ll,
2616                      int* bb_ur,
2617                      uint wtype,
2618                      Ath__array1D<uint>* sdbPowerTable,
2619                      odb::dbCreateNetUtil* createDbNet = NULL);
2620   void resetNetSpefFlag(Ath__array1D<uint>* tmpNetIdTable);
2621 
2622   int fill_gs3(int dir,
2623                int* ll,
2624                int* ur,
2625                int* lo_gs,
2626                int* hi_gs,
2627                uint layerCnt,
2628                uint* dirTable,
2629                uint* pitchTable,
2630                uint* widthTable,
2631                int* sdbTable_ll,
2632                int* sdbTable_ur,
2633                uint* bucketSize,
2634                Ath__array1D<uint>* powerNetTable,
2635                Ath__array1D<uint>* tmpNetIdTable,
2636                Ath__array1D<uint>*** sdbSignalTable,
2637                Ath__array1D<uint>*** instGsTable,
2638                odb::dbCreateNetUtil* createDbNet = NULL);
2639 
2640   void reportTableNetCnt(uint* sdbBucketCnt,
2641                          Ath__array1D<uint>*** sdbSignalTable);
2642   uint sBoxCounter(odb::dbNet* net, uint& maxWidth);
2643   uint powerWireCounter(uint& maxWidth);
2644   uint signalWireCounter(uint& maxWidth);
2645   bool getRotatedFlag();
2646   bool enableRotatedFlag();
2647   uint addShapeOnGs(odb::dbShape* s, bool swap_coords);
2648   uint addSBoxOnGs(odb::dbSBox* s, bool swap_coords);
2649 
2650   uint addMultipleRectsOnSearch(odb::Rect& r,
2651                                 uint level,
2652                                 uint dir,
2653                                 uint id,
2654                                 uint shapeId,
2655                                 uint wtype);
2656 
2657   //--------------- Window
2658   extWindow* initWindowSearch(odb::Rect& extRect,
2659                               uint trackStep,
2660                               uint ccFlag,
2661                               uint modelLevelCnt,
2662                               extMeasure* m);
2663   void fillWindowGs(extWindow* W,
2664                     int* sdbTable_ll,
2665                     int* sdbTable_ur,
2666                     uint* bucketSize,
2667                     Ath__array1D<uint>* powerNetTable,
2668                     Ath__array1D<uint>* tmpNetIdTable,
2669                     Ath__array1D<uint>*** sdbSignalTable,
2670                     Ath__array1D<uint>*** instGsTable,
2671                     odb::dbCreateNetUtil* createDbNet = NULL);
2672   uint fillWindowSearch(extWindow* W,
2673                         int* lo_sdb,
2674                         int* hi_sdb,
2675                         int* sdbTable_ll,
2676                         int* sdbTable_ur,
2677                         uint* bucketSize,
2678                         Ath__array1D<uint>* powerNetTable,
2679                         Ath__array1D<uint>* tmpNetIdTable,
2680                         Ath__array1D<uint>*** sdbSignalTable,
2681                         odb::dbCreateNetUtil* createDbNet = NULL);
2682   uint addShapeOnGS(odb::dbNet* net,
2683                     uint sId,
2684                     odb::Rect& r,
2685                     bool plane,
2686                     odb::dbTechLayer* layer,
2687                     bool gsRotated,
2688                     bool swap_coords,
2689                     int dir,
2690                     bool specialWire = false,
2691                     odb::dbCreateNetUtil* createDbNet = NULL);
2692   uint extractWindow(bool rlog,
2693                      extWindow* W,
2694                      odb::Rect& extRect,
2695                      bool single_sdb,
2696                      extMeasure* m,
2697                      CoupleAndCompute coupleAndCompute,
2698                      int* sdbTable_ll = NULL,
2699                      int* sdbTable_ur = NULL,
2700                      uint* bucketSize = NULL,
2701                      Ath__array1D<uint>* powerNetTable = NULL,
2702                      Ath__array1D<uint>* tmpNetIdTable = NULL,
2703                      Ath__array1D<uint>*** sdbSignalTable = NULL,
2704                      Ath__array1D<uint>*** instGsTable = NULL);
2705   uint couplingTileFlow(bool rlog,
2706                         odb::Rect& extRect,
2707                         extMeasure* m,
2708                         CoupleAndCompute coupleAndCompute);
2709 
2710   uint createWindowsDB(bool rlog,
2711                        odb::Rect& extRect,
2712                        uint trackStep,
2713                        uint ccFlag,
2714                        uint use_signal_tables);
2715   uint fillWindowsDB(bool rlog, odb::Rect& extRect, uint use_signal_tables);
2716   uint fill_gs4(int dir,
2717                 int* ll,
2718                 int* ur,
2719                 int* lo_gs,
2720                 int* hi_gs,
2721                 uint layerCnt,
2722                 uint* dirTable,
2723                 uint* pitchTable,
2724                 uint* widthTable,
2725                 odb::dbCreateNetUtil* createDbNet);
2726 
2727   uint createNetShapePropertires(odb::dbBlock* blk);
2728   void resetGndCaps();
2729   uint rcGenTile(odb::dbBlock* blk);
2730   uint mkTileNets(uint dir,
2731                   int* lo_sdb,
2732                   int* hi_sdb,
2733                   bool powerNets,
2734                   odb::dbCreateNetUtil* createDbNet,
2735                   uint& rcCnt,
2736                   bool countOnly = false);
2737   uint mkTilePowerNets(uint dir,
2738                        int* lo_sdb,
2739                        int* hi_sdb,
2740                        odb::dbCreateNetUtil* createDbNet);
2741   uint rcNetGen(odb::dbNet* net);
2742   uint rcGen(const char* netNames,
2743              double resBound,
2744              bool mergeViaRes,
2745              uint debug,
2746              bool rlog,
2747              odb::ZInterface* Interface);
2748 
2749   void disableRotatedFlag();
2750   FILE* openSearchFile(char* name);
2751   void closeSearchFile();
2752 
2753   void addExtWires(odb::Rect& r,
2754                    extWireBin*** wireBinTable,
2755                    uint netId,
2756                    int shapeId,
2757                    odb::dbTechLayer* layer,
2758                    uint* nm_step,
2759                    int* bb_ll,
2760                    int* bb_ur,
2761                    AthPool<extWire>* wpool,
2762                    bool cntxFlag);
2763   extWireBin*** mkSignalBins(uint binSize,
2764                              int* bb_ll,
2765                              int* bb_ur,
2766                              uint* bucketCnt,
2767                              AthPool<extWire>* wpool,
2768                              bool cntxFlag);
2769   uint addNets3(uint dir,
2770                 int* lo_sdb,
2771                 int* hi_sdb,
2772                 int* bb_ll,
2773                 int* bb_ur,
2774                 uint bucketSize,
2775                 extWireBin*** wireBinTable,
2776                 odb::dbCreateNetUtil* createDbNet);
2777   uint addNets3GS(uint dir,
2778                   int* lo_sdb,
2779                   int* hi_sdb,
2780                   int* bb_ll,
2781                   int* bb_ur,
2782                   uint bucketSize,
2783                   extWireBin*** wireBinTable,
2784                   odb::dbCreateNetUtil* createDbNet);
2785   Ath__array1D<uint>*** mkInstBins(uint binSize,
2786                                    int* bb_ll,
2787                                    int* bb_ur,
2788                                    uint* bucketCnt);
2789   uint addInsts(uint dir,
2790                 int* lo_gs,
2791                 int* hi_gs,
2792                 int* bb_ll,
2793                 int* bb_ur,
2794                 uint bucketSize,
2795                 Ath__array1D<uint>*** wireBinTable,
2796                 odb::dbCreateNetUtil* createDbNet);
2797 
2798   void printLimitArray(int** limitArray, uint layerCnt);
2799   uint mkTileBoundaries(bool skipPower, bool skipInsts);
2800   uint mkNetPropertiesForRsegs(odb::dbBlock* blk, uint dir);
2801   uint rcGenBlock(odb::dbBlock* block = NULL);
2802   void writeMapping(odb::dbBlock* block = NULL);
2803   uint invalidateNonDirShapes(odb::dbBlock* blk, uint dir, bool setMainNet);
2804 
2805   uint getNetBbox(odb::dbNet* net, odb::Rect* maxRect[2]);
2806 
2807   static odb::dbRSeg* getRseg(odb::dbNet* net, uint shapeId, Logger* logger);
2808 
2809   static uint assemblyExt(odb::dbBlock* mainBlock,
2810                           odb::dbBlock* blk,
2811                           Logger* logger);
2812   static uint assemblyExt__2(odb::dbBlock* mainBlock,
2813                              odb::dbBlock* blk,
2814                              Logger* logger);
2815   static odb::dbNet* getDstNet(odb::dbNet* net,
2816                                odb::dbBlock* dstBlock,
2817                                Ath__parser* parser);
2818   static odb::dbRSeg* getMainRSeg(odb::dbNet* srcNet,
2819                                   int srcShapeId,
2820                                   odb::dbNet* dstNet);
2821   static odb::dbRSeg* getMainRSeg2(odb::dbNet* srcNet,
2822                                    int srcShapeId,
2823                                    odb::dbNet* dstNet);
2824   static odb::dbRSeg* getMainRSeg3(odb::dbNet* srcNet,
2825                                    int srcShapeId,
2826                                    odb::dbNet* dstNet);
2827   static uint assemblyCCs(odb::dbBlock* mainBlock,
2828                           odb::dbBlock* blk,
2829                           uint cornerCnt,
2830                           uint& missCCcnt,
2831                           Logger* logger);
2832   static odb::dbRSeg* getMainRseg(odb::dbCapNode* node,
2833                                   odb::dbBlock* blk,
2834                                   Ath__parser* parser,
2835                                   Logger* logger);
2836   static void updateRseg(odb::dbRSeg* rc1, odb::dbRSeg* rseg2, uint cornerCnt);
2837   static uint assembly_RCs(odb::dbBlock* mainBlock,
2838                            odb::dbBlock* blk,
2839                            uint cornerCnt,
2840                            Logger* logger);
2841 
2842   // 021710D BEGIN
2843   uint addRCtoTop(odb::dbBlock* blk, bool write_spef);
2844   uint createCapNodes(odb::dbNet* net,
2845                       odb::dbNet* parentNet,
2846                       uint* capNodeMap,
2847                       uint baseNum);
2848   uint createRSegs(odb::dbNet* net, odb::dbNet* parentNet, uint* capNodeMap);
2849   // uint createCCsegs(odb::dbNet *net, odb::dbNet *parentNet, uint
2850   // *capNodeMap);
2851   uint write_spef_nets(bool flatten, bool parallel);
2852   // uint adjustCapNode(odb::dbNet *net, odb::dbITerm *from_child_iterm, uint
2853   // node_num);
2854   extSpef* getSpef();
2855   static uint printRSegs(odb::dbNet* net, Logger* logger);
2856   // 021710D END
2857 
2858   // 022110D BEGIN
2859   void adjustChildNode(odb::dbCapNode* childNode,
2860                        odb::dbNet* parentNet,
2861                        uint* capNodeMap);
2862   bool createParentCapNode(odb::dbCapNode* node,
2863                            odb::dbNet* parentNet,
2864                            uint nodeNum,
2865                            uint* capNodeMap,
2866                            uint baseNum);
2867   uint adjustParentNode(odb::dbNet* net,
2868                         odb::dbITerm* from_child_iterm,
2869                         uint node_num);
2870   uint createCCsegs(odb::dbNet* net,
2871                     odb::dbNet* parentNet,
2872                     odb::dbNet* topDummyNet,
2873                     uint* capNodeMap,
2874                     uint baseNum);
2875   // 022110D END
2876 
2877   // 022210D BEGIN
2878   uint markCCsegs(odb::dbBlock* blk, bool flag);
2879   // 022210D END
2880 
2881   // 022310D BEGIN
2882   void createTop1stRseg(odb::dbNet* net, odb::dbNet* parentNet);
2883   // 022310D END
2884 
2885   // 021111D BEGIN
2886   uint getLayerSearchBoundaries(odb::dbTechLayer* layer,
2887                                 int* xyLo,
2888                                 int* xyHi,
2889                                 uint* pitch);
2890   void railConn(uint dir,
2891                 odb::dbTechLayer* layer,
2892                 odb::dbNet* net,
2893                 int* xyLo,
2894                 int* xyHi,
2895                 uint* pitch);
2896   void railConn(odb::dbNet* net);
2897   void railConn2(odb::dbNet* net);
2898   bool isSignalNet(odb::dbNet* net);
2899   uint powerRCGen();
2900   // 021111D END
2901   // 021311D BEGIN
2902   uint mergeRails(uint dir,
2903                   std::vector<odb::dbBox*>& boxTable,
2904                   std::vector<odb::Rect*>& mergeTable);
2905   odb::dbITerm* findConnect(odb::dbInst* inst,
2906                             odb::dbNet* net,
2907                             odb::dbNet* targetNet);
2908   uint getITermConn2(uint dir,
2909                      odb::dbWireEncoder& encoder,
2910                      odb::dbWire* wire,
2911                      odb::dbNet* net,
2912                      int* xy,
2913                      int* xy2);
2914   uint getITermConn(uint dir,
2915                     odb::dbWireEncoder& encoder,
2916                     odb::dbWire* wire,
2917                     odb::dbNet* net,
2918                     int* xy,
2919                     int* xy2);
2920   uint viaAndInstConn(uint dir,
2921                       uint width,
2922                       odb::dbTechLayer* layer,
2923                       odb::dbWireEncoder& encoder,
2924                       odb::dbWire* wire,
2925                       odb::dbNet* net,
2926                       odb::Rect* w,
2927                       bool skipSideMetalFlag);
2928   odb::dbNet* createRailNet(odb::dbNet* pnet,
2929                             odb::dbTechLayer* layer,
2930                             odb::Rect* w);
2931   // void print_shapes(odb::dbWire * wire);
2932   uint print_shapes(FILE* fp, odb::dbWire* wire);
2933   // 021311D END
2934   // 021411D BEGIN
2935   FILE* openNanoFile(const char* name,
2936                      const char* name2,
2937                      const char* suffix,
2938                      const char* perms);
2939   void openNanoFiles();
2940   void closeNanoFiles();
2941   void setupNanoFiles(odb::dbNet* net);
2942   void writeResNode(FILE* fp, odb::dbCapNode* capNode, uint level);
2943   double writeRes(FILE* fp,
2944                   odb::dbNet* net,
2945                   uint level,
2946                   uint width,
2947                   uint dir,
2948                   bool skipFirst);
2949   // 021411D END
2950   // 021511D BEGIN
2951   void writeViaRC(FILE* fp,
2952                   uint level,
2953                   odb::dbTechLayer* layer,
2954                   odb::dbBox* v,
2955                   odb::dbBox* w);
2956   uint connectStackedVias(odb::dbNet* net,
2957                           odb::dbTechLayer* layer,
2958                           bool mergeViaRes);
2959   uint via2viaConn(odb::dbNet* net,
2960                    odb::dbBox* v,
2961                    odb::dbTechLayer* layer,
2962                    bool mergeviaRes);
2963   // 021511D END
2964   // 021611D BEGIN
2965   void writeSubckt(FILE* fp,
2966                    const char* keyword,
2967                    const char* vdd,
2968                    const char* std,
2969                    const char* cont);
2970   void writeCapNodes(FILE* fp,
2971                      odb::dbNet* net,
2972                      uint level,
2973                      bool onlyVias,
2974                      bool skipFirst);
2975   void writeCapNodes_0713(FILE* fp, odb::dbNet* net, uint level, bool onlyVias);
2976   // 021611D END
2977   // 021811D BEGIN
2978   bool specialMasterType(odb::dbInst* inst);
2979   // 021811D END
2980   // 021911D BEGIN
2981   uint iterm2Vias(odb::dbInst* inst, odb::dbNet* net);
2982   uint getPowerNets(std::vector<odb::dbNet*>& powerNetTable);
2983   float getPowerViaRes(odb::dbBox* v, float val);
2984   uint findHighLevelPinMacros(std::vector<odb::dbInst*>& instTable);
2985   uint writeViaInfo(FILE* fp,
2986                     std::vector<odb::dbBox*>& viaTable,
2987                     bool m1Vias,
2988                     bool power);
2989   // 021911D END
2990 
2991   void set_adjust_colinear(bool v);
2992   // 032811D END
2993   uint writeViaInfo_old(FILE* fp,
2994                         std::vector<odb::dbBox*>& viaTable,
2995                         bool m1Vias);
2996   uint writeViaCoords(FILE* fp,
2997                       std::vector<odb::dbBox*>& viaTable,
2998                       bool m1Vias);
2999   void writeViaName(char* nodeName,
3000                     odb::dbBox* v,
3001                     uint level,
3002                     const char* post);
3003   void writeViaName(FILE* fp, odb::dbBox* v, uint level, const char* post);
3004   void writeViaNameCoords(FILE* fp, odb::dbBox* v);
3005   // 041311D END
3006   float computeViaResistance(odb::dbBox* viaBox, uint& cutCount);
3007   // 041511D END
3008   void printItermNodeSubCkt(FILE* fp, std::vector<uint>& iTable);
3009   void printViaNodeSubCkt(FILE* fp, std::vector<odb::dbBox*>& viaTable);
3010   // 042711D END
3011 
3012   // 061711D BEGIN
3013   uint mergeStackedVias(FILE* fp,
3014                         odb::dbNet* net,
3015                         std::vector<odb::dbBox*>& viaTable,
3016                         odb::dbBox* botVia,
3017                         FILE* fp1 = NULL);
3018   // 061711D END
3019   // 061911D BEGIN
3020   uint stackedViaConn(FILE* fp, std::vector<odb::dbBox*>& allViaTable);
3021   bool skipSideMetal(std::vector<odb::dbBox*>& viaTable,
3022                      uint level,
3023                      odb::dbNet* net,
3024                      odb::Rect* w);
3025   bool overlapWithMacro(odb::Rect& w);
3026   // 061911D END
3027 
3028   // 062511D BEGIN
3029   void powerWireConn(odb::Rect* w,
3030                      uint dir,
3031                      odb::dbTechLayer* layer,
3032                      odb::dbNet* net);
3033   const char* getBlockType(odb::dbMaster* m);
3034   void sortViasXY(uint dir, std::vector<odb::dbBox*>& viaTable);
3035   // 062511D END
3036   // 063011D BEGIN
3037   void writeViaRes(FILE* fp, odb::dbNet* net, uint level);
3038   void addUpperVia(uint ii, odb::dbBox* v);
3039   void writeViaResistors(FILE* fp,
3040                          uint ii,
3041                          FILE* fp1,
3042                          bool skipWireConn = false);
3043   // 063011D END
3044   // 071211D BEGIN
3045   void writeGeomHeader(FILE* fp, const char* vdd);
3046   void writeResNode(char* nodeName, odb::dbCapNode* capNode, uint level);
3047   float micronCoords(int xy);
3048   void writeSubcktNode(char* capNodeName, bool highMetal, bool vdd);
3049   void setPowerExtOptions(bool skip_power_stubs,
3050                           const char* exclude_cells,
3051                           bool skip_m1_caps,
3052                           const char* f);
3053   bool markExcludedCells();
3054   float distributeCap(FILE* fp, odb::dbNet* net);
3055 
3056   // 071211D END
3057   // 021712D BEGIN
3058   uint readPowerSupplyCoords(char* filename);
3059   uint addPowerSources(std::vector<odb::dbBox*>& viaTable,
3060                        bool power,
3061                        uint level,
3062                        odb::Rect* powerWire);
3063   char* getPowerSourceName(bool power, uint level, uint vid);
3064   char* getPowerSourceName(uint level, uint vid);
3065   void writeViaInfo(FILE* fp, bool power);
3066   void addPowerSourceName(uint ii, char* sname);
3067   // 021712D END
3068   // 062212D
3069   void writeResCoords(FILE* fp,
3070                       odb::dbNet* net,
3071                       uint level,
3072                       uint width,
3073                       uint dir);
3074   void writeViaName_xy(char* nodeName,
3075                        odb::dbBox* v,
3076                        uint bot,
3077                        uint top,
3078                        uint level,
3079                        const char* post = "");
3080   void writeInternalNode_xy(odb::dbCapNode* capNode, FILE* fp);
3081   void writeInternalNode_xy(odb::dbCapNode* capNode, char* buff);
3082   void createNode_xy(odb::dbCapNode* capNode,
3083                      int x,
3084                      int y,
3085                      int level,
3086                      odb::dbITerm* t = NULL);
3087   // void setNodeCoords_xy(FILE *fp, odb::dbNet *net);
3088   uint setNodeCoords_xy(odb::dbNet* net, int level);
3089   bool sameJunctionPoint(int xy[2], int BB[2], uint width, uint dir);
3090 
3091   // 071912D
3092   bool fisrt_markInst_UserFlag(odb::dbInst* inst, odb::dbNet* net);
3093 
3094   // 093012D
3095   bool matchLayerDir(odb::dbBox* rail,
3096                      odb::dbTechLayerDir layerDir,
3097                      int level,
3098                      bool debug);
3099   // 100512D
3100   void addSubcktStatement(const char* cirFile1, const char* subcktFile1);
3101   void setPrefix(char* prefix);
3102   uint getITermPhysicalConn(uint dir,
3103                             uint level,
3104                             odb::dbWireEncoder& encoder,
3105                             odb::dbWire* wire,
3106                             odb::dbNet* net,
3107                             int* xy,
3108                             int* xy2);
3109   void getSpecialItermShapes(odb::dbInst* inst,
3110                              odb::dbNet* specialNet,
3111                              uint dir,
3112                              uint level,
3113                              int* xy,
3114                              int* xy2,
3115                              std::vector<odb::Rect*>& rectTable,
3116                              std::vector<odb::dbITerm*>& itermTable);
3117   bool topHierBlock();
3118 
3119   // 101812D
3120   void writeNegativeCoords(char* buf,
3121                            int netId,
3122                            int x,
3123                            int y,
3124                            int level,
3125                            const char* post = "");
3126 
3127   // 101912D
3128   void writeViasAndClose(odb::dbNet* net, bool m1Vias);
3129   void closeNanoFilesDomainVDD(char* netName);
3130   void closeNanoFilesDomainGND(char* netName);
3131   void netDirPrefix(char* prefix, char* netName);
3132   FILE* openNanoFileNet(char* netname,
3133                         const char* name,
3134                         const char* name2,
3135                         const char* suffix,
3136                         const char* perms);
3137   void openNanoFilesDomain(odb::dbNet* pNet);
3138   void addSubcktStatementDomain(const char* cirFile1,
3139                                 const char* subcktFile1,
3140                                 const char* netName);
3141   void initMappingTables();
3142   void allocMappingTables(int n1, int n2, int n3);
3143   // 102812D
3144   uint addSboxesOnSearch(odb::dbNet* net);
3145   odb::Rect* getRect_SBox(Ath__array1D<uint>* table,
3146                           uint ii,
3147                           bool filter,
3148                           uint dir,
3149                           uint& maxWidth);
3150   uint mergePowerWires(uint dir,
3151                        uint level,
3152                        std::vector<odb::Rect*>& mergeTable);
3153   void railConnOpt(odb::dbNet* net);
3154   uint initPowerSearch();
3155   uint overlapPowerWires(std::vector<odb::Rect*>& mergeTableHi,
3156                          std::vector<odb::Rect*>& mergeTableLo,
3157                          std::vector<odb::Rect*>& resultTable);
3158   odb::dbBox* createMultiVia(uint top, uint bot, odb::Rect* r);
3159   void mergeViasOnMetal_1(odb::Rect* w,
3160                           odb::dbNet* pNet,
3161                           uint level,
3162                           std::vector<odb::dbBox*>& viaTable);
3163   uint addGroupVias(uint level,
3164                     odb::Rect* w,
3165                     std::vector<odb::dbBox*>& viaTable);
3166   uint mergeStackedViasOpt(FILE* fp,
3167                            odb::dbNet* net,
3168                            std::vector<odb::dbBox*>& viaSearchTable,
3169                            odb::dbBox* botVia,
3170                            FILE* fp1,
3171                            uint stackLevel = 1);
3172   // 111112D
3173   odb::dbCapNode* getITermPhysicalConnRC(odb::dbCapNode* srcCapNode,
3174                                          uint level,
3175                                          uint dir,
3176                                          odb::dbNet* net,
3177                                          int* xy,
3178                                          int* xy2,
3179                                          bool macro);
3180   uint viaAndInstConnRC(uint dir,
3181                         uint width,
3182                         odb::dbTechLayer* layer,
3183                         odb::dbNet* net,
3184                         odb::dbNet* orig_power_net,
3185                         odb::Rect* w,
3186                         bool skipSideMetalFlag);
3187   void powerWireConnRC(odb::Rect* w,
3188                        uint dir,
3189                        odb::dbTechLayer* layer,
3190                        odb::dbNet* net);
3191   odb::dbCapNode* getITermConnRC(odb::dbCapNode* srcCapNode,
3192                                  uint level,
3193                                  uint dir,
3194                                  odb::dbNet* net,
3195                                  int* xy,
3196                                  int* xy2);
3197   int _last_node_xy[2];
3198   odb::dbCapNode* getPowerCapNode(odb::dbNet* net, int xy, uint level);
3199   odb::dbCapNode* makePowerRes(odb::dbCapNode* srcCap,
3200                                uint dir,
3201                                int xy[2],
3202                                uint level,
3203                                uint width,
3204                                uint objId,
3205                                int type);
3206   void createNode_xy_RC(char* buf,
3207                         odb::dbCapNode* capNode,
3208                         int x,
3209                         int y,
3210                         int level);
3211   bool _wireInfra;
3212   void writeResNodeRC(char* nodeName, odb::dbCapNode* capNode, uint level);
3213   void writeResNodeRC(FILE* fp, odb::dbCapNode* capNode, uint level);
3214   double writeResRC(FILE* fp,
3215                     odb::dbNet* net,
3216                     uint level,
3217                     uint width,
3218                     uint dir,
3219                     bool skipFirst,
3220                     bool reverse,
3221                     bool onlyVias,
3222                     bool caps,
3223                     int xy[2]);
3224   void writeCapNodesRC(FILE* fp,
3225                        odb::dbNet* net,
3226                        uint level,
3227                        bool onlyVias,
3228                        bool skipFirst);
3229   void writeViaResistorsRC(FILE* fp, uint ii, FILE* fp1);
3230   void viaTagByCapNode(odb::dbBox* v, odb::dbCapNode* cap);
3231   char* getViaResNode(odb::dbBox* v, const char* propName);
3232   void writeMacroItermConns(odb::dbNet* net);
3233   void setupDirNaming();
3234   odb::Rect _extMaxRect;
3235   bool filterPowerGeoms(odb::dbSBox* s, uint targetDir, uint& maxWidth);
3236 
3237   // 031313D
3238   uint iterm2Vias_cells(odb::dbInst* inst, odb::dbITerm* connectedPowerIterm);
3239   void writeCapNodesRC(FILE* fp,
3240                        odb::dbNet* net,
3241                        uint level,
3242                        bool onlyVias,
3243                        std::vector<odb::dbCapNode*>& capNodeTable);
3244   void writeOneCapNode(FILE* fp,
3245                        odb::dbCapNode* capNode,
3246                        uint level,
3247                        bool onlyVias);
3248 
3249   // 032613D
3250   void findViaMainCoord(odb::dbNet* net, char* buff);
3251   void replaceItermCoords(odb::dbNet* net, uint dir, int xy[2]);
3252 
3253   // 041713D
3254   void formOverlapVias(std::vector<odb::Rect*> mergeTable[16],
3255                        odb::dbNet* pNet);
3256 
3257   uint benchVerilog(FILE* fp);
3258   uint benchVerilog_bterms(FILE* fp,
3259                            odb::dbIoType iotype,
3260                            const char* prefix,
3261                            const char* postfix,
3262                            bool v = false);
3263   uint benchVerilog_assign(FILE* fp);
3264 
3265   void setMinRC(uint ii, uint jj, extDistRC* rc);
3266   void setMaxRC(uint ii, uint jj, extDistRC* rc);
3267 };
3268 
3269 }  // namespace rcx
3270 
3271 #endif
3272