<?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 TBB library question atomic cmpxchg implementation in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/TBB-library-question-atomic-cmpxchg-implementation/m-p/777164#M211</link>
    <description>Hoi,&lt;BR /&gt;&lt;BR /&gt;guess I figured out what the problem is. Refering to the file &lt;I&gt;linux_intel64.h&lt;/I&gt;,&lt;I&gt; &lt;/I&gt;I think the "q" case (that is the 64bit or 8byte Macro &lt;I&gt;__MACHINE_DECL_ATOMICS(8,int64_t,"q") &lt;/I&gt;is not well defined, as it references a non existing assembler command:&lt;BR /&gt;&lt;BR /&gt;the ordinary &lt;I&gt;cmpxchg &lt;/I&gt;command to my knowledge is restricted to 8, 16 and 32 bit. For 64bit there is the alternative &lt;I&gt;cmpxchg8b&lt;/I&gt; command. This does, however, NOT take two arguments and, as mentioned above, modifies registers, which the ordinary &lt;I&gt;cmpxchg &lt;/I&gt;command does not doe (except for EAX).&lt;BR /&gt;&lt;BR /&gt;I still think this flawed implementation, but lemme know if I am wrong.&lt;BR /&gt;&lt;BR /&gt;Otherwise, consider this thread/ issue as solved.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;G:&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 29 Nov 2010 10:53:26 GMT</pubDate>
    <dc:creator>Andreas_Beschorner</dc:creator>
    <dc:date>2010-11-29T10:53:26Z</dc:date>
    <item>
      <title>TBB library question atomic cmpxchg implementation</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/TBB-library-question-atomic-cmpxchg-implementation/m-p/777162#M209</link>
      <description>Greetings all,&lt;BR /&gt;I have some (minor) problems with the implementation of the above mentioned function in the library. Getting rid of the macro stuff, it reads like this:&lt;BR /&gt;&lt;PRE&gt;[bash]static inline intXX_t cmpXchg(volPtr ptr, intXX_t dest, intXX_t compareTo)
{
    int32_t ans;
    __asm__ __volatile__("lock; cmpxchgBB %0, %1"
    		: "=a"(ans), "=m"(*(volInt32 *)ptr)			/* out */
    		: "0"(compareTo), "q"(dest), "m"(*(volInt32 *)ptr)	/* in */
    		: "memory");					        /* clobber */
    return ans;
}
[/bash]&lt;/PRE&gt; where XX is either 32 or 64 and BB thus l or q, respectively.&lt;BR /&gt;&lt;BR /&gt;My questions:&lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;How can the compiler (g++ 4.4.xxx) tell whether 64bit R-registers (RDX, RAX, ...) or 32bit E-registers (EDX, EAX, ...) are used?&lt;/LI&gt;&lt;LI&gt;cmpxchg8b (or cmpxchgl) potentially writes a result into EDX:EAX (equivalent setting for 16b variant);how will EDX and ECX be set in this implementation? All in all, why not use "b"(dest) instead of "q"(dest)? And: should we not mention "d" in the outlist, also?&lt;/LI&gt;&lt;LI&gt;The assembler command changes the zeroflag, but the cobbler-list does NOT include "cc"- why?&lt;/LI&gt;&lt;/OL&gt;Thanks a lot for help,&lt;BR /&gt;best wishes,&lt;BR /&gt;G.&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Nov 2010 14:38:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/TBB-library-question-atomic-cmpxchg-implementation/m-p/777162#M209</guid>
      <dc:creator>Andreas_Beschorner</dc:creator>
      <dc:date>2010-11-25T14:38:46Z</dc:date>
    </item>
    <item>
      <title>TBB library question atomic cmpxchg implementation</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/TBB-library-question-atomic-cmpxchg-implementation/m-p/777163#M210</link>
      <description>1) Well, after doing some research, the only explanation I can see so far for NOT clobbering EBX, ECD or EDX and ZeroFlag seem to be that they are scratch or volatile registers. However, afaik this does NOT hold for EBX, so this implementation imho in the worst case suffers from undefined behaviour.&lt;BR /&gt;&lt;BR /&gt;2) In Addition, I still have no idea how to tell between R- and E-registers. Some manuals say, that "r" references R-Registers, while "R" as a constraint refers to "E"-registers, but I can not really find any reliable resource or reference.&lt;BR /&gt;&lt;BR /&gt;Thanks again for help,&lt;BR /&gt;G.&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Nov 2010 15:58:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/TBB-library-question-atomic-cmpxchg-implementation/m-p/777163#M210</guid>
      <dc:creator>Andreas_Beschorner</dc:creator>
      <dc:date>2010-11-26T15:58:49Z</dc:date>
    </item>
    <item>
      <title>TBB library question atomic cmpxchg implementation</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/TBB-library-question-atomic-cmpxchg-implementation/m-p/777164#M211</link>
      <description>Hoi,&lt;BR /&gt;&lt;BR /&gt;guess I figured out what the problem is. Refering to the file &lt;I&gt;linux_intel64.h&lt;/I&gt;,&lt;I&gt; &lt;/I&gt;I think the "q" case (that is the 64bit or 8byte Macro &lt;I&gt;__MACHINE_DECL_ATOMICS(8,int64_t,"q") &lt;/I&gt;is not well defined, as it references a non existing assembler command:&lt;BR /&gt;&lt;BR /&gt;the ordinary &lt;I&gt;cmpxchg &lt;/I&gt;command to my knowledge is restricted to 8, 16 and 32 bit. For 64bit there is the alternative &lt;I&gt;cmpxchg8b&lt;/I&gt; command. This does, however, NOT take two arguments and, as mentioned above, modifies registers, which the ordinary &lt;I&gt;cmpxchg &lt;/I&gt;command does not doe (except for EAX).&lt;BR /&gt;&lt;BR /&gt;I still think this flawed implementation, but lemme know if I am wrong.&lt;BR /&gt;&lt;BR /&gt;Otherwise, consider this thread/ issue as solved.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;G:&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Nov 2010 10:53:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/TBB-library-question-atomic-cmpxchg-implementation/m-p/777164#M211</guid>
      <dc:creator>Andreas_Beschorner</dc:creator>
      <dc:date>2010-11-29T10:53:26Z</dc:date>
    </item>
  </channel>
</rss>

