ce015d0ee231435e2e4370d1a53ba9b011621a1a
1 from nmigen
import Module
, Signal
3 # NOTE: to use cxxsim, export NMIGEN_SIM_MODE=cxxsim from the shell
4 # Also, check out the cxxsim nmigen branch, and latest yosys from git
5 from nmutil
.sim_tmp_alternative
import Simulator
, Delay
, Settle
7 from nmigen
.cli
import rtlil
9 from soc
.decoder
.isa
.caller
import ISACaller
, special_sprs
10 from soc
.decoder
.power_decoder
import (create_pdecode
)
11 from soc
.decoder
.power_decoder2
import (PowerDecode2
)
12 from soc
.decoder
.power_enums
import (XER_bits
, Function
, MicrOp
, CryIn
)
13 from soc
.decoder
.selectable_int
import SelectableInt
14 from soc
.simulator
.program
import Program
15 from soc
.decoder
.isa
.all
import ISA
16 from soc
.config
.endian
import bigendian
18 from soc
.fu
.test
.common
import (TestAccumulatorBase
, TestCase
, ALUHelpers
)
19 from soc
.fu
.mul
.pipeline
import MulBasePipe
20 from soc
.fu
.mul
.pipe_data
import MulPipeSpec
21 from soc
.fu
.mul
.test
.helper
import MulTestHelper
25 class MulTestCases2Arg(TestAccumulatorBase
):
26 def case_0_mullw(self
):
27 lst
= [f
"mullw 3, 1, 2"]
28 initial_regs
= [0] * 32
29 #initial_regs[1] = 0xffffffffffffffff
30 #initial_regs[2] = 0xffffffffffffffff
31 initial_regs
[1] = 0x2ffffffff
33 self
.add_case(Program(lst
, bigendian
), initial_regs
)
35 def case_1_mullwo_(self
):
36 lst
= [f
"mullwo. 3, 1, 2"]
37 initial_regs
= [0] * 32
38 initial_regs
[1] = 0x3b34b06f
39 initial_regs
[2] = 0xfdeba998
40 self
.add_case(Program(lst
, bigendian
), initial_regs
)
42 def case_2_mullwo(self
):
43 lst
= [f
"mullwo 3, 1, 2"]
44 initial_regs
= [0] * 32
45 initial_regs
[1] = 0xffffffffffffa988 # -5678
46 initial_regs
[2] = 0xffffffffffffedcc # -1234
47 self
.add_case(Program(lst
, bigendian
), initial_regs
)
49 def case_3_mullw(self
):
50 lst
= ["mullw 3, 1, 2",
52 initial_regs
= [0] * 32
55 self
.add_case(Program(lst
, bigendian
), initial_regs
)
57 def case_4_mullw_rand(self
):
59 lst
= ["mullw 3, 1, 2"]
60 initial_regs
= [0] * 32
61 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
62 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
63 self
.add_case(Program(lst
, bigendian
), initial_regs
)
65 def case_4_mullw_nonrand(self
):
67 lst
= ["mullw 3, 1, 2"]
68 initial_regs
= [0] * 32
70 initial_regs
[2] = i
+20
71 self
.add_case(Program(lst
, bigendian
), initial_regs
)
73 def case_mulhw__regression_1(self
):
74 lst
= ["mulhw. 3, 1, 2"
76 initial_regs
= [0] * 32
77 initial_regs
[1] = 0x7745b36eca6646fa
78 initial_regs
[2] = 0x47dfba3a63834ba2
79 self
.add_case(Program(lst
, bigendian
), initial_regs
)
81 def case_rand_mul_lh(self
):
82 insns
= ["mulhw", "mulhw.", "mulhwu", "mulhwu."]
84 choice
= random
.choice(insns
)
85 lst
= [f
"{choice} 3, 1, 2"]
86 initial_regs
= [0] * 32
87 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
88 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
89 self
.add_case(Program(lst
, bigendian
), initial_regs
)
91 def case_rand_mullw(self
):
92 insns
= ["mullw", "mullw.", "mullwo", "mullwo."]
94 choice
= random
.choice(insns
)
95 lst
= [f
"{choice} 3, 1, 2"]
96 initial_regs
= [0] * 32
97 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
98 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
99 self
.add_case(Program(lst
, bigendian
), initial_regs
)
101 def case_rand_mulld(self
):
102 insns
= ["mulld", "mulld.", "mulldo", "mulldo."]
104 choice
= random
.choice(insns
)
105 lst
= [f
"{choice} 3, 1, 2"]
106 initial_regs
= [0] * 32
107 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
108 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
109 self
.add_case(Program(lst
, bigendian
), initial_regs
)
111 def case_rand_mulhd(self
):
112 insns
= ["mulhd", "mulhd."]
114 choice
= random
.choice(insns
)
115 lst
= [f
"{choice} 3, 1, 2"]
116 initial_regs
= [0] * 32
117 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
118 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
119 self
.add_case(Program(lst
, bigendian
), initial_regs
)
121 def case_0_mullhw_regression(self
):
122 lst
= [f
"mulhwu 3, 1, 2"]
123 initial_regs
= [0] * 32
124 initial_regs
[1] = 0x4000000000000000
125 initial_regs
[2] = 0x0000000000000002
126 self
.add_case(Program(lst
, bigendian
), initial_regs
)
129 class MulTestCases3Arg(TestAccumulatorBase
):
130 # TODO add test case for these 3 operand cases (madd
131 # needs to be implemented)
132 # "maddhd","maddhdu","maddld"
133 def case_maddld(self
):
134 lst
= ["maddld 1, 2, 3, 4"]
135 initial_regs
= [0] * 32
136 initial_regs
[2] = 0x3
137 initial_regs
[3] = 0x4
138 initial_regs
[4] = 0x5
139 self
.add_case(Program(lst
, bigendian
), initial_regs
)
142 class TestPipe(MulTestHelper
):
143 def test_mul_pipe_2_arg(self
):
144 self
.run_all(MulTestCases2Arg().test_data
, "mul_pipe_caller_2_arg",
145 has_third_input
=False)
147 def test_mul_pipe_3_arg(self
):
148 self
.run_all(MulTestCases3Arg().test_data
, "mul_pipe_caller_3_arg",
149 has_third_input
=True)
152 if __name__
== "__main__":