abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
place_base.c File Reference
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <string.h>
#include "place_base.h"
#include "place_gordian.h"

Go to the source code of this file.

Functions

Rect getNetBBox (const ConcreteNet *net)
 Returns the bounding box of a net. More...
 
float getNetWirelength (const ConcreteNet *net)
 Returns the half-perimeter wirelength of a net. More...
 
float getTotalWirelength ()
 Returns the total HPWL of all nets. More...
 
float getCellArea (const ConcreteCell *cell)
 
void addConcreteNet (ConcreteNet *net)
 Adds a net to the placement database. More...
 
void delConcreteNet (ConcreteNet *net)
 Does not deallocate memory. More...
 
void addConcreteCell (ConcreteCell *cell)
 
void delCellFromPartition (ConcreteCell *cell, Partition *p)
 
void delConcreteCell (ConcreteCell *cell)
 Removes a cell from the placement database. More...
 
int netSortByL (const void *a, const void *b)
 Sorts nets by position of one of its corners. More...
 
int netSortByR (const void *a, const void *b)
 
int netSortByB (const void *a, const void *b)
 
int netSortByT (const void *a, const void *b)
 
int netSortByID (const void *a, const void *b)
 
int cellSortByX (const void *a, const void *b)
 Sorts cells by either position coordinate. More...
 
int cellSortByY (const void *a, const void *b)
 
int cellSortByID (const void *a, const void *b)
 

Variables

ABC_NAMESPACE_IMPL_START int g_place_numCells = 0
 
int g_place_numNets = 0
 
float g_place_rowHeight = 1.0
 
Rect g_place_coreBounds
 
Rect g_place_padBounds
 
ConcreteCell ** g_place_concreteCells = NULL
 
int g_place_concreteCellsSize = 0
 
ConcreteNet ** g_place_concreteNets = NULL
 
int g_place_concreteNetsSize = 0
 

Function Documentation

void addConcreteCell ( ConcreteCell cell)

The cell object must already be allocated and the ID must be set appropriately.

Definition at line 155 of file place_base.c.

155  {
156  assert(cell);
157  assert(cell->m_id >= 0);
158  if (cell->m_id >= g_place_concreteCellsSize) {
166  }
167  if (cell->m_id >= g_place_numCells) {
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 }
char * memset()
ConcreteCell ** g_place_concreteCells
Definition: place_base.c:33
char * realloc()
int g_place_concreteCellsSize
Definition: place_base.c:34
#define assert(ex)
Definition: util_old.h:213
ABC_NAMESPACE_IMPL_START int g_place_numCells
Definition: place_base.c:26
void addConcreteNet ( ConcreteNet net)

Adds a net to the placement database.

The net object must already be allocated and the ID must be set appropriately.

Definition at line 114 of file place_base.c.

114  {
115  assert(net);
116  assert(net->m_id >= 0);
117  if (net->m_id >= g_place_concreteNetsSize) {
125  }
126  if (net->m_id >= g_place_numNets) {
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 }
char * memset()
ConcreteNet ** g_place_concreteNets
Definition: place_base.c:35
int g_place_concreteNetsSize
Definition: place_base.c:36
char * realloc()
int g_place_numNets
Definition: place_base.c:27
#define assert(ex)
Definition: util_old.h:213
int cellSortByID ( const void *  a,
const void *  b 
)

Definition at line 338 of file place_base.c.

338  {
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 }
int cellSortByX ( const void *  a,
const void *  b 
)

Sorts cells by either position coordinate.

These are for use with qsort().

Can tolerate pointers to NULL objects.

Definition at line 314 of file place_base.c.

314  {
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 }
int cellSortByY ( const void *  a,
const void *  b 
)

Definition at line 326 of file place_base.c.

326  {
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 }
void delCellFromPartition ( ConcreteCell cell,
Partition p 
)

Definition at line 180 of file place_base.c.

180  {
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 }
struct Partition * m_sub1
Definition: place_gordian.h:56
struct Partition * m_sub2
Definition: place_gordian.h:56
float getCellArea(const ConcreteCell *cell)
Definition: place_base.c:99
ConcreteCell ** m_members
Definition: place_gordian.h:49
void delCellFromPartition(ConcreteCell *cell, Partition *p)
Definition: place_base.c:180
int m_numMembers
Definition: place_gordian.h:48
#define assert(ex)
Definition: util_old.h:213
float m_area
Definition: place_gordian.h:54
void delConcreteCell ( ConcreteCell cell)

Removes a cell from the placement database.

Does not deallocate memory.

Important: does not modify nets that may point to this cell. If these are connections are not removed, segmentation faults and other nasty errors will occur.

Definition at line 216 of file place_base.c.

216  {
217  assert(cell);
218  g_place_concreteCells[cell->m_id] = 0;
220 
222 }
Partition * g_place_rootPartition
ConcreteCell ** g_place_concreteCells
Definition: place_base.c:33
void delCellFromPartition(ConcreteCell *cell, Partition *p)
Definition: place_base.c:180
#define assert(ex)
Definition: util_old.h:213
ABC_NAMESPACE_IMPL_START int g_place_numCells
Definition: place_base.c:26
void delConcreteNet ( ConcreteNet net)

Does not deallocate memory.

Definition at line 141 of file place_base.c.

141  {
142  assert(net);
143  g_place_concreteNets[net->m_id] = 0;
145 }
ConcreteNet ** g_place_concreteNets
Definition: place_base.c:35
int g_place_numNets
Definition: place_base.c:27
#define assert(ex)
Definition: util_old.h:213
float getCellArea ( const ConcreteCell cell)

Definition at line 99 of file place_base.c.

99  {
100  assert(cell);
101  return cell->m_parent->m_width*cell->m_parent->m_height;
102 }
AbstractCell * m_parent
Definition: place_base.h:57
float m_width
Definition: place_base.h:45
float m_height
Definition: place_base.h:45
#define assert(ex)
Definition: util_old.h:213
Rect getNetBBox ( const ConcreteNet net)

Returns the bounding box of a net.

Definition at line 45 of file place_base.c.

45  {
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 }
float h
Definition: place_base.h:36
float x
Definition: place_base.h:35
float y
Definition: place_base.h:35
ConcreteCell ** m_terms
Definition: place_base.h:72
int m_numTerms
Definition: place_base.h:71
float w
Definition: place_base.h:36
#define assert(ex)
Definition: util_old.h:213
float getNetWirelength ( const ConcreteNet net)

Returns the half-perimeter wirelength of a net.

Definition at line 70 of file place_base.c.

70  {
71  Rect r;
72 
73  assert(net);
74 
75  r = getNetBBox(net);
76  return r.w+r.h;
77 }
float h
Definition: place_base.h:36
float w
Definition: place_base.h:36
Rect getNetBBox(const ConcreteNet *net)
Returns the bounding box of a net.
Definition: place_base.c:45
#define assert(ex)
Definition: util_old.h:213
float getTotalWirelength ( )

Returns the total HPWL of all nets.

Definition at line 86 of file place_base.c.

86  {
87  float r = 0;
88  int n;
89  for(n=0; n<g_place_numNets; n++) if (g_place_concreteNets[n])
91  return r;
92 }
ConcreteNet ** g_place_concreteNets
Definition: place_base.c:35
float getNetWirelength(const ConcreteNet *net)
Returns the half-perimeter wirelength of a net.
Definition: place_base.c:70
int g_place_numNets
Definition: place_base.c:27
int netSortByB ( const void *  a,
const void *  b 
)

Definition at line 263 of file place_base.c.

263  {
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 }
float h
Definition: place_base.h:36
float y
Definition: place_base.h:35
Rect getNetBBox(const ConcreteNet *net)
Returns the bounding box of a net.
Definition: place_base.c:45
int netSortByID ( const void *  a,
const void *  b 
)

Definition at line 291 of file place_base.c.

291  {
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 }
int netSortByL ( const void *  a,
const void *  b 
)

Sorts nets by position of one of its corners.

These are for use with qsort().

Can tolerate pointers to NULL objects.

Definition at line 235 of file place_base.c.

235  {
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 }
float x
Definition: place_base.h:35
Rect getNetBBox(const ConcreteNet *net)
Returns the bounding box of a net.
Definition: place_base.c:45
int netSortByR ( const void *  a,
const void *  b 
)

Definition at line 249 of file place_base.c.

249  {
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 }
float x
Definition: place_base.h:35
float w
Definition: place_base.h:36
Rect getNetBBox(const ConcreteNet *net)
Returns the bounding box of a net.
Definition: place_base.c:45
int netSortByT ( const void *  a,
const void *  b 
)

Definition at line 277 of file place_base.c.

277  {
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 }
float y
Definition: place_base.h:35
Rect getNetBBox(const ConcreteNet *net)
Returns the bounding box of a net.
Definition: place_base.c:45

Variable Documentation

ConcreteCell** g_place_concreteCells = NULL

Definition at line 33 of file place_base.c.

int g_place_concreteCellsSize = 0

Definition at line 34 of file place_base.c.

ConcreteNet** g_place_concreteNets = NULL

Definition at line 35 of file place_base.c.

int g_place_concreteNetsSize = 0

Definition at line 36 of file place_base.c.

Rect g_place_coreBounds

Definition at line 30 of file place_base.c.

ABC_NAMESPACE_IMPL_START int g_place_numCells = 0

Definition at line 26 of file place_base.c.

int g_place_numNets = 0

Definition at line 27 of file place_base.c.

Rect g_place_padBounds

Definition at line 31 of file place_base.c.

float g_place_rowHeight = 1.0

Definition at line 28 of file place_base.c.