hdl.ast: add Value.xor, mapping to $reduce_xor.

Fixes #147.
This commit is contained in:
whitequark 2019-09-13 14:28:43 +00:00
parent b23a9794a4
commit 32310aecad
4 changed files with 23 additions and 0 deletions

View file

@ -135,6 +135,9 @@ class _RHSValueCompiler(_ValueCompiler):
val, = value.operands
mask = (1 << len(val)) - 1
return lambda state: normalize(arg(state) == mask, shape)
if value.op == "r^":
# Believe it or not, this is the fastest way to compute a sideways XOR in Python.
return lambda state: normalize(str(arg(state)).count("1") % 2, shape)
elif len(value.operands) == 2:
lhs, rhs = map(self, value.operands)
if value.op == "+":