<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 25 May 2018 at 11:29, JF Bastien via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div>Hi atomic fans đ¤âď¸đ¤ (and non-fans I guess),</div><div><br></div><div>C++17 adds support for hardware destructive / constructive interference size constexpr values.</div><ul><li>cppreference: <a href="https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size" target="_blank">https://en.<wbr>cppreference.com/w/cpp/thread/<wbr>hardware_destructive_<wbr>interference_size</a></li><li>Paper with motivation: <a href="http://wg21.link/P0154" target="_blank">http://wg21.link/<wbr>P0154</a></li></ul><div>I volunteer to implement the necessary bits to support this in clang and libc++, and to give them proper values for current ARM and x86 processors. Iâve discussed this plan with other libc++ folks as well as libstdc++ / GCC folks, and we plan to implement the same builtins in both toolchains as well as adopt the same constexpr values wherever possible to keep ABIs compatible.</div><div><br></div><div>Under this plan, ARM and x86 will properly expose the new values in libc++, and other targets will automagically expose these values in C++ when theyâre updated with target-specific values in their target tablegen file. After a while targets that havenât settled on values will fail that one libc++ C++17 conformance test (for now the test will only check targets which expose the builtin).</div><div><br></div><div>FWIW MSVC already exposes this, but since they support fewer targets they decided on what everyone knows the right value is to expose: 64B. Weâre not so fortunate, so bear with me as I propose a plan:</div><div><br></div><div><br></div><div><div><b>1. Standard library support</b></div><div><br></div><div>Add the following code to header <font face="Courier New"><new></font>:</div><div><br></div><div><font face="Courier New">#if (</font><span style="font-family:"Courier New"">__cplusplus >= 201703L</span><span style="font-family:"Courier New"">) && __has_builtin(__builtin_<wbr>hardware_destructive_<wbr>interference_size) && __has_builtin(__builtin_<wbr>hardware_constructive_<wbr>interference_size)</span></div><font face="Courier New">inline constexpr std::size_t hardware_destructive_<wbr>interference_size = __builtin_hardware_<wbr>destructive_interference_size(<wbr>);<br>inline constexpr std::size_t hardware_constructive_<wbr>interference_size = __builtin_hardware_<wbr>constructive_interference_<wbr>size();</font><div><font face="Courier New">#endif</font></div><div><br></div><div>Add corresponding tests which ensure that both values are at least <font face="Courier New">alignof(std::max_align_<wbr>t)</font>, and are constexpr. Conditionalize these tests on the same __has_builtin test for now. File a bug and leave a FIXME to move the test to just <font face="Courier New">#if __cplusplus >= 201703L</font> once targets have adopted this. libc++ will keep the __has_builtin test so that itâll compile just fine even if the builtin insât defined, it just wonât expose the values (so user code will only fail if they try to use these values).</div></div></div></blockquote><div><br></div><div>Why do you propose modeling these as builtin functions rather than as preprocessor defines? The latter is how we model every other similar property.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><div><b>2. Compiler support</b></div><div><br></div><div><ol class="m_-8653786450383193184MailOutline"><li>Teach the target infrastructure that hardware interference size is something they can specify (in tablegen files somewhere).</li><li>Allow overriding the value in sub-targets using -march or -mcpu (the sub-target defines the numeric value, and the user gets the overriden one by using -march or -mcpu).</li><li>Allow overriding the value (or defining, if the target doesnât already) on the command line using flags -mhardware-destructive-<wbr>interference-size and -mhardware-constructive-<wbr>interference-size. Initially I thought weâd go with -mattr, but those donât really allow values being passed.</li><li>In clang, if these properties are set, expose the builtin. Donât expose a builtin if the value is not set by the target or on the command-line, such that the STL wonât expose a random value. Iâll expose them even if weâre in pre-C++17 mode, because theyâre builtins and libc++ only exposes the constexpr value if weâre in C++17 or later.</li><li>For generic le32 / be32 ARM targets expose constructive / destructive as 64B.</li><li>For generic le64 / be64 ARM targets expose constructive as 64B and destructive as 128B.</li><li>For generic x86 expose constructive / destructive as 64B.</li><li>Honor existing sub-target preferences (AFAICT x86 doesnât have any, ARM has some in AArch64Subtarget::<wbr>initializeProperties). These override the generic ones above.</li><li>Leave other targets as-is for now, since I canât test them and I donât know what the appropriate values would be. Hopefully this RFC will elicit feedback as to what the appropriate values are.</li></ol><div><br></div><div><br></div><div>What do yâall think?</div><div><br></div><div>Thanks,</div><div><br></div><div>JF</div></div></div><div><br></div></div><br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>