Christophe Leroy <christophe.le...@c-s.fr> writes:

> Help a bit the compiler to provide better code:
>
> unsigned int f(int i)
> {
>       return 1 << (31 - i);
> }
>
> unsigned int g(int i)
> {
>       return 0x80000000 >> i;
> }
>
> Disassembly of section .text:
>
> 00000000 <f>:
>    0: 20 63 00 1f     subfic  r3,r3,31
>    4: 39 20 00 01     li      r9,1
>    8: 7d 23 18 30     slw     r3,r9,r3
>    c: 4e 80 00 20     blr
>
> 00000010 <g>:
>   10: 3d 20 80 00     lis     r9,-32768
>   14: 7d 23 1c 30     srw     r3,r9,r3
>   18: 4e 80 00 20     blr

Well yeah, it saves one instruction, but is it worth it? Are these gpio
routines in some hot path I don't know about?

cheers

Reply via email to