def python_mul_remap_algorithm(a, b):
# version 2 of the MUL_256_X_256_TO_512_ASM algorithm using base 100 rather
# than 2^64, since that's easier to read.
- # run this file in a debugger to see all the intermediate values.
- a_sz = len(a)
- b_sz = len(b)
- a_idx = []
- b_idx = []
- a_plus_b_idx = []
- a_plus_b_plus_1_idx = []
+ a_sz, b_sz = len(a), = len(b)
+ ai, bi, apbi, apbp1 = [], [], [], [] # REMAP indices
for ai in range(a_sz):
for bi in range(b_sz):
- a_idx.append(ai)
- b_idx.append(bi)
- a_plus_b_idx.append(ai + bi)
- a_plus_b_plus_1_idx.append(ai + bi + 1)
+ ai.append(ai)
+ bi.append(bi)
+ apbi.append(ai + bi)
+ apbp1.append(ai + bi + 1)
y = [0] * (a_sz + b_sz)
ca = 0
# always be zero when (i % b_sz == 0).
# That said, hardware will probably want to pattern-match this to
# remove the unnecessary dependency through ca.
- y[a_plus_b_idx[i]], t = maddedu(
- a[a_idx[i]], b[b_idx[i]], y[a_plus_b_idx[i]])
- y[a_plus_b_plus_1_idx[i]], ca = adde(
- y[a_plus_b_plus_1_idx[i]], t, ca)
+ y[apbi[i]], t = maddedu(a[ai[i]], b[bi[i]], y[apbi[i]])
+ y[apbp1[i]], ca = adde(y[apbp1[i]], t, ca)
return y