On May 3, 7:45 pm, Andrey Tarasevich <andreytarasev...@[EMAIL PROTECTED]
>
wrote:
> Tom=E1s =D3 h=C9ilidhe wrote:
> > I'm working with a microcontroller at the moment that has a single
> > instruction for clearing a bit in a byte.
>
> > I started off with the following line of code:
>
> > x &=3D ~0x8u; /* Clear the 4th bit */
>
> > But then I changed it to the following because I thought I might get
> > more efficient assembler out of it:
>
> > x &=3D 0xF7u; /* Clear the 4th bit */
>
> > Suprisingly, the compiler produced more efficient code for the latter,
> > presumably because it recognises the pattern of " x &=3D ~y" for
> > clearing a single bit.
>
> > Anyway just thought I'd give an example of someone winding up with
> > less efficient code when their aim was to make the code more
> > efficient :-D
>
> What the other are saying here is that if size of 'int' on your platform
i=
s
> greater than 1 byte, then these two pieces of code are not equivalent.
Actually that's not the case.
It doesn't matter whether int is 1 byte or more, since int is at least
16 bits, the operators are well-defined, et cetera.


|