[PATCH][X86] __builtin_ctz/clz sometimed defined for zero input

Robinson, Paul Paul_Robinson at playstation.sony.com
Mon Oct 27 22:46:44 PDT 2014


Intel documents _lzcnt_u32/64 as returning operand size for 0 input. Ditto tzcnt.  Here's the lzcnt reference:
https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-67C6440B-D49E-4D7C-98A2-667E47ED63CC.htm

These seem reasonable to support when compiling and targeting a microarch with support for the instructions.

The Intel documentation does not suggest any such restriction.  Currently the only Clang support is in Intrin.h, which we can live with.
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."
http://msdn.microsoft.com/en-us/library/vstudio/bb384809(v=vs.100).aspx

While if we absolutely must due to compatibility, I would push hard to not support these functions unless targeting such hardware.

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.

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…
--paulr

From: Chandler Carruth [mailto:chandlerc at google.com]
Sent: Monday, October 27, 2014 9:38 PM
To: Robinson, Paul
Cc: Richard Smith; Sean Silva; cfe-commits at cs.uiuc.edu
Subject: Re: [PATCH][X86] __builtin_ctz/clz sometimed defined for zero input


On Mon, Oct 27, 2014 at 9:16 PM, Robinson, Paul <Paul_Robinson at playstation.sony.com<mailto:Paul_Robinson at playstation.sony.com>> wrote:
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.

I think it's not the exact header so much as the functions themselves that we should care about.

Intel documents _lzcnt_u32/64 as returning operand size for 0 input. Ditto tzcnt.  Here's the lzcnt reference:
https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-67C6440B-D49E-4D7C-98A2-667E47ED63CC.htm

These seem reasonable to support when compiling and targeting a microarch with support for the instructions.


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."
http://msdn.microsoft.com/en-us/library/vstudio/bb384809(v=vs.100).aspx

While if we absolutely must due to compatibility, I would push hard to not support these functions unless targeting such hardware.

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141028/e2e77018/attachment.html>


More information about the cfe-commits mailing list