[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-chat] Atmega128, JTAG and ADC
From: |
Larry Barello |
Subject: |
RE: [avr-chat] Atmega128, JTAG and ADC |
Date: |
Sun, 17 Jul 2005 19:34:25 -0700 |
What may be true of a low I/O register might not be for a high one (e.g. >
32 IIRC). CPU registers are handled similarly to low I/O registers. I/O >
32 (64 if memory mapped) cannot use bit tests directly and will reduce to an
in/and/test sequence. I/O > $100 can't even use the in/out instructions and
HAVE to be accessed as SRAM and will show up as lds/and/test sequence.
For all cases, I believe comparing to non-zero or zero will be the most
efficient for all the possibilities.
However it is entirely possible that the compiler "knows" about the ((A &
bit) == bit) construct and always uses the most efficient operation
possible.
There are plenty of constructs that the compiler doesn't catch (like your
obvious one, below!). I find it best to not stress the optimizer if I know
a more efficient (generic) way to do things.
Cheers!
-----Original Message-----
From: Jeff Epler [mailto:address@hidden
Sent: Sunday, July 17, 2005 6:54 PM
To: Larry Barello
Cc: Brian Dean; address@hidden
Subject: Re: [avr-chat] Atmega128, JTAG and ADC
On Sun, Jul 17, 2005 at 04:39:58PM -0700, Larry Barello wrote:
> BTW Testing for zero/non-zero takes less code than comparing to an
explicit
> bit value...
With avr-gcc 3.3.2, -Os, all these variations compile to the same thing,
using an `sbrc' instruction.
/***********************************/
extern void p1(void);
extern void p2(void);
void f1(unsigned char c) {
if((c & 8) != 8) p1(); else p2();
}
void f2(unsigned char c) {
if((c & 8) == 0) p1(); else p2();
}
void f3(unsigned char c) {
if(!(c & 8)) p1(); else p2();
}
/***********************************/
Example disassembly:
0: 83 fd sbrc r24, 3
2: 02 c0 rjmp .+4 ; 0x8
4: 00 d0 rcall p1
6: 08 95 ret
8: 00 d0 rcall p2
a: 08 95 ret
I think the best code would actually be
0: 83 fd sbrc r24, 3
2: 00 d0 rjmp p2
4: 00 d0 rjmp p1
but avr-gcc misses it by a factor of 2. Do newer versions do any better? I
know 3.3.2 is a bit old by now.
Jeff
- Re: [avr-chat] PID Tutorial/ Examples, (continued)
- Re: [avr-chat] PID Tutorial/ Examples, Christopher X. Candreva, 2005/07/15
- Re: [avr-chat] PID Tutorial/ Examples, Royce & Sharal Pereira, 2005/07/16
- Re: [avr-chat] PID Tutorial/ Examples, Richard Urwin, 2005/07/16
- [avr-chat] Atmega128, JTAG and ADC, Larry Barello, 2005/07/17
- RE: [avr-chat] Atmega128, JTAG and ADC, Ben Mann, 2005/07/17
- Re: [avr-chat] Atmega128, JTAG and ADC, Brian Dean, 2005/07/17
- Re: [avr-chat] Atmega128, JTAG and ADC, Richard Urwin, 2005/07/17
- RE: [avr-chat] Atmega128, JTAG and ADC, Larry Barello, 2005/07/17
- Re: [avr-chat] Atmega128, JTAG and ADC, Brian Dean, 2005/07/17
- Re: [avr-chat] Atmega128, JTAG and ADC, Jeff Epler, 2005/07/17
- RE: [avr-chat] Atmega128, JTAG and ADC,
Larry Barello <=
Re: [avr-chat] PID Tutorial/ Examples, Alan Kilian, 2005/07/15
Re: [avr-chat] PID Tutorial/ Examples, Richard Urwin, 2005/07/15
RE: [avr-chat] PID Tutorial/ Examples, Dan Miner, 2005/07/15