<?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 I think the suggestion is in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936480#M88992</link>
    <description>&lt;P&gt;I think the suggestion is that the compiler special-case comparison of short strings of known same constant length and just do integer compares. That seems like a worthwhile idea to me, as such comparisons are frequently found in Fortran code.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Sep 2013 13:21:56 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2013-09-23T13:21:56Z</dc:date>
    <item>
      <title>Inefficient code for simple string comparison</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936477#M88989</link>
      <description>&lt;P&gt;The following reproducer exposes an inefficiency with string comparisons. The compiler generates a call to &lt;EM&gt;for_cpstr()&lt;/EM&gt; that consumes substantial compute time for a case I have. Tried with versions 11.1 and 13.1 and get the same assembly code. What is that call good for ? The compiler should be able to do much better with such a simple piece of code.&lt;/P&gt;
&lt;P&gt;subroutine scmp(a,b,l, flag)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; character(*), intent(in) :: a&lt;BR /&gt;&amp;nbsp; character(*), intent(in) :: b&lt;BR /&gt;&amp;nbsp; integer, intent(in)&amp;nbsp; :: l&lt;BR /&gt;&amp;nbsp; logical, intent(out) :: flag&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (a(1:l) == b(1:l)) then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag = .true.&lt;BR /&gt;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag = .false.&lt;BR /&gt;&amp;nbsp; end if&lt;/P&gt;
&lt;P&gt;end subroutine scmp&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 12:00:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936477#M88989</guid>
      <dc:creator>mriedman</dc:creator>
      <dc:date>2013-09-23T12:00:58Z</dc:date>
    </item>
    <item>
      <title>for_cpstr()  compares two</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936478#M88990</link>
      <description>&lt;P&gt;for_cpstr()&amp;nbsp; compares two Fortran CHARACTER objects dealing with "strings" of different length and the different relational operators (EQ here). Is this the call itself you complain about (the overhead of the call) or the efficiency of the code implementing for_cpstr() ?&amp;nbsp;I don't see anything, &amp;nbsp;the compiler could do better.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 12:43:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936478#M88990</guid>
      <dc:creator>Heinz_B_Intel</dc:creator>
      <dc:date>2013-09-23T12:43:42Z</dc:date>
    </item>
    <item>
      <title>O.k. I remember that the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936479#M88991</link>
      <description>&lt;P&gt;O.k. I remember that the world of multi-byte-characters and&amp;nbsp;multi-language strings&amp;nbsp;can be&amp;nbsp;rather complex. (Fortran programmers don't do such stuff.)&lt;/P&gt;
&lt;P&gt;In my case the string comparison deals with keywords of&amp;nbsp;less than a dozen plain ASCII characters, so the subroutine call overhead gets significant. It&amp;nbsp;seems like&amp;nbsp;&lt;EM&gt;for_cpstr()&lt;/EM&gt;&amp;nbsp;then calls &lt;EM&gt;intel_memcmp()&lt;/EM&gt; so the overhead is even worse. One workaround I found is to start comparing&amp;nbsp;just the first character and immediately return in case of inequality. That single character operation does not invoke &lt;EM&gt;for_cpstr().&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Specific code generation for equality / inequality&amp;nbsp;would be desired here. I think it could be done with less than&amp;nbsp;10 assembly instructions.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 13:03:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936479#M88991</guid>
      <dc:creator>mriedman</dc:creator>
      <dc:date>2013-09-23T13:03:01Z</dc:date>
    </item>
    <item>
      <title>I think the suggestion is</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936480#M88992</link>
      <description>&lt;P&gt;I think the suggestion is that the compiler special-case comparison of short strings of known same constant length and just do integer compares. That seems like a worthwhile idea to me, as such comparisons are frequently found in Fortran code.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 13:21:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936480#M88992</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-09-23T13:21:56Z</dc:date>
    </item>
    <item>
      <title>yes - in general it might be</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936481#M88993</link>
      <description>&lt;P&gt;yes - in general it might be helpful to have special implementations of short strings. But here the length is not a compile-time constant and intel_memcmp() does the optimizations like returning as soon as the first character pair is different, using 4-byte/8-byte integer compares and even using the vector-extensions.&lt;/P&gt;
&lt;P&gt;the only optimization I see here would be a special version for strings of equal lenght ( saves a very, very few cycles) or in-lining&amp;nbsp; - but in-lining is not free either ( code size increase, additional register pressure).&lt;/P&gt;
&lt;P&gt;It would be interesting to see&amp;nbsp;benchmark data &amp;nbsp;&amp;nbsp;on how many cycles could be gained really.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 13:39:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936481#M88993</guid>
      <dc:creator>Heinz_B_Intel</dc:creator>
      <dc:date>2013-09-23T13:39:57Z</dc:date>
    </item>
    <item>
      <title>See the Oprofile data to show</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936482#M88994</link>
      <description>&lt;P&gt;See the&amp;nbsp;Oprofile&amp;nbsp;data to show the relevance of this issue in the complete program context. The workaround I mentioned cuts 5.7% of total runtime.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Before workaround&lt;BR /&gt;&lt;/STRONG&gt;samples&amp;nbsp; %&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; symbol name&lt;/P&gt;
&lt;P&gt;522549&amp;nbsp;&amp;nbsp; 20.2889&amp;nbsp; m_tdt512_mp_psi_sweep_cycl_sf_&lt;BR /&gt;264716&amp;nbsp;&amp;nbsp; 10.2781&amp;nbsp; afpktr_&lt;BR /&gt;129155&amp;nbsp;&amp;nbsp;&amp;nbsp; 5.0147&amp;nbsp; __svml_floorf4.R&lt;BR /&gt;&amp;nbsp;. . .&lt;BR /&gt;&lt;STRONG&gt;121155&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.7041&amp;nbsp; for_cpstr&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;78103&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3.0325&amp;nbsp; _intel_fast_memcmp&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;After workaround&lt;/STRONG&gt;&lt;BR /&gt;samples&amp;nbsp; %&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; symbol name&lt;/P&gt;
&lt;P&gt;519767&amp;nbsp;&amp;nbsp; 25.7614&amp;nbsp; m_tdt512_mp_psi_sweep_cycl_sf_&lt;BR /&gt;162412&amp;nbsp;&amp;nbsp;&amp;nbsp; 8.0497&amp;nbsp; afpktr_&lt;BR /&gt;128690&amp;nbsp;&amp;nbsp;&amp;nbsp; 6.3783&amp;nbsp; __svml_floorf4.R&lt;BR /&gt;&amp;nbsp;. . .&lt;BR /&gt;&lt;STRONG&gt;21856&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.2935&amp;nbsp; for_cpstr&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;. . .&lt;BR /&gt;&lt;STRONG&gt;11758&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.6959&amp;nbsp; _intel_fast_memcmp&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 13:56:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936482#M88994</guid>
      <dc:creator>mriedman</dc:creator>
      <dc:date>2013-09-23T13:56:45Z</dc:date>
    </item>
    <item>
      <title>Oh, my eyes were not good</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936483#M88995</link>
      <description>&lt;P&gt;Oh, my eyes were not good enough to see that the end position was a variable and not a constant. I agree with Heinz that an optimization here is more difficult.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2013 13:58:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936483#M88995</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-09-23T13:58:11Z</dc:date>
    </item>
    <item>
      <title>In the above case, the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936484#M88996</link>
      <description>&lt;P&gt;In the above case, the segment (1:l) is the same, in this situation (lengths equal and == operator) you could treat the "arrays" as integer(sizeof character), dimension(l). I do not think the optimization check would be hard to perform and impliment. N.B. this may introduce issues with respect to "l" indexing out of bounds.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2013 20:55:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Inefficient-code-for-simple-string-comparison/m-p/936484#M88996</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-09-24T20:55:49Z</dc:date>
    </item>
  </channel>
</rss>

