Skip to content

Commit

Permalink
SSE42 support (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjinpeng87 authored and siddontang committed Sep 18, 2017
1 parent e535424 commit f2dab35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build_tools/build_detect_platform
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ elif test -z "$PORTABLE"; then
fi
fi

$CXX $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
#include <cstdint>
#include <nmmintrin.h>
int main() {
Expand Down
14 changes: 11 additions & 3 deletions util/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) {
table0_[c >> 24];
}

#if defined(HAVE_SSE42) && defined(__GNUC__)
#if defined(__clang__)
#if __has_cpp_attribute(gnu::target)
__attribute__ ((target ("sse4.2")))
#endif
#else // gcc supports this since 4.4
__attribute__ ((target ("sse4.2")))
#endif
#endif
static inline void Fast_CRC32(uint64_t* l, uint8_t const **p) {
#ifndef HAVE_SSE42
Slow_CRC32(l, p);
Expand Down Expand Up @@ -376,8 +385,7 @@ static bool isSSE42() {
return false;
#elif defined(__GNUC__) && defined(__x86_64__) && !defined(IOS_CROSS_COMPILE)
uint32_t c_;
uint32_t d_;
__asm__("cpuid" : "=c"(c_), "=d"(d_) : "a"(1) : "ebx");
__asm__("cpuid" : "=c"(c_) : "a"(1) : "ebx", "edx");
return c_ & (1U << 20); // copied from CpuId.h in Folly.
#elif defined(_WIN64)
int info[4];
Expand All @@ -398,7 +406,7 @@ bool IsFastCrc32Supported() {
return isSSE42();
}

Function ChosenExtend = Choose_Extend();
static Function ChosenExtend = Choose_Extend();

uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
return ChosenExtend(crc, buf, size);
Expand Down

0 comments on commit f2dab35

Please sign in to comment.