<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to stop the msvc optimizer from flushing registers?]]></title><description><![CDATA[<p>I am trying to optimize the inner loop of an interpreter, and looking at the generated machine code I notice that the compiler always writes a local variable back to the stack frame after it has been modified, even though the variable is held in the same register throughout the entire loop &amp; its lifetime. Sometimes it randomly loads it from the stack as well, even though it was already in the same register just before, and no control flow is present in between.</p>
<p>The variable is not static/volatile, is not aliased (its address is never taken), and its register is never used for other purposes in the generated code. I have all optimisations on max and even have /Oa on. Using <a href="http://vs.net" rel="nofollow">vs.net</a>.</p>
<p>How do I stop the superfluous flushing/loading from happening?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/42978/how-to-stop-the-msvc-optimizer-from-flushing-registers</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 13:36:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/42978.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Jul 2003 15:44:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to stop the msvc optimizer from flushing registers? on Thu, 17 Jul 2003 15:44:53 GMT]]></title><description><![CDATA[<p>I am trying to optimize the inner loop of an interpreter, and looking at the generated machine code I notice that the compiler always writes a local variable back to the stack frame after it has been modified, even though the variable is held in the same register throughout the entire loop &amp; its lifetime. Sometimes it randomly loads it from the stack as well, even though it was already in the same register just before, and no control flow is present in between.</p>
<p>The variable is not static/volatile, is not aliased (its address is never taken), and its register is never used for other purposes in the generated code. I have all optimisations on max and even have /Oa on. Using <a href="http://vs.net" rel="nofollow">vs.net</a>.</p>
<p>How do I stop the superfluous flushing/loading from happening?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/311558</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/311558</guid><dc:creator><![CDATA[Aardappel]]></dc:creator><pubDate>Thu, 17 Jul 2003 15:44:53 GMT</pubDate></item><item><title><![CDATA[Reply to How to stop the msvc optimizer from flushing registers? on Thu, 17 Jul 2003 20:01:56 GMT]]></title><description><![CDATA[<p>Use the register keyword:</p>
<pre><code class="language-cpp">register int i;
for(i = 0; i &lt; 100; ++i)
{
// ...
}
</code></pre>
<p><a href="http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_the_register_keyword.asp" rel="nofollow">http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_the_register_keyword.asp</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/311706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/311706</guid><dc:creator><![CDATA[tag]]></dc:creator><pubDate>Thu, 17 Jul 2003 20:01:56 GMT</pubDate></item><item><title><![CDATA[Reply to How to stop the msvc optimizer from flushing registers? on Fri, 18 Jul 2003 05:03:02 GMT]]></title><description><![CDATA[<p>Wenn du so tief in der optimierung steckst, und sie zwingend notwendig ist würde ich an dieser Stelle auf die Assemblerprogrammierung wechseln.</p>
<p>Das Register Keyword ist ein Wunsch an den Compiler diese Variable in Registern zu halten. Der Compiler kann entscheiden es zu tun muß es aber nicht.<br />
:p</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/311839</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/311839</guid><dc:creator><![CDATA[PAD]]></dc:creator><pubDate>Fri, 18 Jul 2003 05:03:02 GMT</pubDate></item><item><title><![CDATA[Reply to How to stop the msvc optimizer from flushing registers? on Fri, 18 Jul 2003 07:17:42 GMT]]></title><description><![CDATA[<p>danke fuer die antworten. Aber das register keyword wird von msvc 100%-ig ignoriert. Die interpreter soll halt portabel sein, ich will es deshalb in C++ schreiben das auf wichtiche platformen (wie x86) gut optimiert werden kann. Das is durchaus einfach, nuer in diesen fall nicht. Assembler schreiben das schneller ist als was compiler generieren ist auch nicht mal leicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/311880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/311880</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 18 Jul 2003 07:17:42 GMT</pubDate></item><item><title><![CDATA[Reply to How to stop the msvc optimizer from flushing registers? on Fri, 18 Jul 2003 17:16:24 GMT]]></title><description><![CDATA[<p>Dann nimm den Compiler von Intel, der Optimiert was das Zeug hält!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/312433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/312433</guid><dc:creator><![CDATA[tag]]></dc:creator><pubDate>Fri, 18 Jul 2003 17:16:24 GMT</pubDate></item><item><title><![CDATA[Reply to How to stop the msvc optimizer from flushing registers? on Fri, 18 Jul 2003 17:46:46 GMT]]></title><description><![CDATA[<p>Ehm, inline asm ist die einzige Möglichkeit. register ist schon lange keine Empfehlung mehr wie bspw. inline. Der Compiler weiß in der Regel besser was wann in welches Register gehört.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/312453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/312453</guid><dc:creator><![CDATA[Walli]]></dc:creator><pubDate>Fri, 18 Jul 2003 17:46:46 GMT</pubDate></item></channel></rss>