Commit d28152cd authored by Sean Cannella's avatar Sean Cannella Committed by dcsommer

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
parent fa0c6eae
......@@ -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
......
......@@ -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
......
......@@ -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;
......
......@@ -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_
......@@ -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);
......
......@@ -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;
......
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