"Tomás Ó hÉilidhe" <toe@[EMAIL PROTECTED]
> wrote in message
news:851bdee4-c15c-4e07-bc62-166b346d2651@[EMAIL PROTECTED]
> Ian Collins:
>
>> > Suprisingly, the compiler produced more efficient code for the
latter,
>> > presumably because it recognises the pattern of " x &= ~y" for
>> > clearing a single bit.
>>
>> Odd, is x an unsigned 8 bit type?
>
>
> Yes, it is.
>
>
>> If so, the two expressions should
>> generate identical code.
>
>
> If I do:
>
> y &= ~0x08u;
>
> then I get the following assembler:
>
> BCF y, 0x3 /* Clear the 4th bit of y */
>
> If I do:
>
> y &= 0x7Fu;
>
> then I get the following assembler:
>
> MOVLW 0x7f /* Load the ac***ulator with 0x7f */
> ANDWF y, F /* AND y with the ac***ulator
> and store the result in y */
(You meant 0xF7 here?)
Typically a compiler will reduce ~0x8u down to 0xF7u anyway, so there
shouldn't be a difference.
Unless ~0x8u actually generates 0xFFF7u? What's the default uint size on
this compiler? What does y &= 0xFFF7u compile to, if anything? What about
y
&= 0x0A?
Or possibly it's just a quirk in the compiler's optimiser. File a bug
re****t.
-- Bartc


|