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 {
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
......
......@@ -24,7 +24,7 @@ namespace folly {
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
......
......@@ -18,6 +18,7 @@
#define FOLLY_CPUID_H_
#include <cstdint>
#include "folly/Portability.h"
namespace folly {
......@@ -29,7 +30,7 @@ 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
......
......@@ -31,9 +31,10 @@
#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
......
......@@ -21,7 +21,9 @@
#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>
......@@ -607,6 +609,6 @@ typedef GroupVarintDecoder<uint64_t> GroupVarint64Decoder;
} // namespace folly
#endif /* defined(__x86_64__) || defined(__i386__) */
#endif /* FOLLY_X64 || defined(__i386__) */
#endif /* FOLLY_GROUPVARINT_H_ */
......@@ -17,7 +17,9 @@
#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
......
......@@ -72,6 +72,13 @@ struct MaxAlign { char c; } __attribute__((aligned));
# 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__
......
......@@ -107,7 +107,7 @@ pthread_rwlock_t Read 728698 24us 101ns 7.28ms 194us
*/
#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>
......
......@@ -44,13 +44,12 @@
#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 {
//////////////////////////////////////////////////////////////////////
......
......@@ -52,7 +52,9 @@ OUTPUT_FILE = "GroupVarintTables.cpp"
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>
......@@ -96,7 +98,7 @@ extern const __m128i groupVarintSSEMasks[] = {
} // namespace detail
} // namespace folly
#endif /* defined(__x86_64__) || defined(__i386__) */
#endif /* FOLLY_X64 || defined(__i386__) */
""")
def main():
......
......@@ -19,7 +19,7 @@
// 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; \
......
......@@ -87,7 +87,7 @@ void MemoryIdler::flushLocalMallocCaches() {
}
#ifdef __x86_64__
#if FOLLY_X64
static const size_t s_pageSize = sysconf(_SC_PAGESIZE);
static FOLLY_TLS uintptr_t tls_stackLimit;
......
......@@ -28,7 +28,7 @@
#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.
......@@ -38,7 +36,7 @@
// 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
......
......@@ -48,7 +48,7 @@
#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
......@@ -268,7 +268,7 @@ namespace detail {
SizeType size_;
};
#ifdef __x86_64__
#if FOLLY_X64
template<class SizeType, bool ShouldUseHeap>
struct OneBitMutexImpl {
typedef SizeType InternalSizeType;
......@@ -1100,7 +1100,7 @@ private:
}
} FB_PACKED;
#if defined(__x86_64_)
#if FOLLY_X64
typedef unsigned char InlineStorageType[sizeof(value_type) * MaxInline];
#else
typedef typename std::aligned_storage<
......
......@@ -29,7 +29,7 @@
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>");
......@@ -602,14 +602,14 @@ TEST(small_vector, AllHeap) {
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
......
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