[libcxx-commits] [PATCH] D125958: Use __libcpp_clz for a tighter __log2i function
Nilay Vaish via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sat May 21 12:31:30 PDT 2022
nilayvaish requested changes to this revision.
nilayvaish added a comment.
This revision now requires changes to proceed.
Can you take a look at the failed test?
================
Comment at: libcxx/include/__algorithm/sort.h:505
+ if (sizeof(__n) <= sizeof(unsigned))
+ return sizeof(unsigned) * __CHAR_BIT__ - 1 - __libcpp_clz(static_cast<unsigned>(__n));
+ if (sizeof(__n) <= sizeof(unsigned long))
----------------
I am wondering whether __CHAR_BIT__ is preferred over using CHAR_BIT (available from climit header file). I don't know what the convention is for writing library code.
================
Comment at: libcxx/include/__algorithm/sort.h:510-516
+
_Number __log2 = 0;
while (__n > 1) {
__log2++;
__n >>= 1;
}
return __log2;
----------------
Instead of retaining this, should we just have a static_assert() on the size of the type being less or equal to that of unsigned long long?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125958/new/
https://reviews.llvm.org/D125958
More information about the libcxx-commits
mailing list