Initial commit at Tue Apr 25 08:36:02 EDT 2017 by tim on stravinsky
[xcircuit.git] / asg / debug.c
blob0f828b2c3fb7dfdbc558874df92a79a436711f81
1 /************************************************************
2 **
3 ** COPYRIGHT (C) 1993 UNIVERSITY OF PITTSBURGH
4 ** COPYRIGHT (C) 1996 GANNON UNIVERSITY
5 ** ALL RIGHTS RESERVED
6 **
7 ** This software is distributed on an as-is basis
8 ** with no warranty implied or intended. No author
9 ** or distributor takes responsibility to anyone
10 ** regarding its use of or suitability.
12 ** The software may be distributed and modified
13 ** freely for academic and other non-commercial
14 ** use but may NOT be utilized or included in whole
15 ** or part within any commercial product.
17 ** This copyright notice must remain on all copies
18 ** and modified versions of this software.
20 ************************************************************/
23 /* file debug.c */
24 /* ------------------------------------------------------------------------
25 * debugging routines for place and route spl 7/89
27 * ------------------------------------------------------------------------
29 #include <stdio.h>
30 #include <string.h>
31 #include <time.h>
32 #include <math.h>
33 #include "externs.h"
35 /*---------------------------------------------------------------
36 * Forward References
37 *---------------------------------------------------------------
40 void print_tlist();
42 /*---------------------------------------------------------------
43 * print the full list of all modules
44 *---------------------------------------------------------------
47 void print_modules(f)
48 FILE *f;
50 mlist *m;
51 for (m = modules; m != NULL ; m = m->next)
53 fprintf(f, "\nModule index: %d name: %s,\ttype: %s, \tflag: %d\n",
54 m->this->index, m->this->name, m->this->type, m->this->flag);
55 fprintf(f, "\tpostition: %d %d,\tsize: %d %d,\trotation: %d\n",
56 m->this->x_pos, m->this->y_pos,
57 m->this->x_size, m->this->y_size, m->this->rot);
58 fprintf(f, " Terminal List:\n");
59 print_tlist(f,m->this->terms);
64 *---------------------------------------------------------------
65 * print the full list of all nets
66 *---------------------------------------------------------------
69 void print_nets(f)
70 FILE *f;
72 nlist *n;
73 for (n = nets; n != NULL ; n = n->next)
75 fprintf(f, "\nNet name: %s Type: %d \n", n->this->name, n->this->type);
76 fprintf(f, " Terminal List:\n");
77 print_tlist(f,n->this->terms);
82 *---------------------------------------------------------------
83 * print a terminal list
84 *---------------------------------------------------------------
86 void print_tlist(f,t)
87 FILE *f;
88 tlist *t;
90 int i = 0;
91 for(; t != NULL; t = t->next)
93 fprintf(f, "\t%s:%s: %d,%d type:%d", t->this->mod->name, t->this->name,
94 t->this->x_pos, t->this->y_pos, t->this->type);
95 if(++i >= 4)
97 fprintf(f, "\n");
98 i = 0;
103 *---------------------------------------------------------------
104 * print the list of "external/system" terminals
105 *---------------------------------------------------------------
108 void print_ext(f)
109 FILE *f;
111 tlist *t;
112 int i = 0;
114 fprintf(f, "\nExternal Ports:\n");
116 for(t = ext_terms; t != NULL; t = t->next)
118 fprintf(f, "\t%s:", t->this->name);
119 switch (t->this->type)
121 case IN: fprintf(f, "global_input"); break;
123 case OUT: fprintf(f, "global_output"); break;
125 case INOUT: fprintf(f, "global_inout"); break;
127 default: fprintf(f, "bad type"); break;
130 if(++i >= 3)
132 fprintf(f, "\n");
133 i = 0;
139 *---------------------------------------------------------------
140 * print_connections (stf 9-89)
141 *---------------------------------------------------------------
143 void print_connections(f)
144 FILE *f;
146 int i, j;
148 fprintf(f, "\nConnections:\n");
150 for (i = 0; i < module_count; i++)
152 for (j = 0; j < module_count; j++)
154 fprintf(f, "i,j:%d,%d:%d\t", i, j, connected[i][j]);
155 if ((j+1)%5 == 0) fprintf(f, "\n");
157 fprintf(f,"\n");
162 *---------------------------------------------------------------
163 * p_cons (stf 9-89)
164 *---------------------------------------------------------------
166 void p_cons(f,q, limbs)
167 FILE *f;
168 int q;
169 clist *limbs;
171 int i, j;
173 fprintf(f, "\nConnections:(%d)\n", q);
175 for (i = 0; i < q; i++)
177 fprintf(f,"%2d | ", i);
179 for (j = 0; j < q; j++)
181 fprintf(f, "%2d ", connected[i][j]);
182 if ((j+1)%50 == 0) fprintf(f, "\n");
184 fprintf(f," | ");
186 if (find_indexed_element(i, limbs) != NULL)
187 print_ctree(f, ( find_indexed_element(i, limbs) )->this);
188 else
189 fprintf(f, "?");
191 fprintf(f,"\n");
196 *--------------------------------------------------------------
197 * det_in_out_relationship(m1, m2)
198 *--------------------------------------------------------------
200 void det_in_out_relationship(m1, m2, in_x, out_x)
201 module *m1, *m2;
202 int *in_x, *out_x;
204 tlist *tl, *tll;
206 /* Check out the connection between <m1> and <m2> */
207 for (tl = m1->terms; tl != NULL; tl = tl->next)
209 if (tl->this->nt == NULL) /* Don't Care */
211 *out_x = 0;
212 *in_x = 0;
213 break;
216 for (tll = tl->this->nt->terms; tll != NULL; tll = tll->next)
218 if (tll->this->mod == m2)
220 if (((tl->this->type == IN) && (tll->this->type != IN)) ||
221 ((tl->this->type == INOUT) && (tll->this->type == OUT)))
223 /* <m2> drives <m1> */
224 *in_x = m1->x_pos + tl->this->x_pos;
225 *out_x = m2->x_pos + tll->this->x_pos;
227 else if (((tll->this->type == IN) && (tl->this->type != IN)) ||
228 ((tll->this->type == INOUT) && (tl->this->type == OUT)))
230 /* <m1> drives <m2> */
231 *out_x = m1->x_pos + tl->this->x_pos;
232 *in_x = m2->x_pos + tll->this->x_pos;
234 else /* Don't care: */
236 *out_x = 0;
237 *in_x = 0;
244 *--------------------------------------------------------------
245 * float manhattan_PWS (stf 5-91)
246 *--------------------------------------------------------------
248 float manhattan_PWS()
250 /* this function returns the manhattan (x + y) distances among the modules of
251 the design. This number can be used to measure the quality of the
252 placement, and is accomplished by doing a pairwise multiplication of the
253 inverse distance with the connectivity for all of the modules in the
254 design. */
256 /* Modified to only include those connections that are not xfouled */
258 int rIndex, cIndex, match_module_index();
259 int in_x, out_x, xNoise, yNoise;
260 float connectivity, manhat_dist[MAX_MOD][MAX_MOD];
261 float x, y, inv_manhat_dist[MAX_MOD][MAX_MOD], manhat_sum = 0.0;
262 mlist *ml, *mll;
264 /* Rebuild the connected[][] matrix for reference: */
265 build_connections(matrix_type);
266 overlay_connections(module_count, matrix_type);
268 /* Build the two distance matricies */
269 for (ml = modules; ml != NULL; ml = ml->next)
271 rIndex = ml->this->index;
272 for (mll = ml->next; mll != NULL; mll = mll->next)
274 cIndex = mll->this->index;
275 mll->this->placed = UNPLACED; /* Avoids screwups in the cc code */
277 if (connected[rIndex][cIndex] != 0)
279 /* Skip cross-coupled gates: */
280 if (cross_coupled_p(ml->this, mll->this, cc_search_level) != FALSE)
282 break;
284 else
286 /* Noise Reduction */
287 xNoise = ml->this->x_pos + ml->this->x_size/2 -
288 mll->this->x_pos - mll->this->x_size/2;
290 yNoise = ml->this->y_pos + ml->this->y_size/2 -
291 mll->this->y_pos - mll->this->y_size/2;
292 x = (float)abs(xNoise); y = (float)abs(yNoise);
293 in_x = out_x = 0;
295 manhat_dist[rIndex][cIndex] = x + y;
296 if (x + y > 0.0)
298 inv_manhat_dist[rIndex][cIndex] =1.0/manhat_dist[rIndex][cIndex];
300 /* Calculate the pairwise sums: Penalize for bad, non-cc
301 (xfoul) connections: */
302 det_in_out_relationship(ml->this, mll->this, &in_x, &out_x);
303 if (in_x < out_x)
305 connectivity = (float)connected[rIndex][cIndex];
306 manhat_sum -= inv_manhat_dist[rIndex][cIndex] * connectivity;
308 else
310 connectivity = (float)connected[rIndex][cIndex];
311 manhat_sum += inv_manhat_dist[rIndex][cIndex] * connectivity;
319 return(manhat_sum);
322 *--------------------------------------------------------------
323 * print_distance_stats (stf 5-91)
324 *--------------------------------------------------------------
326 void print_distance_stats(mfile)
327 FILE *mfile; /* Where to write the info */
329 /* this function prints the manhattan (x + y) and euclidian (sqrt(x^2 + y^2))
330 distances among the modules of the design to a file "dist_stats"
331 along with a measure of how this correlates with the connectivity
332 of the design. This number can be used to measure the quality of the
333 placement, and is accomplished by doing a pairwise multiplication of the
334 inverse distance with the connectivity for all of the modules in the
335 design. */
337 /* Modified to only include those connections that are not xfouled */
339 int rIndex, cIndex, match_module_index();
340 int in_x, out_x, xNoise, yNoise;
341 float connectivity, manhat_dist[MAX_MOD][MAX_MOD], euclid_dist[MAX_MOD][MAX_MOD];
342 float x, inv_manhat_dist[MAX_MOD][MAX_MOD], manhat_sum = 0.0;
343 float y, inv_euclid_dist[MAX_MOD][MAX_MOD], euclid_sum = 0.0;
344 mlist *ml, *mll;
346 /* Rebuild the connected[][] matrix for reference: */
347 build_connections(matrix_type);
348 overlay_connections(module_count, matrix_type);
350 /* Build the two distance matricies */
351 for (ml = modules; ml != NULL; ml = ml->next)
353 rIndex = ml->this->index;
354 for (mll = ml->next; mll != NULL; mll = mll->next)
356 cIndex = mll->this->index;
357 mll->this->placed = UNPLACED; /* Avoids screwups in the cc code */
359 if (connected[rIndex][cIndex] != 0)
361 /* Skip cross-coupled gates: */
362 if (cross_coupled_p(ml->this, mll->this, cc_search_level) != FALSE)
364 break;
366 else
368 /* Noise Reduction */
369 xNoise = ml->this->x_pos + ml->this->x_size/2 -
370 mll->this->x_pos - mll->this->x_size/2;
372 yNoise = ml->this->y_pos + ml->this->y_size/2 -
373 mll->this->y_pos - mll->this->y_size/2;
374 x = (float)abs(xNoise); y = (float)abs(yNoise);
375 in_x = out_x = 0;
377 manhat_dist[rIndex][cIndex] = x + y;
378 euclid_dist[rIndex][cIndex] = (float)sqrt((double)((x * x)+(y * y)));
379 if (x + y > 0.0)
381 inv_manhat_dist[rIndex][cIndex] =1.0/manhat_dist[rIndex][cIndex];
382 inv_euclid_dist[rIndex][cIndex] =1.0/euclid_dist[rIndex][cIndex];
384 /* Calculate the pairwise sums: Penalize for bad, non-cc
385 (xfoul) connections: */
386 det_in_out_relationship(ml->this, mll->this, &in_x, &out_x);
387 if (in_x < out_x)
389 connectivity = (float)connected[rIndex][cIndex];
390 manhat_sum -= inv_manhat_dist[rIndex][cIndex] * connectivity;
391 euclid_sum -= inv_euclid_dist[rIndex][cIndex] * connectivity;
393 else
395 connectivity = (float)connected[rIndex][cIndex];
396 manhat_sum += inv_manhat_dist[rIndex][cIndex] * connectivity;
397 euclid_sum += inv_euclid_dist[rIndex][cIndex] * connectivity;
405 /* Now dump the two sums to the stats file: */
406 fprintf(mfile,"\t%-8.7f \t%-8.7f ",
407 manhat_sum, euclid_sum);
410 *--------------------------------------------------------------
411 * print_distance_matricies (stf 5-91)
412 *--------------------------------------------------------------
414 void print_distance_matricies()
416 /* this function prints the manhattan (x + y) and euclidian (sqrt(x^2 + y^2))
417 distances among the modules of the design to a file "dist_stats"
418 along with a measure of how this correlates with the connectivity
419 of the design. This number can be used to measure the quality of the
420 placement, and is accomplished by doing a pairwise multiplication of the
421 inverse distance with the connectivity for all of the modules in the
422 design. */
424 FILE *mfile = fopen("dist_stats","a");
425 int rIndex, cIndex, match_module_index();
426 int in_x, out_x, xNoise, yNoise;
427 float connectivity, manhat_dist[MAX_MOD][MAX_MOD], euclid_dist[MAX_MOD][MAX_MOD];
428 float x, inv_manhat_dist[MAX_MOD][MAX_MOD], manhat_sum = 0.0;
429 float y, inv_euclid_dist[MAX_MOD][MAX_MOD], euclid_sum = 0.0;
430 mlist *ml, *mll;
432 /* Rebuild the connected[][] matrix for reference: */
433 build_connections(matrix_type);
434 overlay_connections(module_count, matrix_type);
436 /* Build the two distance matricies */
437 for (ml = modules; ml != NULL; ml = ml->next)
439 rIndex = ml->this->index;
440 for (mll = ml->next; mll != NULL; mll = mll->next)
442 cIndex = mll->this->index;
443 mll->this->placed = UNPLACED; /* Avoids screwups in the cc code */
445 if (connected[rIndex][cIndex] != 0)
447 /* Skip cross-coupled gates: */
448 if (cross_coupled_p(ml->this, mll->this, cc_search_level) != FALSE)
450 break;
452 else
454 /* Noise Reduction */
455 xNoise = ml->this->x_pos + ml->this->x_size/2 -
456 mll->this->x_pos - mll->this->x_size/2;
458 yNoise = ml->this->y_pos + ml->this->y_size/2 -
459 mll->this->y_pos - mll->this->y_size/2;
460 x = (float)abs(xNoise); y = (float)abs(yNoise);
461 in_x = out_x = 0;
463 manhat_dist[rIndex][cIndex] = x + y;
464 euclid_dist[rIndex][cIndex] = (float)sqrt((double)((x * x)+(y * y)));
465 if (x + y > 0.0)
467 inv_manhat_dist[rIndex][cIndex] =1.0/manhat_dist[rIndex][cIndex];
468 inv_euclid_dist[rIndex][cIndex] =1.0/euclid_dist[rIndex][cIndex];
470 /* Calculate the pairwise sums: Penalize for bad, non-cc
471 (xfoul) connections: */
472 det_in_out_relationship(ml->this, mll->this, &in_x, &out_x);
473 if (in_x < out_x)
475 connectivity = (float)connected[rIndex][cIndex];
476 manhat_sum -= inv_manhat_dist[rIndex][cIndex] * connectivity;
477 euclid_sum -= inv_euclid_dist[rIndex][cIndex] * connectivity;
479 else
481 connectivity = (float)connected[rIndex][cIndex];
482 manhat_sum += inv_manhat_dist[rIndex][cIndex] * connectivity;
483 euclid_sum += inv_euclid_dist[rIndex][cIndex] * connectivity;
490 /* Now dump all of this to the stats file: */
491 fprintf(mfile,"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
492 fprintf(mfile,"| -p%d -s%d -c%d -r%-4.2f -m%d %s %s %s\t ||",
493 partition_rule, max_partition_size, max_partition_conn,
494 partition_ratio, matrix_type, (stopAtFirstCut == TRUE) ? "-f" : "--",
495 (useSlivering == FALSE) ? "-v" : "--", (useAveraging == TRUE) ? "-w" : "--");
497 fprintf(mfile, "The Connection Matrix looks like: \n");
498 for(rIndex = 0; rIndex < module_count; rIndex++)
500 for(cIndex = 0; cIndex < module_count; cIndex++)
502 fprintf(mfile, "%6d ", connected[rIndex][cIndex]);
504 ml = (mlist*)member(rIndex, modules, match_module_index);
505 fprintf(mfile," | %s\n", ml->this->name);
508 fprintf(mfile, "\n\nThe Manhattan Distance Matrix looks like: \n");
509 for(rIndex = 0; rIndex < module_count; rIndex++)
511 for(cIndex = 0; cIndex < module_count; cIndex++)
513 fprintf(mfile, "%-6.1f ", manhat_dist[rIndex][cIndex]);
515 ml = (mlist*)member(rIndex, modules, match_module_index);
516 fprintf(mfile," | %s\n", ml->this->name);
519 /* fprintf(mfile, "\n\nThe Euclidian Distance Matrix looks like: \n");
520 for(rIndex = 0; rIndex < module_count; rIndex++)
522 for(cIndex = 0; cIndex < module_count; cIndex++)
524 fprintf(mfile, "%-6.3f ", euclid_dist[rIndex][cIndex]);
526 ml = (mlist*)member(rIndex, modules, match_module_index);
527 fprintf(mfile," | %s\n", ml->this->name);
530 fprintf(mfile,"\n\nThe pairwise sum for inv. Manhattan vs. Connectivity is %-8.7f\n",
531 manhat_sum);
532 fprintf(mfile,"\n\nThe pairwise sum for inv. Euclidian vs. Connectivity is %-8.7f\n",
533 euclid_sum);
534 fclose(mfile);
537 int match_module_index(i, m)
538 int i;
539 module *m;
541 /* Return TRUE if the module->index field matches the index <i> given: */
542 if (m->index == i) return (TRUE);
543 else return(FALSE);
547 *--------------------------------------------------------------
548 * print_ctree (stf 9-89)
549 *--------------------------------------------------------------
551 int print_ctree(f,t)
552 FILE *f;
553 ctree *t;
555 clist *queue = NULL;
556 ctree *temp;
557 int this, next, breadth = 0;
559 if (t == NULL) return 0;
561 /* Load the queue and begin: */
562 indexed_list_insert(t,0,&queue);
563 this = 1; next = 0; breadth = 1;
565 fprintf(f,"{");
567 /* Yank the first person off of the list, and add any children to the back */
570 temp = (ctree *)remove_indexed_element(0, &queue); /* dequeue the next item */
571 if (temp != NULL)
573 if (temp->right!=NULL) /* enque the right child */
575 indexed_list_insert(temp->right,ilist_length(queue),&queue);
576 next += 1;
578 if (temp->left!=NULL) /* enque the left child */
580 indexed_list_insert(temp->left,ilist_length(queue),&queue);
581 next += 1;
583 /* Now do something with the element: */
585 if (temp->this->contents != NULL)
586 fprintf(f,"[c=%d] %s, ", temp->this->connects, temp->this->contents->name);
588 else
589 fprintf(f,"[s=%d c=%d r=%-5.3f]", temp->this->size, temp->this->connects,
590 (float)temp->this->connects/(float)temp->this->size);
592 if (--this == 0) /* end of a layer */
594 breadth = MAX(breadth, next);
595 this = next; next = 0;
596 fprintf(f,": ");
600 /* go on to the next thing in the queue */
601 } while (ilist_length(queue)!= 0);
603 fprintf(f,"}");
604 return (breadth);
610 *---------------------------------------------------------------
611 * print_info
612 *---------------------------------------------------------------
614 void print_info(f)
615 FILE *f;
617 int i;
618 fprintf(f, "\nInfo:\n");
620 for(i = 0; i< module_count; i++)
622 fprintf(f, "module:%d\t used:%d\t in:%d\t out:%d\n",
623 i, module_info[i].used, module_info[i].in, module_info[i].out);
627 *---------------------------------------------------------------
628 * print_boxes
629 *---------------------------------------------------------------
631 void print_boxes(f)
632 FILE *f;
634 mlist *ml;
635 int i;
637 fprintf(f, "\nBoxes:\n");
639 for(i = 0; i<= partition_count; i++)
641 fprintf(f, "Boxes for partition %d:\n", i);
643 for (ml = boxes[i]; ml != NULL; ml = ml->next)
645 fprintf(f, "\t\tModule: %s\n", ml->this->name);
651 *---------------------------------------------------------------
652 * print_strings
653 *---------------------------------------------------------------
655 void print_strings(f)
656 FILE *f;
658 mlist *ml;
659 int i;
661 fprintf(f, "\nStrings:\n");
663 for(i = 0; i<= partition_count; i++)
665 fprintf(f, "string for partition %d: total size: %d %d\n",
666 i, x_sizes[i], y_sizes[i]);
668 for (ml = strings[i]; ml != NULL; ml = ml->next)
670 fprintf(f, "\t\tModule: %s, pos: %d %d, in: %s, out: %s\n",
671 ml->this->name,
672 ml->this->x_pos,
673 ml->this->y_pos,
674 (ml->this->primary_in) ?
675 ml->this->primary_in->nt->name : "",
676 (ml->this->primary_out) ?
677 ml->this->primary_out->nt->name : "");
684 /*---------------------------------------------------------------
685 * print_range
686 *---------------------------------------------------------------
688 print_range(s, rl)
689 char *s;
690 rlist *rl;
692 fprintf(stderr, "Range list: %s\n", s);
694 for (; rl != NULL; rl = rl->next)
696 fprintf(stderr, "\t x-low:%d\t y-high:%d\t crosses:%d\n",
697 rl->this->x, rl->this->y, rl->this->c);
702 *---------------------------------------------------------------
703 * print_result
704 *---------------------------------------------------------------
706 #define SIDE_CONVERT(n) ((n==0)?0:(n==1)?90:(n==2)?180:(n==3)?270:0)
707 #define SIDE_X(n) ((n==0)?-4:(n==1)?0:(n==2)?0:(n==3)?0:0)
708 #define SIDE_Y(n) ((n==0)?0:(n==1)?2:(n==2)?0:(n==3)?-2:0)
710 void print_result(f)
711 FILE *f;
713 mlist *ml;
714 tlist *t;
715 int i, index, c;
717 llist *head, *hhead;
720 /* for date and time */
721 long time_loc;
722 extern long int time();
724 /* copy the Post Script header file to the output file */
725 ps_print_standard_header(f);
727 /* Define the bounding box for the post-script code: */
728 fprintf(f,"%%%%BoundingBox: %d %d %d %d\n",
729 xfloor - CHANNEL_LENGTH - 1,
730 yfloor - CHANNEL_HEIGHT - 1,
731 x_sizes[0] + CHANNEL_LENGTH + 1,
732 y_sizes[0] + CHANNEL_HEIGHT + 1);
735 /* now dump the result */
736 time_loc = time(0L);
738 if (latex != TRUE) /* Not in latex mode */
740 fprintf(f,
741 "\n(N2A %s %s input:? s:%d c:%d r:%-5.3f rule #%d part:%d dir:%d) %d %d %d %d init\n",
742 getenv("USER"), ctime(&time_loc),
743 max_partition_size, max_partition_conn, partition_ratio, partition_rule,
744 partition_count, matrix_type,
745 xfloor, yfloor, x_sizes[0], y_sizes[0]);
747 else /* This stuff replaces the init for latex mode */
749 fprintf(f, "swidth setlinewidth\n/Courier findfont fwidth scalefont setfont\n");
753 for (ml = partitions[0]; ml != NULL; ml = ml->next)
755 ps_print_mod(f, ml->this);
758 if (do_routing == FALSE)
759 for (i=1; i<=partition_count; i++)
761 if (partitions[i] != NULL)
763 index = partitions[i]->this->index;
765 ps_print_border(f,x_positions[i], y_positions[i], x_sizes[i], y_sizes[i]);
766 fprintf(f,"%d %d ([part: #%d, placed:%d]) label\n",
767 x_positions[i] + 1, y_sizes[i] - 2,
768 module_info[index].used, module_info[index].order);
772 fprintf(f, "done\n");
776 *---------------------------------------------------------------
777 * ps_box(x_len, y_len, x_org, y_org, rot)
778 * --------------------------------------------------------------
780 int ps_box(x_len, y_len, x_org, y_org, rot)
781 int x_len, y_len, x_org, y_org, rot;
782 /* this function produces the relative code for a box of size (x_len, y_len)
783 * starting at position (x_org, yorg)
788 /* --------------------------------------------------------------
789 * draft_statistics
790 * This function provides statistics on how well the draft was
791 * done: Statistics are # modules, # nets, # terminals, #cc @ level <l>...
792 * # cc @ level 1, # foul-ups.
793 * A signal flow foulup is defined as any non-cc module who's child is not
794 * in an x-position greater-than its parent.
795 * Other useful info is the filename, date, and all of the (specified?)
796 * command-line args. All information is printed to a file "draft_stats"
797 *---------------------------------------------------------------
799 void draft_statistics()
801 int cc_count[10];
802 int xfouls = 0, yfouls = 0, term_count = 0, lev;
803 int out_x, in_x, out_y, in_y, possibly_screwed, also_unscrewed;
805 mlist *ml;
806 module *m, *last_m, *cc_m, *top_cc_mod, *bot_cc_mod;
807 tlist *t, *tt;
809 FILE *f = fopen("draft_stats", "a");
811 for (lev=0; lev < cc_search_level; lev++) cc_count[lev] = 0;
813 last_m = modules->this;
814 last_m->placed = UNPLACED; /* for cross_coupled_p to work properly */
816 term_count = list_length(last_m->terms);
819 for(ml = modules->next; ml != NULL; ml = ml->next)
821 m = cc_m = ml->this;
822 term_count += list_length(m->terms);
824 /* Set up all the strangeness for cross-coupled modules: */
825 for (lev = 1; (lev <= cc_search_level) && (cc_m != NULL); lev++)
827 cc_m->placed = UNPLACED;
829 if (cross_coupled_p(last_m, cc_m, lev) != FALSE)
831 top_cc_mod = last_m;
832 bot_cc_mod = cc_m;
833 cc_count[lev-1] += 1;
834 break;
836 cc_m = (ml->next != NULL) ? ml->next->this : NULL;
839 for (t = last_m->terms; t != NULL; t = t->next)
841 if ((t->this->type == OUT) || (t->this->type == INOUT))
843 possibly_screwed = FALSE;
844 also_unscrewed = FALSE;
846 for (tt = t->this->nt->terms; tt != NULL; tt = tt->next)
848 if ((tt->this->type == IN) || (tt->this->type == INOUT))
850 out_x = t->this->mod->x_pos + t->this->x_pos;
851 in_x = tt->this->mod->x_pos + tt->this->x_pos;
852 out_y = t->this->mod->y_pos + t->this->y_pos;
853 in_y = tt->this->mod->y_pos + tt->this->y_pos;
855 if (((t->this->mod == top_cc_mod)&&(tt->this->mod == bot_cc_mod)) ||
856 ((t->this->mod == bot_cc_mod)&&(tt->this->mod == top_cc_mod)))
857 { /* Skip cc modules */
858 also_unscrewed = TRUE;
861 else if (out_x > in_x)
862 { xfouls += 1; }
864 else if (out_y < in_y)
865 { possibly_screwed = TRUE; }
867 else
868 { also_unscrewed = TRUE; }
872 if ((possibly_screwed == TRUE) && (also_unscrewed == FALSE)) yfouls += 1;
875 /* for next iteration: */
876 last_m = m;
877 last_m->placed = UNPLACED;
881 /* Done gathering statistics! */
882 terminal_count = term_count; /* Set the global so others can use it */
884 fprintf(f,"------------------------------------------------------------------------------\n");
886 fprintf(f,"? -p%d -s%d -c%d -r%-4.2f | %d\t ||",
887 partition_rule, max_partition_size, max_partition_conn,
888 partition_ratio, term_count);
890 fprintf(f, "\t %d \t %d \t %d \t %dx%d = %d",
891 xfouls, yfouls, xfouls+yfouls, x_sizes[0], y_sizes[0], x_sizes[0] * y_sizes[0]);
892 print_distance_stats(f);
893 fprintf(f," |\n");
894 fclose(f);
898 /*--------------------------------------------------------------
899 * stats_table_header (incomplete)
900 *---------------------------------------------------------------
902 void stats_table_header(f)
903 FILE *f;
905 int lev, cc_count[10], term_count;
907 fprintf(f, "Modules: %d, Nets: %d, Terminals: %d, Partitions: %d\n",
908 module_count, node_count, term_count, partition_count);
910 fprintf(f, "CC Stats: ");
912 for(lev = 1; lev <= cc_search_level; lev++)
914 fprintf(f, "lev%d: %d ", lev, cc_count[lev-1]);
920 *---------------------------------------------------------------
921 * END OF FILE
922 *---------------------------------------------------------------