In muldiv, what is this line of code doing?
prod0 |= prod1 * twos
Also can it overflow?
In muldiv, what is this line of code doing?
prod0 |= prod1 * twos
Also can it overflow?
This is a bitwise operation They do not cause an overflow.
prod0 |= prod1 * twos;
translated as prod0 = prod0 | (prod1 * twos);
The | operation is a binary OR. It puts a 1 on the result bit for which at least one of the corresponding operand bits is 1.
0 | 0 = 0
1 | 0 = 1
0 | 1 = 1
1 | 1 = 1
Then if you have incoming values:
prod0 = 2 // 00000010 binary
prod1 = 2
twos = 2
Then the result prod0 = prod0 | (prod1 * twos) is this:
(prod1 * twos) = 4 // 00000100 binary
prod0 = prod0 | 4 = 00000010 | 00000100 = 000000110 = 6