[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: Fri, 04 Nov 2005 14:16:10 +0100

> 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 ?

> To solve such speed problems, you have to tell the compiler that you 
> want to perform just a 8 bit operation. So use something like:
> ----
> union {
>              uint32_t my_ulong;;
>              struct {
>                          uint8_t a;
>                          uint8_t b;
>                          uint8_t c;
>                          uint8_t d;
>                        } my_bytes;
>           } value;
> value.my_ulong=address;
> if(value.my_bytes.c & 0x40)
> ----
> This is very dirty:
> Now it solves your problem today, so it's up to you to decide to use it 
> or not.
>   Bernard

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)
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
ported, it's only a prototype/one-off for my personal use... and
although I do intend to "upgrade" it in the coming years, with a
graphical LCD module instead of a text module, and some basic data
processing and graphing functionality, I think/guess AVR chips should
still be up to the job, when clocked at 16MHz. 


reply via email to

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