1 |
67 |
olivier.gi |
/*===========================================================================*/
|
2 |
|
|
/* Copyright (C) 2001 Authors */
|
3 |
|
|
/* */
|
4 |
|
|
/* This source file may be used and distributed without restriction provided */
|
5 |
|
|
/* that this copyright statement is not removed from the file and that any */
|
6 |
|
|
/* derivative work contains the original copyright notice and the associated */
|
7 |
|
|
/* disclaimer. */
|
8 |
|
|
/* */
|
9 |
|
|
/* This source file is free software; you can redistribute it and/or modify */
|
10 |
|
|
/* it under the terms of the GNU Lesser General Public License as published */
|
11 |
|
|
/* by the Free Software Foundation; either version 2.1 of the License, or */
|
12 |
|
|
/* (at your option) any later version. */
|
13 |
|
|
/* */
|
14 |
|
|
/* This source is distributed in the hope that it will be useful, but WITHOUT*/
|
15 |
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
16 |
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
|
17 |
|
|
/* License for more details. */
|
18 |
|
|
/* */
|
19 |
|
|
/* You should have received a copy of the GNU Lesser General Public License */
|
20 |
|
|
/* along with this source; if not, write to the Free Software Foundation, */
|
21 |
|
|
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
22 |
|
|
/* */
|
23 |
|
|
/*===========================================================================*/
|
24 |
|
|
/* HARDWARE MULTIPLIER */
|
25 |
|
|
/*---------------------------------------------------------------------------*/
|
26 |
|
|
/* Test the hardware multiplier: */
|
27 |
|
|
/* - MPY mode. */
|
28 |
|
|
/* - MPYS mode. */
|
29 |
|
|
/* - MAC mode. */
|
30 |
|
|
/* - MACS mode. */
|
31 |
|
|
/* */
|
32 |
|
|
/* Author(s): */
|
33 |
|
|
/* - Olivier Girard, olgirard@gmail.com */
|
34 |
|
|
/* */
|
35 |
|
|
/*---------------------------------------------------------------------------*/
|
36 |
|
|
/* $Rev: 18 $ */
|
37 |
|
|
/* $LastChangedBy: olivier.girard $ */
|
38 |
|
|
/* $LastChangedDate: 2009-08-04 23:44:12 +0200 (Tue, 04 Aug 2009) $ */
|
39 |
|
|
/*===========================================================================*/
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
initial
|
43 |
|
|
begin
|
44 |
|
|
$display(" ===============================================");
|
45 |
|
|
$display("| START SIMULATION |");
|
46 |
|
|
$display(" ===============================================");
|
47 |
|
|
repeat(5) @(posedge mclk);
|
48 |
|
|
stimulus_done = 0;
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
// UNSIGNED MULTIPLICATION
|
52 |
|
|
//--------------------------------------------------------
|
53 |
|
|
|
54 |
|
|
@(r15===16'h0001);
|
55 |
|
|
if (r10 !== 16'h7F14) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (1) =====");
|
56 |
|
|
if (r11 !== 16'h007B) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (1) =====");
|
57 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (1) =====");
|
58 |
|
|
|
59 |
|
|
@(r15===16'h0002);
|
60 |
|
|
if (r10 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (2) =====");
|
61 |
|
|
if (r11 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (2) =====");
|
62 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (2) =====");
|
63 |
|
|
|
64 |
|
|
@(r15===16'h0003);
|
65 |
|
|
if (r10 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (3) =====");
|
66 |
|
|
if (r11 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (3) =====");
|
67 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (3) =====");
|
68 |
|
|
|
69 |
|
|
@(r15===16'h0004);
|
70 |
|
|
if (r10 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (4) =====");
|
71 |
|
|
if (r11 !== 16'h3FFF) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (4) =====");
|
72 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (4) =====");
|
73 |
|
|
|
74 |
|
|
@(r15===16'h0005);
|
75 |
|
|
if (r10 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (5) =====");
|
76 |
|
|
if (r11 !== 16'hFFFE) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (5) =====");
|
77 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (5) =====");
|
78 |
|
|
|
79 |
|
|
@(r15===16'h0006);
|
80 |
|
|
if (r10 !== 16'h8001) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (6) =====");
|
81 |
|
|
if (r11 !== 16'h7FFE) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (6) =====");
|
82 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (6) =====");
|
83 |
|
|
|
84 |
|
|
@(r15===16'h0007);
|
85 |
|
|
if (r10 !== 16'h8000) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (7) =====");
|
86 |
|
|
if (r11 !== 16'h3FFF) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (7) =====");
|
87 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (7) =====");
|
88 |
|
|
|
89 |
|
|
@(r15===16'h0008);
|
90 |
|
|
if (r10 !== 16'h8000) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (8) =====");
|
91 |
|
|
if (r11 !== 16'h7FFF) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (8) =====");
|
92 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (8) =====");
|
93 |
|
|
|
94 |
|
|
@(r15===16'h0009);
|
95 |
|
|
if (r10 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: RESLO (9) =====");
|
96 |
|
|
if (r11 !== 16'h4000) tb_error("====== UNSIGNED MULTIPLICATION: RESHI (9) =====");
|
97 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLICATION: SUMEXT (9) =====");
|
98 |
|
|
|
99 |
|
|
$display("Unsigned Multiplication test completed (MPY mode).");
|
100 |
|
|
|
101 |
|
|
// SIGNED MULTIPLICATION
|
102 |
|
|
//--------------------------------------------------------
|
103 |
|
|
|
104 |
|
|
@(r15===16'h0001);
|
105 |
|
|
if (r10 !== 16'h7F14) tb_error("====== SIGNED MULTIPLICATION: RESLO (1) =====");
|
106 |
|
|
if (r11 !== 16'hE7F9) tb_error("====== SIGNED MULTIPLICATION: RESHI (1) =====");
|
107 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (1) =====");
|
108 |
|
|
|
109 |
|
|
@(r15===16'h0002);
|
110 |
|
|
if (r10 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: RESLO (2) =====");
|
111 |
|
|
if (r11 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: RESHI (2) =====");
|
112 |
|
|
if (r12 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (2) =====");
|
113 |
|
|
|
114 |
|
|
@(r15===16'h0003);
|
115 |
|
|
if (r10 !== 16'h0001) tb_error("====== SIGNED MULTIPLICATION: RESLO (3) =====");
|
116 |
|
|
if (r11 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: RESHI (3) =====");
|
117 |
|
|
if (r12 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (3) =====");
|
118 |
|
|
|
119 |
|
|
@(r15===16'h0004);
|
120 |
|
|
if (r10 !== 16'h0001) tb_error("====== SIGNED MULTIPLICATION: RESLO (4) =====");
|
121 |
|
|
if (r11 !== 16'h3FFF) tb_error("====== SIGNED MULTIPLICATION: RESHI (4) =====");
|
122 |
|
|
if (r12 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (4) =====");
|
123 |
|
|
|
124 |
|
|
@(r15===16'h0005);
|
125 |
|
|
if (r10 !== 16'h0001) tb_error("====== SIGNED MULTIPLICATION: RESLO (5) =====");
|
126 |
|
|
if (r11 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: RESHI (5) =====");
|
127 |
|
|
if (r12 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (5) =====");
|
128 |
|
|
|
129 |
|
|
@(r15===16'h0006);
|
130 |
|
|
if (r10 !== 16'h8001) tb_error("====== SIGNED MULTIPLICATION: RESLO (6) =====");
|
131 |
|
|
if (r11 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLICATION: RESHI (6) =====");
|
132 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (6) =====");
|
133 |
|
|
|
134 |
|
|
@(r15===16'h0007);
|
135 |
|
|
if (r10 !== 16'h8000) tb_error("====== SIGNED MULTIPLICATION: RESLO (7) =====");
|
136 |
|
|
if (r11 !== 16'hC000) tb_error("====== SIGNED MULTIPLICATION: RESHI (7) =====");
|
137 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (7) =====");
|
138 |
|
|
|
139 |
|
|
@(r15===16'h0008);
|
140 |
|
|
if (r10 !== 16'h8000) tb_error("====== SIGNED MULTIPLICATION: RESLO (8) =====");
|
141 |
|
|
if (r11 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: RESHI (8) =====");
|
142 |
|
|
if (r12 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (8) =====");
|
143 |
|
|
|
144 |
|
|
@(r15===16'h0009);
|
145 |
|
|
if (r10 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: RESLO (9) =====");
|
146 |
|
|
if (r11 !== 16'h4000) tb_error("====== SIGNED MULTIPLICATION: RESHI (9) =====");
|
147 |
|
|
if (r12 !== 16'h0000) tb_error("====== SIGNED MULTIPLICATION: SUMEXT (9) =====");
|
148 |
|
|
|
149 |
|
|
$display("Signed Multiplication test completed (MPYS mode)");
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
// UNSIGNED MULTIPLY ACCUMULATE
|
153 |
|
|
//--------------------------------------------------------
|
154 |
|
|
|
155 |
|
|
@(r15===16'h0001);
|
156 |
|
|
if (r10 !== 16'h7F14) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (1) =====");
|
157 |
|
|
if (r11 !== 16'hC07B) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (1) =====");
|
158 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (1) =====");
|
159 |
|
|
|
160 |
|
|
@(r15===16'h0002);
|
161 |
|
|
if (r10 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (2) =====");
|
162 |
|
|
if (r11 !== 16'hC000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (2) =====");
|
163 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (2) =====");
|
164 |
|
|
|
165 |
|
|
@(r15===16'h0003);
|
166 |
|
|
if (r10 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (3) =====");
|
167 |
|
|
if (r11 !== 16'hC000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (3) =====");
|
168 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (3) =====");
|
169 |
|
|
|
170 |
|
|
@(r15===16'h0004);
|
171 |
|
|
if (r10 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (4) =====");
|
172 |
|
|
if (r11 !== 16'hFFFF) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (4) =====");
|
173 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (4) =====");
|
174 |
|
|
|
175 |
|
|
@(r15===16'h0005);
|
176 |
|
|
if (r10 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (5) =====");
|
177 |
|
|
if (r11 !== 16'hBFFE) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (5) =====");
|
178 |
|
|
if (r12 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (5) =====");
|
179 |
|
|
|
180 |
|
|
@(r15===16'h0006);
|
181 |
|
|
if (r10 !== 16'h8001) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (6) =====");
|
182 |
|
|
if (r11 !== 16'h3FFE) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (6) =====");
|
183 |
|
|
if (r12 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (6) =====");
|
184 |
|
|
|
185 |
|
|
@(r15===16'h0007);
|
186 |
|
|
if (r10 !== 16'h8000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (7) =====");
|
187 |
|
|
if (r11 !== 16'hFFFF) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (7) =====");
|
188 |
|
|
if (r12 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (7) =====");
|
189 |
|
|
|
190 |
|
|
@(r15===16'h0008);
|
191 |
|
|
if (r10 !== 16'h8000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (8) =====");
|
192 |
|
|
if (r11 !== 16'h3FFF) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (8) =====");
|
193 |
|
|
if (r12 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (8) =====");
|
194 |
|
|
|
195 |
|
|
@(r15===16'h0009);
|
196 |
|
|
if (r10 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESLO (9) =====");
|
197 |
|
|
if (r11 !== 16'h0000) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: RESHI (9) =====");
|
198 |
|
|
if (r12 !== 16'h0001) tb_error("====== UNSIGNED MULTIPLY ACCUMULATE: SUMEXT (9) =====");
|
199 |
|
|
|
200 |
|
|
$display("Unsigned Multiply Accumulate test completed (MAC mode)");
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
// SIGNED MULTIPLY ACCUMULATE
|
204 |
|
|
//--------------------------------------------------------
|
205 |
|
|
|
206 |
|
|
@(r15===16'h0001);
|
207 |
|
|
if (r10 !== 16'h7F14) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (1) =====");
|
208 |
|
|
if (r11 !== 16'hA7F9) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (1) =====");
|
209 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (1) =====");
|
210 |
|
|
|
211 |
|
|
@(r15===16'h0002);
|
212 |
|
|
if (r10 !== 16'h0000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (2) =====");
|
213 |
|
|
if (r11 !== 16'hC000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (2) =====");
|
214 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (2) =====");
|
215 |
|
|
|
216 |
|
|
@(r15===16'h0003);
|
217 |
|
|
if (r10 !== 16'h0001) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (3) =====");
|
218 |
|
|
if (r11 !== 16'hC000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (3) =====");
|
219 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (3) =====");
|
220 |
|
|
|
221 |
|
|
@(r15===16'h0004);
|
222 |
|
|
if (r10 !== 16'h0001) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (4) =====");
|
223 |
|
|
if (r11 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (4) =====");
|
224 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (4) =====");
|
225 |
|
|
|
226 |
|
|
@(r15===16'h0005);
|
227 |
|
|
if (r10 !== 16'h0001) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (5) =====");
|
228 |
|
|
if (r11 !== 16'hC000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (5) =====");
|
229 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (5) =====");
|
230 |
|
|
|
231 |
|
|
@(r15===16'h0006);
|
232 |
|
|
if (r10 !== 16'h8001) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (6) =====");
|
233 |
|
|
if (r11 !== 16'hBFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (6) =====");
|
234 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (6) =====");
|
235 |
|
|
|
236 |
|
|
@(r15===16'h0007);
|
237 |
|
|
if (r10 !== 16'h8000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (7) =====");
|
238 |
|
|
if (r11 !== 16'h8000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (7) =====");
|
239 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (7) =====");
|
240 |
|
|
|
241 |
|
|
@(r15===16'h0008);
|
242 |
|
|
if (r10 !== 16'h8000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (8) =====");
|
243 |
|
|
if (r11 !== 16'hC000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (8) =====");
|
244 |
|
|
if (r12 !== 16'hFFFF) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (8) =====");
|
245 |
|
|
|
246 |
|
|
@(r15===16'h0009);
|
247 |
|
|
if (r10 !== 16'h0000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESLO (9) =====");
|
248 |
|
|
if (r11 !== 16'h0000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: RESHI (9) =====");
|
249 |
|
|
if (r12 !== 16'h0000) tb_error("====== SIGNED MULTIPLY ACCUMULATE: SUMEXT (9) =====");
|
250 |
|
|
|
251 |
|
|
$display("Signed Multiply Accumulate test completed (MACS mode)");
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
stimulus_done = 1;
|
255 |
|
|
end
|
256 |
|
|
|