From c3ed0038f83a1e82ded6e4143e19ec8d3707d49e Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Fri, 15 May 2020 14:38:52 -0400 Subject: [PATCH] Implement signed branch immediates --- src/soc/branch/main_stage.py | 5 ++++- src/soc/branch/test/test_pipe_caller.py | 17 ++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/soc/branch/main_stage.py b/src/soc/branch/main_stage.py index b7348ef6..607cd6bd 100644 --- a/src/soc/branch/main_stage.py +++ b/src/soc/branch/main_stage.py @@ -59,7 +59,10 @@ class BranchMainStage(PipeModBase): with m.Case(InternalOp.OP_B): li = Signal(i_fields['LI'][0:-1].shape()) comb += li.eq(i_fields['LI'][0:-1]) - comb += branch_imm_addr.eq(Cat(Const(0, 2), li)) + li_sgn = li[-1] + comb += branch_imm_addr.eq( + Cat(Const(0, 2), li, + Repl(li_sgn, 64-(li.width + 2)))) comb += branch_taken.eq(1) comb += self.o.nia_out.data.eq(branch_addr) diff --git a/src/soc/branch/test/test_pipe_caller.py b/src/soc/branch/test/test_pipe_caller.py index cc9f3e08..0a158081 100644 --- a/src/soc/branch/test/test_pipe_caller.py +++ b/src/soc/branch/test/test_pipe_caller.py @@ -63,15 +63,14 @@ class BranchTestCase(FHDLTestCase): tc = TestCase(prog, initial_regs, initial_sprs, self.test_name) test_data.append(tc) - def test_ba(self): - lst = ["ba 0x1234"] - initial_regs = [0] * 32 - self.run_tst_program(Program(lst), initial_regs) - - def test_b(self): - lst = ["bl 0x1234"] - initial_regs = [0] * 32 - self.run_tst_program(Program(lst), initial_regs) + def test_unconditional(self): + choices = ["b", "ba", "bl", "bla"] + for i in range(20): + choice = random.choice(choices) + imm = random.randrange(-1<<23, (1<<23)-1) * 4 + lst = [f"{choice} {imm}"] + initial_regs = [0] * 32 + self.run_tst_program(Program(lst), initial_regs) def test_ilang(self): rec = CompALUOpSubset() -- 2.30.2