#undef FB_GEN
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-
-template <class T>
-struct EndianInt : public EndianIntBase<T> {
- public:
- static T big(T x) { return EndianInt::swap(x); }
- static T little(T x) { return x; }
-};
-
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-
template <class T>
struct EndianInt : public EndianIntBase<T> {
public:
- static T big(T x) { return x; }
- static T little(T x) { return EndianInt::swap(x); }
+ static T big(T x) {
+ return kIsLittleEndian ? EndianInt::swap(x) : x;
+ }
+ static T little(T x) {
+ return kIsBigEndian ? EndianInt::swap(x) : x;
+ }
};
-#else
-# error Your machine uses a weird endianness!
-#endif /* __BYTE_ORDER__ */
-
} // namespace detail
// big* convert between native and big-endian representations
BIG
};
- static constexpr Order order =
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- Order::LITTLE;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
- Order::BIG;
-#else
-# error Your machine uses a weird endianness!
-#endif /* __BYTE_ORDER__ */
+ static constexpr Order order = kIsLittleEndian ? Order::LITTLE : Order::BIG;
template <class T> static T swap(T x) {
return folly::detail::EndianInt<T>::swap(x);
#error BitVectorCoding.h requires x86_64
#endif
-#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
-#error BitVectorCoding.h requires little endianness
-#endif
-
namespace folly { namespace compression {
+static_assert(kIsLittleEndian, "BitVectorCoding.h requires little endianness");
+
template <class Pointer>
struct BitVectorCompressedListBase {
BitVectorCompressedListBase() = default;
#error EliasFanoCoding.h requires x86_64
#endif
-#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
-#error EliasFanoCoding.h requires little endianness
-#endif
-
namespace folly { namespace compression {
+static_assert(kIsLittleEndian, "EliasFanoCoding.h requires little endianness");
+
template <class Pointer>
struct EliasFanoCompressedListBase {
EliasFanoCompressedListBase() = default;
static_assert(sizeof(uint32_t) == 4, "bad platform");
static_assert(sizeof(uint64_t) == 8, "bad platform");
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- static constexpr size_t kEpochOffset = 1;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
- static constexpr size_t kEpochOffset = 0; // in units of sizeof(int)
-#else
-# error Your machine uses a weird endianness!
-#endif
+ static constexpr size_t kEpochOffset = kIsLittleEndian ? 1 : 0;
// val_ stores the epoch in the most significant 32 bits and the
// waiter count in the least significant 32 bits.
#undef EXPECTED_CLASS
// Validate ELF data encoding (LSB/MSB)
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-# define EXPECTED_ENCODING ELFDATA2LSB
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-# define EXPECTED_ENCODING ELFDATA2MSB
-#else
-# error Unsupported byte order
-#endif
- if (elfHeader.e_ident[EI_DATA] != EXPECTED_ENCODING) {
+ static constexpr auto kExpectedEncoding =
+ kIsLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
+ if (elfHeader.e_ident[EI_DATA] != kExpectedEncoding) {
if (msg) *msg = "invalid ELF encoding";
return false;
}
-#undef EXPECTED_ENCODING
// Validate ELF version (1)
if (elfHeader.e_ident[EI_VERSION] != EV_CURRENT ||