<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hmmmm now that I think about this maybe we should be using a totally different set of builtins on clang anyway.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
We currently are doing this:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="color: #d4d4d4; background-color: #1e1e1e; font-family: Consolas, 'Courier New', monospace; font-weight: normal; font-size: 14px; line-height: 19px">
<div><span style="color: #569cd6">#define _Compiler_barrier() _ReadWriteBarrier()</span></div>
<br>
<div><span style="color: #569cd6">#if defined(_M_ARM) </span><span>||</span><span style="color: #569cd6"> defined(_M_ARM64)</span></div>
<div><span style="color: #569cd6">#define _Memory_barrier() __dmb(</span><span style="color: #b5cea8">0xB</span><span style="color: #569cd6">)
</span><span style="color: #6a9955">// inner shared data memory barrier</span></div>
<div><span style="color: #569cd6">#define _Compiler_or_memory_barrier() _Memory_barrier()</span></div>
<br>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_STORE8(_Storage, _Value) __iso_volatile_store8(_Atomic_address_as</span><span><</span><span style="color: #569cd6">char</span><span>></span><span style="color: #569cd6">(_Storage), _Value)</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_STORE16(_Storage, _Value) __iso_volatile_store16(_Atomic_address_as</span><span><</span><span style="color: #569cd6">short</span><span>></span><span style="color: #569cd6">(_Storage), _Value)</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_STORE32(_Storage, _Value) __iso_volatile_store32(_Atomic_address_as</span><span><</span><span style="color: #569cd6">int</span><span>></span><span style="color: #569cd6">(_Storage), _Value)</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_STORE64(_Storage, _Value) __iso_volatile_store64(_Atomic_address_as</span><span><</span><span style="color: #569cd6">long long</span><span>></span><span style="color: #569cd6">(_Storage), _Value)</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_LOAD8(_Storage) __iso_volatile_load8(_Atomic_address_as</span><span><</span><span style="color: #569cd6">const char</span><span>></span><span style="color: #569cd6">(_Storage))</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_LOAD16(_Storage) __iso_volatile_load16(_Atomic_address_as</span><span><</span><span style="color: #569cd6">const short</span><span>></span><span style="color: #569cd6">(_Storage))</span></div>
<br>
<div><span style="color: #569cd6">#elif defined(_M_IX86) </span><span>||</span><span style="color: #569cd6"> defined(_M_X64)</span></div>
<div><span style="color: #6a9955">// x86/x64 hardware only emits memory barriers inside _Interlocked intrinsics</span></div>
<div><span style="color: #569cd6">#define _Compiler_or_memory_barrier() _Compiler_barrier()</span></div>
<br>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_STORE8(_Storage, _Value) (</span><span>*</span><span style="color: #569cd6">_Atomic_address_as</span><span><</span><span style="color: #569cd6">char</span><span>></span><span style="color: #569cd6">(_Storage)
</span><span>=</span><span style="color: #569cd6"> _Value)</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_STORE16(_Storage, _Value) (</span><span>*</span><span style="color: #569cd6">_Atomic_address_as</span><span><</span><span style="color: #569cd6">short</span><span>></span><span style="color: #569cd6">(_Storage)
</span><span>=</span><span style="color: #569cd6"> _Value)</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_STORE32(_Storage, _Value) (</span><span>*</span><span style="color: #569cd6">_Atomic_address_as</span><span><</span><span style="color: #569cd6">long</span><span>></span><span style="color: #569cd6">(_Storage)
</span><span>=</span><span style="color: #569cd6"> _Value)</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_STORE64(_Storage, _Value) (</span><span>*</span><span style="color: #569cd6">_Atomic_address_as</span><span><</span><span style="color: #569cd6">long long</span><span>></span><span style="color: #569cd6">(_Storage)
</span><span>=</span><span style="color: #569cd6"> _Value)</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_LOAD8(_Storage) (</span><span>*</span><span style="color: #569cd6">_Atomic_address_as</span><span><</span><span style="color: #569cd6">const char</span><span>></span><span style="color: #569cd6">(_Storage))</span></div>
<div><span style="color: #569cd6">#define _ISO_VOLATILE_LOAD16(_Storage) (</span><span>*</span><span style="color: #569cd6">_Atomic_address_as</span><span><</span><span style="color: #569cd6">const short</span><span>></span><span style="color: #569cd6">(_Storage))</span></div>
<br>
<div><span style="color: #569cd6">#else</span><span> </span><span style="color: #6a9955">// ^^^ x86/x64 / unsupported hardware vvv</span></div>
<div><span style="color: #569cd6">#error </span><span style="color: #ce9178">Unsupported hardware</span></div>
<div><span style="color: #569cd6">#endif</span><span> </span><span style="color: #6a9955">// hardware</span></div>
</div>
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">...</span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
// in _Atomic_storage<_Ty, 1>:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="color: #d4d4d4; background-color: #1e1e1e; font-family: Consolas, 'Courier New', monospace; font-weight: normal; font-size: 14px; line-height: 19px">
<div><span>    _NODISCARD _Ty load() </span><span style="color: #569cd6">const</span><span> </span><span style="color: #569cd6">noexcept</span><span> {
</span><span style="color: #6a9955">// load with sequential consistency</span></div>
<div><span>        </span><span style="color: #569cd6">char</span><span> _As_bytes
</span><span>=</span><span> _ISO_VOLATILE_LOAD8(_Storage);</span></div>
<div><span>        _Compiler_or_memory_barrier();</span></div>
<div><span>        </span><span style="color: #569cd6">return</span><span> </span><span style="color: #569cd6">reinterpret_cast</span><span><</span><span>_Ty</span><span>&></span><span>(_As_bytes);</span></div>
<div><span>    }</span></div>
</div>
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Billy O'Neal (VC LIBS)<br>
<b>Sent:</b> Thursday, March 28, 2019 02:20 PM<br>
<b>To:</b> Reid Kleckner; JF Bastien<br>
<b>Cc:</b> cfe-dev<br>
<b>Subject:</b> Re: [cfe-dev] FYI, Intel folks might be looking to add the __iso_volatile_Xxx family for MSVC STL <atomic> soon</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
> <span style="font-size:15px; background-color:rgb(255,255,255); display:inline!important">all they do is emit a volatile load</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="font-size:15px; background-color:rgb(255,255,255); display:inline!important"><br>
</span></div>
<div style="color:rgb(0,0,0)"><span style="font-size:15px">If I understand correctly the point of these is to make an ordinary volatile load/store happen on ARM under
<a href="https://docs.microsoft.com/en-us/cpp/build/reference/volatile-volatile-keyword-interpretation?view=vs-2017" title="https://docs.microsoft.com/en-us/cpp/build/reference/volatile-volatile-keyword-interpretation?view=vs-2017">
/volatile:ms</a>. We asked for the intrinsic to also be provided on Intel because it reduces the amount of macro-tastic-ness we need in <atomic>.</span></div>
<div style="color:rgb(0,0,0)"><span style="font-size:15px"><br>
</span></div>
<div style="color:rgb(0,0,0)"><span style="font-size:15px">Billy3</span></div>
<div id="x_appendonsend"></div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Reid Kleckner <rnk@google.com><br>
<b>Sent:</b> Thursday, March 28, 2019 02:18 PM<br>
<b>To:</b> JF Bastien<br>
<b>Cc:</b> Billy O'Neal (VC LIBS); cfe-dev<br>
<b>Subject:</b> Re: [cfe-dev] FYI, Intel folks might be looking to add the __iso_volatile_Xxx family for MSVC STL <atomic> soon</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">On Thu, Mar 28, 2019 at 2:14 PM Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<br>
</div>
<div class="x_x_gmail_quote">
<blockquote class="x_x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">On Thu, Mar 28, 2019 at 1:46 PM JF Bastien <<a href="mailto:jfbastien@apple.com" target="_blank">jfbastien@apple.com</a>> wrote:</div>
<div class="x_x_gmail_quote">
<blockquote class="x_x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div>
<div>
<blockquote type="cite">
<div>On Mar 28, 2019, at 12:02 PM, Billy O'Neal (VC LIBS) <<a href="mailto:bion@microsoft.com" target="_blank">bion@microsoft.com</a>> wrote:</div>
<br class="x_x_gmail-m_2722073922146900827gmail-m_7048915203350462242Apple-interchange-newline">
<div>
<div style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
Update: VS2019 Update 2 is likely to do this; who do I need to prod such that I get to use these unconditionally in our <atomic> ?<span id="x_x_gmail-m_2722073922146900827gmail-m_7048915203350462242🙂" title=":slight_smile:">🙂</span></div>
</div>
</blockquote>
<div><br>
</div>
<div>You want the same feature in clang-cl, so I suggest talking to Reid, sending a patch to clang, and having him review it ;-)</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>I think it's just a matter of moving code from <a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fblob%2Fmaster%2Fclang%2Finclude%2Fclang%2FBasic%2FBuiltinsAArch64.def%23L82&data=02%7C01%7Cbion%40microsoft.com%7C83aeb1e5d31d4b7b3bbd08d6b3c2ec83%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C1%7C636894047106237010&sdata=BYsRUy%2FwIT9OchMsEoez7TIPa9iHTqVPI3bjlv25ztE%3D&reserved=0" originalsrc="https://github.com/llvm/llvm-project/blob/master/clang/include/clang/Basic/BuiltinsAArch64.def#L82" shash="VkE1Yy+iH1m6nis5PFcxfnZ4htHAHLCpFPGpPs3SwBeWJbtfU6/molm4d2m6sKJSHT9wPHmCPrNiWWbg+axMONO2XHFxI3Q0kZtXx5tJ7bCRWE8f5j/IQJAhDmKa/MAsob/wafNJdSNjfRyGQwnZqNomrJWBTbwf5tle6vaOJmM=" target="_blank">
BuiltinsAArch64.def</a> (and ARM) to Builtins.def, and maybe some followon changes.</div>
<div><br>
</div>
<div>The naming for these intrinsics is confusing. It reads as, "do an ISO C++ standard volatile load", but it really means "do an atomic (not volatile) load", but I suppose the time to address that is long gone.</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Huh, maybe I'm the one confused, because all they do is emit a volatile load. What exactly do you want to use these for, then? I'm not sure we've implemented them correctly.</div>
<div> </div>
<blockquote class="x_x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div class="x_x_gmail_quote">
<div>I went ahead and started a patch to make them available.</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>