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: <abbo...@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-
_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to