4 parameter integer ACASCREG = 1;
5 parameter integer ADREG = 1;
6 parameter integer ALUMODEREG = 1;
7 parameter integer AREG = 1;
8 parameter AUTORESET_PATDET = "NO_RESET";
9 parameter A_INPUT = "DIRECT";
10 parameter integer BCASCREG = 1;
11 parameter integer BREG = 1;
12 parameter B_INPUT = "DIRECT";
13 parameter integer CARRYINREG = 1;
14 parameter integer CARRYINSELREG = 1;
15 parameter integer CREG = 1;
16 parameter integer DREG = 1;
17 parameter integer INMODEREG = 1;
18 parameter integer MREG = 1;
19 parameter integer OPMODEREG = 1;
20 parameter integer PREG = 1;
21 parameter SEL_MASK = "MASK";
22 parameter SEL_PATTERN = "PATTERN";
23 parameter USE_DPORT = "FALSE";
24 parameter USE_MULT = "MULTIPLY";
25 parameter USE_PATTERN_DETECT = "NO_PATDET";
26 parameter USE_SIMD = "ONE48";
27 parameter [47:0] MASK = 48'h3FFFFFFFFFFF;
28 parameter [47:0] PATTERN = 48'h000000000000;
29 parameter [3:0] IS_ALUMODE_INVERTED = 4'b0;
30 parameter [0:0] IS_CARRYIN_INVERTED = 1'b0;
31 parameter [0:0] IS_CLK_INVERTED = 1'b0;
32 parameter [4:0] IS_INMODE_INVERTED = 5'b0;
33 parameter [6:0] IS_OPMODE_INVERTED = 7'b0;
36 reg CEA1, CEA2, CEAD, CEALUMODE, CEB1, CEB2, CEC, CECARRYIN, CECTRL;
37 reg CED, CEINMODE, CEM, CEP;
38 reg RSTA, RSTALLCARRYIN, RSTALUMODE, RSTB, RSTC, RSTCTRL, RSTD, RSTINMODE, RSTM, RSTP;
48 reg CARRYCASCIN, CARRYIN, MULTSIGNIN;
50 output [29:0] ACOUT, REF_ACOUT;
51 output [17:0] BCOUT, REF_BCOUT;
52 output CARRYCASCOUT, REF_CARRYCASCOUT;
53 output [3:0] CARRYOUT, REF_CARRYOUT;
54 output MULTSIGNOUT, REF_MULTSIGNOUT;
55 output OVERFLOW, REF_OVERFLOW;
56 output [47:0] P, REF_P;
57 output PATTERNBDETECT, REF_PATTERNBDETECT;
58 output PATTERNDETECT, REF_PATTERNDETECT;
59 output [47:0] PCOUT, REF_PCOUT;
60 output UNDERFLOW, REF_UNDERFLOW;
74 if (REF_P !== P) begin
75 $display("ERROR at %1t: REF_P=%b UUT_P=%b DIFF=%b", $time, REF_P, P, REF_P ^ P);
76 errcount = errcount + 1;
79 if (REF_CARRYOUT !== CARRYOUT) begin
80 $display("ERROR at %1t: REF_CARRYOUT=%b UUT_CARRYOUT=%b", $time, REF_CARRYOUT, CARRYOUT);
81 errcount = errcount + 1;
84 if (REF_PATTERNDETECT !== PATTERNDETECT) begin
85 $display("ERROR at %1t: REF_PATTERNDETECT=%b UUT_PATTERNDETECT=%b DIFF=%b REF_P=%b P=%b", $time, REF_PATTERNDETECT, PATTERNDETECT, REF_PATTERNDETECT ^ PATTERNDETECT, REF_P, P);
86 errcount = errcount + 1;
89 if (REF_PATTERNBDETECT !== PATTERNBDETECT) begin
90 $display("ERROR at %1t: REF_PATTERNBDETECT=%b UUT_PATTERNBDETECT=%b DIFF=%b", $time, REF_PATTERNBDETECT, PATTERNBDETECT, REF_PATTERNBDETECT ^ PATTERNBDETECT);
91 errcount = errcount + 1;
94 if (REF_OVERFLOW !== OVERFLOW) begin
95 $display("ERROR at %1t: REF_OVERFLOW=%b UUT_OVERFLOW=%b DIFF=%b", $time, REF_OVERFLOW, OVERFLOW, REF_OVERFLOW ^ OVERFLOW);
96 errcount = errcount + 1;
99 if (REF_UNDERFLOW !== UNDERFLOW) begin
100 $display("ERROR at %1t: REF_UNDERFLOW=%b UUT_UNDERFLOW=%b DIFF=%b", $time, REF_UNDERFLOW, UNDERFLOW, REF_UNDERFLOW ^ UNDERFLOW);
101 errcount = errcount + 1;
108 reg config_valid = 0;
112 if (AREG != 2 && INMODE[0]) config_valid = 0;
113 if (BREG != 2 && INMODE[4]) config_valid = 0;
115 if (USE_SIMD != "ONE48" && OPMODE[3:0] == 4'b0101) config_valid = 0;
117 if (OPMODE[1:0] == 2'b10 && PREG != 1) config_valid = 0;
118 if ((OPMODE[3:2] == 2'b01) ^ (OPMODE[1:0] == 2'b01) == 1'b1) config_valid = 0;
119 if ((OPMODE[6:4] == 3'b010 || OPMODE[6:4] == 3'b110) && PREG != 1) config_valid = 0;
120 if ((OPMODE[6:4] == 3'b100) && (PREG != 1 || OPMODE[3:0] != 4'b1000 || ALUMODE[3:2] == 2'b01 || ALUMODE[3:2] == 2'b11)) config_valid = 0;
121 if ((CARRYINSEL == 3'b100 || CARRYINSEL == 3'b101 || CARRYINSEL == 3'b111) && (PREG != 1)) config_valid = 0;
122 if (OPMODE[6:4] == 3'b111) config_valid = 0;
123 if ((OPMODE[3:0] == 4'b0101) && CARRYINSEL == 3'b010) config_valid = 0;
124 if (CARRYINSEL == 3'b000 && OPMODE == 7'b1001000) config_valid = 0;
126 if ((ALUMODE[3:2] == 2'b01 || ALUMODE[3:2] == 2'b11) && OPMODE[3:2] != 2'b00 && OPMODE[3:2] != 2'b10) config_valid = 0;
133 $dumpfile("test_dsp_model.vcd");
134 $dumpvars(0, testbench);
138 {CEA1, CEA2, CEAD, CEALUMODE, CEB1, CEB2, CEC, CECARRYIN, CECTRL} = 9'b111111111;
139 {CED, CEINMODE, CEM, CEP} = 4'b1111;
142 {ACIN, BCIN, PCIN} = 0;
143 {ALUMODE, CARRYINSEL, INMODE} = 0;
144 {OPMODE, CARRYCASCIN, CARRYIN, MULTSIGNIN} = 0;
146 {RSTA, RSTALLCARRYIN, RSTALUMODE, RSTB, RSTC, RSTCTRL, RSTD, RSTINMODE, RSTM, RSTP} = ~0;
157 {RSTA, RSTALLCARRYIN, RSTALUMODE, RSTB, RSTC, RSTCTRL, RSTD, RSTINMODE, RSTM, RSTP} = 0;
162 while (!config_valid) begin
167 C = {$urandom, $urandom};
169 PCIN = {$urandom, $urandom};
171 {CEA1, CEA2, CEAD, CEALUMODE, CEB1, CEB2, CEC, CECARRYIN, CECTRL} = $urandom | $urandom | $urandom;
172 {CED, CEINMODE, CEM, CEP} = $urandom | $urandom | $urandom | $urandom;
174 // Otherwise we can accidentally create illegal configs
178 {RSTA, RSTALLCARRYIN, RSTALUMODE, RSTB, RSTC, RSTCTRL, RSTD, RSTINMODE, RSTM, RSTP} = $urandom & $urandom & $urandom & $urandom & $urandom & $urandom;
179 {ALUMODE, INMODE} = $urandom;
180 CARRYINSEL = $urandom & $urandom & $urandom;
183 OPMODE[3:0] = 4'b0101; // test multiply more than other modes
184 {CARRYCASCIN, CARRYIN, MULTSIGNIN} = $urandom;
186 // So few valid options in these modes, just force one valid option
187 if (CARRYINSEL == 3'b001) OPMODE = 7'b1010101;
188 if (CARRYINSEL == 3'b010) OPMODE = 7'b0001010;
189 if (CARRYINSEL == 3'b011) OPMODE = 7'b0011011;
190 if (CARRYINSEL == 3'b100) OPMODE = 7'b0110011;
191 if (CARRYINSEL == 3'b101) OPMODE = 7'b0011010;
192 if (CARRYINSEL == 3'b110) OPMODE = 7'b0010101;
193 if (CARRYINSEL == 3'b111) OPMODE = 7'b0100011;
199 if (errcount == 0) begin
200 $display("All tests passed.");
203 $display("Caught %1d errors.", errcount);
209 .ACASCREG (ACASCREG),
211 .ALUMODEREG (ALUMODEREG),
213 .AUTORESET_PATDET (AUTORESET_PATDET),
215 .BCASCREG (BCASCREG),
218 .CARRYINREG (CARRYINREG),
219 .CARRYINSELREG (CARRYINSELREG),
222 .INMODEREG (INMODEREG),
224 .OPMODEREG (OPMODEREG),
226 .SEL_MASK (SEL_MASK),
227 .SEL_PATTERN (SEL_PATTERN),
228 .USE_DPORT (USE_DPORT),
229 .USE_MULT (USE_MULT),
230 .USE_PATTERN_DETECT (USE_PATTERN_DETECT),
231 .USE_SIMD (USE_SIMD),
234 .IS_ALUMODE_INVERTED(IS_ALUMODE_INVERTED),
235 .IS_CARRYIN_INVERTED(IS_CARRYIN_INVERTED),
236 .IS_CLK_INVERTED (IS_CLK_INVERTED),
237 .IS_INMODE_INVERTED (IS_INMODE_INVERTED),
238 .IS_OPMODE_INVERTED (IS_OPMODE_INVERTED)
242 .CARRYCASCOUT (REF_CARRYCASCOUT),
243 .CARRYOUT (REF_CARRYOUT),
244 .MULTSIGNOUT (REF_MULTSIGNOUT),
245 .OVERFLOW (REF_OVERFLOW),
247 .PATTERNBDETECT(REF_PATTERNBDETECT),
248 .PATTERNDETECT (REF_PATTERNDETECT),
250 .UNDERFLOW (REF_UNDERFLOW),
257 .CARRYCASCIN (CARRYCASCIN),
258 .CARRYINSEL (CARRYINSEL),
262 .CEALUMODE (CEALUMODE),
266 .CECARRYIN (CECARRYIN),
269 .CEINMODE (CEINMODE),
275 .MULTSIGNIN (MULTSIGNIN),
279 .RSTALLCARRYIN (RSTALLCARRYIN),
280 .RSTALUMODE (RSTALUMODE),
285 .RSTINMODE (RSTINMODE),
291 .ACASCREG (ACASCREG),
293 .ALUMODEREG (ALUMODEREG),
295 .AUTORESET_PATDET (AUTORESET_PATDET),
297 .BCASCREG (BCASCREG),
300 .CARRYINREG (CARRYINREG),
301 .CARRYINSELREG (CARRYINSELREG),
304 .INMODEREG (INMODEREG),
306 .OPMODEREG (OPMODEREG),
308 .SEL_MASK (SEL_MASK),
309 .SEL_PATTERN (SEL_PATTERN),
310 .USE_DPORT (USE_DPORT),
311 .USE_MULT (USE_MULT),
312 .USE_PATTERN_DETECT (USE_PATTERN_DETECT),
313 .USE_SIMD (USE_SIMD),
316 .IS_ALUMODE_INVERTED(IS_ALUMODE_INVERTED),
317 .IS_CARRYIN_INVERTED(IS_CARRYIN_INVERTED),
318 .IS_CLK_INVERTED (IS_CLK_INVERTED),
319 .IS_INMODE_INVERTED (IS_INMODE_INVERTED),
320 .IS_OPMODE_INVERTED (IS_OPMODE_INVERTED)
324 .CARRYCASCOUT (CARRYCASCOUT),
325 .CARRYOUT (CARRYOUT),
326 .MULTSIGNOUT (MULTSIGNOUT),
327 .OVERFLOW (OVERFLOW),
329 .PATTERNBDETECT(PATTERNBDETECT),
330 .PATTERNDETECT (PATTERNDETECT),
332 .UNDERFLOW (UNDERFLOW),
339 .CARRYCASCIN (CARRYCASCIN),
340 .CARRYINSEL (CARRYINSEL),
344 .CEALUMODE (CEALUMODE),
348 .CECARRYIN (CECARRYIN),
351 .CEINMODE (CEINMODE),
357 .MULTSIGNIN (MULTSIGNIN),
361 .RSTALLCARRYIN (RSTALLCARRYIN),
362 .RSTALUMODE (RSTALUMODE),
367 .RSTINMODE (RSTINMODE),
373 module mult_noreg_nopreadd_nocasc;
379 .AUTORESET_PATDET ("NO_RESET"),
393 .SEL_PATTERN ("PATTERN"),
394 .USE_DPORT ("FALSE"),
395 .USE_MULT ("DYNAMIC"),
396 .USE_PATTERN_DETECT ("NO_PATDET"),
398 .MASK (48'h3FFFFFFFFFFF),
399 .PATTERN (48'h000000000000),
400 .IS_ALUMODE_INVERTED(4'b0),
401 .IS_CARRYIN_INVERTED(1'b0),
402 .IS_CLK_INVERTED (1'b0),
403 .IS_INMODE_INVERTED (5'b0),
404 .IS_OPMODE_INVERTED (7'b0)
408 module mult_allreg_nopreadd_nocasc;
414 .AUTORESET_PATDET ("NO_RESET"),
428 .SEL_PATTERN ("PATTERN"),
429 .USE_DPORT ("FALSE"),
430 .USE_MULT ("DYNAMIC"),
431 .USE_PATTERN_DETECT ("NO_PATDET"),
433 .MASK (48'h3FFFFFFFFFFF),
434 .PATTERN (48'h000000000000),
435 .IS_ALUMODE_INVERTED(4'b0),
436 .IS_CARRYIN_INVERTED(1'b0),
437 .IS_CLK_INVERTED (1'b0),
438 .IS_INMODE_INVERTED (5'b0),
439 .IS_OPMODE_INVERTED (7'b0)
443 module mult_noreg_preadd_nocasc;
449 .AUTORESET_PATDET ("NO_RESET"),
463 .SEL_PATTERN ("PATTERN"),
465 .USE_MULT ("DYNAMIC"),
466 .USE_PATTERN_DETECT ("NO_PATDET"),
468 .MASK (48'h3FFFFFFFFFFF),
469 .PATTERN (48'h000000000000),
470 .IS_ALUMODE_INVERTED(4'b0),
471 .IS_CARRYIN_INVERTED(1'b0),
472 .IS_CLK_INVERTED (1'b0),
473 .IS_INMODE_INVERTED (5'b0),
474 .IS_OPMODE_INVERTED (7'b0)
478 module mult_allreg_preadd_nocasc;
484 .AUTORESET_PATDET ("NO_RESET"),
498 .SEL_PATTERN ("PATTERN"),
500 .USE_MULT ("DYNAMIC"),
501 .USE_PATTERN_DETECT ("NO_PATDET"),
503 .MASK (48'h3FFFFFFFFFFF),
504 .PATTERN (48'h000000000000),
505 .IS_ALUMODE_INVERTED(4'b0),
506 .IS_CARRYIN_INVERTED(1'b0),
507 .IS_CLK_INVERTED (1'b0),
508 .IS_INMODE_INVERTED (5'b0),
509 .IS_OPMODE_INVERTED (7'b0)
513 module mult_inreg_preadd_nocasc;
519 .AUTORESET_PATDET ("NO_RESET"),
533 .SEL_PATTERN ("PATTERN"),
535 .USE_MULT ("DYNAMIC"),
536 .USE_PATTERN_DETECT ("NO_PATDET"),
538 .MASK (48'h3FFFFFFFFFFF),
539 .PATTERN (48'h000000000000),
540 .IS_ALUMODE_INVERTED(4'b0),
541 .IS_CARRYIN_INVERTED(1'b0),
542 .IS_CLK_INVERTED (1'b0),
543 .IS_INMODE_INVERTED (5'b0),
544 .IS_OPMODE_INVERTED (7'b0)
548 module simd12_preadd_noreg_nocasc;
554 .AUTORESET_PATDET ("NO_RESET"),
568 .SEL_PATTERN ("PATTERN"),
570 .USE_MULT ("DYNAMIC"),
571 .USE_PATTERN_DETECT ("NO_PATDET"),
572 .USE_SIMD ("FOUR12"),
573 .MASK (48'h3FFFFFFFFFFF),
574 .PATTERN (48'h000000000000),
575 .IS_ALUMODE_INVERTED(4'b0),
576 .IS_CARRYIN_INVERTED(1'b0),
577 .IS_CLK_INVERTED (1'b0),
578 .IS_INMODE_INVERTED (5'b0),
579 .IS_OPMODE_INVERTED (7'b0)
584 module simd24_preadd_noreg_nocasc;
590 .AUTORESET_PATDET ("NO_RESET"),
604 .SEL_PATTERN ("PATTERN"),
606 .USE_MULT ("DYNAMIC"),
607 .USE_PATTERN_DETECT ("NO_PATDET"),
609 .MASK (48'h3FFFFFFFFFFF),
610 .PATTERN (48'h000000000000),
611 .IS_ALUMODE_INVERTED(4'b0),
612 .IS_CARRYIN_INVERTED(1'b0),
613 .IS_CLK_INVERTED (1'b0),
614 .IS_INMODE_INVERTED (5'b0),
615 .IS_OPMODE_INVERTED (7'b0)
619 module macc_overflow_underflow;
625 .AUTORESET_PATDET ("NO_RESET"),
639 .SEL_PATTERN ("PATTERN"),
640 .USE_DPORT ("FALSE"),
641 .USE_MULT ("DYNAMIC"),
642 .USE_PATTERN_DETECT ("PATDET"),
644 .MASK (48'h1FFFFFFFFFFF),
645 .PATTERN (48'h000000000000),
646 .IS_ALUMODE_INVERTED(4'b0),
647 .IS_CARRYIN_INVERTED(1'b0),
648 .IS_CLK_INVERTED (1'b0),
649 .IS_INMODE_INVERTED (5'b0),
650 .IS_OPMODE_INVERTED (7'b0)