[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] optimization and interrupt

From: Jörg Krein
Subject: [avr-gcc-list] optimization and interrupt
Date: Wed, 9 Mar 2005 16:43:33 +0100

avr-gcc behaves strange when optimizing interrupt code.
In my interrupt routine I compare a variable against two constants.
I added the code at the end of this posting.
After compiling I found only one comparison (113) in the assembler code:

movw r24,r20          
sts (lastcapt)+1,r19  
sts lastcapt,r18      
subi r24,lo8(-(-113)) 
sbci r25,hi8(-(-113)) 
sbiw r24,24           
brsh .L1              

After changing optimization level to 0 i got:

std Y+3,r24
std Y+4,r25
ldd r24,Y+1
ldd r25,Y+2           
sts (lastcapt)+1,r25  
sts lastcapt,r24      
ldd r24,Y+3           
ldd r25,Y+4           
cpi r24,113           
cpc r25,__zero_reg__  
brlo .L1              
ldd r24,Y+3           
ldd r25,Y+4           
cpi r24,137           

So here a two comparisons (113, 137) as expected.
It helps to declare diffcapt to volatile but that doesn't
make sense to me as it is only used in the interrupt
I hope someone has a logical answer, let me believe
in gcc again.

Regards, Joerg

volatile uint16_t       lastcapt;

        uint16_t actcapt;
        uint16_t diffcapt;

        actcapt = ICR1;

        diffcapt = actcapt - lastcapt;
        lastcapt = actcapt;

        if( (diffcapt > 112)  &&  (diffcapt < 137) )

reply via email to

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