Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Example of ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 9 Topic 26045 of 26959
Post > Topic >>

Re: Example of the optimiser recognising a pattern

by vippstar@[EMAIL PROTECTED] May 3, 2008 at 09:48 AM

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.
 




 9 Posts in Topic:
Example of the optimiser recognising a pattern
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-02 14:59:33 
Re: Example of the optimiser recognising a pattern
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-02 15:20:39 
Re: Example of the optimiser recognising a pattern
Ian Collins <ian-news@  2008-05-03 11:23:54 
Re: Example of the optimiser recognising a pattern
=?ISO-8859-1?Q?Tom=E1s_=D  2008-05-02 16:55:43 
Re: Example of the optimiser recognising a pattern
"Bartc" <bc@  2008-05-03 08:12:42 
Re: Example of the optimiser recognising a pattern
vippstar@[EMAIL PROTECTED  2008-05-03 07:16:16 
Re: Example of the optimiser recognising a pattern
Andrey Tarasevich <and  2008-05-03 09:45:25 
Re: Example of the optimiser recognising a pattern
vippstar@[EMAIL PROTECTED  2008-05-03 09:48:17 
Re: Example of the optimiser recognising a pattern
Andrey Tarasevich <and  2008-05-03 10:09:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:11:05 CDT 2008.