3 ms·
Another way would be to use one register for "zero" vs. "non-zero", and another for negative (basically 2 bit sign-magnitude representation). C_sgn = A_sgn
by rep_lodsb 3y ago
Another way would be to use one register for "zero" vs. "non-zero", and another for negative (basically 2 bit sign-magnitude representation).
C_sgn = A_sgn ^ B_sgn
C_mag = A_mag & B_mag
The result can then be converted into bitmasks for positive and negative:
C_plus = C_mag & ~C_sgn
C_minus = C_mag & C_sgn
This solution should be more efficient if there is an "AND NOT" instruction, or when multiplying more than two factors.
- rep_lodsb 3y agoThinking a bit more about this, you could eliminate the conversion and do sum = popcount(mag) - 2*popcount(mag & sgn)