[Top][All Lists]
[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
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within amulti-byte integer ?, (continued)
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?, Bernard Fouché, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?, Vincent Trouilliez, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?, David Kelly, 2005/11/05
- RE: [avr-gcc-list] How to (efficeiently !!!) test a bit within amulti-byte integer ?, Niklas Lövgren, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within amulti-byte integer ?, Eric Weddington, 2005/11/08
- RE: [avr-gcc-list] How to (efficeiently !!!) test a bit withinamulti-byte integer ?, Niklas Lövgren, 2005/11/09
Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?, David Kelly, 2005/11/04