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
10 from soc
.regfile
.util
import fast_reg_to_spr
# HACK!
13 def assert_outputs(self, branch, dec2, sim, prev_nia, code):
17 class BranchTestRunner(TestRunner
):
18 def __init__(self
, test_data
):
19 super().__init
__(test_data
, BranchFunctionUnit
, self
,
22 def get_cu_inputs(self
, dec2
, sim
):
23 """naming (res) must conform to BranchFunctionUnit input regspec
25 res
= yield from get_cu_inputs(dec2
, sim
)
28 def check_cu_outputs(self
, res
, dec2
, sim
, code
):
29 """naming (res) must conform to BranchFunctionUnit output regspec
32 print ("check extra output", repr(code
), res
)
34 # NIA (next instruction address aka PC)
35 branch_taken
= 'nia' in res
36 # TODO - get the old PC, use it to check if the branch was taken
37 # sim_branch_taken = prev_nia != sim.pc.CIA
38 # self.assertEqual(branch_taken, sim_branch_taken, code)
40 branch_addr
= res
['nia']
41 self
.assertEqual(branch_addr
, sim
.pc
.CIA
.value
, code
)
44 lk
= yield dec2
.e
.do
.lk
45 branch_lk
= 'fast2' in res
46 self
.assertEqual(lk
, branch_lk
, code
)
48 branch_lr
= res
['fast2']
49 self
.assertEqual(sim
.spr
['LR'], branch_lr
, code
)
52 ctr_ok
= 'fast1' in res
55 self
.assertEqual(sim
.spr
['CTR'], ctr
, code
)
58 if __name__
== "__main__":
59 unittest
.main(exit
=False)
60 suite
= unittest
.TestSuite()
61 suite
.addTest(BranchTestRunner(BranchTestCase
.test_data
))
63 runner
= unittest
.TextTestRunner()