Convert partsig to use the existing add_op function
authorMichael Nolan <mtnolan2640@gmail.com>
Sun, 9 Feb 2020 01:47:06 +0000 (20:47 -0500)
committerMichael Nolan <mtnolan2640@gmail.com>
Sun, 9 Feb 2020 01:47:06 +0000 (20:47 -0500)
src/ieee754/part/partsig.py
src/ieee754/part/test/test_partsig.py

index 2c2da8a90a6e34e0b4a4996beefaf44f762e96db..f71ecb4a679cfbca2008b85d3f0d0dbc86d9f155 100644 (file)
@@ -98,7 +98,7 @@ class PartitionedSignal:
     def __rrshift__(self, other):
         return Operator(">>", [other, self])
 
-    def add_op(self, op1, op2):
+    def add_op(self, op1, op2, carry):
         op1 = getsig(op1)
         op2 = getsig(op2)
         shape = op1.shape()
@@ -107,23 +107,13 @@ class PartitionedSignal:
         comb = self.m.d.comb
         comb += pa.a.eq(op1)
         comb += pa.b.eq(op2)
-        return pa.output
+        comb += pa.carry_in.eq(carry)
+        return (pa.output, pa.carry_out)
 
     def __add__(self, other):
-        return self.add_op(self, other)
+        result, _ =self.add_op(self, other, carry=0)
+        return result
 
-    def addc(self, other, carry):
-        shape = self.sig.shape()
-        pa = PartitionedAdder(shape[0], self.partpoints)
-        setattr(self.m.submodules, self.get_modname('add'), pa)
-        comb = self.m.d.comb
-        comb += pa.a.eq(self.sig)
-        comb += pa.carry_in.eq(carry)
-        if isinstance(other, PartitionedSignal):
-            comb += pa.b.eq(other.sig)
-        else:
-            comb += pa.b.eq(other)
-        return (pa.output, pa.carry_out)
 
     def __radd__(self, other):
         return self.add_op(other, self)
index 5e5f310b361ebb70fe015f2953cc779f84fc8e54..774e119f6a2525a8cf44e205ceaf6b7034b39db0 100644 (file)
@@ -57,7 +57,8 @@ class TestAddMod(Elaboratable):
         m.d.comb += self.gt_output.eq(self.a > self.b)
         m.d.comb += self.eq_output.eq(self.a == self.b)
         m.d.comb += self.ge_output.eq(self.a >= self.b)
-        add_out, add_carry = self.a.addc(self.b, self.carry_in)
+        add_out, add_carry = self.a.add_op(self.a, self.b,
+                                           self.carry_in)
         m.d.comb += self.add_output.eq(add_out)
         m.d.comb += self.carry_out.eq(add_carry)
         ppts = self.partpoints