00001 #include <assert.h>
00002 #include "util.h"
00003 #include "vpr_types.h"
00004 #include "rr_graph_sbox.h"
00005 #include "rr_graph_util.h"
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 int get_simple_switch_block_track(IN enum e_side from_side,
00030 IN enum e_side to_side,
00031 IN int from_track,
00032 IN enum e_switch_block_type
00033 switch_block_type,
00034 IN int nodes_per_chan);
00035
00036 static enum e_side get_sbox_side(IN int get_i,
00037 IN int get_j,
00038 IN t_rr_type get_type,
00039 IN int comp_i,
00040 IN int comp_j);
00041
00042
00043
00044
00045
00046 struct s_ivec ***
00047 alloc_and_load_switch_block_conn(IN int nodes_per_chan,
00048 IN enum
00049 e_switch_block_type switch_block_type,
00050 IN int Fs)
00051 {
00052 enum e_side from_side, to_side;
00053 int from_track;
00054 struct s_ivec ***switch_block_conn = NULL;
00055
00056 #ifdef CREATE_ECHO_FILES
00057 int i, j, k, l;
00058 FILE *out;
00059 #endif
00060
00061
00062 assert(3 == Fs);
00063
00064 switch_block_conn =
00065 (struct s_ivec ***)alloc_matrix3(0, 3,
00066 0, 3,
00067 0, (nodes_per_chan - 1),
00068 sizeof(struct s_ivec));
00069
00070 for(from_side = 0; from_side < 4; from_side++)
00071 {
00072 for(to_side = 0; to_side < 4; to_side++)
00073 {
00074 for(from_track = 0; from_track < nodes_per_chan;
00075 from_track++)
00076 {
00077 if(from_side != to_side)
00078 {
00079 switch_block_conn[from_side][to_side]
00080 [from_track].nelem = 1;
00081 switch_block_conn[from_side][to_side]
00082 [from_track].list =
00083 (int *)my_malloc(sizeof(int));
00084
00085 switch_block_conn[from_side][to_side]
00086 [from_track].list[0] =
00087 get_simple_switch_block_track
00088 (from_side, to_side, from_track,
00089 switch_block_type, nodes_per_chan);
00090 }
00091 else
00092 {
00093 switch_block_conn[from_side][to_side]
00094 [from_track].nelem = 0;
00095 switch_block_conn[from_side][to_side]
00096 [from_track].list = NULL;
00097 }
00098 }
00099 }
00100 }
00101
00102 #ifdef CREATE_ECHO_FILES
00103 out = my_fopen("switch_block_conn.echo", "w");
00104 for(l = 0; l < 4; ++l)
00105 {
00106 for(k = 0; k < 4; ++k)
00107 {
00108 fprintf(out, "Side %d to %d\n", l, k);
00109 for(j = 0; j < nodes_per_chan; ++j)
00110 {
00111 fprintf(out, "%d: ", j);
00112 for(i = 0; i < switch_block_conn[l][k][j].nelem;
00113 ++i)
00114 {
00115 fprintf(out, "%d ",
00116 switch_block_conn[l][k][j].
00117 list[i]);
00118 }
00119 fprintf(out, "\n");
00120 }
00121 fprintf(out, "\n");
00122 }
00123 }
00124 fclose(out);
00125 #endif
00126
00127 return switch_block_conn;
00128 }
00129
00130
00131 void
00132 free_switch_block_conn(struct s_ivec ***switch_block_conn,
00133 int nodes_per_chan)
00134 {
00135
00136
00137 free_ivec_matrix3(switch_block_conn, 0, 3, 0, 3, 0, nodes_per_chan - 1);
00138 }
00139
00140
00141 #define SBOX_ERROR -1
00142
00143
00144
00145
00146
00147
00148 int
00149 get_simple_switch_block_track(IN enum e_side from_side,
00150 IN enum e_side to_side,
00151 IN int from_track,
00152 IN enum e_switch_block_type switch_block_type,
00153 IN int nodes_per_chan)
00154 {
00155
00156
00157
00158
00159 int to_track;
00160
00161 to_track = SBOX_ERROR;
00162
00163 if(switch_block_type == SUBSET)
00164 {
00165 to_track = from_track;
00166 }
00167
00168
00169
00170
00171 else if(switch_block_type == WILTON)
00172 {
00173
00174 if(from_side == LEFT)
00175 {
00176
00177 if(to_side == RIGHT)
00178 {
00179 to_track = from_track;
00180 }
00181 else if(to_side == TOP)
00182 {
00183 to_track =
00184 (nodes_per_chan -
00185 from_track) % nodes_per_chan;
00186 }
00187 else if(to_side == BOTTOM)
00188 {
00189 to_track =
00190 (nodes_per_chan + from_track -
00191 1) % nodes_per_chan;
00192 }
00193 }
00194
00195 else if(from_side == RIGHT)
00196 {
00197 if(to_side == LEFT)
00198 {
00199 to_track = from_track;
00200 }
00201 else if(to_side == TOP)
00202 {
00203 to_track =
00204 (nodes_per_chan + from_track -
00205 1) % nodes_per_chan;
00206 }
00207 else if(to_side == BOTTOM)
00208 {
00209 to_track =
00210 (2 * nodes_per_chan - 2 -
00211 from_track) % nodes_per_chan;
00212 }
00213 }
00214
00215 else if(from_side == BOTTOM)
00216 {
00217 if(to_side == TOP)
00218 {
00219 to_track = from_track;
00220 }
00221 else if(to_side == LEFT)
00222 {
00223 to_track = (from_track + 1) % nodes_per_chan;
00224 }
00225 else if(to_side == RIGHT)
00226 {
00227 to_track =
00228 (2 * nodes_per_chan - 2 -
00229 from_track) % nodes_per_chan;
00230 }
00231 }
00232
00233 else if(from_side == TOP)
00234 {
00235 if(to_side == BOTTOM)
00236 {
00237 to_track = from_track;
00238 }
00239 else if(to_side == LEFT)
00240 {
00241 to_track =
00242 (nodes_per_chan -
00243 from_track) % nodes_per_chan;
00244 }
00245 else if(to_side == RIGHT)
00246 {
00247 to_track = (from_track + 1) % nodes_per_chan;
00248 }
00249 }
00250
00251 }
00252
00253 else if(switch_block_type == UNIVERSAL)
00254 {
00255
00256 if(from_side == LEFT)
00257 {
00258
00259 if(to_side == RIGHT)
00260 {
00261 to_track = from_track;
00262 }
00263 else if(to_side == TOP)
00264 {
00265 to_track = nodes_per_chan - 1 - from_track;
00266 }
00267 else if(to_side == BOTTOM)
00268 {
00269 to_track = from_track;
00270 }
00271 }
00272
00273 else if(from_side == RIGHT)
00274 {
00275 if(to_side == LEFT)
00276 {
00277 to_track = from_track;
00278 }
00279 else if(to_side == TOP)
00280 {
00281 to_track = from_track;
00282 }
00283 else if(to_side == BOTTOM)
00284 {
00285 to_track = nodes_per_chan - 1 - from_track;
00286 }
00287 }
00288
00289 else if(from_side == BOTTOM)
00290 {
00291 if(to_side == TOP)
00292 {
00293 to_track = from_track;
00294 }
00295 else if(to_side == LEFT)
00296 {
00297 to_track = from_track;
00298 }
00299 else if(to_side == RIGHT)
00300 {
00301 to_track = nodes_per_chan - 1 - from_track;
00302 }
00303 }
00304
00305 else if(from_side == TOP)
00306 {
00307 if(to_side == BOTTOM)
00308 {
00309 to_track = from_track;
00310 }
00311 else if(to_side == LEFT)
00312 {
00313 to_track = nodes_per_chan - 1 - from_track;
00314 }
00315 else if(to_side == RIGHT)
00316 {
00317 to_track = from_track;
00318 }
00319 }
00320 }
00321
00322
00323
00324 if(switch_block_type == FULL)
00325 {
00326 to_track = from_track;
00327 }
00328
00329
00330 if(to_track == SBOX_ERROR)
00331 {
00332 printf
00333 ("Error in get_simple_switch_block_track. Unexpected connection.\n"
00334 "from_side: %d to_side: %d switch_block_type: %d.\n",
00335 from_side, to_side, switch_block_type);
00336 exit(1);
00337 }
00338
00339 return (to_track);
00340 }