From 7ff5121d8ce33ba7ae45d0914e493da13da5d515 Mon Sep 17 00:00:00 2001 From: Bastian Koppelmann Date: Fri, 3 Jan 2020 11:39:59 +0100 Subject: [PATCH] base/pin_layout: Implement hash cache the hash value only depends of the properties 'rect' and 'layer' so we only compute the hash if those values are changed. Otherwise we just return the precomputed value. This gives us a major speedup (~10x) if the hash is used as a key in a dict. During the grouping of pins in analyze_pins() this gives the best improvements. For example for FreePDK45 with num_bits=8, num_words=256 Improved **** Analyzing pins: 20.9 seconds ** Routing: 293.8 seconds ** SRAM creation: 349.8 seconds Non-improved **** Analyzing pins: 267.9 seconds ** Routing: 537.5 seconds ** SRAM creation: 592.9 seconds Signed-off-by: Bastian Koppelmann --- compiler/base/pin_layout.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/base/pin_layout.py b/compiler/base/pin_layout.py index 451bb1ed..d7f6c49e 100644 --- a/compiler/base/pin_layout.py +++ b/compiler/base/pin_layout.py @@ -46,6 +46,7 @@ class pin_layout: debug.error("Couldn't find layer {}".format(layer_name_pp), -1) self.lpp = layer[self.layer] + self._recompute_hash() @property def layer(self): @@ -54,6 +55,7 @@ class pin_layout: @layer.setter def layer(self, l): self._layer = l + self._recompute_hash() @property def rect(self): @@ -62,6 +64,11 @@ class pin_layout: @rect.setter def rect(self, r): self._rect = r + self._recompute_hash() + + def _recompute_hash(self): + """ Recompute the hash for our hash cache """ + self._hash = hash(repr(self)) def __str__(self): """ override print function output """ @@ -80,8 +87,12 @@ class pin_layout: self.rect[1]) def __hash__(self): - """ Implement the hash function for sets etc. """ - return hash(repr(self)) + """ + Implement the hash function for sets etc. We only return a cached + value, that is updated when either 'rect' or 'layer' are changed. This + is a major speedup, if pin_layout is used as a key for dicts. + """ + return self._hash def __lt__(self, other): """ Provide a function for ordering items by the ll point """