macro for cross platform x64 detection
authorElizabeth Smith <elizabeths@fb.com>
Fri, 18 Apr 2014 15:18:54 +0000 (08:18 -0700)
committerSara Golemon <sgolemon@fb.com>
Fri, 18 Apr 2014 19:10:26 +0000 (12:10 -0700)
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

16 files changed:
folly/Baton.h
folly/Checksum.cpp
folly/CpuId.h
folly/DiscriminatedPtr.h
folly/GroupVarint.h
folly/PackedSyncPtr.h
folly/Portability.h
folly/RWSpinLock.h
folly/SmallLocks.h
folly/build/generate_varint_tables.py
folly/detail/AtomicHashUtils.h
folly/detail/MemoryIdler.cpp
folly/experimental/EliasFanoCoding.h
folly/io/async/EventFDWrapper.h
folly/small_vector.h
folly/test/small_vector_test.cpp

index c53afa35f04276029970d635f490a5b3f95a5d18..86b2e013d0caf6785ec71bb2473658829dc0889e 100644 (file)
@@ -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
index 28ed83920247f6e5696a04a91061ee9761c5c3a1..ba32d687a49293d54bdace1ab4a5a1e0f10cd3f8 100644 (file)
@@ -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
index 12e9b0743293e13b89e1859c8064fb682d75698b..facabe18cd046504ec5f3e6caa4531690e1f855b 100644 (file)
@@ -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
index af669549ecb172e3bfcc565d63848e1400c20915..b2e363eb0b3c9ed11390ccbe81822a5f1499eb7b 100644 (file)
 #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
 
index cbfce4b06919e1f745ecaedb3754b2135a7fe77e..5c506a2f1b34897840474bf33e07d90d7329f4d1 100644 (file)
@@ -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_ */
 
index 0dfa1e9865aa408368d76dd3af945ab145c6be3c..fa9fbd5e300d8ec94e9c1f75160d0e86740e434b 100644 (file)
@@ -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
 
index d3edde9e72e3c87a4978798940ba8a8fe3655878..43953f931a064c4afeb55d8a606afa8f65b1b928 100644 (file)
@@ -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__
index 33bce2cd72c946350d744a072c4ab4b7646732d6..c52f7e8b8bfbafd88920936fb5a9720cc8455fee 100644 (file)
@@ -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>
index 8bd1900b784ff7b2ff094d259e36a0bf3afdbca4..b8f081a668b5e2401ea8f483c5f67901bdede4f9 100644 (file)
 #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 {
 
 //////////////////////////////////////////////////////////////////////
index 19589edc8b680311e71b73a07ed9dcd0de1fd52d..60fe683e0767a2b5d7e3ad5a94047347842b275f 100755 (executable)
@@ -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():
index 6ce2125ef694e510d35201c8a251a659a3e293bc..a06db36b2bd53f5803d627641783849b288b0947 100644 (file)
@@ -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;               \
index 979d9329e278f7d19998b2255fc82ae32842e951..3e01ee448ae219f7d9877f18907b91e7e9fa825b 100644 (file)
@@ -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;
index c8e8e3cf07269d8abf2f589750047625c1abac73..f5222f8c8f15159ab0a7ae5cd6d181864c53f6fd 100644 (file)
@@ -28,7 +28,7 @@
 #error EliasFanoCoding.h requires GCC
 #endif
 
-#if !defined(__x86_64__)
+#if !FOLLY_X64
 #error EliasFanoCoding.h requires x86_64
 #endif
 
index 5df88fcb73a1b35900a2412409ac247d59e88704..294d9d37b881a54660d4c2f51442ab6a941e0160 100644 (file)
@@ -1,21 +1,19 @@
 /*
- * 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
index 03c90a38125a43e84e2e4ffee0f4c29df299d482..06d2a3050ec25ec9c1b340406e27bcfc117f0daf 100644 (file)
@@ -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<
index 57b84a4efa345fccbc72c7156d0d736d359fd7ad..5c55a4168276d466f405b8e0189ca490e6fe0036 100644 (file)
@@ -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