From: Sean Cannella Date: Thu, 16 Oct 2014 17:09:06 +0000 (-0700) Subject: Conditionals for iOS / Android compilation X-Git-Tag: v0.22.0~269 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d28152cd020746c61a5972468a4c38f51266a307;p=folly.git Conditionals for iOS / Android compilation Summary: Conditional changes required to compile on iOS and Android. Test Plan: compiled on all platforms Reviewed By: meyering@fb.com Subscribers: kmccray, trunkagent, shilin, njormrod, ranjeeth, subodh, bmatheny FB internal diff: D1618028 Tasks: 5183325 --- diff --git a/folly/Bits.h b/folly/Bits.h index c915111e..b22b8d57 100644 --- a/folly/Bits.h +++ b/folly/Bits.h @@ -55,8 +55,6 @@ #ifndef FOLLY_BITS_H_ #define FOLLY_BITS_H_ -#include - #if !defined(__clang__) && !defined(_MSC_VER) #define FOLLY_INTRINSIC_CONSTEXPR constexpr #else @@ -404,10 +402,12 @@ class Endian { return detail::EndianInt::little(x); } +#if !defined(__ANDROID__) FB_GEN(64) FB_GEN(32) FB_GEN(16) FB_GEN(8) +#endif }; #undef FB_GEN diff --git a/folly/Conv.cpp b/folly/Conv.cpp index 4f825829..25c0069d 100644 --- a/folly/Conv.cpp +++ b/folly/Conv.cpp @@ -46,8 +46,7 @@ static_assert(sizeof(unsigned long long) >= 8, "Wrong value for MaxString::value" ", please update."); -/* Test for GCC >= 3.6.0 */ -#if __GNUC__ > 3 || (__GNUC__ == 3 && (__GNUC_MINOR__ >= 6)) +#ifdef FOLLY_HAVE_INT128_T template <> const char *const MaxString<__uint128_t>::value = "340282366920938463463374607431768211455"; #endif diff --git a/folly/Hash.h b/folly/Hash.h index 1a16f3c8..e04cf8cf 100644 --- a/folly/Hash.h +++ b/folly/Hash.h @@ -42,12 +42,12 @@ namespace folly { namespace hash { // This is the Hash128to64 function from Google's cityhash (available // under the MIT License). We use it to reduce multiple 64 bit hashes // into a single hash. -inline size_t hash_128_to_64(const size_t upper, const size_t lower) { +inline uint64_t hash_128_to_64(const uint64_t upper, const uint64_t lower) { // Murmur-inspired hashing. - const size_t kMul = 0x9ddfea08eb382d69ULL; - size_t a = (lower ^ upper) * kMul; + const uint64_t kMul = 0x9ddfea08eb382d69ULL; + uint64_t a = (lower ^ upper) * kMul; a ^= (a >> 47); - size_t b = (upper ^ a) * kMul; + uint64_t b = (upper ^ a) * kMul; b ^= (b >> 47); b *= kMul; return b; diff --git a/folly/Portability.h b/folly/Portability.h index 4cfec56c..a9298af9 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -245,4 +245,9 @@ using namespace FOLLY_GFLAGS_NAMESPACE; } // namespace gflags #endif +// for TARGET_OS_IPHONE +#ifdef __APPLE__ +#include +#endif + #endif // FOLLY_PORTABILITY_H_ diff --git a/folly/RWSpinLock.h b/folly/RWSpinLock.h index 9ba6390e..f47def60 100644 --- a/folly/RWSpinLock.h +++ b/folly/RWSpinLock.h @@ -117,6 +117,13 @@ pthread_rwlock_t Read 728698 24us 101ns 7.28ms 194us #undef RW_SPINLOCK_USE_X86_INTRINSIC_ #endif +// iOS doesn't define _mm_cvtsi64_si128 and friends +#if defined(__SSE2__) && !TARGET_OS_IPHONE +#define RW_SPINLOCK_USE_SSE_INSTRUCTIONS_ +#else +#undef RW_SPINLOCK_USE_SSE_INSTRUCTIONS_ +#endif + #include #include #include @@ -442,7 +449,7 @@ struct RWTicketIntTrait<64> { typedef uint32_t HalfInt; typedef uint16_t QuarterInt; -#ifdef __SSE2__ +#ifdef RW_SPINLOCK_USE_SSE_INSTRUCTIONS_ static __m128i make128(const uint16_t v[4]) { return _mm_set_epi16(0, 0, 0, 0, v[3], v[2], v[1], v[0]); } @@ -464,7 +471,7 @@ struct RWTicketIntTrait<32> { typedef uint16_t HalfInt; typedef uint8_t QuarterInt; -#ifdef __SSE2__ +#ifdef RW_SPINLOCK_USE_SSE_INSTRUCTIONS_ static __m128i make128(const uint8_t v[4]) { return _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, v[3], v[2], v[1], v[0]); @@ -598,7 +605,7 @@ class RWTicketSpinLockT : boost::noncopyable { t.whole = load_acquire(&ticket.whole); FullInt old = t.whole; -#ifdef __SSE2__ +#ifdef RW_SPINLOCK_USE_SSE_INSTRUCTIONS_ // SSE2 can reduce the lock and unlock overhead by 10% static const QuarterInt kDeltaBuf[4] = { 1, 1, 0, 0 }; // write/read/user static const __m128i kDelta = IntTraitType::make128(kDeltaBuf); @@ -626,7 +633,7 @@ class RWTicketSpinLockT : boost::noncopyable { RWTicket t, old; old.whole = t.whole = load_acquire(&ticket.whole); old.users = old.read; -#ifdef __SSE2__ +#ifdef RW_SPINLOCK_USE_SSE_INSTRUCTIONS_ // SSE2 may reduce the total lock and unlock overhead by 10% static const QuarterInt kDeltaBuf[4] = { 0, 1, 1, 0 }; // write/read/user static const __m128i kDelta = IntTraitType::make128(kDeltaBuf); diff --git a/folly/ThreadName.h b/folly/ThreadName.h index 3926a829..2730277f 100644 --- a/folly/ThreadName.h +++ b/folly/ThreadName.h @@ -25,12 +25,12 @@ namespace folly { // having an undefined compiler function called. #if defined(__GLIBC__) && !defined(__APPLE__) && !defined(__ANDROID__) #if __GLIBC_PREREQ(2, 12) -# define FOLLY_GLIBC_2_12 +# define FOLLY_HAS_PTHREAD_SETNAME_NP #endif #endif inline bool setThreadName(pthread_t id, StringPiece name) { -#ifdef FOLLY_GLIBC_2_12 +#ifdef FOLLY_HAS_PTHREAD_SETNAME_NP return 0 == pthread_setname_np(id, name.fbstr().substr(0, 15).c_str()); #else return false;