[Cryptech-Commits] [core/math/modexpa7] 01/01: Adding CRT support...
git at cryptech.is
git at cryptech.is
Mon Aug 7 09:58:33 UTC 2017
This is an automated email from the git hooks/post-receive script.
meisterpaul1 at yandex.ru pushed a commit to branch systolic_crt
in repository core/math/modexpa7.
commit c61d70d0fdda23d4a1b5332ef821272eace62f47
Author: Pavel V. Shatov (Meister) <meisterpaul1 at yandex.ru>
AuthorDate: Mon Aug 7 12:57:18 2017 +0300
Adding CRT support...
---
src/rtl/modexpa7_systolic_multiplier.v | 2 +
src/tb/tb_systolic_multiplier.v | 98 +++++++++++++++++++++++++++++++++-
2 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/src/rtl/modexpa7_systolic_multiplier.v b/src/rtl/modexpa7_systolic_multiplier.v
index 7293998..851f7d5 100644
--- a/src/rtl/modexpa7_systolic_multiplier.v
+++ b/src/rtl/modexpa7_systolic_multiplier.v
@@ -57,6 +57,8 @@ module modexpa7_systolic_multiplier #
input ena,
output rdy,
+
+ input reduce_only,
output [OPERAND_ADDR_WIDTH-1:0] a_bram_addr,
output [OPERAND_ADDR_WIDTH-1:0] b_bram_addr,
diff --git a/src/tb/tb_systolic_multiplier.v b/src/tb/tb_systolic_multiplier.v
index 96e76d5..493a81d 100644
--- a/src/tb/tb_systolic_multiplier.v
+++ b/src/tb/tb_systolic_multiplier.v
@@ -73,6 +73,8 @@ module tb_systolic_multiplier;
reg rst_n;
reg ena;
+ reg reduce;
+
reg [ 3: 0] n_num_words;
@@ -192,8 +194,11 @@ module tb_systolic_multiplier;
rst_n = 1'b1;
#100;
- test_systolic_multiplier_384(M_384, N_384, N_COEFF_384, FACTOR_384, COEFF_384);
- test_systolic_multiplier_512(M_512, N_512, N_COEFF_512, FACTOR_512, COEFF_512);
+ //test_systolic_multiplier_384(M_384, N_384, N_COEFF_384, FACTOR_384, COEFF_384);
+ //test_systolic_multiplier_512(M_512, N_512, N_COEFF_512, FACTOR_512, COEFF_512);
+
+ test_systolic_multiplier_reduce_192(M_384, P_192, P_COEFF_192, COEFF_192_P);
+ test_systolic_multiplier_reduce_192(M_384, Q_192, Q_COEFF_192, COEFF_192_Q);
end
@@ -236,6 +241,8 @@ module tb_systolic_multiplier;
n_num_words = 4'd11; // set number of words
+ reduce = 0; // normal mode
+
num_passed = 0; // nothing tested so far
num_failed = 0; //
@@ -323,6 +330,8 @@ module tb_systolic_multiplier;
b = m_factor_modulo; // ... and b = m_factor
n_num_words = 4'd15; // set number of words
+
+ reduce = 0; // normal mode
num_passed = 0; // nothing tested so far
num_failed = 0; //
@@ -373,6 +382,91 @@ module tb_systolic_multiplier;
endtask
+
+ task test_systolic_multiplier_reduce_192;
+
+ input [383:0] m;
+ input [191:0] n;
+ input [191:0] n_coeff;
+ input [191:0] coeff;
+
+ reg [575:0] m_coeff_full;
+ reg [191:0] m_coeff_modulo;
+
+ //reg [383:0] a;
+ //reg [383:0] b;
+ //reg [383:0] r;
+
+ //reg [767:0] ab_full;
+ //reg [383:0] ab_modulo;
+
+ //integer round;
+ //integer num_passed;
+ //integer num_failed;
+
+ begin
+
+ m_coeff_full = m * coeff; // m * coeff
+ m_coeff_modulo = m_coeff_full % n; // (m * factor) % n
+
+ /*
+ a = m_factor_modulo; // start with a = m_factor...
+ b = m_factor_modulo; // ... and b = m_factor
+
+ n_num_words = 4'd11; // set number of words
+
+ reduce = 0; // normal mode
+
+ num_passed = 0; // nothing tested so far
+ num_failed = 0; //
+
+ for (round=0; round<NUM_ROUNDS; round=round+1) begin
+
+ // obtain reference value of product
+ ab_full = a * b; // calculate product
+ ab_modulo = ab_full % n; // reduce
+
+ ab_full = ab_modulo * coeff; // take extra coefficient into account
+ ab_modulo = ab_full % n; // reduce again
+
+ write_memories_384(a, b, n, n_coeff); // fill memories
+
+ ena = 1; // start operation
+ #10; //
+ ena = 0; // clear flag
+
+ while (!rdy) #10; // wait for operation to complete
+
+ read_memory_384(r); // get result from memory
+
+ $display("test_systolic_multiplier_384(): round #%0d of %0d", round+1, NUM_ROUNDS);
+ $display(" calculated: %x", r);
+ $display(" expected: %x", ab_modulo);
+
+ // check calculated value
+ if (r === ab_modulo) begin
+ $display(" OK");
+ num_passed = num_passed + 1;
+ end else begin
+ $display(" ERROR");
+ num_failed = num_failed + 1;
+ end
+
+ b = ab_modulo; // prepare for next round
+
+ end
+
+ // final step, display results
+ if (num_passed == NUM_ROUNDS)
+ $display("SUCCESS: All tests passed.");
+ else
+ $display("FAILURE: %0d test(s) not passed.", num_failed);
+ */
+
+ end
+
+ endtask
+
//
// BRAM Writer
More information about the Commits
mailing list