VPR-6.0

vpr/SRC/route/rr_graph_util.c

Go to the documentation of this file.
00001 #include "util.h"
00002 #include "vpr_types.h"
00003 #include "globals.h"
00004 #include "rr_graph_util.h"
00005 
00006 
00007 
00008 /** Inserts a new element at the head of a linked list.  Returns the new head 
00009  * of the list.  One argument is the address of the head of a list of free   
00010  * edge_list elements.  If there are any elements on this free list, the new 
00011  * element is taken from it.  Otherwise a new one is malloced.               
00012  */
00013 t_linked_edge *
00014 insert_in_edge_list(INP t_linked_edge * head,
00015                     INP int edge,
00016                     INP short iswitch)
00017 {
00018 
00019     t_linked_edge *linked_edge;
00020 
00021     linked_edge = (t_linked_edge *) my_malloc(sizeof(t_linked_edge));
00022 
00023     linked_edge->edge = edge;
00024     linked_edge->iswitch = iswitch;
00025     linked_edge->next = head;
00026 
00027     return linked_edge;
00028 }
00029 
00030 #if 0
00031 void
00032 free_linked_edge_soft(INOUT t_linked_edge * edge_ptr,
00033                       INOUT t_linked_edge ** free_list_head_ptr)
00034 {
00035 
00036     /* This routine does a soft free of the structure pointed to by edge_ptr by *
00037      * adding it to the free list.  You have to pass in the address of the      *
00038      * head of the free list.                                                   */
00039 
00040     edge_ptr->next = *free_list_head_ptr;
00041     *free_list_head_ptr = edge_ptr;
00042 }
00043 #endif
00044 
00045 /** Returns the segment number (distance along the channel) of the connection 
00046  * box from from_rr_type (CHANX or CHANY) to to_node (IPIN).                 
00047  */
00048 int
00049 seg_index_of_cblock(t_rr_type from_rr_type,
00050                     int to_node)
00051 {
00052 
00053     if(from_rr_type == CHANX)
00054         return (rr_node[to_node].xlow);
00055     else                        /* CHANY */
00056         return (rr_node[to_node].ylow);
00057 }
00058 
00059 /** Returns the segment number (distance along the channel) of the switch box 
00060  * box from from_node (CHANX or CHANY) to to_node (CHANX or CHANY).  The     
00061  * switch box on the left side of a CHANX segment at (i,j) has seg_index =   
00062  * i-1, while the switch box on the right side of that segment has seg_index 
00063  * = i.  CHANY stuff works similarly.  Hence the range of values returned is 
00064  * 0 to nx (if from_node is a CHANX) or 0 to ny (if from_node is a CHANY).   
00065  */
00066 int
00067 seg_index_of_sblock(int from_node,
00068                     int to_node)
00069 {
00070 
00071     t_rr_type from_rr_type, to_rr_type;
00072 
00073     from_rr_type = rr_node[from_node].type;
00074     to_rr_type = rr_node[to_node].type;
00075 
00076     if(from_rr_type == CHANX)
00077         {
00078             if(to_rr_type == CHANY)
00079                 {
00080                     return (rr_node[to_node].xlow);
00081                 }
00082             else if(to_rr_type == CHANX)
00083                 {
00084                     if(rr_node[to_node].xlow > rr_node[from_node].xlow)
00085                         {       /* Going right */
00086                             return (rr_node[from_node].xhigh);
00087                         }
00088                     else
00089                         {       /* Going left */
00090                             return (rr_node[to_node].xhigh);
00091                         }
00092                 }
00093             else
00094                 {
00095                     printf
00096                         ("Error in seg_index_of_sblock:  to_node %d is of type %d.\n",
00097                          to_node, to_rr_type);
00098                     exit(1);
00099                 }
00100         }
00101     /* End from_rr_type is CHANX */
00102     else if(from_rr_type == CHANY)
00103         {
00104             if(to_rr_type == CHANX)
00105                 {
00106                     return (rr_node[to_node].ylow);
00107                 }
00108             else if(to_rr_type == CHANY)
00109                 {
00110                     if(rr_node[to_node].ylow > rr_node[from_node].ylow)
00111                         {       /* Going up */
00112                             return (rr_node[from_node].yhigh);
00113                         }
00114                     else
00115                         {       /* Going down */
00116                             return (rr_node[to_node].yhigh);
00117                         }
00118                 }
00119             else
00120                 {
00121                     printf
00122                         ("Error in seg_index_of_sblock:  to_node %d is of type %d.\n",
00123                          to_node, to_rr_type);
00124                     exit(1);
00125                 }
00126         }
00127     /* End from_rr_type is CHANY */
00128     else
00129         {
00130             printf
00131                 ("Error in seg_index_of_sblock:  from_node %d is of type %d.\n",
00132                  from_node, from_rr_type);
00133             exit(1);
00134         }
00135 }