In this example fileds F1 and F2 with sizes CAP1 and CAP2 are multiplied and result is written to field MUL with size CAP1+CAP2. Multiplication is performed by accumulating partial sums in MUL field ( CAP2 iterations ). Partial sum is calculated by shift of filed F1 by number of bits equal to iteration number. Meanwhile corresponding bits of field F2 are put in mask register M, so adding of partial sum with MUL field is done only for those channels where bit of F2 is one.
procedure MULF( refer slice mul[ ], f1[ ], f2[ ]; index cap1, cap2 );
index
outcap, i;
begin
outcap := cap1 + cap2;
MASKOFF;
{ Clear mul field }
for i := 0 to outcap-1 do CLEAR( mul[ i ] );
for i := 0 to cap2-1 do
begin
{ Put in mask register i-th bit of multiplier }
MASKOFF;
COPY( M, f2[ i ] );
MASKON;
{ Add up partial sum to mul field,
start adding from i-th bit of mul field }
ADDF( mul[ i ], mul[ i ], f1, cap1, cap1 );
end
end;{ End of MULF }