Convert branch unit to new CR interface
authorMichael Nolan <mtnolan2640@gmail.com>
Fri, 22 May 2020 14:49:26 +0000 (10:49 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Fri, 22 May 2020 14:49:50 +0000 (10:49 -0400)
src/soc/fu/branch/main_stage.py
src/soc/fu/branch/pipe_data.py
src/soc/fu/branch/test/test_pipe_caller.py

index 723182f40257abd0daeb209464a20ea45de3e59b..636e581c4f5d17ab12912ebd504d1fe8f57cb393 100644 (file)
@@ -75,11 +75,13 @@ class BranchMainStage(PipeModBase):
         # https://bugs.libre-soc.org/show_bug.cgi?id=313#c2
         b_fields = self.fields.FormB
         BO = b_fields.BO[0:-1]
-        BI = b_fields.BI[0:-1]
+        BI = b_fields.BI[0:-1][0:2]
+
+        cr_bits = Array([cr[3-i] for i in range(4)])
 
         # The bit of CR selected by BI
         cr_bit = Signal(reset_less=True)
-        comb += cr_bit.eq((cr & (1<<(31-BI))) != 0)
+        comb += cr_bit.eq(cr_bits[BI])
 
         # Whether the conditional branch should be taken
         bc_taken = Signal(reset_less=True)
index 1f79a704a6dabc7dd65780b346cf3e2b842f0165..28099eaa84f065065132208abaa9d8fa4a6f003f 100644 (file)
@@ -33,7 +33,7 @@ from soc.fu.branch.br_input_record import CompBROpSubset # TODO: replace
 class BranchInputData(IntegerData):
     regspec = [('SPR', 'spr1', '0:63'),
                ('SPR', 'spr2', '0:63'),
-               ('CR', 'cr', '32'),
+               ('CR', 'cr', '4'),
                ('PC', 'cia', '0:63')]
     def __init__(self, pspec):
         super().__init__(pspec)
@@ -43,7 +43,7 @@ class BranchInputData(IntegerData):
 
         self.spr1 = Signal(64, reset_less=True) # see table above, SPR1
         self.spr2 = Signal(64, reset_less=True) # see table above, SPR2
-        self.cr = Signal(32, reset_less=True)   # Condition Register(s) CR0-7
+        self.cr = Signal(4, reset_less=True)   # Condition Register(s) CR0-7
         self.cia = Signal(64, reset_less=True)  # Current Instruction Address
 
         # convenience variables.  not all of these are used at once
index 09ccb3fd2bb2b1b736cea5d28ac5a677684ee9d6..541b56dd1e4b3912ca7f9023d4b1e8789e527ac6 100644 (file)
@@ -151,7 +151,6 @@ class TestRunner(FHDLTestCase):
                     yield pdecode2.dec.bigendian.eq(0)  # little / big?
                     yield instruction.eq(ins)          # raw binary instr.
                     yield branch.p.data_i.cia.eq(simulator.pc.CIA.value)
-                    yield branch.p.data_i.cr.eq(simulator.cr.get_range().value)
                     # note, here, the op will need further decoding in order
                     # to set the correct SPRs on SPR1/2/3.  op_bc* require
                     # spr2 to be set to CTR, op_bctar require spr1 to be
@@ -161,6 +160,14 @@ class TestRunner(FHDLTestCase):
                     yield branch.p.data_i.spr2.eq(simulator.spr['CTR'].value)
                     print(f"cr0: {simulator.crl[0].get_range()}")
                     yield Settle()
+
+                    cr_en = yield pdecode2.e.read_cr1.ok
+                    if cr_en:
+                        cr_sel = yield pdecode2.e.read_cr1.data
+                        cr = simulator.crl[cr_sel].get_range().value
+                        yield branch.p.data_i.cr.eq(cr)
+                        full_cr = simulator.cr.get_range().value
+                        print(f"full cr: {full_cr:x}, sel: {cr_sel}, cr: {cr:x}")
                     fn_unit = yield pdecode2.e.fn_unit
                     self.assertEqual(fn_unit, Function.BRANCH.value, code)
                     yield