To clarify: the right shift operator SHOULD be logical, but in mspgcc an arithmetic shift is used. This is probably because the MSP430 has no instruction for logical shifts (it was added in MSP430X). Logical right shift must be emulated by clearing the carry bit and using rotate-through-carry.
This should be fun to fix....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On further investigation: in C a right shift of a negative signed integer is implementation defined. GCC uses arithmetic shift in this case, but logical shift for an unsigned integer. I have verified that the behavior of code compiled by mspgcc is the same as stock gcc 4.4.3 on an i686 platform.
Non-discrepant; no change will be implemented.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Peter for the clarification. Is this the behavior for 32 bit signed numbers too on MSP430 ?. It was a while ago, but i remember facing the issue with 32 bit signed number on MSP430 on Telosb motes. The right shift was not giving me the correct results, and i had to use the divide operator.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To clarify: the right shift operator SHOULD be logical, but in mspgcc an arithmetic shift is used. This is probably because the MSP430 has no instruction for logical shifts (it was added in MSP430X). Logical right shift must be emulated by clearing the carry bit and using rotate-through-carry.
This should be fun to fix....
On further investigation: in C a right shift of a negative signed integer is implementation defined. GCC uses arithmetic shift in this case, but logical shift for an unsigned integer. I have verified that the behavior of code compiled by mspgcc is the same as stock gcc 4.4.3 on an i686 platform.
Non-discrepant; no change will be implemented.
Thanks Peter for the clarification. Is this the behavior for 32 bit signed numbers too on MSP430 ?. It was a while ago, but i remember facing the issue with 32 bit signed number on MSP430 on Telosb motes. The right shift was not giving me the correct results, and i had to use the divide operator.
This is the behaviour for 16, 32, and 64-bit integers, according to my testing.