<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=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 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:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","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;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:1.0in">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Intel documents _lzcnt_u32/64 as returning operand size for 0 input. Ditto tzcnt.  Here's the lzcnt reference:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:1.0in">
<a href="https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-67C6440B-D49E-4D7C-98A2-667E47ED63CC.htm" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"">https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-67C6440B-D49E-4D7C-98A2-667E47ED63CC.htm</span></a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in">These seem reasonable to support when compiling and targeting a microarch with support for the instructions.<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The Intel documentation does not suggest any such restriction.  Currently the only Clang support is in Intrin.h, which we can live with.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:1.0in">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Microsoft documentation claims that __lzcnt* returns the operand size for 0 input, while noting "If you run code that uses this intrinsic on hardware that does not support the lzcnt
 instruction, the results are unpredictable."</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:1.0in">
<a href="http://msdn.microsoft.com/en-us/library/vstudio/bb384809(v=vs.100).aspx" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"">http://msdn.microsoft.com/en-us/library/vstudio/bb384809(v=vs.100).aspx</span></a><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><br>
While if we absolutely must due to compatibility, I would push hard to not support these functions unless targeting such hardware.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in">I find this particularly important because in the grander scheme of things *very little* x86 hardware in the world has lzcnt, and even less tzcnt. =[ Weak APIs like this seem really problematic there.<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hardware that Sony cares about does support these instructions, so, yeah, we want this.  The existing lzcntintrin.h requires __LZCNT__ defined, which subsets
 this into the hardware we care about, so…<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Chandler Carruth [mailto:chandlerc@google.com]
<br>
<b>Sent:</b> Monday, October 27, 2014 9:38 PM<br>
<b>To:</b> Robinson, Paul<br>
<b>Cc:</b> Richard Smith; Sean Silva; cfe-commits@cs.uiuc.edu<br>
<b>Subject:</b> Re: [PATCH][X86] __builtin_ctz/clz sometimed defined for zero input<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Mon, Oct 27, 2014 at 9:16 PM, Robinson, Paul <<a href="mailto:Paul_Robinson@playstation.sony.com" target="_blank">Paul_Robinson@playstation.sony.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:.5in">
I can't find any documentation *at all* for lzcntintrin.h, so I can find no suggestion that its __lzcnt* functions would have defined behavior on an input of 0.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><a name="14954fb3d0a35a65__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span></a><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I think it's not the exact header so much as the functions themselves that we should care about.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Intel documents _lzcnt_u32/64 as returning operand size for 0 input. Ditto tzcnt.  Here's the lzcnt
 reference:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><a href="https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-67C6440B-D49E-4D7C-98A2-667E47ED63CC.htm" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"">https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-67C6440B-D49E-4D7C-98A2-667E47ED63CC.htm</span></a><o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">These seem reasonable to support when compiling and targeting a microarch with support for the instructions.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Microsoft documentation claims that __lzcnt* returns the operand size for 0 input, while noting "If
 you run code that uses this intrinsic on hardware that does not support the lzcnt instruction, the results are unpredictable."</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><a href="http://msdn.microsoft.com/en-us/library/vstudio/bb384809(v=vs.100).aspx" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"">http://msdn.microsoft.com/en-us/library/vstudio/bb384809(v=vs.100).aspx</span></a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><br>
While if we absolutely must due to compatibility, I would push hard to not support these functions unless targeting such hardware.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I find this particularly important because in the grander scheme of things *very little* x86 hardware in the world has lzcnt, and even less tzcnt. =[ Weak APIs like this seem really problematic there.<o:p></o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>