Commit 0f30fbc4 authored by REDMOND\agnel's avatar REDMOND\agnel Committed by Facebook GitHub Bot

Adding x86 support for to_ascii_port_clzll() (#1567)

Summary:
Currently to_ascii_port_clzll() in ToAscii.h always returns 0 in x86. This switches to __builtin_clzll() backed by a polyfill.

Closes https://github.com/facebook/folly/issues/1566.

Pull Request resolved: https://github.com/facebook/folly/pull/1567

Reviewed By: luciang

Differential Revision: D28162903

Pulled By: yfeldblum

fbshipit-source-id: 1872cda7aa155b84086bd15ad6cd40475eeb0ac4
parent 896a7356
......@@ -24,10 +24,7 @@
#include <folly/Utility.h>
#include <folly/lang/Align.h>
#include <folly/lang/CArray.h>
#if _MSC_VER
#include <intrin.h>
#endif
#include <folly/portability/Builtins.h>
namespace folly {
......@@ -56,18 +53,6 @@ using to_ascii_alphabet_upper = to_ascii_alphabet<true>;
namespace detail {
FOLLY_ERASE auto to_ascii_port_clzll(uint64_t v) {
#if _MSC_VER
#if FOLLY_X64
return __lzcnt64(v);
#else
return __assume(0), 0;
#endif
#else
return __builtin_clzll(v);
#endif
}
template <uint64_t Base, typename Alphabet>
struct to_ascii_array {
using data_type_ = c_array<uint8_t, Base>;
......@@ -224,7 +209,7 @@ FOLLY_ALWAYS_INLINE size_t to_ascii_size_clzll(uint64_t v) {
}
// log2 is approx log<2>(v)
size_t const vlog2 = 64 - static_cast<size_t>(to_ascii_port_clzll(v));
size_t const vlog2 = 64 - static_cast<size_t>(__builtin_clzll(v));
// handle directly when Base is power-of-two
if (!(Base & (Base - 1))) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment