From fa272be3bdfef4d68aab728fc93964f46290028b Mon Sep 17 00:00:00 2001 From: Matt Guthaus Date: Mon, 29 Oct 2018 13:49:29 -0700 Subject: [PATCH] Enumerate more enclosures. --- compiler/router/direction.py | 23 +++++++++++++++++++++ compiler/router/grid_utils.py | 18 +++-------------- compiler/router/pin_group.py | 38 +++++++++++++++++++++++------------ compiler/router/router.py | 15 +++++++------- 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/compiler/router/direction.py b/compiler/router/direction.py index 95980618..c3de59a2 100644 --- a/compiler/router/direction.py +++ b/compiler/router/direction.py @@ -1,4 +1,5 @@ from enum import Enum +from vector3d import vector3d class direction(Enum): NORTH = 1 @@ -7,3 +8,25 @@ class direction(Enum): WEST = 4 UP = 5 DOWN = 6 + + + def get_offset(direct): + """ + Returns the vector offset for a given direction. + """ + if direct==direction.NORTH: + offset = vector3d(0,1,0) + elif direct==direction.SOUTH: + offset = vector3d(0,-1,0) + elif direct==direction.EAST: + offset = vector3d(1,0,0) + elif direct==direction.WEST: + offset = vector3d(-1,0,0) + elif direct==direction.UP: + offset = vector3d(0,0,1) + elif direct==direction.DOWN: + offset = vector3d(0,0,-1) + else: + debug.error("Invalid direction {}".format(dirct)) + + return offset diff --git a/compiler/router/grid_utils.py b/compiler/router/grid_utils.py index 62caebe9..748933b6 100644 --- a/compiler/router/grid_utils.py +++ b/compiler/router/grid_utils.py @@ -6,25 +6,13 @@ import debug from direction import direction from vector3d import vector3d + def increment_set(curset, direct): """ Return the cells incremented in given direction """ - if direct==direction.NORTH: - offset = vector3d(0,1,0) - elif direct==direction.SOUTH: - offset = vector3d(0,-1,0) - elif direct==direction.EAST: - offset = vector3d(1,0,0) - elif direct==direction.WEST: - offset = vector3d(-1,0,0) - elif direct==direction.UP: - offset = vector3d(0,0,1) - elif direct==direction.DOWN: - offset = vector3d(0,0,-1) - else: - debug.error("Invalid direction {}".format(dirct)) - + offset = direction.get_offset(direct) + newset = set() for c in curset: newc = c+offset diff --git a/compiler/router/pin_group.py b/compiler/router/pin_group.py index 57bb3419..57191d63 100644 --- a/compiler/router/pin_group.py +++ b/compiler/router/pin_group.py @@ -1,3 +1,4 @@ +from direction import direction from pin_layout import pin_layout from vector3d import vector3d from vector import vector @@ -57,7 +58,7 @@ class pin_group: """ Remove any pin layout that is contained within another. """ - local_debug = True + local_debug = False if local_debug: debug.info(0,"INITIAL: {}".format(pin_list)) @@ -67,6 +68,7 @@ class pin_group: remove_indices = set() # This is n^2, but the number is small for index1,pin1 in enumerate(pin_list): + # If we remove this pin, it can't contain other pins if index1 in remove_indices: continue @@ -74,6 +76,7 @@ class pin_group: # Can't contain yourself if pin1 == pin2: continue + # If we already removed it, can't remove it again... if index2 in remove_indices: continue @@ -81,6 +84,7 @@ class pin_group: if local_debug: debug.info(0,"{0} contains {1}".format(pin1,pin2)) remove_indices.add(index2) + # Remove them in decreasing order to not invalidate the indices for i in sorted(remove_indices, reverse=True): del new_pin_list[i] @@ -98,15 +102,19 @@ class pin_group: # Enumerate every possible enclosure pin_list = [] for seed in self.grids: - (ll, ur) = self.enclose_pin_grids(seed) + (ll, ur) = self.enclose_pin_grids(seed, direction.NORTH, direction.EAST) + enclosure = self.router.compute_pin_enclosure(ll, ur, ll.z) + pin_list.append(enclosure) + + (ll, ur) = self.enclose_pin_grids(seed, direction.EAST, direction.NORTH) enclosure = self.router.compute_pin_enclosure(ll, ur, ll.z) pin_list.append(enclosure) return self.remove_redundant_shapes(pin_list) - def compute_enclosure(self, pin, enclosure): + def compute_connector(self, pin, enclosure): """ - Compute an enclosure to connect the pin to the enclosure shape. + Compute a shape to connect the pin to the enclosure shape. This assumes the shape will be the dimension of the pin. """ if pin.xoverlaps(enclosure): @@ -155,7 +163,7 @@ class pin_group: for pin_list in self.pins: for pin in pin_list: for enclosure in enclosure_list: - new_enclosure = self.compute_enclosure(pin, enclosure) + new_enclosure = self.compute_connector(pin, enclosure) if smallest == None or new_enclosure.area() {0}\n {1}\n".format(combined.pins,combined.grids)) remove_indices.update([index1,index2]) @@ -210,7 +210,7 @@ class router(router_tech): removed_pairs = len(remove_indices)/2 debug.info(1, "Combined {0} pin pairs for {1}".format(removed_pairs,pin_name)) - return(removed_pairs) + return removed_pairs def combine_adjacent_pins(self, pin_name): """ @@ -564,7 +564,8 @@ class router(router_tech): Analyze the shapes of a pin and combine them into groups which are connected. """ pin_set = self.pins[pin_name] - local_debug=False + local_debug = False + # Put each pin in an equivalence class of it's own equiv_classes = [set([x]) for x in pin_set] if local_debug: @@ -595,6 +596,8 @@ class router(router_tech): def combine_classes(equiv_classes): """ Recursive function to combine classes. """ + local_debug = False + if local_debug: debug.info(0,"\nRECURSE:\n",pformat(equiv_classes)) if len(equiv_classes)==1: @@ -634,10 +637,6 @@ class router(router_tech): put a rectangle over it. It does not enclose grid squares that are blocked by other shapes. """ - # These are used for debugging - self.connector_enclosure = [] - self.enclosures = [] - for pin_name in self.pin_groups.keys(): debug.info(1,"Enclosing pins for {}".format(pin_name)) for pg in self.pin_groups[pin_name]: