<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Optimizing for Loops: Reverse Loops</title>
	<atom:link href="http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Fri, 30 Jul 2010 09:05:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Robert</title>
		<link>http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/comment-page-1/#comment-33158</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Mon, 12 Apr 2010 09:31:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/#comment-33158</guid>
		<description>seems that web page removes a - in the text.. 

I did meant minus minus &#039;i&#039;
---i
i---</description>
		<content:encoded><![CDATA[<p>seems that web page removes a &#8211; in the text.. </p>
<p>I did meant minus minus &#8216;i&#8217;<br />
&#8212;i<br />
i&#8212;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert</title>
		<link>http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/comment-page-1/#comment-33157</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Mon, 12 Apr 2010 09:30:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/#comment-33157</guid>
		<description>I noticed this niffy for loop and checked assemble compilation for it. I must say 

// is still fastest with no cmp done. due to --i order of index there will be more clear how the for loop works

for(int i=x-1; i&gt;=0; --i)  
{
   printf()  //causes a call.. 
}
x = 5 =&gt; loop 4,3,2,1,0 
in the case of 
for(i=x; i--; ) 
{
   printf()   //casues a call! but will cause the i to break and result in a cmp/test due to its order and thus not being the fastest allternative.
}

x = 5 =&gt; loop 4,3,2,1,0 

looks good in code though... 
i-- =&gt; cmp i and then dec... 
--i =&gt; dec and cmp in this case branch directly due to zero flag is set default.  hence one instr less..</description>
		<content:encoded><![CDATA[<p>I noticed this niffy for loop and checked assemble compilation for it. I must say </p>
<p>// is still fastest with no cmp done. due to &#8211;i order of index there will be more clear how the for loop works</p>
<p>for(int i=x-1; i&gt;=0; &#8211;i)<br />
{<br />
   printf()  //causes a call..<br />
}<br />
x = 5 =&gt; loop 4,3,2,1,0<br />
in the case of<br />
for(i=x; i&#8211;; )<br />
{<br />
   printf()   //casues a call! but will cause the i to break and result in a cmp/test due to its order and thus not being the fastest allternative.<br />
}</p>
<p>x = 5 =&gt; loop 4,3,2,1,0 </p>
<p>looks good in code though&#8230;<br />
i&#8211; =&gt; cmp i and then dec&#8230;<br />
&#8211;i =&gt; dec and cmp in this case branch directly due to zero flag is set default.  hence one instr less..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jessie Delpino</title>
		<link>http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/comment-page-1/#comment-28821</link>
		<dc:creator>Jessie Delpino</dc:creator>
		<pubDate>Sat, 13 Feb 2010 14:44:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/#comment-28821</guid>
		<description>Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is enormously helpful and beneficial to your readers.</description>
		<content:encoded><![CDATA[<p>Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is enormously helpful and beneficial to your readers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/comment-page-1/#comment-972</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Sun, 16 Dec 2007 16:05:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/#comment-972</guid>
		<description>The basic idea behind it which also appears when compiling without the optimization (optimization greatly depends on the compiler) is that x86 based CPUs have the zero-flag in their ALU. For every arithmetic operation this zerfo-flag is check so by changing the order of the loop we can utilize this zero-flag to omit additional comparison operation for each loop. This should work like the loop with CX in assembly.</description>
		<content:encoded><![CDATA[<p>The basic idea behind it which also appears when compiling without the optimization (optimization greatly depends on the compiler) is that x86 based CPUs have the zero-flag in their ALU. For every arithmetic operation this zerfo-flag is check so by changing the order of the loop we can utilize this zero-flag to omit additional comparison operation for each loop. This should work like the loop with CX in assembly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyku</title>
		<link>http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/comment-page-1/#comment-970</link>
		<dc:creator>Kyku</dc:creator>
		<pubDate>Sun, 16 Dec 2007 12:39:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/#comment-970</guid>
		<description>I don&#039;t see any loops generated when your program is compiled the with -O2. So the the compiler must be smart enough to calculate the final result.
You&#039;d better move the value of loop limit out of compiler&#039;s visibility (get it from argv, for example). What&#039;s more if I put the second loop first, it&#039;s still slower, so your benchmark methodology seems wrong.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t see any loops generated when your program is compiled the with -O2. So the the compiler must be smart enough to calculate the final result.<br />
You&#8217;d better move the value of loop limit out of compiler&#8217;s visibility (get it from argv, for example). What&#8217;s more if I put the second loop first, it&#8217;s still slower, so your benchmark methodology seems wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/comment-page-1/#comment-402</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Wed, 07 Nov 2007 18:05:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/#comment-402</guid>
		<description>You are right, it should be &lt;code&gt;i--&lt;/code&gt;, I fixed the typo. 
Thanks for pointing it out.</description>
		<content:encoded><![CDATA[<p>You are right, it should be <code>i--</code>, I fixed the typo.<br />
Thanks for pointing it out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan E</title>
		<link>http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/comment-page-1/#comment-396</link>
		<dc:creator>Bryan E</dc:creator>
		<pubDate>Wed, 07 Nov 2007 15:49:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/11/07/optimizing-for-loops-reverse-loops/#comment-396</guid>
		<description>Should be &quot;i--&quot; in the second loop....</description>
		<content:encoded><![CDATA[<p>Should be &#8220;i&#8211;&#8221; in the second loop&#8230;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.392 seconds -->
