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

Go to the source code of this file.

Data Structures

struct  hash_element
 

Functions

int hash_string (int hash_max, const char *str)
 
void hash_add (struct hash_element **hash, int hash_max, ConcreteCell *cell)
 
ConcreteCellhash_find (struct hash_element **hash, int hash_max, const char *str)
 
void readBookshelfNets (char *filename)
 
void readBookshelfNodes (char *filename)
 
void readBookshelfPlacement (char *filename)
 
void writeBookshelfPlacement (char *filename)
 
void delNetConnections (ConcreteCell *cell)
 
int main (int argc, char **argv)
 

Variables

ABC_NAMESPACE_IMPL_START
struct hash_element 
hash_element
 
struct hash_element ** hash_cellname
 
int numCells = 0
 
int numNets = 0
 
AbstractCellabstractCells
 
ConcreteCellconcreteCells
 
ConcreteNetconcreteNets
 

Function Documentation

void delNetConnections ( ConcreteCell cell)

Definition at line 294 of file place_test.c.

294  {
295  int n, t, t2, count = 0;
297 
298  for(n=0; n<g_place_numNets; n++) if (g_place_concreteNets[n]) {
300  count = 0;
301  for(t=0; t<net->m_numTerms; t++)
302  if (net->m_terms[t] == cell) count++;
303  if (count) {
304  memcpy(old, net->m_terms, sizeof(ConcreteCell*)*net->m_numTerms);
305  net->m_terms = realloc(net->m_terms,
306  sizeof(ConcreteCell*)*(net->m_numTerms-count));
307  t2 = 0;
308  for(t=0; t<net->m_numTerms; t++)
309  if (old[t] != cell) net->m_terms[t2++] = old[t];
310  net->m_numTerms -= count;
311  }
312  }
313  free(old);
314 }
char * malloc()
VOID_HACK free()
ConcreteNet ** g_place_concreteNets
Definition: place_base.c:35
char * memcpy()
char * realloc()
ConcreteCell ** m_terms
Definition: place_base.h:72
int m_numTerms
Definition: place_base.h:71
int g_place_numNets
Definition: place_base.c:27
ABC_NAMESPACE_IMPL_START int g_place_numCells
Definition: place_base.c:26
void hash_add ( struct hash_element **  hash,
int  hash_max,
ConcreteCell cell 
)

Definition at line 38 of file place_test.c.

39  {
40  int key = hash_string(hash_max, cell->m_label);
41  // printf("adding %s key = %d\n", cell->m_label, key);
42  struct hash_element *element = malloc(sizeof(struct hash_element));
43  assert(element);
44  element->obj = cell;
45  element->next = hash[key];
46  hash[key] = element;
47 }
char * malloc()
struct hash_element * next
Definition: place_test.c:27
char * m_label
Definition: place_base.h:55
ConcreteCell * obj
Definition: place_test.c:26
int hash_string(int hash_max, const char *str)
Definition: place_test.c:30
enum keys key
#define assert(ex)
Definition: util_old.h:213
ConcreteCell* hash_find ( struct hash_element **  hash,
int  hash_max,
const char *  str 
)

Definition at line 49 of file place_test.c.

49  {
50  int key = hash_string(hash_max, str);
51  // printf("looking for %s key = %d\n", str, key);
52  struct hash_element *next = hash[key];
53  while(next) {
54  if (!strcmp(str, next->obj->m_label))
55  return next->obj;
56  next = next->next;
57  }
58  return 0;
59 }
struct hash_element * next
Definition: place_test.c:27
char * m_label
Definition: place_base.h:55
ConcreteCell * obj
Definition: place_test.c:26
int strcmp()
int hash_string(int hash_max, const char *str)
Definition: place_test.c:30
enum keys key
int hash_string ( int  hash_max,
const char *  str 
)

Definition at line 30 of file place_test.c.

30  {
31  unsigned int hash = 0;
32  int p;
33  for(p = 0; p<strlen(str); p++)
34  hash += str[p]*p;
35  return hash % hash_max;
36 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static uint32_t hash(uint32_t x)
Definition: Map.h:38
int strlen()
int main ( int  argc,
char **  argv 
)

Definition at line 316 of file place_test.c.

316  {
317 
318  if (argc != 4) {
319  printf("Usage: %s [nodes] [nets] [pl]\n", argv[0]);
320  exit(1);
321  }
322 
323  readBookshelfNodes(argv[1]);
324  readBookshelfNets(argv[2]);
325  readBookshelfPlacement(argv[3]);
326 
327  globalPreplace(0.8);
328  globalPlace();
329 
330  // DEBUG net/cell removal/addition
331  /*
332  int i;
333  for(i=1000; i<2000; i++) {
334  delConcreteNet(g_place_concreteNets[i]);
335  delNetConnections(g_place_concreteCells[i]);
336  delConcreteCell(g_place_concreteCells[i]);
337  }
338 
339  ConcreteCell newCell[2];
340  newCell[0].m_id = g_place_numCells+1;
341  newCell[0].m_x = 1000;
342  newCell[0].m_y = 1000;
343  newCell[0].m_fixed = false;
344  newCell[0].m_parent = &(abstractCells[1000]);
345  newCell[0].m_label = " ";
346  addConcreteCell(&newCell[0]);
347  newCell[1].m_id = g_place_numCells+3;
348  newCell[1].m_x = 1000;
349  newCell[1].m_y = 1000;
350  newCell[1].m_fixed = false;
351  newCell[1].m_parent = &(abstractCells[1000]);
352  newCell[1].m_label = " ";
353  addConcreteCell(&newCell[1]);
354  */
355 
357 
358  writeBookshelfPlacement(argv[3]);
359 
361 
362  return 0;
363 }
VOID_HACK exit()
VOID_HACK free()
void readBookshelfNodes(char *filename)
Definition: place_test.c:157
void globalPlace()
Performs analytic placement using a GORDIAN-like algorithm.
Definition: place_gordian.c:39
struct hash_element ** hash_cellname
Definition: place_test.c:66
void readBookshelfNets(char *filename)
Definition: place_test.c:79
void globalIncremental()
Performs analytic placement using a GORDIAN-like algorithm.
Definition: place_gordian.c:94
void globalPreplace(float utilization)
Place pad ring, leaving a core area to meet a desired utilization.
Definition: place_pads.c:31
void readBookshelfPlacement(char *filename)
Definition: place_test.c:224
void writeBookshelfPlacement(char *filename)
Definition: place_test.c:272
void readBookshelfNets ( char *  filename)

Definition at line 79 of file place_test.c.

79  {
80  char *tok;
81  char buf[1024];
82  const char *DELIMITERS = " \n\t:";
83  int id = 0;
84  int t;
85  ConcreteCell *cell;
86 
87  FILE *netsFile = fopen(filename, "r");
88  if (!netsFile) {
89  printf("ERROR: Could not open .nets file\n");
90  exit(1);
91  }
92 
93  // line 1 : version
94  while (fgets(buf, 1024, netsFile) && (buf[0] == '\n' || buf[0] == '#'));
95 
96  // line 2 : number of nets
97  while (fgets(buf, 1024, netsFile) && (buf[0] == '\n' || buf[0] == '#'));
98  tok = strtok(buf, DELIMITERS);
99  tok = strtok(NULL, DELIMITERS);
100  numNets = atoi(tok);
101  printf("READ-20 : number of nets = %d\n", numNets);
103 
104  // line 3 : number of pins
105  while (fgets(buf, 1024, netsFile) && (buf[0] == '\n' || buf[0] == '#'));
106 
107  // line XXX : net definitions
108  while(fgets(buf, 1024, netsFile)) {
109  if (buf[0] == '\n' || buf[0] == '#') continue;
110 
111  concreteNets[id].m_id = id;
112  concreteNets[id].m_weight = 1.0;
113 
114  tok = strtok(buf, DELIMITERS);
115  if (!!strcmp(tok, "NetDegree")) {
116  printf("%s\n",buf);
117  printf("ERROR: Incorrect format in .nets file\n");
118  exit(1);
119  }
120 
121  tok = strtok(NULL, DELIMITERS);
122  concreteNets[id].m_numTerms = atoi(tok);
123  if (concreteNets[id].m_numTerms < 0 ||
124  concreteNets[id].m_numTerms > 100000) {
125  printf("ERROR: Bad net degree\n");
126  exit(1);
127  }
128  concreteNets[id].m_terms = malloc(sizeof(ConcreteCell*)*
129  concreteNets[id].m_numTerms);
130 
131  // read terms
132  t = 0;
133  while(t < concreteNets[id].m_numTerms &&
134  fgets(buf, 1024, netsFile)) {
135  if (buf[0] == '\n' || buf[0] == '#') continue;
136 
137  // cell name
138  tok = strtok(buf, DELIMITERS);
139  cell = hash_find(hash_cellname, numCells, tok);
140  if (!cell) {
141  printf("ERROR: Could not find cell %s in .nodes file\n", tok);
142  exit(1);
143  }
144  concreteNets[id].m_terms[t] = cell;
145  t++;
146  }
147 
148  // add!
150 
151  id++;
152  }
153 
154  fclose(netsFile);
155 }
char * filename
Definition: globals.c:40
char * malloc()
VOID_HACK exit()
ConcreteNet * concreteNets
Definition: place_test.c:72
ConcreteCell * hash_find(struct hash_element **hash, int hash_max, const char *str)
Definition: place_test.c:49
void addConcreteNet(ConcreteNet *net)
Adds a net to the placement database.
Definition: place_base.c:114
char * strtok()
struct hash_element ** hash_cellname
Definition: place_test.c:66
float m_weight
Definition: place_base.h:74
int strcmp()
ConcreteCell ** m_terms
Definition: place_base.h:72
int numNets
Definition: place_test.c:68
int m_numTerms
Definition: place_base.h:71
int numCells
Definition: place_test.c:68
void readBookshelfNodes ( char *  filename)

Definition at line 157 of file place_test.c.

157  {
158  char *tok;
159  char buf[1024];
160  const char *DELIMITERS = " \n\t:";
161  int id = 0;
162 
163  FILE *nodesFile = fopen(filename, "r");
164  if (!nodesFile) {
165  printf("ERROR: Could not open .nodes file\n");
166  exit(1);
167  }
168 
169  // line 1 : version
170  while (fgets(buf, 1024, nodesFile) && (buf[0] == '\n' || buf[0] == '#'));
171 
172  // line 2 : num nodes
173  while (fgets(buf, 1024, nodesFile) && (buf[0] == '\n' || buf[0] == '#'));
174  tok = strtok(buf, DELIMITERS);
175  tok = strtok(NULL, DELIMITERS);
176  numCells = atoi(tok);
177  printf("READ-10 : number of cells = %d\n", numCells);
180  hash_cellname = calloc(numCells, sizeof(struct hash_element*));
181 
182  // line 3 : num terminals
183  while (fgets(buf, 1024, nodesFile) && (buf[0] == '\n' || buf[0] == '#'));
184 
185  // line XXX : cell definitions
186  while(fgets(buf, 1024, nodesFile)) {
187  if (buf[0] == '\n' || buf[0] == '#') continue;
188 
189  tok = strtok(buf, DELIMITERS);
190  concreteCells[id].m_id = id;;
191 
192  // label
193  concreteCells[id].m_parent = &(abstractCells[id]);
194  concreteCells[id].m_label = malloc(sizeof(char)*strlen(tok)+1);
195  strcpy(concreteCells[id].m_label, tok);
198  &(concreteCells[id]));
199 
200  // dimensions
201  tok = strtok(NULL, DELIMITERS);
202  abstractCells[id].m_width = atof(tok);
203  tok = strtok(NULL, DELIMITERS);
204  abstractCells[id].m_height = atof(tok);
205  tok = strtok(NULL, DELIMITERS);
206  // terminal
207  abstractCells[id].m_pad = tok && !strcmp(tok, "terminal");
208 
209  // add!
211 
212  // DEBUG
213  /*
214  printf("\"%s\" : %f x %f\n", concreteCells[id].m_label,
215  abstractCells[id].m_width,
216  abstractCells[id].m_height);
217  */
218  id++;
219  }
220 
221  fclose(nodesFile);
222 }
char * filename
Definition: globals.c:40
char * malloc()
VOID_HACK exit()
AbstractCell * m_parent
Definition: place_base.h:57
float m_width
Definition: place_base.h:45
char * strtok()
struct hash_element ** hash_cellname
Definition: place_test.c:66
AbstractCell * abstractCells
Definition: place_test.c:70
char * m_label
Definition: place_base.h:55
int strcmp()
void addConcreteCell(ConcreteCell *cell)
Definition: place_base.c:155
float m_height
Definition: place_base.h:45
ConcreteCell * concreteCells
Definition: place_test.c:71
char * strcpy()
char * m_label
Definition: place_base.h:43
double atof()
int numCells
Definition: place_test.c:68
char * calloc()
int strlen()
void hash_add(struct hash_element **hash, int hash_max, ConcreteCell *cell)
Definition: place_test.c:38
void readBookshelfPlacement ( char *  filename)

Definition at line 224 of file place_test.c.

224  {
225  char *tok;
226  char buf[1024];
227  const char *DELIMITERS = " \n\t:";
228  ConcreteCell *cell;
229 
230  FILE *plFile = fopen(filename, "r");
231  FILE *netsFile = fopen(filename, "r");
232  if (!plFile) {
233  printf("ERROR: Could not open .pl file\n");
234  exit(1);
235  }
236  if (!netsFile) {
237  printf("ERROR: Could not open .nets file\n");
238  exit(1);
239  }
240 
241  // line 1 : version
242  while (fgets(buf, 1024, plFile) && (buf[0] == '\n' || buf[0] == '#'));
243 
244  // line XXX : placement definitions
245  while(fgets(buf, 1024, plFile)) {
246  if (buf[0] == '\n' || buf[0] == '#') continue;
247 
248  tok = strtok(buf, DELIMITERS);
249 
250  // cell name
251  cell = hash_find(hash_cellname, numCells, tok);
252  if (!cell) {
253  printf("ERROR: Could not find cell %s in .nodes file\n",tok);
254  exit(1);
255  }
256 
257  // position
258  tok = strtok(NULL, DELIMITERS);
259  cell->m_x = atof(tok);
260  tok = strtok(NULL, DELIMITERS);
261  cell->m_y = atof(tok);
262 
263  // hfixed
264  cell->m_fixed = strtok(NULL, DELIMITERS) &&
265  (tok = strtok(NULL, DELIMITERS)) &&
266  !strcmp(tok, "\\FIXED");
267  }
268 
269  fclose(plFile);
270 }
char * filename
Definition: globals.c:40
VOID_HACK exit()
ConcreteCell * hash_find(struct hash_element **hash, int hash_max, const char *str)
Definition: place_test.c:49
char * strtok()
struct hash_element ** hash_cellname
Definition: place_test.c:66
int strcmp()
bool m_fixed
Definition: place_base.h:59
double atof()
int numCells
Definition: place_test.c:68
void writeBookshelfPlacement ( char *  filename)

Definition at line 272 of file place_test.c.

272  {
273  int c = 0;
274 
275  FILE *plFile = fopen(filename, "w");
276  if (!plFile) {
277  printf("ERROR: Could not open .pl file\n");
278  exit(1);
279  }
280 
281  fprintf(plFile, "UCLA pl 1.0\n");
282  for(c=0; c<numCells; c++) {
283  fprintf(plFile, "%s %f %f : N %s\n",
284  concreteCells[c].m_label,
285  concreteCells[c].m_x,
286  concreteCells[c].m_y,
287  (concreteCells[c].m_fixed ? "\\FIXED" : ""));
288  }
289 
290  fclose(plFile);
291 }
char * filename
Definition: globals.c:40
VOID_HACK exit()
ConcreteCell * concreteCells
Definition: place_test.c:71
int numCells
Definition: place_test.c:68

Variable Documentation

AbstractCell* abstractCells

Definition at line 70 of file place_test.c.

ConcreteCell* concreteCells

Definition at line 71 of file place_test.c.

ConcreteNet* concreteNets

Definition at line 72 of file place_test.c.

struct hash_element** hash_cellname

Definition at line 66 of file place_test.c.

int numCells = 0

Definition at line 68 of file place_test.c.

int numNets = 0

Definition at line 68 of file place_test.c.