Move asm portability to an Asm portability header
authorChristopher Dykes <cdykes@fb.com>
Mon, 28 Mar 2016 18:20:18 +0000 (11:20 -0700)
committerFacebook Github Bot 4 <facebook-github-bot-4-bot@fb.com>
Mon, 28 Mar 2016 18:35:28 +0000 (11:35 -0700)
Summary: Portabilty.h is just a mashup of everything that was needed up-to now, however, with the Windows port significantly expanding the scope of portability in Folly, it no longer needs to be a massive mashup, so start things by splitting out the asm stubs.

Reviewed By: yfeldblum

Differential Revision: D3007018

fb-gh-sync-id: f32913f74660aaa8889a553ae5d6f7182a4f5789
fbshipit-source-id: f32913f74660aaa8889a553ae5d6f7182a4f5789

13 files changed:
folly/Baton.h
folly/Makefile.am
folly/MicroLock.cpp
folly/Portability.h
folly/RWSpinLock.h
folly/SharedMutex.h
folly/detail/AtomicHashUtils.h
folly/detail/Sleeper.h
folly/detail/TurnSequencer.h
folly/experimental/fibers/Baton.cpp
folly/portability/Asm.h [new file with mode: 0755]
folly/test/SmallLocksTest.cpp
folly/test/SpinLockTest.cpp

index 6d4a7832dd6dc700436fcc96552e6fa33ff11f72..c14e57f32081210e87b09b5bc3e65f47752ae5e9 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <folly/detail/Futex.h>
 #include <folly/detail/MemoryIdler.h>
+#include <folly/portability/Asm.h>
 
 namespace folly {
 
index a56afac1cf2dec68013d85bd490d4ac04dfb5fa1..0f8915a1744e010f72311f0722d709f7e5a74ec9 100644 (file)
@@ -267,6 +267,7 @@ nobase_follyinclude_HEADERS = \
        Padded.h \
        PicoSpinLock.h \
        Portability.h \
+       portability/Asm.h \
        portability/Config.h \
        portability/Constexpr.h \
        portability/Environment.h \
index dd649da1b431e9a25c027c98838e78691eb62a55..778cd5b91527a75f29e87d7d58221452546bfbf0 100644 (file)
@@ -17,6 +17,8 @@
 #include <folly/MicroLock.h>
 #include <thread>
 
+#include <folly/portability/Asm.h>
+
 namespace folly {
 
 void MicroLockCore::lockSlowPath(uint32_t oldWord,
index efef0184ae5f42bfa37761b7da124e5b9029e19d..1b6ce9dbacb050edc43d88e800ea2f2d96f7f1a3 100644 (file)
@@ -369,43 +369,6 @@ inline size_t malloc_usable_size(void* ptr) {
 # define FOLLY_HAS_RTTI 1
 #endif
 
-#ifdef _MSC_VER
-# include <intrin.h>
-#endif
-
-namespace folly {
-
-inline void asm_volatile_memory() {
-#if defined(__clang__) || defined(__GNUC__)
-  asm volatile("" : : : "memory");
-#elif defined(_MSC_VER)
-  ::_ReadWriteBarrier();
-#endif
-}
-
-inline void asm_volatile_pause() {
-#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
-  ::_mm_pause();
-#elif defined(__i386__) || FOLLY_X64
-  asm volatile ("pause");
-#elif FOLLY_A64 || defined(__arm__)
-  asm volatile ("yield");
-#elif FOLLY_PPC64
-  asm volatile("or 27,27,27");
-#endif
-}
-inline void asm_pause() {
-#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
-  ::_mm_pause();
-#elif defined(__i386__) || FOLLY_X64
-  asm ("pause");
-#elif FOLLY_A64 || defined(__arm__)
-  asm ("yield");
-#elif FOLLY_PPC64
-  asm ("or 31,31,31");
-#endif
-}
-
 #if defined(__APPLE__) || defined(_MSC_VER)
 #define MAX_STATIC_CONSTRUCTOR_PRIORITY
 #else
@@ -415,5 +378,4 @@ inline void asm_pause() {
 #define MAX_STATIC_CONSTRUCTOR_PRIORITY __attribute__ ((__init_priority__(102)))
 #endif
 
-} // namespace folly
 #endif // FOLLY_PORTABILITY_H_
index 3091dc1c350b1c87ba3a462c112b1c32212fe8a2..a5b6053467ab8c6f8e686c04f1ca0312fbae62e8 100644 (file)
@@ -137,6 +137,7 @@ pthread_rwlock_t Read        728698     24us       101ns     7.28ms     194us
 */
 
 #include <folly/Portability.h>
+#include <folly/portability/Asm.h>
 
 #if defined(__GNUC__) && \
   (defined(__i386) || FOLLY_X64 || \
index 543b702f577f1e7fdb49abb275b6e9a330e057b8..782a6536636c46fd55804aae909e71d97b39396a 100644 (file)
@@ -25,6 +25,7 @@
 #include <folly/Likely.h>
 #include <folly/detail/CacheLocality.h>
 #include <folly/detail/Futex.h>
+#include <folly/portability/Asm.h>
 #include <sys/resource.h>
 
 // SharedMutex is a reader-writer lock.  It is small, very fast, scalable
index 262f1543e50704f4006bb42abdeb239390d7b03d..bb49eef05ec6ca4e63cc09611b8f4704f81a3e80 100644 (file)
@@ -17,8 +17,8 @@
 #ifndef incl_FOLLY_ATOMIC_HASH_UTILS_H
 #define incl_FOLLY_ATOMIC_HASH_UTILS_H
 
-#include <folly/Portability.h>
 #include <thread>
+#include <folly/portability/Asm.h>
 
 // Some utilities used by AtomicHashArray and AtomicHashMap
 //
index b8c8dfdfba4420e308d45036361e3d8dc7fc2110..f5a12b85da9ac6c6e4acd927fdbd7bd9e6109ac9 100644 (file)
@@ -24,7 +24,7 @@
 #include <cinttypes>
 #include <ctime>
 
-#include <folly/Portability.h>
+#include <folly/portability/Asm.h>
 
 namespace folly {
 
index 32a6f57f16522f355d201c7818424c43472b9fe2..6c62928b08b4b1d262fff8af972ed9f72424fa3f 100644 (file)
@@ -22,7 +22,7 @@
 #include <unistd.h>
 
 #include <folly/detail/Futex.h>
-#include <folly/Portability.h>
+#include <folly/portability/Asm.h>
 
 namespace folly {
 
index 5b3cfdc987eeab2b980d8f4f48b4d988fa2b21ff..9f6d4e412c44b12c64e7b64d7c644ce91760e768 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <folly/detail/MemoryIdler.h>
 #include <folly/experimental/fibers/FiberManager.h>
+#include <folly/portability/Asm.h>
 
 namespace folly { namespace fibers {
 
diff --git a/folly/portability/Asm.h b/folly/portability/Asm.h
new file mode 100755 (executable)
index 0000000..ef9b3fa
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016 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.
+ */
+
+#pragma once
+
+#include <folly/Portability.h>
+
+#ifdef _MSC_VER
+# include <intrin.h>
+#endif
+
+namespace folly {
+inline void asm_volatile_memory() {
+#if defined(__clang__) || defined(__GNUC__)
+  asm volatile("" : : : "memory");
+#elif defined(_MSC_VER)
+  ::_ReadWriteBarrier();
+#endif
+}
+
+inline void asm_volatile_pause() {
+#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
+  ::_mm_pause();
+#elif defined(__i386__) || FOLLY_X64
+  asm volatile("pause");
+#elif FOLLY_A64 || defined(__arm__)
+  asm volatile("yield");
+#elif FOLLY_PPC64
+  asm volatile("or 27,27,27");
+#endif
+}
+
+inline void asm_pause() {
+#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
+  ::_mm_pause();
+#elif defined(__i386__) || FOLLY_X64
+  asm("pause");
+#elif FOLLY_A64 || defined(__arm__)
+  asm("yield");
+#elif FOLLY_PPC64
+  asm("or 31,31,31");
+#endif
+}
+}
index 7ddd29a070a163ca0870433c5c36617d4b1ee5cf..ad6a83785ace8020e1c93114d8e22af511b6b06e 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <gtest/gtest.h>
 
+#include <folly/portability/Asm.h>
+
 using folly::MSLGuard;
 using folly::MicroLock;
 using folly::MicroSpinLock;
index ee12ab1613f7c0a807ff6466b211ba2042300b2d..6d028af1e0f923a8436f4f247c641f8afe0fad19 100644 (file)
@@ -20,6 +20,8 @@
 #include <gtest/gtest.h>
 #include <thread>
 
+#include <folly/portability/Asm.h>
+
 using folly::SpinLockGuardImpl;
 
 namespace {