To summarize your question: how can you add two unsigned arrays of integers that propagate hyphenation.
uint16_t foo[4];
Well, FFFF + FFFF + 1 is just (1) FFFF. Thus, hyphenation can always be added to each word without additional hyphenation (as if the sum could be 20,000).
Creating a temporary amount: sum = foo[3] + bar[3] + carry; with the transfer, initially 0, or this amount creates a new transfer, or not.
- Carry is made from (A + B) if
(A+B) < A - When summing (A + B + c), the transfer is performed if
((A + c) < A) || (((A + c) + B) < B) ((A + c) < A) || (((A + c) + B) < B)
Another possibility is to compute "multi-bit portability" by summing several members in columns, which is often found in bignom multiplications:
AAAA BBBB CCCC DDDD EEEE FFFF .... GGGG HHHH IIII .... .... -------------------------- col4 col3 col2 col1 col0
Now each column creates a 32-bit or 64-bit result and a carry, which does not necessarily correspond to one bit.
uint32_t sum_low = carry_in_from_previous_column; uint32_t sum_high = 0; for (i = 0; i < N; i++) { sum_low += matrix[i][column] & 0xffff; sum_high += matrix[i][column] >> 16; } sum_high += sum_low >> 16;
source share