X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FBits.cpp;h=5b61d470434ee85a65a39269bfd3dc810f482381;hb=0659842527913025d998860811fe135cc6170044;hp=62b759f09182193e78ca79a57babff82dbc4c6d1;hpb=3a976a95d97a91f59a49ca507fde66d0f4f4fcf1;p=folly.git diff --git a/folly/Bits.cpp b/folly/Bits.cpp index 62b759f0..5b61d470 100644 --- a/folly/Bits.cpp +++ b/folly/Bits.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,14 @@ * limitations under the License. */ -#include "folly/Bits.h" +#include -#include "folly/CpuId.h" +#include +#include // None of this is necessary if we're compiling for a target that supports -// popcnt -#ifndef __POPCNT__ - -// Clang doesn't support ifuncs. This also allows ifunc support to be explicitly -// passed in as a compile flag. -#ifndef FOLLY_HAVE_IFUNC -# ifdef __clang__ -# define FOLLY_HAVE_IFUNC 0 -# else -# define FOLLY_HAVE_IFUNC 1 -# endif -#endif - +// popcnt, which includes MSVC +#if !defined(__POPCNT__) && !defined(_MSC_VER) namespace { int popcount_builtin(unsigned int x) { @@ -42,8 +32,7 @@ int popcountll_builtin(unsigned long long x) { return __builtin_popcountll(x); } - -#if FOLLY_HAVE_IFUNC +#if FOLLY_HAVE_IFUNC && !defined(FOLLY_SANITIZE_ADDRESS) // Strictly speaking, these versions of popcount are usable without ifunc // support. However, we would have to check, via CpuId, if the processor @@ -73,7 +62,7 @@ extern "C" Type_popcountll* folly_popcountll_ifunc() { return folly::CpuId().popcnt() ? popcountll_inst : popcountll_builtin; } -#endif // FOLLY_HAVE_IFUNC +#endif // FOLLY_HAVE_IFUNC && !defined(FOLLY_SANITIZE_ADDRESS) } // namespace @@ -83,8 +72,8 @@ namespace detail { // Call folly_popcount_ifunc on startup to resolve to either popcount_inst // or popcount_builtin int popcount(unsigned int x) -#if FOLLY_HAVE_IFUNC - __attribute__((ifunc("folly_popcount_ifunc"))); +#if FOLLY_HAVE_IFUNC && !defined(FOLLY_SANITIZE_ADDRESS) + __attribute__((__ifunc__("folly_popcount_ifunc"))); #else { return popcount_builtin(x); } #endif @@ -92,8 +81,8 @@ int popcount(unsigned int x) // Call folly_popcount_ifunc on startup to resolve to either popcountll_inst // or popcountll_builtin int popcountll(unsigned long long x) -#if FOLLY_HAVE_IFUNC - __attribute__((ifunc("folly_popcountll_ifunc"))); +#if FOLLY_HAVE_IFUNC && !defined(FOLLY_SANITIZE_ADDRESS) + __attribute__((__ifunc__("folly_popcountll_ifunc"))); #else { return popcountll_builtin(x); } #endif @@ -102,4 +91,3 @@ int popcountll(unsigned long long x) } // namespace folly #endif /* !__POPCNT__ */ -