In reply to Rsignori92:
Actually << and <<< behaves the same on
assign b = a << 1 ;
statement.
Both give me the behavior that I actually want on all numbers I tried. So I guess that’s not a problem to me. I cannot change the sizes of a and b because I want a to represent numbers from -16 to +15, and b to represent numbers from -64 to +63.
After a bit trial and error, this is what I concluded about the compiler behavior:
-
The first statement does sign-extending to 6 bits first, and then shifting-
eg: 0101 (+5) → 000101 → 001010 (+10)
eg: 1010 (-6) → 111010 → 110100 (-12) -
The second statement does shifting first, and then sign extends to 6 bits because of signed’(), which results in loss of MSB-
eg: 0101 (+5) → 1010 → 111010 (-6)
eg: 1010 (-6) → 0100 → 000100 (+4)