yield ai, bi, ai + bi, ai + bi + 1
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.
- a_sz, b_sz = len(a), len(b)
- y = [0] * (a_sz + b_sz)
- ca = 0
+ # version 3 that is identical in effect to the python_mul_algorithm above.
+ # yielding indices massively compacts down the function, the assembler is
+ # ridiculously short https://bugs.libre-soc.org/show_bug.cgi?id=1155#c10
+ a_sz, b_sz = len(a), len(b) # lengths of a and b
+ y, ca = [0] * (a_sz + b_sz), 0 # initialise array y, carry to zero
for ai, bi, apbi, apbp1 in python_mul_remap_yielder(a_sz, b_sz):
# no need to clear ca between ai outer loops, since the partial
# products can't get big enough to have a carry out, so ca will