[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: Ian Caddy
Subject: Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?
Date: Fri, 04 Nov 2005 15:20:28 +0800
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050923 Thunderbird/1.0.7 Mnenhy/

Hi Vince,

All your new code is doing is checking that address is non-zero as it is a logical AND with a non-zero number, which would get optimised out.

I haven't tried this, but it might be better:

unsigned char temp;

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

if(temp & 0x04)
   /* Your code */

This is just off the top of my head...hope it works for you.


Ian Caddy

Vincent Trouilliez wrote:
I replaced the '&' operator with the more appropriate '&&' one.... works
much better... 5 instructions instead of 115 (3 + 6*18 + 4) for the
previous code.
So that's indeed about 20 times faster. Although I still don't get why
it can't just use one single SBRC/S instruction instead of these 4 cp or
cpc instructions... I guess I am still missing something in the bit test

                if (address && 0x00040000)
   24ec:        21 15           cp      r18, r1
   24ee:        31 05           cpc     r19, r1
   24f0:        41 05           cpc     r20, r1
   24f2:        51 05           cpc     r21, r1
   24f4:        11 f0           breq    .+4             ; 0x24fa

Hmmm, '&&' might give much tighter code than '&', but my program no
longer works ! So it's still not the proper way to test a bit then,
dear... :o(((


AVR-GCC-list mailing list

Ian Caddy
Goanna Technologies Pty Ltd
+61 8 9221 1860

reply via email to

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