Changeset View
Changeset View
Standalone View
Standalone View
src/leveldb/port/port_posix_sse.cc
Show All 13 Lines | |||||
#include "port/port.h" | #include "port/port.h" | ||||
#if defined(LEVELDB_PLATFORM_POSIX_SSE) | #if defined(LEVELDB_PLATFORM_POSIX_SSE) | ||||
#if defined(_MSC_VER) | #if defined(_MSC_VER) | ||||
#include <intrin.h> | #include <intrin.h> | ||||
#elif defined(__GNUC__) && defined(__SSE4_2__) | #elif defined(__GNUC__) && defined(__SSE4_2__) | ||||
#include <nmmintrin.h> | #include <nmmintrin.h> | ||||
#include <cpuid.h> | |||||
#endif | #endif | ||||
#endif // defined(LEVELDB_PLATFORM_POSIX_SSE) | #endif // defined(LEVELDB_PLATFORM_POSIX_SSE) | ||||
namespace leveldb { | namespace leveldb { | ||||
namespace port { | namespace port { | ||||
#if defined(LEVELDB_PLATFORM_POSIX_SSE) | #if defined(LEVELDB_PLATFORM_POSIX_SSE) | ||||
Show All 12 Lines | |||||
static inline uint64_t LE_LOAD64(const uint8_t *p) { | static inline uint64_t LE_LOAD64(const uint8_t *p) { | ||||
uint64_t dword; | uint64_t dword; | ||||
memcpy(&dword, p, sizeof(dword)); | memcpy(&dword, p, sizeof(dword)); | ||||
return dword; | return dword; | ||||
} | } | ||||
#endif // defined(_M_X64) || defined(__x86_64__) | #endif // defined(_M_X64) || defined(__x86_64__) | ||||
static inline bool HaveSSE42() { | |||||
#if defined(_MSC_VER) | |||||
int cpu_info[4]; | |||||
__cpuid(cpu_info, 1); | |||||
return (cpu_info[2] & (1 << 20)) != 0; | |||||
#elif defined(__GNUC__) | |||||
unsigned int eax, ebx, ecx, edx; | |||||
__get_cpuid(1, &eax, &ebx, &ecx, &edx); | |||||
return (ecx & (1 << 20)) != 0; | |||||
#else | |||||
return false; | |||||
#endif | |||||
} | |||||
#endif // defined(LEVELDB_PLATFORM_POSIX_SSE) | #endif // defined(LEVELDB_PLATFORM_POSIX_SSE) | ||||
// For further improvements see Intel publication at: | // For further improvements see Intel publication at: | ||||
// http://download.intel.com/design/intarch/papers/323405.pdf | // http://download.intel.com/design/intarch/papers/323405.pdf | ||||
uint32_t AcceleratedCRC32C(uint32_t crc, const char* buf, size_t size) { | uint32_t AcceleratedCRC32C(uint32_t crc, const char* buf, size_t size) { | ||||
#if !defined(LEVELDB_PLATFORM_POSIX_SSE) | #if !defined(LEVELDB_PLATFORM_POSIX_SSE) | ||||
return 0; | return 0; | ||||
#else | #else | ||||
static bool have = HaveSSE42(); | |||||
if (!have) { | |||||
return 0; | |||||
} | |||||
const uint8_t *p = reinterpret_cast<const uint8_t *>(buf); | const uint8_t *p = reinterpret_cast<const uint8_t *>(buf); | ||||
const uint8_t *e = p + size; | const uint8_t *e = p + size; | ||||
uint32_t l = crc ^ 0xffffffffu; | uint32_t l = crc ^ 0xffffffffu; | ||||
#define STEP1 do { \ | #define STEP1 do { \ | ||||
l = _mm_crc32_u8(l, *p++); \ | l = _mm_crc32_u8(l, *p++); \ | ||||
} while (0) | } while (0) | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |