<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Copy and modify in Intel® ISA Extensions</title>
    <link>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825920#M1598</link>
    <description>With the brand &lt;A href="http://software.intel.com/file/36945"&gt;new Haswell instructions&lt;/A&gt; like ANDN, BEXTR, RORX, SARX, SHLX, SHRX the mov command can be eliminated for some special cases like the one I mentioned, although in my case the variant of SHRX with constant shift is missing.&lt;BR /&gt;The commands effectively work like &lt;A href="http://software.intel.com/en-us/forums/showthread.php?t=81540&amp;amp;o=a&amp;amp;s=lr"&gt;assignment macro-op fusion&lt;/A&gt;.&lt;BR /&gt;In the meantime the compiler's behavior should be seen as an optimizer bug...</description>
    <pubDate>Sun, 12 Jun 2011 12:29:58 GMT</pubDate>
    <dc:creator>sirrida</dc:creator>
    <dc:date>2011-06-12T12:29:58Z</dc:date>
    <item>
      <title>Copy and modify</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825917#M1595</link>
      <description>When I compile the following C function containing some variants of x ^= x &amp;gt;&amp;gt; n:&lt;BR /&gt;&lt;BR /&gt;===&amp;gt;&lt;BR /&gt;typedef unsigned int t; // or other integer types such as char or int&lt;BR /&gt;t test(t x)&lt;BR /&gt;{&lt;BR /&gt; t x1;&lt;BR /&gt;&lt;BR /&gt; x = x ^ (x &amp;gt;&amp;gt; 1);&lt;BR /&gt;&lt;BR /&gt; x = (x &amp;gt;&amp;gt; 2) ^ x;&lt;BR /&gt;&lt;BR /&gt; x ^= x &amp;gt;&amp;gt; 3;&lt;BR /&gt;&lt;BR /&gt; x1 = x;&lt;BR /&gt; x = x &amp;gt;&amp;gt; 4;&lt;BR /&gt; x = x ^ x1;&lt;BR /&gt;&lt;BR /&gt; x1 = x;&lt;BR /&gt; x = x &amp;gt;&amp;gt; 5;&lt;BR /&gt; x = x1 ^ x;&lt;BR /&gt;&lt;BR /&gt; x1 = x;&lt;BR /&gt; x &amp;gt;&amp;gt;= 6;&lt;BR /&gt; x ^= x1;&lt;BR /&gt;&lt;BR /&gt; return x;&lt;BR /&gt;}&lt;BR /&gt;&amp;lt;===&lt;BR /&gt;&lt;BR /&gt;with maximum optimization most C-compilers generate code for *all* variants of x ^= x &amp;gt;&amp;gt; n such as (registers may vary)&lt;BR /&gt;&lt;BR /&gt;mov edx,eax // make a copy of eax&lt;BR /&gt;shr edx,5 // modify the copy&lt;BR /&gt;xor eax,edx&lt;BR /&gt;&lt;BR /&gt;These are 3 dependent statements whereas my preferred variant is&lt;BR /&gt;&lt;BR /&gt;mov edx,eax // make a copy of eax&lt;BR /&gt;shr eax,5 // modify original register&lt;BR /&gt;xor eax,edx&lt;BR /&gt;&lt;BR /&gt;where the mov and the shr command easily can be processed simultaneously.&lt;BR /&gt;I have tested GCC, AMD's C compiler, MS-C, and Intel-C with the same result.&lt;BR /&gt;&lt;BR /&gt;A speed test revealed that my variant only costs about 2/3 of the time on Intel Atom N450 and 3/4 of the time on Intel i7. I'm quite sure that other processors behave similarly.&lt;BR /&gt;&lt;BR /&gt;Code like this occurs quite often in a program. In many cases the compiler can avoid modifying a copy. It might happen that the association of registers to variables are exchanged by such optimization.&lt;BR /&gt;This trick is not new ... but why is it not applied? Have I missed something?&lt;BR /&gt;&lt;BR /&gt;BTW: My similar inquiry in the GCC forum has not been commented on for about 2 months now, see &lt;A href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48064" target="_blank"&gt;http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48064&lt;/A&gt;</description>
      <pubDate>Tue, 10 May 2011 22:59:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825917#M1595</guid>
      <dc:creator>sirrida</dc:creator>
      <dc:date>2011-05-10T22:59:39Z</dc:date>
    </item>
    <item>
      <title>Copy and modify</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825918#M1596</link>
      <description>I noticed the same thing in my &lt;A href="http://software.intel.com/en-us/forums/showthread.php?t=81540&amp;amp;o=a&amp;amp;s=lr"&gt;assignment macro-op fusion&lt;/A&gt; research. Ironically your suggested software-level transformation would make my hardware-level optimization uneffective. Dealing with this at the hardware level potentially improves performance/Watt beyond what can be achieved through reordering the instructions.&lt;BR /&gt;&lt;BR /&gt;Obviously compilers should be capable of generating either code though. You may want to contact the LLVM team about this (&lt;A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"&gt;http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev&lt;/A&gt;). They won't leave it unanswered for two months...&lt;SPAN style="font-family: Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Good luck!</description>
      <pubDate>Wed, 11 May 2011 11:09:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825918#M1596</guid>
      <dc:creator>capens__nicolas</dc:creator>
      <dc:date>2011-05-11T11:09:38Z</dc:date>
    </item>
    <item>
      <title>Copy and modify</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825919#M1597</link>
      <description>Thank you for your reply!&lt;BR /&gt;&lt;BR /&gt;Macro op fusion needs some magic in the CPU and I would have bet that such a kind of optimization was state of the art for years but my benchmarks have told me otherwise...&lt;BR /&gt;&lt;BR /&gt;Since a compiler should optimize for speed and size, a faster piece of code with equal size should always be preferred - strangely in this fairly simple case at least the mentioned compilers don't do it!&lt;BR /&gt;&lt;BR /&gt;I'm not sure which solution is more energy preserving: Macro op fusion or superscalar execution of a mov command and another command such as shr.&lt;BR /&gt;For the cases where copy and modify is unavoidable, macro op fusion for sure is a good way to get it faster. Effectively mov commands would cost no time. Unfortunately this costs some die space and will only be applicable for some cases, i.e. is probably not as versatile as superscalar execution.&lt;BR /&gt;&lt;BR /&gt;My first experience in AVX programming told me that most mov commands (movdqu, movdqa, movaps and the like) can be be circumvented by clever usage of the new result register and the abolition of the dreadful alignment restrictions. This yields to about 10% less code. Unfortunately I had no access to a real AVX machine yet.</description>
      <pubDate>Wed, 11 May 2011 19:10:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825919#M1597</guid>
      <dc:creator>sirrida</dc:creator>
      <dc:date>2011-05-11T19:10:35Z</dc:date>
    </item>
    <item>
      <title>Copy and modify</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825920#M1598</link>
      <description>With the brand &lt;A href="http://software.intel.com/file/36945"&gt;new Haswell instructions&lt;/A&gt; like ANDN, BEXTR, RORX, SARX, SHLX, SHRX the mov command can be eliminated for some special cases like the one I mentioned, although in my case the variant of SHRX with constant shift is missing.&lt;BR /&gt;The commands effectively work like &lt;A href="http://software.intel.com/en-us/forums/showthread.php?t=81540&amp;amp;o=a&amp;amp;s=lr"&gt;assignment macro-op fusion&lt;/A&gt;.&lt;BR /&gt;In the meantime the compiler's behavior should be seen as an optimizer bug...</description>
      <pubDate>Sun, 12 Jun 2011 12:29:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/Copy-and-modify/m-p/825920#M1598</guid>
      <dc:creator>sirrida</dc:creator>
      <dc:date>2011-06-12T12:29:58Z</dc:date>
    </item>
  </channel>
</rss>

