Commit 5d43d2ab authored by Owen Yamauchi's avatar Owen Yamauchi

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
parent 244a8996
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "folly/GroupVarint.h" #include "folly/GroupVarint.h"
#if HAVE_GROUP_VARINT
namespace folly { namespace folly {
const uint32_t GroupVarint32::kMask[] = { const uint32_t GroupVarint32::kMask[] = {
...@@ -29,4 +30,4 @@ const uint64_t GroupVarint64::kMask[] = { ...@@ -29,4 +30,4 @@ const uint64_t GroupVarint64::kMask[] = {
}; };
} // namespace folly } // namespace folly
#endif
...@@ -21,9 +21,8 @@ ...@@ -21,9 +21,8 @@
#error GroupVarint.h requires GCC #error GroupVarint.h requires GCC
#endif #endif
#if !defined(__x86_64__) && !defined(__i386__) #if defined(__x86_64__) || defined(__i386__)
#error GroupVarint.h requires x86_64 or i386 #define HAVE_GROUP_VARINT 1
#endif
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
...@@ -604,5 +603,6 @@ typedef GroupVarintDecoder<uint64_t> GroupVarint64Decoder; ...@@ -604,5 +603,6 @@ typedef GroupVarintDecoder<uint64_t> GroupVarint64Decoder;
} // namespace folly } // namespace folly
#endif /* defined(__x86_64__) || defined(__i386__) */
#endif /* FOLLY_GROUPVARINT_H_ */ #endif /* FOLLY_GROUPVARINT_H_ */
...@@ -51,13 +51,16 @@ from optparse import OptionParser ...@@ -51,13 +51,16 @@ from optparse import OptionParser
OUTPUT_FILE = "GroupVarintTables.cpp" OUTPUT_FILE = "GroupVarintTables.cpp"
def generate(f): def generate(f):
f.write("#include <stdint.h>\n" f.write("""
"#include <x86intrin.h>\n" #if defined(__x86_64__) || defined(__i386__)
"\n" #include <stdint.h>
"namespace folly {\n" #include <x86intrin.h>
"namespace detail {\n"
"\n" namespace folly {
"extern const __m128i groupVarintSSEMasks[] = {\n") namespace detail {
extern const __m128i groupVarintSSEMasks[] = {
""")
# Compute SSE masks # Compute SSE masks
for i in range(0, 256): for i in range(0, 256):
...@@ -88,10 +91,13 @@ def generate(f): ...@@ -88,10 +91,13 @@ def generate(f):
offset += d offset += d
f.write(" {0},\n".format(offset)) f.write(" {0},\n".format(offset))
f.write("};\n" f.write("""
"\n" };
"} // namespace detail\n"
"} // namespace folly\n") } // namespace detail
} // namespace folly
#endif /* defined(__x86_64__) || defined(__i386__) */
""")
def main(): def main():
parser = OptionParser() parser = OptionParser()
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#include <stdarg.h> #include <stdarg.h>
#include "folly/GroupVarint.h" #include "folly/GroupVarint.h"
// On platforms where it's not supported, GroupVarint will be compiled out.
#if HAVE_GROUP_VARINT
#include <gtest/gtest.h> #include <gtest/gtest.h>
using namespace folly; using namespace folly;
...@@ -259,3 +262,4 @@ TEST(GroupVarint, GroupVarintDecoder) { ...@@ -259,3 +262,4 @@ TEST(GroupVarint, GroupVarintDecoder) {
} }
} }
#endif
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