Skip to content

Commit 29df7fb

Browse files
committed
applied some code suggestions
1 parent f6cde44 commit 29df7fb

File tree

3 files changed

+80
-79
lines changed

3 files changed

+80
-79
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ typedef enum e_power_estimation_method_ e_power_estimation_method;
246246
typedef enum e_power_estimation_method_ t_power_estimation_method;
247247

248248
/* Specifies what part of the FPGA a custom switchblock should be built in (i.e. perimeter, core, everywhere) */
249-
enum e_sb_location {
249+
enum class e_sb_location {
250250
E_PERIMETER = 0,
251251
E_CORNER,
252252
E_FRINGE, /* perimeter minus corners */
@@ -255,7 +255,10 @@ enum e_sb_location {
255255
E_XY_SPECIFIED
256256
};
257257

258-
struct e_sb_loc_spec{
258+
/**
259+
* @brief Describes regions that a specific switch block specifications should be applied to
260+
*/
261+
struct t_sb_loc_spec {
259262
int start = -1;
260263
int repeat = -1;
261264
int incr = -1;
@@ -1927,8 +1930,8 @@ struct t_switchblock_inf {
19271930
int y = -1; /* The exact y-axis location that this SB is used, meanignful when type is set to E_XY_specified */
19281931

19291932
/* We can also define a region to apply this SB to all locations falls into this region using regular expression in the architecture file*/
1930-
e_sb_loc_spec reg_x;
1931-
e_sb_loc_spec reg_y;
1933+
t_sb_loc_spec reg_x;
1934+
t_sb_loc_spec reg_y;
19321935

19331936
t_permutation_map permutation_map; /* map holding the permutation functions attributed to this switchblock */
19341937

@@ -2081,7 +2084,7 @@ struct t_arch {
20812084
std::vector<std::string> ipin_cblock_switch_name;
20822085

20832086
std::vector<t_grid_def> grid_layouts; //Set of potential device layouts
2084-
std::string device_layout; //the layout that is choosen to be used with command line options
2087+
std::string device_layout; //the layout that is chosen to be used with command line options
20852088

20862089
t_clock_arch_spec clock_arch; // Clock related data types
20872090

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3933,17 +3933,17 @@ static void ProcessSwitchblocks(pugi::xml_node Parent, t_arch* arch, const pugiu
39333933
tmp = get_attribute(SubElem, "type", loc_data).as_string(nullptr);
39343934
if (tmp) {
39353935
if (strcmp(tmp, "EVERYWHERE") == 0) {
3936-
sb.location = E_EVERYWHERE;
3936+
sb.location = e_sb_location::E_EVERYWHERE;
39373937
} else if (strcmp(tmp, "PERIMETER") == 0) {
3938-
sb.location = E_PERIMETER;
3938+
sb.location = e_sb_location::E_PERIMETER;
39393939
} else if (strcmp(tmp, "CORE") == 0) {
3940-
sb.location = E_CORE;
3940+
sb.location = e_sb_location::E_CORE;
39413941
} else if (strcmp(tmp, "CORNER") == 0) {
3942-
sb.location = E_CORNER;
3942+
sb.location = e_sb_location::E_CORNER;
39433943
} else if (strcmp(tmp, "FRINGE") == 0) {
3944-
sb.location = E_FRINGE;
3945-
} else if (strcmp(tmp,"XY_SPECIFIED") == 0){
3946-
sb.location = E_XY_SPECIFIED;
3944+
sb.location = e_sb_location::E_FRINGE;
3945+
} else if (strcmp(tmp, "XY_SPECIFIED") == 0) {
3946+
sb.location = e_sb_location::E_XY_SPECIFIED;
39473947
} else {
39483948
archfpga_throw(loc_data.filename_c_str(), loc_data.line(SubElem), "unrecognized switchblock location: %s\n", tmp);
39493949
}
@@ -3965,13 +3965,14 @@ static void ProcessSwitchblocks(pugi::xml_node Parent, t_arch* arch, const pugiu
39653965
sb.y = get_attribute(SubElem, "y", loc_data, ReqOpt::OPTIONAL).as_int(-1);
39663966

39673967
//check if the absolute value is within the device grid width and height
3968-
if(sb.x > grid_width || sb.y > grid_height){
3969-
archfpga_throw(loc_data.filename_c_str(), loc_data.line(SubElem), "Location (%d,%d) is not valid within the grid! grid dimensions are: (%d,%d)\n", sb.x, sb.y, grid_width, grid_height);
3968+
if(sb.x >= grid_width || sb.y >= grid_height) {
3969+
archfpga_throw(loc_data.filename_c_str(), loc_data.line(SubElem), \
3970+
"Location (%d,%d) is not valid within the grid! grid dimensions are: (%d,%d)\n", sb.x, sb.y, grid_width, grid_height);
39703971
}
39713972

39723973

3973-
/* Location also might be speicified with regular expression, get the region that this SB should be applied to*/
3974-
if (sb.x == -1 && sb.y == -1){
3974+
/* Location also might be specified with regular expression, get the region that this SB should be applied to*/
3975+
if (sb.x == -1 && sb.y == -1) {
39753976
auto startx_attr = get_attribute(SubElem, "startx", loc_data, ReqOpt::OPTIONAL);
39763977
auto endx_attr = get_attribute(SubElem, "endx", loc_data, ReqOpt::OPTIONAL);
39773978

vpr/src/route/build_switchblocks.cpp

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ int get_wire_segment_length(const DeviceGrid& grid, e_rr_type chan_type, const t
268268
static int get_switchpoint_of_wire(const DeviceGrid& grid, e_rr_type chan_type, const t_chan_seg_details& wire_details, int seg_coord, e_side sb_side);
269269

270270
/* returns true if the coordinates x/y do not correspond to the location specified by 'location' */
271-
static bool sb_not_here(const DeviceGrid& grid, int x, int y, e_sb_location location, int sb_x, int sb_y, const e_sb_loc_spec& sb_reg_x, const e_sb_loc_spec& sb_reg_y);
271+
static bool sb_not_here(const DeviceGrid& grid, int x, int y, const t_switchblock_inf& sb);
272272

273273
/* checks if the specified coordinates represent a corner of the FPGA */
274274
static bool is_corner(const DeviceGrid& grid, int x, int y);
@@ -280,7 +280,7 @@ static bool is_perimeter(const DeviceGrid& grid, int x, int y);
280280
static bool is_core(const DeviceGrid& grid, int x, int y);
281281

282282
/*checks if the specified coordinates matches the exact one specified in the SB architecture description*/
283-
static bool match_sb_xy(const DeviceGrid& grid, int x, int y, int sb_x, int sb_y, const e_sb_loc_spec& sb_reg_x, const e_sb_loc_spec& sb_reg_y);
283+
static bool match_sb_xy(const DeviceGrid& grid, int x, int y, const t_switchblock_inf& sb);
284284

285285
/* adjusts a negative destination wire index calculated from a permutation formula */
286286
static int adjust_formula_result(int dest_wire, int src_W, int dest_W, int connection_ind);
@@ -320,9 +320,8 @@ t_sb_connection_map* alloc_and_load_switchblock_permutations(const t_chan_detail
320320

321321
/******** slow switch block computation method; computes switchblocks at each coordinate ********/
322322
/* iterate over all the switchblocks specified in the architecture */
323-
for (int i_sb = 0; i_sb < (int)switchblocks.size(); i_sb++) {
324-
t_switchblock_inf sb = switchblocks[i_sb];
325-
323+
for (auto sb: switchblocks) {
324+
326325
/* verify that switchblock type matches specified directionality -- currently we have to stay consistent */
327326
if (directionality != sb.directionality) {
328327
VPR_FATAL_ERROR(VPR_ERROR_ARCH, "alloc_and_load_switchblock_connections: Switchblock %s does not match directionality of architecture\n", sb.name.c_str());
@@ -331,7 +330,7 @@ t_sb_connection_map* alloc_and_load_switchblock_permutations(const t_chan_detail
331330
/* Iterate over the x,y coordinates spanning the FPGA. */
332331
for (size_t x_coord = 0; x_coord < grid.width(); x_coord++) {
333332
for (size_t y_coord = 0; y_coord <= grid.height(); y_coord++) {
334-
if (sb_not_here(grid, x_coord, y_coord, sb.location, sb.x, sb.y, sb.reg_x, sb.reg_y)) {
333+
if (sb_not_here(grid, x_coord, y_coord, sb)) {
335334
continue;
336335
}
337336
/* now we iterate over all the potential side1->side2 connections */
@@ -366,41 +365,41 @@ void free_switchblock_permutations(t_sb_connection_map* sb_conns) {
366365
}
367366

368367
/* returns true if the coordinates x/y do not correspond to the location specified by 'location' */
369-
static bool sb_not_here(const DeviceGrid& grid, int x, int y, e_sb_location location, int sb_x, int sb_y, const e_sb_loc_spec& sb_reg_x, const e_sb_loc_spec& sb_reg_y) {
368+
static bool sb_not_here(const DeviceGrid& grid, int x, int y, const t_switchblock_inf& sb) {
370369
bool sb_not_here = true;
371370

372-
switch (location) {
373-
case E_EVERYWHERE:
371+
switch (sb.location) {
372+
case e_sb_location::E_EVERYWHERE:
374373
sb_not_here = false;
375374
break;
376-
case E_PERIMETER:
375+
case e_sb_location::E_PERIMETER:
377376
if (is_perimeter(grid, x, y)) {
378377
sb_not_here = false;
379378
}
380379
break;
381-
case E_CORNER:
380+
case e_sb_location::E_CORNER:
382381
if (is_corner(grid, x, y)) {
383382
sb_not_here = false;
384383
}
385384
break;
386-
case E_CORE:
385+
case e_sb_location::E_CORE:
387386
if (is_core(grid, x, y)) {
388387
sb_not_here = false;
389388
}
390389
break;
391-
case E_FRINGE:
390+
case e_sb_location::E_FRINGE:
392391
if (is_perimeter(grid, x, y) && !is_corner(grid, x, y)) {
393392
sb_not_here = false;
394393
}
395394
break;
396-
case E_XY_SPECIFIED:
397-
if(match_sb_xy(grid, x, y, sb_x, sb_y, sb_reg_x, sb_reg_y)){
395+
case e_sb_location::E_XY_SPECIFIED:
396+
if(match_sb_xy(grid, x, y, sb)) {
398397
sb_not_here = false;
399398
}
400399

401400
break;
402401
default:
403-
VPR_FATAL_ERROR(VPR_ERROR_ARCH, "sb_not_here: unrecognized location enum: %d\n", location);
402+
VPR_FATAL_ERROR(VPR_ERROR_ARCH, "sb_not_here: unrecognized location enum: %d\n", sb.location);
404403
break;
405404
}
406405
return sb_not_here;
@@ -432,67 +431,65 @@ static bool is_core(const DeviceGrid& grid, int x, int y) {
432431
return is_core;
433432
}
434433

435-
static bool match_sb_xy(const DeviceGrid& grid, int x, int y, int sb_x, int sb_y, const e_sb_loc_spec& sb_reg_x, const e_sb_loc_spec& sb_reg_y){
434+
static bool match_sb_xy(const DeviceGrid& grid, int x, int y, const t_switchblock_inf& sb){
436435

437-
//if one of sb_x and sb_y is defined, we either know the exact location (x,y) or the exact x location (will apply it to all columns)
438-
//or the exact y location (will apply it to all rows)
439-
if(sb_x != -1 || sb_y != -1){
440-
if(x == sb_x && y == sb_y){
436+
//if one of sb_x and sb_y is defined, we either know the exact location (x,y) or the exact x location (will apply it to all rows)
437+
//or the exact y location (will apply it to all columns)
438+
if(sb.x != -1 || sb.y != -1){
439+
if(x == sb.x && y == sb.y){
441440
return true;
442441
}
443442

444-
if(x == sb_x && sb_y == -1){
443+
if(x == sb.x && sb.y == -1){
445444
return true;
446445
}
447446

448-
if(sb_x == -1 && y == sb_y){
447+
if(sb.x == -1 && y == sb.y){
449448
return true;
450449
}
451450
}
452451

453452
//if both sb_x and sb_y is not defined, we have a region that we should apply this SB pattern to, we just need to check
454453
//whether the location passed into this function falls within this region or not
455-
if(sb_x == -1 && sb_y == -1){
456-
//calculate the appropiate region based on the repeatx/repeaty and current location.
457-
//This is to determine whether the given location is part of the current SB specified region with regular expression or not
458-
//After region calculation, the current SB will apply to this location if:
459-
// 1) the given (x,y) location falls into the calculated region
460-
// *AND*
461-
// 2) incrx/incry are respected within the region, this means all locations within the calculated region is
462-
// is not necessary crossponds to the current SB. If incrx/incry is equal to 1, then all locations within the
463-
// calculated region is valid.
464-
465-
//calculate the region
466-
int x_reg_step = (sb_reg_x.repeat != 0) ? (x - sb_reg_x.start) / sb_reg_x.repeat : sb_reg_x.start;
467-
int y_reg_step = (sb_reg_y.repeat != 0) ? (y - sb_reg_y.start) / sb_reg_y.repeat : sb_reg_y.start;
468-
469-
//step must be non-negative
470-
x_reg_step = (x_reg_step < 0) ? 0 : x_reg_step;
471-
y_reg_step = (y_reg_step < 0) ? 0 : y_reg_step;
472-
473-
int reg_startx = sb_reg_x.start + (x_reg_step * sb_reg_x.repeat);
474-
int reg_endx = sb_reg_x.end + (x_reg_step * sb_reg_x.repeat);
475-
reg_endx = std::min(reg_endx, int(grid.width() - 1));
476-
477-
int reg_starty = sb_reg_y.start + (y_reg_step * sb_reg_y.repeat);
478-
int reg_endy = sb_reg_y.end + (y_reg_step * sb_reg_y.repeat);
479-
reg_endy = std::min(reg_endy, int(grid.height() - 1));
480-
481-
//check x coordinate
482-
if (x >= reg_startx && x <= reg_endx){ //should fall into the region
483-
//we also should respect the incrx
484-
//if incrx is not equal to 1, all locations within this region is *NOT* valid
485-
if((y + reg_startx) % sb_reg_x.incr == 0){
486-
//valid x coordinate, check for y value
487-
if(y >= reg_starty && y <= reg_endy){
488-
//check for incry, similar as incrx
489-
if((y + reg_starty) % sb_reg_y.incr == 0){
490-
//both x and y are valid
491-
return true;
492-
}
454+
//calculate the appropriate region based on the repeatx/repeaty and current location.
455+
//This is to determine whether the given location is part of the current SB specified region with regular expression or not
456+
//After region calculation, the current SB will apply to this location if:
457+
// 1) the given (x,y) location falls into the calculated region
458+
// *AND*
459+
// 2) incrx/incry are respected within the region, this means all locations within the calculated region do
460+
// not necessarily crosspond to the current SB. If incrx/incry is equal to 1, then all locations within the
461+
// calculated region are valid.
462+
463+
//calculate the region
464+
int x_reg_step = (sb.reg_x.repeat != 0) ? (x - sb.reg_x.start) / sb.reg_x.repeat : sb.reg_x.start;
465+
int y_reg_step = (sb.reg_y.repeat != 0) ? (y - sb.reg_y.start) / sb.reg_y.repeat : sb.reg_y.start;
466+
467+
//step must be non-negative
468+
x_reg_step = std::max(0, x_reg_step);
469+
y_reg_step = std::max(0, y_reg_step);
470+
471+
int reg_startx = sb.reg_x.start + (x_reg_step * sb.reg_x.repeat);
472+
int reg_endx = sb.reg_x.end + (x_reg_step * sb.reg_x.repeat);
473+
reg_endx = std::min(reg_endx, int(grid.width() - 1));
474+
475+
int reg_starty = sb.reg_y.start + (y_reg_step * sb.reg_y.repeat);
476+
int reg_endy = sb.reg_y.end + (y_reg_step * sb.reg_y.repeat);
477+
reg_endy = std::min(reg_endy, int(grid.height() - 1));
478+
479+
//check x coordinate
480+
if (x >= reg_startx && x <= reg_endx){ //should fall into the region
481+
//we also should respect the incrx
482+
//if incrx is not equal to 1, all locations within this region are *NOT* valid
483+
if((x + reg_startx) % sb.reg_x.incr == 0){
484+
//valid x coordinate, check for y value
485+
if(y >= reg_starty && y <= reg_endy){
486+
//check for incry, similar as incrx
487+
if((y + reg_starty) % sb.reg_y.incr == 0){
488+
//both x and y are valid
489+
return true;
493490
}
494-
}
495-
}
491+
}
492+
}
496493
}
497494

498495
//if reach here, we don't have sb in this location

0 commit comments

Comments
 (0)