<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Book Antiqua";
        panose-1:2 4 6 2 5 3 5 3 3 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma",sans-serif;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma",sans-serif;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Book Antiqua",serif;
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle23
        {mso-style-type:personal-reply;
        font-family:"Book Antiqua",serif;
        color:#943634;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-IE link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>Hi Anastasia,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>My own thoughts on this were to mirror the structure of ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>__builtin_shufflevector</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’, only with true/false instead of element indices.  I just chose OpenCL’s ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>select</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’, because it is the closest construct already supported by CLang/LLVM that came close to what I want, and there was just a possibility this already had some built-in form that I had not discovered (my code search answered my question anyway - thanks also to Elana for your response).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>For example, given an OpenCL ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>select</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ of:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>float4 f1, f2;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>int4 sel = { 0, -1, -1, 0 };<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>float4 res = select(f1, f2, sel);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>This might be represented by a built-in something like:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>float4 res = __builtin_select(f1, f2, false, true, true, false);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>And as with ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>__builtin_shufflevector</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ the IR normalisation/canonicalization could analogously transform code as expressed in many different ways to a single canonical form using ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>__builtin_select</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’.  Also, as with the ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>__builtin_shufflevector</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’, the selectors for ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>__builtin_select</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ would be restricted to constants just as the indices are for ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>__builtin_shufflevector</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ and so not as flexible as OpenCL’s actual ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>select</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ which can accept a variable selector.  This doesn’t really bring in any OpenCL versus C/C++ vs other language issues, as the ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>__builtin_select</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ would be language agnostic.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>The reason that I wondered about this built-in in the first place, was that I wanted to use lane-predication for some operations.  For example, let’s say I have:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>int4 selectiveMultiply(int4 values, int4 selector, int multiplier) {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>  return [OpenCL]select(values, values * multiplier /* splat */, selector);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>}<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>If the ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>selector</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ is the set ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>{false, true, true, false}</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ then the code generated for the above is pretty convoluted, even when that set if known at compile-time via inlining.  But if I could reduce this to a ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>__builtin_select</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’, my custom lowering implementation could lower this to a single lane-predicated multiply instruction.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>Of course, this I can discover these patterns using exhaustive DAG-to-DAG analysis in a target specific fashion, but if the idea was raised to a more abstract idiom within LLVM, then the analysis could be shared by all targets (as is shuffle), and only the target specific lowering really cares, and it can always ‘</span><span style='font-size:12.0pt;font-family:"Courier New";color:black;mso-fareast-language:EN-US'>expand</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>’ if it can’t do anything special anyway - back to the generic status quo.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'>            MartinO<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US>From:</span></b><span lang=EN-US> Anastasia Stulova [mailto:Anastasia.Stulova@arm.com] <br><b>Sent:</b> 13 June 2016 18:47<br><b>To:</b> Demikhovsky, Elena <elena.demikhovsky@intel.com>; Martin.ORiordan@Movidius.com; 'cfe-dev@lists.llvm.org' (cfe-dev@lists.llvm.org) <cfe-dev@lists.llvm.org><br><b>Cc:</b> nd <nd@arm.com><br><b>Subject:</b> RE: [cfe-dev] OpenCL 'select' as a builtin?<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'>Wondering if it would make sense to share __builtin_select among languages, assuming it has the same format…<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'>Anastasia<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma",sans-serif'> cfe-dev [<a href="mailto:cfe-dev-bounces@lists.llvm.org">mailto:cfe-dev-bounces@lists.llvm.org</a>] <b>On Behalf Of </b>Demikhovsky, Elena via cfe-dev<br><b>Sent:</b> 13 June 2016 12:25<br><b>To:</b> <a href="mailto:Martin.ORiordan@Movidius.com">Martin.ORiordan@Movidius.com</a><br><b>Cc:</b> cfe-dev<br><b>Subject:</b> Re: [cfe-dev] OpenCL 'select' as a builtin?<o:p></o:p></span></p></div></div><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><a name="_MailEndCompose"><span lang=EN-US style='color:#1F497D'>No, there is no such intrinsic yet. We also need it for AVX-512 masked intrinsics.</span></a><span lang=EN-US style='color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>So it is worth to add.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>We use __builtin_ia32_select[b|w|d..]* meanwhile, which are not polymorphic. <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>See </span><span lang=EN-US><a href="http://reviews.llvm.org/D21060">http://reviews.llvm.org/D21060</a><span style='color:#1F497D'>.<o:p></o:p></span></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal style='margin-left:36.0pt;text-indent:-18.0pt'><span lang=EN-US style='font-size:12.0pt;color:#2F5496'>-</span><span lang=EN-US style='font-size:7.0pt;font-family:"Times New Roman",serif;color:#2F5496'>          </span><b><i><span lang=EN-US style='font-size:12.0pt;font-family:"Times New Roman",serif;color:#2F5496'> Elena<o:p></o:p></span></i></b></p></div><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><a name="_____replyseparator"></a><b><span lang=EN-US>From:</span></b><span lang=EN-US> cfe-dev [<a href="mailto:cfe-dev-bounces@lists.llvm.org">mailto:cfe-dev-bounces@lists.llvm.org</a>] <b>On Behalf Of </b>Martin J. O'Riordan via cfe-dev<br><b>Sent:</b> Saturday, June 11, 2016 08:05<br><b>To:</b> 'Clang Dev' <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br><b>Subject:</b> [cfe-dev] OpenCL 'select' as a builtin?<o:p></o:p></span></p></div></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'>Is there a builtin for CLang that implements the same semantics as OpenCL’s “select” function, but which can be used from C and C++?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'>I tried the obvious name ‘</span><span style='font-size:12.0pt;font-family:"Courier New"'>__builtin_select</span><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ but that doesn’t exist, and a trawl through the online docs didn’t reveal anything either.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'>            MartinO<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p></div><p><span lang=EN-US>---------------------------------------------------------------------<br>Intel Israel (74) Limited<o:p></o:p></span></p><p><span lang=EN-US>This e-mail and any attachments may contain confidential material for<br>the sole use of the intended recipient(s). Any review or distribution<br>by others is strictly prohibited. If you are not the intended<br>recipient, please contact the sender and delete all copies.<o:p></o:p></span></p></div></body></html>