Skip to content

Commit 0b60604

Browse files
grt: use uint32_t for the packed coordinate dedup key
The packed (x,y) key shifted a uint16_t left by 16 into a signed int32_t, which is undefined when the high coordinate has bit 15 set (value >= 2^31). Use an unsigned 32-bit key (map and pack) to make the shift well-defined. No behavior change: the same distinct keys and first-match aliasing; 140/140 grt tests pass with byte-identical routing. Signed-off-by: Saurav Singh <saurav.singh@fermions.co>
1 parent 06b486f commit 0b60604

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/grt/src/fastroute/include/FastRoute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ class FastRouteCore
812812
// Maps a packed (x,y) grid position to the dcor index of the first node
813813
// inserted at that position, replacing an O(numpoints^2) linear scan with
814814
// O(1) average lookups. Reused across calls to avoid per-call allocation.
815-
std::unordered_map<int32_t, int> tree_node_coord_dedup_;
815+
std::unordered_map<uint32_t, int> tree_node_coord_dedup_;
816816

817817
std::vector<FrNet*> nets_;
818818
std::unordered_map<odb::dbNet*, int> db_net_id_map_; // db net -> net id

src/grt/src/fastroute/src/utility.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,10 +3018,11 @@ void FastRouteCore::setTreeNodesVariables(const int netID)
30183018
treenodes[d].lID = BIG_INT;
30193019
treenodes[d].status = 0;
30203020

3021-
// Pack the int16_t grid coordinates into a single 32-bit key.
3022-
const int32_t key
3023-
= (static_cast<int32_t>(static_cast<uint16_t>(treenodes[d].x)) << 16)
3024-
| static_cast<int32_t>(static_cast<uint16_t>(treenodes[d].y));
3021+
// Pack the int16_t grid coordinates into a single unsigned 32-bit key.
3022+
// Unsigned avoids undefined behavior from shifting into the sign bit.
3023+
const uint32_t key
3024+
= (static_cast<uint32_t>(static_cast<uint16_t>(treenodes[d].x)) << 16)
3025+
| static_cast<uint32_t>(static_cast<uint16_t>(treenodes[d].y));
30253026

30263027
if (d < num_terminals) {
30273028
const int pin_idx = sttrees_[netID].node_to_pin_idx[d];

0 commit comments

Comments
 (0)