<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:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@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:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:"Consolas\,";
panose-1:0 0 0 0 0 0 0 0 0 0;}
/* 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;}
code
{mso-style-priority:99;
font-family:"Courier New";}
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.xmsonormal, li.xmsonormal, div.xmsonormal
{mso-style-name:x_msonormal;
margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.xxxxmsonormal, li.xxxxmsonormal, div.xxxxmsonormal
{mso-style-name:x_xxxmsonormal;
margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.xxxxxapple-converted-space
{mso-style-name:x_xxxxapple-converted-space;}
span.EmailStyle23
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
p.tableblock, li.tableblock, div.tableblock
{mso-style-name:tableblock;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.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;}
/* List Definitions */
@list l0
{mso-list-id:1786195370;
mso-list-type:hybrid;
mso-list-template-ids:-293576984 2056825134 68747267 68747269 68747265 68747267 68747269 68747265 68747267 68747269;}
@list l0:level1
{mso-level-number-format:bullet;
mso-level-text:\F0D8;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;
mso-fareast-font-family:Calibri;
mso-bidi-font-family:Calibri;
color:#666666;}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></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">I never used this extensions in non-OpenCL mode, so I can’t predict what is the impact of the proposed changes.<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">I just note that code snippet from the original email works in OpenCL mode as described in RFC with one very minor note:<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>
<ul style="margin-top:0cm" type="disc">
<li class="xxxxmsonormal" style="mso-list:l0 level1 lfo1"><span lang="EN-US" style="color:#666666">I’m proposing to support vector type values as predicates in the ternary operator:
<b>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.</b> Note that this is exactly what GCC is doing right now [1] in their vector extensions.</span><span lang="EN-US"><o:p></o:p></span></li></ul>
<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">In OpenCL mode the comparison operator returns bitmask to enable bitwise operations (https://godbolt.org/z/F6ynx6):<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" style="background:#FFFFFE"><span lang="EN-US" style="font-family:"Consolas,",serif;color:black">float4 foo(float4 a, float4 b, int4 *c) {<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#FFFFFE"><span lang="EN-US" style="font-family:"Consolas,",serif;color:black"> <span style="background:yellow;mso-highlight:yellow">int4 x = {</span></span><span lang="EN-US" style="font-family:"Consolas,",serif;color:#098658;background:yellow;mso-highlight:yellow">1</span><span lang="EN-US" style="font-family:"Consolas,",serif;color:black;background:yellow;mso-highlight:yellow">, </span><span lang="EN-US" style="font-family:"Consolas,",serif;color:#098658;background:yellow;mso-highlight:yellow">2</span><span lang="EN-US" style="font-family:"Consolas,",serif;color:black;background:yellow;mso-highlight:yellow">, </span><span lang="EN-US" style="font-family:"Consolas,",serif;color:#098658;background:yellow;mso-highlight:yellow">3</span><span lang="EN-US" style="font-family:"Consolas,",serif;color:black;background:yellow;mso-highlight:yellow">, </span><span lang="EN-US" style="font-family:"Consolas,",serif;color:#098658;background:yellow;mso-highlight:yellow">4</span><span lang="EN-US" style="font-family:"Consolas,",serif;color:black;background:yellow;mso-highlight:yellow">};<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#FFFFFE"><span lang="EN-US" style="font-family:"Consolas,",serif;color:black;background:yellow;mso-highlight:yellow"> *c = (a < b) & x;</span><span lang="EN-US" style="font-family:"Consolas,",serif;color:black">
<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#FFFFFE"><span lang="EN-US" style="font-family:"Consolas,",serif;color:black"> </span><span lang="EN-US" style="font-family:"Consolas,",serif;color:blue">return</span><span lang="EN-US" style="font-family:"Consolas,",serif;color:black"> a > b? a : b;<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#FFFFFE"><span style="font-family:"Consolas,",serif;color:black">}<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#FFFFFE"><span style="font-family:"Consolas,",serif;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">and select is defined as
<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>
<table class="MsoNormalTable" border="1" cellpadding="0" style="background:white;border:solid #D8D8CE 1.0pt">
<tbody>
<tr>
<td valign="top" style="border:solid #D8D8CE 1.0pt;background:#EDF2F2;padding:6.75pt 7.5pt 6.75pt 7.5pt">
<p class="MsoNormal"><span lang="EN-US" style="font-size:12.0pt;font-family:"Arial",sans-serif;color:#6D6E71">gentype <b>select</b>(gentype <i>a</i>, gentype <i>b</i>, igentype <i>c</i>) gentype <b>select</b>(gentype <i>a</i>, gentype <i>b</i>, ugentype <i>c</i>)<o:p></o:p></span></p>
</td>
<td valign="top" style="border:solid #D8D8CE 1.0pt;background:#EDF2F2;padding:6.75pt 7.5pt 6.75pt 7.5pt">
<p class="MsoNormal" style="margin-bottom:9.0pt"><span lang="EN-US" style="font-size:12.0pt;font-family:"Arial",sans-serif;color:#6D6E71">For each component of a vector type,<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:9.0pt"><i><span lang="EN-US" style="font-size:12.0pt;font-family:"Arial",sans-serif;color:#6D6E71">result[i]</span></i><span lang="EN-US" style="font-size:12.0pt;font-family:"Arial",sans-serif;color:#6D6E71"> = if MSB
of <i>c[i]</i> is set ? <i>b[i]</i> : <i>a[i]</i>.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:9.0pt"><span lang="EN-US" style="font-size:12.0pt;font-family:"Arial",sans-serif;color:#6D6E71">For a scalar type, <i>result</i> = <i>c</i> ? <i>b</i> : <i>a</i>.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:#264357;background:white">igentype</span><span lang="EN-US" style="font-size:12.0pt;font-family:"Arial",sans-serif;color:#6D6E71"> and </span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:#264357;background:white">ugentype</span><span lang="EN-US" style="font-size:12.0pt;font-family:"Arial",sans-serif;color:#6D6E71"> must
have the same number of elements and bits as </span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:#264357;background:white">gentype</span><sup><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#6D6E71">36</span></sup><span lang="EN-US" style="font-size:12.0pt;font-family:"Arial",sans-serif;color:#6D6E71">.<o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<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">I guess, if we convert predicate elements to bool, we should get the same behavior.<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"> Finkel, Hal J. <hfinkel@anl.gov>
<br>
<b>Sent:</b> Tuesday, May 19, 2020 9:50 PM<br>
<b>To:</b> Bader, Alexey <alexey.bader@intel.com>; Anastasia Stulova <Anastasia.Stulova@arm.com>; Keane, Erich <erich.keane@intel.com>; Min-Yih Hsu <minyihh@uci.edu>; cfe-dev (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] [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, Alexey. In that case, do you have any thoughts on the original email in this thread?<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"> Bader, Alexey <<a href="mailto:alexey.bader@intel.com">alexey.bader@intel.com</a>><br>
<b>Sent:</b> Tuesday, May 19, 2020 1:48 PM<br>
<b>To:</b> Finkel, Hal J. <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>>; Anastasia Stulova <<a href="mailto:Anastasia.Stulova@arm.com">Anastasia.Stulova@arm.com</a>>; 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>>; cfe-dev (<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>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="xmsonormal"><span lang="EN-US">Yes, we do implement these rules for OpenCL and they are applied to all OpenCL versions.</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"><a href="https://godbolt.org/z/YH6ExF">https://godbolt.org/z/YH6ExF</a></span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="xmsonormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> cfe-dev <<a href="mailto:cfe-dev-bounces@lists.llvm.org">cfe-dev-bounces@lists.llvm.org</a>>
<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 <<a href="mailto:Anastasia.Stulova@arm.com">Anastasia.Stulova@arm.com</a>>; 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>>; 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>
</div>
<p class="xmsonormal"> <o:p></o:p></p>
<div>
<p class="xmsonormal"><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?</span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black"> -Hal</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div id="x_Signature">
<div>
<div>
<p class="xmsonormal"><span style="font-size:10.0pt">Hal Finkel<br>
Lead, Compiler Technology and Programming Languages<br>
Leadership Computing Facility<br>
Argonne National Laboratory</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></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="xmsonormal"><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="xmsonormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xmsonormal"><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.</span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black">Anastasia</span><o:p></o:p></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="x_x_divRplyFwdMsg">
<p class="xmsonormal"><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="xmsonormal"> <o:p></o:p></p>
</div>
</div>
<div>
<blockquote style="border:none;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="xmsonormal"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></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_x_divRplyFwdMsg">
<p class="xmsonormal"><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">
</span><o:p></o:p></p>
<div>
<p class="xmsonormal"><span style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">What is the intent with the ext-vector-types? </span><o:p></o:p></p>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<p class="xxxxmsonormal"> <o:p></o:p></p>
<p class="xxxxmsonormal">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="xxxxmsonormal"> <o:p></o:p></p>
<p class="xxxxmsonormal"> -Hal<o:p></o:p></p>
<p class="xxxxmsonormal"> <o:p></o:p></p>
<blockquote style="border:none;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="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<p class="xxxxmsonormal"><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).</span><o:p></o:p></p>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="xxxxmsonormal"><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</span><o:p></o:p></p>
</div>
</div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<div>
<p class="xxxxmsonormal"><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><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><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><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><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><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> -Hal</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div id="x_x_x_x_Signature">
<div>
<div>
<p class="xxxxmsonormal"><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><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="font-size:12.0pt;color:black"> </span><o:p></o:p></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_x_divRplyFwdMsg">
<p class="xxxxmsonormal"><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">
</span><o:p></o:p></p>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<p class="xxxxmsonormal"><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.
</span><o:p></o:p></p>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">Thanks for the pointer</span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">-Min</span><o:p></o:p></p>
<div>
<p class="xxxxmsonormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<div>
<p class="xxxxmsonormal"><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:</span><o:p></o:p></p>
</div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
<div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">Note that this was implemented for non-ext-vector types here:</span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><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></span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">Which matches the GCC version. <span class="xxxxxapple-converted-space"> </span></span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">The attribute is vector_size, not ext_vector_type however.</span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><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).</span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<div>
<p class="xxxxmsonormal"><b><span lang="EN-US" style="color:#666666">From:</span></b><span class="xxxxxapple-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="xxxxxapple-converted-space"> </span><b>On
Behalf Of<span class="xxxxxapple-converted-space"> </span></b>Min-Yih Hsu via cfe-dev<br>
<b>Sent:</b><span class="xxxxxapple-converted-space"> </span>Friday, May 8, 2020 10:58 AM<br>
<b>To:</b><span class="xxxxxapple-converted-space"> </span><a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<b>Subject:</b><span class="xxxxxapple-converted-space"> </span>[cfe-dev] [RFC] Ternary operator with vector type predicate</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">Hi folks,</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">```</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">typedef float float4 __attribute__((ext_vector_type(4)));</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">float4 foo(bool cond, float4 a, float4 b) {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> return cond? a : b;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">}</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">```</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">```</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">float4 foo(float4 a, float4 b) {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> return a > b? a : b;</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">}</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">```</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">Here are the reasons and some advantages:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">I’ll try to come up with a patch for preview as soon as possible.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">Thanks for the feedbacks in advance.</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666">-Min</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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></span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxxxmsonormal"><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></span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
<p class="xxxxmsonormal"><span lang="EN-US" style="color:#666666"> </span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>