gate sse42 implementation of checksum for x86 only
authorStephen Chen <tracelog@fb.com>
Tue, 16 May 2017 17:06:47 +0000 (10:06 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 16 May 2017 17:22:41 +0000 (10:22 -0700)
Summary:
folly/detail/ChecksumDetail.h gets included in Checksum.h and it
unconditionally includes <immintrin.h>. This doesn't compile on
aarch64 platform. Add #ifdefs for this.

Reviewed By: yfeldblum

Differential Revision: D5048636

fbshipit-source-id: d2074eb1b01487b02d95f3e2eebe683237d918fe

folly/Checksum.cpp
folly/detail/ChecksumDetail.cpp
folly/detail/ChecksumDetail.h

index cbc99913c8428ee6a6fdd5ec2a7e50a73aa5a2f6..4e5f7768c1979c8d4b858cd219fd237cc57b6e94 100644 (file)
@@ -21,7 +21,7 @@
 #include <algorithm>
 #include <stdexcept>
 
-#if FOLLY_X64 && (__SSE4_2__ || defined(__clang__) || __GNUC_PREREQ(4, 9))
+#if FOLLY_SSE_PREREQ(4, 2)
 #include <nmmintrin.h>
 #endif
 
@@ -31,7 +31,7 @@ namespace detail {
 
 uint32_t
 crc32c_sw(const uint8_t* data, size_t nbytes, uint32_t startingChecksum);
-#if FOLLY_X64 && (__SSE4_2__ || defined(__clang__) || __GNUC_PREREQ(4, 9))
+#if FOLLY_SSE_PREREQ(4, 2)
 
 // Fast SIMD implementation of CRC-32C for x86 with SSE 4.2
 FOLLY_TARGET_ATTRIBUTE("sse4.2")
@@ -111,6 +111,11 @@ uint32_t crc32c_hw(const uint8_t *data, size_t nbytes,
   throw std::runtime_error("crc32_hw is not implemented on this platform");
 }
 
+uint32_t crc32_hw(const uint8_t *data, size_t nbytes,
+    uint32_t startingChecksum) {
+  throw std::runtime_error("crc32_hw is not implemented on this platform");
+}
+
 bool crc32c_hw_supported() {
   return false;
 }
index 4d1a9c0231642f0e18d239d58cea05d941581c81..7a1f592331c8a41aa533a175d96e0b5d80abf2e8 100644 (file)
 namespace folly {
 namespace detail {
 
+#if FOLLY_SSE_PREREQ(4, 2)
+
 uint32_t
 crc32_hw_aligned(uint32_t remainder, const __m128i* p, size_t vec_count) {
   /* Constants precomputed by gen_crc32_multipliers.c.  Do not edit! */
@@ -269,5 +271,7 @@ _128_bits_at_a_time:
   x0 = _mm_clmulepi64_si128(_mm_and_si128(x0, mask32), barrett_reduction_constants, 0x10);
   return _mm_cvtsi128_si32(_mm_srli_si128(_mm_xor_si128(x0, x1), 4));
 }
+
+#endif
 }
 } // namespace
index 97ad45193feff0c22ebbec9129651f4747458383..05a6f22c8310dfbf275941e83ec20b19e9e9f4cf 100644 (file)
 
 #pragma once
 
+#include <folly/Portability.h>
+
+#if FOLLY_SSE_PREREQ(4, 2)
 #include <immintrin.h>
+#endif
+
 #include <stdint.h>
 #include <cstddef>
 
@@ -68,8 +73,10 @@ uint32_t crc32c_sw(const uint8_t* data, size_t nbytes,
 uint32_t
 crc32_hw(const uint8_t* data, size_t nbytes, uint32_t startingChecksum = ~0U);
 
+#if FOLLY_SSE_PREREQ(4, 2)
 uint32_t
 crc32_hw_aligned(uint32_t remainder, const __m128i* p, size_t vec_count);
+#endif
 
 /**
  * Check whether a hardware-accelerated CRC-32 implementation is