diff --git a/compiler/router/graph.py b/compiler/router/graph.py index e7e62da8..92c5e1fd 100644 --- a/compiler/router/graph.py +++ b/compiler/router/graph.py @@ -12,6 +12,7 @@ from openram.tech import drc from .direction import direction from .graph_node import graph_node from .graph_probe import graph_probe +from .graph_utils import snap_to_grid class graph: @@ -87,7 +88,7 @@ class graph: offset = self.router.offset p = node.center lengths = [blockage.width(), blockage.height()] - centers = blockage.center().snap_to_grid() + centers = snap_to_grid(blockage.center()) ll, ur = blockage.rect safe = [True, True] for i in range(2): @@ -111,7 +112,7 @@ class graph: for via in self.graph_vias: ll, ur = via.rect - center = via.center().snap_to_grid() + center = snap_to_grid(via.center()) if via.on_segment(ll, point, ur) and \ (center.x != point.x or center.y != point.y): return True @@ -187,7 +188,7 @@ class graph: else: # Square-like pin points = [shape.center()] for p in points: - p.snap_to_grid() + p = snap_to_grid(p) x_values.add(p.x) y_values.add(p.y) diff --git a/compiler/router/graph_shape.py b/compiler/router/graph_shape.py index 76a780c6..8801a974 100644 --- a/compiler/router/graph_shape.py +++ b/compiler/router/graph_shape.py @@ -6,6 +6,7 @@ from openram.base.pin_layout import pin_layout from openram.base.vector import vector from openram.tech import drc +from .graph_utils import snap_to_grid class graph_shape(pin_layout): @@ -18,6 +19,9 @@ class graph_shape(pin_layout): pin_layout.__init__(self, name, rect, layer_name_pp) + # Snap the shape to the grid here + ll, ur = self.rect + self.rect = [snap_to_grid(ll), snap_to_grid(ur)] self.inflated_from = inflated_from diff --git a/compiler/router/graph_utils.py b/compiler/router/graph_utils.py new file mode 100644 index 00000000..a8b491a5 --- /dev/null +++ b/compiler/router/graph_utils.py @@ -0,0 +1,25 @@ +# See LICENSE for licensing information. +# +# Copyright (c) 2016-2023 Regents of the University of California, Santa Cruz +# All rights reserved. +# +""" +Utility functions for graph router. +""" +from openram.base import vector +from openram.tech import drc + + +def snap_to_grid(v): + """ Use custom `snap_to_grid` since `vector.snap_to_grid` isn't working. """ + + return vector(snap_offset_to_grid(v.x), snap_offset_to_grid(v.y)) + + +def snap_offset_to_grid(offset): + """ + Use custom `snap_offset_to_grid` since `vector.snap_offset_to_grid` isn't + working. + """ + + return round(offset, len(str(drc["grid"]).split('.')[1]))