Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ARMv8 CRC32C support. #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 7 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ On systems with gcc, we generally recommend:
make all check CXXFLAGS="-g -O3"
sudo make install

Or, if your system has the CRC32 instruction, and you want to build everything:
If your system has the SSE CRC32 instruction, and you want to build everything:

./configure --enable-sse4.2
make all check CXXFLAGS="-g -O3 -msse4.2"
sudo make install

Or, for the ARMv8 CRC32C instruction:

./configure --enable-sse4.2
make all check CXXFLAGS="-g -O3 -march=armv8-a+crc"
sudo make install

Note that our build system doesn't try to determine the appropriate compiler
flag for enabling SSE4.2. For gcc it is "-msse4.2". The --enable-sse4.2
flag to the configure script controls whether citycrc.h is installed when
Expand Down
4 changes: 2 additions & 2 deletions src/city-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <iostream>
#include <string.h>
#include "city.h"
#ifdef __SSE4_2__
#if defined __SSE4_2__ || defined __ARM_FEATURE_CRC32
#include "citycrc.h"
#endif

Expand Down Expand Up @@ -1279,7 +1279,7 @@ void Test(const uint64* expected, int offset, int len) {
Check(expected[4], Uint128High64(u));
Check(expected[5], Uint128Low64(v));
Check(expected[6], Uint128High64(v));
#ifdef __SSE4_2__
#if defined __SSE4_2__ || defined __ARM_FEATURE_CRC32
const uint128 y = CityHashCrc128(data + offset, len);
const uint128 z = CityHashCrc128WithSeed(data + offset, len, kSeed128);
uint64 crc256_results[4];
Expand Down
15 changes: 11 additions & 4 deletions src/city.cc
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,16 @@ uint128 CityHash128(const char *s, size_t len) {
CityHash128WithSeed(s, len, uint128(k0, k1));
}

#ifdef __SSE4_2__
#if defined __SSE4_2__ || defined __ARM_FEATURE_CRC32
#include <citycrc.h>
#ifdef __SSE4_2__
#include <nmmintrin.h>
#define crc32_u64 _mm_crc32_u64
#endif
#ifdef __ARM_FEATURE_CRC32
#include <arm_acle.h>
#define crc32_u64 __crc32cd
#endif

// Requires len >= 240.
static void CityHashCrc256Long(const char *s, size_t len,
Expand Down Expand Up @@ -550,9 +557,9 @@ static void CityHashCrc256Long(const char *s, size_t len,
g += e; \
e += z; \
g += x; \
z = _mm_crc32_u64(z, b + g); \
y = _mm_crc32_u64(y, e + h); \
x = _mm_crc32_u64(x, f + a); \
z = crc32_u64(z, b + g); \
y = crc32_u64(y, e + h); \
x = crc32_u64(x, f + a); \
e = Rotate(e, r); \
c += e; \
s += 40
Expand Down