<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)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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;}
/* 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:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.xxxmsonormal, li.xxxmsonormal, div.xxxmsonormal
        {mso-style-name:x_x_x_msonormal;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.xxxxapple-converted-space
        {mso-style-name:x_x_x_xapple-converted-space;}
span.EmailStyle22
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:2.0cm 42.5pt 2.0cm 3.0cm;}
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="RU" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Yes, we do implement these rules for OpenCL and they are applied to all OpenCL versions.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><a href="https://godbolt.org/z/YH6ExF">https://godbolt.org/z/YH6ExF</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="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"> cfe-dev <cfe-dev-bounces@lists.llvm.org>
<b>On Behalf Of </b>Finkel, Hal J. via cfe-dev<br>
<b>Sent:</b> Tuesday, May 19, 2020 8:36 PM<br>
<b>To:</b> Anastasia Stulova <Anastasia.Stulova@arm.com>; Keane, Erich <erich.keane@intel.com>; Min-Yih Hsu <minyihh@uci.edu>; clang developer list <cfe-dev@lists.llvm.org><br>
<b>Cc:</b> nd <nd@arm.com><br>
<b>Subject:</b> Re: [cfe-dev] [RFC] Ternary operator with vector type predicate<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">Thanks, Anastasia. I have certainly used the ext_vector_type types outside of OpenCL mode in the past. Do we currently implement the OpenCL 2 ternary operator rules for these vectors?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"> -Hal<o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div id="Signature">
<div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">Hal Finkel<br>
Lead, Compiler Technology and Programming Languages<br>
Leadership Computing Facility<br>
Argonne National Laboratory<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Anastasia Stulova <<a href="mailto:Anastasia.Stulova@arm.com">Anastasia.Stulova@arm.com</a>><br>
<b>Sent:</b> Tuesday, May 19, 2020 12:30 PM<br>
<b>To:</b> Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>>; Min-Yih Hsu <<a href="mailto:minyihh@uci.edu">minyihh@uci.edu</a>>; Finkel, Hal J. <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>>; clang developer list <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Cc:</b> nd <<a href="mailto:nd@arm.com">nd@arm.com</a>><br>
<b>Subject:</b> Re: [cfe-dev] [RFC] Ternary operator with vector type predicate</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">I see ext_vector_type as a Clang extension that implements OpenCL rules under OpenCL mode. I believe there are areas where it behaves slightly differently if it's used in non-OpenCL code. I am
 not aware of details, but I believe it is used outside of OpenCL mode too.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">Anastasia<o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="x_divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> cfe-dev <<a href="mailto:cfe-dev-bounces@lists.llvm.org">cfe-dev-bounces@lists.llvm.org</a>> on behalf of Finkel, Hal J. via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Sent:</b> 19 May 2020 14:22<br>
<b>To:</b> Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>>; Min-Yih Hsu <<a href="mailto:minyihh@uci.edu">minyihh@uci.edu</a>><br>
<b>Cc:</b> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a> <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [cfe-dev] [RFC] Ternary operator with vector type predicate</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<blockquote style="border:none #C8C8C8 1.0pt;border-left:solid #C8C8C8 2.25pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<div class="MsoNormal" align="center" style="text-align:center"><span style="color:#666666">
<hr size="2" width="98%" align="center">
</span></div>
<div id="x_x_divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>><br>
<b>Sent:</b> Tuesday, May 19, 2020 8:10 AM<br>
<b>To:</b> Finkel, Hal J. <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>>; Min-Yih Hsu <<a href="mailto:minyihh@uci.edu">minyihh@uci.edu</a>><br>
<b>Cc:</b> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a> <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Subject:</b> RE: [cfe-dev] [RFC] Ternary operator with vector type predicate</span><span style="color:#666666">
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">What is the intent with the ext-vector-types? <o:p></o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"><o:p> </o:p></span></p>
</div>
</div>
</div>
</blockquote>
<p class="xxxmsonormal"><o:p> </o:p></p>
<p class="xxxmsonormal">That's a really good question. I've always thought of them as a slightly-more-convenient version of the vector types, although I suppose that they're really supposed to be OpenCL vectors. The Clang extension docs say, "OpenCL vector
 types are created using the ext_vector_type attribute. It supports the V.xyzw syntax and other tidbits as seen in OpenCL." Thus, for OpenCL, I suppose that it is supposed to do this: <a href="https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_C.html#operators-ternary-selection">https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_C.html#operators-ternary-selection</a><o:p></o:p></p>
<p class="xxxmsonormal"><o:p> </o:p></p>
<p class="xxxmsonormal"> -Hal<o:p></o:p></p>
<p class="xxxmsonormal"><o:p> </o:p></p>
<blockquote style="border:none #C8C8C8 1.0pt;border-left:solid #C8C8C8 2.25pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"><o:p> </o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"><o:p> </o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"><o:p> </o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"><o:p> </o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"><o:p> </o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> It seems to me that it is an incompatible extension without anyone really maintaining them, and slightly different SEMA rules (for seemingly no reason).<o:p></o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">The conditional operator for the vector_size value was implemented as a GCC compatibility option, but no such motivation existed for ext-vetctor-types.<o:p></o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">That said, the semantic analysis for this in ext-vector-types is sufficiently different that it wasn’t possible to combine implementations.  The rules had diverged significantly at one point,
 so there wasn’t really a way to do so compatibly.<o:p></o:p></span></p>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <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="xxxmsonormal"><b><span lang="EN-US" style="color:#666666">From:</span></b><span lang="EN-US" style="color:#666666"> Finkel, Hal J. <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>>
<br>
<b>Sent:</b> Tuesday, May 19, 2020 6:05 AM<br>
<b>To:</b> Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>>; Min-Yih Hsu <<a href="mailto:minyihh@uci.edu">minyihh@uci.edu</a>><br>
<b>Cc:</b> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [cfe-dev] [RFC] Ternary operator with vector type predicate<o:p></o:p></span></p>
</div>
</div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black">In general, I don't like to see features supported by not-ext-vector types that are not supported by ext-vector types.</span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black">That having been said, is this related to our discussion on bool vectors:</span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black">  <a href="http://lists.llvm.org/pipermail/cfe-dev/2020-May/065434.html">http://lists.llvm.org/pipermail/cfe-dev/2020-May/065434.html</a></span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> -Hal</span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div id="x_x_x_Signature">
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:10.0pt;color:#666666">Hal Finkel<br>
Lead, Compiler Technology and Programming Languages<br>
Leadership Computing Facility<br>
Argonne National Laboratory</span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><span lang="EN-US" style="color:#666666"><o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center"><span lang="EN-US" style="color:#666666">
<hr size="2" width="98%" align="center">
</span></div>
<div id="x_x_x_divRplyFwdMsg">
<p class="xxxmsonormal"><b><span lang="EN-US" style="color:black">From:</span></b><span lang="EN-US" style="color:black"> cfe-dev <<a href="mailto:cfe-dev-bounces@lists.llvm.org">cfe-dev-bounces@lists.llvm.org</a>> on behalf of Min-Yih Hsu via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Sent:</b> Friday, May 8, 2020 1:17 PM<br>
<b>To:</b> Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>><br>
<b>Cc:</b> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a> <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [cfe-dev] [RFC] Ternary operator with vector type predicate</span><span lang="EN-US" style="color:#666666">
<o:p></o:p></span></p>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Interesting….then I think the question simply becomes whether we should support it in ext_vector_type as well.
<o:p></o:p></span></p>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Thanks for the pointer<o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">-Min<o:p></o:p></span></p>
<div>
<p class="xxxmsonormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="color:#666666"><o:p> </o:p></span></p>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">On May 8, 2020, at 11:04 AM, Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>> wrote:<o:p></o:p></span></p>
</div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
<div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Note that this was implemented for non-ext-vector types here:<o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"><a href="https://github.com/llvm/llvm-project/commit/349636d2bfc39a5c81a835a95d203a42d9f9301a"><span style="color:purple">https://github.com/llvm/llvm-project/commit/349636d2bfc39a5c81a835a95d203a42d9f9301a</span></a><o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Which matches the GCC version. <span class="xxxxapple-converted-space"> </span><o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">The attribute is vector_size, not ext_vector_type however.<o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Otherwise, it does everything you’re proposing (like I said, just with a more portable vector-type definition).<o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<div>
<p class="xxxmsonormal"><b><span lang="EN-US" style="color:#666666">From:</span></b><span class="xxxxapple-converted-space"><span lang="EN-US" style="color:#666666"> </span></span><span lang="EN-US" style="color:#666666">cfe-dev <<a href="mailto:cfe-dev-bounces@lists.llvm.org">cfe-dev-bounces@lists.llvm.org</a>><span class="xxxxapple-converted-space"> </span><b>On
 Behalf Of<span class="xxxxapple-converted-space"> </span></b>Min-Yih Hsu via cfe-dev<br>
<b>Sent:</b><span class="xxxxapple-converted-space"> </span>Friday, May 8, 2020 10:58 AM<br>
<b>To:</b><span class="xxxxapple-converted-space"> </span><a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<b>Subject:</b><span class="xxxxapple-converted-space"> </span>[cfe-dev] [RFC] Ternary operator with vector type predicate<o:p></o:p></span></p>
</div>
</div>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Hi folks,<o:p></o:p></span></p>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">In clang’s vector extension, the ternary operator (?:) is able to select from two vector type values based on the boolean type predicate. For example:<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">```<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">typedef float float4 __attribute__((ext_vector_type(4)));<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">float4 foo(bool cond, float4 a, float4 b) {<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">  return cond? a : b;<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">}<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">```<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">However, clang currently doesn’t support vector type values as the predicates. So code shown below won’t compile:<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">```<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">float4 foo(float4 a, float4 b) {<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">  return a > b? a : b;<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">}<o:p></o:p></span></p>
</div>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">```<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Which is essentially just a max function that can be implemented by hardware instructions (vmaxps in Intel AVX for example) efficiently.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">I’m proposing to support vector type values as predicates in the ternary operator: If the predicate value has vector type, each of its element would be converted to bool before being used to select
 corresponding elements from the second or third operands. Note that this is exactly what GCC is doing right now [1] in their vector extensions.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">On the (IR) codegen side, since the IR `select`, `icmp`, and `fcmp` instruction all support vector type values as the operands, I don’t think there are much trouble in it.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Here are the reasons and some advantages:<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">1. It provides more flexibility for programmers to do conditional selections on vectors. Especially for cases that can be optimized by hardware instructions like the motivated example above.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">2. It will not break the current usages of ternary operator: If the predicate is a scalar value, it’s still sticking to the current model.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">3. If the goal of our extensions is aiming to “support a broad range of GCC extensions”. Then the behavior should also be as consistent as possible.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">I’ll try to come up with a patch for preview as soon as possible.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Also a slightly off-topic thing: In our document [2], the ternary operator has always been mis-typed as ‘:?’ Maybe we should fix it some times.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">Thanks for the feedbacks in advance.<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">-Min<o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">[1]: <a href="https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html"><span style="color:purple">https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html</span></a><o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666">[2]: <a href="https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors"><span style="color:purple">https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors</span></a><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
<p class="xxxmsonormal"><span lang="EN-US" style="color:#666666"> <o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>