On Fri, Sep 10, 2010 at 2:14 AM, Nicolas Pitre nicolas.pitre@linaro.org wrote:
[...]
lsl r0, r0, #28 asr r0, r0, #28 bx lr
But I doubt gcc could ever become that smart.
Some pointed out to me that the tempting C equivalent
(int)((unsigned)c << 28) >> 28
is invalid C, because the result of the unsigned->signed cast (needed to get arithmetic right shift) is undefined if the argument is > INT_MAX. Maybe that's why the eembc code is so verbose.
Of course, that C snippet is often used in practice, and works on common architectures using a sane integer representation.
Cheers ---Dave