SRC/mst.c File Reference
#include <limits.h>
#include "util.h"
#include "vpr_types.h"
#include "globals.h"
#include "mst.h"
Go to the source code of this file.
Define Documentation
#define ABS_DIFF |
( |
X, |
|
|
Y |
|
) |
(((X) > (Y))? ((X) - (Y)):((Y) - (X))) |
Definition at line 7 of file mst.c.
Function Documentation
Definition at line 15 of file mst.c.
00016 {
00017 int i, ipin, node_dist, node_in_mst, num_pins_on_net, num_edges;
00018 int nearest_node, nearest_node_dist, nearest_node_in_mst;
00019 t_mst_edge *min_spantree;
00020 boolean *in_mst;
00021
00022
00023
00024 num_pins_on_net = (net[inet].num_sinks + 1);
00025 if(num_pins_on_net > USHRT_MAX)
00026 {
00027 printf("Error: num_pins_on_net (%d) > USHRT_MAX(%u)\n",
00028 num_pins_on_net, USHRT_MAX);
00029 exit(1);
00030 }
00031
00032
00033 min_spantree =
00034 (t_mst_edge *) my_malloc(sizeof(t_mst_edge) * (num_pins_on_net - 1));
00035 in_mst = (boolean *) my_malloc(sizeof(boolean) * (num_pins_on_net));
00036
00037
00038 in_mst[0] = TRUE;
00039 for(ipin = 1; ipin < num_pins_on_net; ipin++)
00040 in_mst[ipin] = FALSE;
00041
00042 num_edges = 0;
00043
00044
00045 for(i = 1; i < num_pins_on_net; i++)
00046 {
00047
00048
00049 nearest_node = -1;
00050 nearest_node_dist = -1;
00051 nearest_node_in_mst = -1;
00052
00053 for(ipin = 1; ipin < num_pins_on_net; ipin++)
00054 {
00055
00056 if(!in_mst[ipin])
00057 {
00058 node_dist =
00059 min_dist_from_mst(ipin, inet, in_mst,
00060 &node_in_mst);
00061
00062 if(nearest_node == -1)
00063 {
00064 nearest_node = ipin;
00065 nearest_node_dist = node_dist;
00066 nearest_node_in_mst = node_in_mst;
00067 }
00068 else
00069 {
00070
00071 if(nearest_node_dist >= node_dist)
00072 {
00073 nearest_node = ipin;
00074 nearest_node_dist = node_dist;
00075 nearest_node_in_mst = node_in_mst;
00076 }
00077
00078 if(nearest_node_dist < 0)
00079 {
00080 printf
00081 ("Error: distance is negative\n");
00082 exit(1);
00083 }
00084 }
00085 }
00086 }
00087
00088
00089 min_spantree[num_edges].from_node = nearest_node_in_mst;
00090
00091 min_spantree[num_edges].to_node = nearest_node;
00092
00093 num_edges++;
00094
00095 in_mst[nearest_node] = TRUE;
00096 }
00097
00098 free(in_mst);
00099 return min_spantree;
00100 }
static int min_dist_from_mst |
( |
int |
node_outside, |
|
|
int |
inet, |
|
|
boolean * |
in_mst, |
|
|
int * |
node_inside | |
|
) |
| | [static] |
Definition at line 103 of file mst.c.
00107 {
00108 int ipin, blk1, blk2, dist, closest_node_in_mst, shortest_dist;
00109
00110
00111
00112
00113 closest_node_in_mst = -1;
00114 shortest_dist = -1;
00115
00116 for(ipin = 0; ipin < (net[inet].num_sinks + 1); ipin++)
00117 {
00118 if(in_mst[ipin])
00119 {
00120 blk1 = net[inet].node_block[node_outside];
00121 blk2 = net[inet].node_block[ipin];
00122
00123 dist =
00124 ABS_DIFF(block[blk1].x,
00125 block[blk2].x) + ABS_DIFF(block[blk1].y,
00126 block[blk2].y);
00127
00128 if(closest_node_in_mst == -1)
00129 {
00130 closest_node_in_mst = ipin;
00131 shortest_dist = dist;
00132 }
00133 else
00134 {
00135 if(shortest_dist > dist)
00136 {
00137 closest_node_in_mst = ipin;
00138 shortest_dist = dist;
00139 }
00140 }
00141 }
00142 }
00143
00144 *node_inside = closest_node_in_mst;
00145
00146 return shortest_dist;
00147 }