avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] efficiency of assigning bits (getting OT)


From: E. Weddington
Subject: Re: [avr-gcc-list] efficiency of assigning bits (getting OT)
Date: Mon, 21 Mar 2005 09:53:00 -0700
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

Jim Brain wrote:

Graham Davies wrote:

... There are times when C's integer promotion is a PITA ...


Which is why I personally insist on a full understanding.
I can't argue with that noble goal, but I want to make sure a full understanding of the C language does not become a requirement for participating in this list.

It's not. The list topic is using the GCC compiler for the AVR microprocessor.


I may be the only one on this list who does not have a full grasp of C, so I may speak only for myself.

I don't either.
Have you ever tried to figure out trigraphs? :-P

I just enjoy using the C language to write for such a small and capable microcontroller, and sometimes the code doesn't seem to do what I thought it should in my personal projects using the AVR.

And *that* is the point. If it is not doing what you expect, then that leads to one of two conclusions: The compiler must be buggy, or, your knowledge of the language must be buggy.

The C language was not necssarily designed for use on 8-bit machines. It was designed for machines that were larger. The C language bit operators will promote their operands to an int, which is 16 bits on the AVR. The GCC optimizer is mostly good enough to see that a lot of operations will equate to an 8-bit result and you get efficient code. The optimizer does not always do this however, and sometimes you get weird inefficient code with bit operations. This happens often enough that a FAQ entry was written for the avr-libc user manual that describes this. This is why it is prudent to *typecast* the operands to the size that you want. This gives the compiler more information on how to optimize the statement. This is nothing new. This kind of stuff happens with other compilers as well, but not with all compilers.

Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]