abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
place_base.c
Go to the documentation of this file.
1 /*===================================================================*/
2 //
3 // place_base.c
4 //
5 // Aaron P. Hurst, 2003-2007
6 // ahurst@eecs.berkeley.edu
7 //
8 /*===================================================================*/
9 
10 #include <stdlib.h>
11 #include <limits.h>
12 #include <assert.h>
13 #include <string.h>
14 
15 #include "place_base.h"
16 #include "place_gordian.h"
17 
19 
20 
21 // --------------------------------------------------------------------
22 // Global variables
23 //
24 // --------------------------------------------------------------------
25 
28 float g_place_rowHeight = 1.0;
29 
32 
37 
38 
39 // --------------------------------------------------------------------
40 // getNetBBox()
41 //
42 /// \brief Returns the bounding box of a net.
43 //
44 // --------------------------------------------------------------------
46  int t;
47  Rect r;
48 
49  assert(net);
50 
51  r.x = r.y = INT_MAX;
52  r.w = r.h = -INT_MAX;
53  for(t=0; t<net->m_numTerms; t++) {
54  r.x = net->m_terms[t]->m_x < r.x ? net->m_terms[t]->m_x : r.x;
55  r.y = net->m_terms[t]->m_y < r.y ? net->m_terms[t]->m_y : r.y;
56  r.w = net->m_terms[t]->m_x > r.w ? net->m_terms[t]->m_x : r.w;
57  r.h = net->m_terms[t]->m_y > r.h ? net->m_terms[t]->m_y : r.h;
58  }
59  r.w -= r.x; r.h -= r.y;
60  return r;
61 }
62 
63 
64 // --------------------------------------------------------------------
65 // getNetWirelength()
66 //
67 /// \brief Returns the half-perimeter wirelength of a net.
68 //
69 // --------------------------------------------------------------------
70 float getNetWirelength(const ConcreteNet *net) {
71  Rect r;
72 
73  assert(net);
74 
75  r = getNetBBox(net);
76  return r.w+r.h;
77 }
78 
79 
80 // --------------------------------------------------------------------
81 // getTotalWirelength()
82 //
83 /// \brief Returns the total HPWL of all nets.
84 //
85 // --------------------------------------------------------------------
87  float r = 0;
88  int n;
89  for(n=0; n<g_place_numNets; n++) if (g_place_concreteNets[n])
90  r += getNetWirelength(g_place_concreteNets[n]);
91  return r;
92 }
93 
94 
95 // --------------------------------------------------------------------
96 // getCellArea()
97 //
98 // --------------------------------------------------------------------
99 float getCellArea(const ConcreteCell *cell) {
100  assert(cell);
101  return cell->m_parent->m_width*cell->m_parent->m_height;
102 }
103 
104 
105 // --------------------------------------------------------------------
106 // addConcreteNet()
107 //
108 /// \brief Adds a net to the placement database.
109 ///
110 /// The net object must already be allocated and the ID must be set
111 /// appropriately.
112 //
113 // --------------------------------------------------------------------
115  assert(net);
116  assert(net->m_id >= 0);
117  if (net->m_id >= g_place_concreteNetsSize) {
122  g_place_concreteNets = (ConcreteNet**)realloc(g_place_concreteNets,
124  assert(g_place_concreteNets);
125  }
126  if (net->m_id >= g_place_numNets) {
127  memset(&(g_place_concreteNets[g_place_numNets]), 0,
128  sizeof(ConcreteNet*)*(net->m_id+1-g_place_numNets));
129  g_place_numNets = net->m_id+1;
130  assert(g_place_numNets <= g_place_concreteNetsSize);
131  }
132  g_place_concreteNets[net->m_id] = net;
133 }
134 
135 
136 // --------------------------------------------------------------------
137 // delConcreteNet()
138 //
139 /// Does not deallocate memory.
140 // --------------------------------------------------------------------
142  assert(net);
143  g_place_concreteNets[net->m_id] = 0;
144  while(!g_place_concreteNets[g_place_numNets-1]) g_place_numNets--;
145 }
146 
147 
148 // --------------------------------------------------------------------
149 // addConcreteCell()
150 //
151 /// The cell object must already be allocated and the ID must be set
152 /// appropriately.
153 //
154 // --------------------------------------------------------------------
156  assert(cell);
157  assert(cell->m_id >= 0);
158  if (cell->m_id >= g_place_concreteCellsSize) {
163  g_place_concreteCells = (ConcreteCell**)realloc(g_place_concreteCells,
165  assert(g_place_concreteCells);
166  }
167  if (cell->m_id >= g_place_numCells) {
168  memset(&(g_place_concreteCells[g_place_numCells]), 0,
169  sizeof(ConcreteCell*)*(cell->m_id+1-g_place_numCells));
170  g_place_numCells = cell->m_id+1;
171  }
172  g_place_concreteCells[cell->m_id] = cell;
173 }
174 
175 
176 // --------------------------------------------------------------------
177 // delCellFromPartition()
178 //
179 // --------------------------------------------------------------------
181  int c;
182  bool found = false;
183 
184  assert(cell);
185  assert(p);
186 
187  for(c=0; c<p->m_numMembers; c++)
188  if (p->m_members[c] == cell) {
189  p->m_members[c] = 0;
190  p->m_area -= getCellArea(cell);
191  found = true;
192  break;
193  }
194 
195  if (!found) return;
196 
197  if (!p->m_leaf) {
198  delCellFromPartition(cell, p->m_sub1);
199  delCellFromPartition(cell, p->m_sub2);
200  }
201 }
202 
203 
204 // --------------------------------------------------------------------
205 // delConcreteCell()
206 //
207 /// \brief Removes a cell from the placement database.
208 ///
209 /// Does not deallocate memory.
210 ///
211 /// Important: does not modify nets that may point to this
212 /// cell. If these are connections are not removed, segmentation faults
213 /// and other nasty errors will occur.
214 //
215 // --------------------------------------------------------------------
217  assert(cell);
218  g_place_concreteCells[cell->m_id] = 0;
219  while(!g_place_concreteCells[g_place_numCells-1]) g_place_numCells--;
220 
222 }
223 
224 
225 // --------------------------------------------------------------------
226 // netSortByX...
227 //
228 /// \brief Sorts nets by position of one of its corners.
229 //
230 /// These are for use with qsort().
231 ///
232 /// Can tolerate pointers to NULL objects.
233 ///
234 // --------------------------------------------------------------------
235 int netSortByL(const void *a, const void *b) {
236  const ConcreteNet *pa = *(const ConcreteNet **)a;
237  const ConcreteNet *pb = *(const ConcreteNet **)b;
238  Rect ba, bb;
239 
240  if (!pa && !pb) return 0;
241  else if (!pa) return -1;
242  else if (!pb) return 1;
243  ba = getNetBBox(pa), bb = getNetBBox(pb);
244  if (ba.x < bb.x) return -1;
245  if (ba.x > bb.x) return 1;
246  return 0;
247 }
248 
249 int netSortByR(const void *a, const void *b) {
250  const ConcreteNet *pa = *(const ConcreteNet **)a;
251  const ConcreteNet *pb = *(const ConcreteNet **)b;
252  Rect ba, bb;
253 
254  if (!pa && !pb) return 0;
255  else if (!pa) return -1;
256  else if (!pb) return 1;
257  ba = getNetBBox(pa), bb = getNetBBox(pb);
258  if (ba.x + ba.w < bb.x + bb.w) return -1;
259  if (ba.x + ba.w > bb.x + bb.w) return 1;
260  return 0;
261 }
262 
263 int netSortByB(const void *a, const void *b) {
264  const ConcreteNet *pa = *(const ConcreteNet **)a;
265  const ConcreteNet *pb = *(const ConcreteNet **)b;
266  Rect ba, bb;
267 
268  if (!pa && !pb) return 0;
269  else if (!pa) return -1;
270  else if (!pb) return 1;
271  ba = getNetBBox(pa), bb = getNetBBox(pb);
272  if (ba.y + ba.h < bb.y + bb.h) return -1;
273  if (ba.y + ba.h > bb.y + bb.h) return 1;
274  return 0;
275 }
276 
277 int netSortByT(const void *a, const void *b) {
278  const ConcreteNet *pa = *(const ConcreteNet **)a;
279  const ConcreteNet *pb = *(const ConcreteNet **)b;
280  Rect ba, bb;
281 
282  if (!pa && !pb) return 0;
283  else if (!pa) return -1;
284  else if (!pb) return 1;
285  ba = getNetBBox(pa), bb = getNetBBox(pb);
286  if (ba.y < bb.y) return -1;
287  if (ba.y > bb.y) return 1;
288  return 0;
289 }
290 
291 int netSortByID(const void *a, const void *b) {
292  const ConcreteNet *pa = *(const ConcreteNet **)a;
293  const ConcreteNet *pb = *(const ConcreteNet **)b;
294 
295  if (!pa && !pb) return 0;
296  else if (!pa) return -1;
297  else if (!pb) return 1;
298  if (pa->m_id < pb->m_id) return -1;
299  if (pa->m_id > pb->m_id) return 1;
300  return 0;
301 }
302 
303 
304 // --------------------------------------------------------------------
305 // cellSortByX...
306 //
307 /// \brief Sorts cells by either position coordinate.
308 //
309 /// These are for use with qsort().
310 ///
311 /// Can tolerate pointers to NULL objects.
312 //
313 // --------------------------------------------------------------------
314 int cellSortByX(const void *a, const void *b) {
315  const ConcreteCell *pa = *(const ConcreteCell **)a;
316  const ConcreteCell *pb = *(const ConcreteCell **)b;
317 
318  if (!pa && !pb) return 0;
319  else if (!pa) return -1;
320  else if (!pb) return 1;
321  if (pa->m_x < pb->m_x) return -1;
322  if (pa->m_x > pb->m_x) return 1;
323  return 0;
324 }
325 
326 int cellSortByY(const void *a, const void *b) {
327  const ConcreteCell *pa = *(const ConcreteCell **)a;
328  const ConcreteCell *pb = *(const ConcreteCell **)b;
329 
330  if (!pa && !pb) return 0;
331  else if (!pa) return -1;
332  else if (!pb) return 1;
333  if (pa->m_y < pb->m_y) return -1;
334  if (pa->m_y > pb->m_y) return 1;
335  return 0;
336 }
337 
338 int cellSortByID(const void *a, const void *b) {
339  const ConcreteCell *pa = *(const ConcreteCell **)a;
340  const ConcreteCell *pb = *(const ConcreteCell **)b;
341 
342  if (!pa && !pb) return 0;
343  else if (!pa) return -1;
344  else if (!pb) return 1;
345  if (pa->m_id < pb->m_id) return -1;
346  if (pa->m_id > pb->m_id) return 1;
347  return 0;
348 }
350 
char * memset()
Rect g_place_padBounds
Definition: place_base.c:31
int cellSortByX(const void *a, const void *b)
Sorts cells by either position coordinate.
Definition: place_base.c:314
struct Partition * m_sub1
Definition: place_gordian.h:56
AbstractCell * m_parent
Definition: place_base.h:57
int cellSortByY(const void *a, const void *b)
Definition: place_base.c:326
ConcreteNet ** g_place_concreteNets
Definition: place_base.c:35
float h
Definition: place_base.h:36
float x
Definition: place_base.h:35
static Llb_Mgr_t * p
Definition: llb3Image.c:950
float m_width
Definition: place_base.h:45
Partition * g_place_rootPartition
int netSortByR(const void *a, const void *b)
Definition: place_base.c:249
int g_place_concreteNetsSize
Definition: place_base.c:36
void addConcreteNet(ConcreteNet *net)
Adds a net to the placement database.
Definition: place_base.c:114
int netSortByB(const void *a, const void *b)
Definition: place_base.c:263
float y
Definition: place_base.h:35
ConcreteCell ** g_place_concreteCells
Definition: place_base.c:33
char * realloc()
int netSortByID(const void *a, const void *b)
Definition: place_base.c:291
struct Partition * m_sub2
Definition: place_gordian.h:56
float getCellArea(const ConcreteCell *cell)
Definition: place_base.c:99
int g_place_concreteCellsSize
Definition: place_base.c:34
void addConcreteCell(ConcreteCell *cell)
Definition: place_base.c:155
ConcreteCell ** m_terms
Definition: place_base.h:72
float getNetWirelength(const ConcreteNet *net)
Returns the half-perimeter wirelength of a net.
Definition: place_base.c:70
int netSortByT(const void *a, const void *b)
Definition: place_base.c:277
float m_height
Definition: place_base.h:45
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int cellSortByID(const void *a, const void *b)
Definition: place_base.c:338
float getTotalWirelength()
Returns the total HPWL of all nets.
Definition: place_base.c:86
ConcreteCell ** m_members
Definition: place_gordian.h:49
int m_numTerms
Definition: place_base.h:71
Rect g_place_coreBounds
Definition: place_base.c:30
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
float w
Definition: place_base.h:36
int g_place_numNets
Definition: place_base.c:27
void delCellFromPartition(ConcreteCell *cell, Partition *p)
Definition: place_base.c:180
Rect getNetBBox(const ConcreteNet *net)
Returns the bounding box of a net.
Definition: place_base.c:45
int m_numMembers
Definition: place_gordian.h:48
#define assert(ex)
Definition: util_old.h:213
ABC_NAMESPACE_IMPL_START int g_place_numCells
Definition: place_base.c:26
float g_place_rowHeight
Definition: place_base.c:28
void delConcreteNet(ConcreteNet *net)
Does not deallocate memory.
Definition: place_base.c:141
void delConcreteCell(ConcreteCell *cell)
Removes a cell from the placement database.
Definition: place_base.c:216
int netSortByL(const void *a, const void *b)
Sorts nets by position of one of its corners.
Definition: place_base.c:235
float m_area
Definition: place_gordian.h:54