restructure partsig, use common function for PartitionedEqGtGe
[ieee754fpu.git] / src / ieee754 / part / partsig.py
index 0b9b1336d358d66bbdcb6591f8eab334ab21db31..e3f056d23a41c7bc7e12a572197b42f78a288d9b 100644 (file)
@@ -38,7 +38,7 @@ class PartitionedSignal:
         width = self.sig.shape()[0] # get signal width
         self.partpoints = make_partition(mask, width) # create partition points
         self.modnames = {}
-        for name in ['add', 'eq']:
+        for name in ['add', 'eq', 'gt', 'ge']:
             self.modnames[name] = 0
 
     def set_module(self, m):
@@ -81,15 +81,33 @@ class PartitionedSignal:
             comb += pa.b.eq(other)
         return pa.output
 
-    def __eq__(self, other):
-        print ("eq", self, other)
-        shape = self.sig.shape()
-        pa = PartitionedEq(shape[0], self.partpoints)
-        setattr(self.m.submodules, self.get_modname('eq'), pa)
+    def _compare(self, width, op1, op2, opname, optype):
+        #print (opname, op1, op2)
+        pa = PartitionedEqGtGe(width, self.partpoints)
+        setattr(self.m.submodules, self.get_modname(opname), pa)
         comb = self.m.d.comb
-        comb += pa.a.eq(self.sig)
-        if isinstance(other, PartitionedSignal):
-            comb += pa.b.eq(other.sig)
+        comb += pa.opcode.eq(optype) # set opcode
+        if isinstance(op1, PartitionedSignal):
+            comb += pa.a.eq(op1.sig)
         else:
-            comb += pa.b.eq(other)
+            comb += pa.a.eq(op1)
+        if isinstance(op2, PartitionedSignal):
+            comb += pa.b.eq(op2.sig)
+        else:
+            comb += pa.b.eq(op2)
         return pa.output
+
+    def __eq__(self, other):
+        width = self.sig.shape()[0]
+        return self._compare(width, self, other, "eq", PartitionedEqGtGe.EQ)
+
+    def __ne__(self, other):
+        return ~self.__eq__(other)
+
+    def __gt__(self, other):
+        width = self.sig.shape()[0]
+        return self._compare(width, self, other, "gt", PartitionedEqGtGe.GT)
+
+    def __ge__(self, other):
+        width = self.sig.shape()[0]
+        return self._compare(width, self, other, "ge", PartitionedEqGtGe.GE)