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 <kbastian@mail.uni-paderborn.de>
This commit is contained in:
Bastian Koppelmann 2020-01-03 11:39:59 +01:00
parent 14e8a26246
commit 7ff5121d8c
1 changed files with 13 additions and 2 deletions

View File

@ -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 """