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

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

Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-b


From: Bernard Fouché
Subject: Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?
Date: Fri, 04 Nov 2005 17:28:25 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Vincent Trouilliez wrote:

Now your problem with 'address & 0x00040000' is a real one: avr-gcc is not yet very good with 32 bits operators

Well, this way we have nice things to be looking forward to, for
upcoming releases of gcc.... :-)

(BTW what version of avr-gcc do you use?).

I compiled 3.4.3 ... does 3.4.4 or 4.0 do a better job at it ?
With gcc-3.4.4 and -Os, the compiler loads 4 registers with the 32 bits value (address) and then use 'sbrs <register>,2' to perform the test. Hence it is very fast. It would be faster if it needs only one register to test however. I did not test with gcc-4.x

Well, as we saw earlier today:

        uint8_t temp;

        temp = (address >> 16) & 0xFF;
        if (temp & 0x04)

works perfectly, much simpler and cleaner than all the union stuff ! :o)
It's still dirty: one do not understand why there is such a mess unless it's documented. And optimization is again compiler dependent: use of 'sbrs' is probably quicker...

I am not sure if it's anymore portable (does the >> operator shift left
in systems where MSB is stored first ?) but my program won't ever be
Yes '>>' will work the same everywhere otherwise portability would be a nightmare.


 Bernard




reply via email to

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