return;
}
assert(before == INIT);
-#ifdef __x86_64__
+#if FOLLY_X64
// The pause instruction is the polite way to spin, but it doesn't
// actually affect correctness to omit it if we don't have it.
// Pausing donates the full capabilities of the current core to
namespace detail {
-#if defined(__x86_64__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && \
+#if FOLLY_X64 && defined(__GNUC__) && defined(__GNUC_MINOR__) && \
(((__GNUC__ * 100) + __GNUC_MINOR__) >= 407)
// Fast SIMD implementation of CRC-32C for x86 with SSE 4.2
#define FOLLY_CPUID_H_
#include <cstdint>
+#include "folly/Portability.h"
namespace folly {
class CpuId {
public:
CpuId() {
-#if defined(__x86_64__) || defined(__i386__)
+#if FOLLY_X64 || defined(__i386__)
__asm__("cpuid" : "=c"(c_), "=d"(d_) : "a"(1) : "ebx");
#else
// On non-Intel, none of these features exist; at least not in the same form
#include <stdexcept>
#include <glog/logging.h>
#include "folly/Likely.h"
+#include "folly/Portability.h"
#include "folly/detail/DiscriminatedPtrDetail.h"
-#ifndef __x86_64__
+#if !FOLLY_X64
# error "DiscriminatedPtr is x64-specific code."
#endif
#error GroupVarint.h requires GCC
#endif
-#if defined(__x86_64__) || defined(__i386__)
+#include "folly/Portability.h"
+
+#if FOLLY_X64 || defined(__i386__)
#define HAVE_GROUP_VARINT 1
#include <cstdint>
} // namespace folly
-#endif /* defined(__x86_64__) || defined(__i386__) */
+#endif /* FOLLY_X64 || defined(__i386__) */
#endif /* FOLLY_GROUPVARINT_H_ */
#ifndef FOLLY_PACKEDSYNCPTR_H_
#define FOLLY_PACKEDSYNCPTR_H_
-#ifndef __x86_64__
+#include "folly/Portability.h"
+
+#if !FOLLY_X64
# error "PackedSyncPtr is x64-specific code."
#endif
# define FOLLY_ALWAYS_INLINE
#endif
+// detection for 64 bit
+#if defined(__x86_64__) || defined(_M_X64)
+# define FOLLY_X64 1
+#else
+# define FOLLY_X64 0
+#endif
+
// portable version check
#ifndef __GNUC_PREREQ
# if defined __GNUC__ && defined __GNUC_MINOR__
*/
#if defined(__GNUC__) && !defined(__clang__) && \
- (defined(__i386) || defined(__x86_64__) || \
+ (defined(__i386) || FOLLY_X64 || \
defined(ARCH_K8))
#define RW_SPINLOCK_USE_X86_INTRINSIC_
#include <x86intrin.h>
#include <mutex>
#include <glog/logging.h>
+#include "folly/Portability.h"
-#ifndef __x86_64__
+#if !FOLLY_X64
# error "SmallLocks.h is currently x64-only."
#endif
-#include "folly/Portability.h"
-
namespace folly {
//////////////////////////////////////////////////////////////////////
def generate(f):
f.write("""
-#if defined(__x86_64__) || defined(__i386__)
+#include "folly/Portability.h"
+
+#if FOLLY_X64 || defined(__i386__)
#include <stdint.h>
#include <x86intrin.h>
} // namespace detail
} // namespace folly
-#endif /* defined(__x86_64__) || defined(__i386__) */
+#endif /* FOLLY_X64 || defined(__i386__) */
""")
def main():
// Note: no include guard; different -inl.h files include this and
// undef it more than once in a translation unit.
-#if !(defined(__x86__) || defined(__i386__) || defined(__x86_64__))
+#if !(defined(__x86__) || defined(__i386__) || FOLLY_X64)
#define FOLLY_SPIN_WAIT(condition) \
for (int counter = 0; condition; ++counter) { \
if (counter < 10000) continue; \
}
-#ifdef __x86_64__
+#if FOLLY_X64
static const size_t s_pageSize = sysconf(_SC_PAGESIZE);
static FOLLY_TLS uintptr_t tls_stackLimit;
#error EliasFanoCoding.h requires GCC
#endif
-#if !defined(__x86_64__)
+#if !FOLLY_X64
#error EliasFanoCoding.h requires x86_64
#endif
/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
+ * Copyright 2014 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
+
/**
* Work around the lack of <sys/eventfd.h> on glibc 2.5.1 which we still
* need to support, sigh.
// Values from the Linux kernel source:
// arch/x86/include/asm/unistd_{32,64}.h
#ifndef __NR_eventfd2
-#if defined(__x86_64__)
+#if FOLLY_X64
#define __NR_eventfd2 290
#elif defined(__i386__)
#define __NR_eventfd2 328
#include "folly/Malloc.h"
-#if defined(__GNUC__) && defined(__x86_64__)
+#if defined(__GNUC__) && FOLLY_X64
# include "folly/SmallLocks.h"
# define FB_PACKED __attribute__((packed))
#else
SizeType size_;
};
-#ifdef __x86_64__
+#if FOLLY_X64
template<class SizeType, bool ShouldUseHeap>
struct OneBitMutexImpl {
typedef SizeType InternalSizeType;
}
} FB_PACKED;
-#if defined(__x86_64_)
+#if FOLLY_X64
typedef unsigned char InlineStorageType[sizeof(value_type) * MaxInline];
#else
typedef typename std::aligned_storage<
using folly::small_vector;
using namespace folly::small_vector_policy;
-#if defined(__x86_64__)
+#if FOLLY_X64
static_assert(sizeof(small_vector<int>) == 16,
"Object size is not what we expect for small_vector<int>");
TEST(small_vector, Basic) {
typedef folly::small_vector<int,3,uint32_t
-#ifdef __x86_64__
+#if FOLLY_X64
,OneBitMutex
#endif
> Vector;
Vector a;
-#ifdef __x86_64__
+#if FOLLY_X64
a.lock();
a.unlock();
#endif