aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modexpng_fpga_model.py65
1 files changed, 45 insertions, 20 deletions
diff --git a/modexpng_fpga_model.py b/modexpng_fpga_model.py
index 73a21d3..5632a6f 100644
--- a/modexpng_fpga_model.py
+++ b/modexpng_fpga_model.py
@@ -77,9 +77,9 @@ _VECTOR_CLASS = "Vector"
DUMP_VECTORS = False
DUMP_INDICES = False
DUMP_MACS_CLEARING = False
-DUMP_MACS_ACCUMULATION = False
+DUMP_MACS_ACCUMULATION = True
DUMP_MULT_PARTS = False
-DUMP_RCMB = True
+DUMP_RCMB = False
#
@@ -395,6 +395,12 @@ class ModExpNG_WordMultiplier():
if dump and DUMP_MULT_PARTS:
print("t=%2d, col=%2d > parts[%2d]: mac[%d] = 0x%012x" %
(time, column, part_index, mac_index, parts[part_index]))
+
+ def _mult_store_part_aux(self, parts, time, column, part_index, mac_index, dump):
+ parts[part_index] = self._mac_aux[mac_index]
+ if dump and DUMP_MULT_PARTS:
+ print("t=%2d, col=%2d > parts[%2d]: mac_aux[%d] = 0x%012x" %
+ (time, column, part_index, mac_index, parts[part_index]))
def multiply_square(self, a_wide, b_narrow, ab_num_words, dump=False):
@@ -443,8 +449,6 @@ class ModExpNG_WordMultiplier():
part_index = t
self._mult_store_part(parts, t, col, part_index, x, dump)
-
-
if dump and DUMP_MACS_ACCUMULATION:
print("t=%2d, col=%2d > "% (t, col), end='')
for i in range(NUM_MULTS):
@@ -462,7 +466,9 @@ class ModExpNG_WordMultiplier():
return parts
- def multiply_triangle(self, a_wide, b_narrow, ab_num_words):
+ def multiply_triangle(self, a_wide, b_narrow, ab_num_words, dump=False):
+
+ if dump: print("multiply_triangle()")
num_cols = ab_num_words // NUM_MULTS
@@ -474,15 +480,27 @@ class ModExpNG_WordMultiplier():
last_col = col == (num_cols - 1)
- self._clear_all_macs()
- self._preset_indices(col)
-
- if last_col:
- self._clear_mac_aux()
- self._preset_index_aux(num_cols)
-
for t in range(ab_num_words + 1):
+ if t == 0:
+ self._preset_indices(col)
+ if last_col:
+ self._preset_index_aux(num_cols)
+ else:
+ self._rotate_indices(ab_num_words)
+ if last_col:
+ self._rotate_index_aux()
+
+ if t == 0:
+ self._clear_all_macs()
+ if dump and DUMP_MACS_CLEARING:
+ print("t= 0, col=%2d > clear > all" % (col))
+
+ if last_col:
+ self._clear_mac_aux()
+ if dump and DUMP_MACS_CLEARING:
+ print("t= 0, col=%2d > clear > aux" % (col))
+
# current b-word
bt = b_narrow.words[t]
@@ -492,7 +510,8 @@ class ModExpNG_WordMultiplier():
self._update_one_mac(x, ax, bt)
if t == (col * NUM_MULTS + x):
- parts[t] = self._macs[x]
+ part_index = t
+ self._mult_store_part(parts, t, col, part_index, x, dump)
# aux multiplier
if last_col:
@@ -500,17 +519,23 @@ class ModExpNG_WordMultiplier():
self._update_mac_aux(ax * bt)
if t == ab_num_words:
- parts[t] = self._mac_aux[0]
+ part_index = t
+ self._mult_store_part_aux(parts, t, col, part_index, 0, dump)
+
+ if dump and DUMP_MACS_ACCUMULATION:
+ print("t=%2d, col=%2d > "% (t, col), end='')
+ for i in range(NUM_MULTS):
+ if i > 0: print(" | ", end='')
+ print("mac[%d]: 0x%012x" % (i, self._macs[i]), end='')
+ if last_col:
+ print(" | mac_aux[ 0]: 0x%012x" % (self._mac_aux[0]), end='')
+ print("")
+
# shortcut
if not last_col:
if t == (NUM_MULTS * (col + 1) - 1): break
- # advance indices
- self._rotate_indices(ab_num_words)
- if last_col:
- self._rotate_index_aux()
-
return parts
def multiply_rectangle(self, a_wide, b_narrow, ab_num_words):
@@ -693,7 +718,7 @@ class ModExpNG_Worker():
return ModExpNG_Operand(None, 2*ab_num_words, ab_words)
# 2.
- q_parts = self.multiplier.multiply_triangle(ab, n_coeff, ab_num_words)
+ q_parts = self.multiplier.multiply_triangle(ab, n_coeff, ab_num_words, dump)
q_words = self.recombinator.recombine_triangle(q_parts, ab_num_words, dump)
q = ModExpNG_Operand(None, ab_num_words + 1, q_words)