add test_0_moduw and correct name to trunc_rem
[soc.git] / src / soc / simulator / test_div_sim.py
1 from nmigen import Module, Signal
2 from nmigen.back.pysim import Simulator, Delay, Settle
3 from nmigen.test.utils import FHDLTestCase
4 import unittest
5 from soc.decoder.power_decoder import (create_pdecode)
6 from soc.decoder.power_enums import (Function, InternalOp,
7 In1Sel, In2Sel, In3Sel,
8 OutSel, RC, LdstLen, CryIn,
9 single_bit_flags, Form, SPR,
10 get_signal_name, get_csv)
11 from soc.decoder.power_decoder2 import (PowerDecode2)
12 from soc.simulator.program import Program
13 from soc.simulator.qemu import run_program
14 from soc.decoder.isa.all import ISA
15 from soc.fu.test.common import TestCase
16 from soc.simulator.test_sim import DecoderBase
17
18
19
20 class DivTestCases(FHDLTestCase):
21 test_data = []
22
23 def __init__(self, name="general"):
24 super().__init__(name)
25 self.test_name = name
26
27 def test_0_divw(self):
28 lst = ["addi 1, 0, 0x5678",
29 "addi 2, 0, 0x1234",
30 "divw 3, 1, 2",
31 ]
32 with Program(lst) as program:
33 self.run_tst_program(program, [1, 2, 3])
34
35 def test_0_moduw(self):
36 lst = ["addi 1, 0, 0x5678",
37 "addi 2, 0, 0x1234",
38 "moduw 3, 1, 2",
39 ]
40 with Program(lst) as program:
41 self.run_tst_program(program, [1, 2, 3])
42
43 def run_tst_program(self, prog, initial_regs=None, initial_sprs=None,
44 initial_mem=None):
45 initial_regs = [0] * 32
46 tc = TestCase(prog, self.test_name, initial_regs, initial_sprs, 0,
47 initial_mem, 0)
48 self.test_data.append(tc)
49
50
51 class DecoderTestCase(DecoderBase, DivTestCases):
52 pass
53
54
55 if __name__ == "__main__":
56 unittest.main()