Commit 6607a501 authored by Joe Loser's avatar Joe Loser Committed by Facebook Github Bot

Simplify some macros testing __GNUC__ and __clang__ (#1095)

Summary:
- Both GCC and Clang define the macro `__GNUC__`, `__GNUG__` and
  friends. Simplify some macros whose intent is to check "if we are GCC or
  Clang" but do so via checking `__GNUC__` in addition to `__clang__`. It
  is sufficient to just check `__GNUC__`.
Pull Request resolved: https://github.com/facebook/folly/pull/1095

Reviewed By: Orvid

Differential Revision: D14697480

Pulled By: yfeldblum

fbshipit-source-id: cd6ec82c4235a1321ecdf240afaad7d5c0e99437
parent 3291f635
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
// noinline // noinline
#ifdef _MSC_VER #ifdef _MSC_VER
#define FOLLY_NOINLINE __declspec(noinline) #define FOLLY_NOINLINE __declspec(noinline)
#elif defined(__clang__) || defined(__GNUC__) #elif defined(__GNUC__)
#define FOLLY_NOINLINE __attribute__((__noinline__)) #define FOLLY_NOINLINE __attribute__((__noinline__))
#else #else
#define FOLLY_NOINLINE #define FOLLY_NOINLINE
...@@ -156,7 +156,7 @@ ...@@ -156,7 +156,7 @@
// always inline // always inline
#ifdef _MSC_VER #ifdef _MSC_VER
#define FOLLY_ALWAYS_INLINE __forceinline #define FOLLY_ALWAYS_INLINE __forceinline
#elif defined(__clang__) || defined(__GNUC__) #elif defined(__GNUC__)
#define FOLLY_ALWAYS_INLINE inline __attribute__((__always_inline__)) #define FOLLY_ALWAYS_INLINE inline __attribute__((__always_inline__))
#else #else
#define FOLLY_ALWAYS_INLINE inline #define FOLLY_ALWAYS_INLINE inline
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
// attribute hidden // attribute hidden
#if _MSC_VER #if _MSC_VER
#define FOLLY_ATTR_VISIBILITY_HIDDEN #define FOLLY_ATTR_VISIBILITY_HIDDEN
#elif defined(__clang__) || defined(__GNUC__) #elif defined(__GNUC__)
#define FOLLY_ATTR_VISIBILITY_HIDDEN __attribute__((__visibility__("hidden"))) #define FOLLY_ATTR_VISIBILITY_HIDDEN __attribute__((__visibility__("hidden")))
#else #else
#define FOLLY_ATTR_VISIBILITY_HIDDEN #define FOLLY_ATTR_VISIBILITY_HIDDEN
......
...@@ -68,7 +68,7 @@ constexpr bool kHasUnalignedAccess = false; ...@@ -68,7 +68,7 @@ constexpr bool kHasUnalignedAccess = false;
#if !defined FOLLY_NODISCARD #if !defined FOLLY_NODISCARD
#if defined(_MSC_VER) && (_MSC_VER >= 1700) #if defined(_MSC_VER) && (_MSC_VER >= 1700)
#define FOLLY_NODISCARD _Check_return_ #define FOLLY_NODISCARD _Check_return_
#elif defined(__clang__) || defined(__GNUC__) #elif defined(__GNUC__)
#define FOLLY_NODISCARD __attribute__((__warn_unused_result__)) #define FOLLY_NODISCARD __attribute__((__warn_unused_result__))
#else #else
#define FOLLY_NODISCARD #define FOLLY_NODISCARD
...@@ -146,7 +146,7 @@ constexpr bool kIsSanitize = false; ...@@ -146,7 +146,7 @@ constexpr bool kIsSanitize = false;
#define FOLLY_PACK_ATTR /**/ #define FOLLY_PACK_ATTR /**/
#define FOLLY_PACK_PUSH __pragma(pack(push, 1)) #define FOLLY_PACK_PUSH __pragma(pack(push, 1))
#define FOLLY_PACK_POP __pragma(pack(pop)) #define FOLLY_PACK_POP __pragma(pack(pop))
#elif defined(__clang__) || defined(__GNUC__) #elif defined(__GNUC__)
#define FOLLY_PACK_ATTR __attribute__((__packed__)) #define FOLLY_PACK_ATTR __attribute__((__packed__))
#define FOLLY_PACK_PUSH /**/ #define FOLLY_PACK_PUSH /**/
#define FOLLY_PACK_POP /**/ #define FOLLY_PACK_POP /**/
...@@ -215,7 +215,7 @@ FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS ...@@ -215,7 +215,7 @@ FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS
*/ */
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define FOLLY_TLS __declspec(thread) #define FOLLY_TLS __declspec(thread)
#elif defined(__GNUC__) || defined(__clang__) #elif defined(__GNUC__)
#define FOLLY_TLS __thread #define FOLLY_TLS __thread
#else #else
#error cannot define platform specific thread local storage #error cannot define platform specific thread local storage
......
...@@ -90,7 +90,7 @@ struct Nehalem : public Default { ...@@ -90,7 +90,7 @@ struct Nehalem : public Default {
static FOLLY_ALWAYS_INLINE uint64_t popcount(uint64_t value) { static FOLLY_ALWAYS_INLINE uint64_t popcount(uint64_t value) {
// POPCNT is supported starting with Intel Nehalem, AMD K10. // POPCNT is supported starting with Intel Nehalem, AMD K10.
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__)
// GCC and Clang won't inline the intrinsics. // GCC and Clang won't inline the intrinsics.
uint64_t result; uint64_t result;
asm("popcntq %1, %0" : "=r"(result) : "r"(value)); asm("popcntq %1, %0" : "=r"(result) : "r"(value));
...@@ -109,7 +109,7 @@ struct Haswell : public Nehalem { ...@@ -109,7 +109,7 @@ struct Haswell : public Nehalem {
static FOLLY_ALWAYS_INLINE uint64_t blsr(uint64_t value) { static FOLLY_ALWAYS_INLINE uint64_t blsr(uint64_t value) {
// BMI1 is supported starting with Intel Haswell, AMD Piledriver. // BMI1 is supported starting with Intel Haswell, AMD Piledriver.
// BLSR combines two instructions into one and reduces register pressure. // BLSR combines two instructions into one and reduces register pressure.
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__)
// GCC and Clang won't inline the intrinsics. // GCC and Clang won't inline the intrinsics.
uint64_t result; uint64_t result;
asm("blsrq %1, %0" : "=r"(result) : "r"(value)); asm("blsrq %1, %0" : "=r"(result) : "r"(value));
...@@ -121,7 +121,7 @@ struct Haswell : public Nehalem { ...@@ -121,7 +121,7 @@ struct Haswell : public Nehalem {
static FOLLY_ALWAYS_INLINE uint64_t static FOLLY_ALWAYS_INLINE uint64_t
bextr(uint64_t value, uint32_t start, uint32_t length) { bextr(uint64_t value, uint32_t start, uint32_t length) {
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__)
// GCC and Clang won't inline the intrinsics. // GCC and Clang won't inline the intrinsics.
// Encode parameters in `pattern` where `pattern[0:7]` is `start` and // Encode parameters in `pattern` where `pattern[0:7]` is `start` and
// `pattern[8:15]` is `length`. // `pattern[8:15]` is `length`.
...@@ -137,7 +137,7 @@ struct Haswell : public Nehalem { ...@@ -137,7 +137,7 @@ struct Haswell : public Nehalem {
} }
static FOLLY_ALWAYS_INLINE uint64_t bzhi(uint64_t value, uint32_t index) { static FOLLY_ALWAYS_INLINE uint64_t bzhi(uint64_t value, uint32_t index) {
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__)
// GCC and Clang won't inline the intrinsics. // GCC and Clang won't inline the intrinsics.
const uint64_t index64 = index; const uint64_t index64 = index;
uint64_t result; uint64_t result;
......
...@@ -89,7 +89,7 @@ inline uint64_t select64(uint64_t x, uint64_t k) { ...@@ -89,7 +89,7 @@ inline uint64_t select64(uint64_t x, uint64_t k) {
template <> template <>
FOLLY_ALWAYS_INLINE uint64_t FOLLY_ALWAYS_INLINE uint64_t
select64<compression::instructions::Haswell>(uint64_t x, uint64_t k) { select64<compression::instructions::Haswell>(uint64_t x, uint64_t k) {
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__)
// GCC and Clang won't inline the intrinsics. // GCC and Clang won't inline the intrinsics.
uint64_t result = uint64_t(1) << k; uint64_t result = uint64_t(1) << k;
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
PUSHMI_PP_IGNORE_CXX2A_COMPAT_BEGIN PUSHMI_PP_IGNORE_CXX2A_COMPAT_BEGIN
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5) #if defined(__GNUC__)
#define PUSHMI_NOT_ON_WINDOWS 1 #define PUSHMI_NOT_ON_WINDOWS 1
#else #else
#define PUSHMI_NOT_ON_WINDOWS 0 #define PUSHMI_NOT_ON_WINDOWS 0
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
* } * }
*/ */
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5) #if defined(__GNUC__)
#define PUSHMI_CEXP_NOT_ON_WINDOWS 1 #define PUSHMI_CEXP_NOT_ON_WINDOWS 1
#else #else
#define PUSHMI_CEXP_NOT_ON_WINDOWS 0 #define PUSHMI_CEXP_NOT_ON_WINDOWS 0
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
#include <exception> #include <exception>
#if !defined(FOLLY_FORCE_EXCEPTION_COUNT_USE_STD) && \ #if !defined(FOLLY_FORCE_EXCEPTION_COUNT_USE_STD) && defined(__GNUG__)
(defined(__GNUG__) || defined(__clang__))
#define FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS #define FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS
namespace __cxxabiv1 { namespace __cxxabiv1 {
// forward declaration (originally defined in unwind-cxx.h from from libstdc++) // forward declaration (originally defined in unwind-cxx.h from from libstdc++)
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
namespace folly { namespace folly {
inline void asm_volatile_memory() { inline void asm_volatile_memory() {
#if defined(__clang__) || defined(__GNUC__) #if defined(__GNUC__)
asm volatile("" : : : "memory"); asm volatile("" : : : "memory");
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
::_ReadWriteBarrier(); ::_ReadWriteBarrier();
......
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