Re: [avr-gcc-list] Problem with delay loop

2007-10-03 Thread Paulo Marques
Dave Hansen wrote: [...] I don't remember the code. Was the function declared static? If not, the compiler must generate at least the ret since functions external to the file could potentially call it as well. If the function was static, the code for it (and the calls to it) could indeed be

Re: [avr-gcc-list] Problem with delay loop

2007-10-03 Thread David Brown
Royce Pereira wrote: Hi, On Mon, 01 Oct 2007 13:02:32 +0530, David Brown <[EMAIL PROTECTED]> wrote: Royce Pereira wrote: So I have to write more 'C' code :) to get the same stuff done, in the 'new & smarter' compiler! Interesting. Doesn't seem right, some how. Regards, --Royce. It might

Re: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread Royce Pereira
Hi, David, On Wed, 03 Oct 2007 02:24:16 +0530, David Kelly <[EMAIL PROTECTED]> wrote: > So? Why did *you* change compilers if the old one did what you wanted? > If it doesn't do what you want then its your choice whether to change > your code to conform or to revert to the compiler that did what

Re: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread David Kelly
On Wed, Oct 03, 2007 at 12:23:46AM +0530, Royce Pereira wrote: > > Why then was the empty 'ret' function retained? > I would think such a case would be the prime candidate for > optimisation. The compiler should eliminate such a funtion, as well > as all calls to that function. That would really

RE: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread Dave Hansen
> From: [EMAIL PROTECTED] > > Hi, > > On Mon, 01 Oct 2007 13:02:32 +0530, David Brown <[EMAIL PROTECTED]> wrote: > > Royce Pereira wrote: > >> > >> So I have to write more 'C' code :) to get the same stuff done, in > >> the 'new & smarter' compiler! Interesting. > >> > >> Doesn't seem right,

Re: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread Royce Pereira
Hi, On Mon, 01 Oct 2007 13:02:32 +0530, David Brown <[EMAIL PROTECTED]> wrote: > Royce Pereira wrote: >> >> So I have to write more 'C' code :) to get the same stuff done, in >> the 'new & smarter' compiler! Interesting. >> >> Doesn't seem right, some how. >> >> Regards, --Royce. > > It might

RE: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread John Regehr
> Ah, ok then. In practice, I have never needed to use setjmp/longjmp, so I > have a tendency to forget about these routines. We should all be so lucky :). John Regehr ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailm

RE: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread Eric Weddington
> -Original Message- > From: > [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > org] On Behalf Of Graham Davies > Sent: Monday, October 01, 2007 6:56 PM > To: 'AVR-GCC-LIST' > Subject: Re: [avr-gcc-list] Problem with delay loop > > First point sec

RE: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread Eric Weddington
> -Original Message- > From: > [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > org] On Behalf Of David Brown > Sent: Tuesday, October 02, 2007 2:48 AM > To: 'AVR-GCC-LIST' > Subject: Re: [avr-gcc-list] Problem with delay loop > > Graham

RE: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread Eric Weddington
> -Original Message- > From: John Regehr [mailto:[EMAIL PROTECTED] > Sent: Monday, October 01, 2007 10:59 PM > To: Eric Weddington > Cc: 'Paulo Marques'; 'David Brown'; 'AVR-GCC' > Subject: RE: [avr-gcc-list] Problem with delay loop >

Re: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread David Brown
Graham Davies wrote: Eric Weddington wrote: ... We were discussing the possibility of the compiler being smarter about 'volatile' and local automatic variables. I would definitely say that if the local variable's address is taken, then all bets are off. Second point first. If the address of a

Re: [avr-gcc-list] Problem with delay loop

2007-10-02 Thread David Brown
Paulo Marques wrote: David Brown wrote: Paulo Marques wrote: David Brown wrote: [...] it could perhaps reason that since there is no way for anything outside the program to find out where the local volatile variable resides, there is no way for anything else to influence or use the variable

RE: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread John Regehr
> However, David brings up a good point. A local variable is put on the stack, > generally not the place for hardware to modify the variable. And generally, > other parts of the program (such as ISRs) don't have access to the specific > location of the variable on the stack. Both hardware and ISRs

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread Bob Paddock
On Monday 01 October 2007 09:48:23 am Eric Weddington wrote: > Its an interesting question. I'm not sure what the answer is. Perhaps a > language lawyer on comp.lang.c could explain the reasoning behind the > current standard. http://thread.gmane.org/gmane.linux.kernel/523210 for the Linux view o

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread Graham Davies
Eric Weddington wrote: ... We were discussing the possibility of the compiler being smarter about 'volatile' and local automatic variables. I would definitely say that if the local variable's address is taken, then all bets are off. Second point first. If the address of a variable is taken the

RE: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread Eric Weddington
> -Original Message- > From: Preston Wilson [mailto:[EMAIL PROTECTED] > Sent: Monday, October 01, 2007 8:13 AM > To: Eric Weddington; 'Paulo Marques'; 'David Brown' > Cc: AVR-GCC-LIST > Subject: Re: [avr-gcc-list] Problem with delay loop > >

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread Paulo Marques
David Brown wrote: Paulo Marques wrote: David Brown wrote: [...] it could perhaps reason that since there is no way for anything outside the program to find out where the local volatile variable resides, there is no way for anything else to influence or use the variable, and therefore the "v

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread Preston Wilson
"Eric Weddington" wrote: > ... > I agree with the statement above that "'volatile' is precisely to warn the > compiler that it should not 'reason' anything about [the] variable". > However, David brings up a good point. A local variable is put on the stack, > generally not the place for hardware

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread David Brown
Paulo Marques wrote: David Brown wrote: [...] it could perhaps reason that since there is no way for anything outside the program to find out where the local volatile variable resides, there is no way for anything else to influence or use the variable, and therefore the "volatile" qualifier c

RE: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread Eric Weddington
> -Original Message- > From: > [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > org] On Behalf Of Paulo Marques > Sent: Monday, October 01, 2007 7:35 AM > To: David Brown > Cc: 'AVR-GCC' > Subject: Re: [avr-gcc-list] Problem with delay loop > >

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread Paulo Marques
David Brown wrote: [...] it could perhaps reason that since there is no way for anything outside the program to find out where the local volatile variable resides, there is no way for anything else to influence or use the variable, and therefore the "volatile" qualifier can be ignored. This

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread David Brown
Graham Davies wrote: David Brown wrote (in part): "... since the local variable is volatile, it has to be put on the stack." I don't see how that follows (if it is declared automatic and is of local scope). Graham. It would be more correct to say that since the local variable is volatil

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread Graham Davies
David Brown wrote (in part): "... since the local variable is volatile, it has to be put on the stack." I don't see how that follows (if it is declared automatic and is of local scope). Graham. ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.

Re: [avr-gcc-list] Problem with delay loop

2007-10-01 Thread David Brown
There are good reasons for much of the stuff produced by the use of "volatile" - since the local variable is volatile, it has to be put on the stack. Generating a stack frame on the AVR needs a bit of messing around in the prologue and epilogue, including turning off interrupts while modifyi

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread David Kelly
On Sep 28, 2007, at 8:58 PM, Graham Davies wrote: David Kelly wrote: ... because it was volatile it *had* to be fetched and stored each time. Oh boy. That's a really interesting statement (to me anyway, but I have a volatile fetish). You're saying that having chosen to put the variable

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Graham Davies
David Kelly wrote: ... because it was volatile it *had* to be fetched and stored each time. Oh boy. That's a really interesting statement (to me anyway, but I have a volatile fetish). You're saying that having chosen to put the variable in memory, the compiler is obliged to fetch it prior t

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread David Kelly
On Fri, Sep 28, 2007 at 11:26:43PM +0530, Royce Pereira wrote: > Hi all, > > OK fine I agree. > > we have to use 'volatile' and all. > > But why must it generate such horrid code... There are those here who would tell you that any calibrated delay loop is horrible code. The stack has to be pro

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Royce Pereira
Hi all, OK fine I agree. we have to use 'volatile' and all. But why must it generate such horrid code... (I reproduce the comparison again below to get the *real* issue into focus) The compiler output with the 'correct' code ('volatile' used): //-

RE: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Dave Hansen
> Date: Fri, 28 Sep 2007 14:21:38 +0530> To: [EMAIL PROTECTED]> Subject: Re: > [avr-gcc-list] Problem with delay loop> From: [EMAIL PROTECTED]> CC: > AVR-GCC-list@nongnu.org> > Hi,> > On Fri, 28 Sep 2007 13:42:18 +0530, Klaus > Rudolph <[EMAIL PR

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread David Kelly
On Fri, Sep 28, 2007 at 09:05:40AM -0500, David Kelly wrote: > > For finer delays don't forget the OCR functions on the timers. Is pretty > easy to write and create very accurate delays with: > > void delay( uint8_t delay ); > { > OCR2A = TCNT2 + delay; > TIFR2 = (1< > // wait

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread David Kelly
On Fri, Sep 28, 2007 at 01:29:19PM +0530, Royce Pereira wrote: > Hi all, > > In the latest WinAVR (avr-gcc (GCC) 4.1.2 (WinAVR 20070525) I found this. > > Check this out: > //== > void delay(unsigned del_cnt) > { >while(del_cnt--); > >return; > } > //=

RE: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Eric Weddington
> -Original Message- > From: > [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > org] On Behalf Of David Brown > Sent: Friday, September 28, 2007 3:17 AM > To: AVR-GCC > Subject: Re: [avr-gcc-list] Problem with delay loop > > > This is probably in the FAQ

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Klaus Rudolph
I think we are discussing not the solution :-) The compiler optimizes unused code away, that is OK! If we use a volatile, the WRITE ACCESS could not longer be optimized and also a new READ ACCESS before subtraction must! be done. That is what the compiler do, that is also OK! If there is a "loc

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Graham Davies
Royce Pereira wrote: So I have to write more 'C' code :) to get the same stuff done, in the 'new & smarter' compiler! Not more code, just correct code. Have you tried returning the final value of your delay argument from the function? If the compiler optimizes only within the boundaries of

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Royce Pereira
Hi Klaus, On Fri, 28 Sep 2007 14:57:14 +0530, Klaus Rudolph <[EMAIL PROTECTED]> wrote: > Please use optimizer! Something like -O2 -O3 -Os ... as you need! My makefile already has OPT = s > > Simplify your delay loop: > void delay(volatile word cnt) { ... > Already tried that. No change. If it's

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Klaus Rudolph
Please use optimizer! Something like -O2 -O3 -Os ... as you need! Simplify your delay loop: void delay(volatile word cnt) { ... Have fun! Royce Pereira schrieb: Hi, On Fri, 28 Sep 2007 14:47:26 +0530, David Brown <[EMAIL PROTECTED]> wrote: This is probably in the FAQ somewhere - if not, it

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Royce Pereira
Hi, On Fri, 28 Sep 2007 14:47:26 +0530, David Brown <[EMAIL PROTECTED]> wrote: > > This is probably in the FAQ somewhere - if not, it should be! > > The compiler is smart enough to figure out that your delay function does > no useful work - thus the optimiser does not generate any code. This is

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Royce Pereira
Hi, On Fri, 28 Sep 2007 14:47:26 +0530, David Brown <[EMAIL PROTECTED]> wrote: > > This is probably in the FAQ somewhere - if not, it should be! > > The compiler is smart enough to figure out that your delay function does > no useful work - thus the optimiser does not generate any code. This is >

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread David Brown
This is probably in the FAQ somewhere - if not, it should be! The compiler is smart enough to figure out that your delay function does no useful work - thus the optimiser does not generate any code. This is correct compilation - it's your code that is wrong. The difference is that the newer

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Royce Pereira
Hi, On Fri, 28 Sep 2007 13:42:18 +0530, Klaus Rudolph <[EMAIL PROTECTED]> wrote: > The code has been optimized. Well done! > If you need the variable access use 'volatile' > Why does it get optimised? I understand the meaning of 'volatile', but why is it required here ? It is clear that the varia

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Klaus Rudolph
The code has been optimized. Well done! If you need the variable access use 'volatile' Hi all, In the latest WinAVR (avr-gcc (GCC) 4.1.2 (WinAVR 20070525) I found this. Check this out: //== void delay(unsigned del_cnt) { while(del_cnt--); return; } //

Re: [avr-gcc-list] Problem with delay loop

2007-09-28 Thread Wouter van Gulik
Royce Pereira schreef: Hi all, In the latest WinAVR (avr-gcc (GCC) 4.1.2 (WinAVR 20070525) I found this. Check this out: //== void delay(unsigned del_cnt) { while(del_cnt--); return; } //=== Well writing your own delay_loops is n