5f34beb5cfc93f5ef0ed3b92fabe4386f70a96c6
2 from nmigen
.back
.pysim
import *
3 from nmigen
.test
.utils
import *
5 from ..units
.divider
import *
6 from ..isa
import Funct3
9 def test_op(funct3
, src1
, src2
, result
):
11 with
Simulator(self
.dut
) as sim
:
13 yield self
.dut
.x_op
.eq(funct3
)
14 yield self
.dut
.x_src1
.eq(src1
)
15 yield self
.dut
.x_src2
.eq(src2
)
16 yield self
.dut
.x_valid
.eq(1)
17 yield self
.dut
.x_stall
.eq(0)
19 yield self
.dut
.x_valid
.eq(0)
21 while (yield self
.dut
.m_busy
):
23 self
.assertEqual((yield self
.dut
.m_result
), result
)
25 sim
.add_sync_process(process
)
30 class DividerTestCase(FHDLTestCase
):
34 # Test cases are taken from the riscv-compliance testbench:
35 # https://github.com/riscv/riscv-compliance/tree/master/riscv-test-suite/rv32im
37 # DIV ------------------------------------------------------------------------
39 test_div_0
= test_op(Funct3
.DIV
, 0x00000000, 0x00000000, result
=0xffffffff)
40 test_div_1
= test_op(Funct3
.DIV
, 0x00000000, 0x00000001, result
=0x00000000)
41 test_div_2
= test_op(Funct3
.DIV
, 0x00000000, 0xffffffff, result
=0x00000000)
42 test_div_3
= test_op(Funct3
.DIV
, 0x00000000, 0x7fffffff, result
=0x00000000)
43 test_div_4
= test_op(Funct3
.DIV
, 0x00000000, 0x80000000, result
=0x00000000)
45 test_div_5
= test_op(Funct3
.DIV
, 0x00000001, 0x00000000, result
=0xffffffff)
46 test_div_6
= test_op(Funct3
.DIV
, 0x00000001, 0x00000001, result
=0x00000001)
47 test_div_7
= test_op(Funct3
.DIV
, 0x00000001, 0xffffffff, result
=0xffffffff)
48 test_div_8
= test_op(Funct3
.DIV
, 0x00000001, 0x7fffffff, result
=0x00000000)
49 test_div_9
= test_op(Funct3
.DIV
, 0x00000001, 0x80000000, result
=0x00000000)
51 test_div_10
= test_op(Funct3
.DIV
, 0xffffffff, 0x00000000, result
=0xffffffff)
52 test_div_11
= test_op(Funct3
.DIV
, 0xffffffff, 0x00000001, result
=0xffffffff)
53 test_div_12
= test_op(Funct3
.DIV
, 0xffffffff, 0xffffffff, result
=0x00000001)
54 test_div_13
= test_op(Funct3
.DIV
, 0xffffffff, 0x7fffffff, result
=0x00000000)
55 test_div_14
= test_op(Funct3
.DIV
, 0xffffffff, 0x80000000, result
=0x00000000)
57 test_div_15
= test_op(Funct3
.DIV
, 0x7fffffff, 0x00000000, result
=0xffffffff)
58 test_div_16
= test_op(Funct3
.DIV
, 0x7fffffff, 0x00000001, result
=0x7fffffff)
59 test_div_17
= test_op(Funct3
.DIV
, 0x7fffffff, 0xffffffff, result
=0x80000001)
60 test_div_18
= test_op(Funct3
.DIV
, 0x7fffffff, 0x7fffffff, result
=0x00000001)
61 test_div_19
= test_op(Funct3
.DIV
, 0x7fffffff, 0x80000000, result
=0x00000000)
63 test_div_20
= test_op(Funct3
.DIV
, 0x80000000, 0x00000000, result
=0xffffffff)
64 test_div_21
= test_op(Funct3
.DIV
, 0x80000000, 0x00000001, result
=0x80000000)
65 test_div_22
= test_op(Funct3
.DIV
, 0x80000000, 0xffffffff, result
=0x80000000)
66 test_div_23
= test_op(Funct3
.DIV
, 0x80000000, 0x7fffffff, result
=0xffffffff)
67 test_div_24
= test_op(Funct3
.DIV
, 0x80000000, 0x80000000, result
=0x00000001)
69 # DIVU -----------------------------------------------------------------------
71 test_divu_0
= test_op(Funct3
.DIVU
, 0x00000000, 0x00000000, result
=0xffffffff)
72 test_divu_1
= test_op(Funct3
.DIVU
, 0x00000000, 0x00000001, result
=0x00000000)
73 test_divu_2
= test_op(Funct3
.DIVU
, 0x00000000, 0xffffffff, result
=0x00000000)
74 test_divu_3
= test_op(Funct3
.DIVU
, 0x00000000, 0x7fffffff, result
=0x00000000)
75 test_divu_4
= test_op(Funct3
.DIVU
, 0x00000000, 0x80000000, result
=0x00000000)
77 test_divu_5
= test_op(Funct3
.DIVU
, 0x00000001, 0x00000000, result
=0xffffffff)
78 test_divu_6
= test_op(Funct3
.DIVU
, 0x00000001, 0x00000001, result
=0x00000001)
79 test_divu_7
= test_op(Funct3
.DIVU
, 0x00000001, 0xffffffff, result
=0x00000000)
80 test_divu_8
= test_op(Funct3
.DIVU
, 0x00000001, 0x7fffffff, result
=0x00000000)
81 test_divu_9
= test_op(Funct3
.DIVU
, 0x00000001, 0x80000000, result
=0x00000000)
83 test_divu_10
= test_op(Funct3
.DIVU
, 0xffffffff, 0x00000000, result
=0xffffffff)
84 test_divu_11
= test_op(Funct3
.DIVU
, 0xffffffff, 0x00000001, result
=0xffffffff)
85 test_divu_12
= test_op(Funct3
.DIVU
, 0xffffffff, 0xffffffff, result
=0x00000001)
86 test_divu_13
= test_op(Funct3
.DIVU
, 0xffffffff, 0x7fffffff, result
=0x00000002)
87 test_divu_14
= test_op(Funct3
.DIVU
, 0xffffffff, 0x80000000, result
=0x00000001)
89 test_divu_15
= test_op(Funct3
.DIVU
, 0x7fffffff, 0x00000000, result
=0xffffffff)
90 test_divu_16
= test_op(Funct3
.DIVU
, 0x7fffffff, 0x00000001, result
=0x7fffffff)
91 test_divu_17
= test_op(Funct3
.DIVU
, 0x7fffffff, 0xffffffff, result
=0x00000000)
92 test_divu_18
= test_op(Funct3
.DIVU
, 0x7fffffff, 0x7fffffff, result
=0x00000001)
93 test_divu_19
= test_op(Funct3
.DIVU
, 0x7fffffff, 0x80000000, result
=0x00000000)
95 test_divu_20
= test_op(Funct3
.DIVU
, 0x80000000, 0x00000000, result
=0xffffffff)
96 test_divu_21
= test_op(Funct3
.DIVU
, 0x80000000, 0x00000001, result
=0x80000000)
97 test_divu_22
= test_op(Funct3
.DIVU
, 0x80000000, 0xffffffff, result
=0x00000000)
98 test_divu_23
= test_op(Funct3
.DIVU
, 0x80000000, 0x7fffffff, result
=0x00000001)
99 test_divu_24
= test_op(Funct3
.DIVU
, 0x80000000, 0x80000000, result
=0x00000001)
101 # REM ------------------------------------------------------------------------
103 test_rem_0
= test_op(Funct3
.REM
, 0x00000000, 0x00000000, result
=0x00000000)
104 test_rem_1
= test_op(Funct3
.REM
, 0x00000000, 0x00000001, result
=0x00000000)
105 test_rem_2
= test_op(Funct3
.REM
, 0x00000000, 0xffffffff, result
=0x00000000)
106 test_rem_3
= test_op(Funct3
.REM
, 0x00000000, 0x7fffffff, result
=0x00000000)
107 test_rem_4
= test_op(Funct3
.REM
, 0x00000000, 0x80000000, result
=0x00000000)
109 test_rem_5
= test_op(Funct3
.REM
, 0x00000001, 0x00000000, result
=0x00000001)
110 test_rem_6
= test_op(Funct3
.REM
, 0x00000001, 0x00000001, result
=0x00000000)
111 test_rem_7
= test_op(Funct3
.REM
, 0x00000001, 0xffffffff, result
=0x00000000)
112 test_rem_8
= test_op(Funct3
.REM
, 0x00000001, 0x7fffffff, result
=0x00000001)
113 test_rem_9
= test_op(Funct3
.REM
, 0x00000001, 0x80000000, result
=0x00000001)
115 test_rem_10
= test_op(Funct3
.REM
, 0xffffffff, 0x00000000, result
=0xffffffff)
116 test_rem_11
= test_op(Funct3
.REM
, 0xffffffff, 0x00000001, result
=0x00000000)
117 test_rem_12
= test_op(Funct3
.REM
, 0xffffffff, 0xffffffff, result
=0x00000000)
118 test_rem_13
= test_op(Funct3
.REM
, 0xffffffff, 0x7fffffff, result
=0xffffffff)
119 test_rem_14
= test_op(Funct3
.REM
, 0xffffffff, 0x80000000, result
=0xffffffff)
121 test_rem_15
= test_op(Funct3
.REM
, 0x7fffffff, 0x00000000, result
=0x7fffffff)
122 test_rem_16
= test_op(Funct3
.REM
, 0x7fffffff, 0x00000001, result
=0x00000000)
123 test_rem_17
= test_op(Funct3
.REM
, 0x7fffffff, 0xffffffff, result
=0x00000000)
124 test_rem_18
= test_op(Funct3
.REM
, 0x7fffffff, 0x7fffffff, result
=0x00000000)
125 test_rem_19
= test_op(Funct3
.REM
, 0x7fffffff, 0x80000000, result
=0x7fffffff)
127 test_rem_20
= test_op(Funct3
.REM
, 0x80000000, 0x00000000, result
=0x80000000)
128 test_rem_21
= test_op(Funct3
.REM
, 0x80000000, 0x00000001, result
=0x00000000)
129 test_rem_22
= test_op(Funct3
.REM
, 0x80000000, 0xffffffff, result
=0x00000000)
130 test_rem_23
= test_op(Funct3
.REM
, 0x80000000, 0x7fffffff, result
=0xffffffff)
131 test_rem_24
= test_op(Funct3
.REM
, 0x80000000, 0x80000000, result
=0x00000000)
133 # REMU -----------------------------------------------------------------------
135 test_remu_0
= test_op(Funct3
.REMU
, 0x00000000, 0x00000000, result
=0x00000000)
136 test_remu_1
= test_op(Funct3
.REMU
, 0x00000000, 0x00000001, result
=0x00000000)
137 test_remu_2
= test_op(Funct3
.REMU
, 0x00000000, 0xffffffff, result
=0x00000000)
138 test_remu_3
= test_op(Funct3
.REMU
, 0x00000000, 0x7fffffff, result
=0x00000000)
139 test_remu_4
= test_op(Funct3
.REMU
, 0x00000000, 0x80000000, result
=0x00000000)
141 test_remu_5
= test_op(Funct3
.REMU
, 0x00000001, 0x00000000, result
=0x00000001)
142 test_remu_6
= test_op(Funct3
.REMU
, 0x00000001, 0x00000001, result
=0x00000000)
143 test_remu_7
= test_op(Funct3
.REMU
, 0x00000001, 0xffffffff, result
=0x00000001)
144 test_remu_8
= test_op(Funct3
.REMU
, 0x00000001, 0x7fffffff, result
=0x00000001)
145 test_remu_9
= test_op(Funct3
.REMU
, 0x00000001, 0x80000000, result
=0x00000001)
147 test_remu_10
= test_op(Funct3
.REMU
, 0xffffffff, 0x00000000, result
=0xffffffff)
148 test_remu_11
= test_op(Funct3
.REMU
, 0xffffffff, 0x00000001, result
=0x00000000)
149 test_remu_12
= test_op(Funct3
.REMU
, 0xffffffff, 0xffffffff, result
=0x00000000)
150 test_remu_13
= test_op(Funct3
.REMU
, 0xffffffff, 0x7fffffff, result
=0x00000001)
151 test_remu_14
= test_op(Funct3
.REMU
, 0xffffffff, 0x80000000, result
=0x7fffffff)
153 test_remu_15
= test_op(Funct3
.REMU
, 0x7fffffff, 0x00000000, result
=0x7fffffff)
154 test_remu_16
= test_op(Funct3
.REMU
, 0x7fffffff, 0x00000001, result
=0x00000000)
155 test_remu_17
= test_op(Funct3
.REMU
, 0x7fffffff, 0xffffffff, result
=0x7fffffff)
156 test_remu_18
= test_op(Funct3
.REMU
, 0x7fffffff, 0x7fffffff, result
=0x00000000)
157 test_remu_19
= test_op(Funct3
.REMU
, 0x7fffffff, 0x80000000, result
=0x7fffffff)
159 test_remu_20
= test_op(Funct3
.REMU
, 0x80000000, 0x00000000, result
=0x80000000)
160 test_remu_21
= test_op(Funct3
.REMU
, 0x80000000, 0x00000001, result
=0x00000000)
161 test_remu_22
= test_op(Funct3
.REMU
, 0x80000000, 0xffffffff, result
=0x80000000)
162 test_remu_23
= test_op(Funct3
.REMU
, 0x80000000, 0x7fffffff, result
=0x00000001)
163 test_remu_24
= test_op(Funct3
.REMU
, 0x80000000, 0x80000000, result
=0x00000000)