CMS 3D CMS Logo

Macros | Functions | Variables
crc32c.cc File Reference
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <unistd.h>
#include <pthread.h>

Go to the source code of this file.

Macros

#define POLY   0x82f63b78
 

Functions

uint32_t crc32c (uint32_t crc, const unsigned char *buf, size_t len)
 
bool crc32c_hw_test ()
 
static void crc32c_init_sw (void)
 
static uint32_t crc32c_sw (uint32_t crci, const unsigned char *buf, size_t len)
 

Variables

static pthread_once_t crc32c_once_sw = PTHREAD_ONCE_INIT
 
static uint32_t crc32c_table [8][256]
 

Macro Definition Documentation

◆ POLY

#define POLY   0x82f63b78

Definition at line 49 of file crc32c.cc.

Referenced by crc32c_init_sw().

Function Documentation

◆ crc32c()

uint32_t crc32c ( uint32_t  crc,
const unsigned char *  buf,
size_t  len 
)

Definition at line 340 of file crc32c.cc.

References visDQMUpload::buf, and crc32c_sw().

Referenced by DataModeFRD::checksumValid(), DataModeFRDStriped::checksumValid(), FedRawDataInputSource::getNextEvent(), FRDStreamSource::setRunAndEventInfo(), FRDOutputModule::write(), and RawEventOutputModuleForBU< Consumer >::write().

341 {
342 #if defined(__x86_64__)
343  int sse42;
344 
345  SSE42(sse42);
346  return sse42 ? crc32c_hw(crc, buf, len) : crc32c_sw(crc, buf, len);
347 #else
348  return crc32c_sw(crc, buf, len);
349 #endif
350 }
static uint32_t crc32c_sw(uint32_t crci, const unsigned char *buf, size_t len)
Definition: crc32c.cc:84

◆ crc32c_hw_test()

bool crc32c_hw_test ( )

Definition at line 354 of file crc32c.cc.

Referenced by DAQSource::DAQSource(), and FedRawDataInputSource::FedRawDataInputSource().

355 {
356 
357 #if defined(__x86_64__)
358  int sse42;
359 
360  SSE42(sse42);
361  return sse42;
362 #else
363  return 0;
364 #endif
365 }

◆ crc32c_init_sw()

static void crc32c_init_sw ( void  )
static

Definition at line 56 of file crc32c.cc.

References crc32c_table, dqmdumpme::k, dqmiodumpmetadata::n, and POLY.

Referenced by crc32c_sw().

57 {
58  uint32_t n, crc, k;
59 
60  for (n = 0; n < 256; n++) {
61  crc = n;
62  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
63  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
64  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
65  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
66  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
67  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
68  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
69  crc = crc & 1 ? (crc >> 1) ^ POLY : crc >> 1;
70  crc32c_table[0][n] = crc;
71  }
72  for (n = 0; n < 256; n++) {
73  crc = crc32c_table[0][n];
74  for (k = 1; k < 8; k++) {
75  crc = crc32c_table[0][crc & 0xff] ^ (crc >> 8);
76  crc32c_table[k][n] = crc;
77  }
78  }
79 }
static uint32_t crc32c_table[8][256]
Definition: crc32c.cc:53
#define POLY
Definition: crc32c.cc:49

◆ crc32c_sw()

static uint32_t crc32c_sw ( uint32_t  crci,
const unsigned char *  buf,
size_t  len 
)
static

Definition at line 84 of file crc32c.cc.

References visDQMUpload::buf, crc32c_init_sw(), crc32c_once_sw, crc32c_table, and GetRecoTauVFromDQM_MC_cff::next.

Referenced by crc32c().

85 {
86  const unsigned char *next = buf;
87  uint64_t crc;
88 
89  pthread_once(&crc32c_once_sw, crc32c_init_sw);
90  crc = crci ^ 0xffffffff;
91  while (len && ((const uintptr_t)next & 7) != 0) {
92  crc = crc32c_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8);
93  len--;
94  }
95  while (len >= 8) {
96  crc ^= *(uint64_t *)next;
97  crc = crc32c_table[7][crc & 0xff] ^
98  crc32c_table[6][(crc >> 8) & 0xff] ^
99  crc32c_table[5][(crc >> 16) & 0xff] ^
100  crc32c_table[4][(crc >> 24) & 0xff] ^
101  crc32c_table[3][(crc >> 32) & 0xff] ^
102  crc32c_table[2][(crc >> 40) & 0xff] ^
103  crc32c_table[1][(crc >> 48) & 0xff] ^
104  crc32c_table[0][crc >> 56];
105  next += 8;
106  len -= 8;
107  }
108  while (len) {
109  crc = crc32c_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8);
110  len--;
111  }
112  return (uint32_t)crc ^ 0xffffffff;
113 }
static pthread_once_t crc32c_once_sw
Definition: crc32c.cc:52
static uint32_t crc32c_table[8][256]
Definition: crc32c.cc:53
unsigned long long uint64_t
Definition: Time.h:13
static void crc32c_init_sw(void)
Definition: crc32c.cc:56

Variable Documentation

◆ crc32c_once_sw

pthread_once_t crc32c_once_sw = PTHREAD_ONCE_INIT
static

Definition at line 52 of file crc32c.cc.

Referenced by crc32c_sw().

◆ crc32c_table

uint32_t crc32c_table[8][256]
static

Definition at line 53 of file crc32c.cc.

Referenced by crc32c_init_sw(), and crc32c_sw().