First of all, the document you referenced does NOT contain any more information than the one I've referenced. It's just an older version of the document I have referenced, and since I am using the newer version of the core, that is the version of the document I'm looking at.
Second, since obviously not everyone here knows enough about binary arithmetics to understand my questions, let me illustrate on an example of adding/subtracting 2 3-bit signed numbers:
Using 2's complement representation, we can represent the following numbers with 3 bits:
0 = 000 1 = 001 2 = 010 3 = 011-4 =100
-3 =101
-2 =110
-1 =111
What is the lowest result we can get by adding/subtracting two 3-bit signed numbers? Obviously:
-4 + -4 = 100
- 100 =1000 = (-8 if all 4 bits are considered, or 0 if only 3 bits are considered)
To store the valid result, we only need 4 bits.
What is the highest number we can get by adding/subtracting two 3-bit signed numbers? Obvioulsy:
3+3 = 011- 011 = 0110 (6 if all 4 bits are considered, otherwise -2 if only 3 bits are considered)
To store the valid result we again need at most 4 bits.
Now let's go with the terminology in the Core specification
However, if one of the numbers is unsigned, 4 bits are not enough. We can illustrate that using the following example:
-4 - (7) = -11 If we represent -4 with a 3-bit signed number and 7 with a three bit signed number, we need to sign extend them both (to 4 bits) to be able to get correct result, and we need 5 bits to store the correct result (-11 obviously cannot fit in 4-bits). This explains why P=Q+2 (instead of Q+1) when one of the numbers is unsigned, which was one of my original questions, but nobody would answer it. And I didn't understand it until I performed this analysis.
There, I had to answer one of my questions myself.
However, this still doesn't explain what is the difference between the following two cases:
(See Table 2 in
- Operand A: Unsigned, Operand B: Signed or by input pin (2nd row), when the input pin is set so that the operand B is signed
and
- Operand A: Signed or by input pin, Operand B: Signed or by input pin, (last row) when the input pins denote that the operand A is unsigned and operand B is signed
In both cases 1 and 2 above the operands are exactly the same, but the availability of the overflow flag and the widths of the result are different. In particular, I cannot get the result to be of the width P=Q+2 in case 2. WHY?????????????????????????????????????????
Also, in table 2, why is overflow not available if I select the width of the output to be P=Q+1????