Skip to content

Commit

Permalink
[CPP] Compile fixes for ARM cpus (apache#6129)
Browse files Browse the repository at this point in the history
* [CPP] Compile fixes for ARM cpus

* Fixed formatting
  • Loading branch information
merlimat authored Jan 23, 2020
1 parent d0920fc commit c078a55
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
14 changes: 10 additions & 4 deletions pulsar-client-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ if(CCACHE_PROGRAM)
MESSAGE(STATUS "Using CCache")
endif(CCACHE_PROGRAM)

MESSAGE(STATUS "ARCHITECTURE: ${CMAKE_SYSTEM_PROCESSOR}")

option(BUILD_TESTS "Build tests" ON)
MESSAGE(STATUS "BUILD_TESTS: " ${BUILD_TESTS})

Expand All @@ -49,12 +51,16 @@ set(Boost_NO_BOOST_CMAKE ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)

if (NOT MSVC)
add_compile_options(-msse4.2 -mpclmul -Werror=switch -Wno-deprecated-declarations)
else()
if (MSVC)
# Visual Studio compiler flags
add_definitions(-DWIN32_LEAN_AND_MEAN -DNOGDI -D_WIN32_WINNT=0x0501 -D_CRT_SECURE_NO_WARNINGS)
add_compile_options(/wd4244 /wd4267 /wd4018 /wd4715 /wd4251 /wd4275)
endif(NOT MSVC)
else()
add_compile_options(-Werror=switch -Wno-deprecated-declarations)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
add_compile_options(-msse4.2 -mpclmul)
endif()
endif(MSVC)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Expand Down
24 changes: 22 additions & 2 deletions pulsar-client-cpp/lib/checksum/crc32c_sse42.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
******************************************************************************/
#include "crc32c_sse42.h"

#include <boost/predef.h>

#include <assert.h>
#include <stdlib.h>

#if BOOST_ARCH_X86_64
#include <nmmintrin.h> // SSE4.2
#include <wmmintrin.h> // PCLMUL
#endif

#ifdef _MSC_VER
#include <intrin.h>
#else
#elif BOOST_ARCH_X86_64
#include <cpuid.h>
#endif

Expand Down Expand Up @@ -55,12 +61,15 @@ bool crc32c_initialize() {
__cpuid(CPUInfo, 1);
has_sse42 = (CPUInfo[2] & cpuid_ecx_sse42) != 0;
has_pclmulqdq = (CPUInfo[2] & cpuid_ecx_pclmulqdq) != 0;
#else
#elif BOOST_ARCH_X86_64
unsigned int eax, ebx, ecx, edx;
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
has_sse42 = (ecx & cpuid_ecx_sse42) != 0;
has_pclmulqdq = (ecx & cpuid_ecx_pclmulqdq) != 0;
}
#else
has_sse42 = false;
has_pclmulqdq = false;
#endif
DEBUG_PRINTF1("has_sse42 = %d\n", has_sse42);
DEBUG_PRINTF1("has_pclmulqdq = %d\n", has_pclmulqdq);
Expand Down Expand Up @@ -88,6 +97,8 @@ void chunk_config::make_shift_table(size_t bytes, uint32_t table[256]) {
for (unsigned int i = 0; i < 256; ++i) table[i] = (const bitvector<32>)mul(m, bitvector<32>(i));
}

#if BOOST_ARCH_X86_64

static uint32_t crc32c_chunk(uint32_t crc, const void *buf, const chunk_config &config) {
DEBUG_PRINTF3(" crc32c_chunk(crc = 0x%08x, buf = %p, config.words = " SIZE_T_FORMAT ")", crc, buf,
config.words);
Expand Down Expand Up @@ -228,3 +239,12 @@ uint32_t crc32c(uint32_t init, const void *buf, size_t len, const chunk_config *
DEBUG_PRINTF1("crc = 0x%08x\n", crc);
return crc;
}

#else // ! BOOST_ARCH_X86_64

uint32_t crc32c(uint32_t init, const void *buf, size_t len, const chunk_config *config) {
// SSE 4.2 extension for hw implementation are not present
abort();
}

#endif
2 changes: 1 addition & 1 deletion pulsar-client-cpp/perf/PerfProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ int main(int argc, char** argv) {

pulsar::Client client(pulsar::PulsarFriend::getClient(args.serviceURL, conf, false));

std::atomic<bool> exitCondition;
std::atomic<bool> exitCondition(false);
startPerfProducer(args, producerConf, client, exitCondition);

Clock::time_point oldTime = Clock::now();
Expand Down
2 changes: 1 addition & 1 deletion pulsar-client-cpp/perf/RateLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RateLimiter::RateLimiter(double rate)
: interval_(std::chrono::microseconds((long)(1e6 / rate))),
storedPermits_(0.0),
maxPermits_(rate),
nextFree_() {
nextFree_(Clock::now()) {
assert(rate < 1e6 && "Exceeded maximum rate");
}

Expand Down

0 comments on commit c078a55

Please sign in to comment.