Also copy the module in PartotionSignal.like()
[ieee754fpu.git] / src / ieee754 / part / partsig.py
index d710b7ff186620dd60435fa4265bc27b5bd448f1..24fd80d4cb7985588a134a8789a1b2add2d480dd 100644 (file)
@@ -60,16 +60,27 @@ class PartitionedSignal:
     def eq(self, val):
         return self.sig.eq(getsig(val))
 
+    @staticmethod
+    def like(other, *args, **kwargs):
+        """Builds a new PartitionedSignal with the same PartitionPoints and
+        Signal properties as the other"""
+        result = PartitionedSignal(other.partpoints)
+        result.sig = Signal.like(other.sig, *args, **kwargs)
+        result.m = other.m
+        return result
+
     # unary ops that do not require partitioning
 
     def __invert__(self):
-        return ~self.sig
+        result = PartitionedSignal.like(self)
+        self.m.d.comb += result.sig.eq(~self.sig)
+        return result
 
     # 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
@@ -320,4 +331,4 @@ class PartitionedSignal:
             ``1`` otherwise.
         """
         # amazingly, this should actually work.
-        return ~premise | conclusion
+        return conclusion | ~premise