That's just about arithmetics. It's not semantically wrong because it's actually a correct modulo result, as operations on integers in computers result in the discarding of the high bits which is similar to modulo 2k in a k-bit computer.
First, you should know that non-widening multiplication is the same for both unsigned and 2's complement signed number with the same bit pattern.
For example: 10012 x 00112.
- Treating as unsigned we have 9 x 3 = 27 (0001 10112)
- Treat them as signed we have -7 x 3 = -21 (1110 10112)†
You can see a specific case here. For the general case take 2 positive k-bit numbers m
and n
for example. That means their negative values -m
and -n
will be represented by 2k - m and 2k - n§ respectively. Now we multiply those 2 negative values to get a k-bit result:
(-m)(-n) mod 2k
= (2k - m)(2k - n) mod 2k
= [22k -2k(m+n) + mn] mod 2k
= mn mod 2k
=(-m)(-n) mod 2k
The same in case one number is positive and the other is negative
So regardless of treating two bit patterns as signed or unsigned, the result is still the same.
Now we have two n-bit unsigned numbers and do multiplication on them, we'll get a 2n-bit number, because multiplying an n-bit number and an m-bit number producing an (n+m)-bit result.
But if we only care about the low n-bits of the result then it's exactly the same as the result of two n-bit unsigned numbers with the same bit pattern, as proved above.
So we take two (n/2)-bit signed numbers, sign-extend them to n-bits (your 1st step) and do non-widening multiplication (your 2nd step) to get an n-bit result. What we have now is exactly the same as signed widening multiplication from n/2 bits to n bits.
Doubling the bits in the signed operands is effectively just making them as wide as the final result so that the multiplication is now an unsigned non-widening instead of a signed widening one as before.
†If you notice, the high bits of the signed and unsigned versions will have relation to each other too, if you look at the proof above
§Because that's how two's complement is defined:
The two's complement of an N-bit number is defined as the complement with respect to 2N; in other words, it is the result of subtracting the number from 2N
Similar to 1's complement and 2's complement in binary, in decimal we have 9's complement and 10's complement to represent negative numbers although it's not used in daily life and is out of scope of this problem