Add shift right to test_partsig and partsig
[ieee754fpu.git] / src / ieee754 / part / partsig.py
index 4a2e611baa8ba2cdbc1995dee9eb002442d474e2..1fc7d4b052aa85becb9113b891563106450bcd80 100644 (file)
@@ -64,7 +64,7 @@ class PartitionedSignal:
     # unary ops that require partitioning
 
     def __neg__(self):
-        z = Const(0, self.sig.shape())
+        z = Const(0, len(self.partpoints)+1)
         result, _ = self.add_op(self, ~0, carry=z)  # TODO, subop
         return result
 
@@ -93,7 +93,7 @@ class PartitionedSignal:
     # TODO: detect if the 2nd operand is a Const, a Signal or a
     # PartitionedSignal.  if it's a Const or a Signal, a global shift
     # can occur.  if it's a PartitionedSignal, that's much more interesting.
-    def ls_op(self, op1, op2, carry):
+    def ls_op(self, op1, op2, carry, shr_flag=0):
         op1 = getsig(op1)
         if isinstance(op2, Const) or isinstance(op2, Signal):
             scalar = True
@@ -109,15 +109,18 @@ class PartitionedSignal:
         if scalar:
             comb += pa.data.eq(op1)
             comb += pa.shifter.eq(op2)
+            comb += pa.shift_right.eq(shr_flag)
         else:
             comb += pa.a.eq(op1)
             comb += pa.b.eq(op2)
+            comb += pa.shift_right.eq(shr_flag)
         # XXX TODO: carry-in, carry-out
         #comb += pa.carry_in.eq(carry)
         return (pa.output, 0)
 
     def __lshift__(self, other):
-        result, _ = self.ls_op(self, other, carry=0)
+        z = Const(0, len(self.partpoints)+1)
+        result, _ = self.ls_op(self, other, carry=z) # TODO, carry
         return result
 
     def __rlshift__(self, other):
@@ -125,8 +128,9 @@ class PartitionedSignal:
         return Operator("<<", [other, self])
 
     def __rshift__(self, other):
-        raise NotImplementedError
-        return Operator(">>", [self, other])
+        z = Const(0, len(self.partpoints)+1)
+        result, _ = self.ls_op(self, other, carry=z, shr_flag=1) # TODO, carry
+        return result
 
     def __rrshift__(self, other):
         raise NotImplementedError