--- Quote Start ---
the operand is signed the operands need to be converted to positive format, multiplied then converted to negative at the end if the signs are different.
--- Quote End ---
I agree and the math proof is very straightforward:
n * -m = - (n * m)
-n *m =-(n*m)
so just convert -m to +m, multiply as unsigned, convert result back to negative. The overheads include two setd of inverter + two adders
but:
-m * -n = +(n*m)
convert sign inputs but not output.
I wonder if Trick have a math proof for his trick
By the way here is a 2's complement puzzle:
+ => - invert bits then add 1
- => + invert bits then add 1 ?? how come this correct
(or take 1 then invert bits, makes more sense)
--- Quote Start ---
Not commenting at all on the logistics of signed/unsigned multiplications, but more on synthesizable code, if you write:
signal sum : signed(3 downto 0);
IF(inc = '1') THEN
sum <= sum + 1;
ELSIF(dec = '1') THEN
sum <= sum - 1;
ELSE
sum <= sum;
END IF;
It will usually generate two adders and then mux the output together. However, if you were to write:
signal inc : integer range -1 to 1;
signal sum : signed(3 downto 0);
inc <= -1 when dec = '1' else
1 when inc = '1' else
0;
sum <= sum + inc;
Then it will usually generate a single adder with a mux at one of the input ports.
Obviously the summation should be in a clocked process, but i am being lazy.
Just a thought.
Kevin
--- Quote End ---
True, compiler instantiates one operation unit per operand occurence. It doesn't want to know your intentions. I refrred to this ages ago regarding multipliers, to avoid this use one (*) assignment only then switch your inputs/outputs as you wish.