avr-gcc-list
[Top][All Lists]
Advanced

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

RE: [avr-gcc-list] loop deleted using optimization


From: Dave Hansen
Subject: RE: [avr-gcc-list] loop deleted using optimization
Date: Tue, 06 Mar 2007 20:07:45 -0500

From: alee <address@hidden>
Why does avr-gcc delete my empty "for" loops if I compile with optimization on? I am able to preserve the loop if I add a NOP in the loop but that will eat up one clock cycle. Is there a way to preserve the empty loops without adding any NOP clock cycles? Is this a bug? Below is

It's not a bug, it's a feature. GCC realized the loops weren't doing anything, and so optimized them out. To keep them, you have to give GCC a reason to keep them. As you found, adding a nop to the loop body (probably with asm volatile) gave gcc the reason.

Rather than inserting a nop, you could simply make the loop variable volatile. The volatile keyword tells the compler that it should do exactly what you say to the variable, no more, no less, no "as-if."

Or if you really just want a short delay, look at the functions in delay.h.

HTH,
  -=Dave

_________________________________________________________________
The average US Credit Score is 675. The cost to see yours: $0 by Experian. http://www.freecreditreport.com/pm/default.aspx?sc=660600&bcd=EMAILFOOTERAVERAGE





reply via email to

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