Handle carry out in alu
authorMichael Nolan <mtnolan2640@gmail.com>
Tue, 19 May 2020 15:06:04 +0000 (11:06 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Tue, 19 May 2020 15:21:01 +0000 (11:21 -0400)
src/soc/fu/alu/output_stage.py
src/soc/fu/alu/test/test_pipe_caller.py

index 20f00d6e55a875c1ac5eb4b6fcb20ad26f3dcbd0..24a47ce7179a73b82c7fba848ca6901bdd70a95d 100644 (file)
@@ -37,6 +37,10 @@ class ALUOutputStage(PipeModBase):
         with m.Else():
             comb += target.eq(o)
 
+        # Handle carry_out
+        with m.If(self.i.ctx.op.output_carry):
+            comb += self.o.carry_out.eq(self.i.carry_out)
+
         # create condition register cr0 and sticky-overflow
         is_zero = Signal(reset_less=True)
         is_positive = Signal(reset_less=True)
index 138ad3e1687b1e2450e49794b97d94016ffe131e..94fcad78e03bb831de37e70e1f89a78f6b9f9b14 100644 (file)
@@ -124,14 +124,15 @@ class ALUTestCase(FHDLTestCase):
 
     def test_adde(self):
         lst = ["adde. 5, 6, 7"]
-        initial_regs = [0] * 32
-        initial_regs[6] = random.randint(0, (1<<64)-1)
-        initial_regs[7] = random.randint(0, (1<<64)-1)
-        initial_sprs = {}
-        xer = SelectableInt(0, 64)
-        xer[XER_bits['CA']] = 1
-        initial_sprs[special_sprs['XER']] = xer
-        self.run_tst_program(Program(lst), initial_regs, initial_sprs)
+        for i in range(10):
+            initial_regs = [0] * 32
+            initial_regs[6] = random.randint(0, (1<<64)-1)
+            initial_regs[7] = random.randint(0, (1<<64)-1)
+            initial_sprs = {}
+            xer = SelectableInt(0, 64)
+            xer[XER_bits['CA']] = 1
+            initial_sprs[special_sprs['XER']] = xer
+            self.run_tst_program(Program(lst), initial_regs, initial_sprs)
 
     def test_cmp(self):
         lst = ["subf. 1, 6, 7",
@@ -259,6 +260,12 @@ class TestRunner(FHDLTestCase):
             cr_expected = sim.crl[bf].get_range().value
             self.assertEqual(cr_expected, cr_actual, code)
 
+        cry_out = yield dec2.e.output_carry
+        if cry_out:
+            expected_carry = 1 if sim.spr['XER'][XER_bits['CA']] else 0
+            real_carry = yield alu.n.data_o.carry_out
+            self.assertEqual(expected_carry, real_carry)
+
 
 
 if __name__ == "__main__":