finish code to calculate the 64-bit output of the div pipeline
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 18 Jun 2020 22:47:12 +0000 (15:47 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 18 Jun 2020 22:47:12 +0000 (15:47 -0700)
src/soc/fu/div/output_stage.py

index aed1bdb1638a9abfc4dd36a9f5c2b47a9f332484..88a9ec1eec4bbc4ebb3fece42bbe235a13ae57ff 100644 (file)
@@ -81,18 +81,36 @@ class DivOutputStage(PipeModBase):
         ##########################
         # main switch for DIV
 
+        o = self.o.o.data
+
         with m.Switch(op.insn_type):
-            # TODO(programmerjake): finish switch
-            with m.Case(InternalOp.OP_DIV, InternalOp.OP_DIVE):
+            with m.Case(InternalOp.OP_DIVE):
+                with m.If(op.is_32bit):
+                    with m.If(op.is_signed):
+                        # matches POWER9's divweo behavior
+                        comb += o.eq(quotient_64[0:32].as_unsigned())
+                    with m.Else():
+                        comb += o.eq(quotient_64[0:32].as_unsigned())
+                with m.Else():
+                    comb += o.eq(quotient_64)
+            with m.Case(InternalOp.OP_DIV):
                 with m.If(op.is_32bit):
-                    comb += dividend_in.eq(self.abs_dividend[0:32])
+                    with m.If(op.is_signed):
+                        # matches POWER9's divwo behavior
+                        comb += o.eq(quotient_64[0:32].as_unsigned())
+                    with m.Else():
+                        comb += o.eq(quotient_64[0:32].as_unsigned())
                 with m.Else():
-                    comb += dividend_in.eq(self.abs_dividend[0:64])
+                    comb += o.eq(quotient_64)
             with m.Case(InternalOp.OP_MOD):
                 with m.If(op.is_32bit):
-                    comb += dividend_in.eq(self.abs_dividend[0:32] << 32)
+                    with m.If(op.is_signed):
+                        # matches POWER9's modsw behavior
+                        comb += o.eq(remainder_64[0:32].as_signed())
+                    with m.Else():
+                        comb += o.eq(remainder_64[0:32].as_unsigned())
                 with m.Else():
-                    comb += dividend_in.eq(self.abs_dividend[0:64] << 64)
+                    comb += o.eq(remainder_64)
 
         ###### sticky overflow and context, both pass-through #####