From 1fd8037d41be46d24b3610c89f781fe85def4317 Mon Sep 17 00:00:00 2001 From: "Pavel V. Shatov (Meister)" Date: Sat, 1 Jul 2017 02:05:02 +0300 Subject: Finished modulus-dependent coefficient calculation module: * fixed bug with latency compensation * cleaned up Verilog source * added 512-bit testbench * works in simulator * synthesizes without warnings Changes: * made latency of generic processing element configurable --- src/tb/tb_factor.v | 2 +- src/tb/tb_n_coeff.v | 235 +++++++++++++++++++++++++++++++--------- src/tb/tb_systolic_multiplier.v | 2 +- 3 files changed, 186 insertions(+), 53 deletions(-) (limited to 'src/tb') diff --git a/src/tb/tb_factor.v b/src/tb/tb_factor.v index 53e6769..946883c 100644 --- a/src/tb/tb_factor.v +++ b/src/tb/tb_factor.v @@ -43,7 +43,7 @@ module tb_factor; // // Test Vectors // - `include "../modexp_fpga_model_vectors.v"; + `include "modexp_fpga_model_vectors.v"; // // Parameters diff --git a/src/tb/tb_n_coeff.v b/src/tb/tb_n_coeff.v index 6ab824a..269dc39 100644 --- a/src/tb/tb_n_coeff.v +++ b/src/tb/tb_n_coeff.v @@ -43,12 +43,13 @@ module tb_n_coeff; // // Test Vectors // - `include "../modexp_fpga_model_vectors.v"; + `include "modexp_fpga_model_vectors.v"; // // Parameters // localparam NUM_WORDS_384 = 384 / 32; + localparam NUM_WORDS_512 = 512 / 32; // // Clock (100 MHz) @@ -146,6 +147,7 @@ module tb_n_coeff; #100; test_n_coeff_384(N_384); + test_n_coeff_512(N_512); end @@ -169,9 +171,7 @@ module tb_n_coeff; $finish; end - - n_num_words = 4'd11; // set number of words - + n_num_words = 4'd11; // set number of words write_memory_384(n); // fill memory ena = 1; // start operation @@ -181,7 +181,7 @@ module tb_n_coeff; while (!rdy) #10; // wait for operation to complete read_memory_384(result); // get result from memory - $display(" calculated: %x", result); // + $display(" calculated: %x", result); // display results $display(" expected: %x", n_coeff); // // check calculated value @@ -198,65 +198,159 @@ module tb_n_coeff; endtask - task write_memory_384; + task test_n_coeff_512; + input [511:0] n; + reg [511:0] n_coeff; + reg [511:0] result; + integer i; + begin + + calc_n_coeff_512(n, n_coeff); // calculate n_coeff on-the-fly + + // make sure, that the value matches the one saved in the include file + if (n_coeff !== N_COEFF_512) begin + $display("ERROR: Calculated factor value differs from the one in the test vector!"); + $finish; + end + + n_num_words = 4'd15; // set number of words + write_memory_512(n); // fill memory + + ena = 1; // start operation + #10; // + ena = 0; // clear flag + + while (!rdy) #10; // wait for operation to complete + read_memory_512(result); // get result from memory + + $display(" calculated: %x", result); // display results + $display(" expected: %x", n_coeff); // + + // check calculated value + if (n_coeff === result) begin + $display(" OK"); + $display("SUCCESS: Test passed."); + end else begin + $display(" ERROR"); + $display("FAILURE: Test not passed."); + end + + end + + endtask - input [383:0] n; + // + // write_memory_384 + // + task write_memory_384; + // + input [383:0] n; reg [383:0] n_shreg; - + // begin - - tb_n_wren = 1; // start filling memories - - n_shreg = n; // - - for (w=0; w