Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
namespace crc32c {

uint32_t Extend(uint32_t crc, const uint8_t* data, size_t count) {
#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) && \
(defined(__SSE4_2__) || defined(__AVX__))
static bool can_use_sse42 = CanUseSse42();
if (can_use_sse42) return ExtendSse42(crc, data, count);
#elif HAVE_ARM64_CRC32C
static bool can_use_arm64_crc32 = CanUseArm64Crc32();
if (can_use_arm64_crc32) return ExtendArm64(crc, data, count);
#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) &&
// (defined(__SSE4_2__) || defined(__AVX__))

return ExtendPortable(crc, data, count);
}
Expand Down
12 changes: 6 additions & 6 deletions src/crc32c_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
#include <cstddef>
#include <cstdint>

#include "crc32c/crc32c_config.h"

#include "benchmark/benchmark.h"
#include "crc32c/crc32c_config.h"

#if CRC32C_TESTS_BUILT_WITH_GLOG
#include "glog/logging.h"
Expand Down Expand Up @@ -36,8 +35,7 @@ class CRC32CBenchmark : public benchmark::Fixture {

BENCHMARK_DEFINE_F(CRC32CBenchmark, Public)(benchmark::State& state) {
uint32_t crc = 0;
for (auto _ : state)
crc = crc32c::Extend(crc, block_buffer_, block_size_);
for (auto _ : state) crc = crc32c::Extend(crc, block_buffer_, block_size_);
state.SetBytesProcessed(state.iterations() * block_size_);
}
BENCHMARK_REGISTER_F(CRC32CBenchmark, Public)
Expand Down Expand Up @@ -73,7 +71,8 @@ BENCHMARK_REGISTER_F(CRC32CBenchmark, ArmCRC32C)

#endif // HAVE_ARM64_CRC32C

#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) && \
(defined(__SSE4_2__) || defined(__AVX__))

BENCHMARK_DEFINE_F(CRC32CBenchmark, Sse42)(benchmark::State& state) {
if (!crc32c::CanUseSse42()) {
Expand All @@ -90,7 +89,8 @@ BENCHMARK_REGISTER_F(CRC32CBenchmark, Sse42)
->RangeMultiplier(16)
->Range(256, 16777216); // Block size.

#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) &&
// (defined(__SSE4_2__) || defined(__AVX__))

int main(int argc, char** argv) {
#if CRC32C_TESTS_BUILT_WITH_GLOG
Expand Down
6 changes: 4 additions & 2 deletions src/crc32c_sse42.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#include "./crc32c_round_up.h"
#include "crc32c/crc32c_config.h"

#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) && \
(defined(__SSE4_2__) || defined(__AVX__))

#if defined(_MSC_VER)
#include <intrin.h>
Expand Down Expand Up @@ -253,4 +254,5 @@ uint32_t ExtendSse42(uint32_t crc, const uint8_t* data, size_t size) {

} // namespace crc32c

#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) &&
// (defined(__SSE4_2__) || defined(__AVX__))
6 changes: 4 additions & 2 deletions src/crc32c_sse42.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
// portable version. Most X86 machines are 64-bit nowadays, so it doesn't make
// much sense to spend time building an optimized hardware-accelerated
// implementation.
#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) && \
(defined(__SSE4_2__) || defined(__AVX__))

namespace crc32c {

Expand All @@ -26,6 +27,7 @@ uint32_t ExtendSse42(uint32_t crc, const uint8_t* data, size_t count);

} // namespace crc32c

#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) &&
// (defined(__SSE4_2__) || defined(__AVX__))

#endif // CRC32C_CRC32C_SSE42_H_
6 changes: 4 additions & 2 deletions src/crc32c_sse42_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

#include "crc32c/crc32c_config.h"

#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) && \
(defined(__SSE4_2__) || defined(__AVX__))

// If the compiler supports SSE4.2, it definitely supports X86.

Expand Down Expand Up @@ -43,6 +44,7 @@ inline bool CanUseSse42() {

#endif // defined(_MSC_VER)

#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) &&
// (defined(__SSE4_2__) || defined(__AVX__))

#endif // CRC32C_CRC32C_SSE42_CHECK_H_
10 changes: 6 additions & 4 deletions src/crc32c_sse42_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include "gtest/gtest.h"
#include "./crc32c_sse42.h"

#include "./crc32c_extend_unittests.h"
#include "./crc32c_sse42.h"
#include "gtest/gtest.h"

namespace crc32c {

#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) && \
(defined(__SSE4_2__) || defined(__AVX__))

struct Sse42TestTraits {
static uint32_t Extend(uint32_t crc, const uint8_t* data, size_t count) {
Expand All @@ -19,6 +20,7 @@ struct Sse42TestTraits {

INSTANTIATE_TYPED_TEST_SUITE_P(Sse42, ExtendTest, Sse42TestTraits);

#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
#endif // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__)) &&
// (defined(__SSE4_2__) || defined(__AVX__))

} // namespace crc32c