2 from soc
.decoder
.power_enums
import (XER_bits
, Function
, spr_dict
, SPR
)
4 # XXX bad practice: use of global variables
5 from soc
.fu
.branch
.test
.test_pipe_caller
import BranchTestCase
, get_cu_inputs
7 from soc
.fu
.compunits
.compunits
import BranchFunctionUnit
8 from soc
.fu
.compunits
.test
.test_compunit
import TestRunner
9 from soc
.config
.endian
import bigendian
11 from soc
.regfile
.util
import fast_reg_to_spr
# HACK!
14 def assert_outputs(self, branch, dec2, sim, prev_nia, code):
18 class BranchTestRunner(TestRunner
):
19 def __init__(self
, test_data
):
20 super().__init
__(test_data
, BranchFunctionUnit
, self
,
21 Function
.BRANCH
, bigendian
)
23 def get_cu_inputs(self
, dec2
, sim
):
24 """naming (res) must conform to BranchFunctionUnit input regspec
26 res
= yield from get_cu_inputs(dec2
, sim
)
29 def check_cu_outputs(self
, res
, dec2
, sim
, alu
, code
):
30 """naming (res) must conform to BranchFunctionUnit output regspec
33 print("check extra output", repr(code
), res
)
35 # NIA (next instruction address aka PC)
36 branch_taken
= 'nia' in res
37 # TODO - get the old PC, use it to check if the branch was taken
38 # sim_branch_taken = prev_nia != sim.pc.CIA
39 # self.assertEqual(branch_taken, sim_branch_taken, code)
41 branch_addr
= res
['nia']
42 self
.assertEqual(branch_addr
, sim
.pc
.CIA
.value
, code
)
45 lk
= yield dec2
.e
.do
.lk
46 branch_lk
= 'fast2' in res
47 self
.assertEqual(lk
, branch_lk
, code
)
49 branch_lr
= res
['fast2']
50 self
.assertEqual(sim
.spr
['LR'], branch_lr
, code
)
53 ctr_ok
= 'fast1' in res
56 self
.assertEqual(sim
.spr
['CTR'], ctr
, code
)
59 if __name__
== "__main__":
60 unittest
.main(exit
=False)
61 suite
= unittest
.TestSuite()
62 suite
.addTest(BranchTestRunner(BranchTestCase
.test_data
))
64 runner
= unittest
.TextTestRunner()