Skip to content

Commit

Permalink
PARQUET-488: Add SSE cmake toggle, fix build on systems without SSE
Browse files Browse the repository at this point in the history
I added an option to make SSE strictly opt-in for now. As a side effect of this, parquet-cpp now builds and the test suite passes out of the box on 32-bit ARMv7 (I tried it on my RaspberryPi Model B 2).

Author: Wes McKinney <wesm@apache.org>

Closes apache#74 from wesm/PARQUET-488 and squashes the following commits:

61225e9 [Wes McKinney] Use -march=native
3833efd [Wes McKinney] Remove stale cmake comment
70fcf65 [Wes McKinney] Add cmake PARQUET_USE_SSE option
775c72d [Wes McKinney] Fix compilation on arm7/raspberrypi

Change-Id: If8e4e7e1b7fc64df952cb8b82662bb017ca56f72
  • Loading branch information
wesm committed Mar 14, 2016
1 parent 3e9c72f commit 1dd8582
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
4 changes: 4 additions & 0 deletions cpp/src/parquet/util/bit-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,15 @@ class BitUtil {

/// Returns the number of set bits in x
static inline int Popcount(uint64_t x) {
#ifdef PARQUET_USE_SSE
if (LIKELY(CpuInfo::IsSupported(CpuInfo::POPCNT))) {
return POPCNT_popcnt_u64(x);
} else {
return PopcountNoHw(x);
}
#else
return PopcountNoHw(x);
#endif
}

// Compute correct population count for various-width signed integers
Expand Down
1 change: 0 additions & 1 deletion cpp/src/parquet/util/cpu-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <sys/sysctl.h>
#endif

#include <mmintrin.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/parquet/util/hash-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,15 @@ class HashUtil {
/// Seed values for different steps of the query execution should use different seeds
/// to prevent accidental key collisions. (See IMPALA-219 for more details).
static uint32_t Hash(const void* data, int32_t bytes, uint32_t seed) {
#ifdef PARQUET_USE_SSE
if (LIKELY(CpuInfo::IsSupported(CpuInfo::SSE4_2))) {
return CrcHash(data, bytes, seed);
} else {
return MurmurHash2_64(data, bytes, seed);
}
#else
return MurmurHash2_64(data, bytes, seed);
#endif
}

/// The magic number (used in hash_combine()) 0x9e3779b9 = 2^32 / (golden ratio).
Expand Down
41 changes: 34 additions & 7 deletions cpp/src/parquet/util/sse-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#ifndef PARQUET_UTIL_SSE_UTIL_H
#define PARQUET_UTIL_SSE_UTIL_H

#ifdef PARQUET_USE_SSE
#include <emmintrin.h>
#endif

namespace parquet_cpp {

Expand Down Expand Up @@ -71,6 +73,8 @@ namespace SSEUtil {
};
} // namespace SSEUtil

#ifdef PARQUET_USE_SSE

/// Define the SSE 4.2 intrinsics. The caller must first verify at runtime (or codegen
/// IR load time) that the processor supports SSE 4.2 before calling these. These are
/// defined outside the namespace because the IR w/ SSE 4.2 case needs to use macros.
Expand All @@ -81,12 +85,6 @@ namespace SSEUtil {
/// (IMPALA-1399/1646). The compiler intrinsics cannot be used without -msse4.2, so we
/// define our own implementations of the intrinsics instead.

#if defined(__SSE4_1__) || defined(__POPCNT__)
/// Impala native code should not be compiled with -msse4.1 or higher until the minimum
/// CPU requirement is raised to at least the targeted instruction set.
#error "Do not compile with -msse4.1 or higher."
#endif

/// The PCMPxSTRy instructions require that the control byte 'mode' be encoded as an
/// immediate. So, those need to be always inlined in order to always propagate the
/// mode constant into the inline asm.
Expand Down Expand Up @@ -214,7 +212,36 @@ static inline int64_t POPCNT_popcnt_u64(uint64_t a) {
return 0;
}

#endif
#endif // IR_COMPILE

#else

static inline uint32_t SSE4_crc32_u8(uint32_t crc, uint8_t v) {
DCHECK(false) << "SSE support is not enabled";
return 0;
}

static inline uint32_t SSE4_crc32_u16(uint32_t crc, uint16_t v) {
DCHECK(false) << "SSE support is not enabled";
return 0;
}

static inline uint32_t SSE4_crc32_u32(uint32_t crc, uint32_t v) {
DCHECK(false) << "SSE support is not enabled";
return 0;
}

static inline uint32_t SSE4_crc32_u64(uint32_t crc, uint64_t v) {
DCHECK(false) << "SSE support is not enabled";
return 0;
}

static inline int64_t POPCNT_popcnt_u64(uint64_t a) {
DCHECK(false) << "SSE support is not enabled";
return 0;
}

#endif // PARQUET_USE_SSE

} // namespace parquet_cpp

Expand Down

0 comments on commit 1dd8582

Please sign in to comment.