From ab59cd71f2a31833691ff8988fb041cf2c1a41ac Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Thu, 7 May 2020 15:41:06 -0400 Subject: [PATCH] Add tests for conditional branches --- src/soc/decoder/isa/test_caller.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/soc/decoder/isa/test_caller.py b/src/soc/decoder/isa/test_caller.py index 6e3ccdd2..15a8997e 100644 --- a/src/soc/decoder/isa/test_caller.py +++ b/src/soc/decoder/isa/test_caller.py @@ -128,6 +128,34 @@ class DecoderTestCase(FHDLTestCase): self.assertEqual(sim.gpr(1), SelectableInt(0x1234, 64)) self.assertEqual(sim.gpr(2), SelectableInt(0, 64)) + def test_branch_cond(self): + for i in [0, 10]: + lst = [f"addi 1, 0, {i}", # set r1 to i + "cmpi cr0, 1, 1, 10", # compare r1 with 10 and store to cr0 + "bc 12, 2, 0x8", # beq 0x8 - + # branch if r1 equals 10 to the nop below + "addi 2, 0, 0x1234", # if r1 == 10 this shouldn't execute + "or 0, 0, 0"] # branch target + with Program(lst) as program: + sim = self.run_tst_program(program) + if i == 10: + self.assertEqual(sim.gpr(2), SelectableInt(0, 64)) + else: + self.assertEqual(sim.gpr(2), SelectableInt(0x1234, 64)) + + def test_branch_loop(self): + lst = ["addi 1, 0, 0", + "addi 1, 0, 0", + "addi 1, 1, 1", + "add 2, 2, 1", + "cmpi cr0, 1, 1, 10", + "bc 12, 0, -0xc"] + with Program(lst) as program: + sim = self.run_tst_program(program) + # Verified with qemu + self.assertEqual(sim.gpr(2), SelectableInt(0x37, 64)) + + def test_add_compare(self): lst = ["addis 1, 0, 0xffff", "addis 2, 0, 0xffff", -- 2.30.2