mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-29 18:33:58 +00:00
b937be3779
Summary:
Closes https://github.com/facebook/rocksdb/issues/7691
The optimised CRC code for PPC64le which was originally imported in https://github.com/facebook/rocksdb/pull/2353 is not compatible with Clang 11. It looks like the code most likely originated from https://github.com/antonblanchard/crc32-vpmsum.
The code relied on a GCC header file `ppc-asm.h` which is not available in Clang.
To solve this, I have taken the same approach as the the upstream project from which the CRC code came ffc8018efc (diff-ec3e62c56fbcddeb07230f2a4673c1abd7f0f1cc8e48a2aa560056cfc1b25d60)
and simply imported a copy of the GCC header file into our code-base which will be used when Clang is the compiler on pcc64le.
**NOTE**: The new file `util/ppc-asm.h` may have licensing implications which I guess need to be approved by RocksDB/Facebook before this is merged
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7713
Reviewed By: jay-zhuang
Differential Revision: D25222645
Pulled By: pdillinger
fbshipit-source-id: e3fec9136f26ce1eb7a027048bcf77a6cb3c769c
95 lines
2.5 KiB
C
95 lines
2.5 KiB
C
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
// Copyright (c) 2017 International Business Machines Corp.
|
|
// All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#define CRC_TABLE
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <strings.h>
|
|
#include "util/crc32c_ppc_constants.h"
|
|
|
|
#define VMX_ALIGN 16
|
|
#define VMX_ALIGN_MASK (VMX_ALIGN - 1)
|
|
|
|
#ifdef REFLECT
|
|
static unsigned int crc32_align(unsigned int crc, unsigned char const *p,
|
|
unsigned long len) {
|
|
while (len--) crc = crc_table[(crc ^ *p++) & 0xff] ^ (crc >> 8);
|
|
return crc;
|
|
}
|
|
#endif
|
|
|
|
#ifdef HAVE_POWER8
|
|
unsigned int __crc32_vpmsum(unsigned int crc, unsigned char const *p,
|
|
unsigned long len);
|
|
|
|
static uint32_t crc32_vpmsum(uint32_t crc, unsigned char const *data,
|
|
size_t len) {
|
|
unsigned int prealign;
|
|
unsigned int tail;
|
|
|
|
#ifdef CRC_XOR
|
|
crc ^= 0xffffffff;
|
|
#endif
|
|
|
|
if (len < VMX_ALIGN + VMX_ALIGN_MASK) {
|
|
crc = crc32_align(crc, data, (unsigned long)len);
|
|
goto out;
|
|
}
|
|
|
|
if ((unsigned long)data & VMX_ALIGN_MASK) {
|
|
prealign = VMX_ALIGN - ((unsigned long)data & VMX_ALIGN_MASK);
|
|
crc = crc32_align(crc, data, prealign);
|
|
len -= prealign;
|
|
data += prealign;
|
|
}
|
|
|
|
crc = __crc32_vpmsum(crc, data, (unsigned long)len & ~VMX_ALIGN_MASK);
|
|
|
|
tail = len & VMX_ALIGN_MASK;
|
|
if (tail) {
|
|
data += len & ~VMX_ALIGN_MASK;
|
|
crc = crc32_align(crc, data, tail);
|
|
}
|
|
|
|
out:
|
|
#ifdef CRC_XOR
|
|
crc ^= 0xffffffff;
|
|
#endif
|
|
|
|
return crc;
|
|
}
|
|
|
|
/* This wrapper function works around the fact that crc32_vpmsum
|
|
* does not gracefully handle the case where the data pointer is NULL. There
|
|
* may be room for performance improvement here.
|
|
*/
|
|
uint32_t crc32c_ppc(uint32_t crc, unsigned char const *data, size_t len) {
|
|
unsigned char *buf2;
|
|
|
|
if (!data) {
|
|
buf2 = (unsigned char *)malloc(len);
|
|
bzero(buf2, len);
|
|
crc = crc32_vpmsum(crc, buf2, len);
|
|
free(buf2);
|
|
} else {
|
|
crc = crc32_vpmsum(crc, data, (unsigned long)len);
|
|
}
|
|
return crc;
|
|
}
|
|
|
|
#else /* HAVE_POWER8 */
|
|
|
|
/* This symbol has to exist on non-ppc architectures (and on legacy
|
|
* ppc systems using power7 or below) in order to compile properly
|
|
* there, even though it won't be called.
|
|
*/
|
|
uint32_t crc32c_ppc(uint32_t crc, unsigned char const *data, size_t len) {
|
|
return 0;
|
|
}
|
|
|
|
#endif /* HAVE_POWER8 */
|