Conditionals for iOS / Android compilation
authorSean Cannella <seanc@fb.com>
Thu, 16 Oct 2014 17:09:06 +0000 (10:09 -0700)
committerdcsommer <dcsommer@fb.com>
Fri, 17 Oct 2014 18:44:24 +0000 (11:44 -0700)
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

folly/Bits.h
folly/Conv.cpp
folly/Hash.h
folly/Portability.h
folly/RWSpinLock.h
folly/ThreadName.h

index c915111e1dc3949b367081d8c6a844a540c104b8..b22b8d57899801d9cfa76484220789d5930e00e6 100644 (file)
@@ -55,8 +55,6 @@
 #ifndef FOLLY_BITS_H_
 #define FOLLY_BITS_H_
 
-#include <folly/Portability.h>
-
 #if !defined(__clang__) && !defined(_MSC_VER)
 #define FOLLY_INTRINSIC_CONSTEXPR constexpr
 #else
@@ -404,10 +402,12 @@ class Endian {
     return detail::EndianInt<T>::little(x);
   }
 
+#if !defined(__ANDROID__)
   FB_GEN(64)
   FB_GEN(32)
   FB_GEN(16)
   FB_GEN(8)
+#endif
 };
 
 #undef FB_GEN
index 4f825829cc46fae7e3bdc629b925c5f876a75b9e..25c0069dd0bdbd5c2a673e441b072303ce766d4d 100644 (file)
@@ -46,8 +46,7 @@ static_assert(sizeof(unsigned long long) >= 8,
               "Wrong value for MaxString<unsigned long long>::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
index 1a16f3c8e1a11d14ed7d6bf6298495c86b168895..e04cf8cf48768a1e474de15d904642b5a3e0efa1 100644 (file)
@@ -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;
index 4cfec56c0a3dd6feb7a7762272a87a47510441ad..a9298af99199c151aba79f7f4432990251b74302 100644 (file)
@@ -245,4 +245,9 @@ using namespace FOLLY_GFLAGS_NAMESPACE;
 }  // namespace gflags
 #endif
 
+// for TARGET_OS_IPHONE
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#endif
+
 #endif // FOLLY_PORTABILITY_H_
index 9ba6390ed61d750d8e34483de1422c5c934e5732..f47def6023a77ed600c796cc4a70aa803ceb61cd 100644 (file)
@@ -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 <atomic>
 #include <string>
 #include <algorithm>
@@ -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);
index 3926a829149e8aa1af1b2e16ff34b1ee73440adb..2730277f6e3185818143ae556264a44a65b9caca 100644 (file)
@@ -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;