From 5d43d2ab506d7b02a54ef5a5e1d662a1911d1aa2 Mon Sep 17 00:00:00 2001 From: Owen Yamauchi Date: Thu, 21 Mar 2013 12:13:39 -0700 Subject: [PATCH] Compile out GroupVarint on non-Intel Summary: Compile out instead of erroring. In an ideal world, we'd have a fallback that would work across platforms (i.e. no SSE, no unaligned 32-bit writes etc.) and compile some version of GroupVarint in all environments. I actually tried this; the SSE stuff is all behind #if __SSSE3__ already, so I thought it could work (modulo the unaligned-writes problem). I ran into problems with the SSSE3-vs.-not distinction that @simpkins alluded to in D652764, and decided I'd rather not open that can of worms at the moment. Test Plan: fbmake runtests. Manually force the #ifs to false and make sure fbmake runtests still passes (although GroupVarintTest is empty). Reviewed By: delong.j@fb.com FB internal diff: D747150 --- folly/GroupVarint.cpp | 3 ++- folly/GroupVarint.h | 6 +++--- folly/build/generate_varint_tables.py | 28 ++++++++++++++++----------- folly/test/GroupVarintTest.cpp | 4 ++++ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/folly/GroupVarint.cpp b/folly/GroupVarint.cpp index 2b546245..2ff34368 100644 --- a/folly/GroupVarint.cpp +++ b/folly/GroupVarint.cpp @@ -16,6 +16,7 @@ #include "folly/GroupVarint.h" +#if HAVE_GROUP_VARINT namespace folly { const uint32_t GroupVarint32::kMask[] = { @@ -29,4 +30,4 @@ const uint64_t GroupVarint64::kMask[] = { }; } // namespace folly - +#endif diff --git a/folly/GroupVarint.h b/folly/GroupVarint.h index e3b452ae..dc269195 100644 --- a/folly/GroupVarint.h +++ b/folly/GroupVarint.h @@ -21,9 +21,8 @@ #error GroupVarint.h requires GCC #endif -#if !defined(__x86_64__) && !defined(__i386__) -#error GroupVarint.h requires x86_64 or i386 -#endif +#if defined(__x86_64__) || defined(__i386__) +#define HAVE_GROUP_VARINT 1 #include #include @@ -604,5 +603,6 @@ typedef GroupVarintDecoder GroupVarint64Decoder; } // namespace folly +#endif /* defined(__x86_64__) || defined(__i386__) */ #endif /* FOLLY_GROUPVARINT_H_ */ diff --git a/folly/build/generate_varint_tables.py b/folly/build/generate_varint_tables.py index 55375d2f..19589edc 100755 --- a/folly/build/generate_varint_tables.py +++ b/folly/build/generate_varint_tables.py @@ -51,13 +51,16 @@ from optparse import OptionParser OUTPUT_FILE = "GroupVarintTables.cpp" def generate(f): - f.write("#include \n" - "#include \n" - "\n" - "namespace folly {\n" - "namespace detail {\n" - "\n" - "extern const __m128i groupVarintSSEMasks[] = {\n") + f.write(""" +#if defined(__x86_64__) || defined(__i386__) +#include +#include + +namespace folly { +namespace detail { + +extern const __m128i groupVarintSSEMasks[] = { +""") # Compute SSE masks for i in range(0, 256): @@ -88,10 +91,13 @@ def generate(f): offset += d f.write(" {0},\n".format(offset)) - f.write("};\n" - "\n" - "} // namespace detail\n" - "} // namespace folly\n") + f.write(""" +}; + +} // namespace detail +} // namespace folly +#endif /* defined(__x86_64__) || defined(__i386__) */ +""") def main(): parser = OptionParser() diff --git a/folly/test/GroupVarintTest.cpp b/folly/test/GroupVarintTest.cpp index 1e59016d..32b4ae8f 100644 --- a/folly/test/GroupVarintTest.cpp +++ b/folly/test/GroupVarintTest.cpp @@ -17,6 +17,9 @@ #include #include "folly/GroupVarint.h" +// On platforms where it's not supported, GroupVarint will be compiled out. +#if HAVE_GROUP_VARINT + #include using namespace folly; @@ -259,3 +262,4 @@ TEST(GroupVarint, GroupVarintDecoder) { } } +#endif -- 2.34.1