1 /*
2  *   Copyright (C) 1988-1991 Yale University
3  *
4  *   This work is distributed in the hope that it will be useful; you can
5  *   redistribute it and/or modify it under the terms of the
6  *   GNU General Public License as published by the Free Software Foundation;
7  *   either version 2 of the License,
8  *   or any later version, on the following conditions:
9  *
10  *   (a) YALE MAKES NO, AND EXPRESSLY DISCLAIMS
11  *   ALL, REPRESENTATIONS OR WARRANTIES THAT THE MANUFACTURE, USE, PRACTICE,
12  *   SALE OR
13  *   OTHER DISPOSAL OF THE SOFTWARE DOES NOT OR WILL NOT INFRINGE UPON ANY
14  *   PATENT OR
15  *   OTHER RIGHTS NOT VESTED IN YALE.
16  *
17  *   (b) YALE MAKES NO, AND EXPRESSLY DISCLAIMS ALL, REPRESENTATIONS AND
18  *   WARRANTIES
19  *   WHATSOEVER WITH RESPECT TO THE SOFTWARE, EITHER EXPRESS OR IMPLIED,
20  *   INCLUDING,
21  *   BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
22  *   PARTICULAR
23  *   PURPOSE.
24  *
25  *   (c) LICENSEE SHALL MAKE NO STATEMENTS, REPRESENTATION OR WARRANTIES
26  *   WHATSOEVER TO
27  *   ANY THIRD PARTIES THAT ARE INCONSISTENT WITH THE DISCLAIMERS BY YALE IN
28  *   ARTICLE
29  *   (a) AND (b) above.
30  *
31  *   (d) IN NO EVENT SHALL YALE, OR ITS TRUSTEES, DIRECTORS, OFFICERS,
32  *   EMPLOYEES AND
33  *   AFFILIATES BE LIABLE FOR DAMAGES OF ANY KIND, INCLUDING ECONOMIC DAMAGE OR
34  *   INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER YALE SHALL BE
35  *   ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE
36  *   POSSIBILITY OF THE FOREGOING.
37  *
38  */
39 
40 /* -----------------------------------------------------------------
41 FILE:	    config1.c
42 DESCRIPTION:configures initial macro placement
43 CONTENTS:   config1( )
44 DATE:	    Jan 30, 1988
45 REVISIONS:
46 	    Feb 13, 1988 - passed modified number of bins to routine
47 		This takes into account only number of cell bins
48 		not border bins.
49 	    Feb 27, 1988 - no longer pass number of bins to routine
50 		This makebins calculates it and this routine now calls
51 		makebins.  However, we still must watch border bins.
52 	    Jun 27, 1988 - add calcPinFactor for initializing feedback
53 		controller for overfilled pin site penalty.
54 	    Aug 16, 1988 - fixed sqrt domain error by add temp variables.
55 		var changed to double because wraparound problem.
56 	    Aug 26, 1988 - fixed sqrt domain error correctly by adding
57 		DOUBLE temp variables.
58 	    Jan 29, 1989 - fixed \n problem with message macros.
59 	    Mar 02, 1989 - moved calcLapFactor and calcPinFactor
60 		to penalties.c
61 	    Mar 30, 1989 - changed tile datastructure.
62 	    Apr 30, 1989 - added max_shortSide calculation for
63 		partition case.
64 	    Apr 20, 1990 - Now take aspect ration into account.
65 	    Fri Jan 25 18:02:00 PST 1991 - fixed problem with
66 		recursive sizing of data.
67 	    Mon Feb  4 02:01:57 EST 1991 - added call to update wire estimator
68 		after each configuration change.
69 	    Thu Oct 17 11:47:32 EDT 1991 - added initialization.
70 ----------------------------------------------------------------- */
71 
72 #include <custom.h>
73 #include <yalecad/debug.h>
74 #include <yalecad/file.h>
75 #include <yalecad/system.h>
76 #include <yalecad/draw.h>
77 #include <yalecad/program.h>
78 
79 #define NUMBINSPERCELL  4   /* we want average cell to be in 4 bins
80 				for accuracy */
81 #define WIREAREAUNKNOWN 0   /* at this time we don't know wire area */
82 #define UPDATE  (BOOL)  FALSE /* don't initialize updateFixedCells */
83 
config1()84 void config1()
85 {
86 
87 CELLBOXPTR cellptr ;
88 TILEBOXPTR tileptr ;
89 INT l , r , b , t , cell ;
90 INT numbins, numbinX, numbinY ;
91 INT window ;
92 INT closegraphics() ;
93 char arguments[LRECL] ;
94 char resfile[LRECL] ;
95 char savfile[LRECL] ;
96 BOOL parasite ;
97 DOUBLE tileArea ;
98 DOUBLE softArea ;
99 DOUBLE totalArea ;
100 DOUBLE coreArea ;
101 DOUBLE cellArea ;
102 DOUBLE varpercell ;
103 DOUBLE deltaArea, deltaShort ;
104 DOUBLE shortvarpercell ;
105 DOUBLE var = 0.0 ;
106 DOUBLE temp ;
107 DOUBLE var_short = 0.0 ;
108 DOUBLE shortSide, total_shortSide, mean_shortSide, dev_shortSide ;
109 DOUBLE length, height, max_shortSide ;
110 
111 
112 /*
113  *   Sum the areas of the cells - get total area, average cell area.
114  */
115 totalArea = 0.0 ;
116 total_shortSide = 0.0 ;
117 softArea = 0.0 ;
118 for( cell = 1 ; cell <= numcellsG ; cell++ ) {
119     cellptr = cellarrayG[cell] ;
120     for( tileptr = cellptr->tiles;tileptr; tileptr = tileptr->next ){
121 	l = tileptr->left   ;
122 	r = tileptr->right  ;
123 	b = tileptr->bottom ;
124 	t = tileptr->top    ;
125 	tileArea = (DOUBLE) (r - l) * (DOUBLE) (t - b) ;
126 	totalArea += tileArea ;
127 	if( cellptr->celltype == STDCELLTYPE ){
128 	    softArea += tileArea ;
129 	}
130 	/* calculate mean of smallest size of tile */
131 	length = ABS( r - l ) ;
132 	height = ABS( t - b ) ;
133 	total_shortSide += (DOUBLE) MIN( length , height ) ;
134     }
135 }
136 mean_cellAreaG = (totalArea / (DOUBLE) numcellsG) ;
137 mean_shortSide = total_shortSide / numcellsG ;
138 /*
139  *   Find the variance in the size of the cells.
140  *   Find the variance in the shortest side of the tiles.
141  *   Find the largest short side for configuring partition case.
142  */
143 max_shortSide = (DOUBLE) INT_MIN ;
144 for( cell = 1 ; cell <= numcellsG ; cell++ ) {
145     cellptr = cellarrayG[cell] ;
146     /* get total area for one cell */
147     cellArea = 0.0 ;
148     for( tileptr = cellptr->tiles;tileptr; tileptr = tileptr->next ){
149 	l = tileptr->left   ;
150 	r = tileptr->right  ;
151 	b = tileptr->bottom ;
152 	t = tileptr->top    ;
153 	length = ABS( r - l ) ;
154 	height = ABS( t - b ) ;
155 	cellArea += (DOUBLE) length * (DOUBLE) height ;
156 	/* calculate variance of smallest size of tile */
157 	shortSide = MIN( length , height ) ;
158 	if( cellptr->celltype != STDCELLTYPE ){
159 	    /* find the maximum shortside */
160 	    max_shortSide = MAX( max_shortSide, shortSide ) ;
161 	}
162 	deltaShort = shortSide - mean_shortSide ;
163 	var_short += deltaShort * deltaShort ;
164     }
165     /* note variance of area is over a cell not tile */
166     deltaArea = cellArea - mean_cellAreaG  ;
167     var += deltaArea * deltaArea ;
168 }
169 varpercell = var / (DOUBLE) numcellsG ;
170 dev_cellAreaG = sqrt( varpercell ) ;
171 shortvarpercell = var_short / (DOUBLE) numcellsG ;
172 dev_shortSide = sqrt( shortvarpercell ) ;
173 
174 OUT2("\nTotal cell area : %4.2le\n", totalArea ) ;
175 OUT3("mean cell area : %4.2le      std deviation cell area : %4.2le\n",
176     mean_cellAreaG, dev_cellAreaG ) ;
177 OUT3("mean short side : %4.2le      std deviation short side : %4.2le\n",
178     mean_shortSide, dev_shortSide ) ;
179 
180 if( coreGivenG == 0 ) {
181     blockrG = blocktG = (INT) sqrt( (DOUBLE) totalArea ) + 1 ;
182     /*
183      *    Take into account the aspect ratio requested by the user
184      */
185     blocktG = (INT)( sqrt(chipaspectG) * (DOUBLE) blocktG ) + 1 ;
186     blockrG = (INT)( 1.0 / sqrt(chipaspectG) * (DOUBLE) blockrG ) + 1;
187     blocklG = blockbG = 0 ;
188     totChanLenG = perimG / 2 - (blockrG + blocktG) ;
189     aveChanWidG = 0.0 ;
190 } else {
191     r = t = (INT) sqrt( totalArea ) + 1 ;
192     totChanLenG = perimG / 2 - (r + t) ;
193     aveChanWidG = 0.0 ;
194 }
195 
196 slopeXG = (DOUBLE)(maxWeightG - baseWeightG) / ((DOUBLE) blockrG * 0.5 ) ;
197 slopeYG = (DOUBLE)(maxWeightG - baseWeightG) / ((DOUBLE) blocktG * 0.5 ) ;
198 basefactorG = (DOUBLE) baseWeightG ;
199 wireFactorXG = wireFactorYG = 0.0 ;
200 
201 /* DETERMINE NUMBER OF BINS */
202 cellArea = (DOUBLE) (mean_shortSide + 0 * dev_shortSide ) ;
203 cellArea *= cellArea ;
204 coreArea = ((DOUBLE) blocktG - blockbG) * ((DOUBLE) blockrG - blocklG) ;
205 
206 if( 5.0 * coreArea > (DOUBLE) INT_MAX && !(cost_onlyG) ){
207     scale_dataG = (INT) sqrt( (10.0 * coreArea / (DOUBLE) INT_MAX)) ;
208     scale_dataG++ ; /* round up always */
209     M( MSG,"config1", "Design is too large for integer operations\n");
210     sprintf( YmsgG,
211 	"Calling TimberWolfMC recursively to scale data by %d\n",
212 	scale_dataG ) ;
213     M( MSG, NULL, YmsgG ) ;
214     parasite = get_arg_string( arguments ) ;
215     M( MSG, NULL, arguments ) ;
216     M( MSG, NULL, "\n" ) ;
217     Ysystem( "TimberWolfMC", ABORT, arguments, closegraphics ) ;
218     /* go to cost only mode */
219     cost_onlyG = TRUE ;
220 
221     /* read the placement from restart file by moving sav to res */
222     sprintf( savfile, "%s.msav", cktNameG ) ;
223     sprintf( resfile, "%s.mres", cktNameG ) ;
224 
225     /* make a system independent copy */
226     YcopyFile( savfile, resfile ) ;
227 
228     if( parasite ){
229 	/* if we save the graphics state we need to restore it */
230 	G( TWrestoreState() ) ;
231     }
232     restartG = TRUE ;
233     scale_dataG = 1 ;
234 }
235 
236 numbins = (INT) ((DOUBLE) NUMBINSPERCELL * coreArea /
237 	         (DOUBLE) cellArea ) ;
238 
239 if( numbins <= 1 ){
240     M(ERRMSG,"config1","number of bins calculated is <= 1. Must exit.\n");
241     closegraphics() ;
242     YexitPgm( FAIL ) ;
243 }
244 
245 /* makebins determines globals maxBinX and maxBinY */
246 makebins( numbins ) ;
247 
248 /***** calculate the core configuration constants for wire estimation */
249 blockmxG = (blockrG + blocklG) / 2 ;
250 blockmyG = (blocktG + blockbG) / 2 ;
251 halfXspanG = (blockrG - blocklG) / 2 ;
252 halfYspanG = (blocktG - blockrG) / 2 ;
253 
254 /* take account of border for loadbins */
255 numbinX = maxBinXG - 1;
256 numbinY = maxBinYG - 1;
257 
258 binWidthXG = (blockrG - blocklG) / numbinX ;
259 if( (blockrG - blocklG - binWidthXG * numbinX) >= numbinX / 2 ) {
260     binWidthXG++ ;
261 }
262 binXOffstG = blocklG + 1 - binWidthXG ;
263 
264 binWidthYG = (blocktG - blockbG) / numbinY ;
265 if( (blocktG - blockbG - binWidthYG * numbinY) >= numbinY / 2 ) {
266     binWidthYG++ ;
267 }
268 binYOffstG = blockbG + 1 - binWidthYG ;
269 
270 updateFixedCells( UPDATE ) ;  /* place fixed cells */
271 
272 if( !(cost_onlyG) ){
273     loadbins( WIREAREAUNKNOWN ) ;
274 }
275 
276 placepads() ;
277 
278 bdxlengthG = blockrG - blocklG ;
279 bdylengthG = blocktG - blockbG ;
280 OUT3("bdxlength:%d    bdylength:%d\n",bdxlengthG,bdylengthG);
281 FLUSHOUT();
282 
283 /* update for wire estimation algorithm */
284 resize_wire_params() ;
285 
286 return ;
287 } /* end config1 */
288