Commit 42c850c0 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 4

Update generate_varint_tables to support MSVC

Summary: MSVC is a massive pain in this respect, and, after testing many workarounds, and only ending up with it just emitting a dynamic initializer for them, it's easier to just generate the table as a `uint64_t` and load it explicitly.

Reviewed By: yfeldblum

Differential Revision: D3270226

fbshipit-source-id: 77bc84e58d393373de05a28a30dcb80b66c09c9f
parent e6edf05a
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <nmmintrin.h> #include <nmmintrin.h>
namespace folly { namespace folly {
namespace detail { namespace detail {
extern const __m128i groupVarintSSEMasks[]; alignas(16) extern const uint64_t groupVarintSSEMasks[];
} // namespace detail } // namespace detail
} // namespace folly } // namespace folly
#endif #endif
...@@ -196,7 +196,8 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> { ...@@ -196,7 +196,8 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> {
static const char* decode(const char* p, uint32_t* dest) { static const char* decode(const char* p, uint32_t* dest) {
uint8_t key = p[0]; uint8_t key = p[0];
__m128i val = _mm_loadu_si128((const __m128i*)(p+1)); __m128i val = _mm_loadu_si128((const __m128i*)(p+1));
__m128i mask = detail::groupVarintSSEMasks[key]; __m128i mask =
_mm_load_si128((const __m128i*)&detail::groupVarintSSEMasks[key * 2]);
__m128i r = _mm_shuffle_epi8(val, mask); __m128i r = _mm_shuffle_epi8(val, mask);
_mm_storeu_si128((__m128i*)dest, r); _mm_storeu_si128((__m128i*)dest, r);
return p + detail::groupVarintLengths[key]; return p + detail::groupVarintLengths[key];
...@@ -210,7 +211,8 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> { ...@@ -210,7 +211,8 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> {
uint32_t* c, uint32_t* d) { uint32_t* c, uint32_t* d) {
uint8_t key = p[0]; uint8_t key = p[0];
__m128i val = _mm_loadu_si128((const __m128i*)(p+1)); __m128i val = _mm_loadu_si128((const __m128i*)(p+1));
__m128i mask = detail::groupVarintSSEMasks[key]; __m128i mask =
_mm_load_si128((const __m128i*)&detail::groupVarintSSEMasks[key * 2]);
__m128i r = _mm_shuffle_epi8(val, mask); __m128i r = _mm_shuffle_epi8(val, mask);
// Extracting 32 bits at a time out of an XMM register is a SSE4 feature // Extracting 32 bits at a time out of an XMM register is a SSE4 feature
......
...@@ -56,15 +56,11 @@ def generate(f): ...@@ -56,15 +56,11 @@ def generate(f):
#include <stdint.h> #include <stdint.h>
#if (FOLLY_X64 || defined(__i386__)) && (FOLLY_SSE >= 2)
#include <x86intrin.h>
#endif
namespace folly { namespace folly {
namespace detail { namespace detail {
#if (FOLLY_X64 || defined(__i386__)) && (FOLLY_SSE >= 2) #if (FOLLY_X64 || defined(__i386__)) && (FOLLY_SSE >= 2)
extern const __m128i groupVarintSSEMasks[] = { alignas(16) extern const uint64_t groupVarintSSEMasks[512] = {
""") """)
# Compute SSE masks # Compute SSE masks
...@@ -81,8 +77,8 @@ extern const __m128i groupVarintSSEMasks[] = { ...@@ -81,8 +77,8 @@ extern const __m128i groupVarintSSEMasks[] = {
# 0xff: set corresponding byte in result to 0 # 0xff: set corresponding byte in result to 0
for k in range(d, 4): for k in range(d, 4):
vals[j] |= 0xff << (8 * k) vals[j] |= 0xff << (8 * k)
f.write(" {{static_cast<int64_t>(0x{1:08x}{0:08x}), " f.write(" 0x{1:08x}{0:08x}ULL, "
"static_cast<int64_t>(0x{3:08x}{2:08x})}},\n".format(*vals)) "0x{3:08x}{2:08x}ULL,\n".format(*vals))
f.write("};\n" f.write("};\n"
"#endif /*#if (FOLLY_X64 || defined(__i386__)) && (FOLLY_SSE >= 2)*/\n" "#endif /*#if (FOLLY_X64 || defined(__i386__)) && (FOLLY_SSE >= 2)*/\n"
......
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