@@ -652,6 +652,57 @@ void FastRouteCore::updateRouteType23D(int netID,
652652 }
653653}
654654
655+ // Resistance-aware cost calculation
656+ float FastRouteCore::getMazeRouteCost3D (const int net_id,
657+ const int from_layer,
658+ const int to_layer,
659+ const int from_x,
660+ const int from_y,
661+ const int to_x,
662+ const int to_y,
663+ const bool is_via)
664+ {
665+ FrNet* net = nets_[net_id];
666+ float base_cost = 1.0 ;
667+
668+ if (is_via) {
669+ // Via transition cost
670+ base_cost = via_cost_;
671+ const int via_resistance = getViaResistance (from_layer, to_layer);
672+
673+ return base_cost + via_resistance;
674+ }
675+
676+ // Wire segment cost
677+ const float length = abs (to_x - from_x) + abs (to_y - from_y);
678+ const float wire_resistance
679+ = getLayerResistance (from_layer, length * tile_size_, net);
680+
681+ // Check congestion
682+ bool congested = false ;
683+ if (from_x == to_x) { // vertical
684+ int min_y = std::min (from_y, to_y);
685+ if (v_edges_3D_[from_layer][min_y][from_x].usage
686+ + net->getLayerEdgeCost (from_layer)
687+ > v_edges_3D_[from_layer][min_y][from_x].cap ) {
688+ congested = true ;
689+ }
690+ } else { // horizontal
691+ int min_x = std::min (from_x, to_x);
692+ if (h_edges_3D_[from_layer][from_y][min_x].usage
693+ + net->getLayerEdgeCost (from_layer)
694+ > h_edges_3D_[from_layer][from_y][min_x].cap ) {
695+ congested = true ;
696+ }
697+ }
698+
699+ if (congested) {
700+ base_cost = BIG_INT; // Heavy penalty for congestion
701+ }
702+
703+ return base_cost + wire_resistance;
704+ }
705+
655706void FastRouteCore::mazeRouteMSMDOrder3D (int expand,
656707 int ripupTHlb,
657708 int ripupTHub)
@@ -766,7 +817,9 @@ void FastRouteCore::mazeRouteMSMDOrder3D(int expand,
766817 // left
767818 if (curX > regionX1
768819 && directions_3D_[curL][curY][curX] != Direction::East) {
769- const float tmp = d1_3D_[curL][curY][curX] + 1 ;
820+ const float cost = getMazeRouteCost3D (
821+ netID, curL, curL, curX, curY, curX - 1 , curY, false );
822+ const float tmp = d1_3D_[curL][curY][curX] + cost;
770823 if (h_edges_3D_[curL][curY][curX - 1 ].usage + edge_cost
771824 <= h_edges_3D_[curL][curY][curX - 1 ].cap
772825 && net->getMinLayer () <= curL && curL <= net->getMaxLayer ()) {
@@ -811,7 +864,9 @@ void FastRouteCore::mazeRouteMSMDOrder3D(int expand,
811864 // right
812865 if (Horizontal && curX < regionX2
813866 && directions_3D_[curL][curY][curX] != Direction::West) {
814- const float tmp = d1_3D_[curL][curY][curX] + 1 ;
867+ const float cost = getMazeRouteCost3D (
868+ netID, curL, curL, curX, curY, curX + 1 , curY, false );
869+ const float tmp = d1_3D_[curL][curY][curX] + cost;
815870 const int tmpX = curX + 1 ; // the right neighbor
816871
817872 if (h_edges_3D_[curL][curY][curX].usage + edge_cost
@@ -857,7 +912,9 @@ void FastRouteCore::mazeRouteMSMDOrder3D(int expand,
857912 // bottom
858913 if (!Horizontal && curY > regionY1
859914 && directions_3D_[curL][curY][curX] != Direction::South) {
860- const float tmp = d1_3D_[curL][curY][curX] + 1 ;
915+ const float cost = getMazeRouteCost3D (
916+ netID, curL, curL, curX, curY, curX, curY - 1 , false );
917+ const float tmp = d1_3D_[curL][curY][curX] + cost;
861918 const int tmpY = curY - 1 ; // the bottom neighbor
862919 if (v_edges_3D_[curL][curY - 1 ][curX].usage + edge_cost
863920 <= v_edges_3D_[curL][curY - 1 ][curX].cap
@@ -901,7 +958,9 @@ void FastRouteCore::mazeRouteMSMDOrder3D(int expand,
901958 // top
902959 if (!Horizontal && curY < regionY2
903960 && directions_3D_[curL][curY][curX] != Direction::North) {
904- const float tmp = d1_3D_[curL][curY][curX] + 1 ;
961+ const float cost = getMazeRouteCost3D (
962+ netID, curL, curL, curX, curY, curX, curY + 1 , false );
963+ const float tmp = d1_3D_[curL][curY][curX] + cost;
905964 const int tmpY = curY + 1 ; // the top neighbor
906965 if (v_edges_3D_[curL][curY][curX].usage + edge_cost
907966 <= v_edges_3D_[curL][curY][curX].cap
@@ -945,7 +1004,10 @@ void FastRouteCore::mazeRouteMSMDOrder3D(int expand,
9451004
9461005 // down
9471006 if (curL > 0 && directions_3D_[curL][curY][curX] != Direction::Up) {
948- const float tmp = d1_3D_[curL][curY][curX] + via_cost_;
1007+ // Via cost
1008+ const float cost = getMazeRouteCost3D (
1009+ netID, curL, curL - 1 , curX, curY, curX, curY, true );
1010+ const float tmp = d1_3D_[curL][curY][curX] + cost;
9491011 const int tmpL = curL - 1 ; // the bottom neighbor
9501012
9511013 if (d1_3D_[tmpL][curY][curX]
@@ -986,7 +1048,10 @@ void FastRouteCore::mazeRouteMSMDOrder3D(int expand,
9861048 // up
9871049 if (curL < num_layers_ - 1
9881050 && directions_3D_[curL][curY][curX] != Direction::Down) {
989- const float tmp = d1_3D_[curL][curY][curX] + via_cost_;
1051+ // Via cost
1052+ const float cost = getMazeRouteCost3D (
1053+ netID, curL, curL + 1 , curX, curY, curX, curY, true );
1054+ const float tmp = d1_3D_[curL][curY][curX] + cost;
9901055 const int tmpL = curL + 1 ; // the bottom neighbor
9911056 if (d1_3D_[tmpL][curY][curX]
9921057 >= BIG_INT) // bottom neighbor not been put into src_heap_3D
0 commit comments