203typedef long long int v2di
__attribute__ ((vector_size (16)));
232v2di load_unaligned (
const char*
x)
234 return (v2di)__builtin_ia32_loaddqu (
x);
244v2di load_aligned (
const char*
x)
258#define byteshift_l(X, N) (__builtin_ia32_pslldqi128 ((X), (N)*8))
267#define byteshift_r(X, N) (__builtin_ia32_psrldqi128 ((X), (N)*8))
281#define clmul(A, B, WHICH) (__builtin_ia32_pclmulqdq128 ((A), (B), (WHICH)))
298void byteshift_l256 (v2di in,
size_t n, v2di& outHigh, v2di& outLow)
300 static const uint8_t shuffleMasks[] = {
301 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
302 0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80,
305 const v16qi
mask = (v16qi)load_unaligned ((
const char*)shuffleMasks + (16-n));
306 outLow = (v2di)__builtin_ia32_pshufb128 ((v16qi)in, ~mask);
307 outHigh = (v2di)__builtin_ia32_pshufb128 ((v16qi)in, mask);
325 return y & (
static_cast<int64_t
>(
x)>>63);
338uint64_t exp_mod (
unsigned exp, uint64_t p)
343 for (
unsigned i=0;
i <
exp-64;
i++) {
344 d = (
d<<1) ^ hightest (d, p);
363 for (
unsigned i=0;
i < 64;
i++) {
364 q |= (
h & (1ull << 63)) >> i;
365 h = (
h << 1) ^ hightest (
h, p);
386 v = ((v >> 1) & 0x5555555555555555) | ((v & 0x5555555555555555) << 1);
387 v = ((v >> 2) & 0x3333333333333333) | ((v & 0x3333333333333333) << 2);
388 v = ((v >> 4) & 0x0F0F0F0F0F0F0F0F) | ((v & 0x0F0F0F0F0F0F0F0F) << 4);
389 v = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
390 v = ((v >> 16) & 0x0000FFFF0000FFFF) | ((v & 0x0000FFFF0000FFFF) << 16);
391 v = (v >> 32) | (v << 32);
412v2di folding_round (v2di fold, v2di data, v2di k)
415 ^ clmul (fold, k, 0x00)
416 ^ clmul (fold, k, 0x11);
427v2di fold_trailing_zeros (v2di data, v2di k)
429 return clmul (data, k, 0x10) ^ byteshift_r (data, 8);
440v2di barrett_reduce (v2di R, v2di k)
442 v2di
T1 = clmul (R, k, 0x00);
444 ^ clmul (T1, k, 0x10)
445 ^ byteshift_l (T1, 8);
471 CRCTable (uint64_t p, uint64_t initial = 0xffffffffffffffff);
481 v2di m_fold_constants;
484 v2di m_barrett_constants;
499 for (
int i = 0; i < 256; i++)
502 for (
int j = 0; j < 8; j++)
513 const uint64_t k1 =
bit_reflect (exp_mod (128+64, p)) << 1;
514 const uint64_t k2 =
bit_reflect (exp_mod (128, p)) << 1;
515 const uint64_t mu = (
bit_reflect (exp129_div (p)) << 1) | 1;
516 const uint64_t prev65 = (
bit_reflect (p) << 1) | 1;
518 m_fold_constants =
reinterpret_cast<v2di
>(
a);
519 v2du b = { mu, prev65 };
520 m_barrett_constants =
reinterpret_cast<v2di
>(b);
549 return std::make_unique<CRCTable> (p, initial);
563 uint64_t crc = table.m_initial;
564 const char* seq = data;
565 const char*
end = seq + data_len;
567 crc = table.m_table[(crc ^ *seq++) & 0xff] ^ (crc >> 8);
610 uint64_t crc = table.m_initial;
613 if (!data_len) [[
unlikely]]
return crc;
619 if (
reinterpret_cast<unsigned long>(data) & 15) [[
unlikely]] {
621 size_t leadin = std::min (16 - (
reinterpret_cast<unsigned long>(data) & 15), data_len);
626 if (!data_len) [[
unlikely]]
return crc;
630 v2di fold = {
static_cast<int64_t
>(crc), 0};
633 v2di
k =
table.m_fold_constants;
637 v2di temp2 = load_aligned (data);
639 byteshift_l256 (fold, 16-data_len, crc1, crc0);
641 byteshift_l256 (temp2, 16-data_len, B, A);
644 fold = fold_trailing_zeros (fold, k);
645 fold ^= byteshift_l (crc1, 8);
651 fold ^= load_aligned (data);
656 for (;
n+16 <= data_len;
n += 16) {
657 v2di temp2 = load_aligned (data + n);
658 fold = folding_round (fold, temp2, k);
662 if (n < data_len) [[
likely]] {
663 v2di
remainder = load_aligned (data + n);
665 size_t nrem = data_len -
n;
667 byteshift_l256 (fold, 16-nrem, B, A);
669 fold = folding_round (A, B|
C, k);
671 fold = fold_trailing_zeros (fold, k);
675 fold = barrett_reduce (fold,
table.m_barrett_constants);
719uint64_t
crc64 (
const std::string& s)
748 sprintf (buf,
"%08X%08X",
749 (
unsigned)((crc>>32)&0xffffffff), (
unsigned)(crc&0xffffffff));
__attribute__((always_inline)) inline uint16_t TileCalibDrawerBase
Header file for AthHistogramAlgorithm.
Precomputed tables and constants for the CRC calculation.
uint64_t m_initial
Initial CRC value.
uint64_t m_table[256]
Lookup table for bytewise CRC calculation.
CRCTable(uint64_t p, uint64_t initial=0xffffffffffffffff)
Initialize the CRC tables and constants.
std::vector< std::string > remainder(const std::vector< std::string > &v1, const std::vector< std::string > &v2)
uint64_t bit_reflect(uint64_t v)
A crc-64 implementation, using pclmul where possible.
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
uint64_t crc64(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string,.
uint64_t crc64_bytewise(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string, using a byte-by-byte algorithm.
std::unique_ptr< CRCTable > makeCRCTable(uint64_t p, uint64_t initial=0xffffffffffffffff)
Initialize CRC tables and constants.
const CRCTable defaultCRCTable(0xad93d23594c935a9)
std::string crc64digest(const std::string &str)
Return a CRC-64 digest of a string.
const_iterator end() const
Return an end iterator.
std::string crc64format(uint64_t crc)
Format a CRC-64 as a string.
void deleteCRCTable(CxxUtils::CRCTable *table)
Delete a CRCTable object.
uint64_t crc64addint(uint64_t crc, uint64_t x)
Extend a previously-calculated CRC to include an int.