- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Why don't the For Loops cause a delay?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-25-2012 04:27 PM
Seems like I should see some sort of noticible delay but it zips through this code like the for loops aren't even there...
int main()
{
init_platform();
print("...Hello World...\n\r\n");
int i, j, tmp;
print ("Start Delay\r\n");
for (i=0; i<1000000000; i++) {
tmp=i+1;
for (j=0; j<1000000000; j++) {
tmp=j+1;
}
}
xil_printf ("Done w/Delay - i=(%d) , j=(%d) , tmp=((%d))\r\n\n", i, j, tmp);
print("!!! Goodbye World !!!\n\r");
cleanup_platform();
return 0;
}
Output:
...Hello World...
Start Delay
Done w/Delay - i=(1000000000) , j=(1000000000) , tmp=((1000000000))
!!! Goodbye World !!!
Solved! Go to Solution.
Re: Why don't the For Loops cause a delay?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-25-2012 06:15 PM
Looks like optimization works :smileyhappy:
There may be some other optimization settings available that won't cut out
the loops. Otherwise you could use a variable in external memory instead of tmp
to make sure the loop needs to execute every iteration. I would expect this
loop to take a very long time indeed...
-- Gabor
Re: Why don't the For Loops cause a delay?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-25-2012 06:26 PM
Thanks Gabor, that's interesting! When you say external memory what do you mean? I moved tmp outside the main () { code } to make it a global variable but it still behaves the same. Is it easy to turn off optimization?
Re: Why don't the For Loops cause a delay?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-25-2012 07:54 PM
Turned optimization off and it now delays as expected. Still curious what's meant by external memory. Explanation would be most appreciated.
Regards,
Bob
Re: Why don't the For Loops cause a delay?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-25-2012 09:25 PM
bv wrote:
Thanks Gabor, that's interesting! When you say external memory what do you mean? I moved tmp outside the main () { code } to make it a global variable but it still behaves the same. Is it easy to turn off optimization?
"External memory" as opposed to a register. Most counter variables get put into registers for immediate access. Putting it in the memory space occupied by your SDRAM may force the tools to not optimize the access.
----------------------------------------------------------------
Yes, I do this for a living.
Re: Why don't the For Loops cause a delay?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-26-2012 05:05 AM
Doesn't declaring a variable cause, esp outside the subroutine, force this?
Re: Why don't the For Loops cause a delay?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-26-2012 05:46 AM
bv wrote:
Doesn't declaring a variable cause, esp outside the subroutine, force this?
That really depends on the optimizer. Global optimization allows the compiler to
assume that even global variables do not have side-effects on write as long as
they don't go off-chip (outside the MicroBlaze and its attached BRAM).
It is possible that declaring your tmp variable "volatile" would prevent the loop
from being optimized out.
-- Gabor











