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: Vincent Trouilliez
Subject: Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?
Date: Sat, 05 Nov 2005 01:09:04 +0100

> Ian is close to how I would have handled it. I use a "union32_t" type  
> a fair bit in my code for no other purpose than to pluck values out  
> of the middle painlessly.
> 
> typedef union union32_t {


Okay, I think I can "see the light" about unions now, thanks to David
Kelly and Bernard who hammered it into my brain ;-) and thanks to the
many other people who suggested unions, both on and off list...
I played with them for an hour and find them so many advantages over
obscure shifts, that I love them now... :-)

Works like a charm and produces the best possible code:

                if (addr.u8.c & 0x04)
    2830:       80 91 83 01     lds     r24, 0x0183
    2834:       82 ff           sbrs    r24, 2
    2836:       02 c0           rjmp    .+4             ; 0x283c

only loads the required byte, and performs a straight forward bit test
directly on it, with this lovely sbrs instruction.


Thanks all for the hammering, you didn't waste your time ;-)


--
Vince





reply via email to

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