On 21/04/15 21:09, Dan Carpenter wrote:
I knew the original was undefined because Ian showed me the relevant section from the standard. I'm actually surprised that it doesn't work in GCC. Using -fno-strict-overflow doesn't help either. I think at the optimizations that the kernel uses -O2 and -Os the original "works".
It's mostly down to the limitations of the CPU machine code instructions for shifting. In the case of the x86 32-bit wide shift instructions, the "shift amount operand" is reduced modulo 32 (similarly for shift instructions of other widths). If the compiler were to allow arbitrary, non-constant shift amounts to work properly, it would have to insert extra code to work around the limitations of the underlying instruction.
-- -=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@xxxxxxxxx> )=- -=( Web: http://www.mev.co.uk/ )=- _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel