from ieee754.part_mul_add.adder import PartitionedAdder
from ieee754.part_cmp.eq_gt_ge import PartitionedEqGtGe
+from ieee754.part_bits.xor import PartitionedXOR
from ieee754.part_shift.part_shift_dynamic import PartitionedDynamicShift
from ieee754.part_shift.part_shift_scalar import PartitionedScalarShift
from ieee754.part_mul_add.partpoints import make_partition, PartitionPoints
else:
self.partpoints = make_partition(mask, width)
self.modnames = {}
- for name in ['add', 'eq', 'gt', 'ge', 'ls']:
+ for name in ['add', 'eq', 'gt', 'ge', 'ls', 'xor']:
self.modnames[name] = 0
def set_module(self, m):
# unary ops that require partitioning
def __neg__(self):
- z = Const(0, len(self.partpoints)+1)
- result, _ = self.add_op(self, ~0, carry=z) # TODO, subop
+ z = Const(0, len(self.sig))
+ result, _ = self.sub_op(z, self)
return result
# binary ops that don't require partitioning
Value, out
``1`` if any bits are set, ``0`` otherwise.
"""
+ return self != Const(0) # leverage the __ne__ operator here
return Operator("r|", [self])
def all(self):
``1`` if an odd number of bits are set, ``0`` if an
even number of bits are set.
"""
- # XXXX TODO: return partition-mask-sized set of bits
- raise NotImplementedError
- return Operator("r^", [self])
+ width = len(self.sig)
+ pa = PartitionedXOR(width, self.partpoints)
+ setattr(self.m.submodules, self.get_modname("xor"), pa)
+ self.m.d.comb += pa.a.eq(self.sig)
+ return pa.output
def implies(premise, conclusion):
"""Implication.
``1`` otherwise.
"""
# amazingly, this should actually work.
- return ~premise | conclusion
+ return conclusion | ~premise