Commit 779cbf35 authored by Elizabeth Smith's avatar Elizabeth Smith Committed by Sara Golemon

macro for cross platform x64 detection

Summary: Another cross platform fun macro - this one detects x64 status and requires some portability.h includes (which should only define portability stuff and not actually include anything)

Test Plan: fbmake runtests

Reviewed By: delong.j@fb.com

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