Skip to content

Commit

Permalink
[Sim][#50] Eliminate 'neq' as a separate operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Oct 3, 2022
1 parent dfec2b0 commit f94b247
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions tests/z80sim/z80sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@ def get(n):
a, b = ops
a, b = get(a), get(b)
add((~a, ~b, r), (a, b, r), (a, ~b, ~r), (~a, b, ~r))
elif kind == 'neq':
# TODO: Can be just not(eq())?
a, b = ops
a, b = get(a), get(b)
add((~a, ~b, ~r), (a, b, ~r), (a, ~b, r), (~a, b, r))
elif kind == 'ifelse':
i, t, e = ops
i, t, e = get(i), get(t), get(e)
Expand Down Expand Up @@ -400,7 +395,7 @@ def from_ops(kind, *ops):

COMMUTATIVE = {
'not': False, 'ifelse': False,
'eq': True, 'neq': True, 'or': True, 'and': True}
'eq': True, 'or': True, 'and': True}
if COMMUTATIVE[kind]:
syms = tuple(sorted(syms))

Expand Down Expand Up @@ -629,16 +624,7 @@ def get_eq(a, b):

@staticmethod
def get_neq(a, b):
if a is b:
return FALSE
if a is b.__inversion:
return TRUE
if a.value is not None:
return ~b if a.value else b
if b.value is not None:
return ~a if b.value else a

return __class__.from_ops('neq', a, b)
return ~__class__.get_eq(a, b)

def is_equiv(self, other):
e = Bool.get_neq(self, other)
Expand Down Expand Up @@ -676,7 +662,6 @@ def get(n):
kind, ops = n._e
OPS = {'or': z3.Or, 'and': z3.And, 'not': z3.Not,
'eq': lambda a, b: a == b,
'neq': lambda a, b: a != b,
'ifelse': z3.If}
r = cache[n.symbol] = OPS[kind](*(get(op) for op in ops))
return r
Expand Down

0 comments on commit f94b247

Please sign in to comment.