[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] optimization and interrupt
From: |
Keith Gudger |
Subject: |
Re: [avr-gcc-list] optimization and interrupt |
Date: |
Wed, 9 Mar 2005 08:33:13 -0800 (PST) |
I have to say that the optimizer is brilliant! It subtracts 113 from the
value, then subtracts 24 (113 + 24 = 137), and looks for the carry flag.
Should work, no?
Keith
On Wed, 9 Mar 2005, [iso-8859-1] Jörg Krein wrote:
> Hi,
> 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;
>
> SIGNAL( SIG_INPUT_CAPTURE1 )
> {
> uint16_t actcapt;
> uint16_t diffcapt;
>
> actcapt = ICR1;
>
> diffcapt = actcapt - lastcapt;
> lastcapt = actcapt;
>
> if( (diffcapt > 112) && (diffcapt < 137) )
> {...}
> }
>
>
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>