Skip to content

Commit

Permalink
[Sim][#50] Use the simplest of known-to-be-equivalent states.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Oct 2, 2022
1 parent 2de67e9 commit dfec2b0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/z80sim/z80sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def get(term):
true = __class__.__cache[True] = __class__()
false.value, true.value = False, True
false.__inversion, true.__inversion = true, false
false.size = true.size = 1
return true if term else false

assert isinstance(term, Literal)
Expand All @@ -332,6 +333,7 @@ def get(term):
b.symbol = term
b._e = None
b.__inversion = None
b.size = 1
return b

@property
Expand Down Expand Up @@ -409,6 +411,7 @@ def from_ops(kind, *ops):

b = __class__.__cache[key] = Bool.get(Literal.get(None))
b._e = kind, ops
b.size = sum(op.size for op in ops) + 1

if kind == 'not':
op, = ops
Expand Down Expand Up @@ -516,11 +519,6 @@ def __bool__(self):
def __int__(self):
return int(bool(self))

@property
def size(self):
assert 0 # TODO
return len(str(self))

def __eq__(self, other):
assert 0, "Bool's should not be compared; use is_equiv() instead."

Expand Down Expand Up @@ -1379,7 +1377,11 @@ def __update_group_of(self, n, more, updated):
# No further propagation is necessary if the state of
# the transistor is known to be same. This includes
# the case of a floating gate.
if not state.is_equiv(n.state):
if state.is_equiv(n.state):
# Choose the simplest of the two equivalent states.
if state.size < n.state.size:
n.state = state
else:
n.state = state
for t in n.gate_of:
for c in t.conns:
Expand Down Expand Up @@ -1759,7 +1761,7 @@ def __get_cache(steps):
# Whenever we make changes that invalidate cached states,
# e.g., the names of the nodes are changed, the version
# number must be bumped.
VERSION = 7
VERSION = 8

key = VERSION, __class__.__get_steps_image(steps)
return Cache.get_entry('states', key)
Expand Down

0 comments on commit dfec2b0

Please sign in to comment.